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"
31 if ! isinteger id
; then
35 # Must be between 1 and 4095
36 if [ ${id} -ge 1 ] && [ ${id} -le 4096 ]; then
40 # Otherwise this is invalid
54 # Parse command line arguments
55 while [ $# -gt 0 ]; do
58 address
=$
(cli_get_val
"${1}")
61 id
=$
(cli_get_val
"${1}")
64 parent
=$
(cli_get_val
"${1}")
67 error
"Unrecognized argument: ${1}"
74 # Generate a random MAC address if none was passed
75 if ! isset address
; then
76 address
="$(mac_generate)"
79 # Check if address is valid
80 if ! ismac address
; then
81 log ERROR
"Invalid mac address: ${address}"
86 if ! vlan_valid_id
"${id}"; then
87 log ERROR
"Invalid VLAN ID: ${id}"
91 # Check if a device with the name does already exist
92 if device_exists
"${device}"; then
93 log ERROR
"Device '${device}' already exists"
97 # Check if the parent device exists
98 if ! device_exists
"${parent}"; then
99 log ERROR
"Parent device '${parent}' does not exist"
105 ip link add link
"${parent}" name
"${device}"
106 address
"${address}" type vlan id
"${id}"
110 if ! cmd_quiet
"${command[*]}"; then
111 log ERROR
"Could not create VLAN device ${device}: $?"
115 log DEBUG
"Created VLAN device ${device} (parent = ${parent}, id = ${id})"
128 # Nothing to do, if 8021q module is not loaded.
129 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
131 local dev spacer1 id spacer2 parent
132 while read dev spacer1 id spacer2 parent
; do
133 [ "${device}" = "${dev}" ] ||
continue
137 done < ${PROC_NET_VLAN_CONFIG}
146 # Nothing to do, if 8021q module is not loaded.
147 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
149 local dev spacer1 id spacer2 parent
150 while read dev spacer1 id spacer2 parent
; do
151 [ "${device}" = "${dev}" ] ||
continue
155 done < ${PROC_NET_VLAN_CONFIG}
160 vlan_get_by_parent_and_vid
() {
167 # Nothing to do, if 8021q module is not loaded.
168 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
170 local dev spacer1 id spacer2 par
171 while read dev spacer1 id spacer2 par
; do
172 [ "${parent}" = "${par}" ] ||
continue
173 [ "${vid}" = "${id}" ] ||
continue
177 done < ${PROC_NET_VLAN_CONFIG}