3 # Copyright (C) 2008,2009 Citrix Systems, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published
7 # by the Free Software Foundation; version 2.1 only. with the special
8 # exception on linking described in file LICENSE.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # CA-23900: Warning: when VIFs are added to windows guests with PV drivers the backend vif device is registered,
16 # unregistered and then registered again. This causes the udev event to fire twice and this script runs twice.
17 # Since the first invocation of the script races with the device unregistration, spurious errors are possible
18 # which will be logged but are safe to ignore since the second script invocation should complete the operation.
19 # Note that each script invocation is run synchronously from udev and so the scripts don't race with each other.
21 # Keep other-config/ keys in sync with device.ml:vif_udev_keys
23 BRCTL="/usr/sbin/brctl"
26 vsctl="/usr/bin/ovs-vsctl"
27 dump_vif_details="/usr/share/vswitch/scripts/dump-vif-details"
31 local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous" 2>/dev/null)
32 if [ $? -eq 0 -a -n "${arg}" ] ; then
36 true|on) echo 1 > /sys/class/net/${dev}/brport/promisc ;;
37 *) echo 0 > /sys/class/net/${dev}/brport/promisc ;;
41 logger -t script-vif "${dev}: Promiscuous ports are not supported via vSwitch."
50 local arg=$(xenstore-read "${PRIVATE}/other-config/ethtool-${opt}" 2>/dev/null)
51 if [ $? -eq 0 -a -n "${arg}" ] ; then
53 true|on) /sbin/ethtool -K "${dev}" "${opt}" on ;;
54 false|off) /sbin/ethtool -K "${dev}" "${opt}" off ;;
55 *) logger -t scripts-vif "Unknown ethtool argument ${opt}=${arg} on ${dev}/${VIFUUID}" ;;
62 local mtu=$(xenstore-read "${PRIVATE}/MTU" 2>/dev/null)
63 if [ $? -eq 0 -a -n "${mtu}" ]; then
64 logger -t scripts-vif "Setting ${dev} MTU ${mtu}"
65 ${IP} link set "${dev}" mtu ${mtu} || logger -t scripts-vif "Failed to ip link set ${dev} mtu ${mtu}. Error code $?"
71 local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
72 if [ $? -ne 0 -o -z "${address}" ]; then
73 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore"
76 local bridge=$(xenstore-read "${PRIVATE}/bridge")
77 if [ $? -ne 0 -o -z "${bridge}" ]; then
78 logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore"
81 logger -t scripts-vif "Adding ${dev} to ${bridge} with address ${address}"
83 ${IP} link set "${dev}" down || logger -t scripts-vif "Failed to ip link set ${dev} down"
84 ${IP} link set "${dev}" arp off || logger -t scripts-vif "Failed to ip link set ${dev} arp off"
85 ${IP} link set "${dev}" multicast off || logger -t scripts-vif "Failed to ip link set ${dev} multicast off"
86 ${IP} link set "${dev}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${dev} address ${address}"
87 ${IP} addr flush "${dev}" || logger -t scripts-vif "Failed to ip addr flush ${dev}"
91 ${BRCTL} setfd "${bridge}" 0 || logger -t scripts-vif "Failed to brctl setfd ${bridge} 0"
92 ${BRCTL} addif "${bridge}" "${dev}" || logger -t scripts-vif "Failed to brctl addif ${bridge} ${dev}"
95 local vif_details=$($dump_vif_details $DOMID $DEVID)
96 if [ $? -ne 0 -o -z "${vif_details}" ]; then
97 logger -t scripts-vif "Failed to retrieve vif details for vswitch"
100 $vsctl -- --if-exists del-port $dev -- add-port $bridge $dev $vif_details
104 ${IP} link set "${dev}" up || logger -t scripts-vif "Failed to ip link set ${dev} up"
109 case $NETWORK_MODE in
114 $vsctl del-port $bridge $dev
119 NETWORK_MODE=$(cat /etc/xensource/network.conf)
122 # Older versions of XenServer do not pass in the type as an argument
123 if [[ $# -lt 2 ]]; then
129 case $NETWORK_MODE in
132 logger -t scripts-vif "Unknown network mode $NETWORK_MODE"
139 DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
140 DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
141 dev=vif${DOMID}.${DEVID}
145 DOMID=`echo ${dev#tap} | cut -f 1 -d '.'`
146 DEVID=`echo ${dev#tap} | cut -f 2 -d '.'`
149 logger -t scripts-vif "unknown interface type ${TYPE}"
154 XAPI=/xapi/${DOMID}/hotplug/vif/${DEVID}
155 HOTPLUG=/xapi/${DOMID}/hotplug/vif/${DEVID}
156 PRIVATE=/xapi/${DOMID}/private/vif/${DEVID}
158 logger -t scripts-vif "Called as \"$@\" domid:$DOMID devid:$DEVID mode:$NETWORK_MODE"
161 if [ "${TYPE}" = "vif" ] ; then
173 xenstore-write "${HOTPLUG}/vif" "${dev}"
174 xenstore-write "${HOTPLUG}/hotplug" "online"
176 # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
177 xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
182 if [ "${TYPE}" = "tap" ] ; then
188 if [ "${TYPE}" = "vif" ] ;then
189 xenstore-rm "${HOTPLUG}/hotplug"
191 logger -t scripts-vif "${dev} has been removed"