#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### . /usr/lib/network/header-port HOOK_SETTINGS=( "ADDRESS" "PARENT_PORT" "TAG" ) PORT_PARENTS_VAR="PARENT_PORT" hook_check_settings() { assert isset PARENT_PORT assert isinteger TAG if isset ADDRESS; then assert ismac ADDRESS fi if [ ${TAG} -gt 4096 ]; then error "TAG is greater than 4096." exit ${EXIT_ERROR} fi local reserved for reserved in 0 4095; do if [ "${TAG}" = "${reserved}" ]; then error "TAG=${reserved} is reserved." exit ${EXIT_ERROR} fi done } hook_find_port_name() { assert isset PARENT_PORT assert isset TAG print "${PARENT_PORT}${VLAN_PORT_INTERFIX}${TAG}" } hook_parse_cmdline() { while [ $# -gt 0 ]; do case "${1}" in --address=*) ADDRESS=$(cli_get_val "${1}") # Validate address if ! mac_is_valid "${ADDRESS}"; then error "Invalid MAC address given: ${ADDRESS}" return ${EXIT_CONF_ERROR} fi ;; --port=*) PARENT_PORT=$(cli_get_val "${1}") # Check if PARENT_PORT exists if ! port_exists "${PARENT_PORT}"; then error "Port '${PARENT_PORT}' does not exist" return ${EXIT_CONF_ERROR} fi ;; --tag=*) TAG=$(cli_get_val "${1}") ;; *) error "Unknown argument '${1}'" return ${EXIT_CONF_ERROR} ;; esac shift done # Generate a random MAC address if none given if ! isset ADDRESS; then ADDRESS="$(mac_generate)" fi } hook_create() { local port="${1}" assert isset port device_exists "${port}" && exit ${EXIT_OK} # Read configruation if ! port_settings_read "${port}"; then return ${EXIT_ERROR} fi # Check if the parent port exists if ! port_exists "${PARENT_PORT}"; then error "Port '${PARENT_PORT}' does not exist" return ${EXIT_ERROR} fi # Create the VLAN device if ! vlan_create "${port}" \ --address="${ADDRESS}" \ --parent="${PARENT_PORT}" \ --tag="${TAG}"; then error "Could not create port: ${port}" return ${EXIT_ERROR} fi return ${EXIT_OK} } hook_remove() { local port="${1}" assert isset port if device_exists "${port}"; then vlan_remove "${port}" fi exit ${EXIT_OK} }