source: drbl-virt/conf/initrd_bin/xen-network-common.sh @ 178

Last change on this file since 178 was 170, checked in by rock, 14 years ago

Add: DRBL client -> Xen configuration file

File size: 2.7 KB
Line 
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#
17
18
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.
23
24# Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives.
25
26# Other platforms just use ifup / ifdown directly.
27
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.
34
35if [ -e /etc/SuSE-release ]
36then
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  }
45elif ! which ifup >/dev/null 2>/dev/null
46then
47  preiftransfer()
48  {
49    true
50  }
51  ifup()
52  {
53    false
54  }
55  ifdown()
56  {
57    false
58  }
59else
60  preiftransfer()
61  {
62    true
63  }
64fi
65
66
67first_file()
68{
69  t="$1"
70  shift
71  for file in $@
72  do
73    if [ "$t" "$file" ]
74    then
75      echo "$file"
76      return
77    fi
78  done
79}
80
81find_dhcpd_conf_file()
82{
83  first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
84}
85
86
87find_dhcpd_init_file()
88{
89  first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
90}
91
92# configure interfaces which act as pure bridge ports:
93setup_bridge_port() {
94    local dev="$1"
95
96    # take interface down ...
97    ip link set ${dev} down
98
99    # ... and configure it
100    ip addr flush ${dev}
101}
102
103# Usage: create_bridge bridge
104create_bridge () {
105    local bridge=$1
106
107    # Don't create the bridge if it already exists.
108    if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then
109  brctl addbr ${bridge}
110  brctl stp ${bridge} off
111  brctl setfd ${bridge} 0
112    fi
113}
114
115# Usage: add_to_bridge bridge dev
116add_to_bridge () {
117    local bridge=$1
118    local dev=$2
119
120    # Don't add $dev to $bridge if it's already on a bridge.
121    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
122  ip link set ${dev} up || true
123  return
124    fi
125    brctl addif ${bridge} ${dev}
126    ip link set ${dev} up
127}
128
Note: See TracBrowser for help on using the repository browser.