forked from ovn-org/ovn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
etc_xensource_scripts_vif
executable file
·135 lines (114 loc) · 4.66 KB
/
etc_xensource_scripts_vif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
# Copyright (C) 2008,2009 Citrix Systems, Inc. All rights reserved.
# Copyright (C) 2009 Nicira Networks, Inc.
# CA-23900: Warning: when VIFs are added to windows guests with PV drivers the backend vif device is registered,
# unregistered and then registered again. This causes the udev event to fire twice and this script runs twice.
# Since the first invocation of the script races with the device unregistration, spurious errors are possible
# which will be logged but are safe to ignore since the second script invocation should complete the operation.
# Note that each script invocation is run synchronously from udev and so the scripts don't race with each other.
# Keep other-config/ keys in sync with device.ml:vif_udev_keys
cfg_mod="/usr/bin/ovs-cfg-mod"
dump_vif_details="/usr/share/vswitch/scripts/dump-vif-details"
service="/sbin/service"
TYPE=`echo ${XENBUS_PATH} | cut -f 2 -d '/'`
DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
XAPI=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
HOTPLUG=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
PRIVATE=/xapi/${DOMID}/private/${TYPE}/${DEVID}
BRCTL=/usr/sbin/brctl
IP=/sbin/ip
handle_promiscuous()
{
local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous")
if [ $? -eq 0 -a -n "${arg}" ] ; then
case "${arg}" in
true|on) logger -t script-vif "${vif}: Promiscuous ports are not supported via vSwitch." ;;
*) ;;
esac
fi
}
handle_ethtool()
{
local opt=$1
local arg=$(xenstore-read "${PRIVATE}/other-config/ethtool-${opt}")
if [ $? -eq 0 -a -n "${arg}" ] ; then
case "${arg}" in
true|on) /sbin/ethtool -K "${vif}" "${opt}" on ;;
false|off) /sbin/ethtool -K "${vif}" "${opt}" off ;;
*) logger -t scripts-vif "Unknown ethtool argument ${opt}=${arg} on ${vif}/${VIFUUID}" ;;
esac
fi
}
handle_mtu()
{
local mtu=$(xenstore-read "${PRIVATE}/MTU")
if [ $? -eq 0 -a -n "${mtu}" ]; then
echo "${mtu}" > /sys/class/net/${vif}/mtu
fi
}
add_to_bridge()
{
local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
if [ $? -ne 0 -o -z "${address}" ]; then
logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore"
fi
local bridge=$(xenstore-read "${PRIVATE}/bridge")
if [ $? -ne 0 -o -z "${bridge}" ]; then
logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore"
fi
logger -t scripts-vif "Adding ${vif} to ${bridge} with address ${address}"
vid=
if [ -e "/var/lib/openvswitch/br-$bridge" ]; then
. "/var/lib/openvswitch/br-$bridge"
if [ -n "$VLAN_SLAVE" -a -n "$VLAN_VID" ]; then
bridge=$VLAN_SLAVE
vid="--add=vlan.$vif.tag=$VLAN_VID"
fi
fi
${IP} link set "${vif}" down || logger -t scripts-vif "Failed to ip link set ${vif} down"
${IP} link set "${vif}" arp off || logger -t scripts-vif "Failed to ip link set ${vif} arp off"
${IP} link set "${vif}" multicast off || logger -t scripts-vif "Failed to ip link set ${vif} multicast off"
${IP} link set "${vif}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${vif} address ${address}"
${IP} addr flush "${vif}" || logger -t scripts-vif "Failed to ip addr flush ${vif}"
local vif_details=$($dump_vif_details $DOMID $DEVID)
if [ $? -ne 0 -o -z "${vif_details}" ]; then
logger -t scripts-vif "Failed to retrieve vif details for vswitch"
fi
$cfg_mod -F /etc/ovs-vswitchd.conf \
--del-match="bridge.*.port=$vif" \
--del-match="vlan.$vif.[!0-9]*" \
--del-match="port.$vif.[!0-9]*" \
--add="bridge.$bridge.port=$vif" \
$vid $vif_details -c
$service vswitch reload
${IP} link set "${vif}" up || logger -t scripts-vif "Failed to ip link set ${vif} up"
}
echo Called as "$@" "$TYPE" "$DOMID" "$DEVID" | logger -t scripts-vif
case "$1" in
online)
handle_ethtool rx
handle_ethtool tx
handle_ethtool sg
handle_ethtool tso
handle_ethtool ufo
handle_ethtool gso
handle_mtu
add_to_bridge
handle_promiscuous
xenstore-write "${HOTPLUG}/vif" "${vif}"
xenstore-write "${HOTPLUG}/hotplug" "online"
# xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
;;
remove)
xenstore-rm "${HOTPLUG}/hotplug"
vif=vif${DOMID}.${DEVID}
logger -t scripts-vif "${vif} has been removed"
$cfg_mod -vANY:console:emer -F /etc/ovs-vswitchd.conf \
--del-match="bridge.*.port=${vif}" \
--del-match="vlan.${vif}.[!0-9]*" \
--del-match="port.${vif}.[!0-9]*" -c
$service vswitch reload
;;
esac