From: Dmitry V. Levin Date: Fri, 31 Oct 2008 11:54:47 +0000 (+0000) Subject: vznetaddbr.in: Rewrite without bash-isms and ifconfig X-Git-Url: http://git.openvz.org/?p=vzctl;a=commitdiff_plain;h=93ef4d978a8c609cc04c53f39bc4fe674a089811 vznetaddbr.in: Rewrite without bash-isms and ifconfig Signed-off-by: Dmitry V. Levin --- diff --git a/bin/vznetaddbr.in b/bin/vznetaddbr.in index eb2ba70..e8599e9 100755 --- a/bin/vznetaddbr.in +++ b/bin/vznetaddbr.in @@ -1,53 +1,39 @@ -#!/bin/bash +#!/bin/sh # # Add virtual network interfaces (veth's) in a container to a bridge on CT0 CONFIGFILE=@PKGCONFDIR@/conf/$VEID.conf . $CONFIGFILE -NETIFLIST=$(echo $NETIF | sed 's/;/\n/g') +NETIFLIST=$(printf %s "$NETIF" |tr ';' '\n') -if [ ! -n "$NETIFLIST" ]; then - echo "According to $CONFIGFILE, CT$VEID has no veth interface configured." +if [ -z "$NETIFLIST" ]; then + echo >&2 "According to $CONFIGFILE, CT$VEID has no veth interface configured." exit 1 fi -IFACES=$(echo $NETIFLIST | sed 's/;/\n/g') -for tmp in $IFACES; do - CTIFNAME= - CTBRIDGE= - VZHOSTIF= - - NETIF_OPTIONS=$(echo $tmp | sed 's/,/\n/g') - for str in $NETIF_OPTIONS; do - # getting 'ifname' parameter value - if [[ "$str" =~ ^ifname= ]]; then - # remove the parameter name from the string (along with '=') - CTIFNAME=${str#*=} - fi - if [[ "$str" =~ ^bridge= ]]; then - # remove the parameter name from the string (along with '=') - CTBRIDGE=${str#*=} - fi - # getting 'host_ifname' parameter value - if [[ "$str" =~ ^host_ifname= ]]; then - # remove the parameter name from the string (along with '=') - VZHOSTIF=${str#*=} - fi +for iface in $NETIFLIST; do + bridge= + host_ifname= + + for str in $(printf %s "$iface" |tr ',' '\n'); do + case "$str" in + bridge=*|host_ifname=*) + eval "${str%%=*}=\${str#*=}" ;; + esac done - if [ "$VZHOSTIF" != "$3" ]; then - continue - fi - if [ ! -n "$CTBRIDGE" ]; then - CTBRIDGE=vmbr0 - fi - - echo "Adding interface $VZHOSTIF to bridge $CTBRIDGE on CT0 for CT$VEID" - /sbin/ifconfig $VZHOSTIF 0 - echo 1 > /proc/sys/net/ipv4/conf/$VZHOSTIF/proxy_arp - echo 1 > /proc/sys/net/ipv4/conf/$VZHOSTIF/forwarding - /usr/sbin/brctl addif $CTBRIDGE $VZHOSTIF + [ "$host_ifname" = "$3" ] || + continue + + [ -n "$bridge" ] || + bridge=vmbr0 + + echo "Adding interface $host_ifname to bridge $bridge on CT0 for CT$VEID" + ip addr add 0 dev "$host_ifname" + echo 1 >"/proc/sys/net/ipv4/conf/$host_ifname/proxy_arp" + echo 1 >"/proc/sys/net/ipv4/conf/$host_ifname/forwarding" + brctl addif "$bridge" "$host_ifname" break done