Statistics
| Branch: | Tag: | Revision:

root / tools / kvm-ifup.in @ fcad7225

History | View | Annotate | Download (1.9 kB)

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