[PATCH] tunctl: Optionally create TUN interfaces
Lizzie Dixon
_ at lizzie.io
Sat Aug 20 09:25:41 UTC 2016
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20160820/1df3ea49/attachment.asc>
More information about the busybox
mailing list