Statistics
| Branch: | Tag: | Revision:

root / tools / kvm-ifup.in @ 7eda951b

History | View | Annotate | Download (1.9 kB)

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