Statistics
| Branch: | Tag: | Revision:

root / tools / kvm-ifup.in @ 6e3bf290

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
@SHELL_ENV_INIT@
22

    
23
if [ -z "$INTERFACE" ]; then
24
  echo "No network interface specified"
25
  exit 1
26
fi
27

    
28
if [ -z "$MODE" ]; then
29
  echo "MODE not specified"
30
  exit 1
31
fi
32

    
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
36
fi
37

    
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
44

    
45
  ip link set $INTERFACE up
46
  ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu)
47

    
48
  # Connect the interface to the bridge
49
  brctl addif $BRIDGE $INTERFACE
50
else
51
  ip link set $INTERFACE up
52

    
53
  if [ -z "$IP" ]; then
54
    echo "Routed NIC but no IP address specified"
55
    exit 1
56
  fi
57

    
58
  # Route traffic targeted at the IP to the interface
59
  if [ -n "$LINK" ]; then
60
    while ip rule del dev $INTERFACE; do :; done
61
    ip rule add dev $INTERFACE table $LINK
62
    ip route replace $IP table $LINK proto static dev $INTERFACE
63

    
64
  else
65
    ip route replace $IP proto static dev $INTERFACE
66
  fi
67

    
68
  if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then
69
    echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
70
    echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding
71
  fi
72

    
73
  if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then
74
    echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
75
    echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding
76
  fi
77
fi