summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Semenkov <semenkovk@gmail.com>2019-01-21 11:42:56 +0300
committerRobin H. Johnson <robbat2@gentoo.org>2019-04-20 21:10:41 -0700
commit4ddfad307887e80a296a611832cf3780ccaf9616 (patch)
tree0bcd1f544fc4311ab0f60fe1784d3601ba1eb4eb
parentVeth support added (diff)
downloadnetifrc-4ddfad307887e80a296a611832cf3780ccaf9616.tar.gz
netifrc-4ddfad307887e80a296a611832cf3780ccaf9616.tar.bz2
netifrc-4ddfad307887e80a296a611832cf3780ccaf9616.zip
Two separate peer variables for every peer in veth
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r--doc/net.example.Linux.in7
-rw-r--r--net/veth.sh35
2 files changed, 15 insertions, 27 deletions
diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 6fc6094..8896acf 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -916,7 +916,7 @@
#-----------------------------------------------------------------------------
# Virtual interface device (veth)
-# For veth support install iproute2 and awk
+# For veth support install iproute2
#
# The script uses "standard" ways of IP-address assignement in net.lo script. Network namespaces are not implemented here
# because net.lo currently knows nothing about network namespaces.
@@ -925,10 +925,11 @@
# The interface type must be set for both peers
#type_veth0="veth"
# Here we declare peers for "ip link add" command
-#veth_veth0="veth0 veth1"
+#veth_veth0_peer1="veth0"
+#veth_veth0_peer2="veth1"
#config_veth0="192.168.0.1/24"
#
-# Avoids race
+# Prevents race
#rc_net_veth1_need="net.veth0"
#type_veth1="veth"
# Both peers are created when the first one starts, we don't need to create the second peer
diff --git a/net/veth.sh b/net/veth.sh
index d969a14..5ff6587 100644
--- a/net/veth.sh
+++ b/net/veth.sh
@@ -3,7 +3,7 @@
veth_depend()
{
- program ip awk
+ program ip
}
_config_vars="$_config_vars veth"
@@ -72,19 +72,13 @@ _bring_peer_down()
#Create and bring the veth pair up
_create_peers()
{
- local peers
- peers="$(_get_array "veth_${IFVAR}")"
-
- # veth has exactly two peers.
- # For POSIX compatibility we evade bash arrays
- local npeers
- npeers=$(echo "$peers" | awk '{print NF}')
- if [ "$npeers" != 2 ]; then
- eerror "veth interface must have exactly two peers"
- return 1
- fi
+ local peer1
+ peer1="$(_get_array "veth_${IFVAR}_peer1")"
+
+ local peer2
+ peer2="$(_get_array "veth_${IFVAR}_peer2")"
- for x in ${peers}; do
+ for x in $peer1 $peer2; do
if _exists "$x" ; then
eerror "Interface $x already exists. Can't continue"
return 1
@@ -104,12 +98,6 @@ _create_peers()
return 1
fi
- local peer1
- peer1=$(echo "$peers" | awk '{print $1}')
- local peer2
- peer2=$(echo "$peers" | awk '{print $2}')
-
-
ip link add "$peer1" type veth peer name "$peer2" > /dev/null 2>&1 || {
eerror "Can't create veth peer $peer1 or $peer2"
return 1
@@ -177,14 +165,13 @@ veth_post_stop()
return 0
fi
- local peers
- peers="$(_get_array "veth_${IFVAR}")"
- local first
- first=$(echo "$peers" | awk '{print $1}')
+ local peer1
+ peer1="$(_get_array "veth_${IFVAR}_peer1")"
+
local netns1
netns1="$(_get_array "veth_${IFVAR}_ns1")"
- if ! _bring_peer_down "$first" "$netns1"
+ if ! _bring_peer_down "$peer1" "$netns1"
then
eerror "Can't delete the veth pair ${IFVAR}"
eend 1