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"
37 # Parse command line arguments
38 while [ $# -gt 0 ]; do
41 address
=$
(cli_get_val
"${1}")
44 id
=$
(cli_get_val
"${1}")
47 parent
=$
(cli_get_val
"${1}")
50 error
"Unrecognized argument: ${1}"
57 # Generate a random MAC address if none was passed
58 if ! isset address
; then
59 address
="$(mac_generate)"
62 # Check if address is valid
63 if ! ismac address
; then
64 log ERROR
"Invalid mac address: ${address}"
68 # Check if a device with the name does already exist
69 if device_exists
"${device}"; then
70 log ERROR
"Device '${device}' already exists"
74 # Check if the parent device exists
75 if ! device_exists
"${parent}"; then
76 log ERROR
"Parent device '${parent}' does not exist"
82 ip link add link
"${parent}" name
"${device}"
83 address
"${address}" type vlan id
"${id}"
87 if ! cmd_quiet
"${command[*]}"; then
88 log ERROR
"Could not create VLAN device ${device}: $?"
92 log DEBUG
"Created VLAN device ${device} (parent = ${parent}, id = ${id})"
105 # Nothing to do, if 8021q module is not loaded.
106 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
108 local dev spacer1 id spacer2 parent
109 while read dev spacer1 id spacer2 parent
; do
110 [ "${device}" = "${dev}" ] ||
continue
114 done < ${PROC_NET_VLAN_CONFIG}
123 # Nothing to do, if 8021q module is not loaded.
124 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
126 local dev spacer1 id spacer2 parent
127 while read dev spacer1 id spacer2 parent
; do
128 [ "${device}" = "${dev}" ] ||
continue
132 done < ${PROC_NET_VLAN_CONFIG}
137 vlan_get_by_parent_and_vid
() {
144 # Nothing to do, if 8021q module is not loaded.
145 [ -r "${PROC_NET_VLAN_CONFIG}" ] ||
return ${EXIT_OK}
147 local dev spacer1 id spacer2 par
148 while read dev spacer1 id spacer2 par
; do
149 [ "${parent}" = "${par}" ] ||
continue
150 [ "${vid}" = "${id}" ] ||
continue
154 done < ${PROC_NET_VLAN_CONFIG}