On 14:17 Fri 14 Jan     , Apollon Oikonomopoulos wrote:
> On 11:54 Fri 14 Jan     , Guido Trotter wrote:
> > On Thu, Jan 13, 2011 at 11:29 AM, Apollon Oikonomopoulos
> > <[email protected]> wrote:
> > > On 10:52 Thu 13 Jan     , Guido Trotter wrote:
> > >> As for the rest, yes, let's move to iproute2, I can do it, no prob.
> > >> One last thing: the script should check that IP, INTERFACE and
> > >> NIC_MODE are set and abort otherwise (so ganeti can report the error),
> > >> then LGTM.
> > >>
> > >> Thanks,
> > >>
> > >> Guido
> > >
> > > Revised patch follows. I will retain _KVM_NETWORK_SCRIPT in hv_kvm since
> > > it's marked as an ancillary file, however I'm duplicating the path in
> > > kvm-ifup (using SYSCONFDIR though). Is this acceptable?
> > >
> > > --
> > > In order to retain backwards compatibility, we ship the shell script 
> > > previously
> > > generated by _WriteNetScript as a stand-alone script under PKGLIBDIR.
> > >
> > > Signed-off-by: Apollon Oikonomopoulos <[email protected]>
> > > ---
> > 
> > LGTM
> > 
> > (will pull this after the first 2.4 beta, on devel-2.4, does it sound good?)
> > then eventual script improvements and more flexibility will be in
> > design/implementation for 2.5.
> 
> OK with me.
> 
> Thanks,
> Apollon

Caught some typos while testing again for the last resubmission. Fixed 
version follows.

Apollon

--
In order to retain backwards compatibility, we ship the shell script previously
generated by _WriteNetScript as a stand-alone script under PKGLIBDIR.

Signed-off-by: Apollon Oikonomopoulos <[email protected]>
---
 Makefile.am       |    6 +++++
 lib/constants.py  |    1 +
 tools/kvm-ifup.in |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm-ifup.in

diff --git a/Makefile.am b/Makefile.am
index 458545f..4b13c9b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -363,6 +363,7 @@ pkglib_python_scripts = \
 pkglib_SCRIPTS = \
        daemons/daemon-util \
        daemons/ensure-dirs \
+       tools/kvm-ifup \
        $(pkglib_python_scripts)
 
 EXTRA_DIST = \
@@ -382,6 +383,7 @@ EXTRA_DIST = \
        daemons/ganeti-cleaner.in \
        $(pkglib_python_scripts) \
        devel/upload.in \
+       tools/kvm-ifup.in \
        $(docdot) \
        $(docpng) \
        $(docrst) \
@@ -570,6 +572,10 @@ test/daemon-util_unittest.bash: daemons/daemon-util
 
 test/ganeti-cleaner_unittest.bash: daemons/ganeti-cleaner
 
+tools/kvm-ifup: tools/kvm-ifup.in $(REPLACE_VARS_SED)
+       sed -f $(REPLACE_VARS_SED) < $< > $@
+       chmod +x $@
+
 devel/upload: devel/upload.in $(REPLACE_VARS_SED)
        sed -f $(REPLACE_VARS_SED) < $< > $@
        chmod u+x $@
diff --git a/lib/constants.py b/lib/constants.py
index 16fb71d..b876876 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -139,6 +139,7 @@ RAPI_USERS_FILE = DATA_DIR + "/rapi/users"
 QUEUE_DIR = DATA_DIR + "/queue"
 DAEMON_UTIL = _autoconf.PKGLIBDIR + "/daemon-util"
 SETUP_SSH = _autoconf.TOOLSDIR + "/setup-ssh"
+KVM_IFUP = _autoconf.PKGLIBDIR + "/kvm-ifup"
 ETC_HOSTS = "/etc/hosts"
 DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
 ENABLE_FILE_STORAGE = _autoconf.ENABLE_FILE_STORAGE
diff --git a/tools/kvm-ifup.in b/tools/kvm-ifup.in
new file mode 100644
index 0000000..364d3e6
--- /dev/null
+++ b/tools/kvm-ifup.in
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+# Copyright (C) 2011 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# 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
+
+# Execute the user-supplied network script, if applicable
+if [ -x "@SYSCONFDIR@/ganeti/kvm-vif-bridge" ]; then
+       exec @SYSCONFDIR@/ganeti/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
-- 
1.7.1


Reply via email to