From: Justin Pettit Date: Sat, 24 Jan 2009 01:30:16 +0000 (-0800) Subject: Move setting Nicira datapath ID out of kernel. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=056ae92b0c448a2b7349815d6f291a3e6364b360;p=openvswitch Move setting Nicira datapath ID out of kernel. When generating the datapath id/mac address for an OpenFlow device, the kernel checks the DMI for a suitable one in a Nicira UUID. If one is not found, then a random address is generated. This patch makes it so that a random address is always generated. The DMI Nicira UUID check is now done in the init script, which overrides the random address generated when the datapath was created. Ripping code out of the kernel is good. --- diff --git a/datapath/dp_dev.c b/datapath/dp_dev.c index 2c99d602..58a24698 100644 --- a/datapath/dp_dev.c +++ b/datapath/dp_dev.c @@ -5,7 +5,6 @@ #include #include #include -#include #include "datapath.h" #include "dp_dev.h" @@ -123,45 +122,6 @@ static int dp_dev_stop(struct net_device *netdev) return 0; } -/* Check if the DMI UUID contains a Nicira mac address that should be - * used for this interface. The UUID is assumed to be RFC 4122 - * compliant. */ -static void -set_uuid_mac(struct net_device *netdev) -{ - const char *uuid = dmi_get_system_info(DMI_PRODUCT_UUID); - const char *uptr; - uint8_t mac[ETH_ALEN]; - int i; - - if (!uuid || *uuid == '\0' || strlen(uuid) != 36) - return; - - /* We are only interested version 1 UUIDs, since the last six bytes - * are an IEEE 802 MAC address. */ - if (uuid[14] != '1') - return; - - /* Pull out the embedded MAC address. The kernel's sscanf doesn't - * support field widths on hex digits, so we use this hack. */ - uptr = uuid + 24; - for (i=0; idev_addr, mac, ETH_ALEN); -} - static void dp_getinfo(struct net_device *dev, struct ethtool_drvinfo *info) { strcpy(info->driver, "openflow"); @@ -233,12 +193,6 @@ int dp_dev_setup(struct datapath *dp, const char *dp_name) return err; } - /* For the first datapath, we check the DMI UUID to see if a Nicira - * mac address is available to use instead of the random one just - * generated. */ - if (dp->dp_idx == 0) - set_uuid_mac(netdev); - dp_dev = dp_dev_priv(netdev); dp_dev->dp = dp; skb_queue_head_init(&dp_dev->xmit_queue); diff --git a/debian/openflow-switch.init b/debian/openflow-switch.init index 8ee19cd6..cd518a71 100755 --- a/debian/openflow-switch.init +++ b/debian/openflow-switch.init @@ -25,6 +25,8 @@ DESC=secchan test -x $DAEMON || exit 0 +NICIRA_OUI="002320" + LOGDIR=/var/log/openflow PIDFILE=/var/run/$NAME.pid DHCLIENT_PIDFILE=/var/run/dhclient.of0.pid @@ -271,6 +273,20 @@ case "$1" in xx='[0-9abcdefABCDEF][0-9abcdefABCDEF]' case $DATAPATH_ID in '') + # Check if the DMI System UUID contains a Nicira mac address + # that should be used for this datapath. The UUID is assumed + # to be RFC 4122 compliant. + DMIDECODE=`which dmidecode` + if [ -n $DMIDECODE ]; then + UUID_MAC=`$DMIDECODE -s system-uuid | cut -d'-' -f 5` + case $UUID_MAC in + $NICIRA_OUI*) + ifconfig of0 down + must_succeed "Setting of0 MAC address to $UUID_MAC" ifconfig of0 hw ether $UUID_MAC + ifconfig of0 up + ;; + esac + fi ;; $xx:$xx:$xx:$xx:$xx:$xx) ifconfig of0 down diff --git a/debian/openflow-switch.template b/debian/openflow-switch.template index 2b78b6ba..f3f641e8 100644 --- a/debian/openflow-switch.template +++ b/debian/openflow-switch.template @@ -159,9 +159,10 @@ DAEMON_OPTS="" # DATAPATH_ID: Identifier for this switch. # -# By default, the switch generates a new, random datapath ID every time -# it starts up. By setting this value, the datapath ID will be consistent -# from one run to the next. +# By default, the switch checks if the DMI System UUID contains a Nicira +# mac address to use as a datapath ID. If not, then the switch generates +# a new, random datapath ID every time it starts up. By setting this +# value, the supplied datapath ID will always be used. # # Set DATAPATH_ID to a MAC address in the form XX:XX:XX:XX:XX:XX where each # X is a hexadecimal digit (0-9 or a-f).