]>
git.ipfire.org Git - people/stevee/network.git/blob - src/functions/functions.bridge
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
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 ###############################################################################
30 while [ $# -gt 0 ]; do
33 address
=$
(cli_get_val
${1})
36 mtu
=$
(cli_get_val
${1})
39 error
"Unrecognized argument: ${1}"
46 if device_exists
${bridge}; then
47 log ERROR
"bridge: bridge '${bridge}' does already exist"
51 # Build the ip command.
52 local command="ip link add name ${bridge}"
54 # Add address, if we know it.
55 if ismac address
; then
56 command="${command} address ${address}"
59 # Add MTU if it has been set.
60 if isinteger mtu
; then
61 command="${command} mtu ${mtu}"
64 # Last argument is the device type.
65 command="${command} type bridge"
71 if [ ${ret} -eq ${EXIT_OK} ]; then
72 log DEBUG
"bridge: bridge '${bridge}' has been created"
74 log ERROR
"bridge: Could not create bridge '${bridge}': ${ret}"
84 device_delete
${bridge}
87 bridge_attach_device
() {
94 # Check if bridge exists.
95 if ! device_exists
${bridge}; then
96 log ERROR
"bridge: bridge '${bridge}' does not exist to attach devices to"
100 # Check if device exists.
101 if ! device_exists
${device}; then
102 log ERROR
"bridge: could not attach '${device}' to '${bridge}' because device does not exist"
106 # If device is already attached, exit silently.
107 if list_match
${device} $
(bridge_get_members
${bridge}); then
111 # Make sure that the MTU of the device that is to be attached
112 # to the bridge matches the MTU of the bridge.
113 device_adjust_mtu
"${device}" "${bridge}"
115 # Actually connect bridge and device.
116 if ! device_set_master
"${device}" "${bridge}"; then
117 log ERROR
"Could not attach ${device} to bridge ${bridge}"
121 log DEBUG
"${device} has been attached to bridge ${bridge}"
125 bridge_detach_device
() {
132 # Check if bridge exists.
133 if ! device_exists
${bridge}; then
134 log ERROR
"bridge: bridge '${bridge}' does not exist to detach devices from"
138 # Check if device exists.
139 if ! device_exists
${device}; then
140 log ERROR
"bridge: could not detach '${device}' from '${bridge}' because device does not exist"
144 # If device is not attched, exit silently.
145 if ! list_match
${device} $
(bridge_get_members
${bridge}); then
149 cmd_quiet ip link
set ${device} nomaster
152 if [ ${ret} -eq ${EXIT_OK} ]; then
153 log DEBUG
"bridge: device '${device}' has been detached from bridge '${bridge}'"
155 log ERROR
"bridge: could not detach device '${device}' from bridge '${bridge}': ${ret}"
161 bridge_get_members
() {
167 for member
in ${SYS_CLASS_NET}/${bridge}/brif
/*; do
168 member
=$
(basename ${member})
169 if device_exists
${member}; then
175 bridge_is_forwarding
() {
179 bridge_has_carrier
${zone} ||
return ${EXIT_ERROR}
182 while [ ${seconds} -gt 0 ]; do
183 for device
in ${SYS_CLASS_NET}/${zone}/brif
/*; do
184 [ -e "${device}/state" ] ||
continue
185 if [ "$(<${device}/state)" = "3" ]; then
190 seconds
=$
((${seconds} - 1))
196 bridge_has_carrier
() {
199 local has_carrier
=${EXIT_ERROR}
202 for device
in ${SYS_CLASS_NET}/${zone}/brif
/*; do
203 device
=$
(basename ${device})
204 device_exists
${device} ||
continue
206 device_has_carrier
${device} && has_carrier
=${EXIT_OK}
209 return ${has_carrier}