From: Michael Tremer Date: Sun, 23 Sep 2012 14:21:17 +0000 (+0000) Subject: Add hook for dummy ports. X-Git-Tag: 005~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd86d39fee0951fadd7a8bae5c301e154de07ef6;p=network.git Add hook for dummy ports. --- diff --git a/functions.dummy b/functions.dummy new file mode 100644 index 00000000..13c00694 --- /dev/null +++ b/functions.dummy @@ -0,0 +1,54 @@ +#!/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 . # +# # +############################################################################### + +DUMMY_PORT_PATTERN="dN" + +function dummy_create() { + local device=${1} + assert isset device + + local address=${2} + isset address || address=$(mac_generate) + assert ismac address + + if device_exists ${device}; then + log ERROR "dummy device '${device}' does already exist" + return ${EXIT_ERROR} + fi + + cmd_quiet "ip link add name ${device} address ${address} type dummy" + local ret=$? + + if [ ${ret} -eq ${EXIT_OK} ]; then + log DEBUG "dummy device '${device}' has been created" + else + log ERROR "could not create dummy device '${dummy}': ${ret}" + fi + + return ${ret} +} + +function dummy_remove() { + local device=${1} + assert isset device + + device_delete ${device} +} diff --git a/hooks/ports/dummy b/hooks/ports/dummy new file mode 100755 index 00000000..ff430c0a --- /dev/null +++ b/hooks/ports/dummy @@ -0,0 +1,125 @@ +#!/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="HOOK ADDRESS" + +function _check() { + assert ismac ADDRESS +} + +function _create() { + while [ $# -gt 0 ]; do + case "${1}" in + --address=*) + ADDRESS=$(cli_get_val ${1}) + ;; + *) + warning "Unknown argument '${1}'" + ;; + esac + shift + done + + # Generate a random MAC address if non was set. + if ! isset ADDRESS; then + ADDRESS=$(mac_generate) + fi + + local port=$(port_find_free ${DUMMY_PORT_PATTERN}) + assert isset port + + if config_write $(port_file ${port}) ${HOOK_SETTINGS}; then + log INFO "New dummy port '${port}' has been created" + fi + + exit ${EXIT_OK} +} + +function _edit() { + local port=${1} + assert isset port + shift + + config_read $(port_file ${port}) + + while [ $# -gt 0 ]; do + case "${1}" in + --address=*) + ADDRESS=$(cli_get_val ${1}) + ;; + *) + warning "Unknown argument '${1}'" + ;; + esac + shift + done + + config_write $(port_file ${port}) ${HOOK_SETTINGS} + + exit ${EXIT_OK} +} + +function _up() { + local port=${1} + assert isset port + + config_read $(port_file ${port}) + + # Create device if not already exists. + if ! device_exists ${port}; then + dummy_create ${port} "${ADDRESS}" + fi + + exit ${EXIT_OK} +} + +function _down() { + local port=${1} + assert isset port + + if ! device_exists ${port}; then + exit ${EXIT_OK} + fi + + dummy_remove ${port} + + exit ${EXIT_OK} +} + +function _hotplug_rename() { + local port=${1} + assert isset port + + local device=${2} + assert isset device + + config_read $(port_file ${port}) + + if [ "${ADDRESS}" = "$(device_get_address ${device})" ]; then + log DEBUG "Device '${device}' equals port '${port}'." + exit ${EXIT_OK} + fi + + log DEBUG "Device '${device}' does not equal port '${port}'." + exit ${EXIT_ERROR} +} diff --git a/hooks/zones/bridge.ports/dummy b/hooks/zones/bridge.ports/dummy new file mode 120000 index 00000000..3857774a --- /dev/null +++ b/hooks/zones/bridge.ports/dummy @@ -0,0 +1 @@ +ethernet \ No newline at end of file