aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2013-03-18 17:10:58 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2013-04-06 17:26:10 -0500
commit1e6cef540789ce8b781eb3037ff7058c1a07c07d (patch)
treece43b4782513deea473fc9aa3348c146307dda4f
downloadnetifrc-1e6cef540789ce8b781eb3037ff7058c1a07c07d.tar.gz
netifrc-1e6cef540789ce8b781eb3037ff7058c1a07c07d.tar.bz2
netifrc-1e6cef540789ce8b781eb3037ff7058c1a07c07d.zip
initial commit ported from OpenRc
-rw-r--r--Makefile19
-rw-r--r--Makefile.inc3
-rw-r--r--doc/.gitignore1
-rw-r--r--doc/Makefile11
-rw-r--r--doc/net.example.BSD.in445
-rw-r--r--doc/net.example.Linux.in1247
-rw-r--r--init.d/.gitignore2
-rw-r--r--init.d/Makefile23
-rw-r--r--init.d/net.lo.in789
-rw-r--r--mk/dist.mk38
-rw-r--r--mk/git.mk8
-rw-r--r--mk/gitignore.mk15
-rw-r--r--mk/os-BSD.mk9
-rw-r--r--mk/os-FreeBSD.mk6
-rw-r--r--mk/os-Linux.mk8
-rw-r--r--mk/os-NetBSD.mk7
-rw-r--r--mk/os.mk11
-rw-r--r--mk/scripts.mk58
-rw-r--r--mk/subdir.mk31
-rw-r--r--mk/sys.mk52
-rw-r--r--net/.gitignore4
-rw-r--r--net/Makefile24
-rw-r--r--net/adsl.sh74
-rw-r--r--net/apipa.sh48
-rw-r--r--net/arping.sh131
-rw-r--r--net/bonding.sh223
-rw-r--r--net/br2684ctl.sh50
-rw-r--r--net/bridge.sh190
-rw-r--r--net/ccwgroup.sh106
-rw-r--r--net/clip.sh221
-rw-r--r--net/dhclient.sh76
-rw-r--r--net/dhcpcd.sh88
-rw-r--r--net/ethtool.sh52
-rw-r--r--net/firewalld.sh38
-rw-r--r--net/ifconfig.sh.BSD.in264
-rw-r--r--net/ifconfig.sh.Linux.in328
-rw-r--r--net/ifplugd.sh94
-rw-r--r--net/ifwatchd.sh.BSD.in59
-rw-r--r--net/ip6rd.sh175
-rw-r--r--net/ip6to4.sh116
-rw-r--r--net/ipppd.sh48
-rw-r--r--net/iproute2.sh404
-rw-r--r--net/iwconfig.sh.BSD.in593
-rw-r--r--net/iwconfig.sh.Linux.in763
-rw-r--r--net/macchanger.sh92
-rw-r--r--net/macnet.sh19
-rw-r--r--net/macvlan.sh53
-rw-r--r--net/netplugd.sh96
-rw-r--r--net/pppd.sh243
-rw-r--r--net/pump.sh59
-rw-r--r--net/ssidnet.sh24
-rw-r--r--net/system.sh122
-rw-r--r--net/tuntap.sh102
-rw-r--r--net/udhcpc.sh.Linux.in110
-rw-r--r--net/vlan.sh146
-rw-r--r--net/wpa_supplicant.sh212
-rw-r--r--sh/.gitignore3
-rw-r--r--sh/Makefile21
-rw-r--r--sh/ifwatchd-carrier.sh.in5
-rw-r--r--sh/ifwatchd-nocarrier.sh.in5
-rw-r--r--sh/udhcpc-hook.sh.in117
61 files changed, 8381 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d6c61a1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+# gentoo-oldnet Makefile
+# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+include Makefile.inc
+
+SUBDIR = doc init.d net sh
+
+INSTALLAFTER= _installafter
+
+MK= mk
+include ${MK}/sys.mk
+include ${MK}/os.mk
+include ${MK}/subdir.mk
+include ${MK}/dist.mk
+include ${MK}/git.mk
+
+_installafter:
+ ${ECHO} "${VERSION}${GITVER}" > ${DESTDIR}/${LIBEXECDIR}/version
diff --git a/Makefile.inc b/Makefile.inc
new file mode 100644
index 0000000..2b2fbc4
--- /dev/null
+++ b/Makefile.inc
@@ -0,0 +1,3 @@
+NAME= gentoo-oldnet
+VERSION= 0.1
+PKG= ${NAME}-${VERSION}
diff --git a/doc/.gitignore b/doc/.gitignore
new file mode 100644
index 0000000..a2c6f83
--- /dev/null
+++ b/doc/.gitignore
@@ -0,0 +1 @@
+net.example
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 0000000..840336d
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,11 @@
+DIR= ${DOCDIR}/gentoo-oldnet
+SRCS= net.example.in
+INC= net.example
+
+MK= ../mk
+include ${MK}/os.mk
+
+%.example.in: %.example${SFX}
+ ${CP} $< $@
+
+include ${MK}/scripts.mk
diff --git a/doc/net.example.BSD.in b/doc/net.example.BSD.in
new file mode 100644
index 0000000..3aae310
--- /dev/null
+++ b/doc/net.example.BSD.in
@@ -0,0 +1,445 @@
+##############################################################################
+# QUICK-START
+#
+# The quickest start is if you want to use DHCP.
+# In that case, everything should work out of the box, no configuration
+# necessary, though the startup script will warn you that you haven't
+# specified anything.
+
+# WARNING :- some examples have a mixture of IPv4 (ie 192.168.0.1) and IPv6
+# (ie 4321:0:1:2:3:4:567:89ab) internet addresses. They only work if you have
+# the relevant kernel option enabled. So if you don't have an IPv6 enabled
+# kernel then remove the IPv6 address from your config.
+
+# If you want to use a static address or use DHCP explicitly, jump
+# down to the section labeled INTERFACE HANDLERS.
+#
+# If you want to do anything more fancy, you should take the time to
+# read through the rest of this file.
+
+##############################################################################
+# MODULES
+#
+# We now support modular networking scripts which means we can easily
+# add support for new interface types and modules while keeping
+# compatibility with existing ones.
+#
+# Modules load by default if the package they need is installed. If
+# you specify a module here that doesn't have its package installed
+# then you get an error stating which package you need to install.
+# Ideally, you only use the modules setting when you have two or more
+# packages installed that supply the same service.
+#
+# In other words, you probably should DO NOTHING HERE...
+
+##############################################################################
+# INTERFACE HANDLERS
+
+# For a static configuration, use something like this
+#config_eth0="192.168.0.2/24"
+
+# If you need more than one address, you can use something like this
+# NOTE: ifconfig creates an aliased device for each extra IPv4 address
+# (eth0:1, eth0:2, etc)
+# iproute2 does not do this as there is no need to
+#config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24"
+
+# You can also use IPv6 addresses
+# (you should always specify a prefix length with IPv6 here)
+#config_eth0="192.168.0.2/24 4321:0:1:2:3:4:567:89ab/64 4321:0:1:2:3:4:567:89ac/64"
+
+# If you wish to keep existing addresses + routing and the interface is up,
+# you can specify a noop (no operation). If the interface is down or there
+# are no addresses assigned, then we move onto the next step (default dhcp)
+# This is useful when configuring your interface with a kernel command line
+# or similar
+#config_eth0="noop 192.168.0.2/24"
+
+# If you don't want ANY address (only useful when calling for advanced stuff)
+#config_eth0="null"
+
+# Here's how to do routing if you need it
+# We add an IPv4 default route, IPv4 subnet route and an IPv6 unicast route
+#routes_eth0="default via 192.168.0.1
+#10.0.0.0/8 via 192.168.0.1
+#::/0"
+
+# If a specified module fails (like dhcp - see below), you can specify a
+# fallback like so
+#fallback_eth0="192.168.0.2 netmask 255.255.255.0"
+#fallback_routes_eth0="default via 192.168.0.1"
+
+# NOTE: fallback entry must match the entry location in config_eth0
+# As such you can only have one fallback route.
+# Also, if you do not set a fallback_routes entry for an interface, the
+# routes entry will be used if that is set.
+
+# Some users may need to alter the MTU - here's how
+#mtu_eth0="1500"
+
+# Most drivers that report carrier status function correctly, but some do not
+# One of these faulty drivers is for the Intel e1000 network card, but only
+# at boot time. To get around this you may alter the carrier_timeout value for
+# the interface. 0 is disable and any other number of seconds is how
+# long we wait for carrier. The current default is disabled.
+#carrier_timeout_eth0=0
+
+# You may wish to disable the interface being brought down when stopping.
+# This is only of use for WakeOnLan.
+#ifdown_eth0="NO"
+
+##############################################################################
+# OPTIONAL MODULES
+
+#-----------------------------------------------------------------------------
+# WIRELESS (802.11 support)
+# Wireless can be provided by BSDs ifconfig (iwconfig) or wpa_supplicant
+# wpa_supplicant is preferred, use the modules directive to prefer iwconfig.
+#modules="iwconfig"
+
+# ifconfig (iwconig) support is a one shot script - wpa_supplicant is daemon
+# that scans, associates and re-configures if association is lost.
+# We call it iwconfig to separate the wireless setup from ifconfig.
+####################################
+# HINTS
+#
+# Most users will just need to set the following options
+# key_SSID1="s:yourkeyhere enc open" # s: means a text key
+# key_SSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key
+# preferred_aps="SSID1 SSID2"
+#
+# Clear? Good. Now configure your wireless network below
+
+####################################
+# SETTINGS
+# Hard code an SSID to an interface - leave this unset if you wish the driver
+# to scan for available Access Points
+# I would only set this as a last resort really - use the preferred_aps
+# setting at the bottom of this file
+#essid_eth0='foo'
+
+# Some drivers/hardware don't scan all that well. We have no control over this
+# but we can say how many scans we want to do to try and get a better sweep of
+# the area. The default is 1.
+#scans_eth0="1"
+
+#Channel can be set (1-14), but defaults to 3 if not set.
+#
+# The below is taken verbatim from the BSD wavelan documentation found at
+# http://www.netbsd.org/Documentation/network/wavelan.html
+# There are 14 channels possible; We are told that channels 1-11 are legal for
+# North America, channels 1-13 for most of Europe, channels 10-13 for France,
+# and only channel 14 for Japan. If in doubt, please refer to the documentation
+# that came with your card or access point. Make sure that the channel you
+# select is the same channel your access point (or the other card in an ad-hoc
+# network) is on. The default for cards sold in North America and most of Europe
+# is 3; the default for cards sold in France is 11, and the default for cards
+# sold in Japan is 14.
+#channel_eth0="3"
+
+# Setup any other config commands. This is basically the ifconfig argument
+# without the ifconfig $iface.
+#ifconfig_eth0=""
+# You can do the same per SSID too.
+#ifconfig_SSID=""
+
+# Seconds to wait until associated. The default is to wait 10 seconds.
+# 0 means wait indefinitely. WARNING: this can cause an infinite delay when
+# booting.
+#associate_timeout_eth0="5"
+
+# Define a WEP key per SSID or MAC address (of the AP, not your card)
+# The encryption type (open or restricted) must match the
+# encryption type on the Access Point.
+# To set a hex key, prefix with 0x
+#key_SSID="0x12341234123412341234123456"
+# or you can use strings. Passphrase IS NOT supported
+#key_SSID="foobar"
+#key_SSID="foobar"
+
+# WEP key for the AP with MAC address 001122334455
+#mac_key_001122334455="foobar"
+
+# You can also override the interface settings found in /etc/conf.d/net
+# per SSID - which is very handy if you use different networks a lot
+#config_SSID="dhcp"
+#routes_SSID=
+#fallback_SSID=
+
+# Setting name/domain server causes /etc/resolv.conf to be overwritten
+# Note that if DHCP is used, and you want this to take precedence then
+# please put -R in your dhcpcd options
+#dns_servers_SSID="192.168.0.1 192.168.0.2"
+#dns_domain_SSID="some.domain"
+#dns_search_SSID="search.this.domain search.that.domain"
+# Please check the man page for resolv.conf for more information
+# as domain and search (searchdomains) are mutually exclusive and
+# searchdomains takes precedence
+
+# You can also set any of the /etc/conf.d/net variables per MAC address
+# incase you use Access Points with the same SSID but need different
+# networking configs. Below is an example - of course you use the same
+# method with other variables
+#config_001122334455="dhcp"
+#dns_servers_001122334455="192.168.0.1 192.168.0.2"
+
+# Map a MAC address to an SSID
+# This is used when the Access Point is not broadcasting its SSID
+# WARNING: This will override the SSID being broadcast due to some
+# Access Points sending an SSID even when they have been configured
+# not to!
+# Change 001122334455 to the MAC address and SSID to the SSID
+# it should map to
+#mac_essid_001122334455="SSID"
+
+# This lists the preferred SSIDs to connect to in order
+# SSID's can contain any characters here as they must match the broadcast
+# SSID exactly.
+# Surround each SSID with the " character and separate them with a space
+# If the first SSID isn't found then it moves onto the next
+# If this isn't defined then it connects to the first one found
+#preferred_aps="SSID1 SSID2"
+
+# You can also define a preferred_aps list per interface
+#preferred_aps_eth0="SSID3 SSID4"
+
+# You can also say whether we only connect to preferred APs or not
+# Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly"
+# and "forceany"
+# "any" means it will connect to visible APs in the preferred list and then
+# any other available AP
+# "preferredonly" means it will only connect to visible APs in the preferred
+# list
+# "forcepreferred" means it will forcibly connect to APs in order if it does
+# not find them in a scan
+# "forcepreferredonly" means it forcibly connects to the APs in order and
+# does not bother to scan
+# "forceany" does the same as forcepreferred + connects to any other
+# available AP
+# Default is "any"
+#associate_order="any"
+#associate_order_eth0="any"
+
+# You can define blacklisted Access Points in the same way
+#blacklist_aps="SSID1 SSID2"
+#blacklist_aps_eth0="SSID3 SSID4"
+
+# If you have more than one wireless card, you can say if you want
+# to allow each card to associate with the same Access Point or not
+# Values are "yes" and "no"
+# Default is "yes"
+#unique_ap="yes"
+#unique_ap_eth0="yes"
+
+# IMPORTANT: preferred_only, blacklisted_aps and unique_ap only work when
+# essid_eth0 is not set and your card is capable of scanning
+
+# NOTE: preferred_aps list ignores blacklisted_aps - so if you have
+# the same SSID in both, well, you're a bit silly :p
+
+##################################################
+# wpa_supplicant
+# emerge net-wireless/wpa_supplicant
+# Wireless options are held in /etc/wpa_supplicant/wpa_supplicant.conf
+# Consult the wpa_supplicant.conf.example that is installed in
+# /usr/share/doc/wpa_supplicant
+
+# By default we don't wait for wpa_supplicant to associate and authenticate.
+# If you would like to, so can specify how long in seconds
+#associate_timeout_eth0=60
+# A value of 0 means wait forever.
+
+# You can also override any settings found here per SSID - which is very
+# handy if you use different networks a lot. See below for using the SSID
+# in our variables
+#config_SSID="dhcp"
+# See the System module below for setting dns/nis/ntp per SSID
+
+# You can also override any settings found here per MAC address of the AP
+# in case you use Access Points with the same SSID but need different
+# networking configs. Below is an example - of course you use the same
+# method with other variables
+#mac_config_001122334455="dhcp"
+#mac_dns_servers_001122334455="192.168.0.1 192.168.0.2"
+
+# When an interface has been associated with an Access Point, a global
+# variable called SSID is set to the Access Point's SSID for use in the
+# pre/post user functions below (although it's not available in preup as you
+# won't have associated then)
+
+# If you're using anything else to configure wireless on your interface AND
+# you have installed wpa_supplicant, you need to disable wpa_supplicant
+#modules="!iwconfig !wpa_supplicant"
+#or
+#modules="!wireless"
+
+##############################################################################
+# WIRELESS SSID IN VARIABLES
+##############################################################################
+# Remember to change SSID to your SSID.
+# Say that your SSID is My NET - the line
+# #key_SSID="s:passkey"
+# becomes
+# #key_My_NET="s:passkey"
+# Notice that the space has changed to an underscore - do the same with all
+# characters not in a-z A-Z (English alphabet) 0-9. This only applies to
+# variables and not values.
+#
+# Any SSID's in values like essid_eth0="My NET" may need to be escaped
+# This means placing the character \ before the character
+# \" need to be escaped for example
+# So if your SSID is
+# My "\ NET
+# it becomes
+# My \"\\ NET
+# for example
+# #essid_eth0="My\"\\NET"
+#
+# So using the above we can use
+# #dns_domain_My____NET="My\"\\NET"
+# which is an invalid dns domain, but shows the how to use the variable
+# structure
+#########################################################
+
+#-----------------------------------------------------------------------------
+# DHCP
+# DHCP can be provided by dhclient.
+#
+# dhcpcd: emerge net-misc/dhcpcd
+# dhclient: emerge net-misc/dhcp
+
+# Regardless of which DHCP client you prefer, you configure them the
+# same way using one of following depending on which interface modules
+# you're using.
+#config_eth0="dhcp"
+
+# For passing custom options to dhcpcd use something like the following. This
+# example reduces the timeout for retrieving an address from 60 seconds (the
+# default) to 10 seconds.
+#dhcpcd_eth0="-t 10"
+
+# GENERIC DHCP OPTIONS
+# Set generic DHCP options like so
+#dhcp_eth0="release nodns nontp nonis nogateway nosendhost"
+
+# This tells the dhcp client to release its lease when it stops, not to
+# overwrite dns, ntp and nis settings, not to set a default route and not to
+# send the current hostname to the dhcp server and when it starts.
+# You can use any combination of the above options - the default is not to
+# use any of them.
+
+
+#-----------------------------------------------------------------------------
+# System
+# For configuring system specifics such as domain, dns, ntp and nis servers
+# It's rare that you would need todo this, but you can anyway.
+# This is most benefit to wireless users who don't use DHCP so they can change
+# their configs based on SSID.
+
+# If you omit the _eth0 suffix, then it applies to all interfaces unless
+# overridden by the interface suffix.
+#dns_domain_eth0="your.domain"
+#dns_servers_eth0="192.168.0.2 192.168.0.3"
+#dns_search_eth0="this.domain that.domain"
+#dns_options_eth0="timeout:1 rotate"
+#dns_sortlist_eth0="130.155.160.0/255.255.240.0 130.155.0.0"
+# See the man page for resolv.conf for details about the options and sortlist
+# directives
+
+#ntp_servers_eth0="192.168.0.2 192.168.0.3"
+
+#nis_domain_eth0="domain"
+#nis_servers_eth0="192.168.0.2 192.168.0.3"
+
+# NOTE: Setting any of these will stamp on the files in question. So if you
+# don't specify dns_servers but you do specify dns_domain then no nameservers
+# will be listed in /etc/resolv.conf even if there were any there to start
+# with.
+# If this is an issue for you then maybe you should look into a resolv.conf
+# manager like resolvconf-gentoo to manage this file for you. All packages
+# that baselayout supports use resolvconf-gentoo if installed.
+
+#-----------------------------------------------------------------------------
+# Cable in/out detection
+# Sometimes the cable is in, others it's out. Obviously you don't want to
+# restart net.eth0 every time when you plug it in either.
+# BSD has the Device State Change Daemon - or devd for short
+# To enable this, simple add devd to the boot runlevel
+#rc-update add devd boot
+#rc
+
+##############################################################################
+# ADVANCED CONFIGURATION
+#
+# Four functions can be defined which will be called surrounding the
+# start/stop operations. The functions are called with the interface
+# name first so that one function can control multiple adapters. An extra two
+# functions can be defined when an interface fails to start or stop.
+#
+# The return values for the preup and predown functions should be 0
+# (success) to indicate that configuration or deconfiguration of the
+# interface can continue. If preup returns a non-zero value, then
+# interface configuration will be aborted. If predown returns a
+# non-zero value, then the interface will not be allowed to continue
+# deconfiguration.
+#
+# The return values for the postup, postdown, failup and faildown functions are
+# ignored since there's nothing to do if they indicate failure.
+#
+# ${IFACE} is set to the interface being brought up/down
+# ${IFVAR} is ${IFACE} converted to variable name bash allows
+#
+# For historical and compatibility reasons, preup is actually normally called
+# in the following sequence: up ; preup ; up.
+# The first up causes the kernel to initialize the device, so
+# that it is available for use in the preup function. However, for some
+# hardware, e.g. CAN devices, some configuration is needed before trying to up
+# the interface will actually work. For such hardware, the
+# up_before_preup variables will allow skipping the first up call if set
+# to yes.
+#up_before_preup_IFVAR="NO"
+#up_before_preup="NO"
+
+#preup() {
+# # Remember to return 0 on success
+# return 0
+#}
+
+#predown() {
+# # The default in the script is to test for NFS root and disallow
+# # downing interfaces in that case. Note that if you specify a
+# # predown() function you will override that logic. Here it is, in
+# # case you still want it...
+# if is_net_fs /; then
+# eerror "root filesystem is network mounted -- can't stop ${IFACE}"
+# return 1
+# fi
+#
+# # Remember to return 0 on success
+# return 0
+#}
+
+#postup() {
+# # This function could be used, for example, to register with a
+# # dynamic DNS service. Another possibility would be to
+# # send/receive mail once the interface is brought up.
+
+#}
+
+#postdown() {
+# # Return 0 always
+# return 0
+#}
+
+#failup() {
+# # This function is mostly here for completeness... I haven't
+# # thought of anything nifty to do with it yet ;-)
+#}
+
+#faildown() {
+# # This function is mostly here for completeness... I haven't
+# # thought of anything nifty to do with it yet ;-)
+#}
+
+# You should note that we don't stop the network at system shutdown by default.
+# If you really need this, then set keep_network=NO
diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
new file mode 100644
index 0000000..d8fa084
--- /dev/null
+++ b/doc/net.example.Linux.in
@@ -0,0 +1,1247 @@
+##############################################################################
+# QUICK-START
+#
+# The quickest start is if you want to use DHCP.
+# In that case, everything should work out of the box, no configuration
+# necessary, though the startup script will warn you that you haven't
+# specified anything.
+
+# WARNING :- some examples have a mixture of IPv4 (ie 192.168.0.1) and IPv6
+# (ie 4321:0:1:2:3:4:567:89ab) internet addresses. They only work if you have
+# the relevant kernel option enabled. So if you don't have an IPv6 enabled
+# kernel then remove the IPv6 address from your config.
+
+# If you want to use a static address or use DHCP explicitly, jump
+# down to the section labeled INTERFACE HANDLERS.
+#
+# If you want to do anything more fancy, you should take the time to
+# read through the rest of this file.
+
+
+##############################################################################
+# MODULES
+#
+# We now support modular networking scripts which means we can easily
+# add support for new interface types and modules while keeping
+# compatibility with existing ones.
+#
+# Modules load by default if the package they need is installed. If
+# you specify a module here that doesn't have its package installed
+# then you get an error stating which package you need to install.
+# Ideally, you only use the modules setting when you have two or more
+# packages installed that supply the same service.
+#
+# In other words, you probably should DO NOTHING HERE...
+
+# Prefer ifconfig over iproute2
+#modules="!iproute2"
+
+# You can also specify other modules for an interface
+# In this case we prefer udhcpc over dhcpcd
+#modules_eth0="udhcpc"
+
+# You can also specify which modules not to use - for example you may be
+# using a supplicant or linux-wlan-ng to control wireless configuration but
+# you still want to configure network settings per SSID associated with.
+#modules="!iwconfig !wpa_supplicant"
+# IMPORTANT: If you need the above, please disable modules in that order
+
+
+##############################################################################
+# INTERFACE HANDLERS
+#
+# We provide two interface handlers presently: ifconfig and iproute2.
+# You need one of these to do any kind of network configuration.
+# For ifconfig support, emerge sys-apps/net-tools
+# For iproute2 support, emerge sys-apps/iproute2
+
+# If you don't specify an interface then we prefer iproute2 if it's installed
+# To prefer ifconfig over iproute2
+#modules="!iproute2"
+
+# For a static configuration, use something like this
+# (They all do exactly the same thing btw)
+#config_eth0="192.168.0.2/24"
+#config_eth0="192.168.0.2 netmask 255.255.255.0"
+
+# If you need more than one address, you can use something like this
+# NOTE: ifconfig creates an aliased device for each extra IPv4 address
+# (eth0:1, eth0:2, etc)
+# iproute2 does not do this as there is no need to
+# WARNING: You cannot mix multiple addresses on a line with other parameters!
+#config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24"
+# However, that only works with CIDR addresses, so you can't use netmask.
+
+# You can also use IPv6 addresses
+# (you should always specify a prefix length with IPv6 here)
+#config_eth0="192.168.0.2/24 4321:0:1:2:3:4:567:89ab/64 4321:0:1:2:3:4:567:89ac/64"
+
+# If you wish to keep existing addresses + routing and the interface is up,
+# you can specify a noop (no operation). If the interface is down or there
+# are no addresses assigned, then we move onto the next step (default dhcp)
+# This is useful when configuring your interface with a kernel command line
+# or similar
+#config_eth0="noop 192.168.0.2/24"
+
+# If you don't want ANY address (only useful when calling for advanced stuff)
+#config_eth0="null"
+
+# If you need to pass parameters to go with an address, you can do so on the
+# same line as the address. You should split multiple addresses with newlines.
+# WARNING: You cannot mix multiple addresses on a line with other parameters!
+#config_eth0="192.168.0.2/24 scope host"
+#config_eth0="4321:0:1:2:3:4:567:89ab/64 nodad home preferred_lft 0"
+#config_eth0="192.168.0.2/24 scope host
+#4321:0:1:2:3:4:567:89ab/64 nodad home preferred_lft 0"
+
+# Here's how to do routing if you need it
+# We add an IPv4 default route, IPv4 subnet route and an IPv6 unicast route
+#routes_eth0="default via 192.168.0.1
+#10.0.0.0/8 via 192.168.0.1
+#::/0"
+
+# If a specified module fails (like dhcp - see below), you can specify a
+# fallback like so
+#fallback_eth0="192.168.0.2/24"
+#fallback_routes_eth0="default via 192.168.0.1"
+
+# NOTE: fallback entry must match the entry location in config_eth0
+# As such you can only have one fallback route.
+# Also, if you do not set a fallback_routes entry for an interface, the
+# routes entry will be used if that is set.
+
+# Some users may need to alter the MTU - here's how
+#mtu_eth0="1500"
+# Same for TX Queue Length
+#txqueuelen_eth0="1000"
+
+# Each module described below can set a default base metric, lower is
+# preferred over higher. This is so we can prefer a wired route over a
+# wireless route automatically. You can override this by setting
+#metric_eth0="100"
+# or on a global basis
+#metric="100"
+# The only downside of the global setting is that you have to ensure that
+# there are no conflicting routes yourself. For users with large routing
+# tables you may have to set a global metric as the due to a simple read of
+# the routing table taking over a minute at a time.
+
+# Most drivers that report carrier status function correctly, but some do not
+# One of these faulty drivers is for the Intel e1000 network card, but only
+# at boot time. To get around this you may alter the carrier_timeout value for
+# the interface. 0 is disable and any other number of seconds is how
+# long we wait for carrier. The current default is disabled.
+#carrier_timeout_eth0=0
+
+# You may wish to disable the interface being brought down when stopping.
+# This is only of use for WakeOnLan.
+#ifdown_eth0="NO"
+
+##############################################################################
+# OPTIONAL MODULES
+
+#-----------------------------------------------------------------------------
+# WIRELESS (802.11 support)
+# Wireless can be provided by iwconfig or wpa_supplicant
+# wpa_supplicant is preferred, use the modules directive to prefer iwconfig.
+#modules="iwconfig"
+#
+# iwconfig
+# emerge net-wireless/wireless-tools
+###############################################
+# HINTS
+#
+# Most users will just need to set the following options
+# key_SSID1="s:yourkeyhere enc open" # s: means a text key
+# key_SSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key
+# preferred_aps="'SSID 1' 'SSID 2'"
+#
+# Clear? Good. Now configure your wireless network below
+
+###############################################
+# SETTINGS
+# Hard code an SSID to an interface - leave this unset if you wish the driver
+# to scan for available Access Points
+# Set to "any" to connect to any SSID - the driver picks an Access Point
+# This needs to be done when the driver doesn't support scanning
+# This may work for drivers that don't support scanning but you need automatic
+# AP association
+# I would only set this as a last resort really - use the preferred_aps
+# setting at the bottom of this file
+
+# However, using ad-hoc (without scanning for APs) and master mode
+# do require the SSID to be set - do this here
+#essid_eth0="any"
+
+# Set the mode of the interface (managed, ad-hoc, master or auto)
+# The default is auto
+# If it's ad-hoc or master you also may need to specify the channel below
+#mode_eth0="auto"
+
+# If managed mode fails, drop to ad-hoc mode with the below SSID?
+#adhoc_essid_eth0="WLAN"
+
+# Some drivers/hardware don't scan all that well. We have no control over this
+# but we can say how many scans we want to do to try and get a better sweep of
+# the area. The default is 1.
+#scans_eth0="1"
+
+#Channel can be set (1-14), but defaults to 3 if not set.
+#
+# The below is taken verbatim from the BSD wavelan documentation found at
+# http://www.netbsd.org/Documentation/network/wavelan.html
+# There are 14 channels possible; We are told that channels 1-11 are legal for
+# North America, channels 1-13 for most of Europe, channels 10-13 for France,
+# and only channel 14 for Japan. If in doubt, please refer to the documentation
+# that came with your card or access point. Make sure that the channel you
+# select is the same channel your access point (or the other card in an ad-hoc
+# network) is on. The default for cards sold in North America and most of Europe
+# is 3; the default for cards sold in France is 11, and the default for cards
+# sold in Japan is 14.
+#channel_eth0="3"
+
+# Setup any other config commands. This is basically the iwconfig argument
+# without the iwconfig $iface.
+#iwconfig_eth0=""
+
+# Set private driver ioctls. This is basically the iwpriv argument without
+# the iwpriv $iface. If you use the rt2500 driver (not the rt2x00 one) then
+# you can set WPA here, below is an example.
+#iwpriv_eth0=""
+#iwpriv_SSID="set AuthMode=WPAPSK
+#set EncrypType=TKIP
+#set WPAPSK=yourpasskey"
+#NOTE: Even though you can use WPA like so, you may have to set a WEP key
+#if your driver claims the AP is encrypted. The WEP key itself will not be
+#used though.
+
+# Seconds to wait before scanning
+# Some drivers need to wait until they have finished "loading"
+# before they can scan - otherwise they error and claim that they cannot scan
+# or resource is unavailable. The default is to wait zero seconds
+#sleep_scan_eth0="1"
+
+# Seconds to wait until associated. The default is to wait 10 seconds.
+# 0 means wait indefinitely. WARNING: this can cause an infinite delay when
+# booting.
+#associate_timeout_eth0="5"
+
+# By default a successful association in Managed mode sets the MAC
+# address of the AP connected to. However, some drivers (namely
+# the ipw2100) don't set an invalid MAC address when association
+# fails - so we need to check on link quality which some drivers
+# don't report properly either.
+# So if you have connection problems try flipping this setting
+# Valid options are MAC, quality and all - defaults to MAC
+#associate_test_eth0="MAC"
+
+# Some driver/card combinations need to scan in Ad-Hoc mode
+# After scanning, the mode is reset to the one defined above
+#scan_mode_eth0="Ad-Hoc"
+
+# Below you can define private ioctls to run before and after scanning
+# Format is the same as the iwpriv_eth0 above
+# This is needed for the HostAP drivers
+#iwpriv_scan_pre_eth0="'host_roaming 2'"
+#iwpriv_scan_post_eth0="'host_roaming 0'"
+
+# Define a WEP key per SSID or MAC address (of the AP, not your card)
+# The encryption type (open or restricted) must match the
+# encryption type on the Access Point
+# You can't use "any" for an SSID here
+#key_SSID="1234-1234-1234-1234-1234-1234-56"
+# or you can use strings. Passphrase IS NOT supported
+# To use a string, prefix it with s:
+# Note - this example also sets the encryption method to open
+# which is regarded as more secure than restricted
+#key_SSID="s:foobar enc open"
+#key_SSID="s:foobar enc restricted"
+
+# If you have whitespace in your key, here's how to set it and use other
+# commands like using open encryption.
+#key_SSID="s:'foo bar' enc open"
+
+# WEP key for the AP with MAC address 001122334455
+#mac_key_001122334455="s:foobar"
+
+# Here are some more examples of keys as some users find others work
+# and some don't where they should all do the same thing
+#key_SSID="open s:foobar"
+#key_SSID="open 1234-5678-9012"
+#key_SSID="s:foobar enc open"
+#key_SSID="1234-5678-9012 enc open"
+
+# You may want to set multiple keys - here's an example
+# It sets 4 keys on the card and instructs to use key 2 by default
+#key_SSID="[1] s:passkey1 key [2] s:passkey2 key [3] s:passkey3 key [4] s:passkey4 key [2]"
+
+# You can also override the interface settings found in /etc/conf.d/net
+# per SSID - which is very handy if you use different networks a lot
+#config_SSID="dhcp"
+#dhcpcd_SSID="-t 5"
+#routes_SSID=
+#fallback_SSID=
+
+# Setting name/domain server causes /etc/resolv.conf to be overwritten
+# Note that if DHCP is used, and you want this to take precedence then
+# please put -R in your dhcpcd options
+#dns_servers_SSID="192.168.0.1 192.168.0.2"
+#dns_domain_SSID="some.domain"
+#dns_search_SSID="search.this.domain search.that.domain"
+# Please check the man page for resolv.conf for more information
+# as domain and search (searchdomains) are mutually exclusive and
+# searchdomains takes precedence
+
+# You can also set any of the /etc/conf.d/net variables per MAC address
+# incase you use Access Points with the same SSID but need different
+# networking configs. Below is an example - of course you use the same
+# method with other variables
+#config_001122334455="dhcp"
+#dhcpcd_001122334455="-t 10"
+#dns_servers_001122334455="192.168.0.1 192.168.0.2"
+
+# Map a MAC address to an SSID
+# This is used when the Access Point is not broadcasting its SSID
+# WARNING: This will override the SSID being broadcast due to some
+# Access Points sending an SSID even when they have been configured
+# not to!
+# Change 001122334455 to the MAC address and SSID to the SSID
+# it should map to
+#mac_essid_001122334455="SSID"
+
+# This lists the preferred SSIDs to connect to in order
+# SSID's can contain any characters here as they must match the broadcast
+# SSID exactly.
+# Surround each SSID with the " character and separate them with a space
+# If the first SSID isn't found then it moves onto the next
+# If this isn't defined then it connects to the first one found
+#preferred_aps="SSID1 SSID2"
+
+# You can also define a preferred_aps list per interface
+#preferred_aps_eth0="SSID3 SSID4"
+
+# You can also say whether we only connect to preferred APs or not
+# Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" and "forceany"
+# "any" means it will connect to visible APs in the preferred list and then any
+# other available AP
+# "preferredonly" means it will only connect to visible APs in the preferred list
+# "forcepreferred" means it will forcibly connect to APs in order if it does not find
+# them in a scan
+# "forcepreferredonly" means it forcibly connects to the APs in order and does not bother
+# to scan
+# "forceany" does the same as forcepreferred + connects to any other available AP
+# Default is "any"
+#associate_order="any"
+#associate_order_eth0="any"
+
+# You can define blacklisted Access Points in the same way
+#blacklist_aps="SSID1 SSID2"
+#blacklist_aps_eth0="SSID3 SSID4"
+
+# If you have more than one wireless card, you can say if you want
+# to allow each card to associate with the same Access Point or not
+# Values are "yes" and "no"
+# Default is "yes"
+#unique_ap="yes"
+#unique_ap_eth0="yes"
+
+# IMPORTANT: preferred_only, blacklisted_aps and unique_ap only work when
+# essid_eth0 is not set and your card is capable of scanning
+
+# NOTE: preferred_aps list ignores blacklisted_aps - so if you have
+# the same SSID in both, well, you're a bit silly :p
+
+
+############################################################
+# wpa_supplicant
+# emerge net-wireless/wpa_supplicant
+# Wireless options are held in /etc/wpa_supplicant/wpa_supplicant.conf
+# Consult the wpa_supplicant.conf.example that is installed in
+# /usr/share/doc/wpa_supplicant
+# To configure wpa_supplicant
+#wpa_supplicant_ath0="-Dmadwifi" # For Atheros based cards
+# Consult wpa_supplicant for more drivers - the default is -Dwext which should
+# work for most cards.
+
+# By default we don't wait for wpa_supplicant to associate and authenticate.
+# If you need to change this behaviour then you don't know how our scripts work
+# and setting this value could cause strange things to happen.
+# If you would like it to wait, you can specify how long in seconds.
+#associate_timeout_eth0=60
+# A value of 0 means wait forever.
+
+# You can also override any settings found here per SSID - which is very
+# handy if you use different networks a lot. See below for using the SSID
+# in our variables
+#config_SSID="dhcp"
+# See the System module below for setting dns/nis/ntp per SSID
+
+# You can also override any settings found here per MAC address of the AP
+# in case you use Access Points with the same SSID but need different
+# networking configs. Below is an example - of course you use the same
+# method with other variables
+#mac_config_001122334455="dhcp"
+#mac_dns_servers_001122334455="192.168.0.1 192.168.0.2"
+
+# When an interface has been associated with an Access Point, a global
+# variable called SSID is set to the Access Point's SSID for use in the
+# pre/post user functions below (although it's not available in preup as you
+# won't have associated then)
+
+# If you're using anything else to configure wireless on your interface AND
+# you have installed wpa_supplicant, you need to disable wpa_supplicant
+#modules="!iwconfig !wpa_supplicant"
+#or
+#modules="!wireless"
+
+##############################################################################
+# WIRELESS SSID IN VARIABLES
+##############################################################################
+# Remember to change SSID to your SSID.
+# Say that your SSID is My NET - the line
+# #key_SSID="s:passkey"
+# becomes
+# #key_My_NET="s:passkey"
+# Notice that the space has changed to an underscore - do the same with all
+# characters not in a-z A-Z (English alphabet) 0-9. This only applies to
+# variables and not values.
+#
+# Any SSID's in values like essid_eth0="My NET" may need to be escaped
+# This means placing the character \ before the character
+# \" need to be escaped for example
+# So if your SSID is
+# My "\ NET
+# it becomes
+# My \"\\ NET
+# for example
+# #essid_eth0="My\"\\NET"
+#
+# So using the above we can use
+# #dns_domain_My____NET="My\"\\NET"
+# which is an invalid dns domain, but shows the how to use the variable
+# structure
+#########################################################
+
+
+#-----------------------------------------------------------------------------
+# DHCP
+# DHCP can be provided by dhclient, dhcpcd, pump or udhcpc.
+#
+# dhclient: emerge net-misc/dhcp
+# dhcpcd: emerge net-misc/dhcpcd
+# pump: emerge net-misc/pump
+# udhcpc: emerge sys-apps/busybox
+
+# If you have more than one DHCP client installed, you need to specify which
+# one to use - otherwise we default to dhcpcd if available.
+#modules="dhclient" # to select dhclient over dhcpcd
+#
+# Notes:
+# - All clients send the current hostname to the DHCP server by default
+# - dhcpcd does not daemonize when the lease time is infinite
+# - udhcp-0.9.3-r3 and earlier do not support getting NTP servers
+# - pump does not support getting NIS servers
+# - DHCP tends to erase any existing device information - so add
+# static addresses after dhcp if you need them
+# - dhclient and udhcpc can set other resolv.conf options such as "option"
+# and "sortlist"- see the System module for more details
+
+# Regardless of which DHCP client you prefer, you configure them the
+# same way using one of following depending on which interface modules
+# you're using.
+#config_eth0="dhcp"
+
+# For passing custom options to dhcpcd use something like the following. This
+# example reduces the timeout for retrieving an address from 60 seconds (the
+# default) to 10 seconds.
+#dhcpcd_eth0="-t 10"
+
+# dhclient, udhcpc and pump don't have many runtime options
+# You can pass options to them in a similar manner to dhcpcd though
+#dhclient_eth0="..."
+#udhcpc_eth0="..."
+#pump_eth0="..."
+
+# GENERIC DHCP OPTIONS
+# Set generic DHCP options like so
+#dhcp_eth0="release nodns nontp nonis nogateway nosendhost"
+
+# This tells the dhcp client to release its lease when it stops, not to
+# overwrite dns, ntp and nis settings, not to set a default route and not to
+# send the current hostname to the dhcp server and when it starts.
+# You can use any combination of the above options - the default is not to
+# use any of them.
+
+#-----------------------------------------------------------------------------
+# For APIPA support, emerge net-misc/iputils or net-analyzer/arping
+
+# APIPA is a module that tries to find a free address in the range
+# 169.254.0.0-169.254.255.255 by arping a random address in that range on the
+# interface. If no reply is found then we assign that address to the interface
+
+# This is only useful for LANs where there is no DHCP server and you don't
+# connect directly to the internet.
+#config_eth0="dhcp"
+#fallback_eth0="apipa"
+
+#-----------------------------------------------------------------------------
+# ARPING Gateway configuration
+# and
+# Automatic Private IP Addressing (APIPA)
+# For arpingnet / apipa support, emerge net-misc/iputils or net-analyzer/arping
+#
+# This is a module that tries to find a gateway IP. If it exists then we use
+# that gateways configuration for our own. For the configuration variables
+# simply ensure that each octet is zero padded and the dots are removed.
+# Below is an example.
+#
+#gateways_eth0="192.168.0.1 10.0.0.1"
+#config_192168000001="192.168.0.2/24"
+#routes_192168000001="default via 192.168.0.1"
+#dns_servers_192168000001="192.168.0.1"
+#config_010000000001="10.0.0.254/8"
+#routes_010000000001="default via 10.0.0.1"
+#dns_servers_010000000001="10.0.0.1"
+
+# We can also specify a specific MAC address for each gateway if different
+# networks have the same gateway.
+#gateways_eth0="192.168.0.1,00:11:22:AA:BB:CC 10.0.0.1,33:44:55:DD:EE:FF"
+#config_192168000001_001122AABBCC="192.168.0.2/24"
+#routes_192168000001_001122AABBCC="default via 192.168.0.1"
+#dns_servers_192168000001_001122AABBCC="192.168.0.1"
+#config_010000000001_334455DDEEFF="10.0.0.254/8"
+#routes_010000000001_334455DDEEFF="default via 10.0.0.1"
+#dns_servers_010000000001_334455DDEEFF="10.0.0.1"
+
+# If you need to spoof the source address, you can add that as third parameter
+# like so
+#gateways_eth0="192.168.0.1,00:11:22:AA:BB:CC,192.168.0.50"
+#or
+#gateways_eth0="192.168.0.1,,192.168.0.50"
+# This requires arping to be installed though
+
+# If we don't find any gateways (or there are none configured) then we try and
+# use APIPA to find a free address in the range 169.254.0.0-169.254.255.255
+# by arping a random address in that range on the interface. If no reply is
+# found then we assign that address to the interface.
+
+# This is only useful for LANs where there is no DHCP server.
+#config_eth0="arping"
+
+# or if no DHCP server can be found
+#config_eth0="dhcp"
+#fallback_eth0="arping"
+
+# NOTE: We default to sleeping for 1 second the first time we attempt an
+# arping to give the interface time to settle on the LAN. This appears to
+# be a good default for most instances, but if not you can alter it here.
+#arping_sleep=5
+#arping_sleep_lan=7
+
+# NOTE: We default to waiting 3 seconds to get an arping response. You can
+# change the default wait like so.
+#arping_wait=3
+#arping_wait_lan=2
+
+#-----------------------------------------------------------------------------
+# VLAN (802.1q support)
+# For VLAN support, emerge sys-apps/iproute2
+# The old vconfig based VLAN support is no longer available.
+
+# Specify the VLAN numbers for the interface like so
+# Please ensure your VLAN IDs are NOT zero-padded
+#vlans_eth0="1 2"
+
+# You may not want to assign an IP the the physical interface, but we still
+# need it up.
+#config_eth0="null"
+
+# You can also configure the VLAN - see for ip man page for more details
+# To change the vlan interface name. If not set, the standard "iface.vlanid"
+# will be used. This is the replacement for the old 'vconfig set_name_type'
+# functionality. If you previously relied on the DEV_PLUS_VID or
+# DEV_PLUS_VID_NO_PAD options to have different VLANs with same ID value, on
+# different interfaces, please note that you need to use both the interface and
+# vlan number in the numbering. This applies for all of the options: name,
+# txqueuelen, mac, broadcast, mtu, ingress, egress, flags
+#vlan1_name="vlan1"
+#eth0_vlan2_name="eth0.2"
+#eth1_vlan2_name="eth1.2"
+
+# The following shows the old set_name_type setting and what new option to set:
+# Using eth9 & VLAN VID 26 as an example.
+# VLAN_PLUS_VID vlan26_name="vlan0026"
+# VLAN_PLUS_VID_NO_PAD vlan26_name="vlan26"
+# DEV_PLUS_VID eth9_vlan26_name="eth9.0026"
+# DEV_PLUS_VID_NO_PAD eth9_vlan26_name="eth9.26"
+
+# Set the vlan flags
+#vlan1_flags="reorder_hdr off gvrp on loose_binding on"
+#eth0_vlan1_flags="reorder_hdr off gvrp on loose_binding on"
+
+# Configure in/egress maps
+#vlan1_ingress="2:6 3:5"
+#eth0_vlan1_egress="1:2"
+
+#config_vlan1="172.16.2.1/24"
+#config_vlan2="172.16.3.1/24"
+#config_eth0_1="172.16.4.1/24"
+#config_eth1_1="172.16.5.1/24"
+
+# NOTE: Vlans can be configured with a . in their interface names
+# When configuring vlans with this name type, you need to replace . with a _
+#config_eth0.1="dhcp" - does not work
+#config_eth0_1="dhcp" - does work
+
+# 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 separate
+# script 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
+# rc_net_vlan1_need="net.eth0"
+# NOTE: depend functions only work in /etc/conf.d/net
+# and not in profile configs such as /etc/conf.d/net.foo
+
+# Also, you might want to make eth0 not provide net in this case so that
+# dependent services will start when the vlan is active instead of the
+# physical interface.
+# rc_net_eth0_provide="!net"
+
+# MAC-VLAN support
+# The following configuration can be used to create a new interface 'macvlan0'
+# linked to 'eth0'
+#macvlan_macvlan0="eth0"
+
+# MAC-VLAN mode (private, vepa, bridge, passtru)
+#mode_macvlan0="private"
+
+# IP address, MAC address, ... are configured as a normal interface
+#config_macvlan0="192.168.20.20/24"
+#mac_macvlan0="00:50:06:20:20:20"
+
+#-----------------------------------------------------------------------------
+# Bonding
+# For link bonding/trunking on 2.4 kernels, or kernels without sysfs
+# emerge net-misc/ifenslave
+
+# To bond interfaces together
+#slaves_bond0="eth0 eth1 eth2"
+#config_bond0="null" # You may not want to assign an IP the the bond
+
+# Please note, that you should generally NOT try to change the MAC addresses of
+# a bond interface yourself. If you do so, the kernel and your network switches
+# may not work quite right. It is permissible to set the MAC addresses of bond
+# slaves BEFORE the bond comes up, but not after the bond is up (it will change
+# MAC addresses of the slaves on it's own).
+
+# You can also configure the parameters of the bond here, which must be done
+# via sysfs on 2.6 kernels or newer. The description of all the options can be
+# found in the kernel: /usr/src/linux-*/Documentation/networking/bonding.txt
+# You will probably want the 'mode' option at the least.
+# Some possible parameters: mode fail_over_mac arp_validate arp_interval
+# arp_ip_target downdelay updelay lacp_rate ad_select xmit_hash_policy
+# num_grat_arp num_unsol_na miimon primary primary_reselect use_carrier
+# active_slave queue_id all_slaves_active resend_igmp min_links
+#mode_bond0="round-robin"
+#miimon_bond0="100"
+#arp_ip_target_bond0="+26.0.0.0"
+
+# If any of the slaves require extra configuration - for example wireless or
+# ppp devices - we need to depend function on the bonded interfaces
+#rc_net_bond0_need="net.eth0 net.eth1"
+
+# Bonding subsume support (prevents crashes for root-on-NFS)
+# - Only tested in the default bonding mode ('active-backup') with
+# IPv4
+# - Only subsumes basic interface characteristics (IP, netmask) and
+# excludes additional routes, interface properties such as MTU,
+# interface-associated netfilter rules, etc.
+# In the example below, the (usually kernel-autoconfigured)
+# 'eth0' interface is a member of bond0, which subsumes the
+# existing interface configuration without upsetting NFS.
+#slaves_bond0="eth0 eth1"
+#subsume_bond0="eth0"
+
+#-----------------------------------------------------------------------------
+# Classical IP over ATM
+# For CLIP support emerge net-dialup/linux-atm
+
+# Ensure that you have /etc/atmsigd.conf setup correctly
+# Now setup each clip interface like so
+#clip_atm0="peer_ip [if.]vpi.vci [opts],"
+# where "peer_ip" is the IP address of a PVC peer (in case of an ATM connection
+# with your ISP, your only peer is usually the ISP gateway closest to you),
+# "if" is the number of the ATM interface which will carry the PVC, "vpi.vci"
+# is the ATM VC address, and "opts" may optionally specify VC parameters like
+# qos, pcr, and the like (see "atmarp -s" for further reference). Please also
+# note quoting: it is meant to distinguish the VCs you want to create. You may,
+# in example, create an atm0 interface to more peers, like this:
+#clip_atm0="1.1.1.254,0.8.35 1.1.1.253,1.8.35"
+
+# By default, the PVC will use the LLC/SNAP encapsulation. If you rather need a
+# null encapsulation (aka "VC mode"), please add the keyword "null" to opts.
+
+
+#-----------------------------------------------------------------------------
+# PPP
+# For PPP support, emerge net-dialup/ppp
+# PPP is used for most dialup connections, including ADSL.
+# The older ADSL module is documented below, but you are encouraged to try
+# this module first.
+#
+# You need to create the PPP net script yourself. Make it like so
+#ln -s net.lo /etc/init.d/net.ppp0
+#
+# Each PPP interface requires an interface to use as a "Link"
+#link_ppp0="/dev/ttyS0" # Most PPP links will use a serial port
+#link_ppp0="eth0" # PPPoE requires an ethernet interface
+#link_ppp0="[itf.]vpi.vci" # PPPoA requires the ATM VC's address
+#link_ppp0="/dev/null" # ISDN links should have this
+#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,
+# radattr, radrealms and winbind
+#plugins_ppp0="pppoe" # Required plugin for PPPoE
+#plugins_ppp0="pppoa vc-encaps" # Required plugin for PPPoA with an option
+#plugins_ppp0="capi" # Required plugin for ISDN
+#
+# PPP requires at least a username. You can optionally set a password here too
+# If you don't, then it will use the password specified in /etc/ppp/*-secrets
+# against the specified username
+#username_ppp0='user'
+#password_ppp0='password'
+# NOTE: You can set a blank password like so
+#password_ppp0=
+#
+# The PPP daemon has many options you can specify - although there are many
+# and may seem daunting, it is recommended that you read the pppd man page
+# before enabling any of them
+#pppd_ppp0="
+# maxfail 0 # WARNING: It's not recommended you use this
+# # if you don't specify maxfail then we assume 0
+# updetach # If not set, "/etc/init.d/net.ppp0 start" will return
+# # immediately, without waiting the link to come up
+# # for the first time.
+# # Do not use it for dial-on-demand links!
+# debug # Enables syslog debugging
+# noauth # Do not require the peer to authenticate itself
+# defaultroute # Make this PPP interface the default route
+# usepeerdns # Use the DNS settings provided by PPP
+#
+# On demand options
+# demand # Enable dial on demand
+# idle 30 # Link goes down after 30 seconds of inactivity
+# 10.112.112.112:10.112.112.113 # Phony IP addresses
+# ipcp-accept-remote # Accept the peers idea of remote address
+# ipcp-accept-local # Accept the peers idea of local address
+# holdoff 3 # Wait 3 seconds after link dies before re-starting
+#
+# Dead peer detection
+# lcp-echo-interval 15 # Send a LCP echo every 15 seconds
+# lcp-echo-failure 3 # Make peer dead after 3 consecutive
+# # echo-requests
+#
+# Compression options - use these to completely disable compression
+# noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp
+#
+# Dial-up settings
+# lock # Lock serial port
+# 115200 # Set the serial port baud rate
+# modem crtscts # Enable hardware flow control
+# 192.168.0.1:192.168.0.2 # Local and remote IP addresses
+#"
+#
+# Dial-up PPP users need to specify at least one telephone number
+#phone_number_ppp0="12345689" # Maximum 2 phone numbers are supported
+# They will also need a chat script - here's a good one
+#chat_ppp0="
+#ABORT BUSY
+#ABORT ERROR
+#ABORT 'NO ANSWER'
+#ABORT 'NO CARRIER'
+#ABORT 'NO DIALTONE'
+#ABORT 'Invalid Login'
+#ABORT 'Login incorrect'
+#TIMEOUT 5
+#'' ATZ
+#OK AT # Put your modem initialization string here
+#OK 'ATDT\T'
+#TIMEOUT 60
+#CONNECT ''
+#TIMEOUT 5
+#~-- ''
+#"
+
+# If the link require extra configuration - for example wireless or
+# RFC 268 bridge - we need to depend on the bridge so they get
+# configured correctly.
+#rc_net_ppp0_need="net.nas0"
+
+#WARNING: if MTU of the PPP interface is less than 1500 and you use this
+#machine as a router, you should add the following rule to your firewall
+#
+#iptables -I FORWARD 1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
+
+#-----------------------------------------------------------------------------
+# ADSL
+# For ADSL support, emerge net-dialup/rp-pppoe
+# WARNING: This ADSL module is being deprecated in favour of the PPP module
+# above.
+# You should make the following settings and also put your
+# username/password information in /etc/ppp/pap-secrets
+
+# Configure the interface to use ADSL
+#config_eth0="adsl"
+
+# You probably won't need to edit /etc/ppp/pppoe.conf if you set this
+#adsl_user_eth0="my-adsl-username"
+
+#-----------------------------------------------------------------------------
+# ISDN
+# For ISDN support, emerge net-dialup/isdn4k-utils
+# You should make the following settings and also put your
+# username/password information in /etc/ppp/pap-secrets
+
+# Configure the interface to use ISDN
+#config_ippp0="dhcp"
+# It's important to specify dhcp if you need it!
+#config_ippp0="192.168.0.1/24"
+# Otherwise, you can use a static IP
+
+# NOTE: The interface name must be either ippp or isdn followed by a number
+
+# You may need this option to set the default route
+#ipppd_eth0="defaultroute"
+
+#-----------------------------------------------------------------------------
+# MAC changer
+# Warning: Do NOT use this on bonding interfaces! Bonding changes MACs itself.
+#
+# To set a specific MAC address
+#mac_eth0="00:11:22:33:44:55"
+
+# For changing MAC addresses using the below, emerge net-analyzer/macchanger
+# - to randomize the last 3 bytes only
+#mac_eth0="random-ending"
+# - to randomize between the same physical type of connection (e.g. fibre,
+# copper, wireless) , all vendors
+#mac_eth0="random-samekind"
+# - to randomize between any physical type of connection (e.g. fibre, copper,
+# wireless) , all vendors
+#mac_eth0="random-anykind"
+# - full randomization - WARNING: some MAC addresses generated by this may NOT
+# act as expected
+#mac_eth0="random-full"
+# custom - passes all parameters directly to net-analyzer/macchanger
+#mac_eth0="some custom set of parameters"
+
+# You can also set other options based on the MAC address of your network card
+# Handy if you use different docking stations with laptops
+#config_001122334455="dhcp"
+
+#-----------------------------------------------------------------------------
+# TUN/TAP
+# For TUN/TAP support install iproute2, openvpn or usermode-utilities
+#
+# You must specify if we're a tun or tap device. Then you can give it any
+# name you like - such as vpn
+#tuntap_vpn="tun"
+#config_vpn="192.168.0.1/24"
+
+# Or stick wit the generic names - like tap0
+#tuntap_tap0="tap"
+#config_tap0="192.168.0.1/24"
+
+# Use something like this to pass custom options to iproute2 during
+# tunnel creation. This sets the user and group ownership of the node.
+#iproute2_tun1="user foo group bar"
+# For passing custom options to tunctl use something like the following. This
+# example sets the owner to adm
+#tunctl_tun1="-u adm"
+# OpenVPN-2.1_rc6 and newer allow --user and --group to set owner and group
+# of the node as well
+#openvpn_tun1="--user foo --group bar"
+
+#-----------------------------------------------------------------------------
+# Bridging (802.1d)
+# For bridging support emerge net-misc/bridge-utils
+
+# To add ports to bridge br0
+#bridge_br0="eth0 eth1"
+# or dynamically add them when the interface comes up
+#bridge_add_eth0="br0"
+#bridge_add_eth1="br0"
+
+# NOTE: If you want to manually start an empty bridge, and then dynamically add
+# ports to it you must set at least one of the following variables based on the
+# interface name, so that we can pick it up from your configuration. Even an
+# empty value variable is fine, but at least one of them must be set:
+# brctl_IFVAR
+
+# You need to configure the ports to null values so dhcp does not get started
+#config_eth0="null"
+#config_eth1="null"
+
+# Finally give the bridge an address - dhcp or a static IP, this is assigned to
+# the bridge when the bridge is explicitly started.
+#config_br0="dhcp" # may not work when adding ports dynamically
+#config_br0="192.168.0.1/24"
+
+# If any of the ports require extra configuration - for example wireless or
+# ppp devices - we need to depend on them like so.
+#rc_net_br0_need="net.eth0 net.eth1"
+
+# Below is an example of configuring the bridge
+# Consult "man brctl" for more details
+#brctl_br0="setfd 15
+#sethello 2
+#stp on"
+
+# You can also configure the bridge or bridge members via sysfs on 2.6 kernels
+# or newer. See the kernel bridge documentation for a description of these
+# options.
+#stp_state_br0="0"
+#forward_delay_br0="10"
+#hairpin_mode_eth0="1"
+
+#-----------------------------------------------------------------------------
+# 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
+
+# You may want to configure the encapsulation method as well by adding the -e
+# option to the command above (may need to be before the -a command)
+# -e 0 # LLC (default)
+# -e 1 # VC mux
+
+# Then you can configure the interface as normal
+#config_nas0="'192.168.0.1/24'"
+
+#-----------------------------------------------------------------------------
+# Tunneling
+# WARNING: For tunneling it is highly recommended that you
+# emerge sys-apps/iproute2
+#
+# For GRE tunnels
+#iptunnel_vpn0="mode gre remote 207.170.82.1 key 0xffffffff ttl 255"
+
+# For IPIP tunnels
+#iptunnel_vpn0="mode ipip remote 207.170.82.2 ttl 255"
+
+# To configure the interface
+#config_vpn0="192.168.0.2 pointopoint 192.168.1.2" # ifconfig style
+#config_vpn0="192.168.0.2 peer 192.168.1.1" # iproute2 style
+
+# 6to4 Tunnels allow IPv6 to work over IPv4 addresses, provided you
+# have a non-private address configured on an interface.
+# link_6to4="eth0" # Interface to base its addresses on
+# config_6to4="ip6to4"
+# You may want to depend on eth0 like so
+#rc_net_6to4_need="net.eth0"
+# To ensure that eth0 is configured before 6to4. Of course, the tunnel could be
+# any name and this also works for any configured interface.
+# NOTE: If you're not using iproute2 then your 6to4 tunnel has to be called
+# sit0 - otherwise use a different name like 6to4 in the example above.
+
+# You can also specify a relay and suffix if you like.
+# The default relay is 192.88.99.1 and the default suffix is :1
+#relay_6to4="192.168.3.2"
+#suffix_6to4=":ff"
+
+#-----------------------------------------------------------------------------
+# Advanced Routing
+# WARNING: For advanced routing you MUST be using sys-apps/iproute2
+#
+# This provides a means to do multi-homing and more using the Routing Policy
+# Database (RPDB).
+#
+# See the following links for background and more information.
+# http://linux-ip.net/html/ch-routing.html
+# http://linux-ip.net/html/ch-advanced-routing.html
+
+# The rules listed will be added with 'ip rule add LINE' when the interface is
+# being brought up. They will also be removed with 'ip rule delete LINE'.
+# The rules added are also stored for later removal, so if you alter your rules
+# directly before stopping, you should review your rules again after stopping.
+
+# Note in earlier versions of openrc, this was provided as an example in
+# postup/postdown, however that implementation suffered some bugs in corner
+# cases, which are now fixed with this merger. If you used the previous
+# example, you should only need to drop the relevent portions of your
+# postup/postdown functions, and review the quoting in your rules_IFACE
+# variables.
+
+# Below is a trivial example for a dual-homed connection where there is an OOB
+# management network. Only packets explicitly with an address from or to the
+# OOB are sent via eth0. All others go via eth1 as the eth1 rules have a lower
+# priority.
+
+# If you want to use names for your tables, you should put lines into
+# /etc/iproute2/rt_tables, an example follows:
+# 2 oob
+# 3 external
+#
+# IPv6 RPDB entries are to be found in the rules6_IFVAR variables:
+
+#rules_eth0="
+#from ZZZ.ZZZ.200.128/27 table oob priority 500
+#to ZZZ.ZZZ.200.128/27 table oob priority 550"
+#rules_eth1="
+#from XXX.XXX.112.0/24 table external priority 400
+#to XXX.XXX.112.0/24 table external priority 450"
+#routes_eth0="
+#ZZZ.ZZZ.200.128/27 dev eth0 table oob scope link
+#default via ZZZ.ZZZ.200.129 table oob"
+#routes_eth1="
+#XXX.XXX.112.0/24 dev eth1 table external scope link
+#default via XXX.XXX.112.1 dev eth1"
+
+# IPv6 example:
+#rules6_eth0="
+#from 2001:0DB8:AAAA:BBBB::/64 table vpn priority 100
+#to 2001:0DB8:AAAA:BBBB::/64 table vpn priority 150"
+
+
+#-----------------------------------------------------------------------------
+# System
+# For configuring system specifics such as domain, dns, ntp and nis servers
+# It's rare that you would need todo this, but you can anyway.
+# This is most benefit to wireless users who don't use DHCP so they can change
+# their configs based on SSID.
+
+# If you omit the _eth0 suffix, then it applies to all interfaces unless
+# overridden by the interface suffix.
+#dns_domain_eth0="your.domain"
+#dns_servers_eth0="192.168.0.2 192.168.0.3"
+#dns_search_eth0="this.domain that.domain"
+#dns_options_eth0="timeout:1 rotate"
+#dns_sortlist_eth0="130.155.160.0/255.255.240.0 130.155.0.0"
+# See the man page for resolv.conf for details about the options and sortlist
+# directives
+
+#ntp_servers_eth0="192.168.0.2 192.168.0.3"
+
+#nis_domain_eth0="domain"
+#nis_servers_eth0="192.168.0.2 192.168.0.3"
+
+# NOTE: Setting any of these will stamp on the files in question. So if you
+# don't specify dns_servers but you do specify dns_domain then no nameservers
+# will be listed in /etc/resolv.conf even if there were any there to start
+# with.
+# If this is an issue for you then maybe you should look into a resolv.conf
+# manager like resolvconf-gentoo to manage this file for you. All packages
+# that baselayout supports use resolvconf-gentoo if installed.
+
+#-----------------------------------------------------------------------------
+# Cable in/out detection
+# Sometimes the cable is in, others it's out. Obviously you don't want to
+# restart net.eth0 every time when you plug it in either.
+#
+# netplug is a package that detects this and requires no extra configuration
+# on your part.
+# emerge sys-apps/netplug
+# or
+# emerge sys-apps/ifplugd
+# and you're done :)
+
+# By default we don't wait for netplug/ifplugd to configure the interface.
+# If you would like it to wait so that other services know that network is
+# up then you can specify a timeout here. A value of 0 means wait forever,
+# and a negative value means never wait.
+#plug_timeout_eth0="10"
+# If you want to set it for all interfaces:
+#plug_timeout="10"
+
+# If you don't want to use netplug on a specific interface but you have it
+# installed, you can disable it for that interface via the modules statement
+#modules_eth0="!netplugd"
+# You can do the same for ifplugd
+#
+# You can disable them both with the generic plug
+#modules_eth0="!plug"
+
+# To use specific ifplugd options, fex specifying wireless mode
+#ifplugd_eth0="--api-mode=wlan"
+# man ifplugd for more options
+
+#-----------------------------------------------------------------------------
+# Interface hardware tuning & configuration via ethtool
+# If you need to change explicit hardware settings on your network card prior
+# to bringing the interface up, the following is available.
+#
+# For a full listing of settings, please consulting ethtool(8) and the output
+# of "ethtool --help".
+#
+# Multiple entries (seperated by newlines) are supported in all of the
+# variables as some settings cannot be changed at the same time.
+#
+# Valid variable name fragments: change pause coalesce ring offload
+# change_eeprom identify nfc flash rxfh_indir ntuple
+
+# Set Wake-On-Lan to listen for SecureOn MagicPacket(tm), the message level to
+# notify us of WOL changes, and the SecureOn password to 'DE:AD:BE:EF:CA:FE'.
+#ethtool_change_eth0="wol gs
+#msglvl wol on
+#sopass DE:AD:BE:EF:CA:FE"
+
+# Disable pause auto-negotiation and explicitly enable RX and TX pause.
+#ethtool_pause_eth0="autoneg off
+#rx on tx on"
+
+# Enasble adaptive RX and TX coalescing
+#ethtool_coalesce_eth0="adaptive-rx on adaptive-tx on"
+
+# Change ring buffer settings
+#ethtool_ring_eth0=""
+
+# Enable all offload settings
+#ethtool_offload_eth0="rx on tx on sg on tso on ufo on gso on gro on lro on"
+
+# Change specific bytes in the EEPROM
+#ethtool_change_eeprom_eth0=""
+
+# Run the identify sequence on the interface for 1 second (does not return until completion)
+#ethtool_identify_eth0="1"
+
+# Configure receive network flow classification
+#ethtool_nfc_eth0="
+#rx-flow-hash tcp4 f
+#rx-flow-hash udp4 s"
+
+# Flash firmware to all regions
+#ethtool_flash_eth0="/some/path/firmware1 0"
+
+# Flash firmware to region 1
+#ethtool_flash_eth0="/some/path/firmware2 1"
+
+# Set receive flow hash indirection table for even balancing between N receive queues
+#ethtool_rxfh_indir_eth0="equal 4"
+
+# Configure Rx ntuple filters and actions
+#ethtool_ntuple_eth0=""
+
+# Additionally, there is a special control variable, if you need to change the
+# order of option processing. The default order is:
+# flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple
+
+# Set global order to default
+#ethtool_order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple"
+
+# Hypothetical network card that requires a change-eeprom toggle to enable flashing
+#ethtool_order_eth0="change-eeprom flash change pause coalesce ring offload nfc rxfh-indir ntuple"
+
+#-----------------------------------------------------------------------------
+# Firewalld support
+# If you are using the firewalld daemon to configure your firewall
+# settings and you have specific zones you want to apply to your
+# interfaces, you can do this here.
+#firewalld_zone_eth0="myzone"
+
+##############################################################################
+# ADVANCED CONFIGURATION
+#
+# Four functions can be defined which will be called surrounding the
+# start/stop operations. The functions are called with the interface
+# name first so that one function can control multiple adapters. An extra two
+# functions can be defined when an interface fails to start or stop.
+#
+# The return values for the preup and predown functions should be 0
+# (success) to indicate that configuration or deconfiguration of the
+# interface can continue. If preup returns a non-zero value, then
+# interface configuration will be aborted. If predown returns a
+# non-zero value, then the interface will not be allowed to continue
+# deconfiguration.
+#
+# The return values for the postup, postdown, failup and faildown functions are
+# ignored since there's nothing to do if they indicate failure.
+#
+# ${IFACE} is set to the interface being brought up/down
+# ${IFVAR} is ${IFACE} converted to variable name bash allows
+#
+# For historical and compatibility reasons, preup is actually normally called
+# in the following sequence: up ; preup ; up.
+# The first up causes the kernel to initialize the device, so
+# that it is available for use in the preup function. However, for some
+# hardware, e.g. CAN devices, some configuration is needed before trying to up
+# the interface will actually work. For such hardware, the
+# up_before_preup variables will allow skipping the first up call if set
+# to yes.
+#up_before_preup_IFVAR="NO"
+#up_before_preup="NO"
+
+#preup() {
+# # Test for link on the interface prior to bringing it up. This
+# # only works on some network adapters and requires the
+# # sys-apps/net-tools package to be installed.
+# if mii-tool "${IFACE}" 2> /dev/null | grep -q 'no link'; then
+# ewarn "No link on ${IFACE}, aborting configuration"
+# return 1
+# fi
+#
+# # Test for link on the interface prior to bringing it up. This
+# # only works on some network adapters and requires the ethtool
+# # package to be installed.
+# if ethtool "${IFACE}" | grep -q 'Link detected: no'; then
+# ewarn "No link on ${IFACE}, aborting configuration"
+# return 1
+# fi
+#
+# # Test to see if we're docked or not and configure like so
+# # config_docked="dhcp"
+# if grep -q "1" /sys/devices/platform/dock.0/docked; then
+# einfo "${IFACE} is docked - configuring"
+# _configure_variables "docked"
+# fi
+#
+# # Remember to return 0 on success
+# return 0
+#}
+
+#predown() {
+# # The default in the script is to test for NFS root and disallow
+# # downing interfaces in that case. Note that if you specify a
+# # predown() function you will override that logic. Here it is, in
+# # case you still want it...
+# if is_net_fs /; then
+# eerror "root filesystem is network mounted -- can't stop ${IFACE}"
+# return 1
+# fi
+#
+# # Remember to return 0 on success
+# return 0
+#}
+
+#postup() {
+# # This function could be used, for example, to register with a
+# # dynamic DNS service. Another possibility would be to
+# # send/receive mail once the interface is brought up.
+#}
+
+#postdown() {
+# # Enable Wake-On-LAN for every interface except for lo
+# # Probably a good idea to set ifdown="no" in /etc/conf.d/net
+# # as well ;)
+# [ "${IFACE}" != "lo" ] && ethtool -s "${IFACE}" wol g
+# # Return 0 always
+# return 0
+#}
+
+#failup() {
+# # This function is mostly here for completeness... I haven't
+# # thought of anything nifty to do with it yet ;-)
+#}
+
+#faildown() {
+# # This function is mostly here for completeness... I haven't
+# # thought of anything nifty to do with it yet ;-)
+#}
+
+# You should note that we don't stop the network at system shutdown by default.
+# If you really need this, then set keep_network=NO
diff --git a/init.d/.gitignore b/init.d/.gitignore
new file mode 100644
index 0000000..1c460a0
--- /dev/null
+++ b/init.d/.gitignore
@@ -0,0 +1,2 @@
+net.lo
+net.lo0
diff --git a/init.d/Makefile b/init.d/Makefile
new file mode 100644
index 0000000..0854b57
--- /dev/null
+++ b/init.d/Makefile
@@ -0,0 +1,23 @@
+DIR= ${INITDIR}
+INSTALLAFTER= _installafter_net.lo
+SRCS= net.lo.in
+BIN= ${OBJS}
+
+# Build our old net foo or not
+
+MK= ../mk
+include ${MK}/os.mk
+
+NET_LO-FreeBSD= net.lo0
+NET_LO-Linux= net.lo
+NET_LO-NetBSD= net.lo0
+
+%.in: %${SFX}
+ sed ${SED_REPLACE} ${SED_EXTRA} $< > $@
+
+include ${MK}/scripts.mk
+
+_installafter_: realinstall
+
+_installafter_net.lo: realinstall
+ ${INSTALL} -m ${BINMODE} net.lo ${DESTDIR}/${INITDIR}/${NET_LO-${OS}}
diff --git a/init.d/net.lo.in b/init.d/net.lo.in
new file mode 100644
index 0000000..a4e65e9
--- /dev/null
+++ b/init.d/net.lo.in
@@ -0,0 +1,789 @@
+#!@SBINDIR@/runscript
+# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+MODULESDIR="@LIBEXECDIR@/net"
+MODULESLIST="${RC_SVCDIR}/nettree"
+_config_vars="config routes"
+
+[ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND="NO"
+
+description="Configures network interfaces."
+
+# Handy var so we don't have to embed new lines everywhere for array splitting
+__IFS="
+"
+depend()
+{
+ local IFACE=${RC_SVCNAME#*.}
+ local IFVAR=$(shell_var "${IFACE}")
+
+ need localmount
+ if [ "$RC_UNAME" = Linux -a "$IFACE" != lo ]; then
+ need sysfs
+ fi
+ after bootmisc
+ keyword -jail -prefix -vserver
+
+ case "${IFACE}" in
+ lo|lo0) ;;
+ *)
+ after net.lo net.lo0 dbus
+ provide net
+ ;;
+ esac
+
+ if [ "$(command -v "depend_${IFVAR}")" = "depend_${IFVAR}" ]; then
+ depend_${IFVAR}
+ fi
+
+ local dep= prov=
+ for dep in need use before after provide keyword; do
+ eval prov=\$rc_${dep}_${IFVAR}
+ if [ -n "${prov}" ]; then
+ ${dep} ${prov}
+ ewarn "rc_${dep}_${IFVAR} is deprecated."
+ ewarn "Please use rc_net_${IFVAR}_${dep} instead."
+ fi
+ done
+}
+
+# Support bash arrays - sigh
+_array_helper()
+{
+ local _a=
+
+ eval _a=\$$1
+ _a=$(echo "${_a}" | sed -e 's:^[[:space:]]*::' -e 's:[[:space:]]*$::' -e '/^$/d' -e 's:[[:space:]]\{1,\}: :g')
+
+ [ -n "${_a}" ] && printf "%s\n" "${_a}"
+}
+
+_get_array()
+{
+ local _a=
+ if [ -n "${BASH}" ]; then
+ case "$(declare -p "$1" 2>/dev/null)" in
+ "declare -a "*)
+ ewarn "You are using a bash array for $1."
+ ewarn "This feature will be removed in the future."
+ ewarn "Please see net.example for the correct format for $1."
+ eval "set -- \"\${$1[@]}\""
+ for _a; do
+ printf "%s\n" "${_a}"
+ done
+ return 0
+ ;;
+ esac
+ fi
+
+ _array_helper $1
+}
+
+# Flatten bash arrays to simple strings
+_flatten_array()
+{
+ if [ -n "${BASH}" ]; then
+ case "$(declare -p "$1" 2>/dev/null)" in
+ "declare -a "*)
+ ewarn "You are using a bash array for $1."
+ ewarn "This feature will be removed in the future."
+ ewarn "Please see net.example for the correct format for $1."
+ eval "set -- \"\${$1[@]}\""
+ for x; do
+ printf "'%s' " "$(printf "$x" | sed "s:':'\\\'':g")"
+ done
+ return 0
+ ;;
+ esac
+ fi
+
+ _array_helper $1
+}
+
+_wait_for_carrier()
+{
+ local timeout= efunc=einfon
+
+ _has_carrier && return 0
+
+ eval timeout=\$carrier_timeout_${IFVAR}
+ timeout=${timeout:-${carrier_timeout:-0}}
+
+ # Incase users don't want this nice feature ...
+ [ ${timeout} -le 0 ] && return 0
+
+ yesno ${RC_PARALLEL} && efunc=einfo
+ ${efunc} "Waiting for carrier (${timeout} seconds) "
+ while [ ${timeout} -gt 0 ]; do
+ if _has_carrier; then
+ [ "${efunc}" = "einfon" ] && echo
+ eend 0
+ return 0
+ fi
+ sleep 1
+ : $(( timeout -= 1 ))
+ [ "${efunc}" = "einfon" ] && printf "."
+ done
+
+ [ "${efunc}" = "einfon" ] && echo
+ eend 1
+ return 1
+}
+
+_netmask2cidr()
+{
+ # Some shells cannot handle hex arithmetic, so we massage it slightly
+ # Buggy shells include FreeBSD sh, dash and busybox.
+ # bash and NetBSD sh don't need this.
+ case $1 in
+ 0x*)
+ local hex=${1#0x*} quad=
+ while [ -n "${hex}" ]; do
+ local lastbut2=${hex#??*}
+ quad=${quad}${quad:+.}0x${hex%${lastbut2}*}
+ hex=${lastbut2}
+ done
+ set -- ${quad}
+ ;;
+ esac
+
+ local i= len=
+ local IFS=.
+ for i in $1; do
+ case $i in
+ 0x*) i=$((i)) ;;
+ esac
+ while [ ${i} -ne 0 ]; do
+ : $(( len += i % 2 ))
+ : $(( i >>= 1 ))
+ done
+ done
+
+ echo "${len}"
+}
+
+_configure_variables()
+{
+ local var= v= t=
+
+ for var in ${_config_vars}; do
+ local v=
+ for t; do
+ eval v=\$${var}_${t}
+ if [ -n "${v}" ]; then
+ eval ${var}_${IFVAR}=\$${var}_${t}
+ continue 2
+ fi
+ done
+ done
+}
+
+_which()
+{
+ local i OIFS
+ # Empty
+ [ -z "$1" ] && return
+ # check paths
+ OIFS="$IFS"
+ IFS=:
+ for i in $PATH ; do
+ [ -x $i/$1 ] && echo $i/$1 && break
+ done
+ IFS=$OIFS
+}
+
+# Like _which, but also consider shell builtins, and multiple alternatives
+_program_available()
+{
+ [ -z "$1" ] && return 0
+ local x=
+ for x; do
+ case "${x}" in
+ /*) [ -x "${x}" ] && break;;
+ *) type "${x}" >/dev/null 2>&1 && break;;
+ esac
+ unset x
+ done
+ [ -n "${x}" ] && echo $x && return 0
+ return 1
+}
+
+_show_address()
+{
+ einfo "received address $(_get_inet_address "${IFACE}")"
+}
+
+# Basically sorts our modules into order and saves the list
+_gen_module_list()
+{
+ local x= f= force=$1
+ if ! ${force} && [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ]; then
+ local update=false
+ for x in "${MODULESDIR}"/*.sh; do
+ [ -e "${x}" ] || continue
+ if [ "${x}" -nt "${MODULESLIST}" ]; then
+ update=true
+ break
+ fi
+ done
+ ${update} || return 0
+ fi
+
+ einfo "Caching network module dependencies"
+ # Run in a subshell to protect the main script
+ (
+ after() {
+ eval ${MODULE}_after="\"\${${MODULE}_after}\${${MODULE}_after:+ }$*\""
+ }
+
+ before() {
+ local mod=${MODULE}
+ local MODULE=
+ for MODULE; do
+ after "${mod}"
+ done
+ }
+
+ program() {
+ if [ "$1" = "start" -o "$1" = "stop" ]; then
+ local s="$1"
+ shift
+ eval ${MODULE}_program_${s}="\"\${${MODULE}_program_${s}}\${${MODULE}_program_${s}:+ }$*\""
+ else
+ eval ${MODULE}_program="\"\${${MODULE}_program}\${${MODULE}_program:+ }$*\""
+ fi
+ }
+
+ provide() {
+ eval ${MODULE}_provide="\"\${${MODULE}_provide}\${${MODULE}_provide:+ }$*\""
+ local x
+ for x in $*; do
+ eval ${x}_providedby="\"\${${MODULE}_providedby}\${${MODULE}_providedby:+ }${MODULE}\""
+ done
+ }
+
+ for MODULE in "${MODULESDIR}"/*.sh; do
+ sh -n "${MODULE}" || continue
+ . "${MODULE}" || continue
+ MODULE=${MODULE#${MODULESDIR}/}
+ MODULE=${MODULE%.sh}
+ eval ${MODULE}_depend
+ MODULES="${MODULES} ${MODULE}"
+ done
+
+ VISITED=
+ SORTED=
+ visit() {
+ case " ${VISITED} " in
+ *" $1 "*) return;;
+ esac
+ VISITED="${VISITED} $1"
+
+ eval AFTER=\$${1}_after
+ for MODULE in ${AFTER}; do
+ eval PROVIDEDBY=\$${MODULE}_providedby
+ if [ -n "${PROVIDEDBY}" ]; then
+ for MODULE in ${PROVIDEDBY}; do
+ visit "${MODULE}"
+ done
+ else
+ visit "${MODULE}"
+ fi
+ done
+
+ eval PROVIDE=\$${1}_provide
+ for MODULE in ${PROVIDE}; do
+ visit "${MODULE}"
+ done
+
+ eval PROVIDEDBY=\$${1}_providedby
+ [ -z "${PROVIDEDBY}" ] && SORTED="${SORTED} $1"
+ }
+
+ for MODULE in ${MODULES}; do
+ visit "${MODULE}"
+ done
+
+ printf "" > "${MODULESLIST}"
+ i=0
+ for MODULE in ${SORTED}; do
+ eval PROGRAM=\$${MODULE}_program
+ eval PROGRAM_START=\$${MODULE}_program_start
+ eval PROGRAM_STOP=\$${MODULE}_program_stop
+ eval PROVIDE=\$${MODULE}_provide
+ echo "module_${i}='${MODULE}'" >> "${MODULESLIST}"
+ echo "module_${i}_program='${PROGRAM}'" >> "${MODULESLIST}"
+ echo "module_${i}_program_start='${PROGRAM_START}'" >> "${MODULESLIST}"
+ echo "module_${i}_program_stop='${PROGRAM_STOP}'" >> "${MODULESLIST}"
+ echo "module_${i}_provide='${PROVIDE}'" >> "${MODULESLIST}"
+ : $(( i += 1 ))
+ done
+ echo "module_${i}=" >> "${MODULESLIST}"
+ )
+
+ return 0
+}
+
+_load_modules()
+{
+ local starting=$1 mymods=
+
+ # Ensure our list is up to date
+ _gen_module_list false
+ if ! . "${MODULESLIST}"; then
+ _gen_module_list true
+ . "${MODULESLIST}"
+ fi
+
+ MODULES=
+ if [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then
+ eval mymods=\$modules_${IFVAR}
+ [ -z "${mymods}" ] && mymods=${modules}
+ fi
+
+ local i=-1 x= mod= f= provides=
+ while true; do
+ : $(( i += 1 ))
+ eval mod=\$module_${i}
+ [ -z "${mod}" ] && break
+ [ -e "${MODULESDIR}/${mod}.sh" ] || continue
+
+ eval set -- \$module_${i}_program
+ if [ -n "$1" ]; then
+ if ! _program_available "$@" >/dev/null; then
+ vewarn "Skipping module $mod due to missing program: $@"
+ continue
+ fi
+ fi
+ if ${starting}; then
+ eval set -- \$module_${i}_program_start
+ else
+ eval set -- \$module_${i}_program_stop
+ fi
+ if [ -n "$1" ]; then
+ if ! _program_available "$@" >/dev/null; then
+ vewarn "Skipping module $mod due to missing program: $@"
+ continue
+ fi
+ fi
+
+ eval provides=\$module_${i}_provide
+ if ${starting}; then
+ case " ${mymods} " in
+ *" !${mod} "*) continue;;
+ *" !${provides} "*) [ -n "${provides}" ] && continue;;
+ esac
+ fi
+ MODULES="${MODULES}${MODULES:+ }${mod}"
+
+ # Now load and wrap our functions
+ if ! . "${MODULESDIR}/${mod}.sh"; then
+ eend 1 "${RC_SVCNAME}: error loading module \`${mod}'"
+ exit 1
+ fi
+
+ [ -z "${provides}" ] && continue
+
+ # Wrap our provides
+ local f=
+ for f in pre_start start post_start; do
+ eval "${provides}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }"
+ done
+
+ eval module_${mod}_provides="${provides}"
+ eval module_${provides}_providedby="${mod}"
+ done
+
+ # Wrap our preferred modules
+ for mod in ${mymods}; do
+ case " ${MODULES} " in
+ *" ${mod} "*)
+ eval x=\$module_${mod}_provides
+ [ -z "${x}" ] && continue
+ for f in pre_start start post_start; do
+ eval "${x}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }"
+ done
+ eval module_${x}_providedby="${mod}"
+ ;;
+ esac
+ done
+
+ # Finally remove any duplicated provides from our list if we're starting
+ # Otherwise reverse the list
+ local LIST="${MODULES}" p=
+ MODULES=
+ if ${starting}; then
+ for mod in ${LIST}; do
+ eval x=\$module_${mod}_provides
+ if [ -n "${x}" ]; then
+ eval p=\$module_${x}_providedby
+ [ "${mod}" != "${p}" ] && continue
+ fi
+ MODULES="${MODULES}${MODULES:+ }${mod}"
+ done
+ else
+ for mod in ${LIST}; do
+ MODULES="${mod}${MODULES:+ }${MODULES}"
+ done
+ fi
+
+ veinfo "Loaded modules: ${MODULES}"
+}
+
+_load_config()
+{
+ local config="$(_get_array "config_${IFVAR}")"
+ local fallback="$(_get_array fallback_${IFVAR})"
+
+ config_index=0
+ local IFS="$__IFS"
+ set -- ${config}
+
+ # We should support a space separated array for cidr configs
+ # But only as long as they do not contain other parameters for the address
+ if [ $# = 1 ]; then
+ unset IFS
+ set -- ${config}
+ # Of course, we may have a single address added old style.
+ # If the NEXT argument is a v4 or v6 address, it's the next config.
+ # Otherwise, it's arguments to the first config...
+ if [ "${2#*.*}" = "${2}" -a "${2#*:*}" = "${2}" ]; then
+ # Not an IPv4/IPv6
+ local IFS="$__IFS"
+ set -- ${config}
+ fi
+ fi
+
+ # Ensure that loopback has the correct address
+ if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ]; then
+ if [ "$1" != "null" ]; then
+ config_0="127.0.0.1/8"
+ config_index=1
+ fi
+ else
+ if [ -z "$1" ]; then
+ ewarn "No configuration specified; defaulting to DHCP"
+ config_0="dhcp"
+ config_index=1
+ fi
+ fi
+
+
+ # We store our config in an array like vars
+ # so modules can influence it
+ for cmd; do
+ eval config_${config_index}="'${cmd}'"
+ : $(( config_index += 1 ))
+ done
+ # Terminate the list
+ eval config_${config_index}=
+
+ config_index=0
+ for cmd in ${fallback}; do
+ eval fallback_${config_index}="'${cmd}'"
+ : $(( config_index += 1 ))
+ done
+ # Terminate the list
+ eval fallback_${config_index}=
+
+ # Don't set to zero, so any net modules don't have to do anything extra
+ config_index=-1
+}
+
+# Support functions
+_run_if()
+{
+ local cmd=$1 iface=$2 ifr=${IFACE} ifv=${IFVAR}
+ # Ensure that we don't stamp on real values
+ local IFACE= IFVAR=
+ shift
+ if [ -n "${iface}" ]; then
+ IFACE="${iface}"
+ [ "${iface}" != "${ifr}" ] && IFVAR=$(shell_var "${IFACE}")
+ else
+ IFACE=${ifr}
+ IFVAR=${ifv}
+ fi
+ ${cmd}
+}
+interface_exists()
+{
+ _run_if _exists "$@"
+}
+interface_up()
+{
+ _run_if _up "$@"
+}
+interface_down()
+{
+ _run_if _down "$@"
+}
+
+start()
+{
+ local IFACE=${RC_SVCNAME#*.} oneworked=false fallback=false module=
+ local IFVAR=$(shell_var "${IFACE}") cmd= our_metric=
+ local metric=0 _up_before_preup
+ eval _up_before_preup="\$up_before_preup_${IFVAR}"
+ [ -z "${_up_before_preup}" ] && _up_before_preup=$up_before_preup
+
+ einfo "Bringing up interface ${IFACE}"
+ eindent
+
+ if [ -z "${MODULES}" ]; then
+ local MODULES=
+ _load_modules true
+ fi
+
+ # We up the iface twice if we have a preup to ensure it's up if
+ # available in preup and afterwards incase the user inadvertently
+ # brings it down
+ if [ "$(command -v preup)" = "preup" ]; then
+ yesno "${_up_before_preup:-yes}" && _up 2>/dev/null
+ ebegin "Running preup"
+ eindent
+ preup || return 1
+ eoutdent
+ fi
+
+ _up 2>/dev/null
+
+ for module in ${MODULES}; do
+ if [ "$(command -v "${module}_pre_start")" = "${module}_pre_start" ]; then
+ ${module}_pre_start || exit $?
+ fi
+ done
+
+ if ! _exists; then
+ eerror "ERROR: interface ${IFACE} does not exist"
+ eerror "Ensure that you have loaded the correct kernel module for your hardware"
+ return 1
+ fi
+
+ if ! _wait_for_carrier; then
+ if service_started devd; then
+ ewarn "no carrier, but devd will start us when we have one"
+ mark_service_inactive "${RC_SVCNAME}"
+ else
+ eerror "no carrier"
+ fi
+ return 1
+ fi
+
+ local config= config_index=
+ _load_config
+ config_index=0
+
+ eval our_metric=\$metric_${IFVAR}
+ if [ -n "${our_metric}" ]; then
+ metric=${our_metric}
+ elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then
+ : $(( metric += $(_ifindex) ))
+ fi
+
+ while true; do
+ eval config=\$config_${config_index}
+ [ -z "${config}" ] && break
+
+ set -- ${config}
+ if [ "$1" != "null" -a "$1" != "noop" ]; then
+ ebegin "$1"
+ fi
+ eindent
+ case "$1" in
+ noop)
+ if [ -n "$(_get_inet_address)" ]; then
+ oneworked=true
+ break
+ fi
+ ;;
+ null) :;;
+ [0-9]*|*:*) _add_address ${config};;
+ *)
+ if [ "$(command -v "${config}_start")" = "${config}_start" ]; then
+ "${config}"_start
+ else
+ eerror "nothing provides \`${config}'"
+ fi
+ ;;
+ esac
+ if eend $?; then
+ oneworked=true
+ else
+ eval config=\$fallback_${config_index}
+ if [ -n "${config}" ]; then
+ fallback=true
+ eoutdent
+ ewarn "Trying fallback configuration ${config}"
+ eindent
+ eval config_${config_index}=\$config
+ unset fallback_${config_index}
+ : $(( config_index -= 1 ))
+ fi
+ fi
+ eoutdent
+ : $(( config_index += 1 ))
+ done
+
+ if ! ${oneworked}; then
+ if [ "$(command -v failup)" = "failup" ]; then
+ ebegin "Running failup"
+ eindent
+ failup
+ eoutdent
+ fi
+ return 1
+ fi
+
+ local hideFirstroute=false first=true routes=
+ if ${fallback}; then
+ routes="$(_get_array "fallback_routes_${IFVAR}")"
+ fi
+ if [ -z "${routes}" ]; then
+ routes="$(_get_array "routes_${IFVAR}")"
+ fi
+ if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ]; then
+ if [ "${config_0}" != "null" ]; then
+ routes="127.0.0.0/8 via 127.0.0.1
+${routes}"
+ hideFirstroute=true
+ fi
+ fi
+
+ local OIFS="${IFS}" SIFS="${IFS-y}"
+ local IFS="$__IFS"
+ local fam
+ for cmd in ${routes}; do
+ unset IFS
+ if ${first}; then
+ first=false
+ einfo "Adding routes"
+ fi
+
+ case ${cmd} in
+ -6" "*) fam="-6"; cmd=${cmd#-6 };;
+ -4" "*) fam="-4"; cmd=${cmd#-4 };;
+ esac
+
+ eindent
+ ebegin ${cmd}
+ # Work out if we're a host or a net if not told
+ case ${cmd} in
+ -net" "*|-host" "*);;
+ *" "netmask" "*) cmd="-net ${cmd}";;
+ *.*.*.*/32*) cmd="-host ${cmd}";;
+ *.*.*.*/*|0.0.0.0|0.0.0.0" "*) cmd="-net ${cmd}";;
+ default|default" "*) cmd="-net ${cmd}";;
+ *:*/128*) cmd="-host ${cmd}";;
+ *:*/*) cmd="-net ${cmd}";;
+ *) cmd="-host ${cmd}";;
+ esac
+ if ${hideFirstroute}; then
+ _add_route ${fam} ${cmd} >/dev/null 2>&1
+ hideFirstroute=false
+ else
+ _add_route ${fam} ${cmd} >/dev/null
+ fi
+ eend $?
+ eoutdent
+ done
+ if [ "${SIFS}" = "y" ]; then
+ unset IFS
+ else
+ IFS="${OIFS}"
+ fi
+
+ for module in ${MODULES}; do
+ if [ "$(command -v "${module}_post_start")" = "${module}_post_start" ]; then
+ ${module}_post_start || exit $?
+ fi
+ done
+
+ if [ "$(command -v postup)" = "postup" ]; then
+ ebegin "Running postup"
+ eindent
+ postup
+ eoutdent
+ fi
+
+ return 0
+}
+
+stop()
+{
+ # Don't stop the network at shutdown.
+ # We don't use the noshutdown keyword so that we are started again
+ # correctly if we go back to multiuser.
+ yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0
+
+ local IFACE=${RC_SVCNAME#*.} module=
+ local IFVAR=$(shell_var "${IFACE}") opts=
+
+ einfo "Bringing down interface ${IFACE}"
+ eindent
+
+ if [ -z "${MODULES}" ]; then
+ local MODULES=
+ _load_modules false
+ fi
+
+ if [ "$(command -v predown)" = "predown" ]; then
+ ebegin "Running predown"
+ eindent
+ predown || return 1
+ eoutdent
+ else
+ if is_net_fs /; then
+ eerror "root filesystem is network mounted -- can't stop ${IFACE}"
+ return 1
+ fi
+ fi
+
+ for module in ${MODULES}; do
+ if [ "$(command -v "${module}_pre_stop")" = "${module}_pre_stop" ]; then
+ ${module}_pre_stop || exit $?
+ fi
+ done
+
+ for module in ${MODULES}; do
+ if [ "$(command -v "${module}_stop")" = "${module}_stop" ]; then
+ ${module}_stop
+ fi
+ done
+
+ # Only delete addresses for interfaces that exist
+ if _exists; then
+ # PPP can manage it's own addresses when IN_BACKGROUND
+ # Important in case "demand" set on the ppp link
+ if ! (yesno ${IN_BACKGROUND} && is_ppp) ; then
+ _delete_addresses "${IFACE}"
+ fi
+ fi
+
+ for module in ${MODULES}; do
+ if [ "$(command -v "${module}_post_stop")" = "${module}_post_stop" ]; then
+ ${module}_post_stop
+ fi
+ done
+
+ # If not in background, and not loopback then bring the interface down
+ # unless overridden.
+ if ! yesno ${IN_BACKGROUND} && \
+ [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then
+ eval module=\$ifdown_${IFVAR}
+ module=${module:-${ifdown:-YES}}
+ yesno ${module} && _down 2>/dev/null
+ fi
+
+ type resolvconf >/dev/null 2>&1 && resolvconf -d "${IFACE}" 2>/dev/null
+
+ if [ "$(command -v "postdown")" = "postdown" ]; then
+ ebegin "Running postdown"
+ eindent
+ postdown
+ eoutdent
+ fi
+
+ return 0
+}
diff --git a/mk/dist.mk b/mk/dist.mk
new file mode 100644
index 0000000..82fb8cb
--- /dev/null
+++ b/mk/dist.mk
@@ -0,0 +1,38 @@
+# rules to make a distribution tarball from a git repo
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+GITREF?= HEAD
+DISTPREFIX?= ${NAME}-${VERSION}
+DISTFILE?= ${DISTPREFIX}.tar.bz2
+
+CLEANFILES+= ${NAME}-*.tar.bz2
+
+_SNAP_SH= date -u +%Y%m%d%H%M
+_SNAP:= $(shell ${_SNAP_SH})
+SNAP= ${_SNAP}
+SNAPDIR= ${DISTPREFIX}-${SNAP}
+SNAPFILE= ${SNAPDIR}.tar.bz2
+
+dist:
+ git archive --prefix=${DISTPREFIX}/ ${GITREF} | bzip2 > ${DISTFILE}
+
+distcheck: dist
+ rm -rf ${DISTPREFIX}
+ tar xf ${DISTFILE}
+ MAKEFLAGS= $(MAKE) -C ${DISTPREFIX}
+ MAKEFLAGS= $(MAKE) -C ${DISTPREFIX} check
+ rm -rf ${DISTPREFIX}
+
+snapshot:
+ rm -rf /tmp/${SNAPDIR}
+ mkdir /tmp/${SNAPDIR}
+ cp -RPp * /tmp/${SNAPDIR}
+ (cd /tmp/${SNAPDIR}; make clean)
+ find /tmp/${SNAPDIR} -name .svn -exec rm -rf -- {} \; 2>/dev/null || true
+ tar -cvjpf ${SNAPFILE} -C /tmp ${SNAPDIR}
+ rm -rf /tmp/${SNAPDIR}
+ ls -l ${SNAPFILE}
+
+snap: snapshot
+
diff --git a/mk/git.mk b/mk/git.mk
new file mode 100644
index 0000000..62cae5a
--- /dev/null
+++ b/mk/git.mk
@@ -0,0 +1,8 @@
+_GITVER_SH= if git rev-parse --short HEAD >/dev/null 2>&1; then \
+ printf "."; \
+ git rev-parse --short HEAD; \
+ else \
+ echo ""; \
+ fi
+_GITVER:= $(shell ${_GITVER_SH})
+GITVER= ${_GITVER}
diff --git a/mk/gitignore.mk b/mk/gitignore.mk
new file mode 100644
index 0000000..ce7f689
--- /dev/null
+++ b/mk/gitignore.mk
@@ -0,0 +1,15 @@
+# rules to make .gitignore files
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+IGNOREFILES+= ${CLEANFILES}
+
+.PHONY: .gitignore
+
+.gitignore:
+ @if test -n "${IGNOREFILES}"; then \
+ echo "Ignoring ${IGNOREFILES}"; \
+ echo ${IGNOREFILES} | tr ' ' '\n' > .gitignore; \
+ fi
+
+ignore: .gitignore
diff --git a/mk/os-BSD.mk b/mk/os-BSD.mk
new file mode 100644
index 0000000..fbcd371
--- /dev/null
+++ b/mk/os-BSD.mk
@@ -0,0 +1,9 @@
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+# Generic definitions
+
+PKG_PREFIX?= /usr/local
+SFX= .BSD.in
+
+LIBKVM?= -lkvm
diff --git a/mk/os-FreeBSD.mk b/mk/os-FreeBSD.mk
new file mode 100644
index 0000000..ff5e42f
--- /dev/null
+++ b/mk/os-FreeBSD.mk
@@ -0,0 +1,6 @@
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+# Generic definitions
+
+include ${MK}/os-BSD.mk
diff --git a/mk/os-Linux.mk b/mk/os-Linux.mk
new file mode 100644
index 0000000..40d9c34
--- /dev/null
+++ b/mk/os-Linux.mk
@@ -0,0 +1,8 @@
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+SFX= .Linux.in
+PKG_PREFIX?= /usr
+
+CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=700
+LIBDL= -Wl,-Bdynamic -ldl
diff --git a/mk/os-NetBSD.mk b/mk/os-NetBSD.mk
new file mode 100644
index 0000000..300ea62
--- /dev/null
+++ b/mk/os-NetBSD.mk
@@ -0,0 +1,7 @@
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+# Generic definitions
+
+PKG_PREFIX?= /usr/pkg
+include ${MK}/os-BSD.mk
diff --git a/mk/os.mk b/mk/os.mk
new file mode 100644
index 0000000..c306f05
--- /dev/null
+++ b/mk/os.mk
@@ -0,0 +1,11 @@
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+# Generic definitions
+
+_OS_SH= uname -s
+_OS:= $(shell ${_OS_SH})
+OS?= ${_OS}
+include ${MK}/os-${OS}.mk
+
+RC_LIB= /$(LIBNAME)/rc
diff --git a/mk/scripts.mk b/mk/scripts.mk
new file mode 100644
index 0000000..2201199
--- /dev/null
+++ b/mk/scripts.mk
@@ -0,0 +1,58 @@
+# Install rules for our scripts
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+include ${MK}/sys.mk
+include ${MK}/os.mk
+
+OBJS+= ${SRCS:.in=}
+
+_PKG_SED_SH= if test "${PREFIX}" = "${PKG_PREFIX}"; then echo "-e 's:@PKG_PREFIX@::g'"; else echo "-e 's:@PKG_PREFIX@:${PKG_PREFIX}:g'"; fi
+_PKG_SED:= $(shell ${_PKG_SED_SH})
+_LCL_SED_SH= if test "${PREFIX}" = "${LOCAL_PREFIX}"; then echo "-e 's:@LOCAL_PREFIX@::g'"; else echo "-e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g'"; fi
+_LCL_SED:= $(shell ${_LCL_SED_SH})
+
+SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' -e 's:@PREFIX@:${PREFIX}:g' -e 's:@BINDIR@:${BINDIR}:g' -e 's:@SBINDIR@:${SBINDIR}:g' ${_PKG_SED} ${_LCL_SED}
+
+# Tweak our shell scripts
+%.sh: %.sh.in
+ ${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
+
+%: %.in
+ ${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
+
+all: ${OBJS} ${TARGETS}
+
+realinstall: ${BIN} ${CONF} ${INC}
+ @if test -n "${DIR}"; then \
+ ${ECHO} ${INSTALL} -d ${DESTDIR}/${DIR}; \
+ ${INSTALL} -d ${DESTDIR}/${DIR} || exit $$?; \
+ fi
+ @if test -n "${BIN}"; then \
+ ${ECHO} ${INSTALL} -m ${BINMODE} ${BIN} ${DESTDIR}/${DIR}; \
+ ${INSTALL} -m ${BINMODE} ${BIN} ${DESTDIR}/${DIR} || exit $$?; \
+ fi
+ @if test -n "${INC}"; then \
+ ${ECHO} ${INSTALL} -m ${INCMODE} ${INC} ${DESTDIR}/${DIR}; \
+ ${INSTALL} -m ${INCMODE} ${INC} ${DESTDIR}/${DIR} || exit $$?; \
+ fi
+ @for x in ${CONF}; do \
+ if ! test -e ${DESTDIR}/${PREFIX}${DIR}/$$x; then \
+ ${ECHO} ${INSTALL} -m ${CONFMODE} $$x ${DESTDIR}/${DIR}; \
+ ${INSTALL} -m ${CONFMODE} $$x ${DESTDIR}/${DIR} || exit $$?; \
+ fi; \
+ done
+
+install: all realinstall ${INSTALLAFTER}
+
+check test::
+ @if test -e runtests.sh ; then ./runtests.sh || exit $$? ; fi
+
+# A lot of scripts don't have anything to clean
+# Also, some rm implentation require a file argument regardless of error
+# so we ensure that it has a bogus argument
+CLEANFILES+= ${OBJS}
+clean:
+ @if test -n "${CLEANFILES}"; then echo "rm -f ${CLEANFILES}"; rm -f ${CLEANFILES}; fi
+
+include ${MK}/gitignore.mk
diff --git a/mk/subdir.mk b/mk/subdir.mk
new file mode 100644
index 0000000..7f198f8
--- /dev/null
+++ b/mk/subdir.mk
@@ -0,0 +1,31 @@
+# Recursive rules
+# Adapted from FreeBSDs bsd.subdir.mk
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_+_ ?= +
+ECHODIR ?= echo
+_SUBDIR = @${_+_}for x in ${SUBDIR}; do \
+ if test -d $$x; then \
+ ${ECHODIR} "===> ${DIRPRFX}$$x (${@:realinstall=install})"; \
+ cd $$x; \
+ ${MAKE} ${@:realinstall=install} \
+ DIRPRFX=${DIRPRFX}$$x/ || exit $$?; \
+ cd ..; \
+ fi; \
+done
+
+all:
+ ${_SUBDIR}
+clean:
+ @if test -n "${CLEANFILES}"; then echo "rm -f ${CLEANFILES}"; rm -f ${CLEANFILES}; fi
+ ${_SUBDIR}
+realinstall:
+ ${_SUBDIR}
+install: realinstall ${INSTALLAFTER}
+check test::
+ ${_SUBDIR}
+depend:
+ ${_SUBDIR}
+ignore:
+ ${_SUBDIR}
diff --git a/mk/sys.mk b/mk/sys.mk
new file mode 100644
index 0000000..dc135a0
--- /dev/null
+++ b/mk/sys.mk
@@ -0,0 +1,52 @@
+# Generic system definitions
+# Copyright (c) 2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+AR?= ar
+CP?= cp
+ECHO?= echo
+INSTALL?= install
+RANLIB?= ranlib
+SED?= sed
+SH= /bin/sh
+
+PREFIX?=
+ifeq (${PREFIX},)
+UPREFIX= /usr
+else
+UPREFIX= ${PREFIX}
+endif
+LOCAL_PREFIX= /usr/local
+
+PICFLAG?= -fPIC
+
+SYSCONFDIR?= ${PREFIX}/etc
+INITDIR?= ${SYSCONFDIR}/init.d
+CONFDIR?= ${SYSCONFDIR}/conf.d
+
+BINDIR?= ${PREFIX}/bin
+BINMODE?= 0755
+
+SBINDIR?= ${PREFIX}/sbin
+SBINMODE?= 0755
+
+INCDIR?= ${UPREFIX}/include
+INCMODE?= 0444
+
+_LIBNAME_SH= case `readlink /lib` in /lib64|lib64) echo "lib64";; *) echo "lib";; esac
+_LIBNAME:= $(shell ${_LIBNAME_SH})
+LIBNAME?= ${_LIBNAME}
+LIBDIR?= ${UPREFIX}/${LIBNAME}
+LIBMODE?= 0444
+SHLIBDIR?= ${PREFIX}/${LIBNAME}
+
+LIBEXECDIR?= ${PREFIX}/libexec/gentoo-oldnet
+
+MANPREFIX?= ${UPREFIX}/share
+MANDIR?= ${MANPREFIX}/man
+MANMODE?= 0444
+
+DOCDIR?= ${UPREFIX}/share/doc
+DOCMODE?= 0644
+
+CONFMODE?= 0644
diff --git a/net/.gitignore b/net/.gitignore
new file mode 100644
index 0000000..7adf813
--- /dev/null
+++ b/net/.gitignore
@@ -0,0 +1,4 @@
+ifconfig.sh
+ifwatchd.sh
+iwconfig.sh
+udhcpc.sh
diff --git a/net/Makefile b/net/Makefile
new file mode 100644
index 0000000..a03c171
--- /dev/null
+++ b/net/Makefile
@@ -0,0 +1,24 @@
+DIR= ${LIBEXECDIR}/net
+SRCS= ifconfig.sh.in ${SRCS-${OS}}
+INC= dhclient.sh dhcpcd.sh ifconfig.sh macchanger.sh macnet.sh \
+ ssidnet.sh system.sh wpa_supplicant.sh ${INC-${OS}}
+
+MK= ../mk
+include ${MK}/os.mk
+
+SRCS-FreeBSD= iwconfig.sh.in
+INC-FreeBSD= iwconfig.sh
+
+SRCS-Linux= iwconfig.sh.in udhcpc.sh.in
+INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
+ ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \
+ ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \
+ vlan.sh macvlan.sh ip6rd.sh firewalld.sh
+
+SRCS-NetBSD= ifwatchd.sh.in
+INC-NetBSD= ifwatchd.sh
+
+%.sh.in: %.sh${SFX}
+ ${CP} $< $@
+
+include ${MK}/scripts.mk
diff --git a/net/adsl.sh b/net/adsl.sh
new file mode 100644
index 0000000..744ebc2
--- /dev/null
+++ b/net/adsl.sh
@@ -0,0 +1,74 @@
+# Copyright (c) 2004-2007 Gentoo Foundation
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+adsl_depend()
+{
+ program /usr/sbin/adsl-start /usr/sbin/pppoe-start
+ before dhcp
+}
+
+adsl_setup_vars()
+{
+ local startstop="$1" 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
+}
+
+adsl_start()
+{
+ local exe= cfgfile= user=
+
+ adsl_setup_vars start || return 1
+
+ # Might or might not be set in conf.d/net
+ eval user=\$adsl_user_${IFVAR}
+
+ # Start ADSL with the cfgfile, but override ETH and PIDFILE
+ einfo "Starting ADSL for ${IFACE}"
+ (
+ cat "${cfgfile}";
+ echo "ETH=${IFACE}";
+ echo "PIDFILE=/var/run/rp-pppoe-${IFACE}.pid";
+ [ -n "${user}" ] && echo "USER=${user}";
+ ) | ${exe} >/dev/null
+ eend $?
+}
+
+adsl_stop()
+{
+ local exe= cfgfile=
+
+ [ ! -f /var/run/rp-pppoe-"${IFACE}".pid ] && return 0
+
+ adsl_setup_vars stop || return 1
+
+ einfo "Stopping ADSL for ${IFACE}"
+ (
+ cat "${cfgfile}";
+ echo "ETH=${IFACE}";
+ echo "PIDFILE=/var/run/rp-pppoe-${IFACE}.pid";
+ ) | ${exe} >/dev/null
+ eend $?
+
+ return 0
+}
diff --git a/net/apipa.sh b/net/apipa.sh
new file mode 100644
index 0000000..a4aee8a
--- /dev/null
+++ b/net/apipa.sh
@@ -0,0 +1,48 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+apipa_depend()
+{
+ program /sbin/arping
+}
+
+_random()
+{
+ local r=${RANDOM} # checkbashisms: false positive, we handle it AFTERWARDS
+ if [ -n "${r}" ]; then
+ echo "${r}"
+ else
+ uuidgen | sed -n -e 's/[^[:digit:]]//g' -e 's/\(^.\{1,7\}\).*/\1/p'
+ fi
+}
+
+apipa_start()
+{
+ local iface="$1" i1= i2= addr= i=0
+
+ _exists true || return 1
+
+ einfo "Searching for free addresses in 169.254.0.0/16"
+ eindent
+
+ while [ ${i} -lt 64516 ]; do
+ : $(( i1 = (_random % 255) + 1 ))
+ : $(( i2 = (_random % 255) + 1 ))
+
+ addr="169.254.${i1}.${i2}"
+ vebegin "${addr}/16"
+ if ! arping_address "${addr}"; then
+ eval config_${config_index}="\"${addr}/16 broadcast 169.254.255.255\""
+ : $(( config_index -= 1 ))
+ veend 0
+ eoutdent
+ return 0
+ fi
+
+ : $(( i += 1 ))
+ done
+
+ eerror "No free address found!"
+ eoutdent
+ return 1
+}
diff --git a/net/arping.sh b/net/arping.sh
new file mode 100644
index 0000000..83360d7
--- /dev/null
+++ b/net/arping.sh
@@ -0,0 +1,131 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+arping_depend()
+{
+ program /sbin/arping /usr/sbin/arping2
+ before interface
+}
+
+arping_address()
+{
+ local ip=${1%%/*} mac="$2" spoof="$3" foundmac= i= w= opts=
+
+ # We only handle IPv4 addresses
+ case "${ip}" in
+ 0.0.0.0|0) return 1;;
+ *.*.*.*);;
+ *) return 1;;
+ esac
+
+ # We need to bring the interface up to test
+ _exists "${iface}" || return 1
+ _up "${iface}"
+
+ eval w=\$arping_wait_${IFVAR}
+ [ -z "${w}" ] && w=${arping_wait:-5}
+
+ if type arping2 >/dev/null 2>&1; then
+ if [ -n "${spoof}" ]; then
+ opts="${opts} -S ${spoof}"
+ else
+ [ -z "$(_get_inet_address)" ] && opts="${opts} -0"
+ fi
+ while [ ${w} -gt 0 -a -z "${foundmac}" ]; do
+ foundmac="$(arping2 ${opts} -r -c 1 -i "${IFACE}" "${ip}" 2>/dev/null | \
+ sed -e 'y/abcdef/ABCDEF/')"
+ : $(( w -= 1 ))
+ done
+ else
+ [ -z "$(_get_inet_address)" ] && opts="${opts} -D"
+
+ foundmac="$(arping -w "${w}" ${opts} -f -I "${IFACE}" "${ip}" 2>/dev/null | \
+ sed -n -e 'y/abcdef/ABCDEF/' -e 's/[^[]*\[\([^]]*\)\].*/\1/p')"
+ fi
+ [ -z "${foundmac}" ] && return 1
+
+ if [ -n "${mac}" ]; then
+ if [ "${mac}" != "${foundmac}" ]; then
+ vewarn "Found ${ip} but MAC ${foundmac} does not match"
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+_arping_in_config()
+{
+ _get_array "config_${IFVAR}" | while read i; do
+ [ "${i}" = "arping" ] && return 1
+ done
+ return 1
+}
+
+arping_start()
+{
+ local gateways= x= conf= i=
+ einfo "Pinging gateways on ${IFACE} for configuration"
+
+ eval gateways=\$gateways_${IFVAR}
+ if [ -z "${gateways}" ]; then
+ eerror "No gateways have been defined (gateways_${IFVAR}=\"...\")"
+ return 1
+ fi
+
+ eindent
+
+ for x in ${gateways}; do
+ local IFS=,
+ set -- ${x}
+ local ip=$1 mac=$2 spoof=$3 extra=
+ unset IFS
+
+ if [ -n "${mac}" ]; then
+ mac="$(echo "${mac}" | tr '[:lower:]' '[:upper:]')"
+ extra="(MAC ${mac})"
+ fi
+
+ vebegin "${ip} ${extra}"
+ if arping_address "${ip}" "${mac}" "${spoof}"; then
+ local IFS=.
+ for i in ${ip}; do
+ if [ "${#i}" = "2" ]; then
+ conf="${conf}0${i}"
+ elif [ "${#i}" = "1" ]; then
+ conf="${conf}00${i}"
+ else
+ conf="${conf}${i}"
+ fi
+ done
+ unset IFS
+ [ -n "${mac}" ] && conf="${conf}_$(echo "${mac}" | sed -e 's/://g')"
+
+ eend 0
+ eoutdent
+ veinfo "Configuring ${IFACE} for ${ip} ${extra}"
+ _configure_variables ${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
+
+ # Ensure that we have a valid config - ie arping is no longer there
+ local IFS="$__IFS"
+ for i in $(_get_array "config_${IFVAR}"); do
+ if [ "${i}" = "arping" ]; then
+ eend 1 "No config found for ${ip} (config_${conf}=\"...\")"
+ continue 2
+ fi
+ done
+ unset IFS
+
+ _load_config
+ return 0
+ fi
+ veend 1
+ done
+
+ eoutdent
+ return 1
+}
diff --git a/net/bonding.sh b/net/bonding.sh
new file mode 100644
index 0000000..fb00825
--- /dev/null
+++ b/net/bonding.sh
@@ -0,0 +1,223 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+bonding_depend()
+{
+ before interface macchanger
+ program /sbin/ifconfig /bin/ifconfig
+ # If you do not have sysfs, you MUST have this binary instead for ioctl
+ # Also you will loose some functionality that cannot be done via sysfs:
+ if [ ! -d /sys/class/net ]; then
+ program /sbin/ifenslave
+ fi
+}
+
+_config_vars="$_config_vars slaves"
+
+_is_bond()
+{
+ [ -f "/proc/net/bonding/${IFACE}" ]
+}
+
+bonding_pre_start()
+{
+ local x= s= n= slaves= primary=
+
+ slaves="$(_get_array "slaves_${IFVAR}")"
+ unset slaves_${IFVAR}
+
+ eval primary="\$primary_${IFVAR}"
+ unset primary_${IFVAR}
+
+ eval subsume="\$subsume_${IFVAR}"
+ unset subsume_${IFVAR}
+
+
+ [ -z "${slaves}" ] && return 0
+
+ # Load the kernel module if required
+ if [ ! -d /proc/net/bonding ]; then
+ if ! modprobe bonding; then
+ eerror "Cannot load the bonding module"
+ return 1
+ fi
+ fi
+
+ if [ ! -d /sys/class/net ]; then
+ ewarn "sysfs is not available! You will be unable to create new bonds, or change dynamic parameters!"
+ fi
+
+ # We can create the interface name we like now, but this
+ # requires sysfs
+ if ! _exists && [ -d /sys/class/net ]; then
+ echo "+${IFACE}" > /sys/class/net/bonding_masters
+ fi
+ _exists true || return 1
+
+ if ! _is_bond; then
+ eerror "${IFACE} is not capable of bonding"
+ return 1
+ fi
+
+ # Interface must be down in order to configure
+ _down
+
+ # Configure the bond mode & link monitoring, then we can reloop to ensure
+ # we configure all other options
+ # mode needs to be done before all other options.
+ # miimon needs to be done BEFORE downdelay
+ [ -d /sys/class/net ] && for n in mode miimon; do
+ x=/sys/class/net/"${IFACE}"/bonding/$n
+ [ -f "${x}" ] || continue
+ eval s=\$${n}_${IFVAR}
+ if [ -n "${s}" ]; then
+ einfo "Setting ${n}: ${s}"
+ echo "${s}" >"${x}" || \
+ eerror "Failed to configure $n (${n}_${IFVAR})"
+ fi
+ done
+ # Nice and dynamic for remaining options:)
+ [ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/*; do
+ [ -f "${x}" ] || continue
+ n=${x##*/}
+ eval s=\$${n}_${IFVAR}
+ # skip mode and miimon
+ [ "${n}" == "mode" -o "${n}" == "miimon" ] && continue
+ if [ -n "${s}" ]; then
+ einfo "Setting ${n}: ${s}"
+ echo "${s}" >"${x}" || \
+ eerror "Failed to configure $n (${n}_${IFVAR})"
+ fi
+ done
+
+ ebegin "Adding slaves to ${IFACE}"
+ eindent
+ einfo "${slaves}"
+
+ # Check that our slaves exist
+ (
+ for IFACE in ${slaves}; do
+ _exists true || return 1
+ done
+
+ # Unless we are subsuming an existing interface (NFS root), we down
+ # slave interfaces to work around bugs supposedly in some chipsets
+ # that cause failure to enslave from other states.
+ if [ -z "${subsume}" ]; then
+ for IFACE in ${slaves}; do
+ _delete_addresses
+ _down
+ done
+ fi
+ )
+
+ # Now force the master to up
+ # - First test for interface subsume request (required for NFS root)
+ if [ -n "${subsume}" ]; then
+ einfo "Subsuming ${subsume} interface characteristics."
+ eindent
+ local oiface=${IFACE}
+ IFACE=${subsume}
+ local addr="$(_get_inet_address)"
+ einfo "address: ${addr}"
+ IFACE=${oiface}
+ unset oiface
+ eoutdent
+ # subsume (presumably kernel auto-)configured IP
+ ifconfig ${IFACE} ${addr} up
+ else
+ # warn if root on nfs and no subsume interface supplied
+ local root_fs_type=$(mountinfo -s /)
+ if [ "${root_fs_type}" = "nfs" ]; then
+ warn_nfs=1
+ ewarn "NFS root detected!!!"
+ ewarn " If your system crashes here, /etc/conf.d/net needs"
+ ewarn " subsume_${IFACE}=\"<iface>\" ... where <iface> is the"
+ ewarn " existing, (usually kernel auto-)configured interface."
+ fi
+ # up the interface
+ _up
+ fi
+
+ # finally add in slaves
+ # things needed in the process, and if they are done by ifenslave, openrc, and/or the kernel.
+ # down new slave interface: ifenslave, openrc
+ # set mtu: ifenslave, kernel
+ # set slave MAC: ifenslave, kernel
+ eoutdent
+ if [ -d /sys/class/net ]; then
+ sys_bonding_path=/sys/class/net/"${IFACE}"/bonding
+ local oiface
+ oiface=$IFACE
+ if [ -n "${primary}" ]; then
+ IFACE=$primary
+ _down
+ IFACE=$oiface
+ echo "+${primary}" >$sys_bonding_path/slaves
+ echo "${primary}" >$sys_bonding_path/primary
+ fi
+ for s in ${slaves}; do
+ [ "${s}" = "${primary}" ] && continue
+ if ! grep -q ${s} $sys_bonding_path/slaves; then
+ IFACE=$s
+ _down
+ IFACE=$oiface
+ echo "+${s}" >$sys_bonding_path/slaves
+ fi
+ done
+ else
+ ifenslave "${IFACE}" ${slaves} >/dev/null
+ fi
+ eend $?
+
+ return 0 #important
+}
+
+bonding_stop()
+{
+ _is_bond || return 0
+
+ # Wipe subsumed interface
+ if [ -n "${subsume}" ]; then
+ ifconfig ${subsume} 0.0.0.0
+ fi
+
+ local slaves= s=
+ 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
+ if [ -d /sys/class/net ]; then
+ for s in ${slaves}; do
+ echo -"${s}" > /sys/class/net/"${IFACE}"/bonding/slaves
+ done
+ else
+ ifenslave -d "${IFACE}" ${slaves}
+ fi
+
+ # reset all slaves
+ (
+ for IFACE in ${slaves}; do
+ if _exists; then
+ _delete_addresses
+ _down
+ fi
+ done
+ )
+
+ _down
+
+ if [ -d /sys/class/net ]; then
+ echo "-${IFACE}" > /sys/class/net/bonding_masters
+ fi
+
+ eend 0
+ return 0
+}
diff --git a/net/br2684ctl.sh b/net/br2684ctl.sh
new file mode 100644
index 0000000..b3f6119
--- /dev/null
+++ b/net/br2684ctl.sh
@@ -0,0 +1,50 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+br2684ctl_depend()
+{
+ before ppp
+ program start br2684ctl
+}
+
+_config_vars="$_config_vars bridge bridge_add brctl"
+
+br2684ctl_pre_start()
+{
+ local opts=
+ eval opts=\$br2684ctl_${IFVAR}
+ [ -z "${opts}" ] && return 0
+
+ if [ "${IFACE#nas[0-9]*}" = "${IFACE}" ]; then
+ eerror "Interface must be called nas[0-9] for RFC 2684 Bridging"
+ return 1
+ fi
+
+ case " ${opts} " in
+ *" -b "*|*" -c "*)
+ eerror "The -b and -c options are not allowed for br2684ctl_${IVAR}"
+ return 1
+ ;;
+ *" -a "*);;
+ *)
+ eerror "-a option (VPI and VCI) is required in br2684ctl_${IFVAR}"
+ return 1
+ ;;
+ esac
+
+ einfo "Starting RFC 2684 Bridge control on ${IFACE}"
+ start-stop-daemon --start --exec $(_which br2684ctl) --background \
+ --make-pidfile --pidfile "/var/run/br2684ctl-${IFACE}.pid" \
+ -- -c "${IFACE#nas*}" ${opts}
+ eend $?
+}
+
+br2684ctl_post_stop()
+{
+ local pidfile="/var/run/br2684ctl-${IFACE}.pid"
+ [ -e "${pidfile}" ] || return 0
+
+ einfo "Stopping RFC 2684 Bridge control on ${IFACE}"
+ start-stop-daemon --stop --quiet --pidfile "${pidfile}"
+ eend $?
+}
diff --git a/net/bridge.sh b/net/bridge.sh
new file mode 100644
index 0000000..60d3eeb
--- /dev/null
+++ b/net/bridge.sh
@@ -0,0 +1,190 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+bridge_depend()
+{
+ before interface macnet
+ program brctl
+}
+
+_config_vars="$_config_vars bridge bridge_add brctl"
+
+_is_bridge()
+{
+ [ -d /sys/class/net/"${1:-${IFACE}}"/bridge ]
+ return $?
+}
+
+_is_bridge_port()
+{
+ [ -d /sys/class/net/"${1:-${IFACE}}"/brport ]
+ return $?
+}
+
+_bridge_ports()
+{
+ for x in /sys/class/net/"${1:-${IFACE}}"/brif/*; do
+ n=${x##*/}
+ echo $n
+ done
+}
+
+bridge_pre_start()
+{
+ local brif= oiface="${IFACE}" e= x=
+ # ports is for static add
+ local ports="$(_get_array "bridge_${IFVAR}")"
+ # old config options
+ local opts="$(_get_array "brctl_${IFVAR}")"
+ # brif is used for dynamic add
+ eval brif=\$bridge_add_${IFVAR}
+
+ # we need a way to if the bridge exists in a variable name, not just the
+ # contents of a variable. Eg if somebody has only bridge_add_eth0='br0',
+ # with no other lines mentioning br0.
+ eval bridge_unset=\${bridge_${IFVAR}-y\}
+ eval brctl_unset=\${brctl_${IFVAR}-y\}
+
+ if [ -z "${brif}" -a "${brctl_unset}" = 'y' ]; then
+ if [ -z "${ports}" -a "${bridge_unset}" = "y" ]; then
+ #eerror "Misconfigured static bridge detected (see net.example)"
+ return 0
+ fi
+ fi
+
+ # If the bridge was already up, we should clear it
+ [ "${bridge_unset}" != "y" ] && bridge_post_stop
+
+ (
+ # Normalize order of variables
+ if [ -z "${ports}" -a -n "${brif}" ]; then
+ # Dynamic mode detected
+ ports="${IFACE}"
+ IFACE="${brif}"
+ IFVAR=$(shell_var "${IFACE}")
+ else
+ # Static mode detected
+ ports="${ports}"
+ metric=1000
+ fi
+
+ if ! _is_bridge ; then
+ ebegin "Creating bridge ${IFACE}"
+ if ! brctl addbr "${IFACE}"; then
+ eend 1
+ return 1
+ fi
+ fi
+
+ # TODO: does this reset the bridge every time we add a interface to the
+ # bridge? We should probably NOT do that.
+
+ # Old configuration set mechanism
+ # Only a very limited subset of the options are available in the old
+ # configuration method. The sysfs interface is in the next block instead.
+ local IFS="$__IFS"
+ for x in ${opts}; do
+ unset IFS
+ set -- ${x}
+ x=$1
+ shift
+ set -- "${x}" "${IFACE}" "$@"
+ brctl "$@"
+ done
+ unset IFS
+
+ # New configuration set mechanism, matches bonding
+ for x in /sys/class/net/"${IFACE}"/bridge/*; do
+ [ -f "${x}" ] || continue
+ n=${x##*/}
+ eval s=\$${n}_${IFVAR}
+ if [ -n "${s}" ]; then
+ einfo "Setting ${n}: ${s}"
+ echo "${s}" >"${x}" || \
+ eerror "Failed to configure $n (${n}_${IFVAR})"
+ fi
+ done
+
+ if [ -n "${ports}" ]; then
+ einfo "Adding ports to ${IFACE}"
+ eindent
+
+ local BR_IFACE="${IFACE}"
+ for x in ${ports}; do
+ ebegin "${x}"
+ local IFACE="${x}"
+ local IFVAR=$(shell_var "${IFACE}")
+ if ! _exists "${IFACE}" ; then
+ eerror "Cannot add non-existent interface ${IFACE} to ${BR_IFACE}"
+ return 1
+ fi
+ # The interface is known to exist now
+ _up
+ if ! brctl addif "${BR_IFACE}" "${x}"; then
+ eend 1
+ return 1
+ fi
+ # Per-interface bridge settings
+ for x in /sys/class/net/"${IFACE}"/brport/*; do
+ [ -f "${x}" ] || continue
+ n=${x##*/}
+ eval s=\$${n}_${IFVAR}
+ if [ -n "${s}" ]; then
+ einfo "Setting ${n}@${IFACE}: ${s}"
+ echo "${s}" >"${x}" || \
+ eerror "Failed to configure $n (${n}_${IFVAR})"
+ fi
+ done
+ eend 0
+ done
+ eoutdent
+ fi
+ ) || return 1
+
+ # Bring up the bridge
+ _set_flag promisc
+ _up
+}
+
+bridge_post_stop()
+{
+ local port= ports= delete=false extra=
+
+ if _is_bridge "${IFACE}"; then
+ ebegin "Destroying bridge ${IFACE}"
+ _down
+ for x in /sys/class/net/"${IFACE}"/brif/*; do
+ [ -s $x ] || continue
+ n=${x##*/}
+ ports="${ports} ${n}"
+ done
+ delete=true
+ iface=${IFACE}
+ eindent
+ else
+ # We are taking down an interface that is part of a bridge maybe
+ ports="${IFACE}"
+ local brport_dir="/sys/class/net/${IFACE}/brport"
+ [ -d ${brport_dir} ] || return 0
+ iface=$(readlink ${brport_dir}/bridge)
+ iface=${iface##*/}
+ [ -z "${iface}" ] && return 0
+ extra=" from ${iface}"
+ fi
+
+ for port in ${ports}; do
+ ebegin "Removing port ${port}${extra}"
+ local IFACE="${port}"
+ _set_flag -promisc
+ brctl delif "${iface}" "${port}"
+ eend $?
+ done
+
+ if ${delete}; then
+ eoutdent
+ brctl delbr "${iface}"
+ eend $?
+ fi
+
+ return 0
+}
diff --git a/net/ccwgroup.sh b/net/ccwgroup.sh
new file mode 100644
index 0000000..aaf7de6
--- /dev/null
+++ b/net/ccwgroup.sh
@@ -0,0 +1,106 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars ccwgroup"
+
+ccwgroup_depend()
+{
+ before interface
+}
+
+ccwgroup_load_modules()
+{
+ # make sure we have ccwgroup support or this is a crap shoot
+ if [ ! -d /sys/bus/ccwgroup ] ; then
+ modprobe -q ccwgroup
+ if [ ! -d /sys/bus/ccwgroup ] ; then
+ eerror "ccwgroup support missing in kernel"
+ return 1
+ fi
+ fi
+
+ # verify the specific interface is supported
+ if [ ! -d /sys/bus/ccwgroup/drivers/$1 ] ; then
+ modprobe $1 >/dev/null 2>&1
+ if [ ! -d /sys/bus/ccwgroup/drivers/$1 ] ; then
+ eerror "$1 support missing in kernel"
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+ccwgroup_pre_start()
+{
+ local ccwgroup="$(_get_array "ccwgroup_${IFVAR}")"
+ [ -z "${ccwgroup}" ] && return 0
+
+ local ccw_type
+ eval ccw_type=\${ccwgroup_type_${IFVAR}:-qeth}
+
+ ccwgroup_load_modules ${ccw_type} || return 1
+
+ einfo "Enabling ccwgroup/${ccw_type} on ${IFACE}"
+
+ set -- ${ccwgroup}
+ local first=$1; shift
+ if [ -e /sys/devices/${ccw_type}/${first}/online ]; then
+ echo "0" >/sys/devices/${ccw_type}/${first}/online
+ else
+ echo "${first}$(printf ',%s' "$@")" >/sys/bus/ccwgroup/drivers/${ccw_type}/group
+ fi
+
+ local var val
+ for var in $(_get_array "ccwgroup_opts_${IFVAR}") online=1 ; do
+ val=${var#*=}
+ var=${var%%=*}
+ echo "${val}" > /sys/devices/${ccw_type}/${first}/${var}
+ done
+ eend $?
+
+ # Now that we've properly configured the device, we can run
+ # bring the interface up. Common code tried to do this already,
+ # but it failed because we didn't setup sysfs yet.
+ _up
+}
+
+ccwgroup_pre_stop()
+{
+ local path="/sys/class/net/${IFACE}"
+
+ # Erase any existing ccwgroup to be safe
+ service_set_value ccwgroup_device ""
+ service_set_value ccwgroup_type ""
+
+ [ ! -L "${path}"/device/driver ] && return 0
+ case "$(readlink "${path}"/device/driver)" in
+ */bus/ccwgroup/*) ;;
+ *) return 0;;
+ esac
+
+ local device
+ device="$(readlink "${path}"/device)"
+ device=${device##*/}
+ service_set_value ccwgroup_device "${device}"
+ device="$(readlink "${path}"/device/driver)"
+ device=${device##*/}
+ service_set_value ccwgroup_type "${device}"
+}
+
+ccwgroup_post_stop()
+{
+ local device="$(service_get_value ccwgroup_device)"
+ [ -z "${device}" ] && return 0
+ local ccw_type="$(service_get_value ccwgroup_type)"
+ local path="/sys/devices/${ccw_type}/${device}"
+
+ einfo "Disabling ccwgroup/${ccw_type} on ${IFACE}"
+ if echo "0" >"${path}"/online &&
+ echo "1" >"${path}"/ungroup ; then
+ # The device doesn't disappear right away which breaks
+ # restart, or a quick start up, so wait around.
+ while [ -e "${path}" ] ; do :; done
+ fi
+ eend $?
+}
diff --git a/net/clip.sh b/net/clip.sh
new file mode 100644
index 0000000..2fc290f
--- /dev/null
+++ b/net/clip.sh
@@ -0,0 +1,221 @@
+# Copyright (c) 2005-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+clip_depend()
+{
+ program /usr/sbin/atmsigd
+ before interface
+}
+
+_config_vars="$_config_vars clip"
+
+# This starts a service. Albeit atmsigd, ilmid and atmarpd do allow for back-
+# grounding through the -b option, its usage causes them to be sensible to
+# SIGHUP, which is sent to all daemons when console detaches right after
+# startup. This is probably due to the fact that these programs don't detach
+# themself from the controlling terminal when backgrounding... The only way I
+# see to overcame this is to use the --background option in start-stop-daemon,
+# which is reported as a "last resort" method, but it acts correctly about this.
+atmclip_svc_start()
+{
+ ebegin "Starting $2 Daemon ($1)"
+ start-stop-daemon --start \
+ --background \
+ --make-pidfile --pidfile "/var/run/$1.pid" \
+ --exec "/usr/sbin/$1" -- -l syslog
+ eend $?
+}
+
+atmclip_svcs_start()
+{
+ einfo "First CLIP instance: starting ATM CLIP daemons"
+ eindent
+
+ if yesno ${clip_full:-yes}; then
+ atmclip_svc_start atmsigd "Signaling" && \
+ atmclip_svc_start ilmid "Integrated Local Management Interface" && \
+ atmclip_svc_start atmarpd "Address Resolution Protocol"
+ else
+ atmclip_svc_start atmarpd "Address Resolution Protocol"
+ fi
+
+ local r=$?
+
+ eoutdent
+ return ${r}
+}
+
+atmclip_svc_stop()
+{
+ ebegin "Stopping $2 Daemon ($1)"
+ start-stop-daemon --stop --quiet \
+ --pidfile "/var/run/$1.pid" \
+ --exec "/usr/sbin/$1"
+ eend $?
+}
+
+atmclip_svcs_stop()
+{
+ einfo "Last CLIP instance: stopping ATM CLIP daemons"
+ eindent
+
+ # Heartake operation!
+ sync
+
+ atmclip_svc_stop atmarpd "Address Resolution Protocol"
+ if yesno ${clip_full:-yes}; then
+ atmclip_svc_stop ilmid "Integrated Local Management Interface"
+ atmclip_svc_stop atmsigd "Signaling"
+ fi
+
+ eoutdent
+}
+
+are_atmclip_svcs_running()
+{
+
+ start-stop-daemon --quiet --test --stop --pidfile /var/run/atmarpd.pid || return 1
+
+ if yesno ${clip_full:-yes}; then
+ start-stop-daemon --quiet --test --stop --pidfile /var/run/ilmid.pid || return 1
+ start-stop-daemon --quiet --test --stop --pidfile /var/run/atmsigd.pid || return 1
+ fi
+
+ return 0
+}
+
+clip_pre_start()
+{
+ local clip=
+ eval clip=\$clip_${IFVAR}
+ [ -z "${clip}" ] && return 0
+
+ if [ ! -r /proc/net/atm/arp ]; then
+ modprobe clip && sleep 2
+ if [ ! -r /proc/net/atm/arp ]; then
+ eerror "You need first to enable kernel support for ATM CLIP"
+ return 1
+ fi
+ fi
+
+ local started_here=
+ if ! are_atmclip_svcs_running; then
+ atmclip_svcs_start || return 1
+ started_here=1
+ fi
+
+ if ! _exists; then
+ ebegin "Creating CLIP interface ${IFACE}"
+ atmarp -c "${IFACE}"
+ if ! eend $?; then
+ [ -z "${started_here}" ] && atmclip_svcs_stop
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+clip_post_start()
+{
+ local clip="$(_get_array "clip_${IFVAR}")"
+ [ -z "${clip}" ] && return 0
+
+ are_atmclip_svcs_running || return 1
+
+ # The atm tools (atmarpd?) are silly enough that they would not work with
+ # iproute2 interface setup as opposed to the ifconfig one.
+ # The workaround is to temporarily toggle the interface state from up
+ # to down and then up again, without touching its address. This (should)
+ # work with both iproute2 and ifconfig.
+ _down
+ _up
+
+ # Now the real thing: create a PVC with our peer(s).
+ # There are cases in which the ATM interface is not yet
+ # ready to establish new VCCs. In that cases, atmarp would
+ # fail. Here we allow 10 retries to happen every 2 seconds before
+ # reporting problems. Also, when no defined VC can be established,
+ # we stop the ATM daemons.
+ local has_failures= i=
+ for i in ${clip}; do
+ local IFS=","
+ set -- ${i}
+ unset IFS
+ local peerip="$1"; shift
+ local ifvpivci="$1"; shift
+ ebegin "Creating PVC ${ifvpivci} for peer ${peerip}"
+
+ local nleftretries=10 emsg= ecode=
+ while [ ${nleftretries} -gt 0 ]; do
+ : $(( nleftretries -= 1 ))
+ emsg="$(atmarp -s "${peerip}" "${ifvpivci}" "$@" 2>&1)"
+ ecode=$? && break
+ sleep 2
+ done
+
+ if ! eend ${ecode}; then
+ eerror "Creation failed for PVC ${ifvpivci}: ${emsg}"
+ has_failures=1
+ fi
+ done
+
+ if [ -n "${has_failures}" ]; then
+ clip_pre_stop "${iface}"
+ clip_post_stop "${iface}"
+ return 1
+ else
+ return 0
+ fi
+}
+
+clip_pre_stop()
+{
+ are_atmclip_svcs_running || return 0
+
+ # We remove all the PVCs which may have been created by
+ # clip_post_start for this interface. This shouldn't be
+ # needed by the ATM stack, but sometimes I got a panic
+ # killing CLIP daemons without previously vacuuming
+ # every active CLIP PVCs.
+ # The linux 2.6's ATM stack is really a mess...
+ local itf= t= encp= idle= ipaddr= left=
+ einfo "Removing PVCs on this interface"
+ eindent
+ {
+ read left && \
+ while read itf t encp idle ipaddr left; do
+ if [ "${itf}" = "${IFACE}" ]; then
+ ebegin "Removing PVC to ${ipaddr}"
+ atmarp -d "${ipaddr}"
+ eend $?
+ fi
+ done
+ } < /proc/net/atm/arp
+ eoutdent
+}
+
+# Here we should teorically delete the interface previously created in the
+# clip_pre_start function, but there is no way to "undo" an interface creation.
+# We can just leave the interface down. "ifconfig -a" will still list it...
+# Also, here we can stop the ATM CLIP daemons if there is no other CLIP PVC
+# outstanding. We check this condition by inspecting the /proc/net/atm/arp file.
+clip_post_stop()
+{
+ are_atmclip_svcs_running || return 0
+
+ local itf= left= hasothers=
+ {
+ read left && \
+ while read itf left; do
+ if [ "${itf}" != "${IFACE}" ]; then
+ hasothers=1
+ break
+ fi
+ done
+ } < /proc/net/atm/arp
+
+ if [ -z "${hasothers}" ]; then
+ atmclip_svcs_stop || return 1
+ fi
+}
diff --git a/net/dhclient.sh b/net/dhclient.sh
new file mode 100644
index 0000000..8c100dd
--- /dev/null
+++ b/net/dhclient.sh
@@ -0,0 +1,76 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+dhclient_depend()
+{
+ after interface
+ program start /sbin/dhclient
+ provide dhcp
+}
+
+_config_vars="$_config_vars dhcp dhcpcd"
+
+dhclient_start()
+{
+ local args= opt= opts= pidfile="/var/run/dhclient-${IFACE}.pid"
+ local sendhost=true dconf=
+
+ # Get our options
+ # These options only work in Gentoo, and maybe RedHat
+ eval args=\$dhclient_${IFVAR}
+ eval opts=\$dhcp_${IFVAR}
+ [ -z "${opts}" ] && opts=${dhcp}
+
+ for opt in ${opts}; do
+ case "${opt}" in
+ nodns) args="${args} -e PEER_DNS=no";;
+ nontp) args="${args} -e PEER_NTP=no";;
+ nogateway) args="${args} -e PEER_ROUTERS=no";;
+ nosendhost) sendhost=false;;
+ esac
+ done
+
+ # Add our route metric
+ [ "${metric:-0}" != "0" ] && args="${args} -e IF_METRIC=${metric}"
+
+ if ${sendhost}; then
+ local hname="$(hostname)"
+ if [ "${hname}" != "(none)" -a "${hname}" != "localhost" ]; then
+ dhconf="${dhconf} interface \"${IFACE}\" {"
+ dhconf="${dhconf} send host-name \"${hname}\";"
+ dhconf="${dhconf}}"
+ fi
+ fi
+
+ # Bring up DHCP for this interface
+ ebegin "Running dhclient"
+ echo "${dhconf}" | start-stop-daemon --start --exec /sbin/dhclient \
+ --pidfile "${pidfile}" \
+ -- ${args} -q -1 -pf "${pidfile}" "${IFACE}"
+ eend $? || return 1
+
+ _show_address
+ return 0
+}
+
+dhclient_stop()
+{
+ local pidfile="/var/run/dhclient-${IFACE}.pid" opts=
+ [ ! -f "${pidfile}" ] && return 0
+
+ # Get our options
+ if [ -x /sbin/dhclient ]; then
+ eval opts=\$dhcp_${IFVAR}
+ [ -z "${opts}" ] && opts=${dhcp}
+ fi
+
+ ebegin "Stopping dhclient on ${IFACE}"
+ case " ${opts} " in
+ *" release "*) dhclient -q -r -pf "${pidfile}" "${IFACE}";;
+ *)
+ start-stop-daemon --stop --quiet \
+ --exec /sbin/dhclient --pidfile "${pidfile}"
+ ;;
+ esac
+ eend $?
+}
diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
new file mode 100644
index 0000000..2c0f919
--- /dev/null
+++ b/net/dhcpcd.sh
@@ -0,0 +1,88 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+dhcpcd_depend()
+{
+ after interface
+ program start dhcpcd
+ provide dhcp
+
+ # We prefer dhcpcd over the others
+ after dhclient pump udhcpc
+}
+
+_config_vars="$_config_vars dhcp dhcpcd"
+
+dhcpcd_start()
+{
+ local args= opt= opts= pidfile="/var/run/dhcpcd-${IFACE}.pid" new=true
+ eval args=\$dhcpcd_${IFVAR}
+ [ -z "${args}" ] && args=${dhcpcd}
+
+ # Get our options
+ eval opts=\$dhcp_${IFVAR}
+ [ -z "${opts}" ] && opts=${dhcp}
+
+ case "$(dhcpcd --version)" in
+ "dhcpcd "[123]*) new=false;;
+ esac
+
+ # Map some generic options to dhcpcd
+ for opt in ${opts}; do
+ case "${opt}" in
+ nodns)
+ if ${new}; then
+ args="${args} -C resolv.conf"
+ else
+ args="${args} -R"
+ fi
+ ;;
+ nontp)
+ if ${new}; then
+ args="${args} -C ntp.conf"
+ else
+ args="${args} -N"
+ fi
+ ;;
+ nonis)
+ if ${new}; then
+ args="${args} -C yp.conf"
+ else
+ args="${args} -Y"
+ fi
+ ;;
+ nogateway) args="${args} -G";;
+ nosendhost) args="${args} -h ''";
+ esac
+ done
+
+ # Add our route metric if not given
+ case " $args " in
+ *" -m "*) ;;
+ *) [ "${metric:-0}" != 0 ] && args="$args -m $metric";;
+ esac
+
+ # Bring up DHCP for this interface
+ ebegin "Running dhcpcd"
+
+ eval dhcpcd "${args}" "${IFACE}"
+ eend $? || return 1
+
+ _show_address
+ return 0
+}
+
+dhcpcd_stop()
+{
+ local pidfile="/var/run/dhcpcd-${IFACE}.pid" opts= sig=SIGTERM
+ [ ! -f "${pidfile}" ] && return 0
+
+ ebegin "Stopping dhcpcd on ${IFACE}"
+ eval opts=\$dhcp_${IFVAR}
+ [ -z "${opts}" ] && opts=${dhcp}
+ case " ${opts} " in
+ *" release "*) sig=SIGHUP;;
+ esac
+ start-stop-daemon --stop --quiet --signal ${sig} --pidfile "${pidfile}"
+ eend $?
+}
diff --git a/net/ethtool.sh b/net/ethtool.sh
new file mode 100644
index 0000000..6023d74
--- /dev/null
+++ b/net/ethtool.sh
@@ -0,0 +1,52 @@
+# Copyright (c) 2011 by Gentoo Foundation
+# Released under the 2-clause BSD license.
+
+ethtool_depend()
+{
+ program ethtool
+ before interface
+}
+
+# This is just to trim whitespace, do not add any quoting!
+_trim() {
+ echo $*
+}
+
+ethtool_pre_start() {
+ local order opt OFS="${OIFS}"
+ eval order=\$ethtool_order_${IFVAR}
+ [ -z "${order}" ] && eval order=\$ethtool_order
+ [ -z "${order}" ] && order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple"
+ # ethtool options not used: --driver, --register-dump, --eeprom-dump, --negotiate, --test, --statistics
+ eindent
+ for opt in ${order} ; do
+ local args
+ eval args=\$ethtool_$(echo $opt | tr - _)_${IFVAR}
+
+ # Skip everything if no arguments
+ [ -z "${args}" ] && continue
+
+ # Split on \n
+ OIFS="${IFS}"
+ local IFS="$__IFS"
+
+ for p in ${args} ; do
+ IFS="${OIFS}"
+ local args_pretty="$(_trim "${p}")"
+ # Do nothing if empty
+ [ -z "${args_pretty}" ] && continue
+ [ "${opt}" = "ring" ] && opt="set-ring"
+ args_pretty="--${opt} $IFACE ${args_pretty}"
+ args="--${opt} $IFACE ${args}"
+ ebegin "ethtool ${args_pretty}"
+ ethtool ${args}
+ rc=$?
+ eend $rc "ethtool exit code $rc"
+ # TODO: ethtool has MANY different exit codes, with no
+ # documentation as to which ones are fatal or not. For now we
+ # simply print the exit code and don't stop the start sequence.
+ done
+ IFS="${OIFS}"
+ done
+ eoutdent
+}
diff --git a/net/firewalld.sh b/net/firewalld.sh
new file mode 100644
index 0000000..ae83c57
--- /dev/null
+++ b/net/firewalld.sh
@@ -0,0 +1,38 @@
+# Copyright (c) 2012 Doug Goldstein <cardoe@cardoe.com>
+# Released under the 2-clause BSD license.
+
+firewalld_depend()
+{
+ after interface
+ before dhcp
+ program firewall-cmd
+ [ "$IFACE" != "lo" ] && need firewalld
+}
+
+_config_vars="$_config_vars firewalld_zone"
+
+firewalld_post_start()
+{
+ local firewalld_zone=
+ eval firewalld_zone=\$firewalld_zone_${IFVAR}
+
+ _exists || return 0
+
+ if [ "${IFACE}" != "lo" ]; then
+ firewall-cmd --zone="${firewalld_zone}" \
+ --change-interface="${IFACE}" > /dev/null 2>&1
+ fi
+
+ return 0
+}
+
+firewalld_pre_stop()
+{
+ _exists || return 0
+
+ if [ "${IFACE}" != "lo" ]; then
+ firewall-cmd --remove-interface="${IFACE}" > /dev/null 2>&1
+ fi
+
+ return 0
+}
diff --git a/net/ifconfig.sh.BSD.in b/net/ifconfig.sh.BSD.in
new file mode 100644
index 0000000..c7e98a2
--- /dev/null
+++ b/net/ifconfig.sh.BSD.in
@@ -0,0 +1,264 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+ifconfig_depend()
+{
+ program /sbin/ifconfig
+ provide interface
+}
+
+_exists()
+{
+ # Only FreeBSD sees to have /dev/net .... is there something
+ # other than ifconfig we can use for the others?
+ if [ -d /dev/net ]; then
+ [ -e /dev/net/"${IFACE}" ]
+ else
+ ifconfig "${IFACE}" >/dev/null 2>&1
+ fi
+}
+
+_up()
+{
+ ifconfig "${IFACE}" up
+}
+
+_down()
+{
+ ifconfig "${IFACE}" down
+}
+
+_ifindex()
+{
+ local x= i=1
+ case "${RC_UNAME}" in
+ FreeBSD|DragonFly)
+ for x in /dev/net[0-9]*; do
+ if [ "${x}" -ef /dev/net/"${IFACE}" ]; then
+ echo "${x#/dev/net}"
+ return 0
+ fi
+ : $(( i += 1 ))
+ done
+ ;;
+ default)
+ for x in $(ifconfig -l); do
+ if [ "${x}" = "${IFACE}" ]; then
+ echo "${i}"
+ return 0
+ fi
+ : $(( i += 1 ))
+ done
+ ;;
+ esac
+
+ # Return the next available index
+ echo "${i}"
+ return 1
+}
+
+_ifconfig_ent()
+{
+ LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | while read ent rest; do
+ case "${ent}" in
+ $1) echo "${rest}";;
+ esac
+ done
+}
+
+_get_mac_address()
+{
+ local ent="ether"
+ case "${RC_UNAME}" in
+ NetBSD|OpenBSD) ent="address:";;
+ esac
+
+ case $(_ifconfig_ent "${ent}") in
+ 00:00:00:00:00:00);;
+ 44:44:44:44:44:44);;
+ FF:FF:FF:FF:FF:FF);;
+ "") return 1;;
+ *) echo "${address}";;
+ esac
+
+ return 0;
+}
+
+
+_is_wireless()
+{
+ case "$(_ifconfig_ent "media:")" in
+ IEEE802.11*|"IEEE 802.11 Wireless"*) return 0;;
+ *) return 1;;
+ esac
+}
+
+_get_inet_address()
+{
+ local inet= address= n= netmask= rest=
+ LC_ALL=C ifconfig "${IFACE}" | while read inet address n netmask rest; do
+ if [ "${inet}" = "inet" ]; then
+ echo "${address}/$(_netmask2cidr "${netmask}")"
+ return 0
+ fi
+ done
+}
+
+_add_address()
+{
+ local inet6=
+
+ case "$@" in
+ *:*) inet6=inet6;;
+ esac
+
+ if [ "${metric:-0}" != "0" ]; then
+ set -- "$@" metric ${metric}
+ fi
+
+ # ifconfig doesn't like CIDR addresses
+ case "${RC_UNAME}" in
+ OpenBSD)
+ local ip="${1%%/*}" cidr="${1##*/}" netmask=
+ if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then
+ netmask="$(_cidr2netmask "${cidr}")"
+ shift
+ set -- "${ip}" netmask "${netmask}" "$@"
+ fi
+ ;;
+ esac
+
+ ifconfig "${IFACE}" ${inet6} "$@" alias
+}
+
+_add_route()
+{
+ if [ $# -gt 3 ]; then
+ if [ "$3" = "gw" -o "$3" = "via" ]; then
+ local one=$1 two=$2
+ shift; shift; shift
+ set -- "${one}" "${two}" "$@"
+ fi
+ fi
+
+ case "$@" in
+ *:*) route add -inet6 "$@";;
+ *) route add "$@";;
+ esac
+}
+
+_delete_addresses()
+{
+ einfo "Removing addresses"
+ eindent
+ LC_ALL=C ifconfig "${IFACE}" | while read inet address ali rest; do
+ case "${inet}" in
+ inet|inet6)
+ if [ "${address}" = "alias" ]; then
+ address="${ali}"
+ fi
+ case "${address}" in
+ *"%${IFACE}"|::1) continue;;
+ 127.0.0.1) [ "${IFACE}" = "lo0" ] && continue;;
+ esac
+ einfo "${address}"
+ ifconfig "${IFACE}" "${inet}" "${address}" -alias
+ eend $?
+ ;;
+ esac
+ done
+ eoutdent
+ return 0
+}
+
+_show_address()
+{
+ einfo "received address $(_get_inet_address "${IFACE}")"
+}
+
+_has_carrier()
+{
+ case "$(_ifconfig_ent "status:")" in
+ ""|active|associated) return 0;;
+ *) return 1;;
+ esac
+}
+
+ifconfig_pre_start()
+{
+ local config="$(_get_array "ifconfig_${IFVAR}")" conf= arg= args=
+ local IFS="$__IFS"
+
+ [ -z "${config}" ] && return 0
+
+ veinfo "Running ifconfig commands"
+ eindent
+ for conf in ${config}; do
+ unset IFS
+ args=
+ for arg in ${conf}; do
+ case ${arg} in
+ [Dd][Hh][Cc][Pp]);;
+ [Nn][Oo][Aa][Uu][Tt][Oo]);;
+ [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]);;
+ [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]);;
+ [Ww][Pp][Aa]);;
+ *) args="${args} ${arg}";;
+ esac
+ done
+
+ [ -z "${args}" ] && continue
+ vebegin "ifconfig${args}"
+ eval ifconfig "${IFACE}" "${args}"
+ veend $?
+ done
+ eoutdent
+
+ return 0
+}
+
+_ifconfig_ipv6_tentative()
+{
+ local inet= address= rest=
+ LC_ALL=C ifconfig "${IFACE}" | while read inet address rest; do
+ case "${inet}" in
+ inet6)
+ case "${rest}" in
+ *" "tentative*) return 2;;
+ esac
+ ;;
+ esac
+ done
+ [ $? = 2 ]
+}
+
+ifconfig_post_start()
+{
+ if _ifconfig_ipv6_tentative; then
+ ebegin "Waiting for IPv6 addresses"
+ while true; do
+ _ifconfig_ipv6_tentative || break
+ done
+ eend 0
+ fi
+}
+
+# Is the interface administratively/operationally up?
+# The 'UP' status in ifconfig is the administrative status
+# Operational state does not seem to be available in BSD?
+# 0: up
+# 1: down
+# 2: invalid arguments
+is_admin_up()
+{
+ local iface="$1"
+ [ -z "$iface" ] && iface="$IFACE"
+ ifconfig "${iface}" | \
+ sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; '
+}
+
+is_oper_up()
+{
+ eerror "TODO: is_oper_up not available on BSD"
+ return 2
+}
diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in
new file mode 100644
index 0000000..2afa66c
--- /dev/null
+++ b/net/ifconfig.sh.Linux.in
@@ -0,0 +1,328 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+ifconfig_depend()
+{
+ program /sbin/ifconfig /bin/ifconfig
+ provide interface
+}
+
+_up()
+{
+ ifconfig "${IFACE}" up
+}
+
+_down()
+{
+ ifconfig "${IFACE}" down
+}
+
+_exists()
+{
+ [ -e /sys/class/net/"$IFACE" ]
+}
+
+_ifindex()
+{
+ local index=-1
+ local f v
+ if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
+ index=$(cat /sys/class/net/"${IFACE}"/ifindex)
+ else
+ for f in /sys/class/net/*/ifindex ; do
+ v=$(cat $f)
+ [ $v -gt $index ] && index=$v
+ done
+ : $(( index += 1 ))
+ fi
+ echo "${index}"
+ return 0
+}
+
+_is_wireless()
+{
+ # Support new sysfs layout
+ [ -d /sys/class/net/"${IFACE}"/wireless -o \
+ -d /sys/class/net/"${IFACE}"/phy80211 ] && return 0
+
+ [ ! -e /proc/net/wireless ] && return 1
+ grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
+}
+
+_set_flag()
+{
+ ifconfig "${IFACE}" "$1"
+}
+
+_get_mac_address()
+{
+ local mac=$(LC_ALL=C ifconfig "${IFACE}" | \
+ sed -n -e 's/.* \(HWaddr\|ether\) \(..:..:..:..:..:..\).*/\2/p')
+
+ case "${mac}" in
+ 00:00:00:00:00:00);;
+ 44:44:44:44:44:44);;
+ FF:FF:FF:FF:FF:FF);;
+ "");;
+ *) echo "${mac}"; return 0;;
+ esac
+
+ return 1
+}
+
+_set_mac_address()
+{
+ ifconfig "${IFACE}" hw ether "$1"
+}
+
+_get_inet_address()
+{
+ set -- $(LC_ALL=C ifconfig "${IFACE}" |
+ sed -n -e 's/.*\(inet addr:\|inet \)\([^ ]*\).*\(Mask:\|netmask \)\([^ ]*\).*/\2 \4/p')
+ [ -z "$1" ] && return 1
+
+ echo -n "$1"
+ shift
+ echo "/$(_netmask2cidr "$1")"
+}
+
+_get_inet_addresses()
+{
+ local iface=${IFACE} i=0
+ local addrs="$(_get_inet_address)"
+
+ while true; do
+ local IFACE="${iface}:${i}"
+ _exists || break
+ local addr="$(_get_inet_address)"
+ [ -n "${addr}" ] && addrs="${addrs}${addrs:+ }${addr}"
+ : $(( i += 1 ))
+ done
+ echo "${addrs}"
+}
+
+_cidr2netmask()
+{
+ local cidr="$1" netmask="" done=0 i=0 sum=0 cur=128
+ local octets= frac=
+
+ local octets=$(( cidr / 8 ))
+ local frac=$(( cidr % 8 ))
+ while [ ${octets} -gt 0 ]; do
+ netmask="${netmask}.255"
+ : $(( octets -= 1 ))
+ : $(( done += 1 ))
+ done
+
+ if [ ${done} -lt 4 ]; then
+ while [ ${i} -lt ${frac} ]; do
+ : $(( sum += cur ))
+ : $(( cur /= 2 ))
+ : $(( i += 1 ))
+ done
+ netmask="${netmask}.${sum}"
+ : $(( done += 1 ))
+
+ while [ ${done} -lt 4 ]; do
+ netmask="${netmask}.0"
+ : $(( done += 1 ))
+ done
+ fi
+
+ echo "${netmask#.*}"
+}
+
+_add_address()
+{
+ if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then
+ ifconfig "${IFACE}" "$@" 2>/dev/null
+ return 0
+ fi
+
+ case "$1" in
+ *:*) ifconfig "${IFACE}" inet6 add "$@"; return $?;;
+ esac
+
+ # IPv4 is tricky - ifconfig requires an aliased device
+ # for multiple addresses
+ local iface="${IFACE}"
+ if LC_ALL=C ifconfig "${iface}" | grep -Eq '\<inet (addr:)?.*'; then
+ # Get the last alias made for the interface and add 1 to it
+ i=$(ifconfig | sed '1!G;h;$!d' | grep -m 1 -o "^${iface}:[0-9]*" \
+ | sed -n -e 's/'"${iface}"'://p')
+ : $(( i = ${i:-0} + 1 ))
+ iface="${iface}:${i}"
+ fi
+
+ # ifconfig doesn't like CIDR addresses
+ local ip="${1%%/*}" cidr="${1##*/}" netmask=
+ if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then
+ netmask="$(_cidr2netmask "${cidr}")"
+ shift
+ set -- "${ip}" netmask "${netmask}" "$@"
+ fi
+
+ local arg= cmd=
+ while [ -n "$1" ]; do
+ case "$1" in
+ brd)
+ if [ "$2" = "+" ]; then
+ shift
+ else
+ cmd="${cmd} broadcast"
+ fi
+ ;;
+ peer) cmd="${cmd} pointopoint";;
+ *) cmd="${cmd} $1";;
+ esac
+ shift
+ done
+
+ ifconfig "${iface}" ${cmd}
+}
+
+_add_route()
+{
+ local inet6= family=
+
+ if [ "$1" = "-A" -o "$1" = "-f" -o "$1" = "-family" ]; then
+ family="-A $2"
+ shift; shift
+ elif [ "$1" = "-4" ]; then
+ family="-A inet"
+ shift
+ elif [ "$1" = "-6" ]; then
+ family="-A inet6"
+ shift
+ fi
+
+ if [ -n "${metric}" ]; then
+ set -- "$@" metric ${metric}
+ fi
+
+ if [ $# -eq 3 ]; then
+ set -- "$1" "$2" gw "$3"
+ elif [ "$3" = "via" ]; then
+ local one=$1 two=$2
+ shift; shift; shift
+ set -- "${one}" "${two}" gw "$@"
+ fi
+
+ case "$@" in
+ *:*|default*) [ "$1" = "-net" -o "$1" = "-host" ] && shift;;
+ esac
+
+ route ${family} add "$@" dev "${IFACE}"
+}
+
+_delete_addresses()
+{
+ # We don't remove addresses from aliases
+ case "${IFACE}" in
+ *:*) return 0;;
+ esac
+
+ einfo "Removing addresses"
+ eindent
+ # iproute2 can add many addresses to an iface unlike ifconfig ...
+ # iproute2 added addresses cause problems for ifconfig
+ # as we delete an address, a new one appears, so we have to
+ # keep polling
+ while true; do
+ local addr=$(_get_inet_address)
+ [ -z "${addr}" ] && break
+
+ if [ "${addr}" = "127.0.0.1/8" ]; then
+ # Don't delete the loopback address
+ [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] && break
+ fi
+ einfo "${addr}"
+ ifconfig "${IFACE}" 0.0.0.0 || break
+ done
+
+ # Remove IPv6 addresses
+ local addr=
+ for addr in $(LC_ALL=C ifconfig "${IFACE}" | \
+ sed -n -e 's/^.*\(inet6 addr:\|inet6\) \([^ ]*\) .*\(Scope:[^L]\|scopeid [^<]*<[^l]\).*/\2/p'); do
+ if [ "${IFACE}" = "lo" ]; then
+ case "${addr}" in
+ "::1/128"|"/128") continue;;
+ esac
+ fi
+ einfo "${addr}"
+ ifconfig "${IFACE}" inet6 del "${addr}"
+ done
+
+ return 0
+}
+
+_has_carrier()
+{
+ return 0
+}
+
+_tunnel()
+{
+ iptunnel "$@"
+}
+
+ifconfig_pre_start()
+{
+ local tunnel=
+ eval tunnel=\$iptunnel_${IFVAR}
+ if [ -n "${tunnel}" ]; then
+ # Set our base metric to 1000
+ metric=1000
+ ebegin "Creating tunnel ${IFVAR}"
+ iptunnel add ${tunnel}
+ eend $? || return 1
+ _up
+ fi
+
+ # MTU support
+ local mtu=
+ eval mtu=\$mtu_${IFVAR}
+ [ -n "${mtu}" ] && ifconfig "${IFACE}" mtu "${mtu}"
+
+ # TX Queue Length support
+ local len=
+ eval len=\$txqueuelen_${IFVAR}
+ [ -n "${len}" ] && ifconfig "${IFACE}" txqueuelen "${len}"
+
+ return 0
+}
+
+ifconfig_post_stop()
+{
+ # Don't delete sit0 as it's a special tunnel
+ [ "${IFACE}" = "sit0" ] && return 0
+
+ [ -z "$(iptunnel show "${IFACE}" 2>/dev/null)" ] && return 0
+
+ ebegin "Destroying tunnel ${IFACE}"
+ iptunnel del "${IFACE}"
+ eend $?
+}
+
+# Is the interface administratively/operationally up?
+# The 'UP' status in ifconfig/iproute2 is the administrative status
+# Operational state is available in iproute2 output as 'state UP', or the
+# operstate sysfs variable.
+# 0: up
+# 1: down
+# 2: invalid arguments
+is_admin_up()
+{
+ local iface="$1"
+ [ -z "$iface" ] && iface="$IFACE"
+ ifconfig "${iface}" | \
+ sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; '
+}
+
+is_oper_up()
+{
+ local iface="$1"
+ [ -z "$iface" ] && iface="$IFACE"
+ read state </sys/class/net/"${iface}"/operstate
+ [ "x$state" = "up" ]
+}
diff --git a/net/ifplugd.sh b/net/ifplugd.sh
new file mode 100644
index 0000000..0bcde2f
--- /dev/null
+++ b/net/ifplugd.sh
@@ -0,0 +1,94 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars plug_timeout"
+
+ifplugd_depend()
+{
+ program start /usr/sbin/ifplugd
+ after macnet rename
+ before interface
+ provide plug
+}
+
+ifplugd_pre_start()
+{
+ local pidfile="/var/run/ifplugd.${IFACE}.pid" timeout= args=
+
+ # We don't start ifplugd if we're being called from the background
+ yesno ${IN_BACKGROUND} && return 0
+
+ _exists || return 0
+
+ # We need a valid MAC address
+ # It's a basic test to ensure it's not a virtual interface
+ if ! _get_mac_address >/dev/null 2>&1; then
+ vewarn "ifplugd only works on interfaces with a valid MAC address"
+ return 0
+ fi
+
+ # We don't work on bonded, bridges, tun/tap, vlan or wireless
+ for f in bond bridge tuntap vlan wireless; do
+ if type "_is_${f}" >/dev/null 2>&1; then
+ if _is_${f}; then
+ veinfo "ifplugd does not work with ${f}"
+ return 0
+ fi
+ fi
+ done
+
+ ebegin "Starting ifplugd on ${IFACE}"
+
+ eval args=\$ifplugd_${IFVAR}
+
+ # Mark the us as inactive so netplug can restart us
+ mark_service_inactive
+
+ # Start ifplugd
+ eval start-stop-daemon --start --exec /usr/sbin/ifplugd \
+ --pidfile "${pidfile}" -- "${args}" --iface="${IFACE}"
+ eend $? || return 1
+
+ eindent
+
+ # IFACE-specific, then global, then default
+ eval timeout=\$plug_timeout_${IFVAR}
+ [ -z "${timeout}" ] && timeout=$plug_timeout
+ [ -z "${timeout}" ] && timeout=-1
+ if [ ${timeout} -eq 0 ]; then
+ ewarn "WARNING: infinite timeout set for ${IFACE} to come up"
+ elif [ ${timeout} -lt 0 ]; then
+ einfo "Backgrounding ..."
+ exit 1
+ fi
+
+ veinfo "Waiting for ${IFACE} to be marked as started"
+
+ local i=0
+ while true; do
+ if service_started; then
+ _show_address
+ exit 0
+ fi
+ sleep 1
+ [ ${timeout} -eq 0 ] && continue
+ : $(( i += 1 ))
+ [ ${i} -ge ${timeout} ] && break
+ done
+
+ eend 1 "Failed to configure ${IFACE} in the background"
+ exit 1
+}
+
+ifplugd_stop()
+{
+ yesno ${IN_BACKGROUND} && return 0
+
+ local pidfile="/var/run/ifplugd.${IFACE}.pid"
+ [ ! -e "${pidfile}" ] && return 0
+
+ ebegin "Stopping ifplugd on ${IFACE}"
+ start-stop-daemon --stop --quiet --exec /usr/sbin/ifplugd \
+ --pidfile "${pidfile}" --signal QUIT
+ eend $?
+}
diff --git a/net/ifwatchd.sh.BSD.in b/net/ifwatchd.sh.BSD.in
new file mode 100644
index 0000000..289b120
--- /dev/null
+++ b/net/ifwatchd.sh.BSD.in
@@ -0,0 +1,59 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars plug_timeout"
+
+ifwatchd_depend()
+{
+ program start /usr/sbin/ifwatchd
+ after macnet rename wireless
+ before interface
+ provide plug
+}
+
+ifwatchd_pre_start()
+{
+ # We don't start ifwatchd if we're being called from the background
+ yesno ${IN_BACKGROUND} && return 0
+
+ _exists || return 0
+
+ # We need a valid MAC address
+ # It's a basic test to ensure it's not a virtual interface
+ if ! _get_mac_address >/dev/null 2>&1; then
+ vewarn "ifwatchd only works on interfaces with a valid MAC address"
+ return 0
+ fi
+
+ ebegin "Starting ifwatchd on ${IFACE}"
+
+ # Mark the us as inactive so ifwatchd can restart us
+ mark_service_inactive
+
+ # Start ifwatchd
+ IN_BACKGROUND=yes ; export IN_BACKGROUND
+ start-stop-daemon --start --exec /usr/sbin/ifwatchd \
+ -- -c "@LIBEXECDIR@/sh/ifwatchd-carrier.sh" \
+ -n "@LIBEXECDIR@/sh/ifwatchd-nocarrier.sh" "${IFACE}"
+ unset IN_BACKGROUND
+ eend "$?" || return 1
+
+ einfo "Backgrounding ..."
+ exit 1
+}
+
+ifwatchd_stop()
+{
+ yesno ${IN_BACKGROUND} && return 0
+
+ start-stop-daemon --test --quiet --stop --exec /usr/sbin/ifwatchd \
+ -- -c "@LIBEXECDIR@/sh/ifwatchd-carrier.sh" \
+ -n "@LIBEXECDIR@/sh/ifwatchd-nocarrier.sh" "${IFACE}" \
+ || return 0
+
+ ebegin "Stopping ifwatchd on" "${IFACE}"
+ start-stop-daemon --stop --exec /usr/sbin/ifwatchd \
+ -- -c "@LIBEXECDIR@/sh/ifwatchd-carrier.sh" \
+ -n "@LIBEXECDIR@/sh/ifwatchd-nocarrier.sh" "${IFACE}"
+ eend $?
+}
diff --git a/net/ip6rd.sh b/net/ip6rd.sh
new file mode 100644
index 0000000..a35e2b7
--- /dev/null
+++ b/net/ip6rd.sh
@@ -0,0 +1,175 @@
+# Copyright (c) 2011 by Gentoo Foundation
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars link prefix suffix ipv4mask relay"
+
+ip6rd_depend()
+{
+ program ip
+ after interface
+}
+
+ip6rd_pre_start()
+{
+ # ALL interfaces run pre_start blocks, not just those with something
+ # assigned, so we must check if we need to run on this interface before we
+ # do so.
+ local config
+ eval config=\$config_${IFVAR}
+ [ "$config" = "ip6rd" ] || return 0
+
+ case "${MODULES}" in
+ *" ifconfig "*)
+ eerror "ifconfig is not supported for 6rd"
+ eerror "Please emerge sys-apps/iproute2"
+ return 1
+ ;;
+ esac
+
+ local host= suffix= relay= addr= iface=${IFACE} config_ip6rd= localip= ipv4mask=
+ eval host=\$link_${IFVAR}
+ if [ -z "${host}" ]; then
+ eerror "link_${IFVAR} not set"
+ return 1
+ fi
+
+ eval host=\${link_${IFVAR}}
+ eval ipv4mask=\${ipv4mask_${IFVAR}:-0}
+ eval suffix=\${suffix_${IFVAR}:-1}
+ eval relay=\${relay_${IFVAR}}
+ eval prefix=\${prefix_${IFVAR}}
+
+ IFACE=${host}
+ addrs=$(_get_inet_addresses)
+ IFACE=${iface}
+ if [ -z "${addrs}" ]; then
+ eerror "${host} is not configured with an IPv4 address"
+ return 1
+ fi
+ # TODO: Get this settings from DHCP (Option 212)
+ if [ -z "${prefix}" ]; then
+ eerror "prefix_${IFVAR} not set"
+ return 1
+ fi
+ if [ -z "${relay}" ]; then
+ eerror "relay_${IFVAR} not set"
+ return 1
+ fi
+ for addr in ${addrs}; do
+ # Strip the subnet
+ local ip="${addr%/*}" subnet="${addr#*/}"
+ # We don't work on private IPv4 addresses
+ if _ip6rd_inet_is_private_network "${ip}"
+ then
+ continue
+ fi
+
+ local ip6= ip6_prefix="${prefix%::/*}" ip6_subnet="${prefix#*/}"
+ ip6_subnet=$((ip6_subnet + (32-ipv4mask)))
+ eval ip6="$(printf "${ip6_prefix}:%s::%s" \
+ $(_ip6rd_prefix_shave_bits ${ip} ${ipv4mask}) ${suffix})"
+ veinfo "Derived IPv6 address: ${ip6}"
+
+ # Now apply our IPv6 address to our config
+ config_ip6rd="${config_ip6rd}${config_ip6rd:+ }${ip6}/${ip6_subnet}"
+
+ if [ -n "${localip}" ]; then
+ localip="any"
+ else
+ localip="${ip}"
+ fi
+ done
+
+ if [ -z "${config_ip6rd}" ]; then
+ eerror "No global IPv4 addresses found on interface ${host}"
+ return 1
+ fi
+
+ ebegin "Creating 6rd tunnel ${IFACE}"
+ if [ "${IFACE}" != "sit0" ]; then
+ _tunnel add "${IFACE}" mode sit ttl 255 remote any local "${localip}"
+ fi
+ _tunnel 6rd dev "${IFACE}" 6rd-prefix "${prefix}"
+ eend $? || return 1
+ _up
+
+ routes_ip6rd="2003::/3 via ::${relay} metric 2147483647"
+ service_set_value "config_ip6rd_$IFVAR" "$config_ip6rd"
+ service_set_value "routes_ip6rd_$IFVAR" "$routes_ip6rd"
+}
+
+ip6rd_start()
+{
+ local config_ip6rd=$(service_get_value "config_ip6rd_$IFVAR")
+ local routes_ip6rd=$(service_get_value "routes_ip6rd_$IFVAR")
+
+ # Now apply our config
+ eval config_${config_index}=\'"${config_ip6rd}"\'
+ : $(( config_index -= 1 ))
+
+ # Add a route for us, ensuring we don't delete anything else
+ local routes="$(_get_array "routes_${IFVAR}")
+$routes_ip6rd"
+ eval routes_${IFVAR}=\$routes
+}
+
+_ip6rd_inet_atoi()
+{
+ local IFS="${IFS}." ipi=0 j=3
+ for i in $1 ; do
+ # post-decrement isn't valid
+ ipi=$(( ipi | (i << (8*j)) ))
+ j=$(( j - 1 ))
+ done
+ echo ${ipi}
+}
+
+_ip6rd_inet_itoa()
+{
+ local ipi=$1 bitmask v
+ bitmask=$(( (1 << 24)-1 ))
+ for i in 0 1 2 3; do
+ v=$(( (ipi & ~bitmask) >> 24 ))
+ ipi=$(( (ipi & bitmask) << 8 ))
+ if [ $i != 3 ] ; then
+ printf "%d." $v
+ else
+ printf "%d\n" $v
+ fi
+ done
+}
+
+_ip6rd_inet_get_network()
+{
+ local a=$(_ip6rd_inet_atoi $1)
+ local net=$(( a & ( (1<<$2)-1 ) ))
+ local cidr=$(( 32 - $2 ))
+ echo $(_ip6rd_inet_itoa $(( (net << cidr ) )) )
+}
+
+_ip6rd_inet_is_private_network()
+{
+ if [ "$(_ip6rd_inet_get_network $1 16)" = "192.168.0.0" ]\
+ || [ "$(_ip6rd_inet_get_network $1 8)" = "10.0.0.0" ]\
+ || [ "$(_ip6rd_inet_get_network $1 12)" = "172.16.0.0" ]\
+ || [ "$(_ip6rd_inet_get_network $1 16)" = "169.254.0.0" ]
+ then
+ return 0;
+ fi
+ return 1;
+}
+
+_ip6rd_prefix_shave_bits()
+{
+ local ipi=
+ ipi=$(( ($(_ip6rd_inet_atoi $1) & (1<<(32-$2))-1) << $2))
+ if [ $2 -le 16 ]
+ then
+ printf "%04x:%0$(( (16-$2>>2)+(($2%4)?1:0) ))x" \
+ $((ipi >> 16)) $((ipi & (1<<(16-$2))-1))
+ elif [ $2 -lt 32 ]
+ then
+ printf "%0$(( (32-$2>>2)+(($2%4)?1:0) ))x" \
+ $((ipi >> 16))
+ fi
+}
diff --git a/net/ip6to4.sh b/net/ip6to4.sh
new file mode 100644
index 0000000..51b3858
--- /dev/null
+++ b/net/ip6to4.sh
@@ -0,0 +1,116 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars link suffix relay"
+
+ip6to4_depend()
+{
+ after interface
+ program ip
+}
+
+ip6to4_pre_start()
+{
+ # ALL interfaces run pre_start blocks, not just those with something
+ # assigned, so we must check if we need to run on this interface before we
+ # do so.
+ local config
+ eval config=\$config_${IFVAR}
+ [ "$config" = "ip6to4" ] || return 0
+
+ case " ${MODULES} " in
+ *" ifconfig "*)
+ if [ "${IFACE}" != "sit0" ]; then
+ eerror "ip6to4 can only work on the sit0 interface using ifconfig"
+ eerror "emerge sys-apps/iproute2 to use other interfaces"
+ return 1
+ fi
+ esac
+
+ local host= suffix= relay= addr= iface=${IFACE} config_ip6to4= localip=
+ eval host=\$link_${IFVAR}
+ if [ -z "${host}" ]; then
+ eerror "link_${IFVAR} not set"
+ return 1
+ fi
+
+ eval suffix=\${suffix_${IFVAR}:-1}
+ eval relay=\${relay_${IFVAR}:-192.88.99.1}
+
+ IFACE=${host}
+ addrs=$(_get_inet_addresses)
+ IFACE=${iface}
+ if [ -z "${addrs}" ]; then
+ eerror "${host} is not configured with an IPv4 address"
+ return 1
+ fi
+
+ for addr in ${addrs}; do
+ # Strip the subnet
+ local ip="${addr%/*}" subnet="${addr#*/}"
+ # We don't work on private IPv4 addresses
+ case "${ip}" in
+ 127.*) continue;;
+ 10.*) continue;;
+ 192.168.*) continue;;
+ 172.*)
+ local i=16
+ while [ ${i} -lt 32 ]; do
+ case "${ip}" in
+ 172.${i}.*) break;;
+ esac
+ : $(( i += 1 ))
+ done
+ [ ${i} -lt 32 ] && continue
+ ;;
+ esac
+
+ veinfo "IPv4 address on ${host}: ${ip}/${subnet}"
+ local ipa= ip6= IFS="${IFS}."
+ for i in ${ip}; do
+ ipa="${ipa} ${i}"
+ done
+ unset IFS
+ eval ip6="$(printf "2002:%02x%02x:%02x%02x::%s" ${ipa} ${suffix})"
+ veinfo "Derived IPv6 address: ${ip6}"
+
+ # Now apply our IPv6 address to our config
+ config_ip6to4="${config_ip6to4}${config_ip6to4:+ }${ip6}/48"
+
+ if [ -n "${localip}" ]; then
+ localip="any"
+ else
+ localip="${ip}"
+ fi
+ done
+
+ if [ -z "${config_ip6to4}" ]; then
+ eerror "No global IPv4 addresses found on interface ${host}"
+ return 1
+ fi
+
+ if [ "${IFACE}" != "sit0" ]; then
+ ebegin "Creating 6to4 tunnel on ${IFACE}"
+ _tunnel add "${IFACE}" mode sit ttl 255 remote any local "${localip}"
+ eend $? || return 1
+ _up
+ fi
+ routes_ip6to4="2003::/3 via ::${relay} metric 2147483647"
+ service_set_value "config_ip6to4_$IFVAR" "$config_ip6to4"
+ service_set_value "routes_ip6to4_$IFVAR" "$routes_ip6to4"
+}
+
+ip6to4_start()
+{
+ local config_ip6to4=$(service_get_value "config_ip6to4_$IFVAR")
+ local routes_ip6to4=$(service_get_value "routes_ip6to4_$IFVAR")
+
+ # Now apply our config
+ eval config_${config_index}=\'"${config_ip6to4}"\'
+ : $(( config_index -= 1 ))
+
+ # Add a route for us, ensuring we don't delete anything else
+ local routes="$(_get_array "routes_${IFVAR}")
+$routes_ip6to4"
+ eval routes_${IFVAR}=\$routes
+}
diff --git a/net/ipppd.sh b/net/ipppd.sh
new file mode 100644
index 0000000..537065a
--- /dev/null
+++ b/net/ipppd.sh
@@ -0,0 +1,48 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+ipppd_depend()
+{
+ program start /usr/sbin/ipppd
+ after macnet
+ before interface
+ provide isdn
+}
+
+_config_vars="$_config_vars ipppd"
+
+ipppd_pre_start()
+{
+ local opts= pidfile="/var/run/ipppd-${IFACE}.pid"
+
+ # Check that we are a valid ippp interface
+ case "${IFACE}" in
+ ippp[0-9]*);;
+ *) return 0;;
+ esac
+
+ # Check that the interface exists
+ _exists || return 1
+
+ # Might or might not be set in conf.d/net
+ eval opts=\$ipppd_${IFVAR}
+
+ einfo "Starting ipppd for ${IFACE}"
+ start-stop-daemon --start --exec /usr/sbin/ipppd \
+ --pidfile "${pidfile}" \
+ -- ${opts} pidfile "${pidfile}" \
+ file "/etc/ppp/options.${IFACE}" >/dev/null
+ eend $?
+}
+
+ipppd_post_stop()
+{
+ local pidfile="/var/run/ipppd-${IFACE}.pid"
+
+ [ ! -f "${pidfile}" ] && return 0
+
+ einfo "Stopping ipppd for ${IFACE}"
+ start-stop-daemon --stop --quiet --exec /usr/sbin/ipppd \
+ --pidfile "${pidfile}"
+ eend $?
+}
diff --git a/net/iproute2.sh b/net/iproute2.sh
new file mode 100644
index 0000000..3bab7b7
--- /dev/null
+++ b/net/iproute2.sh
@@ -0,0 +1,404 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+iproute2_depend()
+{
+ program ip
+ provide interface
+ after ifconfig
+}
+
+_up()
+{
+ ip link set dev "${IFACE}" up
+}
+
+_down()
+{
+ ip link set dev "${IFACE}" down
+}
+
+_exists()
+{
+ [ -e /sys/class/net/"$IFACE" ]
+}
+
+_ifindex()
+{
+ local index=-1
+ local f v
+ if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
+ index=$(cat /sys/class/net/"${IFACE}"/ifindex)
+ else
+ for f in /sys/class/net/*/ifindex ; do
+ v=$(cat $f)
+ [ $v -gt $index ] && index=$v
+ done
+ : $(( index += 1 ))
+ fi
+ echo "${index}"
+ return 0
+}
+
+_is_wireless()
+{
+ # Support new sysfs layout
+ [ -d /sys/class/net/"${IFACE}"/wireless -o \
+ -d /sys/class/net/"${IFACE}"/phy80211 ] && return 0
+
+ [ ! -e /proc/net/wireless ] && return 1
+ grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
+}
+
+_set_flag()
+{
+ local flag=$1 opt="on"
+ if [ "${flag#-}" != "${flag}" ]; then
+ flag=${flag#-}
+ opt="off"
+ fi
+ ip link set dev "${IFACE}" "${flag}" "${opt}"
+}
+
+_get_mac_address()
+{
+ local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \
+ -e 'y/abcdef/ABCDEF/' \
+ -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
+
+ case "${mac}" in
+ 00:00:00:00:00:00);;
+ 44:44:44:44:44:44);;
+ FF:FF:FF:FF:FF:FF);;
+ "");;
+ *) echo "${mac}"; return 0;;
+ esac
+
+ return 1
+}
+
+_set_mac_address()
+{
+ ip link set dev "${IFACE}" address "$1"
+}
+
+_get_inet_addresses()
+{
+ LC_ALL=C ip -family inet addr show "${IFACE}" | \
+ sed -n -e 's/.*inet \([^ ]*\).*/\1/p'
+}
+
+_get_inet_address()
+{
+ set -- $(_get_inet_addresses)
+ [ $# = "0" ] && return 1
+ echo "$1"
+}
+
+_add_address()
+{
+ if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then
+ ip addr add "$@" dev "${IFACE}" 2>/dev/null
+ return 0
+ fi
+ local x
+ local address netmask broadcast peer anycast label scope
+ local valid_lft preferred_lft home nodad
+ local confflaglist
+ address="$1" ; shift
+ while [ -n "$*" ]; do
+ x=$1 ; shift
+ case "$x" in
+ netmask|ne*)
+ netmask="/$(_netmask2cidr "$1")" ; shift ;;
+ broadcast|brd|br*)
+ broadcast="$1" ; shift ;;
+ pointopoint|pointtopoint|peer|po*|pe*)
+ peer="$1" ; shift ;;
+ anycast|label|scope|valid_lft|preferred_lft|a*|l*|s*|v*|pr*)
+ case $x in
+ a*) x=anycast ;;
+ l*) x=label ;;
+ s*) x=scope ;;
+ v*) x=valid_lft ;;
+ pr*) x=preferred_lft ;;
+ esac
+ eval "$x=$1" ; shift ;;
+ home|nodad|h*|no*)
+ case $x in h*) x=home ;; n*) x=nodad ;; esac
+ # FIXME: If we need to reorder these, this will take more code
+ confflaglist="${confflaglist} $x" ; ;;
+ *)
+ ewarn "Unknown argument to config_$IFACE: $x"
+ esac
+ done
+
+ # Always scope lo addresses as host unless specified otherwise
+ if [ "${IFACE}" = "lo" ]; then
+ [ -z "$scope" ] && scope="host"
+ fi
+
+ # figure out the broadcast address if it is not specified
+ # This must NOT be set for IPv6 addresses
+ if [ "${address#*:}" = "${address}" ]; then
+ [ -z "$broadcast" ] && broadcast="+"
+ elif [ -n "$broadcast" ]; then
+ eerror "Broadcast keywords are not valid with IPv6 addresses"
+ return 1
+ fi
+
+ # This must appear on a single line, continuations cannot be used
+ set -- "${address}${netmask}" ${peer:+peer} ${peer} ${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} ${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" ${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} $preferred_lft $confflaglist
+ veinfo ip addr add "$@"
+ ip addr add "$@"
+}
+
+_add_route()
+{
+ local family=
+
+ if [ "$1" = "-A" -o "$1" = "-f" -o "$1" = "-family" ]; then
+ family="-f $2"
+ shift; shift
+ elif [ "$1" = "-4" ]; then
+ family="-f inet"
+ shift
+ elif [ "$1" = "-6" ]; then
+ family="-f inet6"
+ shift
+ fi
+
+ if [ $# -eq 3 ]; then
+ set -- "$1" "$2" via "$3"
+ elif [ "$3" = "gw" ]; then
+ local one=$1 two=$2
+ shift; shift; shift
+ set -- "${one}" "${two}" via "$@"
+ fi
+
+ local cmd= have_metric=false
+ while [ -n "$1" ]; do
+ case "$1" in
+ metric) cmd="${cmd} $1"; have_metric=true;;
+ netmask) cmd="${cmd}/$(_netmask2cidr "$2")"; shift;;
+ -host|-net);;
+ *) cmd="${cmd} $1";;
+ esac
+ shift
+ done
+
+ # We cannot use a metric if we're using a nexthop
+ if ! ${have_metric} && \
+ [ -n "${metric}" -a \
+ "${cmd##* nexthop }" = "$cmd" ]
+ then
+ cmd="${cmd} metric ${metric}"
+ fi
+
+ veinfo ip ${family} route append ${cmd} dev "${IFACE}"
+ ip ${family} route append ${cmd} dev "${IFACE}"
+ eend $?
+}
+
+_delete_addresses()
+{
+ ip addr flush dev "${IFACE}" scope global 2>/dev/null
+ ip addr flush dev "${IFACE}" scope site 2>/dev/null
+ if [ "${IFACE}" != "lo" ]; then
+ ip addr flush dev "${IFACE}" scope host 2>/dev/null
+ fi
+ return 0
+}
+
+_has_carrier()
+{
+ LC_ALL=C ip link show dev "${IFACE}" | grep -q "LOWER_UP"
+}
+
+_tunnel()
+{
+ ip tunnel "$@"
+}
+
+# This is just to trim whitespace, do not add any quoting!
+_trim() {
+ echo $*
+}
+
+# This is our interface to Routing Policy Database RPDB
+# This allows for advanced routing tricks
+_ip_rule_runner() {
+ local cmd rules OIFS="${IFS}" family
+ if [ "$1" = "-4" -o "$1" = "-6" ]; then
+ family="$1"
+ shift
+ else
+ family="-4"
+ fi
+ cmd="$1"
+ rules="$2"
+ veindent
+ local IFS="$__IFS"
+ for ru in $rules ; do
+ unset IFS
+ ruN="$(_trim "${ru}")"
+ [ -z "${ruN}" ] && continue
+ vebegin "${cmd} ${ruN}"
+ ip $family rule ${cmd} ${ru}
+ veend $?
+ local IFS="$__IFS"
+ done
+ IFS="${OIFS}"
+ veoutdent
+}
+
+iproute2_pre_start()
+{
+ local tunnel=
+ eval tunnel=\$iptunnel_${IFVAR}
+ if [ -n "${tunnel}" ]; then
+ # Set our base metric to 1000
+ metric=1000
+ # Bug#347657: If the mode is 'ipip6' or 'ip6ip6', the -6 must be passed
+ # to iproute2 during tunnel creation.
+ local ipproto=''
+ [ "${tunnel##mode ipip6}" != "${tunnel}" ] && ipproto='-6'
+ [ "${tunnel##mode ip6ip6}" != "${tunnel}" ] && ipproto='-6'
+
+ ebegin "Creating tunnel ${IFVAR}"
+ ip ${ipproto} tunnel add ${tunnel} name "${IFACE}"
+ eend $? || return 1
+ _up
+ fi
+
+ # MTU support
+ local mtu=
+ eval mtu=\$mtu_${IFVAR}
+ [ -n "${mtu}" ] && ip link set dev "${IFACE}" mtu "${mtu}"
+
+ # TX Queue Length support
+ local len=
+ eval len=\$txqueuelen_${IFVAR}
+ [ -n "${len}" ] && ip link set dev "${IFACE}" txqueuelen "${len}"
+
+ return 0
+}
+
+_iproute2_ipv6_tentative()
+{
+ # Only check tentative when we have a carrier.
+ _has_carrier || return 1
+ LC_ALL=C ip addr show dev "${IFACE}" | \
+ grep -q "^[[:space:]]*inet6 .* tentative"
+}
+
+iproute2_post_start()
+{
+ local n=5
+
+ # Kernel may not have IP built in
+ if [ -e /proc/net/route ]; then
+ local rules="$(_get_array "rules_${IFVAR}")"
+ if [ -n "${rules}" ]; then
+ if ! ip -4 rule list | grep -q "^"; then
+ eerror "IP Policy Routing (CONFIG_IP_MULTIPLE_TABLES) needed for ip rule"
+ else
+ service_set_value "ip_rule" "${rules}"
+ einfo "Adding IPv4 RPDB rules"
+ _ip_rule_runner -4 add "${rules}"
+ fi
+ fi
+ ip -4 route flush table cache dev "${IFACE}"
+ fi
+
+ # Kernel may not have IPv6 built in
+ if [ -e /proc/net/ipv6_route ]; then
+ local rules="$(_get_array "rules6_${IFVAR}")"
+ if [ -n "${rules}" ]; then
+ if ! ip -6 rule list | grep -q "^"; then
+ eerror "IPv6 Policy Routing (CONFIG_IPV6_MULTIPLE_TABLES) needed for ip rule"
+ else
+ service_set_value "ip6_rule" "${rules}"
+ einfo "Adding IPv6 RPDB rules"
+ _ip_rule_runner -6 add "${rules}"
+ fi
+ fi
+ ip -6 route flush table cache dev "${IFACE}"
+ fi
+
+ if _iproute2_ipv6_tentative; then
+ ebegin "Waiting for IPv6 addresses"
+ while [ $n -ge 0 ]; do
+ _iproute2_ipv6_tentative || break
+ sleep 1
+ : $(( n -= 1 ))
+ done
+ [ $n -ge 0 ]
+ eend $?
+ fi
+
+ return 0
+}
+
+iproute2_post_stop()
+{
+ # Kernel may not have IP built in
+ if [ -e /proc/net/route ]; then
+ local rules="$(service_get_value "ip_rule")"
+ if [ -n "${rules}" ]; then
+ einfo "Removing IPv4 RPDB rules"
+ _ip_rule_runner -4 del "${rules}"
+ fi
+
+ # Only do something if the interface actually exist
+ if _exists; then
+ ip -4 route flush table cache dev "${IFACE}"
+ fi
+ fi
+
+ # Kernel may not have IPv6 built in
+ if [ -e /proc/net/ipv6_route ]; then
+ local rules="$(service_get_value "ip6_rule")"
+ if [ -n "${rules}" ]; then
+ einfo "Removing IPv6 RPDB rules"
+ _ip_rule_runner -6 del "${rules}"
+ fi
+
+ # Only do something if the interface actually exist
+ if _exists; then
+ ip -6 route flush table cache dev "${IFACE}"
+ fi
+ fi
+
+ # Don't delete sit0 as it's a special tunnel
+ if [ "${IFACE}" != "sit0" ]; then
+ if [ -n "$(ip tunnel show "${IFACE}" 2>/dev/null)" ]; then
+ ebegin "Destroying tunnel ${IFACE}"
+ ip tunnel del "${IFACE}"
+ eend $?
+ fi
+ fi
+}
+
+# Is the interface administratively/operationally up?
+# The 'UP' status in ifconfig/iproute2 is the administrative status
+# Operational state is available in iproute2 output as 'state UP', or the
+# operstate sysfs variable.
+# 0: up
+# 1: down
+# 2: invalid arguments
+is_admin_up()
+{
+ local iface="$1"
+ [ -z "$iface" ] && iface="$IFACE"
+ ip link show dev $iface | \
+ sed -n '1,1{ /[<,]UP[,>]/{ q 0 }}; q 1; '
+}
+
+is_oper_up()
+{
+ local iface="$1"
+ [ -z "$iface" ] && iface="$IFACE"
+ read state </sys/class/net/"${iface}"/operstate
+ [ "x$state" = "up" ]
+}
diff --git a/net/iwconfig.sh.BSD.in b/net/iwconfig.sh.BSD.in
new file mode 100644
index 0000000..3acaf66
--- /dev/null
+++ b/net/iwconfig.sh.BSD.in
@@ -0,0 +1,593 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars ssid mode associate_timeout preferred_aps"
+_config_vars="$_config_vars blacklist_aps"
+
+iwconfig_depend()
+{
+ program /sbin/ifconfig
+ after plug
+ before interface
+ provide wireless
+}
+
+iwconfig_get_wep_status()
+{
+ local status="disabled"
+ local mode=$(LC_ALL=C ifconfig "${IFACE}" \
+ | sed -n -e 's/^[[:space:]]*authmode \([^ ]*\) privacy ON .*/\1/p')
+ if [ -n "${mode}" ] ; then
+ status="enabled - ${mode}"
+ fi
+
+ echo "(WEP ${status})"
+}
+
+_iwconfig_get()
+{
+ LC_ALL=C ifconfig "${IFACE}" | \
+ sed -n -e "s/^[[:space:]]*ssid \(.*\) channel \([0-9]*\).* bssid \(..:..:..:..:..:..\)\$/\\$1/p"
+}
+
+_get_ssid()
+{
+ local ssid="$(_iwconfig_get 1)"
+ # If the ssid has a space then it's wrapped in quotes. This is a
+ # problem if the real ssid has a quote at the start or the end :/
+ ssid=${ssid#\"}
+ ssid=${ssid%\"}
+ echo "${ssid}"
+}
+
+_get_ap_mac_address()
+{
+ _iwconfig_get 3
+}
+
+_get_channel()
+{
+ _iwconfig_get 2
+}
+
+iwconfig_report()
+{
+ local m="connected to"
+ local ssid="$(_get_ssid)"
+ local mac="$(_get_ap_mac_address "${iface}")"
+ [ -n "${mac}" ] && mac=" at ${mac}"
+ local wep_status="$(iwconfig_get_wep_status "${iface}")"
+ local channel="$(_get_channel)"
+ [ -n "${channel}" ] && channel="on channel ${channel} "
+
+ eindent
+ einfo "${IFACE} ${m} \"${ssid}\"${mac}"
+ einfo "${channel}${wep_status}"
+ eoutdent
+}
+
+iwconfig_get_wep_key()
+{
+ local mac="$1" key=
+ [ -n "${mac}" ] && mac="$(echo "${mac}" | sed -e 's/://g')"
+ eval key=\$mac_key_${mac}
+ [ -z "${key}" ] && eval key=\$key_${SSIDVAR}
+ echo "${key:--}"
+}
+
+iwconfig_user_config()
+{
+ local conf=
+ eval set -- \$ifconfig_${SSIDVAR}
+ for conf in "$@" ; do
+ ifconfig "${IFACE}" ${conf}
+ done
+}
+
+iwconfig_set_mode()
+{
+ local x= opt= unopt="hostap adhoc"
+ case "$1" in
+ master|hostap) unopt="adhoc" opt="hostap" ;;
+ ad-hoc|adhoc) unopt="hostap" opt="adhoc" ;;
+ esac
+ for x in ${unopt} ; do
+ ifconfig "${IFACE}" -mediaopt ${x}
+ done
+ for x in ${opt} ; do
+ ifconfig "${IFACE}" mediaopt ${x}
+ done
+}
+
+iwconfig_setup_specific()
+{
+ local mode="${1:-master}" channel=
+ if [ -z "${SSID}" ]; then
+ eerror "${IFACE} requires an SSID to be set to operate in ${mode} mode"
+ eerror "adjust the ssid_${IFVAR} setting in /etc/conf.d/net"
+ return 1
+ fi
+
+ iwconfig_set_mode "${mode}" || return 1
+
+ SSIDVAR=$(shell_var "${SSID}")
+ local key=$(iwconfig_get_wep_key)
+
+ # Now set the key
+ ifconfig "${IFACE}" wepkey "${key}"
+
+ ifconfig "${IFACE}" ssid "${SSID}" || return 1
+
+ eval channel=\$channel_${IFVAR}
+ # We default the channel to 3
+ ifconfig "${IFACE}" channel "${channel:-3}" || return 1
+
+ iwconfig_user_config
+ iwconfig_report "${iface}"
+ return 0
+}
+
+iwconfig_associate()
+{
+ local mac="$1" channel="$2" caps="$3"
+ local mode= w="(WEP Disabled)" key=
+
+ SSIDVAR=$(shell_var "${SSID}")
+ key=$(iwconfig_get_wep_key "${mac}")
+ case "${caps}" in
+ [EI]P*)
+ if [ "${key}" = "-" ] ; then
+ ewarn "WEP key is not set for \"${SSID}\""
+ return 1
+ fi
+ ;;
+ "") ;;
+ *)
+ if [ "${key}" != "-" ] ; then
+ key="-"
+ ewarn "\"${SSID}\" is not WEP enabled"
+ fi
+ ;;
+ esac
+
+ # Set mode accordingly
+ case "${caps}" in
+ *E*)
+ mode="managed"
+ if LC_ALL=C ifconfig "${IFACE}" | \
+ grep -q "^[[:space:]]*media: .*adhoc" ; then
+ ifconfig "${IFACE}" down -mediaopt adhoc up
+ fi
+ ;;
+ *I*)
+ mode="adhoc"
+ if ! LC_ALL=C ifconfig "${IFACE}" | \
+ grep -q "^[[:space:]]*media: .*adhoc" ; then
+ ifconfig "${IFACE}" down mediaopt adhoc up
+ fi
+ ;;
+ *)
+ if LC_ALL=C ifconfig "${IFACE}" \
+ | grep -q "^[[:space:]]*media: .*adhoc" ; then
+ mode="adhoc"
+ else
+ mode="managed"
+ fi
+ ;;
+ esac
+
+ if [ "${key}" = "-" ] ; then
+ ifconfig "${IFACE}" wepmode off
+ else
+ ifconfig "${IFACE}" wepmode on
+ ifconfig "${IFACE}" deftxkey 1
+ w=$(iwconfig_get_wep_status)
+ fi
+
+ ebegin "Connecting to \"${SSID}\" in ${mode} mode ${w}"
+
+ if ! ifconfig "${IFACE}" wepkey "${key}" ; then
+ eerror "Invalid WEP key ${key}"
+ return 1
+ fi
+
+ ifconfig "${IFACE}" ssid "${SSID}" || return 1
+ iwconfig_user_config
+
+ if [ "${SSID}" != "any" ] && type preassociate >/dev/null 2>/dev/null ; then
+ veinfo "Running preassociate function"
+ veindent
+ ( preassociate )
+ local e=$?
+ veoutdent
+ if [ ${e} -eq 0 ] ; then
+ veend 1 "preassociate \"${SSID}\" on ${IFACE} failed"
+ return 1
+ fi
+ fi
+
+ local timeout= i=0
+ eval timeout=\$associate_timeout_${IFVAR}
+ timeout=${timeout:-10}
+
+ [ ${timeout} -eq 0 ] \
+ && vewarn "WARNING: infinite timeout set for association on ${IFACE}"
+
+ while true; do
+ _has_carrier && break
+ sleep 1
+
+ [ ${timeout} -eq 0 ] && continue
+ : $(( i += 1 ))
+ [ ${i} -ge ${timeout} ] && { eend 1; return 1; }
+ done
+
+ _has_carrier || { eend 1; return 1; }
+ eend 0
+
+ if [ "${SSID}" = "any" ]; then
+ SSID="$(_get_ssid)"
+ iwconfig_associate
+ return $?
+ fi
+
+ iwconfig_report
+
+ if type postassociate >/dev/null 2>/dev/null ; then
+ veinfo "Running postassociate function"
+ veindent
+ ( postassociate )
+ veoutdent
+ fi
+
+ return 0
+}
+
+iwconfig_scan()
+{
+ local x= i=0 scan= quality=
+ einfo "Scanning for access points"
+ eindent
+
+ scan="$(LC_ALL=C ifconfig -v "${IFACE}" list scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")"
+ while [ ${i} -lt 3 -a -z "${scan}" ] ; do
+ scan="${scan}${scan:+ }$(LC_ALL=C ifconfig -v "${IFACE}" scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")"
+ : $(( i += 1 ))
+ done
+
+ APS=-1
+ eval set -- ${scan}
+ for line in "$@" ; do
+ : $(( APS += 1 ))
+ set -- ${line}
+ while true ; do
+ case "$1" in
+ *:*:*:*:*:*) break ;;
+ esac
+ eval SSID_${APS}="\"\${SSID_${APS}}\${SSID_${APS}:+ }$1\""
+ shift
+ done
+ eval MAC_${APS}="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
+ eval CHAN_${APS}="$2"
+ quality=${4%:*}
+ shift ; shift ; shift ; shift ; shift
+ eval CAPS_${APS}="\"$*\""
+
+ # Add 1000 for managed nodes as we prefer them to adhoc
+ set -- $*
+ case "$1" in
+ *E*) eval QUAL_${APS}=$(( quality + 1000 )) ;;
+ *) eval QUAL_${APS}=\$quality ;;
+ esac
+ done
+
+ if [ -z "${MAC_0}" ]; then
+ ewarn "no access points found"
+ eoutdent
+ return 1
+ fi
+
+ # Sort based on quality
+ local i=0 k=1 a= b= x= t=
+ while [ ${i} -lt ${APS} ] ; do
+ : $(( k = i + 1 ))
+ while [ ${k} -le ${APS} ] ; do
+ eval a=\$QUALITY_${i}
+ [ -z "${a}" ] && break
+ eval b=\$QUALITY_${k}
+ if [ -n "${b}" -a "${a}" -lt "${b}" ] ; then
+ for x in MAC SSID CHAN QUALITY CAPS ; do
+ eval t=\$${x}_${i}
+ eval ${x}_${i}=\$${x}_${k}
+ eval ${x}_${k}=\$t
+ done
+ fi
+ : $(( k += 1 ))
+ done
+ : $(( i += 1 ))
+ done
+
+ # Strip any duplicates
+ local i=0 k=1 a= b=
+ while [ ${i} -lt ${APS} ] ; do
+ : $(( k = i + 1 ))
+ while [ ${k} -le ${APS} ] ; do
+ eval a=\$MAC_${i}
+ eval b=\$MAC_${k}
+ if [ "${a}" = "${b}" ] ; then
+ eval a=\$QUALITY_${i}
+ eval b=\$QUALITY_${k}
+ if [ -n "${a}" -a -n "${b}" ] ; then
+ if [ ${a} -ge ${b} ] ; then
+ unset MAC_${k} SSID_${k} CHAN_${k} QUALITY_${k} CAPS_${k}
+ else
+ unset MAC_${i} SSID_${i} CHAN_${i} QUALITY_${i} CAPS_${i}
+ fi
+ else
+ unset MAC_${k} SSID_${k} CHAN_${k} QUALITY_${k} CAPS_${k}
+ fi
+ fi
+ : $(( k += 1 ))
+ done
+ : $(( i += 1 ))
+ done
+
+ local i=0 e= m= s=
+
+ while [ ${i} -le ${APS} ] ; do
+ eval x=\$MAC_${i}
+ if [ -z "${x}" ] ; then
+ : $(( i += 1 ))
+ continue
+ fi
+
+ eval m=\$MODE_${i}
+ [ -n "${m}" ] && m=", ${m}"
+ eval s=\$SSID_${i}
+ eval q=\$QUALITY_${i}
+ eval e=\$CAPS_${i}
+ case "${e}" in
+ [EI]P*) e=", encrypted" ;;
+ *) e="" ;;
+ esac
+ if [ -z "${s}" ] ; then
+ einfo "Found ${x}${m}${e}"
+ else
+ einfo "Found \"${s}\" at ${x}${m}${e}"
+ fi
+
+ x="$(echo "${x}" | sed -e 's/://g')"
+ eval x=\$mac_ssid_${x}
+ if [ -n "${x}" ] ; then
+ eval SSID_${i}=\$x
+ s=${x}
+ eindent
+ einfo "mapping to \"${x}\""
+ eoutdent
+ fi
+
+ eval set -- $(_flatten_array "blacklist_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps")
+ for x; do
+ if [ "${x}" = "${s}" ] ; then
+ ewarn "${s} has been blacklisted - not connecting"
+ unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} CAPS_${i}
+ fi
+ done
+ : $(( i += 1 ))
+ done
+ eoutdent
+ return 0
+}
+
+iwconfig_force_preferred()
+{
+ eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
+ [ $# = 0 ] && return 1
+
+ ewarn "Trying to force preferred in case they are hidden"
+ local ssid=
+ for ssid; do
+ local found_AP=false i=0 e=
+ while [ ${i} -le ${APS:--1} ] ; do
+ eval e=\$SSID_${i}
+ if [ "${e}" = "${ssid}" ] ; then
+ found_AP=true
+ break
+ fi
+ : $(( i += 1 ))
+ done
+ if ! ${found_AP} ; then
+ SSID=${ssid}
+ iwconfig_associate && return 0
+ fi
+ done
+
+ ewarn "Failed to associate with any preferred access points on ${IFACE}"
+ return 1
+}
+
+iwconfig_connect_preferred()
+{
+ eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
+ [ $# = 0 ] && return 1
+
+ local ssid= i= mode= mac= caps= freq= chan=
+ for ssid; do
+ i=0
+ while [ ${i} -le ${APS} ] ; do
+ eval e=\$SSID_${i}
+ if [ "${e}" = "${ssid}" ] ; then
+ SSID=${e}
+ eval mac=\$MAC_${i}
+ eval caps=\$CAPS_${i}
+ eval freq=\$FREQ_${i}
+ eval chan=\$CHAN_${i}
+ iwconfig_associate "${mac}" \
+ "${chan}" "${caps}" && return 0
+ fi
+ : $(( i += 1 ))
+ done
+ done
+
+ return 1
+}
+
+iwconfig_connect_not_preferred()
+{
+ local ssid= i=0 mode= mac= caps= freq= chan= pref=
+
+ while [ ${i} -le ${APS} ] ; do
+ eval e=\$SSID_${i}
+ if [ -z "${e}" ] ; then
+ : $(( i += 1 ))
+ continue
+ fi
+
+ eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
+ pref=false
+ for ssid; do
+ if [ "${e}" = "${ssid}" ] ; then
+ pref=true
+ break
+ fi
+ done
+
+ if ! ${pref} ; then
+ SSID=${e}
+ eval mac=\$MAC_${i}
+ eval caps=\$CAPS_${i}
+ eval freq=\$FREQ_${i}
+ eval chan=\$CHAN_${i}
+ iwconfig_associate "${mac}" \
+ "${chan}" "${caps}" && return 0
+ fi
+ : $(( i += 1 ))
+ done
+
+ return 1
+}
+
+iwconfig_defaults()
+{
+ # Set some defaults
+ #ifconfig "${iface}" txpower 100 2>/dev/null
+ ifconfig "${IFACE}" bssid -
+ ifconfig "${IFACE}" ssid -
+ ifconfig "${IFACE}" wepkey 1:- wepkey 2:- wepkey 3:- wepkey 4:-
+ ifconfig "${IFACE}" authmode open
+ ifconfig "${IFACE}" -mediaopt adhoc
+ ifconfig "${IFACE}" -mediaopt hostap
+}
+
+iwconfig_configure()
+{
+ local x= APS=-1
+ eval SSID=\$ssid_${IFVAR}
+
+ # Setup ad-hoc mode?
+ eval x=\$mode_${IFVAR}
+ x=${x:-managed}
+ case "${x}" in
+ ad-hoc|adhoc|hostap|master) iwconfig_setup_specific "${x}" ;;
+ esac
+
+ if [ "${x}" != "managed" -a "${x}" != "auto" -a "${x}" != "ad-hoc" -a "${x}" != "adhoc" -a ${x} != "master" ] ; then
+ eerror "Only managed, ad-hoc, master and auto modes are supported"
+ return 1
+ fi
+
+ # Has an SSID been forced?
+ if [ -n "${SSID}" ]; then
+ iwconfig_set_mode "${x}"
+ iwconfig_associate && return 0
+ [ "${SSID}" = "any" ] && iwconfig_force_preferred && return 0
+
+ eval SSID=\$adhoc_ssid_${IFVAR}
+ if [ -n "${SSID}" ]; then
+ iwconfig_setup_specific adhoc
+ return $?
+ fi
+ return 1
+ fi
+
+ # Are we forcing preferred only?
+ eval x=\$associate_order_${IFVAR}
+ [ -n "${x}" ] && associate_order=${x}
+ associate_order=${associate_order:-any}
+ if [ "${associate_order}" = "forcepreferredonly" ]; then
+ iwconfig_force_preferred && return 0
+ else
+ iwconfig_scan || return 1
+ iwconfig_connect_preferred && return 0
+ [ "${associate_order}" = "forcepreferred" ] || \
+ [ "${associate_order}" = "forceany" ] && \
+ iwconfig_force_preferred && return 0
+ [ "${associate_order}" = "any" ] || \
+ [ "${associate_order}" = "forceany" ] && \
+ iwconfig_connect_not_preferred && return 0
+ fi
+
+ e="associate with"
+ [ -z "${MAC_0}" ] && e="find"
+ [ "${preferred_aps}" = "force" ] || \
+ [ "${preferred_aps}" = "forceonly" ] && \
+ e="force"
+ e="Couldn't ${e} any access points on ${IFACE}"
+
+ eval SSID=\$adhoc_ssid_${IFVAR}
+ if [ -n "${SSID}" ]; then
+ ewarn "${e}"
+ iwconfig_setup_specific adhoc
+ return $?
+ fi
+
+ eerror "${e}"
+ return 1
+}
+
+iwconfig_pre_start()
+{
+ # We don't configure wireless if we're being called from
+ # the background
+ yesno ${IN_BACKGROUND} && return 0
+
+ service_set_value "SSID" ""
+ _exists || return 0
+
+ if ! _is_wireless ; then
+ veinfo "${IFACE} is not wireless"
+ return 0
+ fi
+
+ iwconfig_defaults
+ iwconfig_user_config
+
+ # Set the base metric to be 2000
+ metric=2000
+
+ einfo "Configuring wireless network for ${IFACE}"
+
+ if iwconfig_configure ; then
+ service_set_value "SSID" "${SSID}"
+ return 0
+ fi
+
+ eerror "Failed to configure wireless for ${IFACE}"
+ iwconfig_defaults
+ #iwconfig "${IFACE}" txpower 0 2>/dev/null
+ unset SSID SSIDVAR
+ _down
+ return 1
+}
+
+iwconfig_post_stop()
+{
+ yesno ${IN_BACKGROUND} && return 0
+ _is_wireless || return 0
+ iwconfig_defaults
+ #iwconfig "${IFACE}" txpower 0 2>/dev/null
+}
diff --git a/net/iwconfig.sh.Linux.in b/net/iwconfig.sh.Linux.in
new file mode 100644
index 0000000..293bc1f
--- /dev/null
+++ b/net/iwconfig.sh.Linux.in
@@ -0,0 +1,763 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars ssid mode associate_timeout sleep_scan"
+_config_vars="$_config_vars preferred_aps blacklist_aps"
+
+iwconfig_depend()
+{
+ program /sbin/iwconfig
+ after plug
+ before interface
+ provide wireless
+}
+
+iwconfig_get_wep_status()
+{
+ local mode= status="disabled"
+
+ # No easy way of doing this grep in bash regex :/
+ if LC_ALL=C iwconfig "${IFACE}" | \
+ grep -qE "^ +Encryption key:[*0-9,A-F]"; then
+ status="enabled"
+ mode=$(LC_ALL=C iwconfig "${IFACE}" | \
+ sed -n -e 's/^.*Security mode:\(.*[^ ]\).*/\1/p')
+ [ -n "${mode}" ] && mode=" - ${mode}"
+ fi
+
+ echo "(WEP ${status}${mode})"
+}
+
+_get_ssid()
+{
+ local i=5 ssid=
+
+ while [ ${i} -gt 0 ]; do
+ ssid=$(iwgetid --raw "${IFACE}")
+ if [ -n "${ssid}" ]; then
+ echo "${ssid}"
+ return 0
+ fi
+ sleep 1
+ : $(( i -= 1 ))
+ done
+
+ return 1
+}
+
+_get_ap_mac_address()
+{
+ local mac="$(iwgetid --raw --ap "${IFACE}")"
+ case "${mac}" in
+ "00:00:00:00:00:00") return 1;;
+ "44:44:44:44:44:44") return 1;;
+ "FF:00:00:00:00:00") return 1;;
+ "FF:FF:FF:FF:FF:FF") return 1;;
+ *) echo "${mac}";;
+ esac
+}
+
+iwconfig_get_mode()
+{
+ LC_ALL=C iwgetid --mode "${IFACE}" | \
+ sed -n -e 's/^.*Mode:\(.*\)/\1/p' | \
+ tr '[:upper:]' '[:lower:]'
+}
+
+iwconfig_set_mode()
+{
+ local mode="$1"
+ [ "${mode}" = "$(iwconfig_get_mode)" ] && return 0
+
+ # Devicescape stack requires the interface to be down
+ _down
+ iwconfig "${IFACE}" mode "${mode}" || return 1
+ _up
+}
+
+iwconfig_get_type()
+{
+ LC_ALL=C iwconfig "${IFACE}" | \
+ sed -n -e 's/^'"$1"' *\([^ ]* [^ ]*\).*/\1/p'
+}
+
+iwconfig_report()
+{
+ local mac= m="connected to"
+ local ssid="$(_get_ssid)"
+ local wep_status="$(iwconfig_get_wep_status)"
+ local channel="$(iwgetid --raw --channel "${iface}")"
+ [ -n "${channel}" ] && channel="on channel ${channel} "
+ local mode="$(iwconfig_get_mode)"
+ if [ "${mode}" = "master" ]; then
+ m="configured as"
+ else
+ mac="$(_get_ap_mac_address)"
+ [ -n "${mac}" ] && mac=" at ${mac}"
+ fi
+
+ eindent
+ einfo "${IFACE} ${m} SSID \"${SSID}\"${mac}"
+ einfo "in ${mode} mode ${channel}${wep_status}"
+ eoutdent
+}
+
+iwconfig_get_wep_key()
+{
+ local mac="$1" key=
+ [ -n "${mac}" ] && mac="$(echo "${mac}" | sed -e 's/://g')"
+ eval key=\$mac_key_${mac}
+ [ -z "${key}" ] && eval key=\$key_${SSIDVAR}
+ if [ -z "${key}" ]; then
+ echo "off"
+ else
+ set -- ${key}
+ local x= e=false
+ for x; do
+ if [ "${x}" = "enc" ]; then
+ e=true
+ break
+ fi
+ done
+ ${e} || key="${key} enc open"
+ echo "${key}"
+ fi
+}
+
+iwconfig_user_config()
+{
+ local conf= var=${SSIDVAR} config=
+ [ -z "${var}" ] && var=${IFVAR}
+
+ config="$(_get_array "iwconfig_${var}")"
+ local IFS="$__IFS"
+ for conf in ${config}; do
+ unset IFS
+ if ! eval iwconfig "${IFACE}" "${conf}"; then
+ ewarn "${IFACE} does not support the following configuration commands"
+ ewarn " ${conf}"
+ fi
+ done
+ unset IFS
+
+ config="$(_get_array "iwpriv_${var}")"
+ local IFS="$__IFS"
+ for conf in ${config}; do
+ unset IFS
+ if ! eval iwpriv "${IFACE}" "${conf}"; then
+ ewarn "${IFACE} does not support the following private ioctls"
+ ewarn " ${conf}"
+ fi
+ done
+}
+
+iwconfig_setup_specific()
+{
+ local mode="$1" channel=
+ if [ -z "${SSID}" ]; then
+ eerror "${IFACE} requires an SSID to be set to operate in ${mode} mode"
+ eerror "adjust the ssid_${IFVAR} setting in /etc/conf.d/net"
+ return 1
+ fi
+ SSIDVAR=$(shell_var "${SSID}")
+ local key=$(iwconfig_get_wep_key)
+
+ iwconfig_set_mode "${mode}"
+
+ # Now set the key
+ if ! eval iwconfig "${IFACE}" key "${key}"; then
+ if [ "${key}" != "off" ]; then
+ ewarn "${IFACE} does not support setting keys"
+ ewarn "or the parameter \"mac_key_${SSIDVAR}\" or \"key_${SSIDVAR}\" is incorrect"
+ fi
+ fi
+
+ # Then set the SSID
+ if ! iwconfig "${IFACE}" essid "${SSID}"; then
+ eerror "${IFACE} does not support setting SSID to \"${SSID}\""
+ return 1
+ fi
+
+ eval channel=\$channel_${SSIDVAR}
+ [ -z "${channel}" ] && eval channel=\$channel_${IFVAR}
+ # We default the channel to 3
+ if ! iwconfig "${IFACE}" channel "${channel:-3}"; then
+ ewarn "${IFACE} does not support setting the channel to \"${channel:-3}\""
+ return 1
+ fi
+
+ # Finally apply the user Config
+ iwconfig_user_config
+
+ iwconfig_report
+ return 0
+}
+
+iwconfig_wait_for_association()
+{
+ local timeout= i=0
+ eval timeout=\$associate_timeout_${IFVAR}
+ timeout=${timeout:-10}
+
+ [ ${timeout} -eq 0 ] \
+ && vewarn "WARNING: infinite timeout set for association on ${IFACE}"
+
+ while true; do
+ # Use sysfs if we can
+ if [ -e /sys/class/net/"${IFACE}"/carrier ]; then
+ if [ "$(cat /sys/class/net/"${IFACE}"/carrier)" = "1" ]; then
+ # Double check we have an ssid and a non-zero
+ # mac address. This is mainly for buggy
+ # prism54 drivers that always set their
+ # carrier on or buggy madwifi drivers that
+ # sometimes have carrier on and ssid set
+ # without being associated. :/
+ [ -n "$(iwgetid --raw "${IFACE}")" ] && [ "$(iwgetid --ap --raw "${IFACE}")" != "00:00:00:00:00:00" ] && return 0
+ fi
+ else
+ local atest=
+ eval atest=\$associate_test_${IFVAR}
+ atest=${atest:-mac}
+ if [ "${atest}" = "mac" -o "${atest}" = "all" ]; then
+ [ -n "$(_get_ap_mac_address)" ] && return 0
+ fi
+ if [ "${atest}" = "quality" -o "${atest}" = "all" ]; then
+ [ "$(sed -n -e 's/^.*'"${IFACE}"': *[0-9]* *\([0-9]*\).*/\1/p' \
+ /proc/net/wireless)" != "0" ] && return 0
+ fi
+ fi
+
+ sleep 1
+ [ ${timeout} -eq 0 ] && continue
+ : $(( i += 1 ))
+ [ ${i} -ge ${timeout} ] && return 1
+ done
+ return 1
+}
+
+iwconfig_associate()
+{
+ local mode="${1:-managed}" mac="$2" wep_required="$3"
+ local freq="$4" chan="$5"
+ local w="(WEP Disabled)" key=
+
+ iwconfig_set_mode "${mode}"
+
+ if [ "${SSID}" = "any" ]; then
+ iwconfig "${IFACE}" ap any 2>/dev/null
+ unset SSIDVAR
+ else
+ SSIDVAR=$(shell_var "${SSID}")
+ key="$(iwconfig_get_wep_key "${mac}")"
+ if [ "${wep_required}" = "on" -a "${key}" = "off" ]; then
+ ewarn "WEP key is not set for \"${SSID}\""
+ return 1
+ fi
+ if [ "${wep_required}" = "off" -a "${key}" != "off" ]; then
+ key="off"
+ ewarn "\"${SSID}\" is not WEP enabled"
+ fi
+
+ if ! eval iwconfig "${IFACE}" key "${key}"; then
+ if [ "${key}" != "off" ]; then
+ ewarn "${IFACE} does not support setting keys"
+ ewarn "or the parameter \"mac_key_${SSIDVAR}\" or \"key_${SSIDVAR}\" is incorrect"
+ return 1
+ fi
+ fi
+ [ "${key}" != "off" ] && w="$(iwconfig_get_wep_status "${iface}")"
+ fi
+
+ if ! iwconfig "${IFACE}" essid "${SSID}"; then
+ if [ "${SSID}" != "any" ]; then
+ ewarn "${IFACE} does not support setting SSID to \"${SSID}\""
+ fi
+ fi
+
+ # Only use channel or frequency
+ if [ -n "${chan}" ]; then
+ iwconfig "${IFACE}" channel "${chan}"
+ elif [ -n "${freq}" ]; then
+ iwconfig "${IFACE}" freq "${freq}"
+ fi
+ [ -n "${mac}" ] && iwconfig "${IFACE}" ap "${mac}"
+
+ # Finally apply the user Config
+ iwconfig_user_config
+
+ ebegin "Connecting to \"${SSID}\" in ${mode} mode ${w}"
+
+ if [ "${SSID}" != "any" ] && type preassociate >/dev/null 2>&1; then
+ veinfo "Running preassociate function"
+ veindent
+ ( preassociate )
+ local e=$?
+ veoutdent
+ if [ ${e} -eq 0 ]; then
+ veend 1 "preassociate \"${SSID}\" on ${IFACE} failed"
+ return 1
+ fi
+ fi
+
+ if ! iwconfig_wait_for_association; then
+ eend 1
+ return 1
+ fi
+ eend 0
+
+ if [ "${SSID}" = "any" ]; then
+ SSID="$(_get_ssid)"
+ iwconfig_associate
+ return $?
+ fi
+
+ iwconfig_report
+
+ if type postassociate >/dev/null 2>&1; then
+ veinfo "Running postassociate function"
+ veindent
+ ( postassociate )
+ veoutdent
+ fi
+
+ return 0
+}
+
+iwconfig_scan()
+{
+ local x= i=0 scan=
+ einfo "Scanning for access points"
+ eindent
+
+ # Sleep if required
+ eval x=\$sleep_scan_${IFVAR}
+ [ -n "${x}" ] && sleep "${x}"
+
+ while [ ${i} -lt 3 ]; do
+ local scan="${scan}${scan:+ }$(LC_ALL=C iwlist "${IFACE}" scan 2>/dev/null | sed -e "s/'/'\\\\''/g" -e "s/$/'/g" -e "s/^/'/g")"
+ # If this is the first pass and txpower as off and we have no
+ # results then we need to wait for at least 2 seconds whilst
+ # the interface does an initial scan.
+ if [ "${i}" = "0" -a "${txpowerwasoff}" = "0" ]; then
+ case "${scan}" in
+ "'${IFACE} "*"No scan results"*)
+ sleep 2
+ txpowerwasoff=1
+ continue
+ ;;
+ esac
+ fi
+ : $(( i += 1 ))
+ done
+
+ if [ -z "${scan}" ]; then
+ ewarn "${iface} does not support scanning"
+ eoutdent
+ eval x=\$adhoc_ssid_${IFVAR}
+ [ -n "${x}" ] && return 0
+ if [ -n "${preferred_aps}" ]; then
+ [ "${associate_order}" = "forcepreferred" ] || \
+ [ "${associate_order}" = "forcepreferredonly" ] && return 0
+ fi
+ eerror "You either need to set a preferred_aps list in /etc/conf.d/wireless"
+ eerror " preferred_aps=\"SSID1 SSID2\""
+ eerror " and set associate_order_${IFVAR}=\"forcepreferred\""
+ eerror " or set associate_order_${IFVAR}=\"forcepreferredonly\""
+ eerror "or hardcode the SSID to \"any\" and let the driver find an Access Point"
+ eerror " ssid_${IFVAR}=\"any\""
+ eerror "or configure defaulting to Ad-Hoc when Managed fails"
+ eerror " adhoc_ssid_${IFVAR}=\"WLAN\""
+ eerror "or hardcode the SSID against the interface (not recommended)"
+ eerror " ssid_${IFVAR}=\"SSID\""
+ return 1
+ fi
+
+ APS=-1
+ eval set -- ${scan}
+ for line; do
+ case "${line}" in
+ *Address:*)
+ : $(( APS += 1 ))
+ eval MAC_${APS}="\""$(echo "${line#*: }" | tr '[:lower:]' '[:upper:]')"\""
+ eval QUALITY_${APS}=0
+ ;;
+ *ESSID:*)
+ x=${line#*\"}
+ x=${x%*\"}
+ eval SSID_${APS}=\$x
+ ;;
+ *Mode:*)
+ x="$(echo "${line#*:}" | tr '[:upper:]' '[:lower:]')"
+ if [ "${x}" = "master" ]; then
+ eval MODE_${APS}=managed
+ else
+ eval MODE_${APS}=\$x
+ fi
+ ;;
+ *'Encryption key:'*)
+ x=${line#*:}
+ eval ENC_${APS}=\$x
+ ;;
+ #*Frequency:*)
+ # freq[i]="${line#*:}"
+ # x="${freq[i]#* }"
+ # freq[i]="${freq[i]%% *}${x:0:1}"
+ # ;;
+ *Channel:*)
+ x=${line#*:}
+ x=${x%% *}
+ eval CHAN_${APS}=\$x
+ ;;
+ *Quality*)
+ x=${line#*:}
+ x=${x%/*}
+ x="$(echo "${x}" | sed -e 's/[^[:digit:]]//g')"
+ x=${x:-0}
+ eval QUALITY_${APS}=\$x
+ ;;
+ esac
+ done
+
+ if [ -z "${MAC_0}" ]; then
+ ewarn "no access points found"
+ eoutdent
+ return 1
+ fi
+
+ # Sort based on quality
+ local i=0 k=1 a= b= x= t=
+ while [ ${i} -lt ${APS} ]; do
+ : $(( k = i + 1 ))
+ while [ ${k} -le ${APS} ]; do
+ eval a=\$QUALITY_${i}
+ [ -z "${a}" ] && break
+ eval b=\$QUALITY_${k}
+ if [ -n "${b}" -a "${a}" -lt "${b}" ]; then
+ for x in MAC SSID MODE CHAN QUALITY ENC; do
+ eval t=\$${x}_${i}
+ eval ${x}_${i}=\$${x}_${k}
+ eval ${x}_${k}=\$t
+ done
+ fi
+ : $(( k += 1 ))
+ done
+ : $(( i += 1 ))
+ done
+
+ # Strip any duplicates
+ local i=0 k=1 a= b=
+ while [ ${i} -lt ${APS} ]; do
+ : $(( k = i + 1 ))
+ while [ ${k} -le ${APS} ]; do
+ eval a=\$MAC_${i}
+ eval b=\$MAC_${k}
+ if [ "${a}" = "${b}" ]; then
+ eval a=\$QUALITY_${i}
+ eval b=\$QUALITY_${k}
+ local u=${k}
+ # We need to split this into two tests, otherwise bash errors
+ [ -n "${a}" -a -n "${b}" ] && [ "${a}" -lt "${b}" ] && u=${i}
+ unset MAC_${u} SSID_${u} MODE_${u} CHAN_${u} QUALITY_${u} ENC_${u}
+ fi
+ : $(( k += 1 ))
+ done
+ : $(( i += 1 ))
+ done
+
+ local i=0 e= m= s=
+
+ while [ ${i} -le ${APS} ]; do
+ eval x=\$MAC_${i}
+ if [ -z "${x}" ]; then
+ : $(( i += 1 ))
+ continue
+ fi
+
+ eval m=\$MODE_${i}
+ eval s=\$SSID_${i}
+ eval q=\$QUALITY_${i}
+ eval e=\$ENC_${i}
+ if [ -n "${e}" -a "${e}" != "off" ]; then
+ e=", encrypted"
+ else
+ e=""
+ fi
+ if [ -z "${s}" ]; then
+ einfo "Found ${x}, ${m}${e}"
+ else
+ einfo "Found \"${s}\" at ${x}, ${m}${e}"
+ fi
+
+ x="$(echo "${x}" | sed -e 's/://g')"
+ eval x=\$mac_ssid_${x}
+ if [ -n "${x}" ]; then
+ eval SSID_${i}=\$x
+ s=${x}
+ eindent
+ einfo "mapping to \"${x}\""
+ eoutdent
+ fi
+
+ eval set -- $(_flatten_array "blacklist_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps")
+ for x; do
+ if [ "${x}" = "${s}" ]; then
+ ewarn "${s} has been blacklisted - not connecting"
+ unset SSID_${i} MAC_${i} ${MODE}_${i} CHAN_${i} QUALITY_${i} ENC_${i}
+ fi
+ done
+ : $(( i += 1 ))
+ done
+ eoutdent
+}
+
+iwconfig_force_preferred()
+{
+ eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
+ [ $# = 0 ] && return 1
+
+ ewarn "Trying to force preferred in case they are hidden"
+ for ssid; do
+ local found_AP=false i=0 e=
+ while [ ${i} -le ${APS} ]; do
+ eval e=\$SSID_${i}
+ if [ "${e}" = "${ssid}" ]; then
+ found_AP=true
+ break
+ fi
+ : $(( i += 1 ))
+ done
+ if ! ${found_AP}; then
+ SSID=${ssid}
+ iwconfig_associate && return 0
+ fi
+ done
+
+ ewarn "Failed to associate with any preferred access points on ${IFACE}"
+ return 1
+}
+
+iwconfig_connect_preferred()
+{
+ local ssid= i= mode= mac= enc= freq= chan=
+ eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
+
+ for ssid; do
+ unset IFS
+ i=0
+ while [ ${i} -le ${APS} ]; do
+ eval e=\$SSID_${i}
+ if [ "${e}" = "${ssid}" ]; then
+ SSID=${e}
+ eval mode=\$MODE_${i}
+ eval mac=\$MAC_${i}
+ eval enc=\$ENC_${i}
+ eval freq=\$FREQ_${i}
+ eval chan=\$CHAN_${i}
+ iwconfig_associate "${mode}" "${mac}" "${enc}" "${freq}" \
+ "${chan}" && return 0
+ fi
+ : $(( i += 1 ))
+ done
+ done
+
+ return 1
+}
+
+iwconfig_connect_not_preferred()
+{
+ local ssid= i=0 mode= mac= enc= freq= chan= pref=false
+
+ while [ ${i} -le ${APS} ]; do
+ eval e=\$SSID_${i}
+ if [ -n "${e}" ]; then
+ eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
+ [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
+ for ssid; do
+ if [ "${e}" = "${ssid}" ]; then
+ pref=true
+ break
+ fi
+ done
+
+ if ! ${pref}; then
+ SSID=${e}
+ eval mode=\$MODE_${i}
+ eval mac=\$MAC_${i}
+ eval enc=\$ENC_${i}
+ eval freq=\$FREQ_${i}
+ eval chan=\$CHAN_${i}
+ iwconfig_associate "${mode}" "${mac}" "${enc}" "${freq}" \
+ "${chan}" && return 0
+ fi
+ fi
+ : $(( i += 1 ))
+ done
+
+ return 1
+}
+
+iwconfig_defaults()
+{
+ # Turn on the radio
+ iwconfig "${IFACE}" txpower on 2>/dev/null
+
+ # Release the AP forced
+ # Must do ap and then ssid otherwise scanning borks
+ iwconfig "${IFACE}" ap off 2>/dev/null
+ iwconfig "${IFACE}" essid off 2>/dev/null
+}
+
+iwconfig_configure()
+{
+ local x= APS=-1
+ eval SSID=\$ssid_${IFVAR}
+
+ # Support old variable
+ [ -z "${SSID}" ] && eval SSID=\$essid_${IFVAR}
+
+ # Setup ad-hoc mode?
+ eval x=\$mode_${IFVAR}
+ x=${x:-managed}
+ if [ "${x}" = "ad-hoc" -o "${x}" = "master" ]; then
+ iwconfig_setup_specific "${x}"
+ return $?
+ fi
+
+ if [ "${x}" != "managed" -a "${x}" != "auto" ]; then
+ eerror "Only managed, ad-hoc, master and auto modes are supported"
+ return 1
+ fi
+
+ # Has an SSID been forced?
+ if [ -n "${SSID}" ]; then
+ iwconfig_set_mode "${x}"
+ iwconfig_associate && return 0
+ [ "${SSID}" = "any" ] && iwconfig_force_preferred && return 0
+
+ eval SSID=\$adhoc_ssid_${IFVAR}
+ if [ -n "${SSID}" ]; then
+ iwconfig_setup_specific ad-hoc
+ return $?
+ fi
+ return 1
+ fi
+
+ eval x=\$preferred_aps_${IFVAR}
+ [ -n "${x}" ] && preferred_aps=${x}
+
+ eval x=\$blacklist_aps_${IFVAR}
+ [ -n "${x}" ] && blacklist_aps=${x}
+
+ eval x=\$associate_order_${IFVAR}
+ [ -n "${x}" ] && associate_order=${x}
+ associate_order=${associate_order:-any}
+
+ if [ "${associate_order}" = "forcepreferredonly" ]; then
+ iwconfig_force_preferred && return 0
+ else
+ iwconfig_scan || return 1
+ iwconfig_connect_preferred && return 0
+ [ "${associate_order}" = "forcepreferred" ] || \
+ [ "${associate_order}" = "forceany" ] && \
+ iwconfig_force_preferred && return 0
+ [ "${associate_order}" = "any" ] || \
+ [ "${associate_order}" = "forceany" ] && \
+ iwconfig_connect_not_preferred && return 0
+ fi
+
+ e="associate with"
+ [ -z "${MAC_0}" ] && e="find"
+ [ "${preferred_aps}" = "force" ] || \
+ [ "${preferred_aps}" = "forceonly" ] && \
+ e="force"
+ e="Couldn't ${e} any access points on ${IFACE}"
+
+ eval SSID=\$adhoc_ssid_${IFVAR}
+ if [ -n "${SSID}" ]; then
+ ewarn "${e}"
+ iwconfig_setup_specific ad-hoc
+ return $?
+ fi
+
+ eerror "${e}"
+ return 1
+}
+
+iwconfig_pre_start()
+{
+ # We don't configure wireless if we're being called from
+ # the background
+ yesno ${IN_BACKGROUND} && return 0
+
+ service_set_value "SSID" ""
+ _exists || return 0
+
+ if ! _is_wireless; then
+ veinfo "Wireless extensions not found for ${IFACE}"
+ return 0
+ fi
+
+ # Warn about old file - we want to punt it really
+ if [ -e /etc/conf.d/wireless ]; then
+ ewarn "/etc/conf.d/wireless is deprecated"
+ ewarn "Please put all settings into /etc/conf.d/net"
+ . /etc/conf.d/wireless
+ fi
+
+ # Store the fact that tx-power was off so we default to a longer
+ # wait if our scan returns nothing
+ LC_ALL=C iwconfig "${IFACE}" | sed -e '1d' | grep -q "Tx-Power=off"
+ local txpowerwasoff=$?
+
+ iwconfig_defaults
+ iwconfig_user_config
+
+ # Set the base metric to be 2000
+ metric=2000
+
+ # Check for rf_kill - only ipw supports this at present, but other
+ # cards may in the future.
+ if [ -e /sys/class/net/"${IFACE}"/device/rf_kill ]; then
+ if [ $(cat /sys/class/net/"${IFACE}"/device/rf_kill) != "0" ]; then
+ eerror "Wireless radio has been killed for interface ${IFACE}"
+ return 1
+ fi
+ fi
+
+ einfo "Configuring wireless network for ${IFACE}"
+
+ # Are we a proper IEEE device?
+ # Most devices reutrn IEEE 802.11b/g - but intel cards return IEEE
+ # in lower case and RA cards return RAPCI or similar
+ # which really sucks :(
+ # For the time being, we will test prism54 not loading firmware
+ # which reports NOT READY!
+ x="$(iwconfig_get_type)"
+ if [ "${x}" = "NOT READY!" ]; then
+ eerror "Looks like there was a problem loading the firmware for ${IFACE}"
+ return 1
+ fi
+
+ if iwconfig_configure; then
+ service_set_value "SSID" "${SSID}"
+ return 0
+ fi
+
+ eerror "Failed to configure wireless for ${IFACE}"
+ iwconfig_defaults
+ iwconfig "${IFACE}" txpower off 2>/dev/null
+ unset SSID SSIDVAR
+ _down
+ return 1
+}
+
+iwconfig_post_stop()
+{
+ yesno ${IN_BACKGROUND} && return 0
+ _exists || return 0
+ iwconfig_defaults
+ iwconfig "${IFACE}" txpower off 2>/dev/null
+}
diff --git a/net/macchanger.sh b/net/macchanger.sh
new file mode 100644
index 0000000..4e535ec
--- /dev/null
+++ b/net/macchanger.sh
@@ -0,0 +1,92 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+macchanger_depend()
+{
+ before macnet
+ # no program 'macchanger', as we have partial functionality without it
+}
+
+_config_vars="$_config_vars mac"
+
+macchanger_pre_start()
+{
+ # We don't change MAC addresses from background
+ yesno ${IN_BACKGROUND} && return 0
+
+ local mac= opts=
+
+ eval mac=\$mac_${IFVAR}
+ [ -z "${mac}" ] && return 0
+
+ _exists true || return 1
+
+ ebegin "Changing MAC address of ${IFACE}"
+
+ # The interface needs to be up for macchanger to work most of the time
+ _down
+
+ mac=$(echo "${mac}" | tr '[:upper:]' '[:lower:]')
+ local hex="[0-9a-f][0-9a-f]"
+ case "${mac}" in
+ # specific mac-addr
+ ${hex}:${hex}:${hex}:${hex}:${hex}:${hex})
+ # We don't need macchanger to change to a specific
+ # mac address
+ _set_mac_address "${mac}"
+ if eend "$?"; then
+ mac=$(_get_mac_address)
+ eindent
+ einfo "changed to ${mac}"
+ eoutdent
+ _up
+ return 0
+ fi
+ ;;
+
+ # increment MAC address, default macchanger behavior
+ increment) opts="${opts}";;
+
+ # randomize just the ending bytes
+ random-ending) opts="${opts} -e";;
+
+ # keep the same kind of physical layer (eg fibre, copper)
+ random-samekind) opts="${opts} -a";;
+
+ # randomize to any known vendor of any physical layer type
+ random-anykind) opts="${opts} -A";;
+
+ # fully random bytes
+ random-full|random) opts="${opts} -r";;
+
+ # default case is just to pass on all the options
+ *) opts="${opts} ${mac}";;
+ esac
+
+ if [ ! -x /sbin/macchanger ]; then
+ eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
+ return 1
+ fi
+
+ mac=$(/sbin/macchanger ${opts} "${IFACE}" \
+ | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )
+ _up
+
+ # Sometimes the interface needs to be up ....
+ if [ -z "${mac}" ]; then
+ mac=$(/sbin/macchanger ${opts} "${IFACE}" \
+ | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )
+ fi
+
+ if [ -z "${mac}" ]; then
+ eend 1 "Failed to set MAC address"
+ return 1
+ fi
+
+ eend 0
+ eindent
+ einfo "changed to" "${mac}"
+ eoutdent
+
+ return 0
+}
diff --git a/net/macnet.sh b/net/macnet.sh
new file mode 100644
index 0000000..1ec2ad7
--- /dev/null
+++ b/net/macnet.sh
@@ -0,0 +1,19 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+macnet_depend()
+{
+ before rename interface wireless
+ after macchanger
+}
+
+macnet_pre_start()
+{
+ local mac=$(_get_mac_address 2>/dev/null)
+ [ -z "${mac}" ] && return 0
+
+ vebegin "Configuring ${IFACE} for MAC address ${mac}"
+ mac=$(echo "${mac}" | sed -e 's/://g')
+ _configure_variables "${mac}"
+ veend 0
+}
diff --git a/net/macvlan.sh b/net/macvlan.sh
new file mode 100644
index 0000000..1b95f5c
--- /dev/null
+++ b/net/macvlan.sh
@@ -0,0 +1,53 @@
+# 2011-09-22 Stef Simoens <stef@bgs.org>
+# based on vlan.sh & tuntap.sh
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# All rights reserved. Released under the 2-clause BSD license.
+
+macvlan_depend()
+{
+ program ip
+ after interface
+ before dhcp macchanger
+}
+
+_is_macvlan()
+{
+ [ -n "$(RC_SVCNAME="net.${IFACE}"; export RC_SVCNAME ; service_get_value macvlan)" ]
+}
+
+macvlan_pre_start()
+{
+ # MAC-VLAN needs an existing interface to link to
+ local macvlan=
+ eval macvlan=\$macvlan_${IFVAR}
+ [ -z "${macvlan}" ] && return 0
+
+ case " ${MODULES} " in
+ *" ifconfig "*)
+ eerror "sys-apps/iproute2 is required to configure MACVLANs"
+ return 1 ;;
+ esac
+
+ # optional mode, default to "private"
+ local mode=
+ eval mode=\$mode_${IFVAR}
+ [ -z "${mode}" ] && mode="private"
+
+ ebegin "Creating MAC-VLAN ${IFACE} to ${macvlan}"
+ e="$(ip link add link "${macvlan}" name "${IFACE}" type macvlan mode "${mode}" 2>&1 1>/dev/null)"
+ if [ -n "${e}" ]; then
+ eend 1 "${e}"
+ else
+ eend 0 && _up && service_set_value macvlan "${macvlan}"
+ fi
+}
+
+
+macvlan_post_stop()
+{
+ _is_macvlan || return 0
+
+ ebegin "Removing MAC-VLAN ${IFACE}"
+ ip link delete "${IFACE}" type macvlan >/dev/null
+ eend $?
+}
diff --git a/net/netplugd.sh b/net/netplugd.sh
new file mode 100644
index 0000000..f43a5e6
--- /dev/null
+++ b/net/netplugd.sh
@@ -0,0 +1,96 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars plug_timeout"
+
+netplugd_depend()
+{
+ program start /sbin/netplugd
+ after macnet rename
+ before interface
+ provide plug
+
+ # Prefer ifplugd
+ before ifplugd
+}
+
+netplugd_pre_start()
+{
+ local pidfile="/var/run/netplugd-${IFACE}.pid" timeout=
+
+ # We don't start netplug if we're being called from the background
+ yesno ${IN_BACKGROUND} && return 0
+
+ _exists || return 0
+
+ # We need a valid MAC address
+ # It's a basic test to ensure it's not a virtual interface
+ if ! _get_mac_address >/dev/null 2>&1; then
+ vewarn "netplug only works on interfaces with a valid MAC address"
+ return 0
+ fi
+
+ # We don't work on bonded, bridges, tun/tap, vlan or wireless
+ for f in bond bridge tuntap vlan wireless; do
+ if type "_is_${f}" >/dev/null 2>&1; then
+ if _is_${f}; then
+ veinfo "netplug does not work with" "${f}"
+ return 0
+ fi
+ fi
+ done
+
+ ebegin "Starting netplug on" "${IFACE}"
+
+ # Mark the us as inactive so netplug can restart us
+ mark_service_inactive
+
+ # Start netplug
+ start-stop-daemon --start --exec /sbin/netplugd \
+ --pidfile "${pidfile}" \
+ -- -i "${IFACE}" -P -p "${pidfile}" -c /dev/null
+ eend "$?" || return 1
+
+ eindent
+
+ # IFACE-specific, then global, then default
+ eval timeout=\$plug_timeout_${IFVAR}
+ [ -z "${timeout}" ] && timeout=$plug_timeout
+ [ -z "${timeout}" ] && timeout=-1
+ if [ ${timeout} -eq 0 ]; then
+ ewarn "WARNING: infinite timeout set for ${IFACE} to come up"
+ elif [ ${timeout} -lt 0 ]; then
+ einfo "Backgrounding ..."
+ exit 1
+ fi
+
+ veinfo "Waiting for ${IFACE} to be marked as started"
+
+ local i=0
+ while true; do
+ if service_started; then
+ _show_address
+ exit 0
+ fi
+ sleep 1
+ [ ${timeout} -eq 0 ] && continue
+ : $(( i += 1 ))
+ [ ${i} -ge ${timeout} ] && break
+ done
+
+ eend 1 "Failed to configure ${IFACE} in the background"
+ exit 1
+}
+
+netplugd_stop()
+{
+ yesno ${IN_BACKGROUND} && return 0
+
+ local pidfile="/var/run/netplugd-${IFACE}.pid"
+ [ ! -e "${pidfile}" ] && return 0
+
+ ebegin "Stopping netplug on" "${IFACE}"
+ start-stop-daemon --stop --quiet --exec /sbin/netplugd \
+ --pidfile "${pidfile}"
+ eend $?
+}
diff --git a/net/pppd.sh b/net/pppd.sh
new file mode 100644
index 0000000..97bd3ee
--- /dev/null
+++ b/net/pppd.sh
@@ -0,0 +1,243 @@
+# Copyright (c) 2005-2007 Gentoo Foundation
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+pppd_depend()
+{
+ program /usr/sbin/pppd
+ after interface
+ before dhcp
+ provide ppp
+}
+
+is_ppp()
+{
+ [ -e /var/run/ppp-"${IFACE}".pid ]
+}
+
+requote()
+{
+ printf "'%s' " "$@"
+}
+
+pppd_pre_start()
+{
+ # Interface has to be called ppp
+ [ "${IFACE%%[0-9]*}" = "ppp" ] || return 0
+
+ # Set our base metric
+ metric=4000
+
+ if yesno ${IN_BACKGROUND}; then
+ local config=
+ eval config=\$config_${IFVAR}
+ # If no config for ppp then don't default to DHCP
+ if [ -z "${config}" ]; then
+ eval config_${IFVAR}=null
+ fi
+ return 0
+ fi
+
+ local link= i= unit="${IFACE#ppp}" opts=
+
+ # PPP requires a link to communicate over - normally a serial port
+ # PPPoE communicates over Ethernet
+ # PPPoA communicates over ATM
+ # In all cases, the link needs to be available before we start PPP
+ eval link=\$link_${IFVAR}
+ [ -n "${link}" ] || return 0
+
+ case "${link}" in
+ /*)
+ if [ ! -e "${link}" ]; then
+ eerror "${link} does not exist"
+ eerror "Please verify hardware or kernel module (driver)"
+ return 1
+ fi
+ ;;
+ esac
+
+ if [ -z "${unit}" ]; then
+ eerror "PPP requires a unit - use net.ppp[0-9] instead of net.ppp"
+ return 1
+ fi
+
+ # We need to flatten the useless array
+ set -- $(_get_array "pppd_${IFVAR}")
+ opts="$@"
+
+ local mtu= hasmtu=false hasmru=false hasmaxfail=false haspersist=false
+ local hasupdetach=false hasdefaultmetric=false
+ for i in ${opts}; do
+ case "${i}" in
+ unit|nodetach|linkname)
+ eerror "The option \"${i}\" is not allowed in pppd_${IFVAR}"
+ return 1
+ ;;
+ defaultmetric) hasdefaultmetric=true;;
+ mtu) hasmtu=true;;
+ mru) hasmru=true;;
+ maxfail) hasmaxfail=true;;
+ persist) haspersist=true;;
+ updetach) hasupdetach=true;;
+ esac
+ done
+
+ # Might be set in conf.d/net
+ local username= password= passwordset=
+ eval username=\$username_${IFVAR}
+ eval password=\$password_${IFVAR}
+ eval passwordset=\$\{password_${IFVAR}-x\}
+ if [ -n "${username}" ] \
+ && [ -n "${password}" -o -z "${passwordset}" ]; then
+ opts="plugin passwordfd.so ${opts} passwordfd 0"
+ fi
+
+ if ! ${hasdefaultmetric}; then
+ local m=
+ eval m=\$metric_${IFVAR}
+ [ -z "${m}" ] && : $(( m = metric + $(_ifindex) ))
+ opts="${opts} defaultmetric ${m}"
+ fi
+ if [ -n "${mtu}" ]; then
+ ${hasmtu} || opts="${opts} mtu ${mtu}"
+ ${hasmru} || opts="${opts} mru ${mtu}"
+ fi
+ ${hasmaxfail} || opts="${opts} maxfail 0"
+ ${haspersist} || opts="${opts} persist"
+
+ # Set linkname because we need /var/run/ppp-${linkname}.pid
+ # This pidfile has the advantage of being there,
+ # even if ${IFACE} interface was never started
+ opts="linkname ${IFACE} ${opts}"
+
+ # Setup auth info
+ if [ -n "${username}" ]; then
+ opts="user '${username}' remotename ${IFACE} ${opts}"
+ fi
+
+ # Load a custom interface configuration file if it exists
+ [ -f "/etc/ppp/options.${IFACE}" ] \
+ && opts="${opts} file '/etc/ppp/options.${IFACE}'"
+
+ # Set unit
+ opts="unit ${unit} ${opts}"
+
+ # Setup connect script
+ local chatprog="/usr/sbin/chat -e -E -v" phone=
+ eval phone=\$phone_number_${IFVAR}
+ set -- ${phone}
+ [ -n "$1" ] && chatprog="${chatprog} -T '$1'"
+ [ -n "$2" ] && chatprog="${chatprog} -U '$2'"
+ # We need to flatten the useless array
+ set -- $(_get_array "chat_${IFVAR}")
+ if [ $# != 0 ]; then
+ opts="${opts} connect '$(echo ${chatprog} $@ | sed -e "s:':'\\\\'':g")'"
+ fi
+
+ # Add plugins
+ local haspppoa=false haspppoe=false plugins="$(_get_array "plugins_${IFVAR}")"
+ local IFS="$__IFS"
+ for i in ${plugins}; do
+ unset IFS
+ set -- ${i}
+ case "$1" in
+ passwordfd) continue;;
+ pppoa) shift; set -- "pppoatm" "$@";;
+ pppoe) shift; set -- "rp-pppoe" "$@";;
+ capi) shift; set -- "capiplugin" "$@";;
+ esac
+ case "$1" in
+ rp-pppoe) haspppoe=true;;
+ pppoatm) haspppoa=true;;
+ esac
+ if [ "$1" = "rp-pppoe" ] || [ "$1" = "pppoatm" -a "${link}" != "/dev/null" ]; then
+ opts="${opts} connect true"
+ set -- "$@" "${link}"
+ fi
+ opts="plugin $1.so ${opts}"
+ shift
+ opts="${opts} $@"
+ done
+ unset IFS
+
+ #Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi)
+ local insert_link_in_opts=1
+ if ${haspppoe}; then
+ if [ ! -e /proc/net/pppoe ]; then
+ # Load the PPPoE kernel module
+ if ! modprobe pppoe; then
+ eerror "kernel does not support PPPoE"
+ return 1
+ fi
+ fi
+
+ # Ensure that the link exists and is up
+ ( IFACE="${link}"; _exists true && _up ) || return 1
+ insert_link_in_opts=0
+ fi
+
+ if ${haspppoa}; then
+ if [ ! -d /proc/net/atm ]; then
+ # Load the PPPoA kernel module
+ if ! modprobe pppoatm; then
+ eerror "kernel does not support PPPoATM"
+ return 1
+ fi
+ fi
+
+ if [ "${link}" != "/dev/null" ]; then
+ insert_link_in_opts=0
+ else
+ ewarn "WARNING: An [itf.]vpi.vci ATM address was expected in link_${IFVAR}"
+ fi
+
+ fi
+ [ "${insert_link_in_opts}" = "0" ] || opts="${link} ${opts}"
+
+ ebegin "Starting pppd in ${IFACE}"
+ mark_service_inactive
+ if [ -n "${username}" ] \
+ && [ -n "${password}" -o -z "${passwordset}" ]; then
+ printf "%s" "${password}" | \
+ eval start-stop-daemon --start --exec /usr/sbin/pppd \
+ --pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null
+ else
+ eval start-stop-daemon --start --exec /usr/sbin/pppd \
+ --pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null
+ fi
+
+ if ! eend $? "Failed to start PPP"; then
+ mark_service_stopped
+ return 1
+ fi
+
+ if ${hasupdetach}; then
+ _show_address
+ else
+ einfo "Backgrounding ..."
+ fi
+
+ # pppd will re-call us when we bring the interface up
+ exit 0
+}
+
+# Dummy function for users that still have config_ppp0="ppp"
+pppd_start()
+{
+ return 0
+}
+
+pppd_stop()
+{
+ yesno ${IN_BACKGROUND} && return 0
+ local pidfile="/var/run/ppp-${IFACE}.pid"
+
+ [ ! -s "${pidfile}" ] && return 0
+
+ # Give pppd at least 30 seconds do die, #147490
+ einfo "Stopping pppd on ${IFACE}"
+ start-stop-daemon --stop --quiet --exec /usr/sbin/pppd \
+ --pidfile "${pidfile}" --retry 30
+ eend $?
+}
diff --git a/net/pump.sh b/net/pump.sh
new file mode 100644
index 0000000..ddd454c
--- /dev/null
+++ b/net/pump.sh
@@ -0,0 +1,59 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+pump_depend()
+{
+ program /sbin/pump
+ after interface
+ provide dhcp
+}
+
+_config_vars="$_config_vars dhcp pump"
+
+pump_start()
+{
+ local args= opt= opts=
+
+ # Get our options
+ eval opts=\$dhcp_${IFVAR}
+ [ -z "${opts}" ] && opts=${dhcp}
+
+ # Map some generic options to dhcpcd
+ for opt in ${opts}; do
+ case "${opt}" in
+ nodns) args="${args} --no-dns";;
+ nontp) args="${args} --no-ntp";;
+ nogateway) args="${args} --no-gateway";;
+ esac
+ done
+
+ # Add our route metric
+ [ "${metric:-0}" != "0" ] && args="${args} --route-metric ${metric}"
+
+ args="${args} --win-client-ident"
+ args="${args} --keep-up --interface ${IFACE}"
+
+ ebegin "Running pump"
+ eval pump "${args}"
+ eend $? || return 1
+
+ _show_address
+ return 0
+}
+
+pump_stop()
+{
+ # We check for a pump process first as querying for status
+ # causes pump to spawn a process
+ start-stop-daemon --quiet --test --stop --exec /sbin/pump || return 0
+
+ # Check that pump is running on the interface
+ if ! pump --status --interface "${IFACE}" >/dev/null 2>&1; then
+ return 0
+ fi
+
+ # Pump always releases the lease
+ ebegin "Stopping pump on ${IFACE}"
+ pump --release --interface "${IFACE}"
+ eend $? "Failed to stop pump"
+}
diff --git a/net/ssidnet.sh b/net/ssidnet.sh
new file mode 100644
index 0000000..b0eed56
--- /dev/null
+++ b/net/ssidnet.sh
@@ -0,0 +1,24 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+ssidnet_depend()
+{
+ before interface system
+ after wireless
+}
+
+ssidnet_pre_start()
+{
+ [ -z "${SSID}" -a -z "${SSIDVAR}" ] && return 0
+
+ local mac=$(_get_ap_mac_address | sed -e 's/://g') x=
+
+ vebegin "Configuring ${IFACE} for SSID ${SSID}"
+ _configure_variables "${mac}" "${SSIDVAR}"
+
+ # Backwards compat for old gateway var
+ eval x=\$gateway_${SSIDVAR}
+ [ -n "${x}" ] && gateway=${x}
+
+ veend 0
+}
diff --git a/net/system.sh b/net/system.sh
new file mode 100644
index 0000000..98017d5
--- /dev/null
+++ b/net/system.sh
@@ -0,0 +1,122 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars dns_servers dns_domain dns_search"
+_config_vars="$_config_vars dns_sortlist dns_options"
+_config_vars="$_config_vars ntp_servers nis_servers nis_domain"
+
+system_depend()
+{
+ after interface
+ before dhcp
+}
+
+_system_dns()
+{
+ local servers= domain= search= sortlist= options= x= imetric=
+
+ eval servers=\$dns_servers_${IFVAR}
+ [ -z "${servers}" ] && servers=${dns_servers}
+
+ eval domain=\$dns_domain_${IFVAR}
+ [ -z "${domain}" ] && domain=${dns_domain}
+
+ eval search=\$dns_search_${IFVAR}
+ [ -z "${search}" ] && search=${dns_search}
+
+ eval sortlist=\$dns_sortlist_${IFVAR}
+ [ -z "${sortlist}" ] && sortlist=${dns_sortlist}
+
+ eval options=\$dns_options_${IFVAR}
+ [ -z "${options}" ] && options=${dns_options}
+
+ [ -z "${servers}" -a -z "${domain}" -a -z "${search}" \
+ -a -z "${sortlist}" -a -z "${options}" ] && return 0
+
+ local buffer="# Generated by net-scripts for interface ${IFACE}\n"
+ [ -n "${domain}" ] && buffer="${buffer}domain ${domain}\n"
+ [ -n "${search}" ] && buffer="${buffer}search ${search}\n"
+
+ for x in ${servers}; do
+ buffer="${buffer}nameserver ${x}\n"
+ done
+
+ [ -n "${sortlist}" ] && buffer="${buffer}sortlist ${sortlist}\n"
+ [ -n "${options}" ] && buffer="${buffer}options ${options}\n"
+
+ # Support resolvconf if we have it.
+ if [ -x /sbin/resolvconf ]; then
+ x="-a ${IFACE}"
+ eval imetric=\${metric_${IFVAR}}
+ if [ -n "${imetric}" ]; then
+ x="${x} -m ${imetric}"
+ fi
+ printf "${buffer}" | resolvconf ${x}
+ else
+ printf "${buffer}" > /etc/resolv.conf
+ chmod 644 /etc/resolv.conf
+ fi
+}
+
+_system_ntp()
+{
+ local servers= buffer= x=
+
+ eval servers=\$ntp_servers_${IFVAR}
+ [ -z "${servers}" ] && servers=${ntp_servers}
+ [ -z "${servers}" ] && return 0
+
+ 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
+ buffer="${buffer}restrict ${x} nomodify notrap noquery\n"
+ buffer="${buffer}server ${x}\n"
+ done
+
+ printf "${buffer}" > /etc/ntp.conf
+ chmod 644 /etc/ntp.conf
+}
+
+_system_nis()
+{
+ local servers= domain= x= buffer=
+
+ eval servers=\$nis_servers_${IFVAR}
+ [ -z "${servers}" ] && servers=${nis_servers}
+
+ eval domain=\$nis_domain_${IFVAR}
+ [ -z "${domain}" ] && domain=${nis_domain}
+
+ [ -z "${servers}" -a -z "${domain}" ] && return 0
+
+ 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
+ buffer="${buffer}domain ${domain} server ${x}\n"
+ done
+ else
+ buffer="${buffer}domain ${domain} broadcast\n"
+ fi
+ else
+ for x in ${servers}; do
+ buffer="${buffer}ypserver ${x}\n"
+ done
+ fi
+
+ printf "${buffer}" > /etc/yp.conf
+ chmod 644 /etc/yp.conf
+}
+
+system_pre_start()
+{
+ _system_dns
+ _system_ntp
+ _system_nis
+
+ return 0
+}
diff --git a/net/tuntap.sh b/net/tuntap.sh
new file mode 100644
index 0000000..331fd83
--- /dev/null
+++ b/net/tuntap.sh
@@ -0,0 +1,102 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+tuntap_depend()
+{
+ before bridge interface macchanger
+ program ip openvpn tunctl
+}
+
+_config_vars="$_config_vars iproute2 openvpn tunctl"
+
+_is_tuntap()
+{
+ [ -n "$(RC_SVCNAME="net.${IFACE}"; export RC_SVCNAME ; service_get_value tuntap)" ]
+}
+
+tuntap_pre_start()
+{
+ local tuntap=
+ local rc=
+ eval tuntap=\$tuntap_${IFVAR}
+
+ [ -z "${tuntap}" ] && return 0
+
+ if [ ! -e /dev/net/tun ]; then
+ if ! modprobe tun; then
+ eerror "TUN/TAP support is not present in this kernel"
+ return 1
+ fi
+ vebegin "Waiting for /dev/net/tun"
+ # /dev/net/tun can take its time to appear
+ local timeout=10
+ while [ ! -e /dev/net/tun -a ${timeout} -gt 0 ]; do
+ sleep 1
+ : $(( timeout -= 1 ))
+ done
+ if [ ! -e /dev/net/tun ]; then
+ eerror "TUN/TAP support present but /dev/net/tun is not"
+ return 1
+ fi
+ veend 0
+ fi
+
+ ebegin "Creating Tun/Tap interface ${IFACE}"
+
+ # Set the base metric to 1000
+ metric=1000
+
+ local i_opts= o_opts= t_opts=
+ local do_iproute2=false do_openvpn=false do_tunctl=false
+ eval i_opts=\$iproute2_${IFVAR}
+ eval o_opts=\$openvpn_${IFVAR}
+ eval t_opts=\$tunctl_${IFVAR}
+
+ if [ -n "${i_opts}" ] && type ip >/dev/null 2>&1; then
+ do_iproute2=true
+ elif [ -n "${o_opts}" ] && type openvpn >/dev/null 2>&1; then
+ do_openvpn=true
+ elif [ -n "${t_opts}" ] && type tunctl >/dev/null 2>&1; then
+ do_tunctl=true
+ elif type ip >/dev/null 2>&1; then
+ do_iproute2=true
+ elif type openvpn >/dev/null 2>&1; then
+ do_openvpn=true
+ elif type tunctl >/dev/null 2>&1; then
+ do_tunctl=true
+ fi
+
+ if ${do_iproute2}; then
+ ip tuntap add dev "${IFACE}" mode "${tuntap}" ${i_opts}
+ rc=$?
+ elif ${do_openvpn}; then
+ openvpn --mktun --dev-type "${tuntap}" --dev "${IFACE}" \
+ ${o_opts} >/dev/null
+ rc=$?
+ elif ${do_tunctl}; then
+ tunctl ${t_opts} -t "${IFACE}" >/dev/null
+ rc=$?
+ else
+ eerror "Neither iproute2, openvpn nor tunctl has been found, please install"
+ eerror "either \"iproute2\" \"openvpn\" or \"usermode-utilities\"."
+ rc=1
+ fi
+ eend $rc && _up && service_set_value tuntap "${tuntap}"
+}
+
+tuntap_post_stop()
+{
+ _is_tuntap || return 0
+
+ ebegin "Destroying Tun/Tap interface ${IFACE}"
+ if type ip > /dev/null 2>&1; then
+ ip tuntap del dev ${IFACE} mode $(service_get_value tuntap)
+ elif type tunctl >/dev/null 2>&1; then
+ tunctl -d "${IFACE}" >/dev/null
+ else
+ openvpn --rmtun \
+ --dev-type "$(service_get_value tuntap)" \
+ --dev "${IFACE}" >/dev/null
+ fi
+ eend $?
+}
diff --git a/net/udhcpc.sh.Linux.in b/net/udhcpc.sh.Linux.in
new file mode 100644
index 0000000..bb502e5
--- /dev/null
+++ b/net/udhcpc.sh.Linux.in
@@ -0,0 +1,110 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+udhcpc_depend()
+{
+ program start /bin/busybox
+ after interface
+ provide dhcp
+}
+
+_config_vars="$_config_vars dhcp udhcpc"
+
+udhcpc_start()
+{
+ local args= opt= opts= pidfile="/var/run/udhcpc-${IFACE}.pid"
+ local sendhost=true cachefile="/var/cache/udhcpc-${IFACE}.lease"
+
+ eval args=\$udhcpc_${IFVAR}
+
+ # Get our options
+ eval opts=\$dhcp_${IFVAR}
+ [ -z "${opts}" ] && opts=${dhcp}
+
+ # This omits the Gentoo specific patch to busybox,
+ # but it creates temporary files.
+ # We can move this stuff to udhcpc hook script to avoid that, should we do?
+ local conf="/var/run/udhcpc-${IFACE}.conf"
+ echo -n >"$conf"
+ # Map some generic options to dhcpcd
+ for opt in ${opts}; do
+ case "${opt}" in
+ nodns) echo "PEER_DNS=no" >>"$conf" ;;
+ nontp) echo "PEER_NTP=no" >>"$conf" ;;
+ nogateway) echo "PEER_ROUTERS=no" >>"$conf" ;;
+ nosendhost) sendhost=false;
+ esac
+ done
+
+ [ "${metric:-0}" != "0" ] && echo "IF_METRIC=${metric}" >>"$conf"
+
+ ebegin "Running udhcpc"
+
+ # Try and load the cache if it exists
+ if [ -f "${cachefile}" ]; then
+ case "$ {args} " in
+ *" --request="*|*" -r "*);;
+ *)
+ local x=$(cat "${cachefile}")
+ # Check for a valid ip
+ case "${x}" in
+ *.*.*.*) args="${args} --request=${x}";;
+ esac
+ ;;
+ esac
+ fi
+
+ case " ${args} " in
+ *" --quit "*|*" -q "*) x="/bin/busybox udhcpc";;
+ *) x="start-stop-daemon --start --exec /bin/busybox \
+ --pidfile \"${pidfile}\" -- udhcpc";;
+ esac
+
+ case " ${args} " in
+ *" --hostname="*|*" -h "*|*" -H "*);;
+ *)
+ if ${sendhost}; then
+ local hname="$(hostname)"
+ if [ "${hname}" != "(none)" ] && [ "${hname}" != "localhost" ]; then
+ args="${args} -x hostname:'${hname}'"
+ fi
+ fi
+ ;;
+ esac
+
+ eval "${x}" "${args}" --interface="${IFACE}" --now \
+ --script="@LIBEXECDIR@/sh/udhcpc-hook.sh" \
+ --pidfile="${pidfile}" >/dev/null
+ eend $? || return 1
+
+ _show_address
+ return 0
+}
+
+udhcpc_stop()
+{
+ local pidfile="/var/run/udhcpc-${IFACE}.pid" opts=
+ [ ! -f "${pidfile}" ] && return 0
+
+ # Get our options
+ eval opts=\$dhcp_${IFVAR}
+ [ -z "${opts}" ] && opts=${dhcp}
+
+ ebegin "Stopping udhcpc on ${IFACE}"
+ case " ${opts} " in
+ *" release "*)
+ start-stop-daemon --stop --quiet --signal USR2 \
+ --exec /bin/busybox --pidfile "${pidfile}"
+ if [ -f /var/cache/udhcpc-"${IFACE}".lease ]; then
+ rm -f /var/cache/udhcpc-"${IFACE}".lease
+ fi
+ ;;
+ esac
+
+ start-stop-daemon --stop --exec /bin/busybox --pidfile "${pidfile}"
+ eend $?
+
+ if [ -e "/var/run/udhcpc-${IFACE}.conf" ]; then
+ rm -f "/var/run/udhcpc-${IFACE}.conf"
+ fi
+}
diff --git a/net/vlan.sh b/net/vlan.sh
new file mode 100644
index 0000000..10040af
--- /dev/null
+++ b/net/vlan.sh
@@ -0,0 +1,146 @@
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+vlan_depend()
+{
+ program ip
+ after interface
+ before dhcp
+}
+
+_config_vars="$_config_vars vlans"
+
+_is_vlan()
+{
+ [ ! -d /proc/net/vlan ] && return 1
+ [ -e /proc/net/vlan/"${IFACE}" ] && return 0
+ grep -Eq "^${IFACE}[[:space:]]+" /proc/net/vlan/config
+}
+
+_get_vlans()
+{
+ [ -e /proc/net/vlan/config ] || return 1
+ sed -n -e 's/^\W*\([^ ]*\) \(.* \) .*'"${IFACE}"'$/\1/p' /proc/net/vlan/config
+}
+
+_check_vlan()
+{
+ if [ ! -d /proc/net/vlan ]; then
+ modprobe 8021q
+ if [ ! -d /proc/net/vlan ]; then
+ eerror "VLAN (802.1q) support is not present in this kernel"
+ return 1
+ fi
+ fi
+}
+
+vlan_pre_start()
+{
+ local vconfig
+ eval vconfig=\$vconfig_${IFVAR}
+ if [ -n "${vconfig}" ]; then
+ eerror "You must convert your vconfig_ VLAN entries to vlan${N} entries."
+ return 1
+ fi
+ local vlans=
+ eval vlans=\$vlans_${IFVAR}
+ [ -z "$vlans" ] && return 0
+ case " ${MODULES} " in
+ *" ifconfig "*)
+ eerror "sys-apps/iproute2 is required to configure VLANs"
+ return 1 ;;
+ esac
+}
+
+vlan_post_start()
+{
+ local vlans=
+ eval vlans=\$vlans_${IFVAR}
+ [ -z "${vlans}" ] && return 0
+
+ _check_vlan || return 1
+ _exists || return 1
+
+ local vlan= e= s= vname= vflags= vingress= vegress=
+ for vlan in ${vlans}; do
+ einfo "Adding VLAN ${vlan} to ${IFACE}"
+ # We need to gather all interface configuration options
+ # 1) naming. Default to the standard "${IFACE}.${vlan}" but it can be anything
+ eval vname=\$${IFACE}_vlan${vlan}_name
+ [ -z "${vname}" ] && eval vname=\$vlan${vlan}_name
+ [ -z "${vname}" ] && vname="${IFACE}.${vlan}"
+ # 2) flags
+ eval vflags=\$${IFACE}_vlan${vlan}_flags
+ [ -z "${vflags}" ] && eval vflags=\$vlan${vlan}_flags
+ # 3) ingress/egress map
+ eval vingress=\$${IFACE}_vlan${vlan}_ingress
+ [ -z "${vingress}" ] && eval vingress=\$vlan${vlan}_ingress
+ [ -z "${vingress}" ] || vingress="ingress-qos-map ${vingress}"
+ eval vegress=\$${IFACE}_vlan${vlan}_egress
+ [ -z "${vegress}" ] && eval vegress=\$vlan${vlan}_egress
+ [ -z "${vegress}" ] || vegress="egress-qos-map ${vegress}"
+
+ # txqueue
+ local txqueuelen=
+ eval txqueuelen=\$txqueuelen_${IFACE}_vlan${vlan}
+ [ -z "${txqueuelen}" ] && eval txqueuelen=\$txqueuelen_vlan${vlan}
+ # mac
+ local mac=
+ eval mac=\$mac_${IFACE}_vlan${vlan}
+ [ -z "${mac}" ] && eval mac=\$mac_vlan${vlan}
+ # broadcast
+ local broadcast=
+ eval broadcast=\$broadcast_${IFACE}_vlan${vlan}
+ [ -z "${broadcast}" ] && eval broadcast=\$broadcast_vlan${vlan}
+ # mtu
+ local mtu=
+ eval mtu=\$mtu_${IFACE}_vlan${vlan}
+ [ -z "${mtu}" ] && eval mtu=\$mtu_vlan${vlan}
+
+ # combine it all
+ local opts="${txqueuelen:+txqueuelen} ${txqueuelen} ${mac:+address} ${mac} ${broadcast:+broadcast} ${broadcast} ${mtu:+mtu} ${mtu}"
+
+ veinfo "ip link add link \"${IFACE}\" name \"${vname}\" ${opts} type vlan id \"${vlan}\" ${vflags} ${vingress} ${vegress}"
+ e="$(ip link add link "${IFACE}" name "${vname}" ${opts} type vlan id "${vlan}" ${vflags} ${vingress} ${vegress} 2>&1 1>/dev/null)"
+ if [ -n "${e}" ]; then
+ eend 1 "${e}"
+ continue
+ fi
+
+ # We may not want to start the vlan ourselves
+ eval s=\$vlan_start_${IFVAR}
+ yesno ${s:-yes} || continue
+
+ # We need to work out the interface name of our new vlan id
+ local ifname="$(sed -n -e \
+ 's/^\([^[:space:]]*\) *| '"${vlan}"' *| .*'"${IFACE}"'$/\1/p' \
+ /proc/net/vlan/config )"
+ mark_service_started "net.${ifname}"
+ (
+ RC_SVCNAME="net.${ifname}" ; export RC_SVCNAME
+ start
+ ) || mark_service_stopped "net.${ifname}"
+ done
+
+ return 0
+}
+
+vlan_pre_stop()
+{
+ local vlan=
+
+ _exists || return 0
+
+ for vlan in $(_get_vlans); do
+ einfo "Removing VLAN ${vlan##*.} from ${IFACE}"
+ (
+ RC_SVCNAME="net.${vlan}" ; export RC_SVCNAME
+ stop
+ ) && {
+ mark_service_stopped "net.${vlan}"
+ ip link delete "${vlan}" type vlan >/dev/null
+ }
+ done
+
+ return 0
+}
diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh
new file mode 100644
index 0000000..53b0256
--- /dev/null
+++ b/net/wpa_supplicant.sh
@@ -0,0 +1,212 @@
+# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+wpa_supplicant_depend()
+{
+ wpas=/usr/sbin/wpa_supplicant
+ [ -x ${wpas} ] || wpas=/sbin/wpa_supplicant
+ if [ -x ${wpas} ]; then
+ program start ${wpas}
+ # bug 345281: if wpa_supplicant is built w/ USE=dbus, we need to start
+ # dbus before we can start wpa_supplicant.
+ ${wpas} -h |grep DBus -sq
+ [ $? -eq 0 ] && need dbus
+ fi
+ after macnet plug
+ before interface
+ provide wireless
+
+ # Prefer us over iwconfig
+ after iwconfig
+}
+
+# Only set these functions if not set already
+# IE, prefer to use iwconfig
+if ! type _get_ssid >/dev/null 2>&1; then
+_get_ssid()
+{
+ local timeout=5 ssid=
+
+ while [ ${timeout} -gt 0 ]; do
+ ssid=$(wpa_cli -i"${IFACE}" status | sed -n -e 's/^ssid=//p')
+ if [ -n "${ssid}" ]; then
+ echo "${ssid}"
+ return 0
+ fi
+ sleep 1
+ : $(( timeout -= 1 ))
+ done
+
+ return 1
+}
+
+_get_ap_mac_address()
+{
+ wpa_cli -i"${IFACE}" status | sed -n -e 's/^bssid=\(.*\)$/\1/p' \
+ | tr '[:lower:]' '[:upper:]'
+}
+fi
+
+wpa_supplicant_pre_start()
+{
+ local opts= cliopts= cfgfile= ctrl_dir= wireless=true
+ local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
+ local actfile=/etc/wpa_supplicant/wpa_cli.sh
+
+ if [ ! -x "${wpas}" ]; then
+ wpas=/sbin/wpa_supplicant
+ wpac=/bin/wpa_cli
+ fi
+ [ "${RC_UNAME}" = "Linux" ] || unset wpac
+ [ -e "${actfile}" ] || unset wpac
+
+ eval opts=\$wpa_supplicant_${IFVAR}
+ eval cliopts=\$wpa_cli_${IFVAR}
+ [ -z "${cliopts}" ] && cliopts=${wpa_cli}
+ case " ${opts} " in
+ *" -Dwired "*) wireless=false;;
+ *) _is_wireless || return 0;;
+ esac
+
+ # We don't configure wireless if we're being called from
+ # the background unless we're not currently running
+ if yesno ${IN_BACKGROUND}; then
+ if ${wireless} && \
+ service_started_daemon "${RC_SVCNAME}" "${wpas}"; then
+ SSID=$(_get_ssid "${IFACE}")
+ SSIDVAR=$(shell_var "${SSID}")
+ service_set_value "SSID" "${SSID}"
+ metric=2000
+ fi
+ return 0
+ fi
+
+ service_set_value "SSID" ""
+ ebegin "Starting wpa_supplicant on ${IFVAR}"
+
+ if type iwconfig_defaults >/dev/null 2>&1; then
+ iwconfig_defaults
+ iwconfig_user_config
+ fi
+
+ cfgfile=${opts##* -c}
+ if [ -n "${cfgfile}" -a "${cfgfile}" != "${opts}" ]; then
+ case "${cfgfile}" in
+ " "*) cfgfile=${cfgfile# *};;
+ esac
+ cfgfile=${cfgfile%% *}
+ else
+ # Support new and old style locations
+ cfgfile="/etc/wpa_supplicant/wpa_supplicant-${IFACE}.conf"
+ [ ! -e "${cfgfile}" ] \
+ && cfgfile="/etc/wpa_supplicant/wpa_supplicant.conf"
+ [ ! -e ${cfgfile} ] \
+ && cfgfile="/etc/wpa_supplicant.conf"
+ opts="${opts} -c ${cfgfile}"
+ fi
+
+ if [ ! -f ${cfgfile} ]; then
+ eend 1 "/etc/wpa_supplicant/wpa_supplicant.conf not found"
+ return 1
+ fi
+
+ # Work out where the ctrl_interface dir is if it's not specified
+ local ctrl_dir=$(sed -e 's/^ *//' \
+ -e '/^ctrl_interface=/!d' \
+ -e 's/^ctrl_interface=//' \
+ -e 's/^ *//' \
+ -e 's/^DIR=//' \
+ -e 's/^ *//' \
+ -e 's/GROUP=.*//' \
+ -e 's/ *$//' \
+ "${cfgfile}")
+ if [ -z "${ctrl_dir}" ]; then
+ ctrl_dir=${opts##* -C}
+ if [ -n "${ctrl_dir}" -a "${ctrl_dir}" != "${opts}" ]; then
+ case "${ctrl_dir}" in
+ " "*) ctrl_dir=${ctrl_dir# *};;
+ esac
+ ctrl_dir=${ctrl_dir%% *}
+ else
+ ctrl_dir="/var/run/wpa_supplicant"
+ opts="${opts} -C ${ctrl_dir}"
+ fi
+ fi
+ service_set_value ctrl_dir "${ctrl_dir}"
+
+ if [ -n "${wpac}" ]; then
+ opts="${opts} -W"
+ elif service_started devd; then
+ mark_service_inactive
+ fi
+ start-stop-daemon --start --exec "${wpas}" \
+ --pidfile "/var/run/wpa_supplicant-${IFACE}.pid" \
+ -- ${opts} -B -i "${IFACE}" \
+ -P "/var/run/wpa_supplicant-${IFACE}.pid"
+ eend $? || return 1
+
+ # If we don't have a working wpa_cli and action file continue
+ if [ -z "${wpac}" ]; then
+ if service_started devd; then
+ ebegin "Backgrounding ..."
+ exit 1
+ fi
+ return 0
+ fi
+
+ # Starting wpa_supplication-0.4.0, we can get wpa_cli to
+ # start/stop our scripts from wpa_supplicant messages
+ local inact=false
+ service_inactive && inact=true
+ mark_service_inactive
+
+ ebegin "Starting wpa_cli on" "${IFACE}"
+ start-stop-daemon --start --exec "${wpac}" \
+ --pidfile "/var/run/wpa_cli-${IFACE}.pid" \
+ -- ${cliopts} -a "${actfile}" -p "${ctrl_dir}" -i "${IFACE}" \
+ -P "/var/run/wpa_cli-${IFACE}.pid" -B
+ if eend $?; then
+ ebegin "Backgrounding ..."
+ exit 1
+ fi
+
+ # wpa_cli failed to start? OK, error here
+ start-stop-daemon --quiet --stop --exec "${wpas}" \
+ --pidfile "/var/run/wpa_supplicant-${IFACE}.pid"
+ ${inact} || mark_service_stopped
+ return 1
+}
+
+wpa_supplicant_post_stop()
+{
+ local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
+
+ if [ ! -x "${wpas}" ]; then
+ wpas=/sbin/wpa_supplicant
+ wpac=/bin/wpa_cli
+ fi
+
+ if yesno "${IN_BACKGROUND}"; then
+ # Only stop wpa_supplicant if it's not the controlling daemon
+ ! service_started_daemon "${RC_SVCNAME}" "${wpas}" 1
+ fi
+ [ $? != 0 ] && return 0
+
+ local pidfile="/var/run/wpa_cli-${IFACE}.pid"
+ if [ -f ${pidfile} ]; then
+ ebegin "Stopping wpa_cli on ${IFACE}"
+ start-stop-daemon --stop --exec "${wpac}" --pidfile "${pidfile}"
+ eend $?
+ fi
+
+ pidfile="/var/run/wpa_supplicant-${IFACE}.pid"
+ if [ -f ${pidfile} ]; then
+ ebegin "Stopping wpa_supplicant on ${IFACE}"
+ start-stop-daemon --stop --exec "${wpas}" --pidfile "${pidfile}"
+ eend $?
+ fi
+
+ # If wpa_supplicant exits uncleanly, we need to remove the stale dir
+ [ -S "/var/run/wpa_supplicant/${IFACE}" ] \
+ && rm -f "/var/run/wpa_supplicant/${IFACE}"
+}
diff --git a/sh/.gitignore b/sh/.gitignore
new file mode 100644
index 0000000..80e488d
--- /dev/null
+++ b/sh/.gitignore
@@ -0,0 +1,3 @@
+ifwatchd-carrier.sh
+ifwatchd-nocarrier.sh
+udhcpc-hook.sh
diff --git a/sh/Makefile b/sh/Makefile
new file mode 100644
index 0000000..6efb98b
--- /dev/null
+++ b/sh/Makefile
@@ -0,0 +1,21 @@
+DIR= ${LIBEXECDIR}/sh
+SRCS= ${SRCS-${OS}}
+INC=
+BIN= ${BIN-${OS}}
+
+MK= ../mk
+include ${MK}/os.mk
+
+SRCS-FreeBSD=
+BIN-FreeBSD=
+
+SRCS-Linux= udhcpc-hook.sh.in
+BIN-Linux= udhcpc-hook.sh
+
+SRCS-NetBSD= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
+BIN-NetBSD= ifwatchd-carrier.sh ifwatchd-nocarrier.sh
+
+include ${MK}/scripts.mk
+
+%.sh: %.sh${SFX}
+ ${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
diff --git a/sh/ifwatchd-carrier.sh.in b/sh/ifwatchd-carrier.sh.in
new file mode 100644
index 0000000..5b5d8b3
--- /dev/null
+++ b/sh/ifwatchd-carrier.sh.in
@@ -0,0 +1,5 @@
+#!@SHELL@
+# Wrapper for ifwatchd(8)
+
+IN_BACKGROUND=yes ; export IN_BACKGROUND
+$RC_SERVICE --quiet start
diff --git a/sh/ifwatchd-nocarrier.sh.in b/sh/ifwatchd-nocarrier.sh.in
new file mode 100644
index 0000000..bbecfe8
--- /dev/null
+++ b/sh/ifwatchd-nocarrier.sh.in
@@ -0,0 +1,5 @@
+#!@SHELL@
+# Wrapper for ifwatchd(8)
+
+IN_BACKGROUND=yes ; export IN_BACKGROUND
+$RC_SERVICE --quiet stop
diff --git a/sh/udhcpc-hook.sh.in b/sh/udhcpc-hook.sh.in
new file mode 100644
index 0000000..0744a04
--- /dev/null
+++ b/sh/udhcpc-hook.sh.in
@@ -0,0 +1,117 @@
+#!@SHELL@
+# busybox udhcp setup script
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+peer_var()
+{
+ [ -n "$1" ] && [ "$1" != "yes" ]
+}
+
+update_dns()
+{
+ peer_var "${PEER_DNS}" && return
+ [ -z "${domain}" ] && [ -z "${dns}" ] && return
+
+ conf="# Generated by udhcpc for ${interface}\n"
+ [ -n "${domain}" ] && conf="${conf}domain ${domain}\n"
+ for i in ${dns} ; do
+ conf="${conf}nameserver ${i}\n"
+ done
+ if [ -x /sbin/resolvconf ] ; then
+ printf "${conf}" | resolvconf -a ${interface}
+ else
+ printf "${conf}" > /etc/resolv.conf
+ chmod 644 /etc/resolv.conf
+ fi
+}
+
+update_ntp()
+{
+ peer_var "${PEER_NTP}" && return
+ [ -z "${ntpsrv}" ] && return
+
+ conf="# Generated by udhcpc for interface ${interface}\n"
+ conf="${conf}restrict default noquery notrust nomodify\n"
+ conf="${conf}restrict 127.0.0.1\n"
+ for i in ${ntpsrv} ; do
+ conf="${conf}restrict ${i} nomodify notrap noquery\n"
+ conf="${conf}server ${i}\n"
+ done
+ conf="${conf}driftfile /var/lib/ntp/ntp.drift\n"
+ conf="${conf}logfile /var/log/ntp.log\n"
+ printf "${conf}" > /etc/ntp.conf
+ chmod 644 /etc/ntp.conf
+}
+
+update_hostname()
+{
+ peer_var "${PEER_HOSTNAME}" && return
+ [ -z "${hostname}" ] && return
+
+ myhost="$(hostname)"
+ [ -z "${myhost}" ] || [ "${myhost}" = "(none)" ] && hostname "${hostname}"
+}
+
+update_interface()
+{
+ [ -n "${broadcast}" ] && broadcast="broadcast ${broadcast}"
+ [ -n "${subnet}" ] && netmask="netmask ${subnet}"
+ [ -n "${mtu}" ] && mtu="mtu ${mtu}"
+ ifconfig "${interface}" ${ip} ${broadcast} ${netmask} ${mtu}
+}
+
+update_routes()
+{
+ peer_var "${PEER_ROUTERS}" && return
+
+ if [ -n "${router}" ] ; then
+ metric=
+ [ -n "${IF_METRIC}" ] && metric="metric ${IF_METRIC}"
+ for i in ${router} ; do
+ route add default gw "${i}" ${metric} dev "${interface}"
+ done
+ fi
+}
+
+deconfig()
+{
+ ifconfig "${interface}" 0.0.0.0
+
+ if ! peer_var "${PEER_ROUTERS}" ; then
+ while route del default dev "${interface}" >/dev/null 2>&1; do
+ :
+ done
+ fi
+
+ if ! peer_var "${PEER_DNS}" ; then
+ [ -x /sbin/resolvconf ] && resolvconf -d "${interface}"
+ fi
+}
+
+if [ -r "/var/run/udhcpc-${interface}.conf" ]; then
+ . "/var/run/udhcpc-${interface}.conf"
+fi
+
+case "$1" in
+ bound|renew)
+ update_hostname
+ update_interface
+ update_routes
+ update_dns
+ update_ntp
+ ;;
+ deconfig|leasefail)
+ deconfig
+ ;;
+ nak)
+ echo "nak: ${message}"
+ ;;
+ *)
+ echo "unknown option $1" >&2
+ echo "Usage: $0 {bound|deconfig|leasefail|nak|renew}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0