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"
22 local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous" 2>/dev/null)
23 if [ $? -eq 0 -a -n "${arg}" ] ; then
25 true|on) logger -t script-vif "${dev}: Promiscuous ports are not supported via vSwitch." ;;
34 local arg=$(xenstore-read "${PRIVATE}/other-config/ethtool-${opt}" 2>/dev/null)
35 if [ $? -eq 0 -a -n "${arg}" ] ; then
37 true|on) /sbin/ethtool -K "${dev}" "${opt}" on ;;
38 false|off) /sbin/ethtool -K "${dev}" "${opt}" off ;;
39 *) logger -t scripts-vif "Unknown ethtool argument ${opt}=${arg} on ${dev}/${VIFUUID}" ;;
46 local mtu=$(xenstore-read "${PRIVATE}/MTU" 2>/dev/null)
47 if [ $? -eq 0 -a -n "${mtu}" ]; then
48 echo "${mtu}" > /sys/class/net/${dev}/mtu
55 local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null)
56 if [ -n "${net_uuid}" ] ; then
57 vif_details="$vif_details --add=port.${dev}.net-uuid=${net_uuid}"
60 local address=$(xenstore-read "/local/domain/$DOMID/device/vif/$DEVID/mac" 2>/dev/null)
61 if [ -n "${address}" ] ; then
62 vif_details="$vif_details --add=port.${dev}.vif-mac=${address}"
65 local vif_uuid=$(xenstore-read "${PRIVATE}/vif-uuid" 2>/dev/null)
66 if [ -n "${vif_uuid}" ] ; then
67 vif_details="$vif_details --add=port.${dev}.vif-uuid=${vif_uuid}"
70 local vm=$(xenstore-read "/local/domain/$DOMID/vm" 2>/dev/null)
71 if [ $? -eq 0 -a -n "${vm}" ] ; then
72 local vm_uuid=$(xenstore-read "$vm/uuid" 2>/dev/null)
74 if [ -n "${vm_uuid}" ] ; then
75 vif_details="$vif_details --add=port.${dev}.vm-uuid=${vm_uuid}"
82 local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
83 if [ $? -ne 0 -o -z "${address}" ]; then
84 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore"
87 local bridge=$(xenstore-read "${PRIVATE}/bridge")
88 if [ $? -ne 0 -o -z "${bridge}" ]; then
89 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore"
92 logger -t scripts-vif "Adding ${dev} to ${bridge} with address ${address}"
94 local VLAN_ID=$($vsctl br-to-vlan $bridge)
96 if [ "$VLAN_ID" -ne 0 ] ; then
97 bridge=$($vsctl br-to-parent $bridge)
98 vid="--add=vlan.${dev}.tag=${VLAN_ID}"
101 if [ "$type" = "vif" ] ; then
102 local vif_details=$(handle_vif_details)
105 ${IP} link set "${dev}" down || logger -t scripts-vif "Failed to ip link set ${dev} down"
106 ${IP} link set "${dev}" arp off || logger -t scripts-vif "Failed to ip link set ${dev} arp off"
107 ${IP} link set "${dev}" multicast off || logger -t scripts-vif "Failed to ip link set ${dev} multicast off"
108 ${IP} link set "${dev}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${dev} address ${address}"
109 ${IP} addr flush "${dev}" || logger -t scripts-vif "Failed to ip addr flush ${dev}"
111 $cfg_mod -F /etc/ovs-vswitchd.conf \
112 --del-match="bridge.*.port=${dev}" \
113 --del-match="vlan.${dev}.[!0-9]*" \
114 --del-match="port.${dev}.[!0-9]*" \
115 --add="bridge.$bridge.port=${dev}" \
117 $service vswitch reload
119 ${IP} link set "${dev}" up || logger -t scripts-vif "Failed to ip link set ${dev} up"
126 DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
127 DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
128 dev=vif${DOMID}.${DEVID}
132 DOMID=`echo ${dev#tap} | cut -f 1 -d '.'`
133 DEVID=`echo ${dev#tap} | cut -f 2 -d '.'`
136 logger -t scripts-vif "unknown interface type ${type}"
141 XAPI=/xapi/${DOMID}/hotplug/vif/${DEVID}
142 HOTPLUG=/xapi/${DOMID}/hotplug/vif/${DEVID}
143 PRIVATE=/xapi/${DOMID}/private/vif/${DEVID}
145 echo Called as "$@" "$DOMID" "$DEVID" | logger -t scripts-vif
148 if [ "${type}" = "vif" ] ; then
160 xenstore-write "${HOTPLUG}/vif" "${dev}"
161 xenstore-write "${HOTPLUG}/hotplug" "online"
163 # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
164 xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
169 if [ "${type}" = "tap" ] ; then
175 if [ "${type}" = "vif" ] ;then
176 xenstore-rm "${HOTPLUG}/hotplug"
178 logger -t scripts-vif "${dev} has been removed"
179 $cfg_mod -vANY:console:emer -F /etc/ovs-vswitchd.conf \
180 --del-match="bridge.*.port=${dev}" \
181 --del-match="vlan.${dev}.[!0-9]*" \
182 --del-match="port.${dev}.[!0-9]*" -c
183 $service vswitch reload