/[baselayout]/trunk/net-scripts/net.modules.d/bridge
Gentoo

Diff of /trunk/net-scripts/net.modules.d/bridge

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1246 Revision 1247
1#!/bin/bash
1# Copyright (c) 2004-2005 Gentoo Foundation 2# Copyright (c) 2004-2005 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 3# Distributed under the terms of the GNU General Public License v2
3 4
4# Contributed by Roy Marples (uberlord@gentoo.org) 5# Contributed by Roy Marples (uberlord@gentoo.org)
5 6
58 59
59# char* bridge_get_ports(char *interface) 60# char* bridge_get_ports(char *interface)
60# 61#
61# Returns the interfaces added to the given bridge 62# Returns the interfaces added to the given bridge
62bridge_get_ports() { 63bridge_get_ports() {
64 brctl show 2>/dev/null \
63 brctl show 2>/dev/null | sed -n -e '/^'$1'/,/^\S/ { /^\('$1'\|\t\)/s/^.*\t//p }' 65 | sed -n -e '/^'"$1"'/,/^\S/ { /^\('"$1"'\|\t\)/s/^.*\t//p }'
64} 66}
65 67
66# bool bridge_start(char *iface) 68# bool bridge_start(char *iface)
67# 69#
68# #set up bridge 70# #set up bridge
69bridge_pre_start() { 71bridge_pre_start() {
70 local iface=$1 ports i e x ifvar=$( bash_variable $1 ) 72 local iface="$1" ports i e x ifvar=$( bash_variable "$1" )
71 local -a opts 73 local -a opts
72 eval ports=\"\$\{bridge_${ifvar}\[@\]\}\" 74 eval ports=\"\$\{bridge_${ifvar}\[@\]\}\"
73 75
74 [[ -z ${ports} ]] && return 0 76 [[ -z ${ports} ]] && return 0
75 77
76 # Destroy the bridge if it exists 78 # Destroy the bridge if it exists
77 bridge_stop ${iface} 79 bridge_stop "${iface}"
78 80
79 ebegin "Creating bridge ${iface}" 81 ebegin "Creating bridge ${iface}"
80 e=$( brctl addbr ${iface} 2>&1 ) 82 e=$( brctl addbr "${iface}" 2>&1 )
81 if [[ -n ${e} ]]; then 83 if [[ -n ${e} ]]; then
82 if [[ ${e} == "br_add_bridge: Package not installed" ]]; then 84 if [[ ${e} == "br_add_bridge: Package not installed" ]]; then
83 eend 1 "Bridging (802.1d) support is not present in this kernel" 85 eend 1 "Bridging (802.1d) support is not present in this kernel"
84 else 86 else
85 eend 1 "${e}" 87 eend 1 "${e}"
87 return 1 89 return 1
88 fi 90 fi
89 91
90 eval opts=( \"\$\{brctl_${ifvar}\[@\]\}\" ) 92 eval opts=( \"\$\{brctl_${ifvar}\[@\]\}\" )
91 for (( i=0; i<${#opts[@]}; i++ )); do 93 for (( i=0; i<${#opts[@]}; i++ )); do
92 x=${opts[i]/ / ${iface} } 94 x="${opts[i]/ / ${iface} }"
93 [[ ${x} == ${opts[i]} ]] && x="${x} ${iface}" 95 [[ ${x} == ${opts[i]} ]] && x="${x} ${iface}"
94 e=$( brctl ${x} 2>&1 1>/dev/null ) 96 e=$( brctl "${x}" 2>&1 1>/dev/null )
95 [[ -n ${e} ]] && ewarn "${e}" 97 [[ -n ${e} ]] && ewarn "${e}"
96 done 98 done
97 eend 0 99 eend 0
98 100
99 einfo "Adding ports to ${iface}" 101 einfo "Adding ports to ${iface}"
100 eindent 102 eindent
101 103
102 for i in ${ports}; do 104 for i in ${ports}; do
103 interface_exists ${i} && continue 105 interface_exists "${i}" && continue
104 eerror "interface ${i} does not exist" 106 eerror "interface ${i} does not exist"
105 return 1 107 return 1
106 done 108 done
107 109
108 for i in ${ports}; do 110 for i in ${ports}; do
109 ebegin "${i}" 111 ebegin "${i}"
110 interface_set_flag ${i} promisc true 112 interface_set_flag "${i}" promisc true
111 interface_up ${i} 113 interface_up "${i}"
112 e=$( brctl addif ${iface} ${i} 2>&1 ) 114 e=$( brctl addif "${iface}" "${i}" 2>&1 )
113 if [[ -n ${e} ]]; then 115 if [[ -n ${e} ]]; then
114 eend 1 "${e}" 116 eend 1 "${e}"
115 interface_set_flag ${i} promisc false 117 interface_set_flag "${i}" promisc false
116 return 1 118 return 1
117 fi 119 fi
118 eend 0 120 eend 0
119 done 121 done
120 eoutdent 122 eoutdent
127# Removes the device 129# Removes the device
128# returns 0 130# returns 0
129bridge_stop() { 131bridge_stop() {
130 bridge_check_installed || return 1 132 bridge_check_installed || return 1
131 133
132 local iface=$1 is_bridge=$( brctl show | grep ^$1 ) 134 local iface="$1" is_bridge=$( brctl show | grep "^$1" )
133 [[ -z ${is_bridge} ]] && return 1 135 [[ -z ${is_bridge} ]] && return 1
134 136
135 ebegin "Destroying bridge ${iface}" 137 ebegin "Destroying bridge ${iface}"
136 interface_down ${iface} 138 interface_down "${iface}"
137 139
138 local ports=$( bridge_get_ports ${1} ) i 140 local ports=$( bridge_get_ports "${iface}" ) i
139 eindent 141 eindent
140 for i in ${ports}; do 142 for i in ${ports}; do
141 ebegin "Removing port ${i}" 143 ebegin "Removing port ${i}"
142 interface_set_flag ${i} promisc false 144 interface_set_flag "${i}" promisc false
143 brctl delif ${iface} ${i} 145 brctl delif "${iface}" "${i}"
144 eend $? 146 eend $?
145 done 147 done
146 eoutdent 148 eoutdent
147 149
148 brctl delbr ${iface} &>${devnull} 150 brctl delbr "${iface}" &>/dev/null
149 eend 0 151 eend 0
150 return 0 152 return 0
151} 153}

Legend:
Removed from v.1246  
changed lines
  Added in v.1247

  ViewVC Help
Powered by ViewVC 1.1.20