3 # This file is based on /etc/xensource/script/vif from Citrix XenServer 5.0.0.
4 # The original file did not contain a copyright notice or license statement.
6 # Copyright (C) 2009 Nicira Networks, Inc.
8 # CA-23900: Warning: when VIFs are added to windows guests with PV drivers the backend vif device is registered,
9 # unregistered and then registered again. This causes the udev event to fire twice and this script runs twice.
10 # Since the first invocation of the script races with the device unregistration, spurious errors are possible
11 # which will be logged but are safe to ignore since the second script invocation should complete the operation.
12 # Note that each script invocation is run synchronously from udev and so the scripts don't race with each other.
14 # Keep other-config/ keys in sync with device.ml:vif_udev_keys
16 cfg_mod="/root/vswitch/bin/ovs-cfg-mod"
17 dump_vif_details="/root/vswitch/scripts/dump-vif-details"
18 service="/sbin/service"
20 TYPE=`echo ${XENBUS_PATH} | cut -f 2 -d '/'`
21 DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
22 DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
24 XAPI=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
25 HOTPLUG=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
26 PRIVATE=/xapi/${DOMID}/private/${TYPE}/${DEVID}
33 local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous")
34 if [ $? -eq 0 -a -n "${arg}" ] ; then
36 true|on) echo 1 > /sys/class/net/${vif}/brport/promisc ;;
37 *) echo 0 > /sys/class/net/${vif}/brport/promisc ;;
45 local arg=$(xenstore-read "${PRIVATE}/other-config/ethtool-${opt}")
46 if [ $? -eq 0 -a -n "${arg}" ] ; then
48 true|on) /sbin/ethtool -K "${vif}" "${opt}" on ;;
49 false|off) /sbin/ethtool -K "${vif}" "${opt}" off ;;
50 *) logger -t scripts-vif "Unknown ethtool argument ${opt}=${arg} on ${vif}/${VIFUUID}" ;;
57 local mtu=$(xenstore-read "${PRIVATE}/MTU")
58 if [ $? -eq 0 -a -n "${mtu}" ]; then
59 echo "${mtu}" > /sys/class/net/${vif}/mtu
65 local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
66 if [ $? -ne 0 -o -z "${address}" ]; then
67 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore"
69 local bridge=$(xenstore-read "${PRIVATE}/bridge")
70 if [ $? -ne 0 -o -z "${bridge}" ]; then
71 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore"
73 logger -t scripts-vif "Adding ${vif} to ${bridge} with address ${address}"
76 if [ -e "/etc/openvswitch/br-$bridge" ]; then
77 . "/etc/openvswitch/br-$bridge"
78 if [ -n "$VLAN_SLAVE" -a -n "$VLAN_VID" ]; then
80 vid="--add=vlan.$vif.tag=$VLAN_VID"
84 ${IP} link set "${vif}" down || logger -t scripts-vif "Failed to ip link set ${vif} down"
85 ${IP} link set "${vif}" arp off || logger -t scripts-vif "Failed to ip link set ${vif} arp off"
86 ${IP} link set "${vif}" multicast off || logger -t scripts-vif "Failed to ip link set ${vif} multicast off"
87 ${IP} link set "${vif}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${vif} address ${address}"
88 ${IP} addr flush "${vif}" || logger -t scripts-vif "Failed to ip addr flush ${vif}"
90 local vif_details=$($dump_vif_details $DOMID $DEVID)
91 if [ $? -ne 0 -o -z "${vif_details}" ]; then
92 logger -t scripts-vif "Failed to retrieve vif details for vswitch"
95 $cfg_mod -F /etc/ovs-vswitchd.conf \
96 --del-match="bridge.*.port=$vif" \
97 --del-match="vlan.$vif.[!0-9]*" \
98 --del-match="port.$vif.[!0-9]*" \
99 --add="bridge.$bridge.port=$vif" \
101 $service vswitch reload
103 ${IP} link set "${vif}" up || logger -t scripts-vif "Failed to ip link set ${vif} up"
106 echo Called as "$@" "$TYPE" "$DOMID" "$DEVID" | logger -t scripts-vif
120 xenstore-write "${HOTPLUG}/vif" "${vif}"
121 xenstore-write "${HOTPLUG}/hotplug" "online"
123 # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
124 xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
128 xenstore-rm "${HOTPLUG}/hotplug"
129 vif=vif${DOMID}.${DEVID}
130 logger -t scripts-vif "${vif} has been removed"
131 $cfg_mod -vANY:console:emer -F /etc/ovs-vswitchd.conf \
132 --del-match="bridge.*.port=${vif}" \
133 --del-match="vlan.${vif}.[!0-9]*" \
134 --del-match="port.${vif}.[!0-9]*" -c
135 $service vswitch reload