2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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 .
/usr
/lib
/network
/header-port
31 # Set the default to 802.1Q
32 DEFAULT_PROTOCOL
="${VLAN_SUPPORTED_PROTOCOLS[0]}"
34 PORT_PARENTS_VAR
="PARENT_PORT"
36 hook_check_settings
() {
38 assert isset PARENT_PORT
41 assert vlan_supported_protocol
"${PROTOCOL}"
44 assert vlan_valid_id
"${ID}"
47 hook_find_port_name
() {
49 assert isset PARENT_PORT
51 print
"${PARENT_PORT}${VLAN_PORT_INTERFIX}${ID}"
54 hook_parse_cmdline
() {
55 while [ $# -gt 0 ]; do
58 ADDRESS
=$
(cli_get_val
"${1}")
61 if ! mac_is_valid
"${ADDRESS}"; then
62 error
"Invalid MAC address given: ${ADDRESS}"
63 return ${EXIT_CONF_ERROR}
67 ID
=$
(cli_get_val
"${1}")
70 if ! vlan_valid_id
"${ID}"; then
71 error
"Invalid VLAN ID: ${ID}"
72 return ${EXIT_CONF_ERROR}
76 PARENT_PORT
=$
(cli_get_val
"${1}")
78 # Check if PARENT_PORT exists
79 if ! port_exists
"${PARENT_PORT}"; then
80 error
"Port '${PARENT_PORT}' does not exist"
81 return ${EXIT_CONF_ERROR}
85 PROTOCOL
="$(cli_get_val "${1}")"
87 # Check if PROTOCOL is supported
88 if ! vlan_supported_protocol
"${PROTOCOL}"; then
89 error
"Protocol '${PROTOCOL}' is not supported"
90 error
"Choose one of ${VLAN_SUPPORTED_PROTOCOLS[*]}"
91 return ${EXIT_CONF_ERROR}
95 error
"Unknown argument '${1}'"
96 return ${EXIT_CONF_ERROR}
102 # Generate a random MAC address if none given
103 if ! isset ADDRESS
; then
104 ADDRESS
="$(mac_generate)"
112 device_exists
"${port}" && exit ${EXIT_OK}
115 if ! port_settings_read
"${port}"; then
119 # Check if the parent port exists
120 if ! port_exists
"${PARENT_PORT}"; then
121 error
"Port '${PARENT_PORT}' does not exist"
125 # Create the partent port first
126 if ! port_create
"${PARENT_PORT}"; then
127 error
"Could not bring up parent port: ${PARENT_PORT}"
131 # Create the VLAN device
132 if ! vlan_create
"${port}" \
133 --address="${ADDRESS}" \
135 --parent="${PARENT_PORT}" \
136 --protocol="${PROTOCOL}"; then
137 error
"Could not create port: ${port}"
148 if device_exists
"${port}"; then
149 vlan_remove
"${port}"