Serious refactoring of TUN/TAP and tunnel code. Linux udp/gre tunnels not yet functional
[nepi.git] / src / nepi / resources / linux / scripts / linux-tap-passfd.py
diff --git a/src/nepi/resources/linux/scripts/linux-tap-passfd.py b/src/nepi/resources/linux/scripts/linux-tap-passfd.py
new file mode 100644 (file)
index 0000000..6332362
--- /dev/null
@@ -0,0 +1,41 @@
+import base64
+import errno
+import os
+import passfd
+import socket
+
+from optparse import OptionParser
+
+PASSFD_MSG = "PASSFD"
+
+def get_options():
+    usage = ("usage: %prog -a <address> -S <vif-socket> ")
+    
+    parser = OptionParser(usage = usage)
+
+    parser.add_option("-a", "--address", dest="address",
+        help = "Socket address to send file descriptor to", type="str")
+    parser.add_option("-S", "--vif-socket", dest="vif_socket",
+        help = "Name for the unix socket to request the TAP file descriptor", 
+        default = "tap.sock", type="str")
+
+    (options, args) = parser.parse_args()
+       
+    return (options.address, options.vif_socket)
+
+if __name__ == '__main__':
+
+    (address, vif_socket) = get_options()
+  
+    # This script sends a message (PASSFD_MSG) to the process that created 
+    # the TUN/TAP device to request that it sens the file descriptor associated
+    # to the TUN/TAP to another process. The other process is waiting for
+    # the file descriptor on 'address'
+    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+    sock.connect(vif_socket)
+    emsg = base64.b64encode(PASSFD_MSG)
+    eargs = address
+    encoded = "%s|%s\n" % (emsg, eargs)
+    sock.send(encoded)
+
+