From c7b10efd125522f3beeb3144b8a5b4cc511d93cf Mon Sep 17 00:00:00 2001 From: Christian Heim Date: Mon, 24 Apr 2006 14:30:20 +0000 Subject: Merging r2014 svn path=/baselayout-vserver/trunk/; revision=341 --- ChangeLog | 56 ++ ChangeLog.vserver | 4 + etc/conf.d/local.start | 2 +- etc/conf.d/rc | 11 + man/rc-update.8 | 9 +- net-scripts/conf.d/net.example | 30 +- net-scripts/init.d/net.lo | 5 +- net-scripts/net.modules.d/adsl.sh | 93 -- net-scripts/net.modules.d/apipa.sh | 46 - net-scripts/net.modules.d/arping.sh | 109 --- net-scripts/net.modules.d/bonding.sh | 120 --- net-scripts/net.modules.d/bridge.sh | 200 ----- net-scripts/net.modules.d/dhclient.sh | 115 --- net-scripts/net.modules.d/dhcpcd.sh | 116 --- net-scripts/net.modules.d/essidnet.sh | 49 -- .../net.modules.d/helpers.d/dhclient-wrapper | 50 -- net-scripts/net.modules.d/helpers.d/dhcp | 123 --- net-scripts/net.modules.d/helpers.d/dhcp-state | 28 - net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper | 63 -- net-scripts/net.modules.d/helpers.d/functions | 566 ------------ net-scripts/net.modules.d/helpers.d/module-loader | 63 -- net-scripts/net.modules.d/helpers.d/pppd-wrapper | 46 - net-scripts/net.modules.d/helpers.d/pump-wrapper | 32 - net-scripts/net.modules.d/helpers.d/udhcpc-wrapper | 28 - net-scripts/net.modules.d/ifconfig.sh | 425 --------- net-scripts/net.modules.d/ifplugd.sh | 146 ---- net-scripts/net.modules.d/ip6to4.sh | 97 --- net-scripts/net.modules.d/ipppd.sh | 72 -- net-scripts/net.modules.d/iproute2.sh | 349 -------- net-scripts/net.modules.d/iptunnel.sh | 55 -- net-scripts/net.modules.d/iwconfig.sh | 946 --------------------- net-scripts/net.modules.d/macchanger.sh | 102 --- net-scripts/net.modules.d/macnet.sh | 43 - net-scripts/net.modules.d/netplugd.sh | 124 --- net-scripts/net.modules.d/pppd.sh | 285 ------- net-scripts/net.modules.d/pump.sh | 102 --- net-scripts/net.modules.d/rename.sh | 63 -- net-scripts/net.modules.d/system.sh | 125 --- net-scripts/net.modules.d/tuntap.sh | 99 --- net-scripts/net.modules.d/udhcpc.sh | 143 ---- net-scripts/net.modules.d/vlan.sh | 154 ---- net-scripts/net.modules.d/wpa_supplicant.sh | 370 -------- net-scripts/net/adsl.sh | 93 ++ net-scripts/net/apipa.sh | 46 + net-scripts/net/arping.sh | 110 +++ net-scripts/net/bonding.sh | 120 +++ net-scripts/net/br2684ctl.sh | 66 ++ net-scripts/net/bridge.sh | 200 +++++ net-scripts/net/ccwgroup.sh | 55 ++ net-scripts/net/dhclient.sh | 120 +++ net-scripts/net/dhcpcd.sh | 116 +++ net-scripts/net/essidnet.sh | 49 ++ net-scripts/net/ifconfig.sh | 425 +++++++++ net-scripts/net/ifplugd.sh | 146 ++++ net-scripts/net/ip6to4.sh | 97 +++ net-scripts/net/ipppd.sh | 72 ++ net-scripts/net/iproute2.sh | 349 ++++++++ net-scripts/net/iptunnel.sh | 55 ++ net-scripts/net/iwconfig.sh | 946 +++++++++++++++++++++ net-scripts/net/macchanger.sh | 102 +++ net-scripts/net/macnet.sh | 43 + net-scripts/net/netplugd.sh | 124 +++ net-scripts/net/pppd.sh | 287 +++++++ net-scripts/net/pump.sh | 102 +++ net-scripts/net/rename.sh | 63 ++ net-scripts/net/system.sh | 125 +++ net-scripts/net/tuntap.sh | 99 +++ net-scripts/net/udhcpc.sh | 147 ++++ net-scripts/net/vlan.sh | 159 ++++ net-scripts/net/wpa_supplicant.sh | 376 ++++++++ sbin/depscan.sh | 56 +- sbin/rc-daemon.sh | 2 +- sbin/rc-services.sh | 34 +- sbin/rc-update | 6 +- sbin/runscript.sh | 8 + src/Makefile | 3 +- tarball.sh | 2 +- 77 files changed, 4873 insertions(+), 5594 deletions(-) delete mode 100644 net-scripts/net.modules.d/adsl.sh delete mode 100644 net-scripts/net.modules.d/apipa.sh delete mode 100644 net-scripts/net.modules.d/arping.sh delete mode 100644 net-scripts/net.modules.d/bonding.sh delete mode 100644 net-scripts/net.modules.d/bridge.sh delete mode 100644 net-scripts/net.modules.d/dhclient.sh delete mode 100644 net-scripts/net.modules.d/dhcpcd.sh delete mode 100644 net-scripts/net.modules.d/essidnet.sh delete mode 100755 net-scripts/net.modules.d/helpers.d/dhclient-wrapper delete mode 100755 net-scripts/net.modules.d/helpers.d/dhcp delete mode 100644 net-scripts/net.modules.d/helpers.d/dhcp-state delete mode 100755 net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper delete mode 100644 net-scripts/net.modules.d/helpers.d/functions delete mode 100644 net-scripts/net.modules.d/helpers.d/module-loader delete mode 100644 net-scripts/net.modules.d/helpers.d/pppd-wrapper delete mode 100755 net-scripts/net.modules.d/helpers.d/pump-wrapper delete mode 100755 net-scripts/net.modules.d/helpers.d/udhcpc-wrapper delete mode 100644 net-scripts/net.modules.d/ifconfig.sh delete mode 100644 net-scripts/net.modules.d/ifplugd.sh delete mode 100644 net-scripts/net.modules.d/ip6to4.sh delete mode 100644 net-scripts/net.modules.d/ipppd.sh delete mode 100644 net-scripts/net.modules.d/iproute2.sh delete mode 100644 net-scripts/net.modules.d/iptunnel.sh delete mode 100644 net-scripts/net.modules.d/iwconfig.sh delete mode 100644 net-scripts/net.modules.d/macchanger.sh delete mode 100644 net-scripts/net.modules.d/macnet.sh delete mode 100644 net-scripts/net.modules.d/netplugd.sh delete mode 100644 net-scripts/net.modules.d/pppd.sh delete mode 100644 net-scripts/net.modules.d/pump.sh delete mode 100644 net-scripts/net.modules.d/rename.sh delete mode 100644 net-scripts/net.modules.d/system.sh delete mode 100644 net-scripts/net.modules.d/tuntap.sh delete mode 100644 net-scripts/net.modules.d/udhcpc.sh delete mode 100644 net-scripts/net.modules.d/vlan.sh delete mode 100644 net-scripts/net.modules.d/wpa_supplicant.sh create mode 100644 net-scripts/net/adsl.sh create mode 100644 net-scripts/net/apipa.sh create mode 100644 net-scripts/net/arping.sh create mode 100644 net-scripts/net/bonding.sh create mode 100644 net-scripts/net/br2684ctl.sh create mode 100644 net-scripts/net/bridge.sh create mode 100644 net-scripts/net/ccwgroup.sh create mode 100644 net-scripts/net/dhclient.sh create mode 100644 net-scripts/net/dhcpcd.sh create mode 100644 net-scripts/net/essidnet.sh create mode 100644 net-scripts/net/ifconfig.sh create mode 100644 net-scripts/net/ifplugd.sh create mode 100644 net-scripts/net/ip6to4.sh create mode 100644 net-scripts/net/ipppd.sh create mode 100644 net-scripts/net/iproute2.sh create mode 100644 net-scripts/net/iptunnel.sh create mode 100644 net-scripts/net/iwconfig.sh create mode 100644 net-scripts/net/macchanger.sh create mode 100644 net-scripts/net/macnet.sh create mode 100644 net-scripts/net/netplugd.sh create mode 100644 net-scripts/net/pppd.sh create mode 100644 net-scripts/net/pump.sh create mode 100644 net-scripts/net/rename.sh create mode 100644 net-scripts/net/system.sh create mode 100644 net-scripts/net/tuntap.sh create mode 100644 net-scripts/net/udhcpc.sh create mode 100644 net-scripts/net/vlan.sh create mode 100644 net-scripts/net/wpa_supplicant.sh diff --git a/ChangeLog b/ChangeLog index edbf2e1..62c405e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,62 @@ Give a better error message when no valid DHCP client is installed. +* baselayout-1.12.0_pre18 (22 Apr 2006) + + 22 Apr 2006; Mike Frysinger : + + Touchup fuser arguments in halt.sh so we dont have to pipe to /dev/null. + + 22 Apr 2006; Roy Marples : + + udhcpc module now requires udhcp-0.9.9_pre20041216-r3 or newer with + the --env command option. + + 21 Apr 2006; Roy Marples : + + br2684 module should now work correctly. + Document usage of br2684 module. + + move /lib/rcscripts/net.modules.d to /lib/rcscripts/net + + 20 Apr 2006; Mike Frysinger : + + Document --verbose option in rc-update #130643 by Christian Heim. + + 18 Apr 2006; Mike Frysinger : + + Sort by mount point, not mount source, in halt.sh #130219 by Mark McKenna. + + Disable CTRL+C in depscan.sh while booting #126512 by Marko Djukic. + + 18 Apr 2006; Roy Marples : + + start-stop-daemon only removes the daemon stopping from the daemon + started list, #130166. + + 15 Apr 2006; Roy Marples : + + net services are now calculated properly in trace_dependencies. + + arping.sh now tests if the interface exists or not. + + 12 Apr 2006; Roy Marples : + + vlans can now be configured with their own interface scripts, which + means that they can now be renamed, #128283. + Thanks to Jonathan deBoer. + + 11 Apr 2006; Roy Marples : + + udhcpc.sh now works with the -q|--quit option again, #129437. + + 09 Apr 2006; Roy Marples : + + RC_COLDPLUG now controls if we add coldplugged services to the boot + runlevel or not, #129331. + + The ccwgroup module now really works! + * baselayout-1.12.0_pre17 (08 Apr 2006) 07 Apr 2006; Roy Marples : diff --git a/ChangeLog.vserver b/ChangeLog.vserver index 021ffdb..169ca5c 100644 --- a/ChangeLog.vserver +++ b/ChangeLog.vserver @@ -1,6 +1,10 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2006 Gentoo Foundation; Distributed under the GPLv2 + 21 Apr 2006; Christian Heim : + Merging latest changes to the baselayout/trunk changes. This merge is based + upon revision 2014. + 08 Apr 2006; Christian Heim : Merging latest changes to the baselayout/trunk changes. This merge is based upon revision 1965. diff --git a/etc/conf.d/local.start b/etc/conf.d/local.start index a55d2cc..7a20c14 100644 --- a/etc/conf.d/local.start +++ b/etc/conf.d/local.start @@ -1,5 +1,5 @@ # /etc/conf.d/local.start # This is a good place to load any misc programs -# on startup ( use 1>&2 to hide output) +# on startup (use &>/dev/null to hide output) diff --git a/etc/conf.d/rc b/etc/conf.d/rc index 3bbcecc..875fd11 100644 --- a/etc/conf.d/rc +++ b/etc/conf.d/rc @@ -10,6 +10,17 @@ RC_TTY_NUMBER=0 RC_PARALLEL_STARTUP="no" +# Dynamic /dev managers can trigger coldplug events which cause services to +# start before we are ready for them. If this happens, we can defer these +# services to start in the boot runlevel. If you don't want this then set +# RC_COLDPLUG to no. +# For more fine grained control you can list full service names to allow +# them to coldplug and prefix them with ! so they don't coldplug. +# Example - RC_COLDPLUG="net.wlan !net.*" +# This allows net.wlan and any service not matching net.* to coldplug. + +RC_COLDPLUG="yes" + # RC_NET_STRICT_CHECKING allows some flexibility with the 'net' service. # The following values are allowed: # none - The 'net' service is always considered up. diff --git a/man/rc-update.8 b/man/rc-update.8 index b5b1d8c..47db9ad 100644 --- a/man/rc-update.8 +++ b/man/rc-update.8 @@ -6,7 +6,7 @@ rc-update \- add and remove init scripts to a runlevel .br \fBrc-update\fR \fIdel\fR \fIscript\fR \fI[runlevels]\fR .br -\fBrc-update\fR \fIshow\fR \fI[runlevels]\fR +\fBrc-update\fR \fIshow\fR \fI[\-\-verbose]\fR \fI[runlevels]\fR .SH DESCRIPTION Gentoo's init system uses named runlevels. Rather than editing some obscure file or managing a directory of symlinks, \fBrc-update\fR exists to quickly @@ -29,9 +29,10 @@ will be removed from all exists runlevels. Example: rc-update del sysklogd .TP -\fBshow (\-s)\fR \fI[runlevels]\fR -Show all init scripts and the runlevels they belong to. If you specify -\fIrunlevels\fR to show, then only those will be included in the output. +\fBshow (\-s)\fR \fI[\-v|\-\-verbose]\fR \fI[runlevels]\fR +Show all enabled scripts and the runlevels they belong to. If you specify +\fIrunlevels\fR to show, then only those will be included in the output. To +view all init scripts, run with the \fI\-\-verbose\fR option. Example: rc-update show .SH "REPORTING BUGS" diff --git a/net-scripts/conf.d/net.example b/net-scripts/conf.d/net.example index 9521449..f103905 100644 --- a/net-scripts/conf.d/net.example +++ b/net-scripts/conf.d/net.example @@ -316,6 +316,15 @@ # NOTE: Vlans are controlled by their physical interface and not per vlan # This means you do not need to create init scripts in /etc/init.d for each # vlan, you must need to create one for the physical interface. +# If you wish to control the configuration of each vlan through a seperate +# script, or wish to rename the vlan interface to something that vconfig +# cannot then you need to do this. +#vlan_start_eth0="no + +# If you do the above then you may want to depend on eth0 like so +# depend_vlan1() { +# need net.eth0 +# } #----------------------------------------------------------------------------- # Bonding @@ -352,7 +361,7 @@ #link_ppp0="/dev/ttyS0" # Most PPP links will use a serial port #link_ppp0="eth0" # PPPoE requires an ethernet interface #link_ppp0="/dev/null" # PPPoA and ISDN links should have this -#link_ppp0="pty $(your_link_command)" # PPP links over ssh, rsh, etc +#link_ppp0="pty 'your_link_command'" # PPP links over ssh, rsh, etc # # Here you should specify what pppd plugins you want to use # Available plugins are: pppoe, pppoa, capi, dhcpc, minconn, radius, @@ -426,6 +435,14 @@ # '~--' '' #) +# If the link require extra configuration - for example wireless or +# RFC 268 bridge - we need to write a depend function for the bridge so they get +# configured correctly. +# This is exactly the same as a depend() function in our init scripts +#depend_ppp0() { +# need net.nas0 +#} + #----------------------------------------------------------------------------- # ADSL # For ADSL support, emerge net-dialup/rp-pppoe @@ -532,6 +549,17 @@ # Consult "man brctl" for more details #brctl_br0=( "setfd 0" "sethello 0" "stp off" ) +#----------------------------------------------------------------------------- +# RFC 2684 Bridge Support +# For RFC 2684 bridge support emerge net-misc/br2684ctl + +# Interface names have to be of the form nas0, nas1, nas2, etc. +# You have to specify a VPI and VCI for the interface like so +#br2684ctl_nas0="-a 0.38" # UK VPI and VCI + +# Then you can configure the interface as normal +#config_nas0=( "192.168.0.1/24" ) + #----------------------------------------------------------------------------- # Tunnelling # WARNING: For tunnelling it is highly recommended that you diff --git a/net-scripts/init.d/net.lo b/net-scripts/init.d/net.lo index da12257..ed46320 100755 --- a/net-scripts/init.d/net.lo +++ b/net-scripts/init.d/net.lo @@ -19,12 +19,13 @@ depend() { # For example, br0 may need eth0 and eth1 local iface="${SVCNAME#*.}" [[ $(type -t "depend_${iface}") == "function" ]] && depend_${iface} + [[ ${iface} != "lo" && ${iface} != "lo0" ]] && after net.lo net.lo0 return 0 } # Define where our modules are -MODULES_DIR="${svclib}/net.modules.d" +MODULES_DIR="${svclib}/net" # Make some wrappers to fudge after/before/need/use depend flags. # These are callbacks so MODULE will be set. @@ -53,7 +54,7 @@ variables() { } is_loopback() { - [[ $1 == "lo" || $1 == "lo"[0-9]* ]] + [[ $1 == "lo" || $1 == "lo0" ]] } # char* interface_device(char *iface) diff --git a/net-scripts/net.modules.d/adsl.sh b/net-scripts/net.modules.d/adsl.sh deleted file mode 100644 index 2e1423b..0000000 --- a/net-scripts/net.modules.d/adsl.sh +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# void adsl_depend(void) -# -# Sets up the dependancies for the module -adsl_depend() { - before dhcp -} - -# bool adsl_check_installed(void) -# -# Returns 1 if rp-pppoe is installed, otherwise 0 -adsl_check_installed() { - [[ -x /usr/sbin/adsl-start || -x /usr/sbin/pppoe-start ]] && return 0 - ${1:-false} && eerror "For ADSL support, emerge net-dialup/rp-pppoe" - return 1 -} - -# bool adsl_setup_vars(char *iface) -# -# Checks to see if the ADSL script has been created or not -adsl_setup_vars() { - local iface="$1" startstop="$2" cfgexe - - if [[ -x /usr/sbin/pppoe-start ]]; then - exe="/usr/sbin/pppoe-${startstop}" - cfgexe=pppoe-setup - else - exe="/usr/sbin/adsl-${startstop}" - cfgexe=adsl-setup - fi - - # Decide which configuration to use. Hopefully there is an - # interface-specific one - cfgfile="/etc/ppp/pppoe-${iface}.conf" - [[ -f ${cfgfile} ]] || cfgfile="/etc/ppp/pppoe.conf" - - if [[ ! -f ${cfgfile} ]]; then - eerror "no pppoe.conf file found!" - eerror "Please run ${cfgexe} to create one" - return 1 - fi - - return 0 -} - -# bool adsl_start(char *iface) -# -# Start ADSL on an interface by calling adsl-start -# -# Returns 0 (true) when successful, non-zero otherwise -adsl_start() { - local iface="$1" exe cfgfile user ifvar="$(bash_variable "$1")" - - adsl_setup_vars "${iface}" start || return 1 - - # Might or might not be set in conf.d/net - user="adsl_user_${ifvar}" - - # Start ADSL with the cfgfile, but override ETH and PIDFILE - einfo "Starting ADSL for ${iface}" - ${exe} <(cat "${cfgfile}"; \ - echo "ETH=${iface}"; \ - echo "PIDFILE=/var/run/rp-pppoe-${iface}.pid"; \ - [[ -n ${!user} ]] && echo "USER=${!user}") \ - >/dev/null - eend $? -} - -# bool adsl_stop(char *iface) -# -# Returns 0 when there is no ADSL to stop or we stop ADSL successfully -# Otherwise 1 -adsl_stop() { - local iface="$1" exe cfgfile - - adsl_check_installed || return 1 - [[ ! -f "/var/run/rp-pppoe-${iface}.pid" ]] && return 0 - - adsl_setup_vars "${iface}" stop || return 1 - - einfo "Stopping ADSL for ${iface}" - ${exe} <(cat "${cfgfile}"; \ - echo "ETH=${iface}"; echo "PIDFILE=/var/run/rp-pppoe-${iface}.pid") \ - >/dev/null - eend $? - - return 0 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/apipa.sh b/net-scripts/net.modules.d/apipa.sh deleted file mode 100644 index 5ccdc18..0000000 --- a/net-scripts/net.modules.d/apipa.sh +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# void apipa_depend(void) -# -# Sets up the dependancies for the module -apipa_depend() { - installed arping - functions interface_exists -} - -# bool apipa_start(char *iface) -# -# Tries to detect a config based on arpinging things -apipa_start() { - local iface="$1" i1 i2 addr i=0 - - interface_exists "$1" true || return 1 - - einfo "Searching for free addresses in 169.254.0.0/16" - eindent - - while [[ ${i} -lt 64516 ]]; do - (( i1=${RANDOM}%255 )) - (( i2=${RANDOM}%255 )) - - addr="169.254.${i1}.${i2}" - vebegin "${addr}/16" - if ! arping_address_exists "${iface}" "${addr}" ; then - config[config_counter]="${addr}/16 broadcast 169.254.255.255" - (( config_counter-- )) - veend 0 - eoutdent - return 0 - fi - - (( i++ )) - done - - eerror "No free address found!" - eoutdent - return 1 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/arping.sh b/net-scripts/net.modules.d/arping.sh deleted file mode 100644 index e17df59..0000000 --- a/net-scripts/net.modules.d/arping.sh +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# void arping_depend(void) -# -# Sets up the dependancies for the module -arping_depend() { - functions interface_exists interface_up -} - -# bool arping_check_installed(void) -# -# Returns 0 if arping or arping2 is installed, otherwise 1 -arping_check_installed() { - [[ -x /sbin/arping || -x /usr/sbin/arping2 ]] && return 0 - if ${1:-false}; then - eerror "For arping support emerge net-misc/iputils or net-analyzer/arping" - fi - return 1 -} - -# bool arping_address_exists(char *interface, char *address) -# -# Returns 0 if the address on the interface responds to an arping -# 1 if not - packets defaults to 1 -# If neither arping (net-misc/iputils) or arping2 (net-analyzer/arping) -# is installed then we return 1 -arping_address_exists() { - local iface="$1" address="${2%%/*}" i - - # We only handle IPv4 addresses - [[ ${address} != *.*.*.* ]] && return 1 - - # 0.0.0.0 isn't a valid address - and some lusers have configured this - [[ ${address} == "0.0.0.0" || ${address} == "0" ]] && return 1 - - # We need to bring the interface up to test - interface_up "${iface}" - - if [[ -x /sbin/arping ]] ; then - /sbin/arping -q -c 2 -w 3 -D -f -I "${iface}" "${address}" \ - &>/dev/null || return 0 - elif [[ -x /usr/sbin/arping2 ]] ; then - for (( i=0; i<3; i++ )) ; do - /usr/sbin/arping2 -0 -c 1 -i "${iface}" "${address}" \ - &>/dev/null && return 0 - done - fi - return 1 -} - -# bool arping_start(char *iface) -# -# arpings a list of gateways -# If one is foung then apply it's configuration -arping_start() { - local iface="$1" gateways x conf i - - interface_exists "${iface}" true || return 1 - - einfo "Pinging gateways on ${iface} for configuration" - - gateways="gateways_${ifvar}[@]" - if [[ -z ${!gateways} ]] ; then - eerror "No gateways have been defined (gateways_${ifvar}=\"...\")" - return 1 - fi - - eindent - - for x in ${!gateways}; do - vebegin "${x}" - if arping_address_exists "${iface}" "${x}" ; then - for i in ${x//./ } ; do - if [[ ${#i} == "2" ]] ; then - conf="${conf}0${i}" - elif [[ ${#i} == "1" ]] ; then - conf="${conf}00${i}" - else - conf="${conf}${i}" - fi - done - veend 0 - eoutdent - veinfo "Configuring ${iface} for ${x}" - configure_variables "${iface}" "${conf}" - - # Call the system module as we've aleady passed it by .... - # And it *has* to be pre_start for other things to work correctly - system_pre_start "${iface}" - - t="config_${ifvar}[@]" - config=( "${!t}" ) - t="fallback_config_${ifvar}[@]" - fallback_config=( "${!t}" ) - t="fallback_route_${ifvar}[@]" - fallback_route=( "${!t}" ) - config_counter=-1 - return 0 - fi - veend 1 - done - - eoutdent - return 1 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/bonding.sh b/net-scripts/net.modules.d/bonding.sh deleted file mode 100644 index 2b8a086..0000000 --- a/net-scripts/net.modules.d/bonding.sh +++ /dev/null @@ -1,120 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# void bonding_depend(void) -# -# Sets up the dependancies for the module -bonding_depend() { - before interface macchanger - functions interface_exists interface_up interface_down \ - interface_del_addresses -} - -# void bonding_expose(void) -# -# Expose variables that can be configured -bonding_expose() { - variables slaves -} - -# bool bonding_check_installed(void) -# -# Returns 0 if ifenslave is installed, otherwise 1 -bonding_check_installed() { - [[ -x /sbin/ifenslave ]] && return 0 - ${1:-false} && eerror "For link aggregation (bonding) support, emerge net-misc/ifenslave" - return 1 -} - -# bonding_exists(char *interface) -# -# Returns 0 if we are a bonded interface, otherwise 1 -bonding_exists() { - [[ -f "/proc/net/bonding/$1" ]] -} - -# bool bonding_post_start(char *iface) -# -# Bonds the interface -bonding_pre_start() { - local iface="$1" s ifvar="$(bash_variable "$1")" - local -a slaves - - slaves="slaves_${ifvar}[@]" - [[ -z ${!slaves} ]] && return 0 - slaves=( "${!slaves}" ) - - # Support space seperated slaves - [[ ${#slaves[@]} == 1 ]] && slaves=( ${slaves} ) - - interface_exists "${iface}" true || return 1 - - if ! bonding_exists "${iface}" ; then - eerror "${iface} is not capable of bonding" - return 1 - fi - - ebegin "Adding slaves to ${iface}" - eindent - einfo "${slaves[@]}" - - # Check that our slaves exist - for s in "${slaves[@]}" ; do - interface_exists "${s}" true || return 1 - done - - # Must force the slaves to a particular state before adding them - for s in "${slaves[@]}" ; do - interface_del_addresses "${s}" - interface_up "${s}" - done - - # now force the master to up - interface_up "${iface}" - - # finally add in slaves - eoutdent - /sbin/ifenslave "${iface}" ${slaves[@]} >/dev/null - eend $? - - return 0 #important -} - -# bool bonding_stop(void) -# Unbonds bonded interfaces -# -# Always returns 0 (true) -bonding_stop() { - local iface="$1" slaves s - - # return silently if this is not a bonding interface - ! bonding_exists "${iface}" && return 0 - - # don't trust the config, get the active list instead - slaves="$( \ - sed -n -e 's/^Slave Interface: //p' "/proc/net/bonding/${iface}" \ - | tr '\n' ' ' \ - )" - [[ -z ${slaves} ]] && return 0 - - # remove all slaves - ebegin "Removing slaves from ${iface}" - eindent - einfo "${slaves}" - eoutdent - /sbin/ifenslave -d "${iface}" ${slaves} - - # reset all slaves - for s in ${slaves}; do - if interface_exists "${s}" ; then - interface_del_addresses "${s}" - interface_down "${s}" - fi - done - - eend 0 - return 0 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/bridge.sh b/net-scripts/net.modules.d/bridge.sh deleted file mode 100644 index 67af002..0000000 --- a/net-scripts/net.modules.d/bridge.sh +++ /dev/null @@ -1,200 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# Fix any potential localisation problems -# Note that LC_ALL trumps LC_anything_else according to locale(7) -brctl() { - LC_ALL=C /sbin/brctl "$@" -} -# void bridge_depend(void) -# -# Sets up the dependancies for the module -bridge_depend() { - before interface macnet - functions interface_down interface_del_addresses interface_set_flag -} - -# void bridge_expose(void) -# -# Expose variables that can be configured -bridge_expose() { - variables bridge bridge_add brctl -} - -# bool bridge_check_installed(void) -# -# Returns 1 if bridge is installed, otherwise 0 -bridge_check_installed() { - [[ -x /sbin/brctl ]] && return 0 - ${1:-false} && eerror "For bridge support, emerge net-misc/bridge-utils" - return 1 -} - -# char* bridge_get_ports(char *interface) -# -# Returns the interfaces added to the given bridge -bridge_get_ports() { - brctl show 2>/dev/null \ - | sed -n -e '/^'"$1"'/,/^\S/ { /^\('"$1"'\|\t\)/s/^.*\t//p }' -} - -# char* bridge_get_bridge(char *interface) -# -# Returns the bridge interface of the given interface -bridge_get_bridge() { - local x="$( brctl show 2>/dev/null \ - | sed -e '1 {d}; /^[^ ]/ { N }; /.*'"$1"'.*/ {s/^\([^ \t]\+\).*/\1/p}; d')" - - local -a a=( ${x} ) - if [[ ${#a[@]} == "1" ]] ; then - echo "${x}" - elif [[ $1 == "${a[3]}" ]] ; then - echo "${a[0]}" - fi -} - -# bool bridge_exists(char *interface) -# -# Returns 0 if the bridge exists, otherwise 1 -bridge_exists() { - brctl show 2>/dev/null | grep -q "^$1" -} - -# bool bridge_create(char *interface) -# -# Creates the bridge - no ports are added here though -# Returns 0 on success otherwise 1 -bridge_create() { - local iface="$1" ifvar="$(bash_variable "$1")" x i opts - - ebegin "Creating bridge ${iface}" - x="$(brctl addbr "${iface}" 2>&1)" - if [[ -n ${x} ]] ; then - if [[ ${x//Package not installed/} != "${x}" ]] ; then - eend 1 "Bridging (802.1d) support is not present in this kernel" - else - eend 1 "${x}" - fi - return 1 - fi - - opts="brctl_${ifvar}[@]" - for i in "${!opts}" ; do - x="${i/ / ${iface} }" - [[ ${x} == "${i}" ]] && x="${x} ${iface}" - x="$(brctl ${x} 2>&1 1>/dev/null)" - [[ -n ${x} ]] && ewarn "${x}" - done - eend 0 -} - -# bool bridge_add_port(char *interface, char *port) -# -# Adds the port to the bridge -bridge_add_port() { - local iface="$1" port="$2" e - - interface_set_flag "${port}" promisc true - interface_up "${port}" - e="$(brctl addif "${iface}" "${port}" 2>&1)" - if [[ -n ${e} ]] ; then - interface_set_flag "${port}" promisc false - echo "${e}" >&2 - return 1 - fi - return 0 -} - -# bool bridge_delete_port(char *interface, char *port) -# -# Deletes a port from a bridge -bridge_delete_port() { - interface_set_flag "$2" promisc false - brctl delif "$1" "$2" -} - -# bool bridge_start(char *iface) -# -# set up bridge -# This can also be called by non-bridges so that the bridge can be created -# dynamically -bridge_pre_start() { - local iface="$1" ports briface i ifvar="$(bash_variable "$1")" opts - ports="bridge_${ifvar}[@]" - briface="bridge_add_${ifvar}" - opts="brctl_${ifvar}[@]" - - [[ -z ${!ports} && -z ${!briface} && -z ${!opts} ]] && return 0 - - # Destroy the bridge if it exists - [[ -n ${!ports} ]] && bridge_stop "${iface}" - - # Allow ourselves to add to the bridge - if [[ -z ${!ports} && -n ${!briface} ]] ; then - ports="${iface}" - iface="${!briface}" - else - ports="${!ports}" - # We are the bridge, so set our base metric to 1000. - metric=1000 - fi - - # Create the bridge if needed - bridge_exists "${iface}" || bridge_create "${iface}" - - if [[ -n ${ports} ]] ; then - einfo "Adding ports to ${iface}" - eindent - - for i in ${ports} ; do - interface_exists "${i}" true || return 1 - done - - for i in ${ports} ; do - ebegin "${i}" - bridge_add_port "${iface}" "${i}" - eend $? || return 1 - done - eoutdent - fi - - return 0 -} - -# bool bridge_stop(char *iface) -# -# Removes the device -# returns 0 -bridge_stop() { - local iface="$1" ports i deletebridge=false extra="" - - if bridge_exists "${iface}" ; then - ebegin "Destroying bridge ${iface}" - interface_down "${iface}" - ports="$(bridge_get_ports "${iface}")" - deletebridge=true - eindent - else - # Work out if we're added to a bridge for removal or not - ports="${iface}" - iface="$(bridge_get_bridge "${iface}")" - [[ -z ${iface} ]] && return 0 - extra=" from ${iface}" - fi - - for i in ${ports} ; do - ebegin "Removing port ${i}${extra}" - bridge_delete_port "${iface}" "${i}" - eend $? - done - - if ${deletebridge} ; then - eoutdent - brctl delbr "${iface}" &>/dev/null - eend 0 - fi - return 0 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/dhclient.sh b/net-scripts/net.modules.d/dhclient.sh deleted file mode 100644 index 6514224..0000000 --- a/net-scripts/net.modules.d/dhclient.sh +++ /dev/null @@ -1,115 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# Fix any potential localisation problems -# Note that LC_ALL trumps LC_anything_else according to locale(7) -dhclient() { - LC_ALL=C /sbin/dhclient "$@" -} - -# void dhclient_depend(void) -# -# Sets up the dependancies for the module -dhclient_depend() { - after interface - provide dhcp - functions interface_exists interface_get_address -} - -# void dhclient_expose(void) -# -# Expose variables that can be configured -dhclient_expose() { - variables dhclient dhcp -} - -# bool dhclient_check_installed(void) -# -# Returns 1 if dhclient is installed, otherwise 0 -dhclient_check_installed() { - [[ -x /sbin/dhclient ]] && return 0 - ${1:-false} && eerror "For DHCP (dhclient) support, emerge net-misc/dhcp" - return 1 -} - -# bool dhclient_stop(char *iface) -# -# Stop dhclient on an interface -# Always returns 0 -dhclient_stop() { - local iface="$1" pidfile="/var/run/dhclient-$1.pid" - - [[ ! -f ${pidfile} ]] && return 0 - - ebegin "Stopping dhclient on ${iface}" - local ifvar="$(bash_variable "${iface}")" - local d="dhcp_${ifvar}" - [[ -z ${!d} ]] && d="dhcp" - if [[ " ${!d} " == *" release "* ]] ; then - dhclient -q -r -pf "${pidfile}" "${iface}" - else - start-stop-daemon --stop --exec /sbin/dhclient --pidfile "${pidfile}" - fi - eend $? -} - -# bool dhclient_start(char *iface) -# -# Start DHCP on an interface by calling dhclient $iface $options -# -# Returns 0 (true) when a DHCP address is obtained, otherwise 1 -dhclient_start() { - local iface="$1" ifvar="$(bash_variable "$1")" dhconf= - local pidfile="/var/run/dhclient-${iface}.pid" - - interface_exists "${iface}" true || return 1 - - # Load our default options - opts="dhclient_${ifvar}" - opts="${!opts}" - - local d="dhcp_${ifvar}" - [[ -z ${!d} ]] && d="dhcp" - - # Add our peer and metric options - if [[ " ${!d} " == *" nodns "* ]] ; then - opts="${opts} -e PEER_DNS=no" - elif [[ " ${opts} " != *" -e PEER_DNS="* ]] ; then - opts="${opts} -e PEER_DNS=yes" - fi - if [[ " ${!d} " == *" nontp "* ]] ; then - opts="${opts} -e PEER_NTP=no" - elif [[ " ${opts} " != *" -e PEER_NTP="* ]] ; then - opts="${opts} -e PEER_NTP=yes" - fi - local metric="metric_${ifvar}" - if [[ -n ${!metric} && ${!metric} != "0" ]] ; then - opts="${opts} -e IF_METRIC=${!metric}" - fi - - # Send our hostname by editing cffile - if [[ " ${!d} " != *" nosendhost "* ]] ; then - local hname="$(hostname)" - if [[ ${hname} != "(none)" && ${hname} != "localhost" ]]; then - dhconf="${dhconf} interface \"${iface}\" {\n" - dhconf="${dhconf} send host-name \"${hname}\"\n;" - dhconf="${dhconf}}" - fi - fi - - echo "${dhconf}" > /tmp/dhconf-${iface} - # Bring up DHCP for this interface (or alias) - ebegin "Running dhclient" - echo -e "${dhconf}" | start-stop-daemon --start --exec /sbin/dhclient \ - --pidfile "${pidfile}" -- ${opts} -q -1 -pf "${pidfile}" - eend $? || return 1 - - # DHCP succeeded, show address retrieved - local addr="$(interface_get_address "${iface}")" - einfo "${iface} received address ${addr}" - - return 0 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/dhcpcd.sh b/net-scripts/net.modules.d/dhcpcd.sh deleted file mode 100644 index 2311386..0000000 --- a/net-scripts/net.modules.d/dhcpcd.sh +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -# Contributed by Roy Marples (uberlord@gentoo.org) - -# void dhcpcd_depend(void) -# -# Sets up the dependancies for the module -dhcpcd_depend() { - after interface - provide dhcp - functions interface_exists interface_get_address -} - -# void dhcpcd_expose(void) -# -# Expose variables that can be configured -dhcpcd_expose() { - variables dhcpcd dhcp -} - -# bool dhcpcd_check_installed(void) -# -# Returns 1 if dhcpcd is installed, otherwise 0 -dhcpcd_check_installed() { - if [[ -x /sbin/dhcpcd ]]; then - if dhcpcd -h 2>&1 | grep -q "etcDir" ; then - return 0 - else - ${1:-false} && eerror "We require dhcpcd-2.0.0 or newer" - return 1 - fi - fi - - ${1:-false} && eerror "For DHCP (dhcpcd) support, emerge net-misc/dhcpcd" - return 1 -} - -# bool dhcpcd_stop(char *iface) -# -# Stop DHCP on an interface by calling dhcpcd -z $iface -# -# Returns 0 (true) when a DHCP address dropped -# otherwise return 1 -dhcpcd_stop() { - local iface=$1 signal pidfile="/var/run/dhcpcd-$1.pid" d - - [[ ! -f ${pidfile} ]] && return 0 - - ebegin "Stopping dhcpcd on ${iface}" - - local ifvar="$(bash_variable "${iface}")" - d="dhcp_${ifvar}" - d=" ${!d} " - [[ ${d} == " " ]] && d=" ${dhcp} " - - if [[ ${d} == *" release "* ]] ; then - /sbin/dhcpcd -k "${iface}" - else - start-stop-daemon --stop --exec /sbin/dhcpcd --pidfile "${pidfile}" - fi - eend $? -} - -# bool dhcpcd_start(char *iface) -# -# Start DHCP on an interface by calling dhcpcd $iface $options -# -# Returns 0 (true) when a DHCP address is obtained, otherwise 1 -dhcpcd_start() { - local iface="$1" opts pidfile="/var/run/dhcpcd-$1.pid" - local ifvar="$(bash_variable "${iface}")" metric d - - interface_exists "${iface}" true || return 1 - - # Get our options - opts="dhcpcd_${ifvar}" - opts="${!opts}" - - # Map some generic options to dhcpcd - d="dhcp_${ifvar}" - d=" ${!d} " - [[ ${d} == " " ]] && d=" ${dhcp} " - [[ ${d} == *" nodns "* ]] && opts="${opts} -R" - [[ ${d} == *" nontp "* ]] && opts="${opts} -N" - [[ ${d} == *" nonis "* ]] && opts="${opts} -Y" - [[ ${d} == *" nogateway "* ]] && opts="${opts} -G" - - # We transmit the hostname by default:q - if [[ " ${d} " != *" nosendhost "* && " ${opts} " != *" -h "* ]]; then - local hname="$(hostname)" - [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \ - && opts="-h \"${hname}\" ${opts}" - fi - - # Stop dhcpcd from bringing the interface down when we exit - opts="${opts} -o" - - # Add our route metric - metric="metric_${ifvar}" - [[ -n ${!metric} && ${!metric} != "0" ]] && opts="${opts} -m ${!metric}" - - # Bring up DHCP for this interface (or alias) - ebegin "Running dhcpcd" - - eval /sbin/dhcpcd "${opts}" "${iface}" - eend $? || return 1 - - # DHCP succeeded, show address retrieved - local addr="$( interface_get_address "${iface}" )" - einfo "${iface} received address ${addr}" - - return 0 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/essidnet.sh b/net-scripts/net.modules.d/essidnet.sh deleted file mode 100644 index 689a6ea..0000000 --- a/net-scripts/net.modules.d/essidnet.sh +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) -# Many thanks to all the people in the Gentoo forums for their ideas and -# motivation for me to make this and keep on improving it - -# Load our config if it exists -[[ -f "$(add_suffix "/etc/conf.d/wireless" )" ]] \ - && source "$(add_suffix "/etc/conf.d/wireless" )" - -# void essidnet_depend(void) -# -# Sets up the dependancies for the module -essidnet_depend() { - before interface system - after wireless - installed wireless - functions wireless_exists wireless_get_essid wireless_get_ap_mac_address -} - -# bool essidnet_start(char *iface) -# -# All interfaces and module scripts can depend on the variables function -# which returns a space seperated list of user configuration variables -# We can override each variable here from a given ESSID or the MAC -# of the AP connected to. MAC configuration takes precedence -# Always returns 0 -essidnet_pre_start() { - local iface="$1" - - wireless_exists "${iface}" || return 0 - - local mac="$(wireless_get_ap_mac_address "${iface}")" - local ESSID="$(wireless_get_essid "${iface}")" - local essid="$(bash_variable "${ESSID}")" - mac="${mac//:/}" - - vebegin "Configuring ${iface} for ESSID \"${ESSID//\\\\/\\\\}\"" 2>/dev/null - configure_variables "${iface}" "${essid}" "${mac}" - - # Backwards compat for old gateway var - x="gateway_${essid}" - [[ -n ${!x} ]] && gateway="${iface}/${!x}" - - veend 0 2>/dev/null - return 0 -} - -# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/helpers.d/dhclient-wrapper b/net-scripts/net.modules.d/helpers.d/dhclient-wrapper deleted file mode 100755 index c2d980b..0000000 --- a/net-scripts/net.modules.d/helpers.d/dhclient-wrapper +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# Instead of writing new functions for dhclient, we simply map their variables -# over to udhcpc style ones and call those scripts! - -[[ -e /etc/dhcp/dhclient-enter-hooks ]] \ - && ( source /etc/dhcp/dhclient-enter-hooks ) - -case "${reason}" in - BOUND|REBOOT|REBIND) action="bound" ;; - RENEW) action="renew" ;; - RELEASE|PREINIT|FAIL|EXPIRE|TIMEOUT) action="deconfig" ;; - MEDIUM) exit 0 ;; -esac - -if [[ -z ${action} ]] ; then - echo "dhclient sent an unknown action ${reason}!" >&2 - exit 1 -fi - -export ip="${new_ip_address}" -export subnet="${new_subnet_mask}" -export broadcast="${new_broadcast_address}" -export routers="${new_routers}" - -export hostname="${new_host_name}" - -export dns_domain_${interface}="${new_domain_name}" -export dns_servers_${interface}="${new_domain_name_servers}" - -export ntp_servers_${interface}="${new_domain_name_servers}" - -export nis_domain_${interface}="${new_nis_domain}" -export nis_servers_${interface}="${new_nis_servers}" - -[[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh -RC_QUIET_STDOUT="yes" - -"${svclib}/net.modules.d/helpers.d/dhcp" "${action}" -result="$?" - -[[ -e /etc/dhcp/dhclient-exit-hooks ]] \ - && ( source /etc/dhcp/dhclient-exit-hooks ) - -exit "${result}" - -# vim: ts=4 : diff --git a/net-scripts/net.modules.d/helpers.d/dhcp b/net-scripts/net.modules.d/helpers.d/dhcp deleted file mode 100755 index d210705..0000000 --- a/net-scripts/net.modules.d/helpers.d/dhcp +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/bash -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -action="$1" -service="net.${interface}" - -[[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh -RC_QUIET_STDOUT="yes" - -source "${svclib}/net.modules.d/helpers.d/module-loader" - -# Bring the interface up -interface_is_up "${interface}" || interface_up "${interface}" - -case "${action}" in - bound|renew) - # We handle these actions below - ;; - deconfig|leasefail) - # Just remove IPv4 / inet addresses - interface_del_addresses "${interface}" true - service_started "${service}" && mark_service_inactive "${service}" - remove_state "${interface}" - if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then - if service_inactive "${service}" ; then - best_interface="$(select_best_interface)" - apply_state "${best_interface}" - fi - fi - echo "${action}" - exit 0 - ;; - nak) - echo "${action}" - exit 0 - ;; - *) - echo "${action}" - echo "We don't handle that action" >&2 - exit 1 - ;; -esac - -# Map MAC address variables to interface variables -macnet_pre_start "${interface}" - -# Map wireless ESSID variables to interface variables -if [[ -n ${wireless_module} ]] ; then - if wireless_exists "${interface}" ; then - essidnet_pre_start "${interface}" - fi -fi - -# Calculate the metric for our routes -ifvar="$(bash_variable "${interface}")" -metric="metric_${ifvar}" -metric="${!metric}" -if [[ -z ${metric} ]] ; then - if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then - metric="$(calculate_metric "${interface}")" - else - metric="0" - fi - eval metric_${ifvar}="${metric}" -fi - -# Configure our IP address -ip="${ip// /}" -subnet="${subnet// /}" -cidr="$(netmask2cidr "${subnet}")" -broadcast="${broadcast// /}" -[[ -n ${broadcast} ]] && broadcast="broadcast ${broadcast}" - -# If we don't have our address then we flush it and then add our new one -curip="$(interface_get_address "${interface}")" -if [[ ${curip} != "${ip}/${cidr}" ]] ; then - # Just remove IPv4 / inet addresses - interface_del_addresses "${interface}" true - interface_add_address "${interface}" "${ip}/${cidr}" "${broadcast}" -fi - -d="dhcp_${ifvar}" -d=" ${!d} " -[[ ${d} == " " ]] && d=" ${dhcp} " - -# Configure our default route - we only have 1 default route -if [[ ${d} != *" nogateway "* ]] ; then - for r in ${routers}; do - interface_default_route "${interface}" "${r}" "${metric:-0}" && break - done -fi - -# Configure our hostname - but only if we need it -if [[ -n ${hostname} ]] ; then - x="$(hostname)" - [[ ${x} == "(none)" || ${x} == "localhost" ]] && hostname "${hostname}" -fi - -[[ ! -d "${statedir}/${interface}" ]] \ - && mkdir -m 0755 -p "${statedir}/${interface}" - -# Only setup the information we're told to -# By default that's everything -[[ ${d} != *" nodns "* ]] && system_dns "${interface}" -[[ ${d} != *" nontp "* ]] && system_ntp "${interface}" -[[ ${d} != *" nonis "* ]] && system_nis "${interface}" - -if service_inactive "${service}" ; then - mark_service_started "${service}" - if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then - best_interface="$(select_best_interface)" - apply_state "${best_interface}" - else - apply_state "${interface}" - fi -fi - -echo "${action}" -exit 0 - -# vim: ts=4 : diff --git a/net-scripts/net.modules.d/helpers.d/dhcp-state b/net-scripts/net.modules.d/helpers.d/dhcp-state deleted file mode 100644 index b16e6cc..0000000 --- a/net-scripts/net.modules.d/helpers.d/dhcp-state +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2005-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -source "${svclib}/sh/rc-services.sh" -source "${svclib}/net.modules.d/helpers.d/functions" -conf="$(add_suffix /etc/conf.d/net)" -[[ -e ${conf} ]] && source "${conf}" - -service="net.${interface}" - -if [[ ${action} != "up" ]] ; then - service_started "${service}" && mark_service_inactive "${service}" - remove_state "${interface}" false -else - service_inactive "${service}" && mark_service_started "${service}" -fi - -if service_started "${service}" || service_inactive "${service}" ; then - if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then - best_interface="$(select_best_interface)" - apply_state "${best_interface}" - elif [[ ${action} == "up" ]] ; then - apply_state "${interface}" - fi -fi - -# vim: set ft=sh ts=4 : diff --git a/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper b/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper deleted file mode 100755 index ca4778b..0000000 --- a/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash -# Copyright (c) 2005-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -interface="${1##*/dhcpcd-}" -interface="${interface%%.info}" - -if [[ $2 != "up" && $2 != "new" ]] ; then - action="down" -else - action="up" -fi - -[[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh -RC_QUIET_STDOUT="yes" -source "${svclib}/net.modules.d/helpers.d/module-loader" - -# Map MAC address variables to interface variables -macnet_pre_start "${interface}" - -# Map wireless ESSID variables to interface variables -if [[ -n ${wireless_module} ]] ; then - if wireless_exists "${interface}" ; then - essidnet_pre_start "${interface}" - fi -fi - -# Add any search paths if we have any defined -ifvar="$(bash_variable "${interface}")" - -if [[ ${action} == "up" ]] ; then - d="dhcp_${ifvar}" - d=" ${!d} " - [[ ${d} == " " ]] && d=" ${dhcp} " - resolv="${statedir}/${interface}/resolv.conf" - - if [[ ${d} != *" nodns "* ]] ; then - search="dns_search_${ifvar}" - if [[ -n ${!search} ]] ; then - tmp="${resolv}.$$" - egrep -v "^[ \t]*(search|domain)[ \t]*" "${resolv}" > "${tmp}" - echo "search ${!search}" >> "${tmp}" - mv "${tmp}" "${resolv}" - fi - fi - - system_dns_extra "${interface}" "${resolv}" -fi - -# As we override the -c option, we need to call the specified script ourself -opts="dhcpcd_${ifvar}" -exe="${!opts##* -c }" -if [[ -n ${exe} && ${exe} != "${!opts}" ]] ; then - exe="${exe%% *}" -else - exe="/etc/dhcpc/dhcpcd.exe" -fi -[[ -x ${exe} ]] && ( ${exe} "$@" 1>/dev/null ) - -source "${svclib}/net.modules.d/helpers.d/dhcp-state" - -# vim: ts=4 : diff --git a/net-scripts/net.modules.d/helpers.d/functions b/net-scripts/net.modules.d/helpers.d/functions deleted file mode 100644 index 6975bf1..0000000 --- a/net-scripts/net.modules.d/helpers.d/functions +++ /dev/null @@ -1,566 +0,0 @@ -# Copyright (c) 2004-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# Contributed by Roy Marples (uberlord@gentoo.org) - -# We will be loaded after conf.d/rc and conf.d/net so we can set a default -# here. -RC_AUTO_INTERFACE="${RC_AUTO_INTERFACE:-no}" - -netdir="/var/lib/net-scripts" -statedir="${netdir}/state" - -# Contributed by Roy Marples (uberlord@gentoo.org) - -# char* interface_device(char *iface) -# -# Gets the base device of the interface -# Can handle eth0:1 and eth0.1 -# Which returns eth0 in this case -interface_device() { - local dev="${1%%.*}" - [[ ${dev} == "$1" ]] && dev="${1%%:*}" - echo "${dev}" -} - -# char* interface_type(char* iface) -# -# Returns the base type of the interface -# eth, ippp, etc -interface_type() { - echo "${1%%[0-9]*}" -} - -# void save_state(char *interface) -# -# Saves state information regarding the interface -save_state() { - local iface="$1" - local d="${statedir}/${iface}" - - [[ ! -d ${d} ]] && mkdir -m 0755 -p "${d}" - cp -p /etc/resolv.conf /etc/ntp.conf /etc/yp.conf "${d}" 2>/dev/null -} - -# void remove_state(char *interface) -# -# Removes state information regarding the interface -remove_state() { - local d="${statedir}/$1" - - [[ -d ${d} ]] && rm -Rf "${d}" 2>/dev/null - [[ ! ${2:-true} ]] && mkdir -m 0755 -p "${d}" -} - -# void apply_state(char *interface) -# -# Apply's state information about the interface to the system -# If the files in the state dir are not links back to etc then -# we create them if RC_AUTO_INTERFACE="yes" -# -apply_state() { - local iface="$1" - - if [[ -z ${iface} ]] ; then - iface="$(select_best_interface)" - [[ -z ${iface} ]] && return - fi - - local d="${statedir}/${iface}" - if [[ -d ${d} ]] ; then - local files="$(ls "${d}")" - if [[ -n ${files} ]] ; then - if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then - cp -pPR "${d}"/* "${netdir}" - local file - for file in ${files} ; do - # Skip .sv files - [[ ${file} == *".sv" ]] && continue - local link="$(readlink "/etc/${file}" 2>/dev/null)" - if [[ ${link} != "${netdir}/${file}" ]] ; then - [[ -e "/etc/${file}" ]] && rm -f "/etc/${file}" - ln -snf "${netdir}/${file}" "/etc/${file}" - fi - done - else - cp -pPR "${d}"/* /etc - fi - fi - fi - - [[ ${RC_AUTO_INTERFACE} == "yes" ]] && merge_configs -} - -# char* order_interfaces(bool require_gateway) -# -# Lists the interfaces in route metric order that we have configured -# (ie a state dir exists) -# require_gateway defaults to false -order_interfaces() { - local ifaces extra - - ${1:-false} && extra=' && $2=="00000000"' - ifaces="$(awk '{if (NR>1 && $1!="lo"'"${extra}"') print $7, $1}' \ - /proc/net/route \ - | sort -n | cut -d' ' -f2 | uniq)" - - # Append lo if it's up - if ! ${1:-false} ; then - if grep -q "^lo[ \t]*" /proc/net/route ; then - ifaces="${ifaces} lo" - fi - fi - - local i order - for i in ${ifaces}; do - [[ -d "${statedir}/${i}" ]] && order="${order}${i} " - done - - echo "${order}" -} - -# void merge_resolv() -# -# Merges the resolv.conf info from active interfaces -merge_resolv() { - local -a ifaces=( $(order_interfaces) ) - local i j f - - # We only work for ifaces with a resolv.conf - j=${#ifaces[@]} - for (( i=0; i "${f}" - chmod 644 "${f}" - for i in ${new_srvs[@]}; do - echo "nameserver ${i}" >> "${f}" - done - if [[ -n ${new_search} ]] ; then - if [[ ${n_search} == "1" ]] ; then - echo "domain${new_search}" >> "${f}" - else - echo "search${new_search}" >> "${f}" - fi - fi - - [[ -n ${new_sortlist} ]] && echo "sortlist${new_sortlist}" >> "${f}" - - # We seperated the options out using # in our sed call above - # so we set IFS here. If you do any spliting futher down in this function - # then you will need to reset IFS. - local IFS="#" - for i in ${new_opts}; do - [[ -n ${i# } ]] && echo "options ${i# }" >> "${f}" - done - - mv "${f}" "${netdir}/resolv.conf" -} - - -# void merge_ntp() -# -# Merges the ntp.conf info from active interfaces -merge_ntp() { - local -a ifaces=( $(order_interfaces) ) - local i j f - - # We only work for ifaces with a ntp.conf - j=${#ifaces[@]} - for (( i=0; i "${f}" - chmod 644 "${f}" - - echo "restrict default noquery notrust nomodify" >> "${f}" - echo "restrict 127.0.0.1" >> "${f}" - - for i in ${srvs}; do - echo "restrict ${i} nomodify notrap noquery" >> "${f}" - echo "server ${i}" >> "${f}" - done - - echo "driftfile /var/lib/ntp/ntp.drift" >> "${f}" - echo "logfile /var/log/ntp.log" >> "${f}" - - mv "${f}" "${netdir}/ntp.conf" -} - -# void merge_configs() -# -# Merge config files together -merge_configs() { - merge_resolv - merge_ntp -} - -# char* select_best_interface() -# -# Selects the best interface to apply state information to -# This is currently based on routing metrics -select_best_interface() { - local -a ifs=( $(order_interfaces) ) - - # Move lo to the back of the pecking order of it's active - local x=" ${ifs[@]} " - [[ ${x// lo / } != "${x}" ]] && ifs=( ${x// lo / } lo ) - - local iface - for iface in ${ifs[@]} ; do - if [[ -e "${statedir}/${iface}/resolv.conf" ]] ; then - echo "${iface}" - return 0 - fi - done - - echo "${ifs[0]}" -} - -# int calculate_metric(char *interface) -# -# Calculates the best metric for the interface -# The Linux kernel does not use this at the moment, but we use it so that -# default routes remain and we can work out the "best" interface -calculate_metric() { - local iface="$1" exclude='$1!="Iface" && $1!="lo"' - - # Have we already got a metric? - local m="$( awk '$1=="'${iface}'" && $2=="00000000" { print $7 }' \ - /proc/net/route )" - if [[ -n ${m} ]] ; then - echo "${m}" - return 0 - fi - - local itype="$(interface_type "${iface}")" x i - - # If we're not a wireless device then exclude wireless from the - # routing table so we stay < 1000 - if [[ -e /proc/net/wireless ]] ; then - if ! grep -q "^[ \t]*${iface}:[ \t]" /proc/net/wireless ; then - local i="$(sed -n -e 's/^[ \t]*\(.*\):.*/\1/p' /proc/net/wireless)" - for x in ${i} ; do - exclude="${exclude} && "'$1'"!=\"${x}\"" - done - fi - fi - - # Exclude ppp and ippp as well - local ix="ppp|ippp" - [[ ${itype} == "ppp" ]] && ix="ippp" - [[ ${itype} == "ippp" ]] && ix="ppp" - i="$( sed -n -e 's/^[ ]*\('"${ix}"'[0-9]*\):.*$/\1/p' /proc/net/dev )" - for x in ${i} ; do - exclude="${exclude} && "'$1'"!=\"${x}\"" - done - - local m="$( awk "${exclude} { print "'$7'" }" /proc/net/route \ - | sort -rn | head -n 1 | cut -d' ' -f2 )" - m="${m:--1}" - (( m ++ )) - - # If we're a wireless device then add 1000 so that wired interfaces take preference - if [[ -e /proc/net/wireless ]] ; then - grep -q "^[ \t]*${iface}:[ \t]" /proc/net/wireless && (( m+= 1000 )) - fi - - # If we're a ppp device then we add 2000 for ISDN, otherwise 3000 - [[ ${itype} == "ippp" ]] && (( m+= 2000 )) - [[ ${itype} == "ppp" ]] && (( m+= 3000 )) - - echo "${m}" -} - -# int netmask2cidr(char *netmask) -# -# Returns the CIDR of a given netmask -netmask2cidr() { - local binary="" i bin - - for i in ${1//./ }; do - bin="" - while [[ ${i} != "0" ]] ; do - bin=$[${i}%2]${bin} - (( i=i>>1 )) - done - binary="${binary}${bin}" - done - binary="${binary%%0*}" - echo "${#binary}" -} - -# char* netmask2cidr(int cidr) -# -# Returns the netmask of a given CIDR -cidr2netmask() { - local cidr="$1" netmask="" done=0 i sum=0 cur=128 - local octets frac - - (( octets=cidr/8 )) - (( frac=cidr%8 )) - while [[ octets -gt 0 ]] ; do - netmask="${netmask}.255" - (( octets-- )) - (( done++ )) - done - - if [[ ${done} -lt 4 ]] ; then - for (( i=0; i<${frac}; i++ )); do - (( sum+=cur )) - (( cur/=2 )) - done - netmask="${netmask}.${sum}" - (( done++ )) - - while [[ ${done} -lt 4 ]] ; do - netmask="${netmask}.0" - (( done++ )) - done - fi - - echo "${netmask:1}" -} - -# char* ip_network(char *ip, char *netmask) -# -# Returns the network of the ip address -# ip can be 192.168.0.51/24 -# or -# ip can be 192.168.0.51 and netmask is 255.255.255.0 -ip_network() { - local ip="$1" mask="$2" i network x - - # We only work for IPv4 addresses - [[ ${ip} != *.*.*.* ]] && return - - # If we didn't get parameter 2 then assume we have a CIDR - if [[ -z ${mask} ]] ; then - mask="${ip##*/}" - [[ -z ${mask} || ${mask} == ${ip} ]] && return 1 - mask="$(cidr2netmask "${mask}")" - ip="${ip%%/*}" - fi - - ip=( ${ip//./ } ) - mask=( ${mask//./ } ) - - for (( i=0; i<4; i++ )); do - (( x=ip[i] & mask[i] )) - network="${network}${x}" - [[ ${i} -lt 3 ]] && network="${network}." - done - - echo "${network}" -} - -# bool is_function(char* name) -# -# Returns 0 if the given name is a shell function, otherwise 1 -is_function() { - [[ -z $1 ]] && return 1 - [[ $(type -t "$1") == "function" ]] -} - -# void function_wrap(char* source, char* target) -# -# wraps function calls - for example function_wrap(this, that) -# maps function names this_* to that_* -function_wrap() { - local i - - is_function "${2}_depend" && return - - for i in $( typeset -f | grep -o '^'"${1}"'_[^ ]*' ); do - eval "${2}${i#${1}}() { ${i} \"\$@\"; }" - done -} - -# char[] * expand_parameters(char *cmd) -# -# Returns an array after expanding parameters. For example -# "192.168.{1..3}.{1..3}/24 brd +" -# will return -# "192.168.1.1/24 brd +" -# "192.168.1.2/24 brd +" -# "192.168.1.3/24 brd +" -# "192.168.2.1/24 brd +" -# "192.168.2.2/24 brd +" -# "192.168.2.3/24 brd +" -# "192.168.3.1/24 brd +" -# "192.168.3.2/24 brd +" -# "192.168.3.3/24 brd +" -expand_parameters() { - local x="$( eval echo ${@// /_} )" - local -a a=( ${x} ) - - a=( "${a[@]/#/\"}" ) - a=( "${a[@]/%/\"}" ) - echo "${a[*]//_/ }" -} - -# void configure_variables(char *interface, char *option1, [char *option2]) -# -# Maps configuration options from _