From 30f1fdd36559899dcd53d0620b1a0c4e7cebdc29 Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Thu, 9 Mar 2017 16:14:46 -0600 Subject: rc.inet1{,.conf}: Allow create/destroy of virtual tun/tap devices --- rc.inet1 | 27 +++++++++++++++++++++++++++ rc.inet1.conf | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/rc.inet1 b/rc.inet1 index 5f9c29d..2f982ca 100644 --- a/rc.inet1 +++ b/rc.inet1 @@ -73,6 +73,31 @@ lo_down() { # INTERFACE FUNCTIONS # ####################### +# Function to determine if virtual interfaces are defined +virtif_determine() { + if [ ! -z ${VIRTIFNAME} ]; then + virtifcount=$(echo ${VIRTIFNAME[@]} | wc -w) + else + return 1 + fi +} + +# Function to create virtual interfaces +virtif_create() { + # argument is 'i' - the position of this interface in the IFNAME array. + for i in $(seq 0 ${virtifcount}); do + /sbin/ip tuntap add dev ${VIRTIFNAME[$i]} mode ${VIRTIFTYPE[$i]} user ${VIRTIFUSER[$i]} group ${VIRTIFGROUP[$i]} + done +} + +# Function to destory virtual interfaces +virtif_destroy() { + # argument is 'i' - the position of this interface in the IFNAME array. + for i in $(seq 0 ${virtifcount}); do + /sbin/ip tuntap del dev ${VIRTIFNAME[$i]} mode ${VIRTIFTYPE[$i]} + done +} + # Function to assemble a bridge interface. br_open() { # argument is 'i' - the position of this interface in the IFNAME array. @@ -256,6 +281,7 @@ gateway_down() { # Function to start the network: start() { lo_up + virtif_determine && virtif_create for i in ${IFNAME[@]} ; do if_up $i done @@ -268,6 +294,7 @@ stop() { for i in ${IFNAME[@]} ; do if_down $i done + virtif_determine && virtif_destroy lo_down } diff --git a/rc.inet1.conf b/rc.inet1.conf index 85a8041..93b3e6c 100644 --- a/rc.inet1.conf +++ b/rc.inet1.conf @@ -55,6 +55,23 @@ DEBUG_ETH_UP="no" #USE_DHCP[0]="" #DHCP_HOSTNAME[0]="" +# Virtual interfaces to create - these are created before any address +# configuration or bridge setup is done, so you may use these interfaces +# as IFNAME or BRNICS values. These can be tun or tap interfaces: +# adjust VIRTIFNAME and VIRTIFTYPE accordingly +# +# Virtual tap interface example +#VIRTIFNAME[0]="tap0" +#VIRTIFTYPE[0]="tap" +#VIRTIFUSER[0]="root" +#VIRTIFGROUP[0]="root" +# +# Virtual tun interface example +#VIRTIFNAME[1]="tun0" +#VIRTIFTYPE[1]="tun" +#VIRTIFUSER[1]="someuser" +#VIRTIFGROUP[1]="somegroup" + ## Example config information for wlan0. Uncomment the lines you need and fill ## in your data. (You may not need all of these for your wireless network) #IFNAME[4]="wlan0" -- cgit v1.2.3 From 6d9819e53e571df0b657fa12535290f59c031113 Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Wed, 12 Jul 2017 02:11:28 -0500 Subject: rc.inet1: fix index number usage in virtual interface setup/destroy --- rc.inet1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.inet1 b/rc.inet1 index 2f982ca..9ab5102 100644 --- a/rc.inet1 +++ b/rc.inet1 @@ -76,7 +76,7 @@ lo_down() { # Function to determine if virtual interfaces are defined virtif_determine() { if [ ! -z ${VIRTIFNAME} ]; then - virtifcount=$(echo ${VIRTIFNAME[@]} | wc -w) + virtifcount=$(expr $(echo ${VIRTIFNAME[@]} | wc -w) - 1) else return 1 fi -- cgit v1.2.3 From 04cd52d9770c138cebc5ada8fa9732911b226307 Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Thu, 9 Mar 2017 16:34:24 -0600 Subject: README: Noted status of virtual-ifs branch --- README | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/README b/README index 9cd7f39..915a5f8 100644 --- a/README +++ b/README @@ -6,32 +6,15 @@ This document is/will be useful: http://baturin.org/docs/iproute2/ To prevent multiple people trying to push changes to master branch, please make changes in a user branch, push them, and I'll merge, -or make a diff and send it to me. +or make a diff and send it to me. If you would like commit access +to a user branch, send me a mail with an ssh pubkey attached. -Before production use and/or heavy testing, grep through for any -instances of "TODO" and fix them :-) +This branch is feature-complete with respect to the stock networking +scripts in Slackware -current, but it also (has|will hopefully have) +other features listed below as TODO items. TODO: - -There's plenty of room for refactoring and even rewriting here, such -as supporting addition of tun/tap devices for adding to bridges or -using for VPNs, supporting IPv6, etcetera. However, primary focus thus -far is to simply duplicate existing functionality and make sure it all -works as expected. Once that's confirmed, we can reassess where to go -from there. - -I've got one host here (no tests run on this host though) that shows -the loopback interface in state UNKNOWN: - 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1 - link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 -No idea how common this is, but perhaps a slight change of the loopback -checking logic is needed... - -Tested successfully so far: - * dhcp configuration of one interface - * static configuration of one interface - * bridge with four interfaces (eth0, tap1, tap2, tap3) with static - IP address; I created the tap interfaces manually in rc.modules.local - since there's currently no support for creating them in the network - scripts + * create tun/tap interfaces [done] + * additional IP addresses to interfaces + * IPv6 support -- cgit v1.2.3 From 6281b5d47da57004b1d00f1a9946f5af6cca38a0 Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Thu, 13 Jul 2017 19:11:47 -0500 Subject: rc.inet1: Use bash builtin arithmetic instead of external expr --- rc.inet1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.inet1 b/rc.inet1 index 9ab5102..871b38d 100644 --- a/rc.inet1 +++ b/rc.inet1 @@ -76,7 +76,7 @@ lo_down() { # Function to determine if virtual interfaces are defined virtif_determine() { if [ ! -z ${VIRTIFNAME} ]; then - virtifcount=$(expr $(echo ${VIRTIFNAME[@]} | wc -w) - 1) + virtifcount=$(($(echo ${VIRTIFNAME[@]} | wc -w) - 1)) else return 1 fi -- cgit v1.2.3