Revision 4855760b

b/.gitignore
104 104
/tools/ensure-dirs
105 105
/tools/users-setup
106 106
/tools/vcluster-setup
107
/tools/vif-ganeti
108
/tools/net-common
107 109
/tools/node-cleanup
108 110
/tools/node-daemon-setup
109 111
/tools/prepare-node-join
b/Makefile.am
197 197
	$(man_MANS) \
198 198
	$(manhtml) \
199 199
	tools/kvm-ifup \
200
	tools/vif-ganeti \
201
	tools/net-common \
200 202
	tools/users-setup \
201 203
	tools/vcluster-setup \
202 204
	stamp-directories \
......
938 940
myexeclib_SCRIPTS = \
939 941
	daemons/daemon-util \
940 942
	tools/kvm-ifup \
943
	tools/vif-ganeti \
944
	tools/net-common \
941 945
	$(pkglib_python_scripts) \
942 946
	$(HS_MYEXECLIB_PROGS)
943 947

  
......
973 977
	devel/upload \
974 978
	devel/webserver \
975 979
	tools/kvm-ifup.in \
980
	tools/vif-ganeti.in \
981
	tools/net-common.in \
976 982
	tools/users-setup.in \
977 983
	tools/vcluster-setup.in \
978 984
	$(docinput) \
......
1395 1401
	sed -f $(REPLACE_VARS_SED) < $< > $@
1396 1402
	chmod +x $@
1397 1403

  
1404
tools/vif-ganeti: tools/vif-ganeti.in $(REPLACE_VARS_SED)
1405
	sed -f $(REPLACE_VARS_SED) < $< > $@
1406
	chmod +x $@
1407

  
1408
tools/net-common: tools/net-common.in $(REPLACE_VARS_SED)
1409
	sed -f $(REPLACE_VARS_SED) < $< > $@
1410
	chmod +x $@
1411

  
1398 1412
tools/users-setup: tools/users-setup.in $(REPLACE_VARS_SED)
1399 1413
	sed -f $(REPLACE_VARS_SED) < $< > $@
1400 1414
	chmod +x $@
b/tools/kvm-ifup.in
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 19
# 02110-1301, USA.
20 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
21
source @PKGLIBDIR@/net-common
32 22

  
33 23
# Execute the user-supplied network script, if applicable
34 24
if [ -x "$CONF_DIR/kvm-vif-bridge" ]; then
35 25
  exec $CONF_DIR/kvm-vif-bridge
36 26
fi
37 27

  
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

  
51
elif [ "$MODE" = "openvswitch" ]; then
52
  ovs-vsctl add-port ${LINK} $INTERFACE
53

  
54
else
55
  ip link set $INTERFACE up
56

  
57
  if [ -z "$IP" ]; then
58
    echo "Routed NIC but no IP address specified"
59
    exit 1
60
  fi
61

  
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
67

  
68
  else
69
    ip route replace $IP proto static dev $INTERFACE
70
  fi
71

  
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
76
  fi
77

  
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
81
  fi
82
fi
28
check
29
setup_bridge
30
setup_ovs
31
setup_route
b/tools/net-common.in
1
#!/bin/bash
2
#
3

  
4
# Copyright (C) 2011, 2012, 2013 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
function check {
24

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

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

  
35
}
36

  
37
function fix_mac {
38

  
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
45

  
46
}
47

  
48
function setup_bridge {
49

  
50
  if [ "$MODE" = "bridged" ]; then
51
    fix_mac
52
    ip link set $INTERFACE up
53
    ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu)
54

  
55
    # Connect the interface to the bridge
56
    brctl addif $BRIDGE $INTERFACE
57
  fi
58

  
59
}
60

  
61
function setup_ovs {
62
  if [ "$MODE" = "openvswitch" ]; then
63
    ovs-vsctl add-port ${LINK} $INTERFACE
64
  fi
65
}
66

  
67
function setup_route {
68
  if [ "$MODE" = "openvswitch" ]; then
69
    ip link set $INTERFACE up
70

  
71
    if [ -z "$IP" ]; then
72
      echo "Routed NIC but no IP address specified"
73
      exit 1
74
    fi
75

  
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
81

  
82
    else
83
      ip route replace $IP proto static dev $INTERFACE
84
    fi
85

  
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
90
    fi
91

  
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
95
    fi
96
  fi
97
}
b/tools/vif-ganeti.in
1
#!/bin/bash
2
#
3

  
4
# Copyright (C) 2011, 2012, 2013 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

  
22
if [ -x "@XEN_CONFIG_DIR@/scripts/vif-custom" ]; then
23
	exec @XEN_CONFIG_DIR@/scripts/vif-custom $*
24
fi
25

  
26
source @PKGLIBDIR@/net-common
27

  
28
dir=$(dirname "$0")
29
. "$dir"/vif-common.sh
30

  
31
# taken from older vif-common.sh
32
dev=$vif
33
dev_=${dev#vif}
34
domid=${dev_%.*}
35
devid=${dev_#*.}
36
domname=$(xm domname $domid)
37

  
38
NIC_DIR=$RUN_DIR/xen-hypervisor/nic
39
INTERFACE=$dev
40
INSTANCE=$domname
41

  
42
source $NIC_DIR/$domname/$devid
43

  
44
setup_bridge
45
setup_ovs
46
setup_route
47

  
48
success

Also available in: Unified diff