3 # Copyright (C) 2008,2009 Citrix Systems, Inc. All rights reserved.
4 # Copyright (C) 2009 Nicira Networks, Inc.
6 # CA-23900: Warning: when VIFs are added to windows guests with PV drivers the backend vif device is registered,
7 # unregistered and then registered again. This causes the udev event to fire twice and this script runs twice.
8 # Since the first invocation of the script races with the device unregistration, spurious errors are possible
9 # which will be logged but are safe to ignore since the second script invocation should complete the operation.
10 # Note that each script invocation is run synchronously from udev and so the scripts don't race with each other.
12 # Keep other-config/ keys in sync with device.ml:vif_udev_keys
14 cfg_mod
="/root/vswitch/bin/ovs-cfg-mod"
15 dump_vif_details
="/root/vswitch/scripts/dump-vif-details"
16 service
="/sbin/service"
18 TYPE
=`echo ${XENBUS_PATH} | cut -f 2 -d '/'`
19 DOMID
=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
20 DEVID
=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
22 XAPI
=/xapi
/${DOMID}/hotplug/${TYPE}/${DEVID}
23 HOTPLUG
=/xapi
/${DOMID}/hotplug/${TYPE}/${DEVID}
24 PRIVATE
=/xapi
/${DOMID}/private/${TYPE}/${DEVID}
31 local arg
=$
(xenstore-read
"${PRIVATE}/other-config/promiscuous")
32 if [ $?
-eq 0 -a -n "${arg}" ] ; then
34 true|on
) logger
-t script-vif
"${vif}: Promiscuous ports are not supported via vSwitch." ;;
43 local arg
=$
(xenstore-read
"${PRIVATE}/other-config/ethtool-${opt}")
44 if [ $?
-eq 0 -a -n "${arg}" ] ; then
46 true|on
) /sbin
/ethtool
-K "${vif}" "${opt}" on
;;
47 false|off
) /sbin
/ethtool
-K "${vif}" "${opt}" off
;;
48 *) logger
-t scripts-vif
"Unknown ethtool argument ${opt}=${arg} on ${vif}/${VIFUUID}" ;;
55 local mtu
=$
(xenstore-read
"${PRIVATE}/MTU")
56 if [ $?
-eq 0 -a -n "${mtu}" ]; then
57 echo "${mtu}" > /sys
/class
/net
/${vif}/mtu
63 local address
=$
(xenstore-read
"${PRIVATE}/bridge-MAC")
64 if [ $?
-ne 0 -o -z "${address}" ]; then
65 logger
-t scripts-vif
"Failed to read ${PRIVATE}/bridge-MAC from xenstore"
67 local bridge
=$
(xenstore-read
"${PRIVATE}/bridge")
68 if [ $?
-ne 0 -o -z "${bridge}" ]; then
69 logger
-t scripts-vif
"Failed to read ${PRIVATE}/bridge from xenstore"
71 logger
-t scripts-vif
"Adding ${vif} to ${bridge} with address ${address}"
74 if [ -e "/var/lib/openvswitch/br-$bridge" ]; then
75 .
"/var/lib/openvswitch/br-$bridge"
76 if [ -n "$VLAN_SLAVE" -a -n "$VLAN_VID" ]; then
78 vid
="--add=vlan.$vif.tag=$VLAN_VID"
82 ${IP} link set "${vif}" down || logger -t scripts-vif "Failed to ip link set ${vif} down
"
83 ${IP} link set "${vif}" arp off || logger -t scripts-vif "Failed to ip link set ${vif} arp off"
84 ${IP} link set "${vif}" multicast off || logger -t scripts-vif "Failed to ip link set ${vif} multicast off
"
85 ${IP} link set "${vif}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${vif} address ${address}"
86 ${IP} addr flush "${vif}" || logger -t scripts-vif "Failed to ip addr flush ${vif}"
88 local vif_details=$($dump_vif_details $DOMID $DEVID)
89 if [ $? -ne 0 -o -z "${vif_details}" ]; then
90 logger -t scripts-vif "Failed to retrieve vif details
for vswitch
"
93 $cfg_mod -F /etc/ovs-vswitchd.conf \
94 --del-match="bridge.
*.port
=$vif" \
95 --del-match="vlan.
$vif.
[!0-9]*" \
96 --del-match="port.
$vif.
[!0-9]*" \
97 --add="bridge.
$bridge.port
=$vif" \
99 $service vswitch reload
101 ${IP} link set "${vif}" up || logger -t scripts-vif "Failed to ip link set ${vif} up"
104 echo Called as
"$@" "$TYPE" "$DOMID" "$DEVID" | logger
-t scripts-vif
118 xenstore-write
"${HOTPLUG}/vif" "${vif}"
119 xenstore-write
"${HOTPLUG}/hotplug" "online"
121 # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
122 xenstore-write
"/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
126 xenstore-rm
"${HOTPLUG}/hotplug"
127 vif
=vif
${DOMID}.
${DEVID}
128 logger
-t scripts-vif
"${vif} has been removed"
129 $cfg_mod -vANY:console
:emer
-F /etc
/ovs-vswitchd.conf \
130 --del-match="bridge.*.port=${vif}" \
131 --del-match="vlan.${vif}.[!0-9]*" \
132 --del-match="port.${vif}.[!0-9]*" -c
133 $service vswitch reload