blob: b8361e487349d7a66b321e6157499be5bb6a2ab9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
From: Dmitry V. Levin <ldv@altlinux.org>
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 <ldv@altlinux.org>
---
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
|