From 5248512a484594efe0b1d45e1c3b2bd6bd3a27cd Mon Sep 17 00:00:00 2001 From: Christian Heim Date: Fri, 7 Apr 2006 12:09:33 +0000 Subject: Merging net-scripts changes; fixing ChangeLog's svn path=/baselayout-vserver/trunk/; revision=314 --- ChangeLog.vserver | 30 +++++++- net-scripts/net.modules.d/adsl.sh | 2 +- net-scripts/net.modules.d/apipa.sh | 2 +- net-scripts/net.modules.d/arping.sh | 2 +- net-scripts/net.modules.d/bonding.sh | 4 +- net-scripts/net.modules.d/bridge.sh | 2 +- net-scripts/net.modules.d/dhclient.sh | 99 +++++++++----------------- net-scripts/net.modules.d/dhcpcd.sh | 11 +-- net-scripts/net.modules.d/essidnet.sh | 2 +- net-scripts/net.modules.d/ifconfig.sh | 98 ++++++++++---------------- net-scripts/net.modules.d/ifplugd.sh | 2 +- net-scripts/net.modules.d/ip6to4.sh | 2 +- net-scripts/net.modules.d/ipppd.sh | 2 +- net-scripts/net.modules.d/iproute2.sh | 57 ++------------- net-scripts/net.modules.d/iptunnel.sh | 2 +- net-scripts/net.modules.d/iwconfig.sh | 2 +- net-scripts/net.modules.d/macchanger.sh | 2 +- net-scripts/net.modules.d/macnet.sh | 2 +- net-scripts/net.modules.d/netplugd.sh | 2 +- net-scripts/net.modules.d/pppd.sh | 8 ++- net-scripts/net.modules.d/pump.sh | 7 +- net-scripts/net.modules.d/rename.sh | 2 +- net-scripts/net.modules.d/system.sh | 104 ++++++++++------------------ net-scripts/net.modules.d/tuntap.sh | 36 ++++------ net-scripts/net.modules.d/udhcpc.sh | 55 +++++++++++---- net-scripts/net.modules.d/vlan.sh | 2 +- net-scripts/net.modules.d/wpa_supplicant.sh | 2 +- 27 files changed, 222 insertions(+), 319 deletions(-) diff --git a/ChangeLog.vserver b/ChangeLog.vserver index 439b064..4f84d74 100644 --- a/ChangeLog.vserver +++ b/ChangeLog.vserver @@ -1,7 +1,7 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2006 Gentoo Foundation; Distributed under the GPLv2 - 06 Apr 2006; Christian Heim : + 07 Apr 2006; Christian Heim : Merging latest changes to the baselayout/trunk changes. This merge is based upon revision 1959. @@ -15,37 +15,63 @@ net-scripts/conf.d/net.example | 8 net-scripts/init.d/net.lo | 287 +++-- net-scripts/net.modules.d/adsl | 93 - + net-scripts/net.modules.d/adsl.sh | 93 + net-scripts/net.modules.d/apipa | 46 + net-scripts/net.modules.d/apipa.sh | 46 net-scripts/net.modules.d/arping | 109 -- + net-scripts/net.modules.d/arping.sh | 109 ++ net-scripts/net.modules.d/bonding | 120 -- + net-scripts/net.modules.d/bonding.sh | 120 ++ net-scripts/net.modules.d/bridge | 198 --- + net-scripts/net.modules.d/bridge.sh | 198 +++ net-scripts/net.modules.d/dhclient | 150 -- + net-scripts/net.modules.d/dhclient.sh | 150 ++ net-scripts/net.modules.d/dhcpcd | 123 -- + net-scripts/net.modules.d/dhcpcd.sh | 123 ++ net-scripts/net.modules.d/essidnet | 49 + net-scripts/net.modules.d/essidnet.sh | 49 net-scripts/net.modules.d/ifconfig | 453 -------- + net-scripts/net.modules.d/ifconfig.sh | 453 ++++++++ net-scripts/net.modules.d/ifplugd | 146 -- + net-scripts/net.modules.d/ifplugd.sh | 146 ++ net-scripts/net.modules.d/ip6to4 | 97 - + net-scripts/net.modules.d/ip6to4.sh | 97 + net-scripts/net.modules.d/ipppd | 72 - + net-scripts/net.modules.d/ipppd.sh | 72 + net-scripts/net.modules.d/iproute2 | 392 ------- + net-scripts/net.modules.d/iproute2.sh | 392 +++++++ net-scripts/net.modules.d/iptunnel | 52 + net-scripts/net.modules.d/iptunnel.sh | 52 net-scripts/net.modules.d/iwconfig | 943 ------------------ + net-scripts/net.modules.d/iwconfig.sh | 943 ++++++++++++++++++ net-scripts/net.modules.d/macchanger | 102 - + net-scripts/net.modules.d/macchanger.sh | 102 + net-scripts/net.modules.d/macnet | 43 + net-scripts/net.modules.d/macnet.sh | 43 net-scripts/net.modules.d/netplugd | 124 -- + net-scripts/net.modules.d/netplugd.sh | 124 ++ net-scripts/net.modules.d/pppd | 279 ----- + net-scripts/net.modules.d/pppd.sh | 279 +++++ net-scripts/net.modules.d/pump | 105 -- + net-scripts/net.modules.d/pump.sh | 105 ++ net-scripts/net.modules.d/rename | 63 - + net-scripts/net.modules.d/rename.sh | 63 + net-scripts/net.modules.d/system | 155 -- + net-scripts/net.modules.d/system.sh | 155 ++ net-scripts/net.modules.d/tuntap | 103 - + net-scripts/net.modules.d/tuntap.sh | 103 + net-scripts/net.modules.d/udhcpc | 117 -- + net-scripts/net.modules.d/udhcpc.sh | 117 ++ net-scripts/net.modules.d/vlan | 154 -- + net-scripts/net.modules.d/vlan.sh | 154 ++ net-scripts/net.modules.d/wpa_supplicant | 368 ------- + net-scripts/net.modules.d/wpa_supplicant.sh | 368 +++++++ sbin/functions.sh | 48 sbin/rc | 12 sbin/rc-daemon.sh | 2 sbin/rc-services.sh | 31 sbin/runscript.sh | 163 +-- - 40 files changed, 469 insertions(+), 4964 deletions(-) + 66 files changed, 5125 insertions(+), 4964 deletions(-) 17 Mar 2006; Christian Heim : Merging latest changes to the baselayout/trunk changes. This merge is based diff --git a/net-scripts/net.modules.d/adsl.sh b/net-scripts/net.modules.d/adsl.sh index 0dcc677..2e1423b 100644 --- a/net-scripts/net.modules.d/adsl.sh +++ b/net-scripts/net.modules.d/adsl.sh @@ -90,4 +90,4 @@ adsl_stop() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/apipa.sh b/net-scripts/net.modules.d/apipa.sh index 4ebd469..5ccdc18 100644 --- a/net-scripts/net.modules.d/apipa.sh +++ b/net-scripts/net.modules.d/apipa.sh @@ -43,4 +43,4 @@ apipa_start() { return 1 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/arping.sh b/net-scripts/net.modules.d/arping.sh index 1a476e7..e17df59 100644 --- a/net-scripts/net.modules.d/arping.sh +++ b/net-scripts/net.modules.d/arping.sh @@ -106,4 +106,4 @@ arping_start() { return 1 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/bonding.sh b/net-scripts/net.modules.d/bonding.sh index 6095c74..2b8a086 100644 --- a/net-scripts/net.modules.d/bonding.sh +++ b/net-scripts/net.modules.d/bonding.sh @@ -94,7 +94,7 @@ bonding_stop() { # don't trust the config, get the active list instead slaves="$( \ sed -n -e 's/^Slave Interface: //p' "/proc/net/bonding/${iface}" \ - | xargs \ + | tr '\n' ' ' \ )" [[ -z ${slaves} ]] && return 0 @@ -117,4 +117,4 @@ bonding_stop() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/bridge.sh b/net-scripts/net.modules.d/bridge.sh index ec1e2ff..cf6e605 100644 --- a/net-scripts/net.modules.d/bridge.sh +++ b/net-scripts/net.modules.d/bridge.sh @@ -195,4 +195,4 @@ bridge_stop() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/dhclient.sh b/net-scripts/net.modules.d/dhclient.sh index b8d3312..6514224 100644 --- a/net-scripts/net.modules.d/dhclient.sh +++ b/net-scripts/net.modules.d/dhclient.sh @@ -43,24 +43,15 @@ dhclient_stop() { [[ ! -f ${pidfile} ]] && return 0 ebegin "Stopping dhclient on ${iface}" - local ifvar="$(bash_variable "${iface}")" local d="dhcp_${ifvar}" - d=" ${!d} " - [[ ${d} == " " ]] && d=" ${dhcp} " - - if [[ ${d} == *" release "* ]] ; then - local dhconf="interface \"${iface}\" {\n \ - script \"${MODULES_DIR}/helpers.d/dhclient-wrapper\";\n \ - }\n" - local r="$(echo -e "${dhconf}" \ - | dhclient -q -r -pf "${pidfile}" "${iface}" )" - [[ ${r} == "deconfig" ]] - eend $? "dhclient returned ${r}" + [[ -z ${!d} ]] && d="dhcp" + if [[ " ${!d} " == *" release "* ]] ; then + dhclient -q -r -pf "${pidfile}" "${iface}" else start-stop-daemon --stop --exec /sbin/dhclient --pidfile "${pidfile}" - eend $? fi + eend $? } # bool dhclient_start(char *iface) @@ -69,76 +60,50 @@ dhclient_stop() { # # Returns 0 (true) when a DHCP address is obtained, otherwise 1 dhclient_start() { - local iface="$1" ifvar="$(bash_variable "$1")" + local iface="$1" ifvar="$(bash_variable "$1")" dhconf= local pidfile="/var/run/dhclient-${iface}.pid" - local cffile="/etc/dhcp/dhclient.conf" interface_exists "${iface}" true || return 1 - # Load any dhclient.conf instructions specified by the user - local opts="dhclient_conf_${ifvar}" - local dhconf="${!opts}" - - # Load our options + # Load our default options opts="dhclient_${ifvar}" opts="${!opts}" - # Work out our cffile - local x="${opts##* -cf }" - if [[ ${x} != "${opts}" ]]; then - x="${x%% *}" - if [[ -n ${x} ]]; then - cffile="${x}" - opts="${opts//-cf ${cffile}/}" - fi + 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 - - # Warn that we're going to override parts of their cffile - if [[ -e ${cffile} ]] ; then - opts="${opts} -cf ${cffile}" - if grep -q "^[ \t]*script[ \t]" "${cffile}" ; then - ewarn "The script specified in ${cffile} will not be used" - 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 d="dhcp_${ifvar}" - d=" ${!d} " - [[ ${d} == " " ]] && d=" ${dhcp} " - - local ah="" + 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 + if [[ " ${!d} " != *" nosendhost "* ]] ; then local hname="$(hostname)" if [[ ${hname} != "(none)" && ${hname} != "localhost" ]]; then - ah="send host-name \"${hname}\"\n;" - # Warn that we're going to override parts of their cffile - if [[ -e ${cffile} ]] ; then - if grep -q "^[ \t]*send[ \t]*host-name[ \t]" "${cffile}" ; then - ewarn "The host-name \"${hname}\" will be sent instead of" - ewarn "the one specified in ${cffile}" - vewarn "Set dhcp_${ifvar}=\"nosendhost\" in /etc/conf.d/net" - vewarn "to stop this from happening" - fi - fi + dhconf="${dhconf} interface \"${iface}\" {\n" + dhconf="${dhconf} send host-name \"${hname}\"\n;" + dhconf="${dhconf}}" fi fi - dhconf="${dhconf} interface \"${iface}\" {\n \ - script \"/${MODULES_DIR}/helpers.d/dhclient-wrapper\";\n \ - ${ah} - }" + echo "${dhconf}" > /tmp/dhconf-${iface} # Bring up DHCP for this interface (or alias) ebegin "Running dhclient" - x="$(echo -e "${dhconf}" | dhclient ${opts} -q -1 -pf "${pidfile}")" - # We just check the last 5 letters - [[ ${x:${#x} - 5:5} == "bound" ]] - if [[ $? != "0" ]]; then - # Kill the offending daemon as it likes to hang around - start-stop-daemon --stop --exec /sbin/dhclient --pidfile "${pidfile}" - eend 1 "${x}" - return 1 - fi - eend 0 + 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}")" @@ -147,4 +112,4 @@ dhclient_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/dhcpcd.sh b/net-scripts/net.modules.d/dhcpcd.sh index 516f7e3..2311386 100644 --- a/net-scripts/net.modules.d/dhcpcd.sh +++ b/net-scripts/net.modules.d/dhcpcd.sh @@ -59,7 +59,7 @@ dhcpcd_stop() { else start-stop-daemon --stop --exec /sbin/dhcpcd --pidfile "${pidfile}" fi - eend $? "timed out" + eend $? } # bool dhcpcd_start(char *iface) @@ -100,16 +100,9 @@ dhcpcd_start() { metric="metric_${ifvar}" [[ -n ${!metric} && ${!metric} != "0" ]] && opts="${opts} -m ${!metric}" - # Instruct dhcpcd to use our wrapper - opts="${opts} -c \"${svclib}/net.modules.d/helpers.d/dhcpcd-wrapper\"" - - # Instruct dhcpcd to create it's files in our state dir - opts="${opts} -e \"${statedir}/${iface}\"" - # Bring up DHCP for this interface (or alias) ebegin "Running dhcpcd" - [[ ! -d "${statedir}/${iface}" ]] && mkdir -m 0755 -p "${statedir}/${iface}" eval /sbin/dhcpcd "${opts}" "${iface}" eend $? || return 1 @@ -120,4 +113,4 @@ dhcpcd_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/essidnet.sh b/net-scripts/net.modules.d/essidnet.sh index 69e2db5..689a6ea 100644 --- a/net-scripts/net.modules.d/essidnet.sh +++ b/net-scripts/net.modules.d/essidnet.sh @@ -46,4 +46,4 @@ essidnet_pre_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/ifconfig.sh b/net-scripts/net.modules.d/ifconfig.sh index bec988e..4f7b82c 100644 --- a/net-scripts/net.modules.d/ifconfig.sh +++ b/net-scripts/net.modules.d/ifconfig.sh @@ -55,6 +55,38 @@ ifconfig_exists() { return 1 } +# char* cidr2netmask(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}" +} + # void ifconfig_up(char *iface) # # provides a generic interface for bringing interfaces up @@ -383,71 +415,11 @@ ifconfig_add_address() { interface_up "${real_iface}" # Some kernels like to apply lo with an address when they are brought up - if [[ ${iface} == "lo" && ${config[@]} == "127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255" ]]; then - ifconfig "${iface}" 0.0.0.0 + if [[ ${config[@]} == "127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255" ]]; then + is_loopback "${iface}" && ifconfig "${iface}" 0.0.0.0 fi ifconfig "${iface}" ${config[@]} - r="$?" - [[ ${r} != "0" ]] && return ${r} - - local metric ifvar="$(bash_variable "${real_iface}")" - # Remove the newly added route and replace with our metric - metric="metric_${ifvar}" - [[ ${!metric:-0} == "0" ]] && return ${r} - - if [[ -z ${netmask} ]]; then - for (( i=1; i<${#config[@]}-1; i++ )); do - if [[ ${config[i]} == "netmask" ]]; then - netmask="${config[i+1]}" - cidr="$(netmask2cidr "${netmask}")" - break - fi - done - [[ -z ${netmask} ]] && return ${r} - fi - - local network="$(ip_network "${ip}" "${netmask}")" - - if route del -net "${network}/${cidr}" metric 0 dev "${iface}" \ - 2>/dev/null ; then - route add -net "${network}/${cidr}" metric "${!metric:-0}" dev "${iface}" - fi - - return ${r} -} - -# void ifconfig_route_metric(char* interface, int metric) -# -# Change all routes for an interface to a given metric -ifconfig_route_metric() { - local dest gateway mask flags metric ref use - route -n | grep " $1$" | { - while read dest gateway mask flags metric ref use ; do - if [[ ${gateway} != "0.0.0.0" ]]; then - gateway="gw ${gateway}" - else - unset gateway - fi - route del ${dest} - route add -net ${dest} netmask ${mask} ${gateway} metric "$2" dev "$1" - done - } -} - -# void ifconfig_default_route(char* interface, char* gateway_ip, int metric) -# -# Force default route to the specified gateway -ifconfig_default_route() { - local metric="${3:-0}" - - # Delete any existing default routes - while true ; do - route del default metric "${metric}" dev "$1" 2>/dev/null || break - done - - # Then we add our route - route add default gw "$2" metric "${metric}" dev "$1" } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/ifplugd.sh b/net-scripts/net.modules.d/ifplugd.sh index 8fa1cc1..110b443 100644 --- a/net-scripts/net.modules.d/ifplugd.sh +++ b/net-scripts/net.modules.d/ifplugd.sh @@ -143,4 +143,4 @@ ifplugd_stop() { eend $? } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/ip6to4.sh b/net-scripts/net.modules.d/ip6to4.sh index 4dde13f..cd3f1f6 100644 --- a/net-scripts/net.modules.d/ip6to4.sh +++ b/net-scripts/net.modules.d/ip6to4.sh @@ -94,4 +94,4 @@ ip6to4_start() { } # vim:ts=4 -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/ipppd.sh b/net-scripts/net.modules.d/ipppd.sh index 0280ea6..943f558 100644 --- a/net-scripts/net.modules.d/ipppd.sh +++ b/net-scripts/net.modules.d/ipppd.sh @@ -69,4 +69,4 @@ ipppd_stop() { } # vim:ts=4 -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/iproute2.sh b/net-scripts/net.modules.d/iproute2.sh index 498eea6..f600704 100644 --- a/net-scripts/net.modules.d/iproute2.sh +++ b/net-scripts/net.modules.d/iproute2.sh @@ -78,8 +78,7 @@ iproute2_down() { iproute2_is_up() { local check="\" addr="${2:-false}" ${addr} && check="${check}.*inet " - ip addr show "$1" | xargs | grep -Eq "${check}" && return 0 - return 1 + ip addr show "$1" | tr '\n' ' ' | grep -Eq "${check}" } # void iproute2_set_flag(char *iface, char *flag, bool enabled) @@ -232,8 +231,9 @@ iproute2_add_address() { config=( "${config[@]//pointopoint/peer}" ) # Always scope lo addresses as host unless specified otherwise - [[ ${iface} == "lo" && " ${config[@]} " != *" scope "* ]] \ - && config=( "${config[@]}" "scope host" ) + if [[ " ${config[@]} " != *" scope "* ]] ; then + is_loopback "${iface}" && config=( "${config[@]}" "scope host" ) + fi # IPv4 specifics if [[ ${config[@]} == *.*.*.* ]] ; then @@ -246,30 +246,11 @@ iproute2_add_address() { interface_up "${iface}" # Some kernels like to apply lo with an address when they are brought up - if [[ ${iface} == "lo" \ - && ${config[@]} == "127.0.0.1/8 brd 127.255.255.255 scope host" ]] ; then - ip addr del dev "${iface}" 127.0.0.1/8 2>/dev/null + if [[ ${config[@]} == "127.0.0.1/8 brd 127.255.255.255 scope host" ]] ; then + is_loopback "${iface}" && ip addr del dev "${iface}" 127.0.0.1/8 2>/dev/null fi ip addr add dev "${iface}" ${config[@]} - local r="$?" - [[ ${r} != "0" ]] && return "${r}" - - local ifvar="$( bash_variable "${iface}" )" - # Remove the newly added route and replace with our metric - local metric="metric_${ifvar}" - [[ ${!metric:-0} == "0" ]] && return "${r}" - - local network="$( ip_network "${config[0]}" )" - [[ -z ${network} ]] && return "${r}" - - local cidr="${config[0]##*/}" - if ip route del "${network}/${cidr}" metric 0 dev "${iface}" \ - 2>/dev/null ; then - ip route add "${network}/${cidr}" metric "${!metric:-0}" dev "${iface}" - fi - - return "${r}" } # bool iproute2_pre_start(char *interface) @@ -355,30 +336,6 @@ iproute2_post_start() { return 0 } -# void iproute2_route_metric(char* interface, int metric) -# -# Change all routes for an interface to a given metric -iproute2_route_metric() { - local route="" - ip route | grep " dev $1" | { - while read route ; do - ip route del ${route} - ip route add ${route} metric "$2" - done - } -} - -# void iproute2_default_route(char* interface, char* gateway_ip, int metric) -# -# Force default route to the specified gateway, optionally on -# the given interface -iproute2_default_route() { - local metric="${3:-0}" - - ip route change default via "$2" metric "${metric}" dev "$1" 2>/dev/null \ - || ip route append default via "$2" metric "${metric}" dev "$1" 2>/dev/null -} - # void iproute2_post_stop(char* interface) iproute2_post_stop() { local iface="$1" rule="" @@ -389,4 +346,4 @@ iproute2_post_stop() { ip route flush cache dev "${iface}" } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/iptunnel.sh b/net-scripts/net.modules.d/iptunnel.sh index ff62bb9..860f9aa 100644 --- a/net-scripts/net.modules.d/iptunnel.sh +++ b/net-scripts/net.modules.d/iptunnel.sh @@ -49,4 +49,4 @@ iptunnel_stop() { eend $? } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/iwconfig.sh b/net-scripts/net.modules.d/iwconfig.sh index 0711043..f19afb2 100644 --- a/net-scripts/net.modules.d/iwconfig.sh +++ b/net-scripts/net.modules.d/iwconfig.sh @@ -940,4 +940,4 @@ iwconfig_post_stop() { iwconfig_defaults "${iface}" } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/macchanger.sh b/net-scripts/net.modules.d/macchanger.sh index 76720b6..6331997 100644 --- a/net-scripts/net.modules.d/macchanger.sh +++ b/net-scripts/net.modules.d/macchanger.sh @@ -99,4 +99,4 @@ macchanger_pre_start() { return 0 #important } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/macnet.sh b/net-scripts/net.modules.d/macnet.sh index 6be0a4b..86a3453 100644 --- a/net-scripts/net.modules.d/macnet.sh +++ b/net-scripts/net.modules.d/macnet.sh @@ -40,4 +40,4 @@ macnet_pre_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/netplugd.sh b/net-scripts/net.modules.d/netplugd.sh index cd8ebe2..f0dfdb7 100644 --- a/net-scripts/net.modules.d/netplugd.sh +++ b/net-scripts/net.modules.d/netplugd.sh @@ -121,4 +121,4 @@ netplugd_stop() { eend $? } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/pppd.sh b/net-scripts/net.modules.d/pppd.sh index 97caf6b..df5cbd2 100644 --- a/net-scripts/net.modules.d/pppd.sh +++ b/net-scripts/net.modules.d/pppd.sh @@ -124,6 +124,12 @@ pppd_start() { return 1 fi + if [[ ${!link} == "/"* && ! -e ${!link} ]] ; then + eerror "${link} does not exist" + eerror "Please verify hardware or kernel module (driver)" + return 1 + fi + # Might or might not be set in conf.d/net local user password i username="username_${ifvar}" @@ -276,4 +282,4 @@ pppd_stop() { eend $? } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/pump.sh b/net-scripts/net.modules.d/pump.sh index a2dacfc..51fc6ad 100644 --- a/net-scripts/net.modules.d/pump.sh +++ b/net-scripts/net.modules.d/pump.sh @@ -84,10 +84,7 @@ pump_start() { metric="metric_${ifvar}" [[ -n ${!metric} ]] && opts="${opts} --route-metric ${!metric}" - [[ ! -d "${statedir}/${iface}" ]] && mkdir -m 0755 -p "${statedir}/${iface}" - - opts="${opts} --win-client-ident --etc-dir=${statedir}/${iface}" - opts="${opts} --script \"${svclib}/net.modules.d/helpers.d/pump-wrapper\"" + opts="${opts} --win-client-ident" opts="${opts} --keep-up --interface ${iface}" # Bring up DHCP for this interface (or alias) @@ -102,4 +99,4 @@ pump_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/rename.sh b/net-scripts/net.modules.d/rename.sh index 43a6da1..f3de442 100644 --- a/net-scripts/net.modules.d/rename.sh +++ b/net-scripts/net.modules.d/rename.sh @@ -60,4 +60,4 @@ rename_pre_start() { exit 1 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/system.sh b/net-scripts/net.modules.d/system.sh index 5d841d3..c32bb74 100644 --- a/net-scripts/net.modules.d/system.sh +++ b/net-scripts/net.modules.d/system.sh @@ -18,96 +18,66 @@ system_expose() { ntp_servers nis_domain nis_servers } -system_dns_extra() { - local iface="$1" ifvar="$(bash_variable "$1")" out="$2" x sortlist - local -a options - - x="dns_options_${ifvar}[@]" - options=( "${!x}" ) - [[ -z ${options} ]] && options=( "${dns_options[@]}" ) - for x in "${options[@]}" ; do - echo "options ${x}" >> "${out}" - done - - sortlist="dns_sortlist_${ifvar}" - [[ -z ${!sortlist} ]] && sortlist="dns_sortlist" - [[ -n ${!sortlist} ]] && echo "sortlist ${!sortlist}" >> "${out}" -} - system_dns() { - local iface="$1" ifvar="$(bash_variable "$1")" x domain search - local conffile="${statedir}/${iface}/resolv.conf" tmpfile="${conffile}.$$" - local -a servers + local iface="$1" ifvar="$(bash_variable "$1")" x= domain= search= + local buffer= + local -a servers=() servers="dns_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="dns_servers[@]" - servers="${!servers}" domain="dns_domain_${ifvar}" [[ -z ${!domain} ]] && domain="dns_domain" - domain="${!domain}" search="dns_search_${ifvar}" [[ -z ${!search} ]] && search="dns_search" - search="${!search}" - [[ -z ${servers} && -z ${domain} && -z ${search} ]] && return 0 - - echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" - chmod 644 "${tmpfile}" - - if [[ -n ${domain} ]] ; then - # Strip leading and trailing spaces - domain="${domain# *}" - domain="${domain%* }" - if [[ ${domain} == *" "* ]] ; then - [[ -z ${search} ]] && search="${domain}" - domain="${domain%% *}" - fi - echo "domain ${domain}" >> "${tmpfile}" - fi + [[ -z ${!servers} && -z ${!domain} && -z ${!search} ]] && return 0 - for x in ${servers} ; do - echo "nameserver ${x}" >> "${tmpfile}" - done - - [[ -n ${search} ]] && echo "search ${search}" >> "${tmpfile}" + buffer="# Generated by net-scripts for interface ${iface}\n" + [[ -n ${!domain} ]] && buffer="${buffer}domain ${!domain}\n" + [[ -n ${!search} ]] && buffer="${buffer}search ${!search}\n" - system_dns_extra "${iface}" "${tmpfile}" + for x in ${!servers} ; do + buffer="${buffer}nameserver ${x}\n" + done - mv "${tmpfile}" "${conffile}" + # Support resolvconf if we have it. + if [[ -x /sbin/resolvconf ]] ; then + echo -e "${buffer}" | resolvconf -a "${iface}" + else + echo -e "${buffer}" > /etc/resolv.conf + chmod 644 /etc/resolv.conf + fi } system_ntp() { - local iface="$1" ifvar="$(bash_variable "$1")" x - local conffile="${statedir}/${iface}/ntp.conf" tmpfile="${conffile}.$$" - local -a servers + local iface="$1" ifvar="$(bash_variable "$1")" x= buffer= + local -a servers=() servers="ntp_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="ntp_servers[@]" [[ -z ${!servers} ]] && return 0 - echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" - chmod 644 "${tmpfile}" - - echo "restrict default noquery notrust nomodify" >> "${tmpfile}" - echo "restrict 127.0.0.1" >> "${tmpfile}" + buffer="# Generated by net-scripts for interface ${iface}\n" + buffer="${buffer}restrict default noquery notrust nomodify\n" + buffer="${buffer}restrict 127.0.0.1\n" for x in ${!servers} ; do - echo "restrict ${x} nomodify notrap noquery" >> "${tmpfile}" - echo "server ${x}" >> "${tmpfile}" + buffer="${buffer}restrict ${x} nomodify notrap noquery\n" + buffer="${buffer}server ${x}\n" done - echo "driftfile /var/lib/ntp/ntp.drift" >> "${tmpfile}" - echo "logfile /var/log/ntp.log" >> "${tmpfile}" + buffer="${buffer}driftfile /var/lib/ntp/ntp.drift\n" + buffer="${buffer}logfile /var/log/ntp.log\n" - mv "${tmpfile}" "${conffile}" + echo -e "${buffer}" > /etc/ntp.conf + chmod 644 /etc/ntp.conf } system_nis() { - local iface="$1" ifvar="$(bash_variable "$1")" domain x - local conffile="${statedir}/${iface}/yp.conf" tmpfile="${conffile}.$$" - local -a servers + local iface="$1" ifvar="$(bash_variable "$1")" domain= x= buffer= + local -a servers=() servers="nis_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="nis_servers[@]" @@ -117,25 +87,25 @@ system_nis() { [[ -z ${!servers} && -z ${!domain} ]] && return 0 - echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" - chmod 644 "${tmpfile}" + buffer="# Generated by net-scripts for interface ${iface}\n" if [[ -n ${!domain} ]] ; then hostname -y "${!domain}" if [[ -n ${!servers} ]] ; then for x in ${!servers} ; do - echo "domain ${!domain} server ${x}" >> "${tmpfile}" + buffer="${buffer}domain ${!domain} server ${x}\n" done else - echo "domain ${!domain} broadcast" >> "${tmpfile}" + buffer="${buffer}domain ${!domain} broadcast\n" fi else for x in ${!servers} ; do - echo "ypserver ${x}" >> "${tmpfile}" + buffer="${buffer}ypserver ${x}\n" done fi - mv "${tmpfile}" "${conffile}" + echo -e "${buffer}" > /etc/yp.conf + chmod 644 /etc/yp.conf } # bool system_post_start(char *iface) @@ -152,4 +122,4 @@ system_pre_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/tuntap.sh b/net-scripts/net.modules.d/tuntap.sh index e0d1865..dc40523 100644 --- a/net-scripts/net.modules.d/tuntap.sh +++ b/net-scripts/net.modules.d/tuntap.sh @@ -1,5 +1,7 @@ -# Copyright (c) 2004-2006 Gentoo Foundation +#!/bin/bash +# Copyright (c) 2004-2005 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 @@ -17,12 +19,6 @@ tunctl() { tuntap_depend() { before interface macchanger functions interface_exists interface_type -} - -# void tuntap_expose(void) -# -# Expose variables that can be configured -tuntap_expose() { variables tunctl } @@ -52,34 +48,28 @@ tuntap_check_kernel() { # # Returns 0 if the tun/tap interface exists, otherwise 1 tuntap_exists() { - local itype="$(interface_type "$1")" - [[ ${itype} != "tun" && ${itype} != "tap" ]] && return 1 - interface_exists "$1" + [[ -n $(get_options tuntap "net.$1") ]] } # bool tuntap_pre_start(char *iface) # # Create the device, give it the right perms tuntap_pre_start() { - local iface="$1" itype="$(interface_type "$1")" - - # Check that we are a valid tun/tap interface - # NOTE - the name can be anything as we define it - # but for simplicity in the config we require either - # tun or tap - [[ ${itype} != "tun" && ${itype} != "tap" ]] && return 0 + local iface="$1" ifvar="$(bash_variable "$1")" + local tuntap="tuntap_${ifvar}" + [[ -z ${!tuntap} ]] && return 0 tuntap_check_kernel || return 1 ebegin "Creating Tun/Tap interface ${iface}" if [[ -x /usr/sbin/openvpn ]] ; then - openvpn --mktun --dev "${iface}" >/dev/null + openvpn --mktun --dev-type "${!tuntap}" --dev "${iface}" \ + > /dev/null else - local ifvar="$(bash_variable "${iface}")" local opts="tunctl_${ifvar}" tunctl ${!opts} -t "${iface}" >/dev/null fi - eend $? + eend $? && save_options tuntap "${!tuntap}" } # bool tuntap_stop(char *iface) @@ -93,11 +83,13 @@ tuntap_stop() { ebegin "Destroying Tun/Tap interface ${iface}" if [[ -x /usr/sbin/openvpn ]] ; then - openvpn --rmtun --dev "${iface}" >/dev/null + openvpn --rmtun \ + --dev-type "$(get_options tuntap)" \ + --dev "${iface}" > /dev/null else tunctl -d "${fiace}" >/dev/null fi eend $? } -# vim: set ft=sh ts=4 : +# vim:ts=4 diff --git a/net-scripts/net.modules.d/udhcpc.sh b/net-scripts/net.modules.d/udhcpc.sh index 041afb2..3c646fe 100644 --- a/net-scripts/net.modules.d/udhcpc.sh +++ b/net-scripts/net.modules.d/udhcpc.sh @@ -47,17 +47,20 @@ udhcpc_stop() { local ifvar="$(bash_variable "${iface}")" d="dhcp_${ifvar}" - d=" ${!d} " - [[ ${d} == " " ]] && d=" ${dhcp} " + [[ -z ${!d} ]] && d="dhcp" - if [[ ${d} == *" release "* ]]; then + if [[ " ${!d} " == *" release "* ]]; then kill -s USR2 "${pid}" &>/dev/null [[ -f "/var/cache/udhcpc-${iface}.lease" ]] \ && rm "/var/cache/udhcpc-${iface}.lease" fi start-stop-daemon --stop --exec /sbin/udhcpc --pidfile "${pidfile}" - eend $? + eend $? || return 1 + + [[ -e /var/run/udhcpc-"${iface}".conf ]] \ + && rm -f /var/run/udhcpc-"${iface}".conf + return 0 } # bool udhcpc_start(char *iface) @@ -76,10 +79,9 @@ udhcpc_start() { opts="${!opts}" d="dhcp_${ifvar}" - d=" ${!d} " - [[ ${d} == " " ]] && d=" ${dhcp} " + [[ -z ${!d} ]] && d="dhcp" - if [[ " ${d} " != *" nosendhost "* ]]; then + if [[ " ${!d} " != *" nosendhost "* ]]; then if [[ ! " ${opts}" =~ " -([hH] |-hostname=)" ]]; then local hname="$(hostname)" [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \ @@ -87,6 +89,31 @@ udhcpc_start() { fi fi + # Setup options for the udhcpc script + # We pass these via a seperate config file so we're nice and fast + # maybe oneday, udhcp will accept custom env vars. + local conf="/var/run/udhcpc-${iface}.conf" + echo "# udhcpc runtime configuration for interface ${iface}" > "${conf}" + if [[ " ${!d} " == *" nodns "* ]] ; then + #opts="${opts} --env PEER_DNS=no" + echo "PEER_DNS=no" >> "${conf}" + else + #opts="${opts} --env PEER_DNS=yes" + echo "PEER_DNS=yes" >> "${conf}" + fi + if [[ " ${!d} " == *" nontp "* ]] ; then + #opts="${opts} --env PEER_NTP=no" + echo "PEER_NTP=no" >> "${conf}" + else + #opts="${opts} --env PEER_NTP=yes" + echo "PEER_NTP=yes" >> "${conf}" + fi + local metric="metric_${ifvar}" + if [[ -n ${!metric} ]] ; then + #opts="${opts} --env IF_METRIC=${!metric}" + echo "IF_METRIC=${!metric}" >> "${conf}" + fi + # Bring up DHCP for this interface (or alias) ebegin "Running udhcpc" @@ -99,13 +126,11 @@ udhcpc_start() { fi fi - x="$( eval udhcpc "${opts}" --now --pidfile="${pidfile}" \ - --interface="${iface}" \ - --script="${MODULES_DIR}/helpers.d/udhcpc-wrapper" 2>&1 \ - | egrep -v '^info,' )" - # We just check the last 5 letters - [[ ${x:((${#x} - 5)):5} == "bound" ]] - eend "$?" "${x}" || return 1 + eval start-stop-daemon --start --exec /sbin/udhcpc \ + --pidfile "${pidfile}" \ + -- "${opts}" --interface="${iface}" --now --quiet \ + --pidfile="${pidfile}" + eend $? || return 1 # DHCP succeeded, show address retrieved local addr="$(interface_get_address "${iface}")" @@ -114,4 +139,4 @@ udhcpc_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/vlan.sh b/net-scripts/net.modules.d/vlan.sh index 393bc72..e7f0735 100644 --- a/net-scripts/net.modules.d/vlan.sh +++ b/net-scripts/net.modules.d/vlan.sh @@ -151,4 +151,4 @@ vlan_stop() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : diff --git a/net-scripts/net.modules.d/wpa_supplicant.sh b/net-scripts/net.modules.d/wpa_supplicant.sh index 22343a7..f2357bd 100644 --- a/net-scripts/net.modules.d/wpa_supplicant.sh +++ b/net-scripts/net.modules.d/wpa_supplicant.sh @@ -365,4 +365,4 @@ wpa_supplicant_post_stop() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : -- cgit v1.2.3-65-gdbad