]>
git.ipfire.org Git - people/stevee/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}
31 if ! device_exists
${device}; then
32 log WARN
"Could not attach '${device}' to '${bridge}' becase device does not exist."
36 # If device is already attached, exit silently
37 if listmatch
${device} $
(bridge_get_members
${bridge}); then
41 log INFO
"Attaching device '${device}' to bridge '${bridge}'."
43 brctl addif
${bridge} ${device}
46 function bridge_detach_device
() {
53 if ! device_exists
${bridge}; then
54 error
"Bridge '${bridge}' does not exist."
58 if ! device_exists
${device}; then
62 # If device is not attached, exit silently
63 if ! listmatch
${device} $
(bridge_get_members
${bridge}); then
67 log INFO
"Detaching device '${device}' from bridge '${bridge}'."
69 brctl delif
${bridge} ${device}
72 function bridge_get_members
() {
78 for member
in ${SYS_CLASS_NET}/${bridge}/brif
/*; do
79 member
=$
(basename ${member})
80 if device_exists
${member}; then
86 function bridge_is_forwarding
() {
90 bridge_has_carrier
${zone} ||
return ${EXIT_ERROR}
93 while [ ${seconds} -gt 0 ]; do
94 for device
in ${SYS_CLASS_NET}/${zone}/brif
/*; do
95 [ -e "${device}/state" ] ||
continue
96 if [ "$(<${device}/state)" = "3" ]; then
101 seconds
=$
((${seconds} - 1))
107 function bridge_has_carrier
() {
110 local has_carrier
=${EXIT_ERROR}
113 for device
in ${SYS_CLASS_NET}/${zone}/brif
/*; do
114 device
=$
(basename ${device})
115 device_exists
${device} ||
continue
117 device_has_carrier
${device} && has_carrier
=${EXIT_OK}
120 return ${has_carrier}