root / tools / kvm-ifup.in @ 1e00889c
History | View | Annotate | Download (2.3 kB)
1 |
#!/bin/bash |
---|---|
2 |
# |
3 |
|
4 |
# Copyright (C) 2011, 2012 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 |
if [ -z "$INTERFACE" ]; then |
22 |
echo "No network interface specified" |
23 |
exit 1 |
24 |
fi |
25 |
|
26 |
if [ -z "$MODE" ]; then |
27 |
echo "MODE not specified" |
28 |
exit 1 |
29 |
fi |
30 |
|
31 |
# Execute the user-supplied network script, if applicable |
32 |
if [ -x "@SYSCONFDIR@/ganeti/kvm-vif-bridge" ]; then |
33 |
exec @SYSCONFDIR@/ganeti/kvm-vif-bridge |
34 |
fi |
35 |
|
36 |
if [ "$MODE" = "bridged" ]; then |
37 |
# Fix the autogenerated MAC to have the first octet set to "fe" |
38 |
# to discourage the bridge from using the TAP dev's MAC |
39 |
FIXED_MAC=$(ip link show $INTERFACE | \ |
40 |
awk '{if ($1 == "link/ether") printf("fe%s",substr($2,3,15))}') |
41 |
ip link set $INTERFACE address $FIXED_MAC |
42 |
|
43 |
ip link set $INTERFACE up |
44 |
ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu) |
45 |
|
46 |
# Connect the interface to the bridge |
47 |
brctl addif $BRIDGE $INTERFACE |
48 |
else |
49 |
ip link set $INTERFACE up |
50 |
|
51 |
if [ -z "$IP" ]; then |
52 |
echo "Routed NIC but no IP address specified" |
53 |
exit 1 |
54 |
fi |
55 |
|
56 |
# Route traffic targeted at the IP to the interface |
57 |
if [ -n "$LINK" ]; then |
58 |
while ip rule del dev $INTERFACE; do :; done |
59 |
ip rule add dev $INTERFACE table $LINK |
60 |
ip route replace $IP table $LINK proto static dev $INTERFACE |
61 |
|
62 |
else |
63 |
ip route replace $IP proto static dev $INTERFACE |
64 |
fi |
65 |
|
66 |
if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then |
67 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp |
68 |
echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding |
69 |
fi |
70 |
|
71 |
if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then |
72 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp |
73 |
echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding |
74 |
fi |
75 |
fi |