4 # Copyright (C) 2011, 2012, 2013 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
25 if [ -z "$INTERFACE" ]; then
26 echo "No network interface specified"
30 if [ -z "$MODE" ]; then
31 echo "MODE not specified"
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 # in case of a vif (xen_netback device) this action is not allowed
44 ip link set $INTERFACE address $FIXED_MAC || true
48 function setup_bridge {
50 if [ "$MODE" = "bridged" ]; then
52 ip link set $INTERFACE up
53 ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu)
55 # Connect the interface to the bridge
56 brctl addif $BRIDGE $INTERFACE
62 if [ "$MODE" = "openvswitch" ]; then
63 ovs-vsctl add-port ${LINK} $INTERFACE
67 function setup_route {
68 if [ "$MODE" = "openvswitch" ]; then
69 ip link set $INTERFACE up
72 echo "Routed NIC but no IP address specified"
76 # Route traffic targeted at the IP to the interface
77 if [ -n "$LINK" ]; then
78 while ip rule del dev $INTERFACE; do :; done
79 ip rule add dev $INTERFACE table $LINK
80 ip route replace $IP table $LINK proto static dev $INTERFACE
83 ip route replace $IP proto static dev $INTERFACE
86 # Allow routing and arp proxying, or ndp proxying (IPv6)
87 if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then
88 echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
89 echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding
92 if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then
93 echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
94 echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding