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
50 # Parse command line arguments
51 while [ $# -gt 0 ]; do
54 address
=$
(cli_get_val
"${1}")
57 parent
=$
(cli_get_val
"${1}")
60 tag
=$
(cli_get_val
"${1}")
63 error
"Unrecognized argument: ${1}"
70 # Generate a random MAC address if none was passed
71 if ! isset address
; then
72 address
="$(mac_generate)"
75 # Check if address is valid
76 if ! ismac address
; then
77 log ERROR
"Invalid mac address: ${address}"
81 # Check if a device with the name does already exist
82 if device_exists
"${device}"; then
83 log ERROR
"Device '${device}' already exists"
87 # Check if the parent device exists
88 if ! device_exists
"${parent}"; then
89 log ERROR
"Parent device '${parent}' does not exist"
93 # Load ebtables stuff.
98 ip link add link
"${parent}" name
"${device}"
99 address
"${address}" type vlan id
"${tag}"
103 if ! cmd_quiet
"${command[*]}"; then
104 log ERROR
"Could not create VLAN device ${device}: $?"
108 log DEBUG
"Created VLAN device ${device} (parent = ${parent}, id = ${tag})"
121 # Nothing to do, if 8021q module is not loaded.
122 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
124 local dev spacer1 id spacer2 parent
125 while read dev spacer1 id spacer2 parent
; do
126 [ "${device}" = "${dev}" ] ||
continue
130 done < ${PROC_NET_VLAN_CONFIG}
139 # Nothing to do, if 8021q module is not loaded.
140 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
142 local dev spacer1 id spacer2 parent
143 while read dev spacer1 id spacer2 parent
; do
144 [ "${device}" = "${dev}" ] ||
continue
148 done < ${PROC_NET_VLAN_CONFIG}
153 vlan_get_by_parent_and_vid
() {
160 # Nothing to do, if 8021q module is not loaded.
161 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
163 local dev spacer1 id spacer2 par
164 while read dev spacer1 id spacer2 par
; do
165 [ "${parent}" = "${par}" ] ||
continue
166 [ "${vid}" = "${id}" ] ||
continue
170 done < ${PROC_NET_VLAN_CONFIG}