From: Michael Tremer Date: Sun, 23 Sep 2012 19:18:47 +0000 (+0000) Subject: vlan: Rewrite VLAN stuff. X-Git-Tag: 005~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7951525a2ca2d0e0f01e0180a59260979b55992f;p=network.git vlan: Rewrite VLAN stuff. Got rid of vconfig and clean up a lot of stuff. --- diff --git a/functions.cli b/functions.cli index 5d5b9143..66d7be5a 100644 --- a/functions.cli +++ b/functions.cli @@ -118,7 +118,7 @@ function cli_device_headline() { if enabled long; then # Virtual devices. - device_is_virtual ${device} && cli_device_virtual ${device} + device_is_vlan ${device} && cli_device_vlan ${device} # Bonded devices. device_is_bonded ${device} && cli_device_bonded ${device} @@ -154,13 +154,13 @@ function cli_device_stats() { cli_space } -function cli_device_virtual() { +function cli_device_vlan() { local device=${1} cli_headline 2 "VLAN" - cli_print_fmt1 2 "Parent" "$(virtual_get_parent ${device})" - cli_print_fmt1 2 "VID" "$(virtual_get_id ${device})" + cli_print_fmt1 2 "Parent" "$(vlan_get_parent ${device})" + cli_print_fmt1 2 "VID" "$(vlan_get_id ${device})" cli_space } diff --git a/functions.device b/functions.device index c9836c0c..6de949e0 100644 --- a/functions.device +++ b/functions.device @@ -185,36 +185,41 @@ function device_get_bridge() { device_ifindex_to_name ${ifindex} } -# Check if the device is a virtual device -function device_is_virtual() { +# Check if the device is a vlan device +function device_is_vlan() { local device=${1} + assert isset device - [ -e "/proc/net/vlan/${device}" ] + [ -e "${PROC_NET_VLAN}/${device}" ] } -# Check if the device has virtual devices -function device_has_virtuals() { +# Check if the device has vlan devices +function device_has_vlans() { local device=${1} + assert isset device - if device_is_virtual ${device}; then + if device_is_vlan ${device}; then return ${EXIT_FALSE} fi - local virtuals=$(device_get_virtuals ${device}) - [ -n "${virtuals}" ] && return ${EXIT_OK} || return ${EXIT_ERROR} + local vlans=$(device_get_vlans ${device}) + [ -n "${vlans}" ] && return ${EXIT_OK} || return ${EXIT_ERROR} } -function device_get_virtuals() { +function device_get_vlans() { local device=${1} + assert isset device # If no 8021q module has been loaded into the kernel, # we cannot do anything. - [ -r "/proc/net/vlan/config" ] || return ${EXIT_OK} + [ -r "${PROC_NET_VLAN_CONFIG}" ] || return ${EXIT_OK} local dev spacer1 id spacer2 parent while read dev spacer1 id spacer2 parent; do - [ "${parent}" = "${device}" ] && echo "${dev}" - done < /proc/net/vlan/config | sort + [ "${parent}" = "${device}" ] || continue + + print "${dev}" + done < ${PROC_NET_VLAN_CONFIG} } # Check if the device is a ppp device @@ -267,7 +272,7 @@ function device_is_ethernet() { device_is_ppp ${device} && \ return ${EXIT_ERROR} - device_is_virtual ${device} && \ + device_is_vlan ${device} && \ return ${EXIT_ERROR} [ "$(__device_get_file ${device} type)" != "1" ] && \ @@ -280,7 +285,7 @@ function device_is_ethernet() { function device_get_type() { local device=${1} - if device_is_virtual ${device}; then + if device_is_vlan ${device}; then echo "vlan" elif device_is_bonding ${device}; then @@ -419,7 +424,7 @@ function device_is_free() { function device_is_used() { local device=${1} - device_has_virtuals ${device} && \ + device_has_vlans ${device} && \ return ${EXIT_OK} device_is_bonded ${device} && \ return ${EXIT_OK} @@ -483,8 +488,8 @@ function device_set_parent_up() { local device=${1} local parent - if device_is_virtual ${device}; then - parent=$(virtual_get_parent ${device}) + if device_is_vlan ${device}; then + parent=$(vlan_get_parent ${device}) device_is_up ${parent} && return ${EXIT_OK} @@ -520,8 +525,8 @@ function device_set_parent_down() { local device=${1} local parent - if device_is_virtual ${device}; then - parent=$(virtual_get_parent ${device}) + if device_is_vlan ${device}; then + parent=$(vlan_get_parent ${device}) device_is_up ${parent} || return ${EXIT_OK} diff --git a/functions.virtual b/functions.virtual deleted file mode 100644 index ba037ba8..00000000 --- a/functions.virtual +++ /dev/null @@ -1,197 +0,0 @@ -#!/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 . # -# # -############################################################################### - -function virtual_init() { - module_load 8021q - - ebtables-restore </dev/null - vconfig add ${port} ${vid} >/dev/null - - if [ $? -ne ${EXIT_OK} ]; then - error_log "Could not create virtual device '${newport}'." - return ${EXIT_ERROR} - fi - - oldport=$(virtual_get_by_parent_and_vid ${port} ${vid}) - - fi - - assert device_exists ${oldport} - - if ! device_exists ${oldport}; then - error "Could not determine the created virtual device '${newport}'." - return ${EXIT_ERROR} - fi - - # The device is expected to be named like ${port}.${vid} - # and will be renamed to the virtual schema - device_set_name ${oldport} ${newport} - - if [ $? -ne ${EXIT_OK} ]; then - error_log "Could not set name of virtual device '${newport}'." - return ${EXIT_ERROR} - fi - - assert device_exists ${newport} - - # Setting new mac address - device_set_address ${newport} ${mac} - - if [ $? -ne ${EXIT_OK} ]; then - error_log "Could not set address '${mac}' to virtual device '${newport}'." - return ${EXIT_ERROR} - fi - - # Bring up the new device - device_set_up ${newport} - - return ${EXIT_OK} -} - -function virtual_remove() { - local device=${1} - - log INFO "Removing virtual device '${device}' with address '$(macify ${device})'." - - device_set_down ${device} - - vconfig rem ${device} >/dev/null - - if [ $? -ne ${EXIT_OK} ]; then - error_log "Could not remote virtual device '${newport}'." - return ${EXIT_ERROR} - fi - - return ${EXIT_OK} -} - -function virtual_get_parent() { - local device=${1} - - # Nothing to do, if 8021q module is not loaded. - [ -r "/proc/net/vlan/config" ] || return ${EXIT_OK} - - local dev spacer1 id spacer2 parent - while read dev spacer1 id spacer2 parent; do - if [ "${device}" = "${dev}" ]; then - echo "${parent}" - return ${EXIT_OK} - fi - done < /proc/net/vlan/config - - return ${EXIT_ERROR} -} - -function virtual_get_id() { - local device=${1} - - # Nothing to do, if 8021q module is not loaded. - [ -r "/proc/net/vlan/config" ] || return ${EXIT_OK} - - local dev spacer1 id spacer2 parent - while read dev spacer1 id spacer2 parent; do - if [ "${device}" = "${dev}" ]; then - echo "${id}" - return ${EXIT_OK} - fi - done < /proc/net/vlan/config - - return ${EXIT_ERROR} -} - -function virtual_get_by_parent_and_vid() { - local parent=${1} - local vid=${2} - - assert isset parent - assert isset vid - - # Nothing to do, if 8021q module is not loaded. - [ -r "/proc/net/vlan/config" ] || return ${EXIT_OK} - - local dev spacer1 id spacer2 par - while read dev spacer1 id spacer2 par; do - if [ "${parent}" = "${par}" ] && [ "${vid}" = "${id}" ]; then - echo "${dev}" - return ${EXIT_OK} - fi - done < /proc/net/vlan/config - - return ${EXIT_ERROR} -} diff --git a/functions.vlan b/functions.vlan new file mode 100644 index 00000000..8bcf169d --- /dev/null +++ b/functions.vlan @@ -0,0 +1,156 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2012 IPFire Network Development Team # +# # +# 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 . # +# # +############################################################################### + +PROC_NET_VLAN="/proc/net/vlan" +PROC_NET_VLAN_CONFIG="${PROC_NET_VLAN}/config" + +VLAN_PORT_INTERFIX="v" + +function vlan_init() { + ebtables-restore <