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 ###############################################################################
22 PROC_NET_VLAN
="/proc/net/vlan"
23 PROC_NET_VLAN_CONFIG
="${PROC_NET_VLAN}/config"
25 VLAN_PORT_INTERFIX
="v"
28 ebtables-restore
<<EOF
36 -A BROUTING -p 802_1Q -j DROP
51 if isset address
; then
55 # Check if a device with the name does already exist.
56 if device_exists
${device}; then
57 log ERROR
"device '${device}' does already exist"
61 # Check if the parent device exists.
62 if ! device_exists
${parent}; then
63 log ERROR
"parent device '${parent}' does not exist"
67 # Load ebtables stuff.
70 local command="ip link add link ${parent} name ${device}"
72 if isset address
; then
73 command="${command} address ${address}"
76 command="${command} type vlan id ${tag}"
81 if [ ${ret} -eq ${EXIT_OK} ]; then
82 log DEBUG
"vlan device '${device}' has been created"
84 log ERROR
"could not create vlan device '${device}': ${ret}"
94 # Set down device (if not already done).
95 device_set_down
${device}
97 device_delete
${device}
104 # Nothing to do, if 8021q module is not loaded.
105 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
107 local dev spacer1 id spacer2 parent
108 while read dev spacer1 id spacer2 parent
; do
109 [ "${device}" = "${dev}" ] ||
continue
113 done < ${PROC_NET_VLAN_CONFIG}
122 # Nothing to do, if 8021q module is not loaded.
123 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
125 local dev spacer1 id spacer2 parent
126 while read dev spacer1 id spacer2 parent
; do
127 [ "${device}" = "${dev}" ] ||
continue
131 done < ${PROC_NET_VLAN_CONFIG}
136 vlan_get_by_parent_and_vid
() {
143 # Nothing to do, if 8021q module is not loaded.
144 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
146 local dev spacer1 id spacer2 par
147 while read dev spacer1 id spacer2 par
; do
148 [ "${parent}" = "${par}" ] ||
continue
149 [ "${vid}" = "${id}" ] ||
continue
153 done < ${PROC_NET_VLAN_CONFIG}