-#!/bin/sh
+#!/bin/bash
#
-# Copyright (C) 2011 Google Inc.
+# Copyright (C) 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
-if [ -z "$INTERFACE" ]; then
- echo "No network interface specified"
- exit 1
-fi
-
-if [ -z "$MODE" ]; then
- echo "MODE not specified"
- exit 1
-fi
+source @PKGLIBDIR@/net-common
# Execute the user-supplied network script, if applicable
-if [ -x "@SYSCONFDIR@/ganeti/kvm-vif-bridge" ]; then
- exec @SYSCONFDIR@/ganeti/kvm-vif-bridge
+if [ -x "$CONF_DIR/kvm-vif-bridge" ]; then
+ exec $CONF_DIR/kvm-vif-bridge
fi
-ip link set $INTERFACE up
-
-if [ "$MODE" = "bridged" ]; then
- # Connect the interface to the bridge
- brctl addif $BRIDGE $INTERFACE
-else
- if [ -z "$IP" ]; then
- echo "Routed NIC but no IP address specified"
- exit 1
- fi
-
- # Route traffic targeted at the IP to the interface
- if [ -n "$LINK" ]; then
- while ip rule del dev $INTERFACE; do :; done
- ip rule add dev $INTERFACE table $LINK
- ip route replace $IP table $LINK proto static dev $INTERFACE
-
- else
- ip route replace $IP proto static dev $INTERFACE
- fi
-
- if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then
- echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
- echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding
- fi
-
- if [ -d "/proc/sys/net/ipv6/conf/$INTERFACE" ]; then
- echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
- echo 1 > /proc/sys/net/ipv6/conf/$INTERFACE/forwarding
- fi
-fi
+check
+setup_bridge
+setup_ovs
+setup_route