[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH] tunctl: Optionally create TUN interfaces
From: Lizzie Dixon <_ () lizzie ! io>
Date: 2016-08-20 9:25:41
Message-ID: 20160820092541.GA688 () empress
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
Sorry, missed a 'p--n' in opt_complementary. Here's the whole thing,
updated:
---
networking/tunctl.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/networking/tunctl.c b/networking/tunctl.c
index 941e8bb..46c76fd 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:p--n"; // 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
["signature.asc" (application/pgp-signature)]
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic