From: Michael Tremer Date: Mon, 2 Mar 2009 20:55:52 +0000 (+0100) Subject: I worked on that stupid networking stuff... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae69ea7e49754d8d667832995050c34a951301c0;p=ipfire-3.x.git I worked on that stupid networking stuff... Don't expect that this works, but I wanted to commit it. --- diff --git a/src/initscripts/core/network b/src/initscripts/core/network index 2cc3a0697..9f42d1c3a 100644 --- a/src/initscripts/core/network +++ b/src/initscripts/core/network @@ -17,41 +17,23 @@ ### END INIT INFO . /lib/lsb/init-functions -. /etc/sysconfig/network +. /etc/init.d/networking/functions case "${1}" in start) # Start all network interfaces - for file in $(find ${NETWORK_DEVICES} -maxdepth 1); do - interface=${file##*/} - - if [ -d "${file}" ] || [ -n "${interface}" ]; then - continue - fi - - IN_BOOT=1 ${NETWORK_SCRIPTS}/brup ${interface} + for zone in $(find ${CONFIG_ZONES}/ -maxdepth 1); do + [ -d "${zone}" ] || continue + IN_BOOT=1 /etc/init.d/networking/zone ${zone##*/} up done touch /var/lock/subsys/network ;; stop) - # Reverse list - FILES="" - for file in $(find ${NETWORK_DEVICES} -maxdepth 1); do - interface=${file##*/} - - if [ -d "${file}" ] || [ -n "${interface}" ]; then - continue - fi - FILES="${file} ${FILES}" - done - # Stop all network interfaces - for file in ${FILES} - do - interface=${file##*/} - - IN_BOOT=1 ${NETWORK_SCRIPTS}/brdown ${interface} + for zone in $(find ${CONFIG_ZONES}/ -maxdepth 1); do + [ -d "${zone}" ] || continue + IN_BOOT=1 /etc/init.d/networking/zone ${zone##*/} down done rm -f /var/lock/subsys/network ;; diff --git a/src/initscripts/networking/brdown b/src/initscripts/networking/brdown deleted file mode 100644 index 68a005f4e..000000000 --- a/src/initscripts/networking/brdown +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -######################################################################## -# Begin $NETWORK_DEVICES/brdown -# -# Description : Bridge Down -# -# Authors : Michael Tremer - michael.tremer@ipfire.org -# -# Version : 00.00 -# -# Notes : This script removes the created bridge, removes -# all child interface from it and then -# the IFCONFIG variable is passed to the scripts found -# in the services directory, to indicate what file the -# service should source to get environmental variables. -# -######################################################################## - -. /lib/lsb/init-functions - -message="Bringing down the ${1} interface..." - -# Collect a list of configuration files for our interface -if [ -n "${2}" ]; then - for file in ${@#$1} # All parameters except $1 - do - FILES="${FILES} ${NETWORK_DEVICES}/${1}/${file}" - done -elif [ -d "${NETWORK_DEVICES}/${1}" ]; then - FILES=`echo ${NETWORK_DEVICES}/${1}/*` -else - FILES="${NETWORK_DEVICES}/${1}" -fi - -# Reverse the order configuration files are processed in -for file in ${FILES}; do - # skip backup files - if [ "${file}" != "${file%""~""}" ]; then - continue - fi - - # place interfaces at last position - if [[ "${file}" =~ "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" ]]; then - FILES2="${FILES2} ${file}" - continue - fi - - # append the rest - FILES2="${file} ${FILES2}" -done -FILES=${FILES2} - -# Process each configuration file -export BRIDGE_DOWN=1 -for file in ${FILES}; do - if [ ! -f "${file}" ]; then - log_warning_msg - message="${file} is not a network configuration file or directory." - log_warning_msg - fi - /etc/init.d/networking/ifdown ${file} -done - -if [ -z "${2}" ]; then - # Check if bridge already exists - bridge_status=`brctl show 2>/dev/null` - if echo "${bridge_status}" | grep -q "^${1}"; then - # Create and bring up the bridge - ip link set ${1} down || failed=1 - brctl delbr ${1} || failed=1 - (exit ${failed}) - evaluate_retval standard - fi -fi - -# End $NETWORK_DEVICES/brdown diff --git a/src/initscripts/networking/brup b/src/initscripts/networking/brup deleted file mode 100644 index 03afe7232..000000000 --- a/src/initscripts/networking/brup +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -######################################################################## -# Begin $NETWORK_DEVICES/brup -# -# Description : Bridge Up -# -# Authors : Michael Tremer - michael.tremer@ipfire.org -# -# Version : 00.00 -# -# Notes : This script creates a bridge with a given name. -# Then all required interfaces are added to the brige and -# the IFCONFIG variable is passed to the scripts found -# in the services directory, to indicate what file the -# service should source to get environmental variables. -# -######################################################################## - -. /lib/lsb/init-functions - -message="Bringing up ${1} interface..." - -# Collect a list of configuration files for our interface -if [ -n "${2}" ]; then - for file in ${@#$1} # All parameters except $1 - do - FILES="${FILES} ${NETWORK_DEVICES}/${1}/${file}" - done -elif [ -d "${NETWORK_DEVICES}/${1}" ]; then - FILES=`echo ${NETWORK_DEVICES}/${1}/*` -else - FILES="${NETWORK_DEVICES}/${1}" -fi - -# Sort files -for file in ${FILES}; do - # skip backup files - if [ "${file}" != "${file%""~""}" ]; then - continue - fi - - # place interfaces at first position - if [[ "${file}" =~ "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" ]]; then - FILES2="${file} ${FILES2}" - continue - fi - - # append the rest - FILES2="${FILES2} ${file}" -done -FILES=${FILES2} - -# Check if bridge already exists -bridge_status=`brctl show 2>/dev/null` -if ! echo "${bridge_status}" | grep -q "^${1}"; then - # Create and bring up the bridge - brctl addbr ${1} || failed=1 - ip link set ${1} up || failed=1 - (exit ${failed}) - evaluate_retval standard -else - log_warning_msg - message="Bridge does already exist." - log_warning_msg -fi - -# Process each configuration file -export BRIDGE_UP=1 -for file in ${FILES}; do - if [ ! -f "${file}" ]; then - log_warning_msg - message="${file} is not a network configuration file or directory." - log_warning_msg - fi - /etc/init.d/networking/ifup ${file} -done diff --git a/src/initscripts/networking/functions b/src/initscripts/networking/functions index ee65e3c63..5dd1bec52 100644 --- a/src/initscripts/networking/functions +++ b/src/initscripts/networking/functions @@ -19,23 +19,56 @@ # # ############################################################################### -[ -f "/etc/sysconfig/network" ] && . /etc/sysconfig/network +CONFIG_DIR=/etc/sysconfig/networking + +CONFIG_ZONES=${CONFIG_DIR}/zones +CONFIG_PORTS=${CONFIG_DIR}/ports function is_mac() { - egrep "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" <<<$1 + egrep -q "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" <<<$1 } function get_device_by_mac() { - local mac=$1 + local mac + local i + + mac=$1 + for i in /sys/class/net/*; do if [ "$(cat $i/address)" = "$mac" ]; then - echo $(basename $i) + grep -q "^${i##*/}" /proc/net/vlan/config 2>/dev/null && continue + echo ${i##*/} + break fi done } +function get_device_by_mac_and_vid() { + local mac + local vid + + mac=$1 + vid=$2 + + local i + local VID + local DEVICE + for i in $(cat /proc/net/vlan/config 2>/dev/null); do + awk -F'|' '{ print $2 $3 }' | read DEVICE VID PARENT + if [ -n "${VID}" ] || [ -n "${DEVICE}" ]; then + continue + fi + if [ "${vid}" = "${VID}" ] && [ "$(macify ${PARENT})" = "${mac}" ]; then + echo "${DEVICE}" + return 0 + fi + done + return 1 +} + function get_mac_by_device() { - local device=$1 + local device + device=$1 if [ -d "/sys/class/net/$device" ]; then cat /sys/class/net/$device/address return 0 @@ -43,8 +76,51 @@ function get_mac_by_device() { return 1 } +function devicify() { + local device + local mac + + device=$1 + + if is_mac ${device}; then + mac=${device} + device=$(get_device_by_mac ${device}) + fi + echo ${device} +} + +function macify() { + local input + local mac + + input=$1 + + if is_mac ${input}; then + mac=${input} + else + mac=$(get_mac_by_device ${input}) + fi + echo ${mac} +} + function device_exists() { - ip link show ${1} &>/dev/null + ip link show $(devicify ${1}) &>/dev/null +} + +function rename_device() { + local source + local destination + + source=$1 + destination=$2 + + # Check if devices exist + if ! device_exists ${source} || device_exists ${destination}; then + return 4 + fi + + ip link set ${source} name ${destination} + return $? } function zone_exists() { @@ -52,5 +128,19 @@ function zone_exists() { } function bridge_devices() { - : #TODO + local bridge + bridge=$1 + [ -z "${bridge}" ] && return 2 + brctl show | grep "^${bridge}" | awk '{ print $NF }' | grep -v "^interfaces$" +} + +function zone_add_port() { + brctl addif ${1} ${2} +} + +function all_zones() { + local zone + for zone in ${CONFIG_ZONES}/*; do + [ -d "${zone}" ] && echo ${zone} + done } diff --git a/src/initscripts/networking/hooks/bridge-slave b/src/initscripts/networking/hooks/bridge-slave index 16b9eb7e2..62ef54deb 100644 --- a/src/initscripts/networking/hooks/bridge-slave +++ b/src/initscripts/networking/hooks/bridge-slave @@ -13,7 +13,7 @@ ######################################################################## . /lib/lsb/init-functions -. ${IFCONFIG} +[ -n "${CONFIG}" ] && . ${CONFIG} interface=${IFCONFIG##*/} diff --git a/src/initscripts/networking/hooks/ethernet b/src/initscripts/networking/hooks/ethernet index ca247be6b..72842d165 100644 --- a/src/initscripts/networking/hooks/ethernet +++ b/src/initscripts/networking/hooks/ethernet @@ -13,7 +13,10 @@ ######################################################################## . /lib/lsb/init-functions -. ${CONFIG} +. /etc/init.d/networking/functions +[ -n "${CONFIG}" ] && . ${CONFIG} + +port=$(macify ${1}) case "${2}" in up) @@ -24,8 +27,22 @@ case "${2}" in : # Do nothing ;; + add) + cat < ${CONFIG_PORTS}/${port}/ethernet +HOOK=ethernet +EOF + ln -sf ${CONFIG_PORTS}/${port}/ethernet \ + ${CONFIG_ZONES}/${ZONE}/port-${port}-ethernet + ;; + + remove) + rm -f \ + ${CONFIG_ZONES}/${ZONE}/port-${port}-ethernet \ + ${CONFIG_PORTS}/${port}/ethernet + ;; + *) - echo "Usage: ${0} [interface] {up|down}" + echo "Usage: ${0} [interface] {up|down|add|remove}" exit 1 ;; esac diff --git a/src/initscripts/networking/hooks/ipv4-static b/src/initscripts/networking/hooks/ipv4-static index 417d22de6..1a192764f 100644 --- a/src/initscripts/networking/hooks/ipv4-static +++ b/src/initscripts/networking/hooks/ipv4-static @@ -14,7 +14,7 @@ ######################################################################## . /lib/lsb/init-functions -. ${IFCONFIG} +[ -n "${CONFIG}" ] && . ${CONFIG} if [ -z "${IP}" ]; then log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue." diff --git a/src/initscripts/networking/hooks/ipv4-static-route b/src/initscripts/networking/hooks/ipv4-static-route index 4205a022d..7dc90fe9f 100644 --- a/src/initscripts/networking/hooks/ipv4-static-route +++ b/src/initscripts/networking/hooks/ipv4-static-route @@ -13,7 +13,7 @@ ######################################################################## . /lib/lsb/init-functions -. ${IFCONFIG} +[ -n "${CONFIG}" ] && . ${CONFIG} case "${TYPE}" in ("" | "network") diff --git a/src/initscripts/networking/hooks/stp b/src/initscripts/networking/hooks/stp index ee294fc15..9e87e4a85 100644 --- a/src/initscripts/networking/hooks/stp +++ b/src/initscripts/networking/hooks/stp @@ -13,7 +13,7 @@ ######################################################################## . /lib/lsb/init-functions -. ${IFCONFIG} +[ -n "${CONFIG}" ] && . ${CONFIG} case "${2}" in up) diff --git a/src/initscripts/networking/hooks/vlan b/src/initscripts/networking/hooks/vlan index 43420ef70..907c72f0d 100644 --- a/src/initscripts/networking/hooks/vlan +++ b/src/initscripts/networking/hooks/vlan @@ -13,24 +13,44 @@ ######################################################################## . /lib/lsb/init-functions -. ${CONFIG} +. /etc/init.d/networking/functions +[ -n "${CONFIG}" ] && . ${CONFIG} + +port=$(macify ${1}) +device=$(devicify ${port}) case "${2}" in up) modprobe 8021q - MESSAGE="Adding VLAN ${ID} to interface ${1}..." - vconfig add ${1} ${ID} &>/dev/null + MESSAGE="Adding VLAN ${ID} to port ${port}..." + vconfig add ${device} ${ID} &>/dev/null evaluate_retval ;; down) - MESSAGE="Removing VLAN ${ID} from interface ${1}..." - vconfig rem ${1} ${ID} &>/dev/null + MESSAGE="Removing VLAN ${ID} from port ${port}..." + vconfig rem ${device} ${ID} &>/dev/null evaluate_retval ;; + add) + ID=$3 + cat < ${CONFIG_PORTS}/${port}/vlan-${ID} +HOOK=vlan +ID=${ID} +EOF + ln -sf ${CONFIG_PORTS}/${port}/vlan-${ID} \ + ${CONFIG_ZONES}/${ZONE}/port-${port}-vlan-${ID} + ;; + + remove) + rm -f \ + ${CONFIG_PORTS}/${port}/vlan-${ID} \ + ${CONFIG_ZONES}/${ZONE}/port-${port}-vlan-${ID} + ;; + *) - echo "Usage: ${0} [interface] {up|down}" + echo "Usage: ${0} [interface] {up|down|add|remove}" exit 1 ;; esac diff --git a/src/initscripts/networking/ifdown b/src/initscripts/networking/ifdown deleted file mode 100644 index fe9258e24..000000000 --- a/src/initscripts/networking/ifdown +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -######################################################################## -# Begin $NETWORK_DEVICES/ifdown -# -# Description : Interface Down -# -# Authors : Michael Tremer - michael.tremer@ipfire.org -# -# Version : 00.00 -# -# Notes : This script brings up the configuration of each interface. -# It handles some dependencies. -# -######################################################################## - -. /lib/lsb/init-functions - -file=${1} - -if [ ! -f "${file}" ]; then - message="Unable to process ${file}. File does not exist." - log_failure_msg - exit 1 -fi - -. ${file} - -if [ -n "${SERVICE}" -a -x "${NETWORK_SCRIPTS}/services/${SERVICE}" ]; then - IFCONFIG=${file} ${NETWORK_SCRIPTS}/services/${SERVICE} ${1} down -else - echo -e "${FAILURE}Unable to process ${file}. Either" - echo -e "${FAILURE}the SERVICE variable was not set," - echo -e "${FAILURE}or the specified service cannot be executed." - message="" - log_failure_msg -fi - -# XXX We must check if a bridge has no devices left. - -# End $NETWORK_DEVICES/ifdown diff --git a/src/initscripts/networking/ifup b/src/initscripts/networking/ifup deleted file mode 100644 index 092d13a60..000000000 --- a/src/initscripts/networking/ifup +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -######################################################################## -# Begin $NETWORK_DEVICES/ifup -# -# Description : Interface Up -# -# Authors : Michael Tremer - michael.tremer@ipfire.org -# -# Version : 00.00 -# -# Notes : This script brings up the configuration of each interface. -# It handles some dependencies. -# -######################################################################## - -. /lib/lsb/init-functions - -file=${1} - -if [ ! -f "${file}" ]; then - message="Unable to process ${file}. File does not exist." - log_failure_msg - exit 1 -fi - -. ${file} - -# XXX We must check if a bridge is there and up. - -if [ -n "${SERVICE}" -a -x "${NETWORK_SCRIPTS}/services/${SERVICE}" ]; then - IFCONFIG=${file} ${NETWORK_SCRIPTS}/services/${SERVICE} ${1} up -else - echo -e "${FAILURE}Unable to process ${file}. Either" - echo -e "${FAILURE}the SERVICE variable was not set," - echo -e "${FAILURE}or the specified service cannot be executed." - message="" - log_failure_msg -fi - -# End $NETWORK_DEVICES/ifup diff --git a/src/initscripts/networking/port b/src/initscripts/networking/port new file mode 100644 index 000000000..f2b7e611b --- /dev/null +++ b/src/initscripts/networking/port @@ -0,0 +1,107 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2009 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 . # +# # +############################################################################### + +. /lib/lsb/init-functions +. /etc/init.d/networking/functions + +port=$(macify $1) +action=$2 + +shift 2 + +if ! device_exists ${port}; then + echo "Port ${port} does not exist." + exit 1 +fi + +if [ -z "${port}" ] || [ -z "${action}" ]; then + echo "Usage: $0 [hooks]" + echo +fi + +for arg in ${@-$(find ${CONFIG_PORTS}/${port}/)}; do + arg=${arg##*/} + [ -e "${CONFIG_PORTS}/${port}/${arg}" ] || continue + hooks="${hooks} ${CONFIG_PORTS}/${port}/${arg}" +done + +echo "DEBUG: hooks: $hooks" + +# Getting zone variable +#local zone +#if [ -z "$ZONE" ]; then +# for zone in $(all_zones); do +# for i in ${zone}/port-*; do +# i=$(readlink ${i}) +# for j in ${ports}; do +# if [ "${i}" = "${j}" ]; then +# ZONE=${i%/*} +# ZONE=${ZONE##*/} +# fi +# done +# done +# done +#fi + +case "$action" in + up) + message="Setting up port ${port}..." + ip link set $(devicify ${port}) up + evaluate_retval + + for hook in ${hooks}; do + [ -d "${hook}" ] && continue + ( + . ${hook} + if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then + CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${port} up + else + echo -e "${FAILURE}Unable to process ${hook}. Either" + echo -e "${FAILURE}the HOOK variable was not set," + echo -e "${FAILURE}or the specified hook cannot be executed." + message="" + log_failure_msg + fi + ) + done + ;; + down) + for hook in ${hooks}; do + [ -d "${hook}" ] && continue + ( + . ${hook} + if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then + CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${port} down + else + echo -e "${FAILURE}Unable to process ${hook}. Either" + echo -e "${FAILURE}the HOOK variable was not set," + echo -e "${FAILURE}or the specified hook cannot be executed." + message="" + log_failure_msg + fi + ) + done + + message="Pushing down port ${port}..." + ip link set $(devicify ${port}) down + evaluate_retval + ;; +esac diff --git a/src/initscripts/networking/zone b/src/initscripts/networking/zone new file mode 100644 index 000000000..54e06c41b --- /dev/null +++ b/src/initscripts/networking/zone @@ -0,0 +1,83 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2009 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 . # +# # +############################################################################### + +. /lib/lsb/init-functions +. /etc/init.d/networking/functions + +zone=$1 +action=$2 + +case "$action" in + up) + message="Bringing up zone ${zone}..." + + # Check if bridge already exists + zone_status=`brctl show 2>/dev/null` + if ! echo "${zone_status}" | grep -q "^${zone}"; then + #/etc/init.d/networking/hooks pre-up ${CONFIG_ZONES}/${zone} + + # Create and bring up the zone + brctl addbr ${zone} || failed=1 + ip link set ${zone} up || failed=1 + (exit ${failed}) + evaluate_retval standard + + [ "${IN_BOOT}" = "1" ] && \ + for port in ${CONFIG_ZONES}/${zone}/port-*; do + #port=$(readlink ${port}) + ZONE=${zone} /etc/init.d/networking/port ${port} up + done + + ###/etc/init.d/networking/hooks post-up ${CONFIG_ZONES}/${zone} + else + log_warning_msg + message="Zone ${zone} does already exist." + log_warning_msg + fi + ;; + + down) + message="Bringing down zone ${zone}..." + # Check if bridge already exists + zone_status=`brctl show 2>/dev/null` + if echo "${zone_status}" | grep -q "^${zone}"; then + #/etc/init.d/networking/hooks pre-down ${CONFIG_ZONES}/${zone} + # remove devices + + for port in ${CONFIG_ZONES}/${zone}/port-*; do + brctl delif ${zone} ${port##*/} + /etc/init.d/networking/port ${port} down + done + + # Bring down the zone and delete it + ip link set ${zone} down || failed=1 + brctl delbr ${zone} || failed=1 + (exit ${failed}) + evaluate_retval standard + + #/etc/init.d/networking/hooks post-down ${CONFIG_ZONES}/${zone} + else + log_warning_msg + message="Zone ${zone} does not exist." + log_warning_msg + fi + ;; +esac diff --git a/src/initscripts/sysconfig/network b/src/initscripts/sysconfig/network index 4cfa7f92f..45e537e7f 100644 --- a/src/initscripts/sysconfig/network +++ b/src/initscripts/sysconfig/network @@ -1,2 +1 @@ HOSTNAME=ipfire.localdomain -NETWORK_DEVICES=/etc/sysconfig/network-devices diff --git a/src/network/network b/src/network/network index cad8d640b..59422f601 100644 --- a/src/network/network +++ b/src/network/network @@ -26,12 +26,7 @@ BOLD="\\033[1;39m" NORMAL="\\033[0;39m" ERROR="\\033[1;31m" -. ../src/initscripts/networking/functions - -CONFIG_DIR=${CONFIG_DIR-/etc/sysconfig/networking} - -CONFIG_ZONES=${CONFIG_DIR}/zones -CONFIG_PORTS=${CONFIG_DIR}/ports +. /etc/init.d/networking/functions function usage() { echo "Usage $0 - TODO" @@ -83,21 +78,6 @@ function _exit() { exit $1 } -function devicify() { - local device - local mac - - device=$1 - - if is_mac ${device}; then - mac=${device} - device=$(get_device_by_mac ${device}) - decho "Figured out that ${mac} is ${device}." - fi - decho "Function: devicify $@ -> ${device}" - echo ${device} -} - function port_show() { local port @@ -114,16 +94,16 @@ function port_show() { function port_add() { local port local zone - local vid + local hook zone=$1 - port=$(devicify $2) - vid=${3-0} + port=$(macify $2) + hook=${3-ethernet} - decho "Function: port_add $@" - decho " Zone: ${zone} Port: ${port} VLAN-ID: ${vid}" + shift 3 - # XXX Check if vlan id is valid + decho "Function: port_add" + decho " Zone: ${zone} Port: ${port} Hook: ${hook} $@" if ! zone_exists ${zone}; then error "Zone ${BOLD}${zone}${NORMAL} does not exist." @@ -131,46 +111,60 @@ function port_add() { fi if [ -z "$port" ]; then - error "Port ${BOLD}${2}${NORMAL} could not be found." + error "Port ${BOLD}${port}${NORMAL} could not be found." return 1 fi - + if ! device_exists ${port}; then error "Port ${BOLD}${port}${NORMAL} does not exist." return 1 fi - local mac - mac=$(get_mac_by_device ${port}) - - mkdir -p ${CONFIG_PORTS}/${mac} 2>/dev/null - touch ${CONFIG_PORTS}/${mac}/${vid} - ln -sf ${CONFIG_PORTS}/${mac}/${vid} ${CONFIG_ZONES}/${zone}/port-${mac}-${vid} - - # XXX add code to bring up device immediately - - vecho "Successfully added port ${BOLD}${port}${NORMAL} (${mac} - ${vid}) to ${BOLD}${zone}${NORMAL}." + mkdir -p ${CONFIG_PORTS}/${port} 2>/dev/null + if [ -x "/etc/init.d/networking/hooks/${hook}" ]; then + ZONE=${zone} /etc/init.d/networking/hooks/${hook} ${port} add $@ + RET=$? + if [ "$RET" -eq "0" ]; then + vecho "Successfully added port ${BOLD}${port}${NORMAL} (${hook} $@) to ${BOLD}${zone}${NORMAL}." + /etc/init.d/networking/port ${port} up + else + error "Hook ${BOLD}${hook}${NORMAL} exited with $RET." + return $RET + fi + else + error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable." + return 1 + fi } function port_del() { local port local zone - local vid - + local hook + zone=$1 port=$(devicify $2) - vid=${3-0} + hook=${3-ethernet} - decho "Function: port_del $@" - decho " Zone: ${zone} Port: ${port} VLAN-ID: ${vid}" + shift 3 - rm -f ${CONFIG_ZONES}/${zone}/port-${mac}-${vid} \ - ${CONFIG_PORTS}/${mac}/${vid} 2>/dev/null - rm -r ${CONFIG_PORTS}/${mac}/ 2>/dev/null # XXX Does this only remove if dir is empty? + decho "Function: port_del" + decho " Zone: ${zone} Port: ${port} Hook: ${hook}" - # XXX add code to bring down device immediately - - vecho "Successfully removed port ${BOLD}${port}${NORMAL} (${mac} - ${vid}) from ${BOLD}${zone}${NORMAL}." + if [ -x "/etc/init.d/networking/hooks/${hook}" ]; then + /etc/init.d/networking/port ${port} down ## XXX How do we identify only that one hook? + ZONE=${zone} /etc/init.d/networking/hooks/${hook} ${port} remove $@ + RET=$? + if [ "$RET" -eq "0" ]; then + vecho "Successfully removed port ${BOLD}${port}${NORMAL} (${hook} $@) from ${BOLD}${zone}${NORMAL}." + else + error "Hook ${BOLD}${hook}${NORMAL} exited with $RET." + return $RET + fi + else + error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable." + return 1 + fi } function zone_show() { @@ -205,7 +199,7 @@ function zone_show() { echo -e "# ${ERROR}Ports:${NORMAL}" local port for port in ${CONFIG_ZONES}/${zone}/port-*; do - port=$(basename ${port}) + port=${port##*/} echo "# ${port#port-}" debug && echo "# TODO: Is port up or down?" done diff --git a/src/rootfiles/core/initscripts b/src/rootfiles/core/initscripts index c5f49cf9c..1519abab8 100644 --- a/src/rootfiles/core/initscripts +++ b/src/rootfiles/core/initscripts @@ -15,18 +15,18 @@ etc/init.d/mountfs etc/init.d/mountkernfs etc/init.d/network etc/init.d/networking -etc/init.d/networking/brdown -etc/init.d/networking/brup etc/init.d/networking/functions -etc/init.d/networking/ifdown -etc/init.d/networking/ifup +etc/init.d/networking/hooks +etc/init.d/networking/hooks/bonding +etc/init.d/networking/hooks/bridge-slave +etc/init.d/networking/hooks/ethernet +etc/init.d/networking/hooks/ipv4-static +etc/init.d/networking/hooks/ipv4-static-route +etc/init.d/networking/hooks/stp +etc/init.d/networking/hooks/vlan etc/init.d/networking/net-hotplug -etc/init.d/networking/services -etc/init.d/networking/services/bonding -etc/init.d/networking/services/bridge-slave -etc/init.d/networking/services/ipv4-static -etc/init.d/networking/services/ipv4-static-route -etc/init.d/networking/services/stp +etc/init.d/networking/port +etc/init.d/networking/zone etc/init.d/ntpd etc/init.d/openldap etc/init.d/random diff --git a/src/rootfiles/core/stage3 b/src/rootfiles/core/stage3 index efd161749..163027188 100644 --- a/src/rootfiles/core/stage3 +++ b/src/rootfiles/core/stage3 @@ -6,6 +6,5 @@ etc/ipfire/certs etc/ipfire/certs/index.txt etc/ipfire/certs/serial etc/ipfire/crls -etc/ipfire/network -etc/ipfire/network/devices -etc/sysconfig/network-devices +etc/ipfire/networking +etc/sysconfig/networking