Busybox tunctl can only create TAP devices (i.e., with IFF_TAP). This
patch allows it to create TUN devices with options like the other tunctl.

Thanks!

---
 networking/tunctl.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/networking/tunctl.c b/networking/tunctl.c
index 941e8bb..c55c3b9 100644
--- a/networking/tunctl.c
+++ b/networking/tunctl.c
@@ -17,6 +17,8 @@
 //usage:     "\n       -f name         tun device (/dev/net/tun)"
 //usage:     "\n       -t name         Create iface 'name'"
 //usage:     "\n       -d name         Delete iface 'name'"
+//usage:     "\n       -n              Specify a TUN interface. (Implied if 
the iface name contains 'tun')."
+//usage:     "\n       -p              Specify a TAP interface."
 //usage:       IF_FEATURE_TUNCTL_UG(
 //usage:     "\n       -u owner        Set iface owner"
 //usage:     "\n       -g group        Set iface group"
@@ -58,21 +60,30 @@ int tunctl_main(int argc UNUSED_PARAM, char **argv)
                OPT_f = 1 << 0, // control device name (/dev/net/tun)
                OPT_t = 1 << 1, // create named interface
                OPT_d = 1 << 2, // delete named interface
+               OPT_n = 1 << 3, // create a TUN interface
+               OPT_p = 1 << 4, // create a TAP interface
 #if ENABLE_FEATURE_TUNCTL_UG
-               OPT_u = 1 << 3, // set new interface owner
-               OPT_g = 1 << 4, // set new interface group
-               OPT_b = 1 << 5, // brief output
+               OPT_u = 1 << 5, // set new interface owner
+               OPT_g = 1 << 6, // set new interface group
+               OPT_b = 1 << 7, // brief output
 #endif
        };
 
-       opt_complementary = "=0:t--d:d--t"; // no arguments; t ^ d
-       opts = getopt32(argv, "f:t:d:" IF_FEATURE_TUNCTL_UG("u:g:b"),
+       opt_complementary = "=0:t--d:d--t:n--p"; // no arguments; t ^ d
+       opts = getopt32(argv, "f:t:d:np" IF_FEATURE_TUNCTL_UG("u:g:b"),
                        &opt_device, &opt_name, &opt_name
                        IF_FEATURE_TUNCTL_UG(, &opt_user, &opt_group));
 
+       memset(&ifr, 0, sizeof(ifr));
+
+       // select mode
+       if (!(opts & OPT_n) && !(opts & OPT_p)) {
+               opts |= strstr(opt_name, "tun") ? OPT_n : OPT_p;
+       }
+       ifr.ifr_flags |= (opts & OPT_n) ? IFF_TUN : IFF_TAP;
+
        // select device
-       memset(&ifr, 0, sizeof(ifr));
-       ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+       ifr.ifr_flags |= IFF_NO_PI;
        strncpy_IFNAMSIZ(ifr.ifr_name, opt_name);
 
        // open device
-- 
2.9.3

Attachment: signature.asc
Description: PGP signature

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to