]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/udev/network-hotplug-bridges
4b8764598d1d55e6339cf52836483b1f1b1fccb1
2 ############################################################################
4 # This file is part of the IPFire Firewall. #
6 # IPFire is free software; you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation; either version 2 of the License, or #
9 # (at your option) any later version. #
11 # IPFire is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with IPFire; if not, write to the Free Software #
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
20 # Copyright (C) 2016 IPFire Team <info@ipfire.org> #
22 ############################################################################
24 [ -n "${INTERFACE}" ] ||
exit 2
26 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
29 local intf
="${INTERFACE%?}"
34 for zone
in GREEN BLUE ORANGE RED
; do
35 # Try to find if INTERFACE is the *phys version of a zone
36 if [ "${intf}" = "${zone}" ]; then
41 # Try to find out if this INTERFACE is a slave of a zone
43 for slave
in $
(get_value
"${zone}_SLAVES"); do
44 # Compare if the mac address matches or if the name matches
45 if [ -r "/sys/class/net/${INTERFACE}/address" -a "$(</sys/class/net/${INTERFACE}/address)" = "${slave}" ] || [ "${INTERFACE}" = "${slave}" ]; then
59 random_mac_address
() {
63 printf -v address
"${address}:%02x" "$(( RANDOM % 256 ))"
69 # Try to detect which zone we are operating on
72 # Cannot proceed if we could not find a zone
73 if [ -z "${ZONE}" ]; then
74 logger
"Could not find a bridged zone for ${INTERFACE}"
78 # Determine the mode of this zone
79 MODE
="$(get_value "${ZONE}_MODE
")"
81 # The name of the virtual bridge
82 BRIDGE
="$(get_value "${ZONE}_DEV
")"
83 STP
="$(get_value "${ZONE}_STP
")"
84 STP_PRIORITY
="$(get_value "${ZONE}_STP_PRIORITY
")"
88 # We need to check if $STP_PRIORITY has a valid value if not set it
89 if [ -z "${STP_PRIORITY}" ]; then
93 ADDRESS
="$(get_value "${ZONE}_MACADDR
")"
94 [ -n "${ADDRESS}" ] || ADDRESS
="$(random_mac_address)"
96 # We need to create the bridge if it doesn't exist, yet
97 if [ ! -d "/sys/class/net/${BRIDGE}" ]; then
98 ip link add
"${BRIDGE}" address
"${ADDRESS}" type bridge \
99 $
([ "${STP}" = "on" ] && echo "stp_state 1 priority ${STP_PRIORITY}" )
100 #ip link set "${BRIDGE}" up
103 # Try setting wireless interfaces into master mode
104 if [ -d "/sys/class/net/${INTERFACE}/phy80211" ]; then
105 iw dev
"${INTERFACE}" set type __ap
108 # Attach the physical device
109 logger
"Attach ${INTERFACE} to ${BRIDGE}"
110 ip link
set dev
"${INTERFACE}" master
"${BRIDGE}"
111 ip link
set dev
"${INTERFACE}" up
119 logger
-t "network" "Unhandled mode '${MODE}' for '${ZONE}' (${INTERFACE})"