4 # Copyright (C) 2011, 2012 Google Inc.
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.
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.
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
23 if [ -z "$INTERFACE" ]; then
24 echo "No network interface specified"
28 if [ -z "$MODE" ]; then
29 echo "MODE not specified"
33 # Execute the user-supplied network script, if applicable
34 if [ -x "$CONF_DIR/kvm-vif-bridge" ]; then
35 exec $CONF_DIR/kvm-vif-bridge
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
45 ip link set $INTERFACE up
46 ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu)
48 # Connect the interface to the bridge
49 brctl addif $BRIDGE $INTERFACE
51 elif [ "$MODE" = "openvswitch" ]; then
52 ovs-vsctl add-port ${LINK} $INTERFACE
55 ip link set $INTERFACE up
58 echo "Routed NIC but no IP address specified"
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
69 ip route replace $IP proto static dev $INTERFACE
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
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