root / tools / kvm-ifup.in @ 756df409
History | View | Annotate | Download (1.9 kB)
1 |
#!/bin/sh |
---|---|
2 |
|
3 |
# Copyright (C) 2011 Google Inc. |
4 |
# |
5 |
# This program is free software; you can redistribute it and/or modify |
6 |
# it under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 2 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# This program is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 |
# General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with this program; if not, write to the Free Software |
17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 |
# 02110-1301, USA. |
19 |
|
20 |
if [ -z "$INTERFACE" ]; then |
21 |
echo "No network interface specified" |
22 |
exit 1 |
23 |
fi |
24 |
|
25 |
if [ -z "$MODE" ]; then |
26 |
echo "MODE not specified" |
27 |
exit 1 |
28 |
fi |
29 |
|
30 |
# Execute the user-supplied network script, if applicable |
31 |
if [ -x "@SYSCONFDIR@/ganeti/kvm-vif-bridge" ]; then |
32 |
exec @SYSCONFDIR@/ganeti/kvm-vif-bridge |
33 |
fi |
34 |
|
35 |
ip link set $INTERFACE up |
36 |
|
37 |
if [ "$MODE" = "bridged" ]; then |
38 |
# Connect the interface to the bridge |
39 |
brctl addif $BRIDGE $INTERFACE |
40 |
else |
41 |
if [ -z "$IP" ]; then |
42 |
echo "Routed NIC but no IP address specified" |
43 |
exit 1 |
44 |
fi |
45 |
|
46 |
# Route traffic targeted at the IP to the interface |
47 |
if [ -n "$LINK" ]; then |
48 |
while ip rule del dev $INTERFACE; do :; done |
49 |
ip rule add dev $INTERFACE table $LINK |
50 |
ip route replace $IP table $LINK proto static dev $INTERFACE |
51 |
|
52 |
else |
53 |
ip route replace $IP proto static dev $INTERFACE |
54 |
fi |
55 |
|
56 |
if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then |
57 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp |
58 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding |
59 |
fi |
60 |
|
61 |
if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then |
62 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp |
63 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding |
64 |
fi |
65 |
fi |