forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetc_xensource_scripts_vif
executable file
·258 lines (225 loc) · 8.3 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/sh
# Copyright (C) 2008,2009 Citrix Systems, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; version 2.1 only. with the special
# exception on linking described in file LICENSE.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# 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
BRCTL="/usr/sbin/brctl"
IP="/sbin/ip"
vsctl="/usr/bin/ovs-vsctl"
handle_promiscuous()
{
local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous" 2>/dev/null)
if [ $? -eq 0 -a -n "${arg}" ] ; then
case $NETWORK_MODE in
bridge)
case "${arg}" in
true|on) echo 1 > /sys/class/net/${dev}/brport/promisc ;;
*) echo 0 > /sys/class/net/${dev}/brport/promisc ;;
esac
;;
vswitch)
logger -t script-vif "${dev}: Promiscuous ports are not supported via vSwitch."
;;
esac
fi
}
handle_ethtool()
{
local opt=$1
local arg=$(xenstore-read "${PRIVATE}/other-config/ethtool-${opt}" 2>/dev/null)
if [ $? -eq 0 -a -n "${arg}" ] ; then
case "${arg}" in
true|on) /sbin/ethtool -K "${dev}" "${opt}" on ;;
false|off) /sbin/ethtool -K "${dev}" "${opt}" off ;;
*) logger -t scripts-vif "Unknown ethtool argument ${opt}=${arg} on ${dev}/${VIFUUID}" ;;
esac
fi
}
handle_mtu()
{
local mtu=$(xenstore-read "${PRIVATE}/MTU" 2>/dev/null)
if [ $? -eq 0 -a -n "${mtu}" ]; then
logger -t scripts-vif "Setting ${dev} MTU ${mtu}"
${IP} link set "${dev}" mtu ${mtu} || logger -t scripts-vif "Failed to ip link set ${dev} mtu ${mtu}. Error code $?"
fi
}
set_vif_external_id()
{
local key=$1
local value=$2
logger -t scripts-vif "vif${DOMID}.${DEVID} external-ids:\"${key}\"=\"${value}\""
echo "-- set interface vif${DOMID}.${DEVID} external-ids:\"${key}\"=\"${value}\""
}
handle_vswitch_vif_details()
{
local vif_details=
local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null)
if [ -n "${net_uuid}" ] ; then
set_vif_external_id "xs-network-uuid" "${net_uuid}"
fi
local address=$(xenstore-read "/local/domain/$DOMID/device/vif/$DEVID/mac" 2>/dev/null)
if [ -n "${address}" ] ; then
set_vif_external_id "xs-vif-mac" "${address}"
fi
local vif_uuid=$(xenstore-read "${PRIVATE}/vif-uuid" 2>/dev/null)
if [ -n "${vif_uuid}" ] ; then
set_vif_external_id "xs-vif-uuid" "${vif_uuid}"
fi
local vm=$(xenstore-read "/local/domain/$DOMID/vm" 2>/dev/null)
if [ $? -eq 0 -a -n "${vm}" ] ; then
local vm_uuid=$(xenstore-read "$vm/uuid" 2>/dev/null)
fi
if [ -n "${vm_uuid}" ] ; then
set_vif_external_id "xs-vm-uuid" "${vm_uuid}"
fi
}
xs550_set_internal_network_uuid()
{
. /etc/xensource-inventory
if test "$PRODUCT_VERSION" = "5.5.0" || test "${BUILD_NUMBER%p}" -le 26131
then
# vNetManager needs to know the network UUID(s) associated with each
# datapath. Normally interface-reconfigure adds them, but XAPI does
# not use interface-reconfigure for internal networks. Instead, XAPI
# calls the addbr ioctl internally, so we have to do it here instead
# for internal networks. This is only acceptable because xapi is lazy
# about creating internal networks: it only creates one just before it
# adds the first vif to it. There may still be a brief delay between
# the initial ovs-vswitchd connection to vNetManager and setting this
# configuration variable, but vNetManager can tolerate that.
local bridge=$1
local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null)
if [ -n "${net_uuid}" ] ; then
logger -t scripts-vif "${bridge} xs-network-uuids ${net_uuid}"
echo "-- br-set-external-id $bridge xs-network-uuids ${net_uuid}"
fi
else
# XAPI after 5.5.0 sets the network external ids itself, via ovs-vsctl.
:
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"
exit 1
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"
exit 1
fi
logger -t scripts-vif "Adding ${dev} to ${bridge} with address ${address}"
${IP} link set "${dev}" down || logger -t scripts-vif "Failed to ip link set ${dev} down"
${IP} link set "${dev}" arp off || logger -t scripts-vif "Failed to ip link set ${dev} arp off"
${IP} link set "${dev}" multicast off || logger -t scripts-vif "Failed to ip link set ${dev} multicast off"
${IP} link set "${dev}" address "${address}" || logger -t scripts-vif "Failed to ip link set ${dev} address ${address}"
${IP} addr flush "${dev}" || logger -t scripts-vif "Failed to ip addr flush ${dev}"
case $NETWORK_MODE in
bridge)
${BRCTL} setfd "${bridge}" 0 || logger -t scripts-vif "Failed to brctl setfd ${bridge} 0"
${BRCTL} addif "${bridge}" "${dev}" || logger -t scripts-vif "Failed to brctl addif ${bridge} ${dev}"
;;
vswitch)
if [ "$TYPE" = "vif" ] ; then
local vif_details=$(handle_vswitch_vif_details)
fi
$vsctl -- --if-exists del-port $dev -- add-port $bridge $dev $vif_details $(xs550_set_internal_network_uuid $bridge)
;;
esac
${IP} link set "${dev}" up || logger -t scripts-vif "Failed to ip link set ${dev} up"
}
remove_from_bridge()
{
case $NETWORK_MODE in
bridge)
# Nothing to do
;;
vswitch)
# If ovs-brcompatd is running, it might already have deleted the
# port. Use --if-exists to suppress the error that would otherwise
# arise in that case.
$vsctl -- --if-exists del-port $dev
;;
esac
}
NETWORK_MODE=$(cat /etc/xensource/network.conf)
ACTION=$1
# Older versions of XenServer do not pass in the type as an argument
if [[ $# -lt 2 ]]; then
TYPE=vif
else
TYPE=$2
fi
case $NETWORK_MODE in
bridge|vswitch) ;;
*)
logger -t scripts-vif "Unknown network mode $NETWORK_MODE"
exit 1
;;
esac
case ${TYPE} in
vif)
DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
dev=vif${DOMID}.${DEVID}
;;
tap)
dev=$INTERFACE
DOMID=`echo ${dev#tap} | cut -f 1 -d '.'`
DEVID=`echo ${dev#tap} | cut -f 2 -d '.'`
;;
*)
logger -t scripts-vif "unknown interface type ${TYPE}"
exit 1
;;
esac
XAPI=/xapi/${DOMID}/hotplug/vif/${DEVID}
HOTPLUG=/xapi/${DOMID}/hotplug/vif/${DEVID}
PRIVATE=/xapi/${DOMID}/private/vif/${DEVID}
logger -t scripts-vif "Called as \"$@\" domid:$DOMID devid:$DEVID mode:$NETWORK_MODE"
case "${ACTION}" in
online)
if [ "${TYPE}" = "vif" ] ; then
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" "${dev}"
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"
fi
;;
add)
if [ "${TYPE}" = "tap" ] ; then
add_to_bridge
fi
;;
remove)
if [ "${TYPE}" = "vif" ] ;then
xenstore-rm "${HOTPLUG}/hotplug"
fi
logger -t scripts-vif "${dev} has been removed"
remove_from_bridge
;;
esac