]>
git.ipfire.org Git - people/ms/network.git/blob - functions.bridge
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 function bridge_attach_device
() {
29 assert device_exists
${bridge}
30 assert device_exists
${device}
32 # If device is already attached, exit silently
33 if listmatch
${device} $
(bridge_get_members
${bridge}); then
37 log INFO
"Attaching device '${device}' to bridge '${bridge}'."
39 brctl addif
${bridge} ${device}
42 function bridge_detach_device
() {
49 if ! device_exists
${bridge}; then
50 error
"Bridge '${bridge}' does not exist."
54 if ! device_exists
${device}; then
58 # If device is not attached, exit silently
59 if ! listmatch
${device} $
(bridge_get_members
${bridge}); then
63 log INFO
"Detaching device '${device}' from bridge '${bridge}'."
65 brctl delif
${bridge} ${device}
68 function bridge_get_members
() {
74 for member
in ${SYS_CLASS_NET}/${bridge}/brif
/*; do
75 member
=$
(basename ${member})
76 if device_exists
${member}; then
82 function bridge_is_forwarding
() {
86 bridge_has_carrier
${zone} ||
return ${EXIT_ERROR}
89 while [ ${seconds} -gt 0 ]; do
90 for device
in ${SYS_CLASS_NET}/${zone}/brif
/*; do
91 [ -e "${device}/state" ] ||
continue
92 if [ "$(<${device}/state)" = "3" ]; then
97 seconds
=$
((${seconds} - 1))
103 function bridge_has_carrier
() {
106 local has_carrier
=${EXIT_ERROR}
109 for device
in ${SYS_CLASS_NET}/${zone}/brif
/*; do
110 device
=$
(basename ${device})
111 device_exists
${device} ||
continue
113 device_has_carrier
${device} && has_carrier
=${EXIT_OK}
116 return ${has_carrier}