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="/usr/bin/ovs-cfg-mod"
15 vsctl="/usr/bin/ovs-vsctl"
16 dump_vif_details="/usr/share/vswitch/scripts/dump-vif-details"
17 service="/sbin/service"
19 TYPE=`echo ${XENBUS_PATH} | cut -f 2 -d '/'`
20 DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
21 DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
23 XAPI=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
24 HOTPLUG=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
25 PRIVATE=/xapi/${DOMID}/private/${TYPE}/${DEVID}
32 local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous")
33 if [ $? -eq 0 -a -n "${arg}" ] ; then
35 true|on) logger -t script-vif "${vif}: Promiscuous ports are not supported via vSwitch." ;;
44 local arg=$(xenstore-read "${PRIVATE}/other-config/ethtool-${opt}")
45 if [ $? -eq 0 -a -n "${arg}" ] ; then
47 true|on) /sbin/ethtool -K "${vif}" "${opt}" on ;;
48 false|off) /sbin/ethtool -K "${vif}" "${opt}" off ;;
49 *) logger -t scripts-vif "Unknown ethtool argument ${opt}=${arg} on ${vif}/${VIFUUID}" ;;
56 local mtu=$(xenstore-read "${PRIVATE}/MTU")
57 if [ $? -eq 0 -a -n "${mtu}" ]; then
58 echo "${mtu}" > /sys/class/net/${vif}/mtu
64 local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
65 if [ $? -ne 0 -o -z "${address}" ]; then
66 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore"
68 local bridge=$(xenstore-read "${PRIVATE}/bridge")
69 if [ $? -ne 0 -o -z "${bridge}" ]; then
70 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore"
72 logger -t scripts-vif "Adding ${vif} to ${bridge} with address ${address}"
74 local VLAN_ID=$($vsctl br-to-vlan $bridge)
76 if [ "$VLAN_ID" -ne 0 ] ; then
77 bridge=$($vsctl br-to-parent $bridge)
78 vid="--add=vlan.${dev}.tag=${VLAN_ID}"
81 ${IP} link set "${vif}" down || logger -t scripts-vif "Failed to ip link set ${vif} down"
82 ${IP} link set "${vif}" arp off || logger -t scripts-vif "Failed to ip link set ${vif} arp off"
83 ${IP} link set "${vif}" multicast off || logger -t scripts-vif "Failed to ip link set ${vif} multicast off"
84 ${IP} link set "${vif}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${vif} address ${address}"
85 ${IP} addr flush "${vif}" || logger -t scripts-vif "Failed to ip addr flush ${vif}"
87 local vif_details=$($dump_vif_details $DOMID $DEVID)
88 if [ $? -ne 0 -o -z "${vif_details}" ]; then
89 logger -t scripts-vif "Failed to retrieve vif details for vswitch"
92 $cfg_mod -F /etc/ovs-vswitchd.conf \
93 --del-match="bridge.*.port=$vif" \
94 --del-match="vlan.$vif.[!0-9]*" \
95 --del-match="port.$vif.[!0-9]*" \
96 --add="bridge.$bridge.port=$vif" \
98 $service vswitch reload
100 ${IP} link set "${vif}" up || logger -t scripts-vif "Failed to ip link set ${vif} up"
103 echo Called as "$@" "$TYPE" "$DOMID" "$DEVID" | logger -t scripts-vif
117 xenstore-write "${HOTPLUG}/vif" "${vif}"
118 xenstore-write "${HOTPLUG}/hotplug" "online"
120 # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
121 xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
125 xenstore-rm "${HOTPLUG}/hotplug"
126 vif=vif${DOMID}.${DEVID}
127 logger -t scripts-vif "${vif} has been removed"
128 $cfg_mod -vANY:console:emer -F /etc/ovs-vswitchd.conf \
129 --del-match="bridge.*.port=${vif}" \
130 --del-match="vlan.${vif}.[!0-9]*" \
131 --del-match="port.${vif}.[!0-9]*" -c
132 $service vswitch reload