~ubuntu-branches/ubuntu/trusty/xen-common/trusty

« back to all changes in this revision

Viewing changes to tools/hotplug/Linux/xen-network-common.sh

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2009-11-22 16:51:53 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091122165153-d36l98kbx8a930h2
Tags: 3.4.2-2
* Redefine Xen version tests to allow detection of bare metal.
  (closes: #556859)
* Support oldstyle Xen kernel without xenfs. (closes: #557151)
* Use debhelper compat level 7.
* Remove oldstable-only conflicts.
* Add wrapper for xenpm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
# Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives.
 
20
 
 
21
# Other platforms just use ifup / ifdown directly.
 
22
 
 
23
##
 
24
# preiftransfer
 
25
#
 
26
# @param $1 The current name for the physical device, which is also the name
 
27
#           that the virtual device will take once the physical device has
 
28
#           been renamed.
 
29
 
 
30
if ! which ifup >/dev/null 2>/dev/null
 
31
then
 
32
  preiftransfer()
 
33
  {
 
34
    true
 
35
  }
 
36
  ifup()
 
37
  {
 
38
    false
 
39
  }
 
40
  ifdown()
 
41
  {
 
42
    false
 
43
  }
 
44
else
 
45
  preiftransfer()
 
46
  {
 
47
    true
 
48
  }
 
49
fi
 
50
 
 
51
 
 
52
first_file()
 
53
{
 
54
  t="$1"
 
55
  shift
 
56
  for file in $@
 
57
  do
 
58
    if [ "$t" "$file" ]
 
59
    then
 
60
      echo "$file"
 
61
      return
 
62
    fi
 
63
  done
 
64
}
 
65
 
 
66
find_dhcpd_conf_file()
 
67
{
 
68
  first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
 
69
}
 
70
 
 
71
 
 
72
find_dhcpd_init_file()
 
73
{
 
74
  first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
 
75
}
 
76
 
 
77
find_dhcpd_arg_file()
 
78
{
 
79
  first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp3-server
 
80
}
 
81
 
 
82
# configure interfaces which act as pure bridge ports:
 
83
setup_bridge_port() {
 
84
    local dev="$1"
 
85
 
 
86
    # take interface down ...
 
87
    ip link set ${dev} down
 
88
 
 
89
    # ... and configure it
 
90
    ip addr flush ${dev}
 
91
}
 
92
 
 
93
# Usage: create_bridge bridge
 
94
create_bridge () {
 
95
    local bridge=$1
 
96
 
 
97
    # Don't create the bridge if it already exists.
 
98
    if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then
 
99
        brctl addbr ${bridge}
 
100
        brctl stp ${bridge} off
 
101
        brctl setfd ${bridge} 0
 
102
    fi
 
103
}
 
104
 
 
105
# Usage: add_to_bridge bridge dev
 
106
add_to_bridge () {
 
107
    local bridge=$1
 
108
    local dev=$2
 
109
 
 
110
    # Don't add $dev to $bridge if it's already on a bridge.
 
111
    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
 
112
        ip link set ${dev} up || true
 
113
        return
 
114
    fi
 
115
    brctl addif ${bridge} ${dev}
 
116
    ip link set ${dev} up
 
117
}
 
118