3 # Copyright (C) 2008,2009 Citrix Systems, Inc.
4 # Copyright (C) 2009 Nicira Networks, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published
8 # by the Free Software Foundation; version 2.1 only. with the special
9 # exception on linking described in file LICENSE.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
16 # CA-23900: Warning: when VIFs are added to windows guests with PV drivers the backend vif device is registered,
17 # unregistered and then registered again. This causes the udev event to fire twice and this script runs twice.
18 # Since the first invocation of the script races with the device unregistration, spurious errors are possible
19 # which will be logged but are safe to ignore since the second script invocation should complete the operation.
20 # Note that each script invocation is run synchronously from udev and so the scripts don't race with each other.
22 # Keep other-config/ keys in sync with device.ml:vif_udev_keys
24 cfg_mod="/root/vswitch/bin/ovs-cfg-mod"
25 dump_vif_details="/root/vswitch/scripts/dump-vif-details"
26 service="/sbin/service"
28 TYPE=`echo ${XENBUS_PATH} | cut -f 2 -d '/'`
29 DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
30 DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
32 XAPI=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
33 HOTPLUG=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
34 PRIVATE=/xapi/${DOMID}/private/${TYPE}/${DEVID}
41 local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous")
42 if [ $? -eq 0 -a -n "${arg}" ] ; then
44 true|on) logger -t script-vif "${vif}: Promiscuous ports are not supported via vSwitch." ;;
53 local arg=$(xenstore-read "${PRIVATE}/other-config/ethtool-${opt}")
54 if [ $? -eq 0 -a -n "${arg}" ] ; then
56 true|on) /sbin/ethtool -K "${vif}" "${opt}" on ;;
57 false|off) /sbin/ethtool -K "${vif}" "${opt}" off ;;
58 *) logger -t scripts-vif "Unknown ethtool argument ${opt}=${arg} on ${vif}/${VIFUUID}" ;;
65 local mtu=$(xenstore-read "${PRIVATE}/MTU")
66 if [ $? -eq 0 -a -n "${mtu}" ]; then
67 echo "${mtu}" > /sys/class/net/${vif}/mtu
73 local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
74 if [ $? -ne 0 -o -z "${address}" ]; then
75 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore"
77 local bridge=$(xenstore-read "${PRIVATE}/bridge")
78 if [ $? -ne 0 -o -z "${bridge}" ]; then
79 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore"
81 logger -t scripts-vif "Adding ${vif} to ${bridge} with address ${address}"
84 if [ -e "/var/lib/openvswitch/br-$bridge" ]; then
85 . "/var/lib/openvswitch/br-$bridge"
86 if [ -n "$VLAN_SLAVE" -a -n "$VLAN_VID" ]; then
88 vid="--add=vlan.$vif.tag=$VLAN_VID"
92 ${IP} link set "${vif}" down || logger -t scripts-vif "Failed to ip link set ${vif} down"
93 ${IP} link set "${vif}" arp off || logger -t scripts-vif "Failed to ip link set ${vif} arp off"
94 ${IP} link set "${vif}" multicast off || logger -t scripts-vif "Failed to ip link set ${vif} multicast off"
95 ${IP} link set "${vif}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${vif} address ${address}"
96 ${IP} addr flush "${vif}" || logger -t scripts-vif "Failed to ip addr flush ${vif}"
98 local vif_details=$($dump_vif_details $DOMID $DEVID)
99 if [ $? -ne 0 -o -z "${vif_details}" ]; then
100 logger -t scripts-vif "Failed to retrieve vif details for vswitch"
103 $cfg_mod -F /etc/ovs-vswitchd.conf \
104 --del-match="bridge.*.port=$vif" \
105 --del-match="vlan.$vif.trunks=*" \
106 --del-match="vlan.$vif.tag=*" \
107 --del-match="port.$vif.[!0-9]*" \
108 --add="bridge.$bridge.port=$vif" \
110 $service vswitch reload
112 ${IP} link set "${vif}" up || logger -t scripts-vif "Failed to ip link set ${vif} up"
115 echo Called as "$@" "$TYPE" "$DOMID" "$DEVID" | logger -t scripts-vif
129 xenstore-write "${HOTPLUG}/vif" "${vif}"
130 xenstore-write "${HOTPLUG}/hotplug" "online"
132 # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
133 xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
137 xenstore-rm "${HOTPLUG}/hotplug"
138 vif=vif${DOMID}.${DEVID}
139 logger -t scripts-vif "${vif} has been removed"
140 $cfg_mod -vANY:console:emer -F /etc/ovs-vswitchd.conf \
141 --del-match="bridge.*.port=${vif}" \
142 --del-match="vlan.${vif}.trunks=*" \
143 --del-match="vlan.${vif}.tag=*" \
144 --del-match="port.${vif}.[!0-9]*" -c
145 $service vswitch reload