From: Michael Tremer Date: Sat, 31 Jan 2009 22:20:31 +0000 (+0100) Subject: I have written a net hotplug script. X-Git-Tag: v3.0-alpha1~44^2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d14512fd8130e4288dfea0d0f7a625d0ab3ad70;p=ipfire-3.x.git I have written a net hotplug script. --- diff --git a/config/udev/60-net.rules b/config/udev/60-net.rules new file mode 100644 index 000000000..a606a6e1f --- /dev/null +++ b/config/udev/60-net.rules @@ -0,0 +1 @@ +SUBSYSTEM=="net", RUN+="/etc/init.d/networking/net-hotplug" diff --git a/lfs/initscripts b/lfs/initscripts index f96468d3b..61910ab08 100644 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -92,7 +92,7 @@ $(OBJECT) : chmod 644 /etc/init.d/ipfire-functions # Install networking scripts - for i in $(DIR_APP)/networking/{br,if}{down,up}; do \ + for i in $(DIR_APP)/networking/{br{down,up},net-hotplug; do \ install -v -m 754 $$i /etc/init.d/networking; \ done diff --git a/src/initscripts/networking/ifdown b/src/initscripts/networking/ifdown deleted file mode 100644 index 28d1f1813..000000000 --- a/src/initscripts/networking/ifdown +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/sh -######################################################################## -# Begin $NETWORK_DEVICES/ifdown -# -# Description : Interface Down -# -# Authors : Nathan Coulson - nathan@linuxfromscratch.org -# Kevin P. Fleming - kpfleming@linuxfromscratch.org -# -# Version : 00.01 -# -# Notes : 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 - -# Collect a list of configuration files for our interface -if [ -n "${2}" ]; then - for file in ${@#$1}; do # All parameters except $1 - FILES="${FILES} ${NETWORK_DEVICES}/ifconfig.${1}/${file}" - done -elif [ -d "${NETWORK_DEVICES}/ifconfig.${1}" ]; then - FILES=`echo ${NETWORK_DEVICES}/ifconfig.${1}/*` -else - FILES="${NETWORK_DEVICES}/ifconfig.${1}" -fi - -# Reverse the order configuration files are processed in -for file in ${FILES}; do - FILES2="${file} ${FILES2}" -done -FILES=${FILES2} - -# Process each configuration file -for file in ${FILES}; do - # skip backup files - if [ "${file}" != "${file%""~""}" ]; then - continue - fi - - if [ ! -f "${file}" ]; then - message="${file} is not a network configuration file or directory." - log_warning_msg - fi - ( - . ${file} - - # Will not process this service if started by boot, and ONBOOT - # is not set to yes - if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then - continue - fi - - # Will not process this service if started by hotplug, and - # ONHOTPLUG is not set to yes - if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" ]; then - continue - fi - - # This will run the service script, if SERVICE is set - if [ -n "${SERVICE}" -a -x "${NETWORK_DEVICES}/services/${SERVICE}" ]; then - if ip link show ${1} > /dev/null 2>&1 - then - IFCONFIG=${file} ${NETWORK_DEVICES}/services/${SERVICE} ${1} down - else - message="Interface ${1} doesn't exist." - log_warning_msg - fi - 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 - ) -done - -if [ -z "${2}" ]; then - link_status=`ip link show $1` - if [ -n "${link_status}" ]; then - if echo "${link_status}" | grep -q UP; then - message="Bringing down the ${1} interface..." - ip link set ${1} down - evaluate_retval standard - fi - fi -fi - -# End $NETWORK_DEVICES/ifdown diff --git a/src/initscripts/networking/ifup b/src/initscripts/networking/ifup deleted file mode 100644 index 50e173ca6..000000000 --- a/src/initscripts/networking/ifup +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/sh -######################################################################## -# Begin $NETWORK_DEVICES/ifup -# -# Description : Interface Up -# -# Authors : Nathan Coulson - nathan@linuxfromscratch.org -# Kevin P. Fleming - kpfleming@linuxfromscratch.org -# -# Version : 00.00 -# -# Notes : 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 - -# 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}/ifconfig.${1}/${file}" - done -elif [ -d "${NETWORK_DEVICES}/ifconfig.${1}" ]; then - FILES=`echo ${NETWORK_DEVICES}/ifconfig.${1}/*` -else - FILES="${NETWORK_DEVICES}/ifconfig.${1}" -fi - -message="Bringing up the ${1} interface..." - -# Process each configruation file -for file in ${FILES}; do - # skip backup files - if [ "${file}" != "${file%""~""}" ]; then - continue - fi - - if [ ! -f "${file}" ]; then - log_warning_msg - message="${file} is not a network configuration file or directory." - log_warning_msg - fi - - ( - . ${file} - - # Will not process this service if started by boot, and ONBOOT - # is not set to yes - if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then - continue - fi - # Will not process this service if started by hotplug, and - # ONHOTPLUG is not set to yes - if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" -a "${HOSTNAME}" != "(none)" ]; then - continue - fi - - if [ -n "${SERVICE}" -a -x "${NETWORK_DEVICES}/services/${SERVICE}" ]; then - if [ -z "${CHECK_LINK}" -o "${CHECK_LINK}" = "y" -o "${CHECK_LINK}" = "yes" -o "${CHECK_LINK}" = "1" ]; then - if ip link show ${1} > /dev/null 2>&1; then - link_status=`ip link show ${1}` - if [ -n "${link_status}" ]; then - if ! echo "${link_status}" | grep -q UP; then - ip link set ${1} up - evaluate_retval standard - fi - fi - else - message="${message}Interface ${1} doesn't exist." - log_warning_msg - fi - fi - IFCONFIG=${file} ${NETWORK_DEVICES}/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 - ) -done - -# End $NETWORK_DEVICES/ifup diff --git a/src/initscripts/networking/net-hotplug b/src/initscripts/networking/net-hotplug new file mode 100644 index 000000000..8b89510fb --- /dev/null +++ b/src/initscripts/networking/net-hotplug @@ -0,0 +1,58 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007, 2008, 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 . # +# # +############################################################################### + +if [ "$INTERFACE" = "" ]; then + exit 1 +fi + +case $ACTION in + add|register) + case $INTERFACE in + # interfaces that are brought up as a part of configuration + ppp*|ippp*|isdn*|plip*|lo*|irda*|dummy*|ipsec*|tun*|tap*) + exit 0 + ;; + # interfaces that are registered then brought up + *) + export IN_HOTPLUG=1 + ## Put ifup code here + ;; + esac + ;; + + remove|unregister) + case $INTERFACE in + # interfaces that are brought down as part of deconfiguration + ppp*|ippp*|isdn*|plip*|lo*|irda*|dummy*|ipsec*|tun*|tap*) + exit 0 + ;; + *) + export IN_HOTPLUG=1 + ## Put ifdown code here + ;; + esac + ;; + + *) + exit 1 + ;; + +esac