mirror of https://github.com/OpenRC/openrc.git
Remove gentoo's net.* scripts
It has been determined that it will be best for gentoo's net.* scripts to be in a separate package to allow independent development. This package will be called netifrc and maintained by Gentoo.
This commit is contained in:
parent
b2f8ac9382
commit
838c9efb36
5
Makefile
5
Makefile
|
@ -6,11 +6,6 @@ include Makefile.inc
|
|||
|
||||
SUBDIR= conf.d etc init.d local.d man scripts sh src sysctl.d
|
||||
|
||||
# Build our old net foo or not
|
||||
ifeq (${MKNET},oldnet)
|
||||
SUBDIR+= net doc
|
||||
endif
|
||||
|
||||
# Build pkgconfig or not
|
||||
MKPKGCONFIG?= yes
|
||||
ifeq (${MKPKGCONFIG},yes)
|
||||
|
|
2
README
2
README
|
@ -10,7 +10,7 @@ You may wish to tweak the installation with the below arguments
|
|||
PROGLDFLAGS=-static
|
||||
LIBNAME=lib64
|
||||
DESTDIR=/tmp/openrc-image
|
||||
MKNET=oldnet
|
||||
MKNET=no
|
||||
MKPAM=pam
|
||||
MKPREFIX=yes
|
||||
MKPKGCONFIG=no
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
The following applies only to the newnet stack, which is not presently
|
||||
maintained in OpenRC. The oldnet stack is maintained instead.
|
||||
- Robin H. Johnson <robbat2@gentoo.org>, 2011/02/21
|
||||
|
||||
OpenRC Network Ideals
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
include ../mk/net.mk
|
||||
|
||||
DIR= ${CONFDIR}
|
||||
CONF= bootmisc fsck hostname localmount netmount urandom tmpfiles \
|
||||
${CONF-${OS}}
|
||||
|
||||
ifeq (${MKNET},)
|
||||
ifeq (${MKNET},yes)
|
||||
CONF+= network staticroute
|
||||
TARGETS+= network staticroute
|
||||
CLEANFILES+= network staticroute
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
# This blank configuration will automatically use DHCP for any net.*
|
||||
# scripts in /etc/init.d. To create a more complete configuration,
|
||||
# please review /usr/share/doc/openrc*/net.example* and save your configuration
|
||||
# in /etc/conf.d/net (this file :]!).
|
|
@ -1 +0,0 @@
|
|||
net.example
|
11
doc/Makefile
11
doc/Makefile
|
@ -1,11 +0,0 @@
|
|||
DIR= ${DOCDIR}/openrc
|
||||
SRCS= net.example.in
|
||||
INC= net.example
|
||||
|
||||
MK= ../mk
|
||||
include ${MK}/os.mk
|
||||
|
||||
%.example.in: %.example${SFX}
|
||||
${CP} $< $@
|
||||
|
||||
include ${MK}/scripts.mk
|
|
@ -1,445 +0,0 @@
|
|||
##############################################################################
|
||||
# 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
|
File diff suppressed because it is too large
Load Diff
|
@ -1,23 +1,19 @@
|
|||
include ../mk/net.mk
|
||||
|
||||
DIR= ${INITDIR}
|
||||
SRCS= bootmisc.in fsck.in hostname.in local.in localmount.in loopback.in \
|
||||
netmount.in root.in savecache.in swap.in swapfiles.in \
|
||||
tmpfiles.setup.in swclock.in sysctl.in urandom.in ${SRCS-${OS}}
|
||||
BIN= ${OBJS}
|
||||
|
||||
# Build our old net foo or not
|
||||
ifeq (${MKNET},)
|
||||
# Are we installing our network scripts?
|
||||
ifeq (${MKNET},yes)
|
||||
SRCS+= network.in staticroute.in
|
||||
endif
|
||||
|
||||
ifeq (${MKNET},oldnet)
|
||||
INSTALLAFTER= _installafter_net.lo
|
||||
SRCS+= net.lo.in
|
||||
endif
|
||||
|
||||
MK= ../mk
|
||||
include ${MK}/os.mk
|
||||
|
||||
NET_LO-FreeBSD= net.lo0
|
||||
# Generic BSD scripts
|
||||
SRCS-FreeBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \
|
||||
rpcbind.in savecore.in syslogd.in
|
||||
|
@ -25,12 +21,10 @@ SRCS-FreeBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \
|
|||
SRCS-FreeBSD+= adjkerntz.in devd.in dumpon.in encswap.in ipfw.in \
|
||||
mixer.in nscd.in powerd.in syscons.in
|
||||
|
||||
NET_LO-Linux= net.lo
|
||||
SRCS-Linux= devfs.in dmesg.in hwclock.in consolefont.in keymaps.in \
|
||||
killprocs.in modules.in mount-ro.in mtab.in numlock.in \
|
||||
procfs.in sysfs.in termencoding.in tmpfiles.dev.in
|
||||
|
||||
NET_LO-NetBSD= net.lo0
|
||||
# Generic BSD scripts
|
||||
SRCS-NetBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \
|
||||
rpcbind.in savecore.in syslogd.in
|
||||
|
@ -43,6 +37,3 @@ SRCS-NetBSD+= devdb.in swap-blk.in ttys.in wscons.in
|
|||
include ${MK}/scripts.mk
|
||||
|
||||
_installafter_: realinstall
|
||||
|
||||
_installafter_net.lo: realinstall
|
||||
${INSTALL} -m ${BINMODE} net.lo ${DESTDIR}/${INITDIR}/${NET_LO-${OS}}
|
||||
|
|
789
init.d/net.lo.in
789
init.d/net.lo.in
|
@ -1,789 +0,0 @@
|
|||
#!@SBINDIR@/runscript
|
||||
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
||||
# Released under the 2-clause BSD license.
|
||||
|
||||
MODULESDIR="${RC_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
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
ifconfig.sh
|
||||
iwconfig.sh
|
24
net/Makefile
24
net/Makefile
|
@ -1,24 +0,0 @@
|
|||
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
|
||||
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=
|
||||
INC-NetBSD= ifwatchd.sh
|
||||
|
||||
%.sh: %.sh${SFX}
|
||||
${CP} $< $@
|
||||
|
||||
include ${MK}/scripts.mk
|
74
net/adsl.sh
74
net/adsl.sh
|
@ -1,74 +0,0 @@
|
|||
# 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
|
||||
}
|
48
net/apipa.sh
48
net/apipa.sh
|
@ -1,48 +0,0 @@
|
|||
# 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
|
||||
}
|
131
net/arping.sh
131
net/arping.sh
|
@ -1,131 +0,0 @@
|
|||
# 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
|
||||
}
|
223
net/bonding.sh
223
net/bonding.sh
|
@ -1,223 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
190
net/bridge.sh
190
net/bridge.sh
|
@ -1,190 +0,0 @@
|
|||
# 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
|
||||
}
|
106
net/ccwgroup.sh
106
net/ccwgroup.sh
|
@ -1,106 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
221
net/clip.sh
221
net/clip.sh
|
@ -1,221 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,264 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,328 +0,0 @@
|
|||
# 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" ]
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
# 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 "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \
|
||||
-n "${RC_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 "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \
|
||||
-n "${RC_LIBEXECDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" \
|
||||
|| return 0
|
||||
|
||||
ebegin "Stopping ifwatchd on" "${IFACE}"
|
||||
start-stop-daemon --stop --exec /usr/sbin/ifwatchd \
|
||||
-- -c "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \
|
||||
-n "${RC_LIBEXECDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}"
|
||||
eend $?
|
||||
}
|
175
net/ip6rd.sh
175
net/ip6rd.sh
|
@ -1,175 +0,0 @@
|
|||
# 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
|
||||
}
|
116
net/ip6to4.sh
116
net/ip6to4.sh
|
@ -1,116 +0,0 @@
|
|||
# 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
|
||||
}
|
48
net/ipppd.sh
48
net/ipppd.sh
|
@ -1,48 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
404
net/iproute2.sh
404
net/iproute2.sh
|
@ -1,404 +0,0 @@
|
|||
# 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" ]
|
||||
}
|
|
@ -1,593 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,763 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
243
net/pppd.sh
243
net/pppd.sh
|
@ -1,243 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
59
net/pump.sh
59
net/pump.sh
|
@ -1,59 +0,0 @@
|
|||
# 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"
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
# 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
|
||||
}
|
122
net/system.sh
122
net/system.sh
|
@ -1,122 +0,0 @@
|
|||
# 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
|
||||
}
|
102
net/tuntap.sh
102
net/tuntap.sh
|
@ -1,102 +0,0 @@
|
|||
# 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 $?
|
||||
}
|
110
net/udhcpc.sh
110
net/udhcpc.sh
|
@ -1,110 +0,0 @@
|
|||
# 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="${RC_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
|
||||
}
|
146
net/vlan.sh
146
net/vlan.sh
|
@ -1,146 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,212 +0,0 @@
|
|||
# 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}"
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
include ../mk/net.mk
|
||||
|
||||
BOOT= bootmisc fsck hostname localmount loopback \
|
||||
root swap swapfiles sysctl urandom ${BOOT-${OS}}
|
||||
DEFAULT= local netmount
|
||||
|
@ -10,7 +12,7 @@ BOOTDIR= ${LEVELDIR}/boot
|
|||
DEFAULTDIR= ${LEVELDIR}/default
|
||||
SHUTDOWNDIR= ${LEVELDIR}/shutdown
|
||||
|
||||
ifeq (${MKNET},)
|
||||
ifeq (${MKNET},yes)
|
||||
BOOT+= network staticroute
|
||||
endif
|
||||
|
||||
|
@ -25,12 +27,6 @@ BOOT-${OS}=
|
|||
SHUTDOWN-${OS}=
|
||||
SYSINIT-${OS}=
|
||||
|
||||
ifeq (${MKNET},oldnet)
|
||||
BOOT-FreeBSD+= net.lo0
|
||||
BOOT-Linux+= net.lo
|
||||
BOOT-NetBSD+= net.lo0
|
||||
endif
|
||||
|
||||
BOOT-BSD= hostid newsyslog savecore syslogd swap-blk
|
||||
|
||||
# Generic BSD stuff
|
||||
|
|
|
@ -6,9 +6,6 @@ runscript.sh
|
|||
cgroup-release-agent.sh
|
||||
init.sh
|
||||
init-early.sh
|
||||
ifwatchd-carrier.sh
|
||||
ifwatchd-nocarrier.sh
|
||||
rc-cgroup.sh
|
||||
udhcpc-hook.sh
|
||||
tmpfiles.sh
|
||||
migrate-to-run.sh
|
||||
|
|
|
@ -13,12 +13,12 @@ SRCS-FreeBSD=
|
|||
BIN-FreeBSD=
|
||||
|
||||
SRCS-Linux= cgroup-release-agent.sh.in init-early.sh.in migrate-to-run.sh.in \
|
||||
rc-cgroup.sh.in udhcpc-hook.sh.in
|
||||
rc-cgroup.sh.in
|
||||
BIN-Linux= cgroup-release-agent.sh init-early.sh migrate-to-run.sh \
|
||||
rc-cgroup.sh udhcpc-hook.sh
|
||||
rc-cgroup.sh
|
||||
|
||||
SRCS-NetBSD= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
|
||||
BIN-NetBSD= ifwatchd-carrier.sh ifwatchd-nocarrier.sh
|
||||
SRCS-NetBSD=
|
||||
BIN-NetBSD=
|
||||
|
||||
include ${MK}/scripts.mk
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
#!@SHELL@
|
||||
# Wrapper for ifwatchd(8)
|
||||
|
||||
IN_BACKGROUND=yes ; export IN_BACKGROUND
|
||||
$RC_SERVICE --quiet start
|
|
@ -1,5 +0,0 @@
|
|||
#!@SHELL@
|
||||
# Wrapper for ifwatchd(8)
|
||||
|
||||
IN_BACKGROUND=yes ; export IN_BACKGROUND
|
||||
$RC_SERVICE --quiet stop
|
|
@ -1,117 +0,0 @@
|
|||
#!@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
|
Loading…
Reference in New Issue