Revision b008fa25
b/.gitignore | ||
---|---|---|
108 | 108 |
/tools/ensure-dirs |
109 | 109 |
/tools/users-setup |
110 | 110 |
/tools/vcluster-setup |
111 |
/tools/vif-ganeti |
|
112 |
/tools/net-common |
|
111 | 113 |
/tools/node-cleanup |
112 | 114 |
/tools/node-daemon-setup |
113 | 115 |
/tools/prepare-node-join |
b/Makefile.am | ||
---|---|---|
196 | 196 |
$(man_MANS) \ |
197 | 197 |
$(manhtml) \ |
198 | 198 |
tools/kvm-ifup \ |
199 |
tools/vif-ganeti \ |
|
200 |
tools/net-common \ |
|
199 | 201 |
tools/users-setup \ |
200 | 202 |
tools/vcluster-setup \ |
201 | 203 |
stamp-directories \ |
... | ... | |
939 | 941 |
myexeclib_SCRIPTS = \ |
940 | 942 |
daemons/daemon-util \ |
941 | 943 |
tools/kvm-ifup \ |
944 |
tools/vif-ganeti \ |
|
945 |
tools/net-common \ |
|
942 | 946 |
$(pkglib_python_scripts) \ |
943 | 947 |
$(HS_MYEXECLIB_PROGS) |
944 | 948 |
|
... | ... | |
974 | 978 |
devel/upload \ |
975 | 979 |
devel/webserver \ |
976 | 980 |
tools/kvm-ifup.in \ |
981 |
tools/vif-ganeti.in \ |
|
982 |
tools/net-common.in \ |
|
977 | 983 |
tools/vcluster-setup.in \ |
978 | 984 |
$(docinput) \ |
979 | 985 |
doc/html \ |
... | ... | |
1384 | 1390 |
sed -f $(REPLACE_VARS_SED) < $< > $@ |
1385 | 1391 |
chmod +x $@ |
1386 | 1392 |
|
1393 |
tools/vif-ganeti: tools/vif-ganeti.in $(REPLACE_VARS_SED) |
|
1394 |
sed -f $(REPLACE_VARS_SED) < $< > $@ |
|
1395 |
chmod +x $@ |
|
1396 |
|
|
1397 |
tools/net-common: tools/net-common.in $(REPLACE_VARS_SED) |
|
1398 |
sed -f $(REPLACE_VARS_SED) < $< > $@ |
|
1399 |
chmod +x $@ |
|
1400 |
|
|
1387 | 1401 |
tools/users-setup: Makefile $(userspecs) |
1388 | 1402 |
set -e; \ |
1389 | 1403 |
{ echo '#!/bin/sh'; \ |
b/tools/kvm-ifup.in | ||
---|---|---|
18 | 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | 19 |
# 02110-1301, USA. |
20 | 20 |
|
21 |
@SHELL_ENV_INIT@ |
|
22 |
|
|
23 |
if [ -z "$INTERFACE" ]; then |
|
24 |
echo "No network interface specified" |
|
25 |
exit 1 |
|
26 |
fi |
|
27 |
|
|
28 |
if [ -z "$MODE" ]; then |
|
29 |
echo "MODE not specified" |
|
30 |
exit 1 |
|
31 |
fi |
|
21 |
source @PKGLIBDIR@/net-common |
|
32 | 22 |
|
33 | 23 |
# Execute the user-supplied network script, if applicable |
34 | 24 |
if [ -x "$CONF_DIR/kvm-vif-bridge" ]; then |
35 | 25 |
exec $CONF_DIR/kvm-vif-bridge |
36 | 26 |
fi |
37 | 27 |
|
38 |
if [ "$MODE" = "bridged" ]; then |
|
39 |
# Fix the autogenerated MAC to have the first octet set to "fe" |
|
40 |
# to discourage the bridge from using the TAP dev's MAC |
|
41 |
FIXED_MAC=$(ip link show $INTERFACE | \ |
|
42 |
awk '{if ($1 == "link/ether") printf("fe%s",substr($2,3,15))}') |
|
43 |
ip link set $INTERFACE address $FIXED_MAC |
|
44 |
|
|
45 |
ip link set $INTERFACE up |
|
46 |
ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu) |
|
47 |
|
|
48 |
# Connect the interface to the bridge |
|
49 |
brctl addif $BRIDGE $INTERFACE |
|
50 |
|
|
51 |
elif [ "$MODE" = "openvswitch" ]; then |
|
52 |
ovs-vsctl add-port ${LINK} $INTERFACE |
|
53 |
|
|
54 |
else |
|
55 |
ip link set $INTERFACE up |
|
56 |
|
|
57 |
if [ -z "$IP" ]; then |
|
58 |
echo "Routed NIC but no IP address specified" |
|
59 |
exit 1 |
|
60 |
fi |
|
61 |
|
|
62 |
# Route traffic targeted at the IP to the interface |
|
63 |
if [ -n "$LINK" ]; then |
|
64 |
while ip rule del dev $INTERFACE; do :; done |
|
65 |
ip rule add dev $INTERFACE table $LINK |
|
66 |
ip route replace $IP table $LINK proto static dev $INTERFACE |
|
67 |
|
|
68 |
else |
|
69 |
ip route replace $IP proto static dev $INTERFACE |
|
70 |
fi |
|
71 |
|
|
72 |
# Allow routing and arp proxying, or ndp proxying (IPv6) |
|
73 |
if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then |
|
74 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp |
|
75 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding |
|
76 |
fi |
|
77 |
|
|
78 |
if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then |
|
79 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp |
|
80 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding |
|
81 |
fi |
|
82 |
fi |
|
28 |
check |
|
29 |
setup_bridge |
|
30 |
setup_ovs |
|
31 |
setup_route |
b/tools/net-common.in | ||
---|---|---|
1 |
#!/bin/bash |
|
2 |
# |
|
3 |
|
|
4 |
# Copyright (C) 2011, 2012, 2013 Google Inc. |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or modify |
|
7 |
# it under the terms of the GNU General Public License as published by |
|
8 |
# the Free Software Foundation; either version 2 of the License, or |
|
9 |
# (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, but |
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
# General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 |
# 02110-1301, USA. |
|
20 |
|
|
21 |
@SHELL_ENV_INIT@ |
|
22 |
|
|
23 |
function check { |
|
24 |
|
|
25 |
if [ -z "$INTERFACE" ]; then |
|
26 |
echo "No network interface specified" |
|
27 |
exit 1 |
|
28 |
fi |
|
29 |
|
|
30 |
if [ -z "$MODE" ]; then |
|
31 |
echo "MODE not specified" |
|
32 |
exit 1 |
|
33 |
fi |
|
34 |
|
|
35 |
} |
|
36 |
|
|
37 |
function fix_mac { |
|
38 |
|
|
39 |
# Fix the autogenerated MAC to have the first octet set to "fe" |
|
40 |
# to discourage the bridge from using the TAP dev's MAC |
|
41 |
FIXED_MAC=$(ip link show $INTERFACE | \ |
|
42 |
awk '{if ($1 == "link/ether") printf("fe%s",substr($2,3,15))}') |
|
43 |
# in case of a vif (xen_netback device) this action is not allowed |
|
44 |
ip link set $INTERFACE address $FIXED_MAC || true |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
function setup_bridge { |
|
49 |
|
|
50 |
if [ "$MODE" = "bridged" ]; then |
|
51 |
fix_mac |
|
52 |
ip link set $INTERFACE up |
|
53 |
ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu) |
|
54 |
|
|
55 |
# Connect the interface to the bridge |
|
56 |
brctl addif $BRIDGE $INTERFACE |
|
57 |
fi |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
function setup_ovs { |
|
62 |
if [ "$MODE" = "openvswitch" ]; then |
|
63 |
ovs-vsctl add-port ${LINK} $INTERFACE |
|
64 |
fi |
|
65 |
} |
|
66 |
|
|
67 |
function setup_route { |
|
68 |
if [ "$MODE" = "openvswitch" ]; then |
|
69 |
ip link set $INTERFACE up |
|
70 |
|
|
71 |
if [ -z "$IP" ]; then |
|
72 |
echo "Routed NIC but no IP address specified" |
|
73 |
exit 1 |
|
74 |
fi |
|
75 |
|
|
76 |
# Route traffic targeted at the IP to the interface |
|
77 |
if [ -n "$LINK" ]; then |
|
78 |
while ip rule del dev $INTERFACE; do :; done |
|
79 |
ip rule add dev $INTERFACE table $LINK |
|
80 |
ip route replace $IP table $LINK proto static dev $INTERFACE |
|
81 |
|
|
82 |
else |
|
83 |
ip route replace $IP proto static dev $INTERFACE |
|
84 |
fi |
|
85 |
|
|
86 |
# Allow routing and arp proxying, or ndp proxying (IPv6) |
|
87 |
if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then |
|
88 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp |
|
89 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding |
|
90 |
fi |
|
91 |
|
|
92 |
if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then |
|
93 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp |
|
94 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding |
|
95 |
fi |
|
96 |
fi |
|
97 |
} |
b/tools/vif-ganeti.in | ||
---|---|---|
1 |
#!/bin/bash |
|
2 |
# |
|
3 |
|
|
4 |
# Copyright (C) 2011, 2012, 2013 Google Inc. |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or modify |
|
7 |
# it under the terms of the GNU General Public License as published by |
|
8 |
# the Free Software Foundation; either version 2 of the License, or |
|
9 |
# (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, but |
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
# General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 |
# 02110-1301, USA. |
|
20 |
|
|
21 |
|
|
22 |
if [ -x "@XEN_CONFIG_DIR@/scripts/vif-custom" ]; then |
|
23 |
exec @XEN_CONFIG_DIR@/scripts/vif-custom $* |
|
24 |
fi |
|
25 |
|
|
26 |
source @PKGLIBDIR@/net-common |
|
27 |
|
|
28 |
dir=$(dirname "$0") |
|
29 |
. "$dir"/vif-common.sh |
|
30 |
|
|
31 |
# taken from older vif-common.sh |
|
32 |
dev=$vif |
|
33 |
dev_=${dev#vif} |
|
34 |
domid=${dev_%.*} |
|
35 |
devid=${dev_#*.} |
|
36 |
domname=$(xm domname $domid) |
|
37 |
|
|
38 |
NIC_DIR=$RUN_DIR/xen-hypervisor/nic |
|
39 |
INTERFACE=$dev |
|
40 |
INSTANCE=$domname |
|
41 |
|
|
42 |
source $NIC_DIR/$domname/$devid |
|
43 |
|
|
44 |
setup_bridge |
|
45 |
setup_ovs |
|
46 |
setup_route |
|
47 |
|
|
48 |
success |
Also available in: Unified diff