ia64/xen-unstable

view tools/examples/xen-network-common.sh @ 11100:905ff6e616cc

[HVM] Add stubs to Linux for the new hvm_op hypercall.
Signed-off-by: Steven Smith <ssmith@xensource.com>
author kfraser@localhost.localdomain
date Mon Aug 14 11:33:50 2006 +0100 (2006-08-14)
parents 45f504d6b548
children b688d4a68a3e
line source
1 #
2 # Copyright (c) 2005 XenSource Ltd.
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of version 2.1 of the GNU Lesser General Public
6 # License as published by the Free Software Foundation.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
19 # On SuSE it is necessary to run a command before transfering addresses and
20 # routes from the physical interface to the virtual. This command creates a
21 # variable $HWD_CONFIG_0 that specifies the appropriate configuration for
22 # ifup.
24 # Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives.
26 # Other platforms just use ifup / ifdown directly.
28 ##
29 # preiftransfer
30 #
31 # @param $1 The current name for the physical device, which is also the name
32 # that the virtual device will take once the physical device has
33 # been renamed.
35 if [ -e /etc/SuSE-release ]
36 then
37 preiftransfer()
38 {
39 eval `/sbin/getcfg -d /etc/sysconfig/network/ -f ifcfg- -- $1`
40 }
41 ifup()
42 {
43 /sbin/ifup ${HWD_CONFIG_0} $1
44 }
45 elif ! which ifup >/dev/null 2>/dev/null
46 then
47 if [ -e /etc/conf.d/net ]
48 then
49 preiftransfer()
50 {
51 true
52 }
53 ifup()
54 {
55 /etc/init.d/net.$1 start
56 }
57 ifdown()
58 {
59 /etc/init.d/net.$1 stop
60 }
61 else
62 preiftransfer()
63 {
64 true
65 }
66 ifup()
67 {
68 false
69 }
70 ifdown()
71 {
72 false
73 }
74 fi
75 else
76 preiftransfer()
77 {
78 true
79 }
80 fi
83 first_file()
84 {
85 t="$1"
86 shift
87 for file in $@
88 do
89 if [ "$t" "$file" ]
90 then
91 echo "$file"
92 return
93 fi
94 done
95 }
97 find_dhcpd_conf_file()
98 {
99 first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
100 }
103 find_dhcpd_init_file()
104 {
105 first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
106 }
108 # configure interfaces which act as pure bridge ports:
109 # - make quiet: no arp, no multicast (ipv6 autoconf)
110 # - set mac address to fe:ff:ff:ff:ff:ff
111 setup_bridge_port() {
112 local dev="$1"
114 # take interface down ...
115 ip link set ${dev} down
117 # ... and configure it
118 ip link set ${dev} arp off
119 ip link set ${dev} multicast off
120 ip link set ${dev} addr fe:ff:ff:ff:ff:ff
121 ip addr flush ${dev}
122 }
124 # Usage: create_bridge bridge
125 create_bridge () {
126 local bridge=$1
128 # Don't create the bridge if it already exists.
129 if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then
130 brctl addbr ${bridge}
131 brctl stp ${bridge} off
132 brctl setfd ${bridge} 0
133 ip link set ${bridge} arp off
134 ip link set ${bridge} multicast off
135 fi
136 ip link set ${bridge} up
137 }
139 # Usage: add_to_bridge bridge dev
140 add_to_bridge () {
141 local bridge=$1
142 local dev=$2
144 # Don't add $dev to $bridge if it's already on a bridge.
145 if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
146 return
147 fi
148 brctl addif ${bridge} ${dev}
149 ip link set ${dev} up
150 }