Force tap's MAC prefix to "fe"
[ganeti-local] / tools / kvm-ifup.in
index 2ff8ccb..a5e8c1b 100644 (file)
@@ -1,7 +1,7 @@
-#!/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
@@ -33,14 +33,20 @@ if [ -x "@SYSCONFDIR@/ganeti/kvm-vif-bridge" ]; then
        exec @SYSCONFDIR@/ganeti/kvm-vif-bridge
 fi
 
-ip link set $INTERFACE up
-
 if [ "$MODE" = "bridged" ]; then
+       # Fix the autogenerated MAC to have the first octet set to "fe"
+       # to discourage the bridge from using the TAP dev's MAC
+       FIXED_MAC=$(ip link show $INTERFACE | awk '{if ($1 == "link/ether") printf("fe%s",substr($2,3,15))}')
+       ip link set $INTERFACE address $FIXED_MAC
+
+       ip link set $INTERFACE up
        ip link set $INTERFACE mtu $(</sys/class/net/${BRIDGE}/mtu)
 
        # Connect the interface to the bridge
        brctl addif $BRIDGE $INTERFACE
 else
+       ip link set $INTERFACE up
+
        if [ -z "$IP" ]; then
                echo "Routed NIC but no IP address specified"
                exit 1