Statistics
| Branch: | Tag: | Revision:

root / tools / kvm-ifup.in @ 82989b8d

History | View | Annotate | Download (2.3 kB)

1 1817dca9 Michael Hanselmann
#!/bin/bash
2 f299ca21 Michael Hanselmann
#
3 26916aad Apollon Oikonomopoulos
4 1817dca9 Michael Hanselmann
# Copyright (C) 2011, 2012 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 1e00889c Iustin Pop
  echo "No network interface specified"
23 1e00889c Iustin Pop
  exit 1
24 26916aad Apollon Oikonomopoulos
fi
25 26916aad Apollon Oikonomopoulos
26 26916aad Apollon Oikonomopoulos
if [ -z "$MODE" ]; then
27 1e00889c Iustin Pop
  echo "MODE not specified"
28 1e00889c Iustin Pop
  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 1e00889c Iustin Pop
  exec @SYSCONFDIR@/ganeti/kvm-vif-bridge
34 26916aad Apollon Oikonomopoulos
fi
35 26916aad Apollon Oikonomopoulos
36 99e92fa0 Michael Hanselmann
if [ "$MODE" = "bridged" ]; then
37 1e00889c Iustin Pop
  # Fix the autogenerated MAC to have the first octet set to "fe"
38 1e00889c Iustin Pop
  # to discourage the bridge from using the TAP dev's MAC
39 1e00889c Iustin Pop
  FIXED_MAC=$(ip link show $INTERFACE | \
40 1e00889c Iustin Pop
    awk '{if ($1 == "link/ether") printf("fe%s",substr($2,3,15))}')
41 1e00889c Iustin Pop
  ip link set $INTERFACE address $FIXED_MAC
42 be3f52f3 Simon Deziel
43 1e00889c Iustin Pop
  ip link set $INTERFACE up
44 1e00889c Iustin Pop
  ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu)
45 3bdca55d Andrea Spadaccini
46 1e00889c Iustin Pop
  # Connect the interface to the bridge
47 1e00889c Iustin Pop
  brctl addif $BRIDGE $INTERFACE
48 26916aad Apollon Oikonomopoulos
else
49 1e00889c Iustin Pop
  ip link set $INTERFACE up
50 be3f52f3 Simon Deziel
51 1e00889c Iustin Pop
  if [ -z "$IP" ]; then
52 1e00889c Iustin Pop
    echo "Routed NIC but no IP address specified"
53 1e00889c Iustin Pop
    exit 1
54 1e00889c Iustin Pop
  fi
55 26916aad Apollon Oikonomopoulos
56 1e00889c Iustin Pop
  # Route traffic targeted at the IP to the interface
57 1e00889c Iustin Pop
  if [ -n "$LINK" ]; then
58 1e00889c Iustin Pop
    while ip rule del dev $INTERFACE; do :; done
59 1e00889c Iustin Pop
    ip rule add dev $INTERFACE table $LINK
60 1e00889c Iustin Pop
    ip route replace $IP table $LINK proto static dev $INTERFACE
61 26916aad Apollon Oikonomopoulos
62 1e00889c Iustin Pop
  else
63 1e00889c Iustin Pop
    ip route replace $IP proto static dev $INTERFACE
64 1e00889c Iustin Pop
  fi
65 26916aad Apollon Oikonomopoulos
66 1e00889c Iustin Pop
  if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then
67 1e00889c Iustin Pop
    echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
68 1e00889c Iustin Pop
    echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding
69 1e00889c Iustin Pop
  fi
70 26916aad Apollon Oikonomopoulos
71 1e00889c Iustin Pop
  if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then
72 1e00889c Iustin Pop
    echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
73 1e00889c Iustin Pop
    echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding
74 1e00889c Iustin Pop
  fi
75 26916aad Apollon Oikonomopoulos
fi