From 4e457e0efd0e5fd5df24c7e9ed63b02d0196ea8d Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Fri, 28 Dec 2012 02:38:58 +0100 Subject: Forking netcfg to netctl (1/2) This commit contains the moving of files. --- LICENSE | 20 --- Makefile | 73 +++----- NEWS | 174 +----------------- README | 29 ++- config/iftab | 20 --- config/netcfg | 16 -- contrib/PKGBUILD | 31 ++-- contrib/iptables.hook | 17 -- contrib/logging.hook | 86 --------- contrib/pm-utils.handler | 73 -------- contrib/zsh-completion | 52 ------ docs/Makefile | 19 +- docs/examples/openvpn | 5 - docs/examples/ppp | 4 - docs/features.txt | 147 --------------- docs/footer.txt | 22 --- docs/index.txt | 57 ------ docs/netcfg-profiles.5.txt | 321 --------------------------------- docs/netcfg.8.txt | 91 ---------- docs/netctl.1.txt | 91 ++++++++++ docs/netctl.profile.5.txt | 321 +++++++++++++++++++++++++++++++++ rc.d/net-auto-wired | 62 ------- rc.d/net-auto-wireless | 61 ------- rc.d/net-profiles | 55 ------ rc.d/net-rename | 28 --- rc.d/net-set-variable | 10 -- scripts/ifplugd.action | 49 ----- scripts/netcfg | 106 ----------- scripts/netcfg-daemon | 102 ----------- scripts/netcfg-menu | 55 ------ scripts/netcfg-wpa_actiond | 87 --------- scripts/netcfg-wpa_actiond-action | 56 ------ scripts/pm-utils | 26 --- scripts/wifi-menu | 263 --------------------------- services/netctl-auto@.service | 14 ++ services/netctl-ifplugd@.service | 10 ++ services/netctl.service | 14 ++ services/netctl@.service | 14 ++ src/8021x | 275 ---------------------------- src/connections/bond | 40 ----- src/connections/bridge | 47 ----- src/connections/ethernet | 279 ----------------------------- src/connections/openvpn | 52 ------ src/connections/ppp | 31 ---- src/connections/pppoe | 77 -------- src/connections/tunnel | 34 ---- src/connections/tuntap | 28 --- src/connections/vlan | 28 --- src/connections/wireless | 116 ------------ src/globals | 136 -------------- src/hooks/fancy | 90 ---------- src/hooks/initscripts | 35 ---- src/ifplugd.action | 49 +++++ src/lib/8021x | 275 ++++++++++++++++++++++++++++ src/lib/auto.action | 56 ++++++ src/lib/connections/README | 28 +++ src/lib/connections/bond | 40 +++++ src/lib/connections/bridge | 47 +++++ src/lib/connections/ethernet | 279 +++++++++++++++++++++++++++++ src/lib/connections/pppoe | 77 ++++++++ src/lib/connections/tunnel | 34 ++++ src/lib/connections/tuntap | 28 +++ src/lib/connections/vlan | 28 +++ src/lib/connections/wireless | 116 ++++++++++++ src/lib/globals | 136 ++++++++++++++ src/lib/network | 368 ++++++++++++++++++++++++++++++++++++++ src/lib/rfkill | 61 +++++++ src/netctl | 106 +++++++++++ src/netctl-auto | 87 +++++++++ src/network | 368 -------------------------------------- src/rfkill | 61 ------- src/wifi-menu | 263 +++++++++++++++++++++++++++ systemd/net-auto-wired.service | 10 -- systemd/net-auto-wireless.service | 14 -- systemd/netcfg.service | 14 -- systemd/netcfg@.service | 14 -- 76 files changed, 2601 insertions(+), 3907 deletions(-) delete mode 100644 LICENSE delete mode 100644 config/iftab delete mode 100644 config/netcfg delete mode 100755 contrib/iptables.hook delete mode 100755 contrib/logging.hook delete mode 100755 contrib/pm-utils.handler delete mode 100644 contrib/zsh-completion delete mode 100644 docs/examples/openvpn delete mode 100644 docs/examples/ppp delete mode 100644 docs/features.txt delete mode 100644 docs/footer.txt delete mode 100644 docs/index.txt delete mode 100644 docs/netcfg-profiles.5.txt delete mode 100644 docs/netcfg.8.txt create mode 100644 docs/netctl.1.txt create mode 100644 docs/netctl.profile.5.txt delete mode 100755 rc.d/net-auto-wired delete mode 100755 rc.d/net-auto-wireless delete mode 100755 rc.d/net-profiles delete mode 100755 rc.d/net-rename delete mode 100644 rc.d/net-set-variable delete mode 100755 scripts/ifplugd.action delete mode 100755 scripts/netcfg delete mode 100755 scripts/netcfg-daemon delete mode 100755 scripts/netcfg-menu delete mode 100755 scripts/netcfg-wpa_actiond delete mode 100755 scripts/netcfg-wpa_actiond-action delete mode 100755 scripts/pm-utils delete mode 100755 scripts/wifi-menu create mode 100644 services/netctl-auto@.service create mode 100644 services/netctl-ifplugd@.service create mode 100644 services/netctl.service create mode 100644 services/netctl@.service delete mode 100644 src/8021x delete mode 100644 src/connections/bond delete mode 100644 src/connections/bridge delete mode 100644 src/connections/ethernet delete mode 100644 src/connections/openvpn delete mode 100644 src/connections/ppp delete mode 100644 src/connections/pppoe delete mode 100644 src/connections/tunnel delete mode 100644 src/connections/tuntap delete mode 100644 src/connections/vlan delete mode 100644 src/connections/wireless delete mode 100644 src/globals delete mode 100755 src/hooks/fancy delete mode 100755 src/hooks/initscripts create mode 100755 src/ifplugd.action create mode 100644 src/lib/8021x create mode 100755 src/lib/auto.action create mode 100644 src/lib/connections/README create mode 100644 src/lib/connections/bond create mode 100644 src/lib/connections/bridge create mode 100644 src/lib/connections/ethernet create mode 100644 src/lib/connections/pppoe create mode 100644 src/lib/connections/tunnel create mode 100644 src/lib/connections/tuntap create mode 100644 src/lib/connections/vlan create mode 100644 src/lib/connections/wireless create mode 100644 src/lib/globals create mode 100644 src/lib/network create mode 100644 src/lib/rfkill create mode 100755 src/netctl create mode 100755 src/netctl-auto delete mode 100644 src/network delete mode 100644 src/rfkill create mode 100755 src/wifi-menu delete mode 100644 systemd/net-auto-wired.service delete mode 100644 systemd/net-auto-wireless.service delete mode 100644 systemd/netcfg.service delete mode 100644 systemd/netcfg@.service diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 4cb113c..0000000 --- a/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2007, James Rayner - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -Neither the name of the Arch Linux nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile index 023ed64..8d22397 100644 --- a/Makefile +++ b/Makefile @@ -1,74 +1,53 @@ -export VERSION = 3.1 +export VERSION = 0.1 -.PHONY: install install-docs docs tarball pkgbuild upload clean +.PHONY: install install-docs docs tarball pkgbuild clean install: install-docs # Configuration files - install -d $(DESTDIR)/etc/network.d/{examples,interfaces} - install -Dm644 config/netcfg $(DESTDIR)/etc/conf.d/netcfg - install -m644 config/iftab $(DESTDIR)/etc/iftab + install -d $(DESTDIR)/etc/network.d/{examples,hooks,interfaces} install -m644 docs/examples/* $(DESTDIR)/etc/network.d/examples/ # Libs - install -d $(DESTDIR)/usr/lib/network/{connections,hooks} - install -m644 src/{network,rfkill,8021x,globals} $(DESTDIR)/usr/lib/network/ - install -m755 src/connections/* $(DESTDIR)/usr/lib/network/connections/ - # Hooks - install -m755 src/hooks/* $(DESTDIR)/usr/lib/network/hooks/ + install -d $(DESTDIR)/usr/lib/network/connections + install -m644 src/lib/{8021x,globals,ip,rfkill} $(DESTDIR)/usr/lib/network/ + install -m644 src/lib/connections/* $(DESTDIR)/usr/lib/network/connections/ + install -m755 src/lib/{auto.action,network} $(DESTDIR)/usr/lib/network/ # Scripts install -d $(DESTDIR)/usr/bin install -m755 \ - scripts/netcfg \ - scripts/netcfg-daemon \ - scripts/netcfg-menu \ - scripts/netcfg-wpa_actiond \ - scripts/netcfg-wpa_actiond-action \ - scripts/wifi-menu \ + src/netctl \ + src/netctl-auto \ + src/wifi-menu \ $(DESTDIR)/usr/bin/ - install -Dm755 scripts/ifplugd.action $(DESTDIR)/etc/ifplugd/netcfg.action - install -Dm755 scripts/pm-utils $(DESTDIR)/usr/lib/pm-utils/sleep.d/50netcfg - # Daemons - install -Dm755 rc.d/net-set-variable $(DESTDIR)/etc/rc.d/functions.d/net-set-variable - install -m755 \ - rc.d/net-profiles \ - rc.d/net-rename \ - rc.d/net-auto-wired \ - rc.d/net-auto-wireless \ - $(DESTDIR)/etc/rc.d/ + install -Dm755 src/ifplugd.action $(DESTDIR)/etc/ifplugd/netctl.action + # Services install -d $(DESTDIR)/usr/lib/systemd/system - install -m644 \ - systemd/*.service \ - $(DESTDIR)/usr/lib/systemd/system/ + install -m644 services/*.service $(DESTDIR)/usr/lib/systemd/system/ install-docs: docs - install -d $(DESTDIR)/usr/share/man/{man5,man8} + install -d $(DESTDIR)/usr/share/man/{man1,man5,man7} + install -m644 docs/*.1 $(DESTDIR)/usr/share/man/man1/ install -m644 docs/*.5 $(DESTDIR)/usr/share/man/man5/ - install -m644 docs/*.8 $(DESTDIR)/usr/share/man/man8/ - install -d $(DESTDIR)/usr/share/doc/netcfg/contrib - install -m644 contrib/{*.hook,pm-utils.handler} $(DESTDIR)/usr/share/doc/netcfg/contrib/ + install -m644 docs/*.7 $(DESTDIR)/usr/share/man/man7/ docs: $(MAKE) -C $@ -tarball: netcfg-$(VERSION).tar.xz -netcfg-$(VERSION).tar.xz: | docs - cp scripts/netcfg{,.orig} - sed -i "s/NETCFG_VER=.*/NETCFG_VER=$(VERSION)/" scripts/netcfg +tarball: netctl-$(VERSION).tar.xz +netctl-$(VERSION).tar.xz: | docs + cp src/netctl{,.orig} + sed -i "s/NETCTL_VERSION=.*/NETCTL_VERSION=$(VERSION)/" src/netctl git stash save -q - git archive -o netcfg-$(VERSION).tar --prefix=netcfg-$(VERSION)/ stash + git archive -o netctl-$(VERSION).tar --prefix=netctl-$(VERSION)/ stash git stash pop -q - mv scripts/netcfg{.orig,} - tar --exclude-vcs --transform "s%^%netcfg-$(VERSION)/%" --owner=root --group=root --mtime=./netcfg-$(VERSION).tar -rf netcfg-$(VERSION).tar docs/*.[1-8] - xz netcfg-$(VERSION).tar + mv src/netctl{.orig,} + tar --exclude-vcs --transform "s%^%netctl-$(VERSION)/%" --owner=root --group=root --mtime=./netctl-$(VERSION).tar -rf netctl-$(VERSION).tar docs/*.[1-8] + xz netctl-$(VERSION).tar pkgbuild: PKGBUILD -PKGBUILD: netcfg-$(VERSION).tar.xz +PKGBUILD: netctl-$(VERSION).tar.xz sed -e "s/%pkgver%/$(VERSION)/" -e "s/%md5sum%/$(shell md5sum $< | cut -d ' ' -f 1)/" contrib/PKGBUILD > $@ -upload: netcfg-$(VERSION).tar.xz - md5sum $< > MD5SUMS.$(VERSION) - scp $< MD5SUMS.$(VERSION) gerolde.archlinux.org:/srv/ftp/other/netcfg/ - clean: $(MAKE) -C docs clean - -@rm -vf PKGBUILD *.xz MD5SUMS.* 2>/dev/null + -@rm -vf PKGBUILD *.xz 2>/dev/null diff --git a/NEWS b/NEWS index 9dfe933..8c6149c 100644 --- a/NEWS +++ b/NEWS @@ -1,172 +1,2 @@ -version 3.1 -- reword systemd service descriptions -- fix support for 'last' when using systemd -- fix support for 'options' in /etc/resolv.conf - -version 3.0 -- drop a version number digit -- add support for 'options' in /etc/resolv.conf -- update rfkill implementation -- fix bond connections (FS#31770) -- assorted fixes - -version 2.8.11 -- add IPv6 support for PPPoE connections -- use a workound for a unit stopping bug in systemd - -version 2.8.10 -- allow hex passphrases in wifi-menu -- ifplugd path change for net-auto-wired (FS#31340) - -version 2.8.9 -- add priority support to net-auto-wireless (FS#30737) -- fix wifi-menu key handling (FS#31057) -- add systemd net-profiles symlink for compatibility - -version 2.8.8 -- fix killing wpa_actiond (FS#30664) -- fix tuntap without an IP (FS#30638) - -version 2.8.7 -- Fixed parsing of GROUP= part of ctrl_interface for custom wifi configurations - -version 2.8.6 -- Fixed key limitation test in wifi-menu -- Improved responsiveness for wireless networking -- Revised logic for wpa_supplicant configurations with non-standard control paths -- Code cleanup - -version 2.8.5 -- Provide the ability to start the last used profile (FS#23015) -- Support weird characters in wifi-menu (FS#30342) and elsewhere -- Fix net-auto-wired.service (FS#30348) -- Introduce polling timeout logic -- Increase default carrier timeout (FS#30361) - -version 2.8.4 -- fixed wait for wifi scan results (FS#29946) -- PPPoE default to noauth (FS#30016) -- stop waiting longer than necessary when bringing an interface up - -version 2.8.3 -- Duplicate Address Detection is dealt with for IPv6 users (FS#28887) - NOTE: IPCFG is now processed after IPv6 address set-up -- additional attributes in ADDR6 and ROUTES6 entries are now allowed -- initscripts sh compatibility is restored (FS#29880) -- a bonding documentation error is fixed (FS#29918) - -version 2.8.2 -- netcfg now has a website: www.archlinux.org/netcfg/ -- replace routes in IPv6 by default (FS#29480) -- fixes: pm-utils support is back, systemd improvements, documentation, FS#28522 - -version 2.8.1 -- add compatibility for configuration in /etc/rc.conf - give users time to move to the new scheme -- fix support for the kernel command line -- give initscripts users more familiar output - -version 2.8.0 -- end support for wireless-dbus and ethernet-iproute syntax - use wireless and ethernet instead -- end support for configuration in /etc/rc.conf - use /etc/conf.d/netcfg instead -- add sample script demonstrating firewall location handling (FS#26380) -- drop implicit dependency on initscripts -- add systemd service file for profiles (netcfg@.service) -- add systemd service file for NETWORKS array in /etc/conf.d/netcfg (netcfg.service) -- assorted fixes (FS#20569, FS#28138, FS#28590, FS#28683) - -version 2.7.3 -- fix dhcpcd to not remove/re-acquire a lease unnecessarily -- fix sysctl parameters for interfaces with vlans (FS#26259) - -version 2.7.2 -- fix bash completion -- discontinue "-old" connections - -version 2.7 -- add support for tunnel interfaces -- add support for interface bonding (FS#24802) -- add support for hexadecimal ESSIDs (FS#24333) -- add support for PPPoE connections -- add support for profile backgrounding in net-profiles (FS#23934) -- add interactive wifi connection tool wifi-menu -- add netcfg option to reconnect an interface (-R) (FS#28196) -- rename the option to disconnect an interface (was: -i, now: -D) -- stop suggesting profile-scripting through /etc/network.d/hooks as it was - unused and the {PRE,POST}_{UP,DOWN} variables work just fine (FS#27496) -- assorted fixes (FS#24599, FS#26370, FS#26607, FS#28022) - -version 2.6.8 -- fix broken 802.11 in non-wireless setups (FS#25473) -- fix rfkill errors in net-auto-wireless (FS#25514) -- fix error message about non-existing net.ipv6.conf... (FS#25530) - -version 2.6.7 -- fix wrong quoting of $profile (FS#25362) -- fix wrong parsing of wpa_supplicant configuration (FS#25464) -- fix conflict with old ROUTES variable (FS#25432) - -version 2.6.6 -- fix wrong rc scripts names in suspend hook (FS#20330) -- fix wireless failure when using wpa-config and a custom - ctrl_interface path (FS#24929) -- bash-completion: add -r to option list (FS#25188) - -version 2.6.5 -- specify device name explicitly when setting gateways - -version 2.6.4 -- documentation update, new man page "netcfg-profiles" -- modify wireless workflow to avoid issues with association - -version 2.6.3 -- fix infinite symlink loop (FS#25077) - -version 2.6.2 -- fix broken WEP support (FS#24896) -- fix dhcpcd/dhclient not stopped properly (FS#23293) -- fix specifying access point by BSSID (FS#24906) - -version 2.6.1 -- fix missing mkdir for net-auto-wireless -- add basic configuration capabilities to tun/tap interfaces - -version 2.6 -- add support for IPv6 configuration (FS#18699) -- add support for static routes configuration (FS#18700) -- add support for creating tun/tap interfaces (FS#15049) -- add configuration file /etc/conf.d/netcfg for net-auto-wireless -- add support for restricting automatic startup of profiles (FS#23169) -- bridge: add support for several brctl options (FS#16625) -- wireless: add support for explicit BSSID (FS#24582) -- wireless: add support for ad-hoc connections (FS#19683) -- wireless: no longer require wireless_tools to work -- use /run instead of /var/run -- drops hard dependency on net-tools package -- drops hard dependency on wireless_tools package - -version 2.5.5 -- new connection types: openvpn (FS#21490), vlan -- new option HIDDEN (for hidden SSIDs) -- new option SKIPNOCARRIER (FS#21755) -- default WPA driver is now nl80211 -- minor fixes and improvements (FS#17190, FS#17546, - FS#20150, FS#20569, FS#21377, FS#23293) -- better zsh completion file (FS#19823) - -netcfg 2.5.4 -- new connection type: bridge -- new option NETMASK for ethernet - -netcfg 2.5.3 -- fixes to rfkill handling (FS#18391, FS#18385) -- fix for FS#18411 - -netcfg 2.5.2 -- fix for FS#17190 - -netcfg 2.5.1 -- fix for FS#17190 -- additional examples +netctl 0.1 +- forked from netcfg 3.1 and changed considerably diff --git a/README b/README index f7d24e5..9b27fa6 100644 --- a/README +++ b/README @@ -1,26 +1,23 @@ Dependencies: -- Linux +- systemd - Bash 4.x - GNU Coreutils - iproute2 -- dialog: for interactive menu -- ifplugd: for automatic connection -- wireless_tools: for net_rename - -For DHCP support: -- dhcpcd -- dhclient (for DHCPv6) +- resolvconf -For wireless support: -- wpa_supplicant +Optional: +- dhcpcd or dhclient: for DHCP support +- wpa_supplicant: for WPA support +- dialog: for the interactive assistant +- ifplugd: for automatic connection - wpa_actiond: for automatic connection - -For bonding support -- ifenslave - -For bridge support: -- bridge-utils +- ifenslave: for bonding support +- bridge-utils: for bridge support For documentation generation: - asciidoc +Naming Conventions for Variables: +end-user variables - CamelCase +local variables - lower_case +other variables - UPPER_CASE diff --git a/config/iftab b/config/iftab deleted file mode 100644 index e016644..0000000 --- a/config/iftab +++ /dev/null @@ -1,20 +0,0 @@ -# Example iftab - -# Format: {New name} {Criteria} - -# Match on driver -#ipw0 driver ipw2100 -#eth9 driver ndiswrapper -#rl0 driver 8139too - -# Match on MAC address -#wlan0 mac 00:11:22:33:44:%5 -#eth1 mac 11:22:33:44:55:66 - -# Match on sysfs attribute -#myvpn SYSFS{address} 00:10:83:* - -# Automatically number -#eth* ipw2100 - -## More examples in 'man iftab' diff --git a/config/netcfg b/config/netcfg deleted file mode 100644 index 59ee57c..0000000 --- a/config/netcfg +++ /dev/null @@ -1,16 +0,0 @@ -# Enable these netcfg profiles at boot time. -# - prefix an entry with a '@' to background its startup -# - set to 'last' to restore the profiles running at the last shutdown -# - set to 'menu' to present a menu (requires the dialog package) -# Network profiles are found in /etc/network.d -NETWORKS=(last) - -# Specify the name of your wired interface for net-auto-wired -WIRED_INTERFACE="eth0" - -# Specify the name of your wireless interface for net-auto-wireless -WIRELESS_INTERFACE="wlan0" - -# Array of profiles that may be started by net-auto-wireless. -# When not specified, all wireless profiles are considered. -#AUTO_PROFILES=("profile1" "profile2") diff --git a/contrib/PKGBUILD b/contrib/PKGBUILD index 9ccc600..e743bfe 100644 --- a/contrib/PKGBUILD +++ b/contrib/PKGBUILD @@ -1,37 +1,32 @@ # Maintainer: Jouke Witteveen -pkgname=netcfg +pkgname=netctl pkgver=%pkgver% pkgrel=1 pkgdesc="Network configuration and profile scripts" -url="http://archlinux.org/netcfg/" -license=("BSD") -backup=(etc/iftab etc/conf.d/netcfg) -groups=(base) -depends=("coreutils" "dhcpcd" "iproute2") +url="http://archlinux.org/netctl/" +license=("GPL") +depends=("coreutils" "iproute2" "openresolv") #makedepends=('asciidoc') # The source tarball includes pre-built documentation. -optdepends=('dialog: for the menu based profile and wifi selectors' +optdepends=('dialog: for the menu based wifi assistant' + 'dhclient: for DHCP support (or dhcpcd)' + 'dhcpcd: for DHCP support (or dhclient)' 'wpa_supplicant: for wireless networking support' - 'ifplugd: for automatic wired connections through net-auto-wired' - 'wpa_actiond: for automatic wireless connections through net-auto-wireless' - 'wireless_tools: for interface renaming through net-rename' + 'ifplugd: for automatic wired connections through netctl-ifplugd' + 'wpa_actiond: for automatic wireless connections through netctl-auto' 'ifenslave: for bond connections' 'bridge-utils: for bridge connections' ) -source=(ftp://ftp.archlinux.org/other/netcfg/netcfg-${pkgver}.tar.xz) +conflicts=("netcfg") +source=(ftp://ftp.archlinux.org/other/netctl/netctl-${pkgver}.tar.xz) arch=(any) md5sums=('%md5sum%') package() { - cd "$srcdir/netcfg-${pkgver}" + cd "$srcdir/netctl-${pkgver}" make DESTDIR="$pkgdir" install - install -D -m644 LICENSE "$pkgdir/usr/share/licenses/netcfg/LICENSE" # Shell Completion - install -D -m644 contrib/bash-completion "$pkgdir/usr/share/bash-completion/completions/netcfg" - install -D -m644 contrib/zsh-completion "$pkgdir/usr/share/zsh/site-functions/_netcfg" - - # Compatibility - ln -s netcfg.service "$pkgdir/usr/lib/systemd/system/net-profiles.service" + install -D -m644 contrib/bash-completion "$pkgdir/usr/share/bash-completion/completions/netctl" } diff --git a/contrib/iptables.hook b/contrib/iptables.hook deleted file mode 100755 index 95546ba..0000000 --- a/contrib/iptables.hook +++ /dev/null @@ -1,17 +0,0 @@ -### Sample netcfg hook script for location based firewall rules. -### To install, make this executable and put it in /usr/lib/network/hooks - -### USAGE -## You need to have iptables installed to use this script. -## Add a location to your network profile and add firewall to your POST_UP. -## The iptables setup in /etc/iptables/$LOCATION.rules will now be loaded -## automatically when a connection is established. -## -## Sample excerpt from the profile: -## LOCATION="library" -## POST_UP="firewall" - -function firewall { - /usr/sbin/iptables-restore < "/etc/iptables/$LOCATION.rules" -} - diff --git a/contrib/logging.hook b/contrib/logging.hook deleted file mode 100755 index 82d0ed1..0000000 --- a/contrib/logging.hook +++ /dev/null @@ -1,86 +0,0 @@ -### Sample netcfg hook script for logging/debugging connections -### To install, make this executable and put it in /usr/lib/network/hooks - - -. /etc/rc.conf -. /etc/rc.d/functions - - -# if NETCFG_DEBUG is set, debugging messages go to stderr instead of syslog - -# What facility to send log messages to? if set to "", nothing will be sent to syslog -NETCFG_LOG="${NETCFG_LOG-local0}" - - - -function report_log { - if [[ -n "$NETCFG_LOG" ]]; then - local caller level="$1" - shift - case "$0" in - net-auto|netcfg-auto-*) caller=net-auto;; - net-profiles) caller=net-profiles;; - net-rename) caller=net-rename;; - *) caller=netcfg;; - esac - logger -p "${NETCFG_LOG}.$level" -t "$caller" -- "$*" - fi -} - - -function report_err { - report_log err "$*" - printhl "$*" -} - - -function report_notice { - report_log notice "$*" - # print "$*" >&2 - checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 -} - - -function report_debug { - if checkyesno "$NETCFG_DEBUG"; then - echo "DEBUG: $*" >&2 - else - report_log debug "$*" - fi -} - - -function report_try { - report_log notice "trying $*..." - stat_busy "$*" - REPORT_TRYING=1 -} - - -function report_fail { - if [[ -n "$*" ]]; then - report_log err "$*" - if [[ -n "$REPORT_TRYING" ]]; then - stat_append "- $*" - REPORT_TRYING= - stat_fail - else - printhl "$*" - fi - elif [[ -n "$REPORT_TRYING" ]]; then - REPORT_TRYING= - stat_fail - fi -} - - -function report_success { - if [[ -n "$*" ]]; then - stat_append "- $*" - REPORT_TRYING= - fi - report_log notice "${*:-succeeded}" - stat_done -} - -# vim: ft=sh ts=4 et sw=4: diff --git a/contrib/pm-utils.handler b/contrib/pm-utils.handler deleted file mode 100755 index 378d32d..0000000 --- a/contrib/pm-utils.handler +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -. /usr/lib/pm-utils/functions - -[[ -f /usr/lib/network/network ]] || exit $NA -. /usr/lib/network/network -. /etc/conf.d/netcfg - -WIRELESS_INTERFACE=${WIRELESS_INTERFACE:-wlan0} - -auto_resume() -{ - if checkyesno ${RESTOREPROFILES:-no}; then - all_resume - sleep 2 - fi - restartservice net-auto-wireless - restartservice net-auto-wired - restartservice net-profiles -} - -daemon_suspend_all() -{ - stopservice net-auto-wireless - stopservice net-auto-wired - stopservice net-profiles -} - -case "$1" in - hibernate|suspend_hybrid|suspend) - report_notice "suspending all interfaces..." - daemon_suspend_all - if checkyesno "${RESTOREPROFILES:-no}"; then - interface_suspend all - fi - ;; - thaw|resume) - if [ -f "$STATE_DIR/interface/${WIRELESS_INTERFACE}" ]; then - report_notice "resuming all interfaces..." - auto_resume ${WIRELESS_INTERFACE} - else - report_notice "resuming all interfaces except wireless..." - all_resume ${WIRELESS_INTERFACE} - fi - ;; - radio_off) - report_notice "suspending wireless interface..." - interface_suspend ${WIRELESS_INTERFACE} no - set_iface disabled ${WIRELESS_INTERFACE} - bring_interface forcedown ${WIRELESS_INTERFACE} - ;; - radio_on) - report_notice "resuming wireless interface..." - auto_resume ${WIRELESS_INTERFACE} - if [ -x /etc/pm/power.d/??wifi ]; then - /usr/bin/on_ac_power # this is in pm-utils - case $? in - 0) # on ac - /etc/pm/power.d/??wifi false - ;; - 1) # on battery - /etc/pm/power.d/??wifi true - ;; - esac - fi - ;; - *) - ;; -esac - -exit $? - -# vim: ft=sh ts=4 et sw=4: diff --git a/contrib/zsh-completion b/contrib/zsh-completion deleted file mode 100644 index e05e183..0000000 --- a/contrib/zsh-completion +++ /dev/null @@ -1,52 +0,0 @@ -#compdef netcfg -local -a disp - -all_options() { - local _subcommands - _subcommands=('list:List all available profiles' - 'current:Report currently running profiles' - 'check-iface:Start the specified profile, only if its interface is not currently up' - 'up:Start the specified profile' - 'reconnect:Disconnect and reconnect the specified profile' - 'iface-recon:Reconnect profile active on specified interface' - 'down:Stop the specified profile' - 'iface-down:Stop the profile up on the specified interface' - 'all-down:Stop all connected profiles' - 'all-suspend:Suspend and store the name of all active profiles' - 'all-resume:Reconnect any profiles that have been suspended') - - _path_files -W "/etc/network.d" -g "*(.)" - _describe 'subcommand' _subcommands -} - -all_profiles() { - _path_files -W "/etc/network.d" -g "*(.)" -} - -up_profiles() { - _files -W "/run/network/profiles" -} - -up_ifaces() { - _files -W "/run/network/interfaces" -} - -_arguments -C \ -'(- *)-l[List all available profiles]' \ -'(- *)-c[Start the specified profile, only if its interface is not currently up]:Network profile:all_profiles' \ -'(- *)-u[Start specified profile]:Network profile:all_profiles' \ -'(- *)-r[Disconnect and reconnect the specified profile]:Active profiles:up_profiles' \ -'(- *)-R[Reconnect profile active on specified interface]:Active interface:up_ifaces' \ -'(- *)-d[Take specified profile down]:Active profile:up_profiles' \ -'(- *)-D[Take down profile active on specified interface]:Active interface:up_ifaces' \ -'(- *)-a[Take all active profiles down]' \ -'(- *)*:All options:all_options' - -if [[ ${#words} == 3 ]]; then - case $words[2] in - 'check-iface' | 'up') all_profiles;; - 'reconnect' | 'down') up_profiles;; - 'iface-recon' | 'iface-down') up_ifaces;; - esac -fi - diff --git a/docs/Makefile b/docs/Makefile index ef05303..879e5ac 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,21 +1,12 @@ -# Makefile for netcfg documentation +# Makefile for netctl documentation -MANPAGES = netcfg.8 netcfg-profiles.5 -WEBPAGES = index.html features.html $(MANPAGES:%=%.html) +MANPAGES = netctl.1 netctl.profile.5 netctl.special.7 -.PHONY: manpages website clean +.PHONY: manpages clean manpages: $(MANPAGES) -website: website.tar.xz - -$(MANPAGES): %: %.txt footer.txt +$(MANPAGES): %: %.txt a2x -d manpage -f manpage -a manversion=$(VERSION) $< -$(WEBPAGES): %.html: %.txt - asciidoc -a disable-javascript -a linkcss -a max-width=960px $< - -website.tar.xz: $(WEBPAGES) - tar --transform "s%^%netcfg/%" -cJf $@ $^ -C /etc/asciidoc/stylesheets asciidoc.css - clean: - -@rm -vf $(MANPAGES) $(WEBPAGES) website.tar.xz 2>/dev/null + -@rm -vf $(MANPAGES) 2>/dev/null diff --git a/docs/examples/openvpn b/docs/examples/openvpn deleted file mode 100644 index b6106aa..0000000 --- a/docs/examples/openvpn +++ /dev/null @@ -1,5 +0,0 @@ -CONNECTION="openvpn" -INTERFACE="ignore" -OVPN_CONFIG="/etc/openvpn/example/openvpn.conf" -OVPN_PID_FILE="/tmp/openvpn.example.pid" -OVPN_FLAGS="" diff --git a/docs/examples/ppp b/docs/examples/ppp deleted file mode 100644 index dfb6bc1..0000000 --- a/docs/examples/ppp +++ /dev/null @@ -1,4 +0,0 @@ -CONNECTION='ppp' -INTERFACE='ignore' -PEER='provider' -PPP_TIMEOUT=10 diff --git a/docs/features.txt b/docs/features.txt deleted file mode 100644 index 4cf7def..0000000 --- a/docs/features.txt +++ /dev/null @@ -1,147 +0,0 @@ -Netcfg Features ---------------- - -Network Profile management -~~~~~~~~~~~~~~~~~~~~~~~~~~ -netcfg is profile based. Each network has an individual profile. These -profiles can be individually connected/disconnected at any time. The -profile configuration varies depending on whether it's a wireless, -ethernet (wired) or other type of connection. The available options are -documented on the netcfg website and in the included examples. The -installed and available connection types can be seen at -'/usr/lib/network/connections/' - -To connect to a profile called `mynetwork' which would be located at -'/etc/network.d/mynetwork', you may run: - ----------------- -netcfg mynetwork ----------------- - -To disconnect from the same profile you could run one of: - ---------------------- -netcfg -d mynetwork -netcfg down mynetwork ---------------------- - -To reconnect: - -------------------- -netcfg -r mynetwork -------------------- - -For more options, see ''netcfg help'' - - -Start a specific list of profiles on boot -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -net-profiles allows you to start some profiles at boot time. Specify the -profiles you want netcfg to start (in the order you want them to be -started) in the +NETWORKS+ line in '/etc/conf.d/netcfg'. -Prefix a profile with a `@' to start it in the background. For example: - --------------------------------- -NETWORKS=(@adsl @mywireless lan) --------------------------------- - -Alternatively, you can have netcfg restart the profiles you had running -at the previous shutdown by specifying +NETWORKS=(last)+. - -Next, enable the `netcfg' systemd service or, on legacy systems, add -`net-profiles' to +DAEMONS+ in '/etc/rc.conf'. - - -Wireless automatic connection and roaming support -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Through the use of wpa_actiond which calls commands on a wpa_supplicant -event, netcfg now has automatic connection and roaming support. - -To use this: - -. Install core/wpa_actiond -. In '/etc/conf.d/netcfg' set +WIRELESS_INTERFACE+ to your wireless interface, eg: -+ ---------------------------- -WIRELESS_INTERFACE="wlan0" ---------------------------- -. Run `systemctl start net-auto-wireless` - -To run on boot, enable the `net-auto-wireless' systemd service. - - -Per interface configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Configuration that applies to all profiles using an interface can be set -at '/etc/network.d/interfaces/$INTERFACE'. For example: - ------------------------------- -/etc/network.d/interfaces/eth0 ------------------------------- - -This is useful for wpa_supplicant options, radio kill switch support, -pre/post up/down scripts and net-auto-wireless. It is loaded before a -profile is loaded so that any profile based options will take priority. - - -Execute commands before/after interface up/down -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If your interface requires special actions prior/after the -establishment/closure of a connection, you may use the +PRE_UP+, POST_UP, -+PRE_DOWN+, +POST_DOWN+ properties. For example, if you want to run a -script before connecting: - ------------------------- -PRE_UP="/path/to/script" ------------------------- - -Or if you want to manage resolv.conf through resolvconf, you could -remove any DNS related options and use the following, which will be run -after a successful connection: - ----------------------------------------------------------------- -POST_UP='echo "nameserver 8.8.8.8" | resolvconf -a "$INTERFACE"' ----------------------------------------------------------------- - -If the commands specified in these properties return anything other than -0 (success), netcfg aborts the current operation. If you command might -fail, create a separate bash script with an "exit 0;" at the end. -Alternatively you may add "|| true" to the end of the command that may -fail. - - -Output Hooks -~~~~~~~~~~~~ -netcfg has limited support to load hooks that handle output. By default -it loads the "arch" hook which provides the familiar output that you -see. A syslog logging hook is also included. These can be found at -'/usr/lib/network/hooks/' - - -Menu based profile selection -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -You may select a profile to connect to from a menu. This requires the -'dialog' package installed. To display a menu, simply run `netcfg-menu`. -If you wish to have a menu on boot, set +NETWORKS=(menu)+ in your -'/etc/conf.d/netcfg' and ensure that `net-profiles' is in the +DAEMONS+ -array. A boot-time menu is not supported on systemd installations. - - -Menu based wireless network selection -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -You can also connect to a wireless network using a menu. To display the -menu, run `wifi-menu [-o] [interface]`. The _interface_ defaults to the -+WIRELESS_INTERFACE+ from '/etc/conf.d/netcfg'. When `-o' is specified, -passwords are obscured (ie masked and saved in hexadecimal form). The -tool generates a profile file if no suitable profile was found. - - -Debugging -~~~~~~~~~ -To run netcfg with debugging output, set the NETCFG_DEBUG environment -variable to "yes", for example: - -------------------------------------- -NETCFG_DEBUG="yes" netcfg -------------------------------------- - diff --git a/docs/footer.txt b/docs/footer.txt deleted file mode 100644 index c9efbad..0000000 --- a/docs/footer.txt +++ /dev/null @@ -1,22 +0,0 @@ -More information can be found at **. - - -BUGS ----- -For bugtracking, ** is used. - - -AUTHORS -------- -netcfg has many contributors. -For a list of contributors, use `git shortlog -s` on the netcfg.git repository. - -Current maintainer: - -* Jouke Witteveen - -Past maintainers: - -* Rémy Oudompheng -* James Rayner - diff --git a/docs/index.txt b/docs/index.txt deleted file mode 100644 index 10ba380..0000000 --- a/docs/index.txt +++ /dev/null @@ -1,57 +0,0 @@ -netcfg home page ----------------- - -About -~~~~~ -netcfg is profile based network connection tool. It can connect to a -variety of connections (including wired, wireless and PPP) and is easily -extended to support other connection types. - - -Features -~~~~~~~~ - -* Easy configuration -* Wireless, wired and ppp connections -* Wireless roaming and automatic connection (using wpa_actiond/wpa_supplicant) -* Radio kill switch (rfkill) awareness -* pm-utils suspend/resume support -* Execution of commands before/after up/down -* Wired link detection (using ifplugd) -* Modern iproute and wpa_supplicant based connectivity - - -Optional dependencies -~~~~~~~~~~~~~~~~~~~~~ - -* wpa_supplicant: for wireless networking -* wpa_actiond: Wireless Roaming/autoconnect -* ifplugd: Wired link detection -* dialog: Menu support -* bridge-utils: To set up bridge connections - - -Documentation -~~~~~~~~~~~~~ - -* https://wiki.archlinux.org/index.php/Netcfg[Arch Linux Wiki page] -* link:features.html[Feature documentation] -* link:netcfg.8.html[netcfg man page] -* link:netcfg-profiles.5.html[netcfg-profiles man page] - - -Contact -~~~~~~~ - -To report bugs or issues with netcfg, please use the -https://bugs.archlinux.org[Arch Linux Bug Tracker] - -To seek help using netcfg, please post on the -https://bbs.archlinux.org[Arch Linux Forums] - - -Copyright -~~~~~~~~~ -netcfg is Copyright (C) 2011-2012, Netcfg Development Team -and Copyright (C) 2007-2010 James Rayner -and is licensed through the Modified BSD License. diff --git a/docs/netcfg-profiles.5.txt b/docs/netcfg-profiles.5.txt deleted file mode 100644 index f929e47..0000000 --- a/docs/netcfg-profiles.5.txt +++ /dev/null @@ -1,321 +0,0 @@ -NETCFG-PROFILES(5) -================== - -NAME ----- -netcfg-profiles - netcfg profiles documentation and syntax - - -DESCRIPTION ------------ -The *netcfg*(8) profiles are plain text files that defines variables for -netcfg behavior. They must be compliant with *bash*(1) shell syntax and -usually do not execute any code. - -They are named '/etc/network.d/$\{profile_name}', where -+$\{profile_name\}+ must not contain a newline character and should not -start with the `@'-sign. - - -OVERVIEW --------- -Profiles must define mandatory variables: - -+INTERFACE+:: - The name of the associated network interface. -+DESCRIPTION+:: - A description of the profile. -+CONNECTION+:: - The connection type used by the profile. - -Connections define how the network is set up for the profile and also -determine additional configuration variable that control their -behavior. The available connection types are determined by files in -'/usr/lib/network/connections/'. - - -Available connections ---------------------- -ethernet:: - Standard network configuration, suitable for wired connections. -wireless:: - Wireless connection, with *wpa_supplicant*(1) as configuration - back-end. -bond:: - Bonded network interfaces using *ifenslave*. -bridge:: - Network bridge setup using *brctl*(8). -tuntap:: - TUN/TAP interfaces. -tunnel:: - Tunnel interfaces. -vlan:: - VLAN setup. -openvpn:: - OpenVPN setup. -ppp:: - PPP connections setup. -pppoe:: - PPPoE connections setup. - -The configuration variable for these connection types is described in -the following sections. - - -Ethernet options reference --------------------------- - -Description -~~~~~~~~~~~ -This connection method uses the iproute suite of tools and dhcpcd to -gain an IP address. - -+IP+ (required for IPv4):: - Either `static' or `dhcp'. Set to `no' to have netcfg bring the interface - up but assign no addresses. Static requires at least one of +ADDR+ or - +IPCFG+. - -IPv4 options -~~~~~~~~~~~~ -+ADDR+ (requires +IP+ of `static'):: - A single IP address to configure a static IP. -+GATEWAY+ (requires +IP+ of `static'):: - Set specified gateway -+NETMASK+ (requires +IP+ of `static'):: - Set specified netmask. Defaults to 24. -+ROUTES+:: - An array of custom routes (of the form _address range_ via _gateway_) - -IPv6 options -~~~~~~~~~~~~ -+IP6+ (required for IPv6):: - Either `dhcp', `dhcp-noaddr', `stateless', `static'. Set to `no' to - disable IPv6. -+ADDR6+ (required when +IP6+ is `static'):: - An array of IPv6 addresses: prefix length may be specified via - `1234:bcd::11/64' syntax. -+GATEWAY6+ (requires +IP6+ of `static'):: - The gateway address for IPv6 routing. -+ROUTES6+:: - An array of custom routes (of the form _address range_ via _gateway_) -+DAD_TIMEOUT+:: - Time to wait for Duplicate Address Detection to succeed. Defaults to - 3 seconds. - -DNS configuration -^^^^^^^^^^^^^^^^^ -+DNS+:: - Array of DNS nameservers. Simply specify the IP's of each of the DNS - nameservers. -+DNS_OPTIONS+:: - Array of ``option'' lines for '/etc/resolv.conf' -+SEARCH+:: - ``search'' line for '/etc/resolv.conf' -+DOMAIN+:: - ``domain'' line for '/etc/resolv.conf' -+HOSTNAME+:: - Set the system hostname. Ensure any hostname is correctly referenced - in '/etc/hosts' - -DHCP configuration -^^^^^^^^^^^^^^^^^^ -+DHCP_OPTIONS+ (ipv4):: - String. Any extra arguments to pass to the dhcp client, presently - dhcpcd. -+DHCP_TIMEOUT+:: - Integer. Maximum time to try for a DHCP IP. Default is 10 seconds. -+DHCLIENT+:: - yes/no. Use dhclient instead of dhcpcd. Defaults to no -+DHCLIENT_OPTIONS+ (ipv4):: - String. Extra options to pass to dhclient for IPv4. -+DHCLIENT6_OPTIONS+ (ipv6):: - String. Extra options to pass to dhclient for IPv6. - -802.11x Authentication -^^^^^^^^^^^^^^^^^^^^^^ -+AUTH8021X+:: - Use 802.11x authentication. Enable with `yes'. -+WPA_CONF+ (required for an +AUTH8021X+ of `yes' only):: - Path to wpa_supplicant configuration. Defaults to - '/etc/wpa_supplicant.conf' -+WPA_OPTS+ (optional for an +AUTH8021X+ of `yes'):: - Extra arguments for wpa_supplicant not specified otherwise. Any option - here must specify wpa_supplicant driver. Defaults to _-Dwired_. - -Miscellaneous options -^^^^^^^^^^^^^^^^^^^^^ -+IPCFG+:: - Array of arguments to pass to `ip`. The power of this options is that - it allows both simple and complicated routing configurations, within - the framework of netcfg. -+SKIPNOCARRIER+:: - `yes'/`no'. Don't abort interface setup if no carrier is found. - - -Examples -~~~~~~~~ - -Using ADDR and GATEWAY to set static IP and gateway -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ---------------------- -IP="static" -ADDR="192.168.1.23" -GATEWAY="192.168.1.1" ---------------------- - -Using IPCFG to set a static IP and gateway with custom DNS -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -------------------------------------------------------------------------------------- -IP="static" -IPCFG=("addr add dev eth0 192.168.1.23/24 brd +" "route add default via 192.168.1.1") -DNS=("208.67.222.222" "208.67.220.220") -------------------------------------------------------------------------------------- - - -Wireless options reference --------------------------- - -Description -~~~~~~~~~~~ -This connection method uses wpa_supplicant to configure a wireless -network connection. This connection uses the 'ethernet' connection after -successful association and thus supports all of its options. - -Options -~~~~~~~ -+SECURITY+ (required for security of `wep', `wpa', `wpa-configsection' or `wpa-config'):: - One of `wpa', `wep', `none', `wpa-configsection' or `wpa-config'. - Defaults to `none'. -+KEY+ (required for +SECURITY+ of `wpa' or `wep' only):: - Wireless encryption key. -+ESSID+ (this or +AP+ is required):: - Name of network to connect to, or hexadecimal digits (see - `ESSID_TYPE') -+ESSID_TYPE+ (optional, defaults to `ascii'):: - Set to `ascii' or `hex', if set to `hex', +ESSID+ will be interpreted as - an hexadecimal +SSID+ and written unquoted to the wpa_supplicant - configuration file. -+AP+ (this or +ESSID+ is required):: - AP (BSSID) of the network to connect to. -+HIDDEN+ (optional):: - Define this to connect to hidden ESSIDs. -+ADHOC+ (optional):: - Define this to use ad-hoc mode for wireless. -+TIMEOUT+ (optional):: - Time to wait for association. Defaults to 15 seconds. -+SCAN+ (optional):: - `yes'/`no'. Scan for a wireless network rather than blindly attempting to - connect. Hidden SSID networks do not appear in a scan. -+PRIORITY+ (optional):: - Priority group for the network. The matched network with the highest - priority will be selected. Defaults to 0. - -WPA options -^^^^^^^^^^^ -+WPA_CONF+ (for +SECURITY+ of `wpa-config' only):: - Path to wpa_supplicant configuration. Defaults to - '/etc/wpa_supplicant.conf' -+WPA_OPTS+:: - Extra arguments for wpa_supplicant not specified otherwise. -+WPA_GROUP+:: - Group that has authority to configure wpa_supplicant via it's control - interface. Used in any configuration that is generated by netcfg. -+WPA_COUNTRY+ (optional, nl80211 based drivers):: - The country where the device will be used. This allows wpa_supplicant - to enforce any local regulatory limitations and will allow all - appropriate channels/frequencies for your device. -+WPA_DRIVER+ (optional):: - A comma-separated list of wpa_supplicant driver interfaces to try. - Defaults to `nl80211,wext'. - -rfkill (Radio Kill Switch) options -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -+RFKILL+:: - hard/soft A switch with physical on/off state that cannot be - controlled via software is considered a *hard* switch. Any switch that - can be controlled via software is considered *soft*. -+RFKILL_NAME+:: - Some switches sysfs entries are not linked with the interface. To - match them up, configure the name from '/sys/class/rfkill/rfkillX/name' - here so that netcfg can identify which to control. - - -Options for `bridge' connections --------------------------------- -The options of `ethernet' connections apply to set up standard IP -connectivity. - -+BRIDGE_INTERFACES+:: - List of network interfaces taking part in the bridge. -+FWD_DELAY+:: - Forward delay of the bridge, see *brctl*(8) -+MAX_AGE+:: - maxage parameter, see *brctl*(8) - - -Options for `tuntap' connections --------------------------------- -The options of `ethernet' connections apply to set up standard IP -connectivity. - -+MODE+:: - Set to `tun' or `tap'. -+USER+:: - The owning user of the tun/tap interface. -+GROUP+:: - The owning group of the tun/tap interface. - - -Options for `ppp' connections ------------------------------ -+PEER+:: - The *pppd*(8) peer to use. -+PPP_TIMEOUT+:: - *pppd*(8) timeout. - - -Options for `vlan' connections ------------------------------- -+INTERFACE+:: - The name of the virtual interface. -+VLAN_PHYS_DEV+:: - The name of the associated physical interface. -+VLAN_ID+:: - See *ip*(8). - - -Options for `tunnel' connections --------------------------------- -Standard `ethernet' options apply for IP configuration. - -+INTERFACE+:: - The name of the tunnel interface. -+MODE+:: - The tunnel type (e.g. `sit'). See *ip*(8) for available modes. -+LOCAL+:: - The address of the local end of the tunnel. -+REMOTE+:: - The address of the remote end of the tunnel. - - -Options for `bond' connections ------------------------------- -Standard `ethernet' options apply for IP configuration. - -+SLAVE_INTERFACES+ (Bash array):: - An array of names of interfaces to be bound together. - - -Options for `openvpn' connections ---------------------------------- -+OVPN_CONFIG+:: - Path to the *openvpn*(8) config file. -+OVPN_PID_FILE+:: - Path to the *openvpn*(8) PID file. -+OVPN_FLAGS+:: - Options to pass to *openvpn*(8) invocation. - - -SEE ALSO --------- -include::footer.txt[] diff --git a/docs/netcfg.8.txt b/docs/netcfg.8.txt deleted file mode 100644 index 54fbd78..0000000 --- a/docs/netcfg.8.txt +++ /dev/null @@ -1,91 +0,0 @@ -NETCFG(8) -========= - -NAME ----- -netcfg - start/stop/control network profiles - - -SYNOPSIS --------- -netcfg [_options_] - -netcfg *profile* - - -DESCRIPTION ------------ -*netcfg* is used to configure and manage network connections via -profiles. It has pluggable support for a range of connection types, such -as wireless, ethernet, ppp. It is also capable of starting/stopping many -to one connections, that is, multiple connections within the same -profile, optionally with bonding. - -It may be run at boot, by enabling the 'netcfg' systemd service, or, on -legacy systems, by adding 'net-profiles' to +DAEMONS+ in '/etc/rc.conf'. -After boot time, it may be used to start profiles, simply by passing only -the profile name. - -When run without options, `netcfg profile` is equivalent to `netcfg -u -profile`. - - -OPTIONS -------- -*-l, list*:: - List all available profiles -*current*:: - Report currently running profiles -*-c, check-iface* _profile_:: - Start the specified profile, only if it's interface is not currently up. -*-u, up* _profile_:: - Start the specified profile -*-r, reconnect* _profile_:: - Disconnect and reconnect the specified profile -*-R, iface-recon* _interface_:: - Reconnect profile active on specified interface -*-d, down* _profile_:: - Stop the specified profile -*-D, iface-down* _interface_:: - Stop the profile up on the specified interface. -*-a, all-down*:: - Stop all connected profiles -*all-suspend*:: - Suspend and store the name of all active profiles. -*all-resume*:: - Reconnect any profiles that have been suspended. -*-v, --version*:: - Display version information and exit -*-h, --help*:: - Display help message and exit - - -CONFIGURATION FILES -------------------- -'/etc/conf.d/netcfg':: - Parameters for startup. -'/etc/network.d/':: - User-defined profiles. - - -FILES ------ -'/usr/lib/network/connections/':: - Currently installed network profile types. -'/etc/network.d/examples/':: - Example profiles. -'/usr/share/doc/netcfg/contrib/':: - Inspirational scripts. - - -ENVIRONMENT VARIABLES ---------------------- -+NETCFG_DEBUG+:: - Set to 1 to activate debug output. - - -SEE ALSO --------- -*netcfg-profiles*(5) on how to configure netcfg. - -include::footer.txt[] diff --git a/docs/netctl.1.txt b/docs/netctl.1.txt new file mode 100644 index 0000000..54fbd78 --- /dev/null +++ b/docs/netctl.1.txt @@ -0,0 +1,91 @@ +NETCFG(8) +========= + +NAME +---- +netcfg - start/stop/control network profiles + + +SYNOPSIS +-------- +netcfg [_options_] + +netcfg *profile* + + +DESCRIPTION +----------- +*netcfg* is used to configure and manage network connections via +profiles. It has pluggable support for a range of connection types, such +as wireless, ethernet, ppp. It is also capable of starting/stopping many +to one connections, that is, multiple connections within the same +profile, optionally with bonding. + +It may be run at boot, by enabling the 'netcfg' systemd service, or, on +legacy systems, by adding 'net-profiles' to +DAEMONS+ in '/etc/rc.conf'. +After boot time, it may be used to start profiles, simply by passing only +the profile name. + +When run without options, `netcfg profile` is equivalent to `netcfg -u +profile`. + + +OPTIONS +------- +*-l, list*:: + List all available profiles +*current*:: + Report currently running profiles +*-c, check-iface* _profile_:: + Start the specified profile, only if it's interface is not currently up. +*-u, up* _profile_:: + Start the specified profile +*-r, reconnect* _profile_:: + Disconnect and reconnect the specified profile +*-R, iface-recon* _interface_:: + Reconnect profile active on specified interface +*-d, down* _profile_:: + Stop the specified profile +*-D, iface-down* _interface_:: + Stop the profile up on the specified interface. +*-a, all-down*:: + Stop all connected profiles +*all-suspend*:: + Suspend and store the name of all active profiles. +*all-resume*:: + Reconnect any profiles that have been suspended. +*-v, --version*:: + Display version information and exit +*-h, --help*:: + Display help message and exit + + +CONFIGURATION FILES +------------------- +'/etc/conf.d/netcfg':: + Parameters for startup. +'/etc/network.d/':: + User-defined profiles. + + +FILES +----- +'/usr/lib/network/connections/':: + Currently installed network profile types. +'/etc/network.d/examples/':: + Example profiles. +'/usr/share/doc/netcfg/contrib/':: + Inspirational scripts. + + +ENVIRONMENT VARIABLES +--------------------- ++NETCFG_DEBUG+:: + Set to 1 to activate debug output. + + +SEE ALSO +-------- +*netcfg-profiles*(5) on how to configure netcfg. + +include::footer.txt[] diff --git a/docs/netctl.profile.5.txt b/docs/netctl.profile.5.txt new file mode 100644 index 0000000..f929e47 --- /dev/null +++ b/docs/netctl.profile.5.txt @@ -0,0 +1,321 @@ +NETCFG-PROFILES(5) +================== + +NAME +---- +netcfg-profiles - netcfg profiles documentation and syntax + + +DESCRIPTION +----------- +The *netcfg*(8) profiles are plain text files that defines variables for +netcfg behavior. They must be compliant with *bash*(1) shell syntax and +usually do not execute any code. + +They are named '/etc/network.d/$\{profile_name}', where ++$\{profile_name\}+ must not contain a newline character and should not +start with the `@'-sign. + + +OVERVIEW +-------- +Profiles must define mandatory variables: + ++INTERFACE+:: + The name of the associated network interface. ++DESCRIPTION+:: + A description of the profile. ++CONNECTION+:: + The connection type used by the profile. + +Connections define how the network is set up for the profile and also +determine additional configuration variable that control their +behavior. The available connection types are determined by files in +'/usr/lib/network/connections/'. + + +Available connections +--------------------- +ethernet:: + Standard network configuration, suitable for wired connections. +wireless:: + Wireless connection, with *wpa_supplicant*(1) as configuration + back-end. +bond:: + Bonded network interfaces using *ifenslave*. +bridge:: + Network bridge setup using *brctl*(8). +tuntap:: + TUN/TAP interfaces. +tunnel:: + Tunnel interfaces. +vlan:: + VLAN setup. +openvpn:: + OpenVPN setup. +ppp:: + PPP connections setup. +pppoe:: + PPPoE connections setup. + +The configuration variable for these connection types is described in +the following sections. + + +Ethernet options reference +-------------------------- + +Description +~~~~~~~~~~~ +This connection method uses the iproute suite of tools and dhcpcd to +gain an IP address. + ++IP+ (required for IPv4):: + Either `static' or `dhcp'. Set to `no' to have netcfg bring the interface + up but assign no addresses. Static requires at least one of +ADDR+ or + +IPCFG+. + +IPv4 options +~~~~~~~~~~~~ ++ADDR+ (requires +IP+ of `static'):: + A single IP address to configure a static IP. ++GATEWAY+ (requires +IP+ of `static'):: + Set specified gateway ++NETMASK+ (requires +IP+ of `static'):: + Set specified netmask. Defaults to 24. ++ROUTES+:: + An array of custom routes (of the form _address range_ via _gateway_) + +IPv6 options +~~~~~~~~~~~~ ++IP6+ (required for IPv6):: + Either `dhcp', `dhcp-noaddr', `stateless', `static'. Set to `no' to + disable IPv6. ++ADDR6+ (required when +IP6+ is `static'):: + An array of IPv6 addresses: prefix length may be specified via + `1234:bcd::11/64' syntax. ++GATEWAY6+ (requires +IP6+ of `static'):: + The gateway address for IPv6 routing. ++ROUTES6+:: + An array of custom routes (of the form _address range_ via _gateway_) ++DAD_TIMEOUT+:: + Time to wait for Duplicate Address Detection to succeed. Defaults to + 3 seconds. + +DNS configuration +^^^^^^^^^^^^^^^^^ ++DNS+:: + Array of DNS nameservers. Simply specify the IP's of each of the DNS + nameservers. ++DNS_OPTIONS+:: + Array of ``option'' lines for '/etc/resolv.conf' ++SEARCH+:: + ``search'' line for '/etc/resolv.conf' ++DOMAIN+:: + ``domain'' line for '/etc/resolv.conf' ++HOSTNAME+:: + Set the system hostname. Ensure any hostname is correctly referenced + in '/etc/hosts' + +DHCP configuration +^^^^^^^^^^^^^^^^^^ ++DHCP_OPTIONS+ (ipv4):: + String. Any extra arguments to pass to the dhcp client, presently + dhcpcd. ++DHCP_TIMEOUT+:: + Integer. Maximum time to try for a DHCP IP. Default is 10 seconds. ++DHCLIENT+:: + yes/no. Use dhclient instead of dhcpcd. Defaults to no ++DHCLIENT_OPTIONS+ (ipv4):: + String. Extra options to pass to dhclient for IPv4. ++DHCLIENT6_OPTIONS+ (ipv6):: + String. Extra options to pass to dhclient for IPv6. + +802.11x Authentication +^^^^^^^^^^^^^^^^^^^^^^ ++AUTH8021X+:: + Use 802.11x authentication. Enable with `yes'. ++WPA_CONF+ (required for an +AUTH8021X+ of `yes' only):: + Path to wpa_supplicant configuration. Defaults to + '/etc/wpa_supplicant.conf' ++WPA_OPTS+ (optional for an +AUTH8021X+ of `yes'):: + Extra arguments for wpa_supplicant not specified otherwise. Any option + here must specify wpa_supplicant driver. Defaults to _-Dwired_. + +Miscellaneous options +^^^^^^^^^^^^^^^^^^^^^ ++IPCFG+:: + Array of arguments to pass to `ip`. The power of this options is that + it allows both simple and complicated routing configurations, within + the framework of netcfg. ++SKIPNOCARRIER+:: + `yes'/`no'. Don't abort interface setup if no carrier is found. + + +Examples +~~~~~~~~ + +Using ADDR and GATEWAY to set static IP and gateway +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +--------------------- +IP="static" +ADDR="192.168.1.23" +GATEWAY="192.168.1.1" +--------------------- + +Using IPCFG to set a static IP and gateway with custom DNS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +------------------------------------------------------------------------------------- +IP="static" +IPCFG=("addr add dev eth0 192.168.1.23/24 brd +" "route add default via 192.168.1.1") +DNS=("208.67.222.222" "208.67.220.220") +------------------------------------------------------------------------------------- + + +Wireless options reference +-------------------------- + +Description +~~~~~~~~~~~ +This connection method uses wpa_supplicant to configure a wireless +network connection. This connection uses the 'ethernet' connection after +successful association and thus supports all of its options. + +Options +~~~~~~~ ++SECURITY+ (required for security of `wep', `wpa', `wpa-configsection' or `wpa-config'):: + One of `wpa', `wep', `none', `wpa-configsection' or `wpa-config'. + Defaults to `none'. ++KEY+ (required for +SECURITY+ of `wpa' or `wep' only):: + Wireless encryption key. ++ESSID+ (this or +AP+ is required):: + Name of network to connect to, or hexadecimal digits (see + `ESSID_TYPE') ++ESSID_TYPE+ (optional, defaults to `ascii'):: + Set to `ascii' or `hex', if set to `hex', +ESSID+ will be interpreted as + an hexadecimal +SSID+ and written unquoted to the wpa_supplicant + configuration file. ++AP+ (this or +ESSID+ is required):: + AP (BSSID) of the network to connect to. ++HIDDEN+ (optional):: + Define this to connect to hidden ESSIDs. ++ADHOC+ (optional):: + Define this to use ad-hoc mode for wireless. ++TIMEOUT+ (optional):: + Time to wait for association. Defaults to 15 seconds. ++SCAN+ (optional):: + `yes'/`no'. Scan for a wireless network rather than blindly attempting to + connect. Hidden SSID networks do not appear in a scan. ++PRIORITY+ (optional):: + Priority group for the network. The matched network with the highest + priority will be selected. Defaults to 0. + +WPA options +^^^^^^^^^^^ ++WPA_CONF+ (for +SECURITY+ of `wpa-config' only):: + Path to wpa_supplicant configuration. Defaults to + '/etc/wpa_supplicant.conf' ++WPA_OPTS+:: + Extra arguments for wpa_supplicant not specified otherwise. ++WPA_GROUP+:: + Group that has authority to configure wpa_supplicant via it's control + interface. Used in any configuration that is generated by netcfg. ++WPA_COUNTRY+ (optional, nl80211 based drivers):: + The country where the device will be used. This allows wpa_supplicant + to enforce any local regulatory limitations and will allow all + appropriate channels/frequencies for your device. ++WPA_DRIVER+ (optional):: + A comma-separated list of wpa_supplicant driver interfaces to try. + Defaults to `nl80211,wext'. + +rfkill (Radio Kill Switch) options +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ++RFKILL+:: + hard/soft A switch with physical on/off state that cannot be + controlled via software is considered a *hard* switch. Any switch that + can be controlled via software is considered *soft*. ++RFKILL_NAME+:: + Some switches sysfs entries are not linked with the interface. To + match them up, configure the name from '/sys/class/rfkill/rfkillX/name' + here so that netcfg can identify which to control. + + +Options for `bridge' connections +-------------------------------- +The options of `ethernet' connections apply to set up standard IP +connectivity. + ++BRIDGE_INTERFACES+:: + List of network interfaces taking part in the bridge. ++FWD_DELAY+:: + Forward delay of the bridge, see *brctl*(8) ++MAX_AGE+:: + maxage parameter, see *brctl*(8) + + +Options for `tuntap' connections +-------------------------------- +The options of `ethernet' connections apply to set up standard IP +connectivity. + ++MODE+:: + Set to `tun' or `tap'. ++USER+:: + The owning user of the tun/tap interface. ++GROUP+:: + The owning group of the tun/tap interface. + + +Options for `ppp' connections +----------------------------- ++PEER+:: + The *pppd*(8) peer to use. ++PPP_TIMEOUT+:: + *pppd*(8) timeout. + + +Options for `vlan' connections +------------------------------ ++INTERFACE+:: + The name of the virtual interface. ++VLAN_PHYS_DEV+:: + The name of the associated physical interface. ++VLAN_ID+:: + See *ip*(8). + + +Options for `tunnel' connections +-------------------------------- +Standard `ethernet' options apply for IP configuration. + ++INTERFACE+:: + The name of the tunnel interface. ++MODE+:: + The tunnel type (e.g. `sit'). See *ip*(8) for available modes. ++LOCAL+:: + The address of the local end of the tunnel. ++REMOTE+:: + The address of the remote end of the tunnel. + + +Options for `bond' connections +------------------------------ +Standard `ethernet' options apply for IP configuration. + ++SLAVE_INTERFACES+ (Bash array):: + An array of names of interfaces to be bound together. + + +Options for `openvpn' connections +--------------------------------- ++OVPN_CONFIG+:: + Path to the *openvpn*(8) config file. ++OVPN_PID_FILE+:: + Path to the *openvpn*(8) PID file. ++OVPN_FLAGS+:: + Options to pass to *openvpn*(8) invocation. + + +SEE ALSO +-------- +include::footer.txt[] diff --git a/rc.d/net-auto-wired b/rc.d/net-auto-wired deleted file mode 100755 index 807bb22..0000000 --- a/rc.d/net-auto-wired +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -. /etc/rc.conf -. /etc/rc.d/functions -. /usr/lib/network/globals -. /etc/conf.d/netcfg - -if [[ ! -x /usr/bin/ifplugd ]]; then - exit_stderr "Please install 'ifplugd' to use net-auto-wired" -fi - -if [[ -z "${WIRED_INTERFACE}" ]]; then - exit_stderr "No interface name set. Add to /etc/conf.d/netcfg a line"$'\n' \ - " WIRED_INTERFACE='your_interface'" -fi - -CFG=/etc/ifplugd/ifplugd.conf -ACTION=/etc/ifplugd/netcfg.action -PIDFILE=/var/run/ifplugd.$WIRED_INTERFACE.pid -[[ -f $PIDFILE ]] && read PID < $PIDFILE - -# Source ifplugd configuration -[ -f $CFG ] && . $CFG - -case "$1" in - start) - if ! ck_daemon net-auto-wired; then - exit_stderr "net-auto-wired has already been started: try \"/etc/rc.d/net-auto-wired restart\"" - fi - stat_busy "Starting netcfg auto-wired mode for interface ${WIRED_INTERFACE}" - A="`eval echo \$\{ARGS_${WIRED_INTERFACE}\}`" - [[ "$A" ]] || A="$ARGS" - [[ "$PID" ]] || /usr/bin/ifplugd -i $WIRED_INTERFACE -r $ACTION $A - # ifplugd may return non-zero, but still succeed if -w is passed, as default in upstream config. - sleep 1 - if [[ -f $PIDFILE ]]; then - add_daemon net-auto-wired - stat_done - else - stat_fail - fi - ;; - stop) - if ! ck_daemon net-auto-wired; then - stat_busy "Stopping netcfg auto-wired mode for interface ${WIRED_INTERFACE}" - if [[ "$PID" ]] && /usr/bin/ifplugd -k -i $WIRED_INTERFACE -r $ACTION; then - rm_daemon net-auto-wired - stat_done - else - stat_fail - fi - fi - ;; - restart) - "$0" stop - sleep 1 - "$0" start - ;; - *) - echo "Usage: $0 {start|stop|restart}" -esac -exit 0 diff --git a/rc.d/net-auto-wireless b/rc.d/net-auto-wireless deleted file mode 100755 index 9094232..0000000 --- a/rc.d/net-auto-wireless +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -. /etc/rc.conf -. /etc/rc.d/functions -. /usr/lib/network/globals -. /etc/conf.d/netcfg - -if [[ ! -x /usr/sbin/wpa_actiond ]]; then - exit_stderr "Please install 'wpa_actiond' to use net-auto-wireless" -fi - -if [[ -z "${WIRELESS_INTERFACE}" ]]; then - exit_stderr "No interface name set. Add to /etc/conf.d/netcfg a line"$'\n' \ - " WIRELESS_INTERFACE='your_interface'" -fi - -case "$1" in - start) - if ! ck_daemon net-auto-wireless; then - exit_stderr "net-auto-wireless has already been started: try \"/etc/rc.d/net-auto-wireless restart\"" - fi - # Ensure any device renaming has occurred as intended - for daemon in "${DAEMONS[@]}"; do - if [[ "$daemon" = "net-rename" ]]; then - if ck_daemon net-rename; then - /etc/rc.d/net-rename start - fi - fi - done - - stat_busy "Starting netcfg auto-wireless mode for interface ${WIRELESS_INTERFACE}" - if /usr/bin/netcfg-wpa_actiond "${WIRELESS_INTERFACE}" >/dev/null; then - add_daemon net-auto-wireless - stat_done - else - stat_fail - fi - ;; - stop) - if ! ck_daemon net-auto-wireless; then - stat_busy "Stopping netcfg auto-wireless mode for interface ${WIRELESS_INTERFACE}" - if /usr/bin/netcfg-wpa_actiond stop "${WIRELESS_INTERFACE}" >/dev/null; then - rm_daemon net-auto-wireless - stat_done - else - stat_fail - fi - fi - ;; - restart) - "$0" stop - sleep 1 - "$0" start - ;; - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 - ;; -esac -exit 0 -# vim: ft=sh ts=4 et sw=4: diff --git a/rc.d/net-profiles b/rc.d/net-profiles deleted file mode 100755 index ae9c00e..0000000 --- a/rc.d/net-profiles +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -# -# This script utilizes netcfg-daemon. - -. /etc/rc.conf -. /etc/rc.d/functions -. /usr/lib/network/globals - -case "$1" in - start) - if ! ck_daemon net-profiles; then - exit_stderr "net-profiles has already been started. Try '/etc/rc.d/net-profiles restart'" - fi - - # Ensure any device renaming has occurred as intended - for daemon in "${DAEMONS[@]}"; do - if [[ $daemon = net-rename ]]; then - if ck_daemon net-rename; then - /etc/rc.d/net-rename start - fi - fi - done - - # $NET env var is passed from the kernel boot line - if [[ -n $NET ]]; then - # Record the connected profile for net-profiles stop - if [[ $NET = menu ]]; then - /usr/bin/netcfg-menu || exit 1 - mv "$STATE_DIR"/{menu,netcfg-daemon} - else - /usr/bin/netcfg check-iface "$NET" || exit 1 - echo "$NET" > "$STATE_DIR/netcfg-daemon" - fi - elif ! /usr/bin/netcfg-daemon start; then - exit_err "No profile started." - fi - add_daemon net-profiles - ;; - stop) - if ck_daemon net-profiles; then - exit_stderr "net-profiles is not running" - fi - /usr/bin/netcfg-daemon stop - rm_daemon net-profiles - ;; - restart) - "$0" stop - sleep 1 - "$0" start - ;; - *) - exit_stderr "Usage: $0 {start|stop|restart}" -esac - -# vim: ft=sh ts=4 et sw=4: diff --git a/rc.d/net-rename b/rc.d/net-rename deleted file mode 100755 index 42dfa23..0000000 --- a/rc.d/net-rename +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -. /etc/rc.conf -. /etc/rc.d/functions -. /usr/lib/network/globals - -case "$1" in - start) - report_try "Renaming network devices" - ifrename -p -t - report_success - - add_daemon net-rename - ;; - stop) - rm_daemon net-rename - # No stop neccesary, but add one to look nice on shutdown. - /bin/true - ;; - restart) - "$0" start - ;; - *) - exit_stderr "Usage: $0 {start|stop|restart}" - ;; -esac - -# vim: ft=sh ts=4 et sw=4: diff --git a/rc.d/net-set-variable b/rc.d/net-set-variable deleted file mode 100644 index d2d68fa..0000000 --- a/rc.d/net-set-variable +++ /dev/null @@ -1,10 +0,0 @@ -# Set the NET variable if specified on the kernel command line. - -net_set_variable() { - local re="\" - if [[ -f /proc/cmdline && $(< /proc/cmdline) =~ $re ]]; then - export NET=${BASH_REMATCH[1]} - fi -} - -add_hook multi_start net_set_variable diff --git a/scripts/ifplugd.action b/scripts/ifplugd.action deleted file mode 100755 index ea3a16c..0000000 --- a/scripts/ifplugd.action +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# -# ifplugd.action script for netcfg - -. /usr/lib/network/network - -case "$2" in - up) - # Look for a dhcp based profile to try first - # dhcp can actually outright fail, whereas - # it's difficult to tell if static succeeded - # Also check profile is same iface and is right connection - echo "up" - declare -a preferred_profiles - declare -a dhcp_profiles - declare -a static_profiles - for profile in $(list_profiles); do - ( - echo "loading $profile" - load_profile "$profile" - [[ "$INTERFACE" == "$1" && "$CONNECTION" == "ethernet" ]] || continue - checkyesno "${AUTO_WIRED:-no}" && exit 1 # user preferred AUTO profile - [[ "$IP" == "dhcp" ]] && exit 2 # dhcp profile - exit 3 # static profile - ) - case $? in - 1) preferred_profiles+=("$profile");; - 2) dhcp_profiles+=("$profile");; - 3) static_profiles+=("$profile");; - esac - done - if [[ ${#preferred_profiles[@]} > 1 ]]; then - echo "AUTO_WIRED flag for $1 set in more than one profile (${preferred_profiles[*]})" - fi - for profile in "${preferred_profiles[@]}" "${dhcp_profiles[@]}" "${static_profiles[@]}"; do - profile_up "$profile" && exit 0 - done - ;; - down) - if check_iface "$1"; then - interface_down "$1" && exit 0 - fi - ;; - *) - echo "Wrong arguments" > /dev/stderr - ;; -esac - -exit 1 diff --git a/scripts/netcfg b/scripts/netcfg deleted file mode 100755 index f1d79e8..0000000 --- a/scripts/netcfg +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash - -. /usr/lib/network/network - -NETCFG_VER=2-notpackaged - -version() -{ - echo "netcfg v$NETCFG_VER" -} - -usage() -{ - version - cat << END -Usage: - Start specified profile: netcfg profile - Other functions: netcfg argument profile -Arguments: - current Report currently running profiles --a, all-down Take all active profiles down --c, check-iface Do not start profile if interface is already up --d, down Take specified profile down --D, iface-down Take down profile active on specified interface --h, help This help message --l, list List all available profiles --r, reconnect Disconnect and reconnect specified profile --R, iface-recon Reconnect profile active on specified interface --u, up Start specified profile --v, version Output version information and exit - all-resume Resume previously suspended profiles and reconnect them - all-suspend Store a list of current running profiles and suspend them -END -} - -# TODO: Re-add ROOT check and rewrite with getopts from BashFAQ - -case "$1" in - --version|-v|version) - version - exit 0;; - --help|-h|help) - usage - exit 0;; - list|-l) - list_profiles - exit 0;; - current|-s|status) - if [[ -d "$STATE_DIR/profiles/" ]]; then - ls "$STATE_DIR/profiles/" - exit 0 - else - exit_stderr "No active profiles." - fi;; -esac - -if [[ $(id -u) -gt 0 ]]; then - exit_stderr "This script should be run as root." -fi - -# Ensure cwd is not in a transient directory, which may prevent unmounting due to netcfg children -cd / - -case "$1" in - -c|check-iface|-u|up) - CHECK="YES" - profile_up "$2";; - -d|down) - profile_down "$2";; - -D|iface-down) - interface_down "$2";; - -a|all-down) - all_down;; - -r|reconnect) - profile_down "$2" - profile_up "$2";; - -R|iface-recon) - interface_reconnect "$2";; - all-resume) - all_resume;; - all-suspend) - all_suspend;; - clean) - rm "$STATE_DIR/interfaces"/* 2> /dev/null - rm "$STATE_DIR/profiles"/* 2> /dev/null - rm "$STATE_DIR/suspend"/* 2> /dev/null - rm "$STATE_DIR/netcfg-daemon" 2> /dev/null - killall wpa_supplicant 2> /dev/null - killall dhcpcd 2> /dev/null - killall dhclient 2> /dev/null - ;; - -*|--*) - usage - exit 1;; - *) - if [[ -n "$1" ]]; then - profile_up "$1" - else - usage - exit 1 - fi - ;; -esac -exit $? - -# vim: ft=sh ts=4 et sw=4: diff --git a/scripts/netcfg-daemon b/scripts/netcfg-daemon deleted file mode 100755 index b3111da..0000000 --- a/scripts/netcfg-daemon +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# -# This script implements support for the NETWORKS array in /etc/conf.d/netcfg. - -. /usr/lib/network/globals -. /etc/conf.d/netcfg -STATE_FILE="$STATE_DIR/netcfg-daemon" -LAST_STATE="/var/lib/netcfg/netcfg.state" - -case "$1" in - start) - (( $(id -u) )) && exit_stderr "This script should be run as root." - [[ -e $STATE_FILE ]] && exit_err "netcfg-daemon is already started" - [[ ${NETWORKS+x} != x ]] && exit_err "NETWORKS is not set in /etc/conf.d/netcfg" - - if [[ ${#NETWORKS[@]} -eq 1 ]]; then - case $NETWORKS in - last) - if [[ ! -e $LAST_STATE ]]; then - report_err "No recorded netcfg state to restore" - # This counts as successful startup since the daemon - # should be stopped on shutdown. - exit 0 - fi - - # The order in LAST_STATE is meaningless so we can just as - # well start the profiles in parallel. - while read profile; do - if /usr/bin/netcfg up "$profile"; then - echo "$profile" >> "$STATE_FILE" - fi & - done < "$LAST_STATE" - wait - exit $? ;; - menu) - /usr/bin/netcfg-menu ${NETWORKS_MENU_TIMEOUT-5} && \ - mv "$STATE_DIR/menu" "$STATE_FILE" - exit $? ;; - esac - fi - - for profile in "${NETWORKS[@]}"; do - if [[ "$profile" = "${profile#@}" ]]; then - if /usr/bin/netcfg check-iface "$profile"; then - echo "$profile" >> "$STATE_FILE" - fi - else - # It is up to the user to make sure no backgrounded profile - # uses an interface that is used by another active profile. - if /usr/bin/netcfg up "${profile#@}"; then - echo "$profile" >> "$STATE_FILE" - fi >/dev/null & - PROFILE_BKGD=1 - fi - done - # Generate a return value. - [[ -f $STATE_FILE || -n $PROFILE_BKGD ]] - ;; - stop) - (( $(id -u) )) && exit_stderr "This script should be run as root." - - if [[ ${#NETWORKS[@]} -eq 1 && $NETWORKS = last ]]; then - mkdir -p "$(dirname "$LAST_STATE")" - /usr/bin/netcfg current > "$LAST_STATE" - /usr/bin/netcfg all-down - exit $? - fi - - [[ ! -e $STATE_FILE ]] && exit_err "netcfg-daemon was not started" - # Stop the profiles in the reverse order they were started. - tac "$STATE_FILE" | ( - while read profile; do - if [[ -e "$STATE_DIR/profiles/${profile#@}" ]]; then - if [[ "$profile" = "${profile#@}" ]]; then - /usr/bin/netcfg down "$profile" || exit $? - else - /usr/bin/netcfg down "${profile#@}" & - fi - fi - done - rm "$STATE_FILE" - # Generate a return value and make sure we are good to restart. - wait - ) - ;; - restart) - "$0" stop - sleep 1 - "$0" start - ;; - status) - if [[ -e $STATE_FILE ]]; then - report_notice "profiles started by netcfg-daemon:" - sed 's/^@//' "$STATE_FILE" - else - report_notice "netcfg-daemon was not started" - fi - ;; - *) - echo "Usage: $0 {start|stop|restart|status}" -esac - diff --git a/scripts/netcfg-menu b/scripts/netcfg-menu deleted file mode 100755 index 9a875ae..0000000 --- a/scripts/netcfg-menu +++ /dev/null @@ -1,55 +0,0 @@ -#! /bin/bash - -. /usr/lib/network/network - -if ! type dialog &> /dev/null; then - echo "Please install 'dialog' to use netcfg-menu" - exit 1 -fi - -check_make_state_dir -# JP: we'll use $STATE_DIR/menu to record what profile is being connected in this way -rm -f "$STATE_DIR/menu" - -# Set timeout -TIMEOUT=${1-0} - -# Scan all profiles -i=0 -# JP: change for prof to while read prof to avoid assumption that profile names are always single tokens (no spaces etc.) -while read prof; do - # if there is a profile called "main", Use as default - [[ "$prof" = "main" ]] && DEFAULT="main" - profiles[i++]="$prof" - profiles[i++]=$(. "$PROFILE_DIR/$prof"; echo "$DESCRIPTION") -done < <(list_profiles | sort) # JP: re-use list_profiles instead of duplicating it; avoid subshell we'd get by piping it to the while read... - -if [[ ${#profiles} -eq 0 ]]; then - exit_err "No profiles were found in $PROFILE_DIR" -fi - -[[ -n "$NETWORKS_MENU_DEFAULT" ]] && DEFAULT="$NETWORKS_MENU_DEFAULT" -# if no default yet, use the first entry -[[ -z "$DEFAULT" ]] && DEFAULT="${profiles[0]}" - -# Display Dialog -PROFILE=$(dialog --timeout "$TIMEOUT" --default-item "$DEFAULT" --stdout \ - --menu 'Select the network profile you wish to use' \ - 13 50 6 "${profiles[@]}") -ret=$? -case $ret in - 1) ;; # Cancel - do nothing - 255|0) # Timeout (use default) or user selection - [[ -z "$PROFILE" ]] && PROFILE="$DEFAULT" - profile_up "$PROFILE" - ret=$? - (( ret == 0 )) && echo "$PROFILE" > "$STATE_DIR/menu" - ;; - *) # Should not happen - exit_err "Abnormal return code from dialog: $ret" - ;; -esac - -exit $ret # JP: exit with caught $? - -# vim: ft=sh ts=4 et sw=4: diff --git a/scripts/netcfg-wpa_actiond b/scripts/netcfg-wpa_actiond deleted file mode 100755 index c6aaf67..0000000 --- a/scripts/netcfg-wpa_actiond +++ /dev/null @@ -1,87 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network -. "$SUBR_DIR/8021x" -. "$SUBR_DIR/rfkill" -. /etc/conf.d/netcfg - -AUTOWIFI="/usr/sbin/wpa_actiond -p /run/wpa_supplicant" -ACTION_SCRIPT="/usr/bin/netcfg-wpa_actiond-action" - -case $1 in - help) - echo "netcfg-wpa_actiond " - echo "netcfg-wpa_actiond stop " - exit - ;; - stop) - [[ -z $2 ]] && echo "Please specify an interface to stop" && exit 1 - interface=$2 - PIDFILE="/run/wpa_actiond_${interface}.pid" - [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" - netcfg -D "$interface" - timeout_wait 1 '[[ ! -f "$PIDFILE" ]]' || kill "$(< "$PIDFILE")" - # only try to disable software rfkill switches (FS#25514) - if [[ "$RFKILL" == "soft" ]]; then - set_rf_state "$interface" disabled $RFKILL_NAME || exit $? - fi - exit - ;; - *) - interface=$1; shift - PIDFILE="/run/wpa_actiond_${interface}.pid" - EXTRA_AUTOWIFI_OPTIONS="$*" - ;; -esac - -if [[ -z $interface ]]; then - echo "No interface specified" - exit 1 -fi - -# Load interface specific config -[[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" - -if [[ -f "$CONN_DIR/interfaces/$interface" ]]; then - netcfg -D "$interface" -fi - -if [[ -n "$RFKILL" ]]; then # Enable radio if necessary - enable_rf "$interface" "$RFKILL" "$RFKILL_NAME" || exit $? -fi - -WPA_CONF="$(make_wpa_config_file "$interface")" - -if [[ -n "${AUTO_PROFILES}" ]]; then - for prof in "${AUTO_PROFILES[@]}"; do echo "$prof"; done -else - list_profiles -fi | while read profile; do - echo "$profile" - ( - load_profile "$profile" - - [[ $CONNECTION != "wireless" ]] && exit 1 - [[ $INTERFACE != $interface ]] && exit 1 - # Exclude wpa-config, the wpa_conf is 'complete' and doesn't fit in this scheme - [[ -z "$SECURITY" ]] && SECURITY="none" - [[ $SECURITY == "wpa-config" ]] && exit 1 - - printf "%s\n" "network={" "$(make_wpa_config)" "id_str=\"$profile\"" "}" >> "$WPA_CONF" - ) -done - - -[[ -z $WPA_DRIVER ]] && WPA_DRIVER="nl80211,wext" -WPA_OPTS="-W $WPA_OPTS" - -# Kill any existing wpa_supplicant on this interface -stop_wpa "$interface" &> /dev/null - -if start_wpa "$interface" "$WPA_CONF" "$WPA_DRIVER" $WPA_OPTS; then - if $AUTOWIFI -i "$interface" -P "$PIDFILE" -a "$ACTION_SCRIPT" $EXTRA_AUTOWIFI_OPTIONS; then - exit 0 - fi -fi - -exit 1 - diff --git a/scripts/netcfg-wpa_actiond-action b/scripts/netcfg-wpa_actiond-action deleted file mode 100755 index 1f29364..0000000 --- a/scripts/netcfg-wpa_actiond-action +++ /dev/null @@ -1,56 +0,0 @@ -#! /bin/bash - -interface="$1" -ssid="$2" -profile="$3" -action="$4" - -. /usr/lib/network/network -[[ "$profile" ]] && load_profile "$profile" - -case $action in - CONNECT) - if [[ -z $profile ]]; then - # Load interface specific config - [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" - dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" -K $DHCP_OPTIONS "$interface" - exit $? - fi - if ! DHCPCD_INTERNAL_OPTIONS="-K" $CONN_DIR/ethernet up "$profile"; then - exit 1 # what to do if fail? - fi - - set_profile up "$profile" - - if ! ( eval $POST_UP ); then # JP: sandbox the eval - # failing POST_UP will take interface down - "$CONN_DIR/$ethernet" down "$profile" - exit 1 - fi - ;; - DISCONNECT) - if [[ -z $profile ]]; then - dhcpcd -k "$interface" - exit $? - fi - if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval - exit 1 - fi - if ! "$CONN_DIR/ethernet" down "$profile"; then - exit 1 - fi - if ! ( eval $POST_DOWN ); then # JP: sandbox the eval - exit 1 - fi - set_profile down "$profile" - ;; - LOST|REESTABLISHED) - # Not handled. - exit 0 - ;; - *) - # ??? - exit 1 - ;; -esac - diff --git a/scripts/pm-utils b/scripts/pm-utils deleted file mode 100755 index 93ee763..0000000 --- a/scripts/pm-utils +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -. /usr/lib/pm-utils/functions - -suspend_netcfg() { - netcfg all-suspend -} - -resume_netcfg() { - netcfg all-resume -} - -if type netcfg > /dev/null; then - case "$1" in - hibernate|suspend) - suspend_netcfg - ;; - thaw|resume) - resume_netcfg - ;; - *) - ;; - esac -fi - -exit $? diff --git a/scripts/wifi-menu b/scripts/wifi-menu deleted file mode 100755 index f46db0d..0000000 --- a/scripts/wifi-menu +++ /dev/null @@ -1,263 +0,0 @@ -#! /bin/bash - -. /usr/lib/network/network -. "$SUBR_DIR/8021x" -. /etc/conf.d/netcfg - -usage() -{ - cat << END -Usage: wifi-menu [-o | --obscure] [-h | --help] [interface] - -Interactively connect to a wireless network. - -Arguments: - -o, --obscure Show asterisks for the characters of the password - and store the password as a hexadecimal string. - -h, --help Show this help. - interface The wireless interface to use. - (default: WIRELESS_INTERFACE from /etc/conf.d/netcfg) - -For choosing from all available profiles, use netcfg-menu. -END -} - -# Fills PROFILES and ESSIDS with the profile names and essids of the profiles -# for interface $1. -init_profiles() -{ - local i=0 essid profile - while read profile; do - essid=$( - unset INTERFACE ESSID - . "$PROFILE_DIR/$profile" &> /dev/null - if [[ "$INTERFACE" = "$1" && -n "$ESSID" ]]; then - printf "%s" "$ESSID" - if [[ "$DESCRIPTION" =~ "Automatically generated" ]]; then - return 2 - else - return 1 - fi - fi - return 0 - ) - case $? in - 2) - GENERATED+=("$profile") - ;& - 1) - PROFILES[i]=$profile - ESSIDS[i]=$essid - (( ++i )) - ;; - esac - done < <(list_profiles) -} - -# Builds ENTRIES as an argument list for dialog based on scan results in $1. -init_entries() -{ - local i=0 flags signal ssid - while IFS=$'\t' read signal flags ssid; do - ENTRIES[i++]="--" # $ssid might look like an option to dialog. - ENTRIES[i++]=$ssid - if inarray "$ssid" "${ESSIDS[@]}"; then - if inarray "$(ssid_to_profile "$ssid")" "${GENERATED[@]}"; then - ENTRIES[i]="+" # Automatically generated - else - ENTRIES[i]="*" # Handmade - fi - else - ENTRIES[i]="-" # Not present - fi - if [[ "$ssid" = "$CONNECTION" ]]; then - ENTRIES[i]="!" # Currently connected - fi - if [[ "$flags" =~ WPA2|WPA|WEP ]]; then - ENTRIES[i]+=":${BASH_REMATCH[0],,}" - else - ENTRIES[i]+=":none" - fi - ENTRIES[i]+=" :$signal" - (( ++i )) - done < "$1" -} - -# Finds a profile name for ssid $1. -ssid_to_profile() -{ - local i - for i in $(seq 0 $((${#ESSIDS[@]}-1))); do - if [[ "$1" = "${ESSIDS[i]}" ]]; then - printf "%s" "${PROFILES[i]}" - return 0 - fi - done - return 1 -} - -# Creates a profile for ssid $1. -create_profile() -{ - local box flags key msg security - PROFILE="$INTERFACE-${1//\//_}" - [[ -e "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu" - flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2) - if [[ "$flags" =~ WPA|WEP ]]; then - security=${BASH_REMATCH[0],,} - else - security=none - fi - if [[ "$flags" =~ PSK|WEP ]]; then - [[ "$OBSCURE" ]] && box="--insecure --passwordbox" || box="--inputbox" - msg="Enter $security security key for\n'$1'" - key=$(dialog $box "$msg" 10 40 --stdout) || return $? - if [[ "${#key}" -ge 8 && "${#key}" -le 63 ]]; then - if [[ "$OBSCURE" ]]; then - key=$(wpa_passphrase "$1" "$key" | grep -m 1 "^[[:space:]]*psk=") - key=${key#*psk=} - else - key=$(printf "%q" "$key") - fi - elif ! [[ "${#key}" -eq 64 && "$key" = +([[:xdigit:]]) ]]; then - return 4 - fi - fi - cat << EOF > "$PROFILE_DIR/$PROFILE" -CONNECTION='wireless' -DESCRIPTION='Automatically generated profile by wifi-menu' -INTERFACE='$INTERFACE' -SECURITY='$security' -ESSID=$(printf "%q" "$1") -IP='dhcp' -${key+KEY=$key} -EOF - printf "%s" "$PROFILE" - return 0 -} - -# Connects to ssid $1 using an available profile or an automatically created -# one if none exists. -connect_to_ssid() -{ - local msg - PROFILE=$(ssid_to_profile "$1") - if [[ $? -eq 0 ]]; then - clear - check_profile "$PROFILE" && profile_down "$PROFILE" - else - PROFILE=$(create_profile "$1") - RETURN=$? - (( RETURN == 0 )) || return $RETURN - SPAWNED_PROFILE=1 - clear - fi - if ! profile_up "$PROFILE"; then - if (( SPAWNED_PROFILE )); then - msg=" CONNECTING FAILED - -Do you want to keep the generated profile ('$PROFILE')?" - dialog --yesno "$msg" 10 40 --stdout || rm "$PROFILE_DIR/$PROFILE" - clear - fi - return 2 - fi - return 0 -} - -while [[ "$1" = -* ]]; do - case "$1" in - -h|--help) - usage - exit - ;; - -o|--obscure) - OBSCURE=1 - shift - ;; - -*) - report_err "Invalid option: $1" - usage - exit 255 - ;; - esac -done -if [[ $# -gt 1 ]]; then - report_err "Too many arguments" - usage - exit 255 -fi - -if [[ $(id -u) -ne 0 ]]; then - exit_stderr "This script needs to be run with root privileges" -fi -if ! type dialog &> /dev/null; then - exit_stderr "Please install 'dialog' to use wifi-menu" -fi - -INTERFACE=${1-$WIRELESS_INTERFACE} -if [[ -z "$INTERFACE" ]]; then - report_err "Missing interface specification" - usage - exit 255 -fi - -cd / # We do not want to spawn anything that can block unmounting -is_interface "$INTERFACE" || exit_fail "No such interface: $INTERFACE" -if ! interface_is_up "$INTERFACE"; then - [[ -f "$IFACE_DIR/$INTERFACE" ]] && . "$IFACE_DIR/$INTERFACE" - bring_interface up "$INTERFACE" || exit_fail "Interface unavailable" - SPAWNED_INTERFACE=1 -fi - -report_try "Scanning for networks" -CONNECTION=$(wpa_call "$INTERFACE" status 2> /dev/null | grep -m 1 "^ssid=") -CONNECTION=${CONNECTION#ssid=} -NETWORKS=$(wpa_supplicant_scan "$INTERFACE" 3,4,5) -if [[ $? -eq 0 ]]; then - trap 'rm -f "$NETWORKS"' EXIT - report_success - init_profiles "$INTERFACE" - init_entries "$NETWORKS" - MSG="Select the network you wish to use -Flags description: - * - handmade profile present - + - automatically generated profile present - - - no profile present - ! - active connection present" - CHOICE=$(dialog --column-separator : --menu "$MSG" 24 50 12 \ - "${ENTRIES[@]}" --stdout) - RETURN=$? - if (( RETURN == 0 )); then - connect_to_ssid "$CHOICE" - RETURN=$? - fi -else - report_fail - RETURN=3 -fi - -case $RETURN in - 0|2) # Connected | Connecting failed - ;; - 1) # Canceled - clear - ;; - 3) # No networks found - report_err "No networks found" - ;; - 4) # Invalid passphrase length (WEP keys have tighter restrictions) - clear - report_err "Passphrase must be 8..63 characters" - ;; - 255) # ESC or error - clear - report_err "Aborted" - ;; - *) # Should not happen - report_err "Unexpected return code from dialog: $RETURN" - RETURN=7 - ;; -esac -(( RETURN && SPAWNED_INTERFACE )) && bring_interface down "$INTERFACE" -exit $RETURN diff --git a/services/netctl-auto@.service b/services/netctl-auto@.service new file mode 100644 index 0000000..81f2369 --- /dev/null +++ b/services/netctl-auto@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Automatic wireless network connection via netcfg +Before=network.target +Wants=network.target + +[Service] +EnvironmentFile=/etc/conf.d/netcfg +ExecStart=/usr/bin/netcfg-wpa_actiond $WIRELESS_INTERFACE +ExecStop=/usr/bin/netcfg-wpa_actiond stop $WIRELESS_INTERFACE +RemainAfterExit=yes +Type=forking + +[Install] +WantedBy=multi-user.target diff --git a/services/netctl-ifplugd@.service b/services/netctl-ifplugd@.service new file mode 100644 index 0000000..8948ac6 --- /dev/null +++ b/services/netctl-ifplugd@.service @@ -0,0 +1,10 @@ +[Unit] +Description=Automatic wired network connection via netcfg + +[Service] +EnvironmentFile=/etc/conf.d/netcfg +ExecStart=/usr/bin/ifplugd -i $WIRED_INTERFACE -r /etc/ifplugd/netcfg.action -fIns +ExecStop=/usr/bin/netcfg iface-down $WIRED_INTERFACE + +[Install] +WantedBy=multi-user.target diff --git a/services/netctl.service b/services/netctl.service new file mode 100644 index 0000000..f400be0 --- /dev/null +++ b/services/netctl.service @@ -0,0 +1,14 @@ +[Unit] +Description=Netcfg multi-profile daemon +Before=network.target +Wants=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/netcfg-daemon start +ExecStop=/usr/bin/netcfg-daemon stop +KillMode=none + +[Install] +WantedBy=multi-user.target diff --git a/services/netctl@.service b/services/netctl@.service new file mode 100644 index 0000000..57229f8 --- /dev/null +++ b/services/netctl@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Netcfg networking service for profile %i +Before=network.target +Wants=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/netcfg check-iface %i +ExecStop=-/usr/bin/netcfg down %i +KillMode=none + +[Install] +WantedBy=multi-user.target diff --git a/src/8021x b/src/8021x deleted file mode 100644 index d2ddfe4..0000000 --- a/src/8021x +++ /dev/null @@ -1,275 +0,0 @@ -# Usage: wpa_call $interface $call ... -# Wrapper around wpa_cli to deal with supplicant configurations that set a -# non-standard control path. -wpa_call() -{ - local args=("-i" "$1") - shift - - if [[ -n "$WPA_CTRL_DIR" ]]; then - args+=("-p" "$WPA_CTRL_DIR") - elif [[ -n "$WPA_CONF" ]] && grep -q "^[[:space:]]*ctrl_interface=" "$WPA_CONF"; then - WPA_CTRL_DIR=$(grep -m 1 "^[[:space:]]*ctrl_interface=" "$WPA_CONF") - WPA_CTRL_DIR=${WPA_CTRL_DIR#*ctrl_interface=} - if [[ "$WPA_CTRL_DIR" == DIR=* ]]; then - WPA_CTRL_DIR=${WPA_CTRL_DIR:4} - WPA_CTRL_DIR=${WPA_CTRL_DIR%% GROUP=*} - fi - args+=("-p" "$WPA_CTRL_DIR") - fi - report_debug wpa_cli "${args[@]}" "$@" - wpa_cli "${args[@]}" "$@" -} - -# Uses wpa_supplicant to check for association to a network -# wpa_check interface [timeout] -wpa_check() -{ - local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}" CONDITION="${3:-COMPLETED}" - # CONDITION is required as wired connections are ready at ASSOCIATED not COMPLETED FS#20150 - - while (( timeout < TIMEOUT )); do - ( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors - if (( timeout < 2 )); then - eval $(wpa_call "$INTERFACE" status 2> /dev/null | grep -F "wpa_state=") - else - eval $(wpa_call "$INTERFACE" status | grep -F "wpa_state=") - fi - [[ "$wpa_state" = "$CONDITION" ]] - ) && return 0 - sleep 1 - (( ++timeout )) - done - echo "$wpa_state" - # wpa_cli -i "$INTERFACE" terminate >/dev/null 2>&1 # callers sometimes called stop_wpa, which does more but seems redundant - # termination should either be handled properly here, or by callers - stop_wpa "$INTERFACE" - return 1 -} - -start_wpa() -{ - local INTERFACE="$1" WPA_CONF="$2" WPA_DRIVER="$3" - shift 3 - local WPA_OPTS="$@" PIDFILE="/run/wpa_supplicant_${INTERFACE}.pid" - - if [[ -n "$WPA_CONF" ]]; then - WPA_CONF="-c$WPA_CONF" - else - WPA_CTRL_DIR="/run/wpa_supplicant" - WPA_CONF="-C$WPA_CTRL_DIR" - fi - - wpa_supplicant -B -P "$PIDFILE" -i "$INTERFACE" -D "$WPA_DRIVER" "$WPA_CONF" $WPA_OPTS - - # wait up to one second for the pid file to appear - timeout_wait 1 '[[ -f "$PIDFILE" ]]'; - return $? -} - -stop_wpa() -{ - local INTERFACE="$1" - # we need this as long as wpa_cli has a different default than netcfg - [[ -z "$WPA_CTRL_DIR" && -z "$WPA_CONF" ]] && WPA_CTRL_DIR="/run/wpa_supplicant" - - # done if wpa_supplicant is already terminated for this interface - [[ -e "$WPA_CTRL_DIR/$INTERFACE" ]] || return - - wpa_call "$INTERFACE" terminate > /dev/null - - # wait up to one second for the pid file to be removed - timeout_wait 1 '[[ ! -f "/run/wpa_supplicant_${INTERFACE}.pid" ]]' || \ - kill "$(< "/run/wpa_supplicant_${INTERFACE}.pid")" &> /dev/null & -} - -wpa_reconfigure() { - wpa_call "$1" reconfigure > /dev/null - return $? -} - -wpa_check_current_essid() { - # usage: wpa_check_current_essid $interface $essid - # check that wpa_supplicant is connected to the right essid - local INTERFACE=$1 ESSID=$2 status - status=$(wpa_call "$INTERFACE" status | grep "^ssid=") - if (( $? == 0 )) && [[ "$status" == "ssid=$ESSID" ]]; then - return 0 - else - return 1 - fi -} - -wpa_find_essid() { - # usage: wpa_find_essid $INTERFACE $ESSID - # look for existence of a given essid. Assumes wpa_supplicant is - # running - result=$(wpa_supplicant_scan_and_find "$1" 5 "$2") - ret=$? - echo $result - report_debug wpa_find_essid "\"$result\"" - return $ret -} - -wpa_find_ap() { - # usage: wpa_find_essid $INTERFACE $ESSID - # look for existence of a given essid. Assumes wpa_supplicant is - # running - bssid=${2,,} # set to lowercase - result=$(wpa_supplicant_scan_and_find "$1" 1 "$bssid") - ret=$? - echo $result - report_debug wpa_find_ap "\"$result\"" - return $ret -} - -wpa_supplicant_scan_and_find() { - #usage: wpa_supplicant_scan_and_find $INTERFACE $FIELD $ITEM - # field = 1 for bssid, 5 for essid - # item = string to lookup - local INTERFACE="$1" FIELD="$2" ITEM="$3" RETRIES=5 scan_ok=0 try - for ((try=0; try < $RETRIES; try++)); do - local found - wpa_call "$INTERFACE" scan > /dev/null - sleep 2 - found=$(wpa_call "$INTERFACE" scan_results | tail -n+2 | cut -f "$FIELD" | grep -F -x -m 1 -- "$ITEM") - (( $? == 0 )) && scan_ok=1 - - # ITEM has been found, echo it - if [[ -n "$found" ]]; then - echo "$found" - return 0 - fi - done - if (( $scan_ok != 1 )); then - report_debug wpa_supplicant_scan_and_find "unable to retrieve scan results" - fi - return 1 -} - -wpa_supplicant_scan() { - local INTERFACE="$1" fields="$2" spawned_wpa=0 essids - # temp file used, as keeping ESSID's with spaces in their name in arrays - # is hard, obscure and kinda nasty. This is simpler and clearer. - - [[ -z "$INTERFACE" ]] && return 1 - essids=$(mktemp --tmpdir essid.XXXXXXXX) - - if [[ "$(wpa_call "$INTERFACE" ping 2> /dev/null)" != "PONG" ]]; then - start_wpa "$INTERFACE" "" "${WPA_DRIVER:-nl80211,wext}" || return 1 - spawned_wpa=1 - fi - - wpa_call "$INTERFACE" scan > /dev/null - # Wait at least 3 seconds for scan results - sleep 3 - # Sometimes, that is not enough (FS#29946) - timeout_wait 7 '! wpa_call "$INTERFACE" status | grep -F -q "wpa_state=SCANNING"' - wpa_call "$INTERFACE" scan_results | - tail -n+2 | - sort -rn -k3 | - sort -u -k5 | - sort -rn -k3 | - cut -f"$fields" > "$essids" - - # Fields are tab delimited - # Remove extraneous output from wpa_cli - # Sort by strength - # Remove duplicates - # Re-sort by strength as the removal disorders the list - # Cut to the AP/essid fields only - - (( $spawned_wpa == 1 )) && stop_wpa "$INTERFACE" - - # File of 0 length, ie. no ssid's. - if [[ ! -s "$essids" ]]; then - rm -f "$essids" - return 1 - fi - - echo "$essids" - return 0 -} - -# Requires already loaded profile -make_wpa_config_file() { - local WPA_CONFD="$STATE_DIR/wpa.$1" - - # make empty tmp dir with correct permissions, rename it - check_make_state_dir - mkdir -p /run/wpa_supplicant - rm -rf "$WPA_CONFD" - mv -f "$(mktemp -d --tmpdir=$STATE_DIR)" "$WPA_CONFD" || return 1 - echo "ctrl_interface=/run/wpa_supplicant" >> "$WPA_CONFD/wpa.conf" - echo "ctrl_interface_group=${WPA_GROUP:-wheel}" >> "$WPA_CONFD/wpa.conf" - [[ $WPA_COUNTRY ]] && echo "country=$WPA_COUNTRY" >> "$WPA_CONFD/wpa.conf" - [[ -n "$ADHOC" ]] && echo "ap_scan=2" >> "$WPA_CONFD/wpa.conf" - echo "$WPA_CONFD/wpa.conf" -} - -# Requires already loaded profile -make_wpa_config() { - case $SECURITY in - none|wep|wpa) - case "${ESSID_TYPE:-ascii}" in - ascii) - echo "ssid=\"$ESSID\"" - ;; - hex) - # Hex ESSID is written unquoted and in lowercase (FS#24333) - echo "ssid=${ESSID,,}" - ;; - *) - report_fail "ESSID_TYPE must be set to 'ascii' or 'hex'." - return 1 - ;; - esac - if [[ -n "$AP" ]]; then - echo "bssid=${AP,,}" - fi - [[ -n "$ADHOC" ]] && echo "mode=1" - ;; - wpa-configsection) - echo "$CONFIGSECTION" - ;; - *) - return 1 - ;; - esac - - # Key management - case $SECURITY in - none) - echo "key_mgmt=NONE" - ;; - wep) - echo "key_mgmt=NONE" - echo "wep_tx_keyidx=0" - if [[ ${KEY:0:2} == "s:" ]]; then # TODO: does wpa_supplicant handle this as expected? - echo "wep_key0=\"${KEY:2}\"" - else - echo "wep_key0=$KEY" - fi - ;; - wpa) - echo "proto=RSN WPA" - if [[ "${#KEY}" -eq 64 ]]; then - echo "psk=$KEY" - else - echo "psk=\"$KEY\"" - fi - ;; - esac - - # Hidden SSID - if checkyesno ${HIDDEN:-no}; then - echo "scan_ssid=1" - fi - - # Priority group for the network - if [[ -n "$PRIORITY" ]]; then - echo "priority=$PRIORITY" - fi -} - -# vim: ft=sh ts=4 et sw=4 tw=0: diff --git a/src/connections/bond b/src/connections/bond deleted file mode 100644 index bc5aa95..0000000 --- a/src/connections/bond +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network -IFENSLAVE="/sbin/ifenslave" - -bond_up() { - load_profile "$1" - - if [[ -e "/sys/class/net/$INTERFACE" ]]; then - report_fail "Interface $INTERFACE already exists." - exit 1 - else - ip link add dev $INTERFACE type bond - fi - bring_interface up "$INTERFACE" - - for slave in "${SLAVE_INTERFACES[@]}"; do - bring_interface up "$slave" - $IFENSLAVE $INTERFACE $slave - done - - "$CONN_DIR/ethernet" up "$1" - return 0 -} - -bond_down() { - load_profile "$1" - - for slave in "${SLAVE_INTERFACES[@]}"; do - $IFENSLAVE $INTERFACE -d $slave - done - - "$CONN_DIR/ethernet" down "$1" - ip link delete "$INTERFACE" - return 0 -} - -bond_$1 "$2" -exit $? - -# vim: set ts=4 et sw=4: diff --git a/src/connections/bridge b/src/connections/bridge deleted file mode 100644 index 6b3ab67..0000000 --- a/src/connections/bridge +++ /dev/null @@ -1,47 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network -BRCTL="/usr/sbin/brctl" - -bridge_up() { - local bridge_interface - load_profile "$1" - - if [[ -e "/sys/class/net/$INTERFACE" ]]; then - if [[ ! -d "/sys/class/net/$INTERFACE/brif" ]]; then - report_fail "Interface $INTERFACE already exists and is not a bridge." - exit 1 - fi - else - $BRCTL addbr "$INTERFACE" - fi - - for bridge_client in $BRIDGE_INTERFACES; do - ip link set "$bridge_client" promisc on up - ip addr flush dev "$bridge_client" - $BRCTL addif "$INTERFACE" "$bridge_client" - done - # Set options - [[ "$FWD_DELAY" ]] && $BRCTL setfd "$INTERFACE" "$FWD_DELAY" - [[ "$MAX_AGE" ]] && $BRCTL setmaxage "$INTERFACE" "$MAX_AGE" - - "$CONN_DIR/ethernet" up "$1" - return 0 -} - -bridge_down() { - local bridge_interface - load_profile "$1" - - for bridge_client in $BRIDGE_INTERFACES; do - ip link set "$bridge_client" promisc off down - $BRCTL delif "$INTERFACE" "$bridge_client" - done - - "$CONN_DIR/ethernet" down "$1" - $BRCTL delbr "$INTERFACE" - return 0 -} - -bridge_$1 "$2" -exit $? -# vim: set ts=4 et sw=4: diff --git a/src/connections/ethernet b/src/connections/ethernet deleted file mode 100644 index 487adf8..0000000 --- a/src/connections/ethernet +++ /dev/null @@ -1,279 +0,0 @@ -#! /bin/bash -# Source file for the 'ethernet' connection -# ethernet_up $profile -# ethernet_down $profile -# ethernet_status - -. /usr/lib/network/network - -report_iproute() -{ - report_fail "$*" - bring_interface down "$INTERFACE" - exit 1 -} - -ethernet_up() { - load_profile "$1" - SYSCTL_INTERFACE="${INTERFACE/.//}" - - if ! is_interface "$INTERFACE"; then - report_iproute "Interface $INTERFACE does not exist" - fi - - # Disable IPv6 before bringing the interface up to prevent SLAAC - if [[ "$IP6" == "no" ]]; then - sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.disable_ipv6=1" - fi - - report_debug ethernet_up bring_interface up "$INTERFACE" - bring_interface up "$INTERFACE" - - if ! checkyesno "${SKIPNOCARRIER:-no}"; then - # Some cards are plain slow to come up. Don't fail immediately. - if ! timeout_wait "${CARRIER_TIMEOUT:-5}" '(( $(< "/sys/class/net/$INTERFACE/carrier") ))'; then - report_iproute "No connection" - fi - fi - - - if checkyesno "${AUTH8021X:-no}"; then - . "$SUBR_DIR/8021x" - [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" - [[ -z "$WPA_DRIVER" ]] && WPA_DRIVER="wired" - - report_debug ethernet_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS" - if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then - report_fail "wpa_supplicant did not start, possible configuration error" - return 1 - fi - - if ! wpa_check "$INTERFACE" "$TIMEOUT" "ASSOCIATED"; then - bring_interface down "$INTERFACE" - report_fail "WPA Authentication/Association Failed" - return 1 - fi - fi - - if [[ -z "$IP" && -z "$IP6" ]]; then - report_iproute "At least one of IP or IP6 should be specified" - return 1 - fi - - case "$IP" in - dhcp) - if checkyesno "${DHCLIENT:-no}"; then - rm -r "/run/dhclient-${INTERFACE}.pid" >/dev/null 2>&1 - report_debug ethernet_up dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/run/dhclient-$INTERFACE.pid" "$INTERFACE" - if ! dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/run/dhclient-${INTERFACE}.pid" ${DHCLIENT_OPTIONS} "$INTERFACE"; then - report_fail "DHCP IP lease attempt failed." - stop_80211x - return 1 - fi - else - # Clear remaining pid files. - rm -f "/run/dhcpcd-$INTERFACE".{pid,cache} >/dev/null 2>&1 - # If using own dns, tell dhcpcd to NOT replace resolv.conf - [[ -n "$DNS" ]] && DHCP_OPTIONS="-C resolv.conf $DHCP_OPTIONS" - # Start dhcpcd - report_debug ethernet_up dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCPCD_INTERNAL_OPTIONS $DHCP_OPTIONS "$INTERFACE" - dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCPCD_INTERNAL_OPTIONS $DHCP_OPTIONS "$INTERFACE" 2>&1 | report_debug "$(cat)" - if [[ "$PIPESTATUS" -ne 0 ]]; then - report_fail "DHCP IP lease attempt failed." - stop_80211x - return 1 - fi - fi - ;; - static) - if [[ -n "$ADDR" ]]; then - [[ -z $NETMASK ]] && NETMASK=24 - report_debug ethernet_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE" - if ! ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"; then - report_iproute "Could not configure interface" - fi - fi - if [[ -n "$GATEWAY" ]]; then - report_debug ethernet_up ip route add default via "$GATEWAY" dev "$INTERFACE" - if ! ip route add default via "$GATEWAY" dev "$INTERFACE"; then - report_iproute "Adding gateway $GATEWAY failed" - fi - fi - ;; - ""|no) - ;; - *) - report_iproute "IP must be either 'dhcp', 'static' or 'no'" - ;; - esac - - if [[ -n "$IP" && -n "$ROUTES" ]]; then - for route in "${ROUTES[@]}"; do - report_debug ethernet_up ip route add $route dev "$INTERFACE" - if ! ip route add $route dev "$INTERFACE"; then - report_iproute "Adding route '$route' failed" - fi - done - fi - - # Load ipv6 module if necessary (FS#25530) - case "$IP6" in - dhcp*|stateless|static) - [[ -d "/proc/sys/net/ipv6" ]] || modprobe ipv6 - ;; - no) - [[ -d "/proc/sys/net/ipv6" ]] && sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=0" - ;; - "") # undefined IP6 does not prevent RA's from being received -> nop - ;; - *) - report_iproute "IP6 must be 'dhcp', 'dhcp-noaddr', 'stateless', 'static' or 'no'" - ;; - esac - - case "$IP6" in - dhcp*) - if ! type dhclient &>/dev/null; then - report_fail "You need to install dhclient to use DHCPv6." - stop_80211x - return 1 - fi - sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=1" - if [[ "$IP6" == "dhcp-noaddr" ]]; then - DHCLIENT6_OPTIONS="-S ${DHCLIENT6_OPTIONS}" - fi - _DHCLIENT_PIDFILE="/run/dhclient6-${INTERFACE}.pid" - rm -r ${_DHCLIENT_PIDFILE} &>/dev/null - report_debug ethernet_up dhclient -6 -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf ${_DHCLIENT_PIDFILE} "$INTERFACE" - if ! dhclient -6 -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf ${_DHCLIENT_PIDFILE} ${DHCLIENT6_OPTIONS} "$INTERFACE"; then - report_fail "DHCPv6 IP lease attempt failed." - stop_80211x - return 1 - fi - ;; - stateless) - sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=1" - ;; - static) - sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=0" - if [[ -n "$ADDR6" ]]; then - for addr in "${ADDR6[@]}"; do - report_debug ethernet_up ip -6 addr add $addr dev "$INTERFACE" - if ! ip -6 addr add $addr dev "$INTERFACE"; then - report_iproute "Could not add address '$addr' to interface" - fi - done - fi - ;; - esac - - if [[ -n "$IP6" ]]; then - # Wait for DAD to finish (FS#28887) - report_debug ethernet_up ip -6 addr show dev "$INTERFACE" tentative - if ! timeout_wait "${DAD_TIMEOUT:-3}" '[[ -z "$(ip -6 addr show dev "$INTERFACE" tentative)" ]]'; then - report_iproute "Duplicate Address Detection is taking too long" - fi - - # Add static IPv6 routes - if [[ -n "$ROUTES6" ]]; then - for route in "${ROUTES6[@]}"; do - report_debug ethernet_up ip -6 route add $route dev "$INTERFACE" - if ! ip -6 route add $route dev "$INTERFACE"; then - report_iproute "Adding route '$route' failed" - fi - done - fi - - # Set a custom gateway after waiting for DAD to finish - if [[ "$IP6" == "static" && -n "$GATEWAY6" ]]; then - report_debug ethernet_up ip -6 route replace default via "$GATEWAY6" dev "$INTERFACE" - if ! ip -6 route replace default via "$GATEWAY6" dev "$INTERFACE"; then - report_iproute "Adding gateway $GATEWAY6 failed" - fi - fi - fi - - if [[ -n "$IPCFG" ]]; then - for line in "${IPCFG[@]}"; do - report_debug ethernet_up ip "$line" - if ! ip $line; then - report_iproute "Could not configure interface ($line)." - fi - done - fi - - # Set hostname - if [[ -n "$HOSTNAME" ]]; then - report_debug ethernet_up hostname "$HOSTNAME" - if ! echo "$HOSTNAME" >/proc/sys/kernel/hostname; then - report_iproute "Cannot set hostname to $HOSTNAME" - fi - fi - - # Generate a new resolv.conf - if [[ -n "$DNS" ]]; then - : >/etc/resolv.conf - [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf - [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf - for dns in "${DNS[@]}"; do - echo "nameserver $dns" >>/etc/resolv.conf - done - for dnsoption in "${DNS_OPTIONS[@]}"; do - echo "options $dnsoption" >>/etc/resolv.conf - done - fi - - return 0 -} - -ethernet_down() { - load_profile "$1" - - if [[ "$IP" == "dhcp" ]]; then - if checkyesno "${DHCLIENT:-no}"; then - if [[ -f "/run/dhclient-$INTERFACE.pid" ]]; then - report_debug ethernet_down dhclient -q -x "$INTERFACE" -pf "/run/dhclient-$INTERFACE.pid" - dhclient -q -x "$INTERFACE" -pf "/run/dhclient-$INTERFACE.pid" &>/dev/null - #dhclient -q -r "$INTERFACE" &>/dev/null - fi - else - if [[ -f "/run/dhcpcd-$INTERFACE.pid" ]]; then - report_debug ethernet_down dhcpcd -qk "$INTERFACE" - dhcpcd -qk "$INTERFACE" &>/dev/null - fi - fi - fi - if [[ "$IP6" == dhcp* ]]; then - if [[ -f "/run/dhclient6-$INTERFACE.pid" ]]; then - report_debug ethernet_down dhclient -6 -q -x "$INTERFACE" -pf "/run/dhclient6-$INTERFACE.pid" - dhclient -6 -q -x "$INTERFACE" -pf "/run/dhclient6-$INTERFACE.pid" &>/dev/null - report_debug ethernet_down /bin/kill $(< /run/dhclient6-$INTERFACE.pid) - /bin/kill $(< /run/dhclient6-$INTERFACE.pid) &>/dev/null - fi - fi - - stop_80211x - - if [[ "$CONNECTION" == "wireless" ]]; then - report_debug ethernet_down bring_interface flush "$INTERFACE" - bring_interface flush "$INTERFACE" - else - report_debug ethernet_down bring_interface down "$INTERFACE" - bring_interface down "$INTERFACE" - fi - return 0 -} - -# Stop wpa_supplicant if neccessary -stop_80211x() { - if checkyesno "${AUTH8021X:-no}"; then - . "$SUBR_DIR/8021x" - [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" - report_debug ethernet_down stop_wpa "$INTERFACE" - stop_wpa "$INTERFACE" - fi -} - -ethernet_$1 "$2" -exit $? -# vim: set ts=4 et sw=4: diff --git a/src/connections/openvpn b/src/connections/openvpn deleted file mode 100644 index 170d582..0000000 --- a/src/connections/openvpn +++ /dev/null @@ -1,52 +0,0 @@ -#! /bin/bash -# Originally contributed by Thomas Jost: https://bugs.archlinux.org/task/21490 - -. /usr/lib/network/network - -openvpn_up() { - load_profile "$1" - [[ -z "$OVPN_CONFIG" ]] && OVPN_CONFIG="/etc/openvpn/openvpn.conf" - [[ -z "$OVPN_PID_FILE" ]] && OVPN_PID_FILE="/run/openvpn-$1.pid" - [[ -z "$OVPN_FLAGS" ]] && OVPN_FLAGS="" - - OVPN_CONF_DIR="`dirname $OVPN_CONFIG`" - OVPN_CONF_FILE="`basename $OVPN_CONFIG`" - - /usr/sbin/openvpn --writepid $OVPN_PID_FILE --daemon --cd "$OVPN_CONF_DIR" --config "$OVPN_CONF_FILE" $OVPN_FLAGS - - if [[ $? -ne 0 ]]; then - report_fail "OpenVPN connection failed" - exit 1 - fi - - # Generate a new resolv.conf - if [[ -n "$DNS" ]]; then - [[ -e /etc/resolv.conf ]] && cp /etc/resolv.conf /tmp/openvpn-$1-resolv.conf - : >/etc/resolv.conf - [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf - [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf - for dns in "${DNS[@]}"; do - echo "nameserver $dns" >>/etc/resolv.conf - done - for dnsoption in "${DNS_OPTIONS[@]}"; do - echo "options $dnsoption" >>/etc/resolv.conf - done - fi -} - -openvpn_down() { - load_profile "$1" - [[ -z "$OVPN_PID_FILE" ]] && OVPN_PID_FILE="/run/openvpn-$1.pid" - - kill $(head -1 $OVPN_PID_FILE) - rm $OVPN_PID_FILE - - # Restore an old resolv.conf - if [[ -e /tmp/openvpn-$1-resolv.conf ]]; then - mv -f /tmp/openvpn-$1-resolv.conf /etc/resolv.conf - fi -} - -openvpn_$1 "$2" -exit $? -# vim: ft=sh ts=4 et sw=4: diff --git a/src/connections/ppp b/src/connections/ppp deleted file mode 100644 index da0fd6f..0000000 --- a/src/connections/ppp +++ /dev/null @@ -1,31 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network - - -ppp_up() { - load_profile "$1" - [[ -z "$PEER" ]] && PEER="provider" - [[ -z "$PPP_TIMEOUT" ]] && PPP_TIMEOUT=30 - - /usr/sbin/pppd call "$PEER" updetach child-timeout "$PPP_TIMEOUT" linkname "$PEER" - - if [[ $? -ne 0 ]]; then - report_fail "Couldn't make pppd connection." - return 1 - fi -} - -ppp_down() { - load_profile "$1" - PIDFILE="/var/run/ppp-$(basename $PEER).pid" - - if [[ -e $PIDFILE ]]; then - PID=$(head -1 $PIDFILE) - [[ -n "$PID" ]] && kill "$PID" - fi -} - -ppp_$1 "$2" -exit $? - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/connections/pppoe b/src/connections/pppoe deleted file mode 100644 index 17fe42d..0000000 --- a/src/connections/pppoe +++ /dev/null @@ -1,77 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network - -_quotestring() { - echo "\"${1/\"/\\\"}\"" -} - -pppoe_up() { - local cfg - load_profile "$1" - - mkdir -p "$STATE_DIR/pppoe.${INTERFACE}.$1/" - chmod 700 "$STATE_DIR/pppoe.${INTERFACE}.$1/" - cfg="$STATE_DIR/pppoe.${INTERFACE}.$1/options" - : > "${cfg}" - chmod 600 "${cfg}" - - echo "plugin rp-pppoe.so" >> "${cfg}" - echo "nic-${INTERFACE}" >> "${cfg}" - echo "noauth" >> "${cfg}" - if checkyesno ${DEFAULTROUTE:-1}; then - echo "defaultroute" >> "${cfg}" - else - echo "nodefaultroute" >> "${cfg}" - fi - if checkyesno ${USEPEERDNS:-1}; then - echo "usepeerdns" >> "${cfg}" - fi - echo "linkname $(_quotestring "$1")" >> "${cfg}" - echo "maxfail 5" >> "${cfg}" - echo "updetach" >> "${cfg}" - if [[ ${CONNECTION_MODE} == demand ]]; then - echo "demand" >> "${cfg}" - echo "idle ${IDLE_TIMEOUT}" >> "${cfg}" - else - echo "persist" >> "${cfg}" - fi - echo "user $(_quotestring "${USER}")" >> "${cfg}" - echo "password $(_quotestring "${PASSWORD}")" >> "${cfg}" - [[ -n ${LCP_ECHO_INTERVAL} ]] && echo "lcp-echo-interval ${LCP_ECHO_INTERVAL}" >> "${cfg}" - [[ -n ${LCP_ECHO_FAILURE} ]] && echo "lcp-echo-failure ${LCP_ECHO_FAILURE}" >> "${cfg}" - [[ -n ${PPPOE_SERVICE} ]] && echo "rp_pppoe_service $(_quotestring "${PPPOE_SERVICE}")" >> "${cfg}" - [[ -n ${PPPOE_AC} ]] && echo "rp_pppoe_ac $(_quotestring "${PPPOE_AC}")" >> "${cfg}" - [[ -n ${PPPOE_SESSION} ]] && echo "rp_pppoe_sess $(_quotestring "${PPPOE_SESSION}")" >> "${cfg}" - [[ -n ${PPPOE_MAC} ]] && echo "pppoe-mac $(_quotestring "${PPPOE_MAC}")" >> "${cfg}" - [[ ${PPPOE_IP6} == yes ]] && echo "+ipv6" >> "${cfg}" - - /sbin/ip link set dev "${INTERFACE}" up - /usr/sbin/pppd file "${cfg}" - - if [[ $? -ne 0 ]]; then - rm "${cfg}" - rmdir "$STATE_DIR/pppoe.${INTERFACE}.$1/" - report_fail "Couldn't make pppd connection." - return 1 - fi -} - -pppoe_down() { - load_profile "$1" - local cfg - cfg="$STATE_DIR/pppoe.${INTERFACE}.$1/options" - PIDFILE="/var/run/ppp-$1.pid" - - if [[ -e $PIDFILE ]]; then - read PID < "$PIDFILE" - [[ "$PID" ]] && kill "$PID" - fi - - rm "${cfg}" - rmdir "$STATE_DIR/pppoe.${INTERFACE}.$1/" -} - -pppoe_$1 "$2" -exit $? - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/connections/tunnel b/src/connections/tunnel deleted file mode 100644 index 6cefc5c..0000000 --- a/src/connections/tunnel +++ /dev/null @@ -1,34 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network - -tunnel_up() { - load_profile "$1" - - if [[ -e "/sys/class/net/$INTERFACE" ]]; then - report_fail "Interface $INTERFACE already exists." - exit 1 - else - ip tunnel add "$INTERFACE" mode "$MODE" remote "$REMOTE" - fi - - if [[ -n "$LOCAL" ]]; then - ip tunnel change "$INTERFACE" local "$LOCAL" - fi - - "$CONN_DIR/ethernet" up "$1" - return 0 -} - -tunnel_down() { - load_profile "$1" - - "$CONN_DIR/ethernet" down "$1" - ip tunnel del "$INTERFACE" - - return 0 -} - -tunnel_$1 "$2" -exit $? - -# vim: set ts=4 et sw=4: diff --git a/src/connections/tuntap b/src/connections/tuntap deleted file mode 100644 index 6985c8c..0000000 --- a/src/connections/tuntap +++ /dev/null @@ -1,28 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network - -tuntap_up() { - load_profile "$1" - - if [[ -e /sys/class/net/$INTERFACE ]]; then - report_fail "Interface $INTERFACE already exists." - exit 1 - else - ip tuntap add dev "$INTERFACE" mode "$MODE" \ - user "$USER" group "$GROUP" - fi - IP=${IP-no} "$CONN_DIR/ethernet" up "$1" - return 0 -} - -tuntap_down() { - load_profile "$1" - - "$CONN_DIR/ethernet" down "$1" - ip tuntap del dev "$INTERFACE" mode "$MODE" - return 0 -} - -tuntap_$1 "$2" -exit $? -# vim: set ts=4 et sw=4 tw=0: diff --git a/src/connections/vlan b/src/connections/vlan deleted file mode 100644 index 75c7fa9..0000000 --- a/src/connections/vlan +++ /dev/null @@ -1,28 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network - -vlan_up() { - load_profile "$1" - - if [[ -e "/sys/class/net/$INTERFACE" ]]; then - report_fail "Interface $INTERFACE already exists." - exit 1 - else - bring_interface up "$VLAN_PHYS_DEV" - ip link add link "$VLAN_PHYS_DEV" name "$INTERFACE" type vlan id "$VLAN_ID" - fi - "$CONN_DIR/ethernet" up "$1" - return 0 -} - -vlan_down() { - load_profile "$1" - - "$CONN_DIR/ethernet" down "$1" - ip link delete "$INTERFACE" - return 0 -} - -vlan_$1 "$2" -exit $? -# vim: set ts=4 et sw=4: diff --git a/src/connections/wireless b/src/connections/wireless deleted file mode 100644 index 135bec7..0000000 --- a/src/connections/wireless +++ /dev/null @@ -1,116 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network -. "$SUBR_DIR/8021x" -. "$SUBR_DIR/rfkill" - -wireless_up() { - PROFILE="$1" - load_profile "$PROFILE" - - # Default settings - SECURITY=${SECURITY:-none} - WPA_DRIVER=${WPA_DRIVER:-nl80211,wext} - - enable_rf $INTERFACE $RFKILL $RFKILL_NAME || return 1 - - # Check if interface exists - is_interface "$INTERFACE" || { report_fail "interface $INTERFACE does not exist"; return 1; } - - # Kill any lingering wpa_supplicants. - stop_wpa "$INTERFACE" &> /dev/null - - # Start wpa_supplicant - if [[ "$SECURITY" = "wpa-config" ]]; then - WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}" - else - WPA_CONF=$(make_wpa_config_file $INTERFACE) - fi - report_debug wireless_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS" - if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then - report_fail "wpa_supplicant did not start, possible configuration error" - return 1 - fi - - # Scan for network's existence first - if checkyesno "${SCAN:-no}"; then - report_debug wireless_up scanning - local OLDESSID="$ESSID" - if [[ -n "$AP" ]]; then - BSSID=$(wpa_find_ap "$INTERFACE" "$AP") - else - ESSID=$(wpa_find_essid "$INTERFACE" "$ESSID") - fi - if [[ $? -gt 0 ]]; then - report_fail "Wireless network \"$OLDESSID\" not present." - report_debug wireless_up stop_wpa "$INTERFACE" - stop_wpa "$INTERFACE" - return 1 - fi - fi - - # Build configuration file - case "$SECURITY" in - wpa-config) - ;; - none|wep|wpa|wpa-configsection) - printf "%s\n" "network={" "$(make_wpa_config)" "}" >> "$WPA_CONF" - report_debug wireless_up "Configuration generated at $WPA_CONF" - report_debug wireless_up wpa_reconfigure "$INTERFACE" - if ! wpa_reconfigure "$INTERFACE"; then - report_fail "WPA configuration failed!" - stop_wpa "$INTERFACE" - return 1 - fi - ;; - *) - report_fail "Invalid SECURITY setting: $SECURITY" - ;; - esac - - # Bring interface up after starting wpa_supplicant - # This is important since cards such as iwl3945 do not support - # mode switching when they are already up. - report_debug wireless_up ifup - bring_interface up "$INTERFACE" || return 1 - - report_debug wireless_up wpa_check - if ! wpa_check "$INTERFACE" "$TIMEOUT"; then - report_fail "WPA Authentication/Association Failed" - return 1 - fi - - if ! "$CONN_DIR/ethernet" up "$PROFILE"; then - wireless_down "$PROFILE" YES - return 1 - fi -} - -# wireless_down PROFILE [ LEAVE ifconfig up? default no ] -wireless_down() { - local PROFILE="$1" - load_profile "$PROFILE" - - "$CONN_DIR/ethernet" down "$PROFILE" - - # The config file can contain a non-standard control socket path - if [[ "$SECURITY" = "wpa-config" ]]; then - WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}" - fi - report_debug wireless_down stop_wpa "$INTERFACE" - stop_wpa "$INTERFACE" - rm -rf "$STATE_DIR/wpa.$INTERFACE" - - bring_interface down "$INTERFACE" - - # Handle wireless kill switches - # Any reason why a hardware switch should be considered on interface down? - if [[ "$RFKILL" == "soft" ]]; then - set_rf_state "$INTERFACE" disabled $RFKILL_NAME || return 1 - fi -} - -wireless_$1 "$2" "$3" -exit $? - -# vim: ft=sh ts=4 et sw=4 tw=0: - diff --git a/src/globals b/src/globals deleted file mode 100644 index 491f9d6..0000000 --- a/src/globals +++ /dev/null @@ -1,136 +0,0 @@ -# /usr/lib/networks/globals -# -# All +x files in /usr/lib/network/hooks will be sourced when this file is. -# Hook files can override any of the utility functions defined here for custom -# behavior (such as logging error messages to syslog). This lets us keep netcfg -# simple but gives it the flexibility for users to make modular use of it to do -# more complex things - - -### Globals -PROFILE_DIR="/etc/network.d" -IFACE_DIR="$PROFILE_DIR/interfaces" -SUBR_DIR="/usr/lib/network" -HOOKS_DIR="$SUBR_DIR/hooks" -CONN_DIR="$SUBR_DIR/connections" -STATE_DIR="/run/network" - - - -### Logging/Error reporting - -function report_err { - echo "$*" -} - -function report_notice { - echo "$*" -} - -function report_debug { - checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 -} - -function report_try { - # This needs -n and a trailing space. - echo -n ":: $* " - REPORT_TRYING=1 -} - -function report_fail { - if [[ -n "$*" ]]; then - if (( REPORT_TRYING )); then - echo "- $* [fail]" - REPORT_TRYING= - else - echo "$*" - fi - elif (( REPORT_TRYING )); then - echo "[fail]" - REPORT_TRYING= - fi -} - -function report_success { - if [[ -n "$*" ]]; then - # This needs -n and a trailing space. - echo -n "- $* " - fi - echo "[done]" - REPORT_TRYING= -} - -### For calling scripts only; don't use in library functions -function exit_stderr { echo "$*" >&2; exit 1; } -function exit_err { report_err "$*"; exit 1; } -function exit_fail { report_fail "$*"; exit 1; } - - -### From FreeBSD's /etc/rc.subr -## -# checkyesno var -# Test $1 variable, and warn if not set to YES or NO. -# Return 0 if it's "yes" (et al), nonzero otherwise. -# To default to yes, do: "checkyesno ${VAR:-yes}". -# -function checkyesno() { - local _value="$1" - #debug "checkyesno: $1 is set to $_value." - case "$_value" in - - # "yes", "true", "on", or "1" - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) - return 0 - ;; - - # "no", "false", "off", or "0" - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) - return 1 - ;; - *) - #warn "\$${1} is not set properly - see rc.conf(5)." - return 1 - ;; - esac -} - -## Check if variable is a member of an array -# $1: the variable to find -# $2...: the array elements -function inarray() { - local item search="$1" - shift - for item in "$@"; do - if [[ "$item" == "$search" ]]; then - return 0 - fi - done - return 1 -} - -## Waits until a statement succeeds or a timeout occurs -# $1: timeout in seconds -# $2...: condition command -function timeout_wait() { - local timeout="$1" - (( timeout *= 10 )) - shift - while ! eval "$*"; do - (( timeout-- > 0 )) || return 1 - sleep 0.1 - done - return 0 -} - - -### Load all +x files in $HOOKS_DIR -function load_hooks() { - local hook - for hook in $(find -L "$HOOKS_DIR/" -maxdepth 1 -type f -executable | sort -u); do - source "$hook" - done -} - -load_hooks - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/hooks/fancy b/src/hooks/fancy deleted file mode 100755 index a64514e..0000000 --- a/src/hooks/fancy +++ /dev/null @@ -1,90 +0,0 @@ -# Fancy output is for terminal output only. -[[ -t 1 ]] || return - - -### Fancy Logging/Error reporting - -function report_err { - print_prefixed "${FANCY_OTHER}" "${FANCY_HIGHLIGHT}$*" -} - -function report_notice { - print_prefixed "${FANCY_OTHER}" "$*" -} - -function report_try { - printf "${FANCY_OTHER}${PREFIX_BUSY}${FANCY_NORMAL} %s " "$*" - report_busy - REPORT_TRYING=1 -} - -function report_fail { - if [[ -n "$*" ]]; then - if [[ -n "$REPORT_TRYING" ]]; then - report_append "$*" - report_failed - REPORT_TRYING= - else - print_prefixed "${FANCY_FAILED}" "${FANCY_HIGHLIGHT}$*" - fi - elif [[ -n "$REPORT_TRYING" ]]; then - report_failed - REPORT_TRYING= - fi -} - -function report_success { - if [[ -n "$*" ]]; then - if [[ -n "$REPORT_TRYING" ]]; then - report_append "$*" - report_done - REPORT_TRYING= - else - print_prefixed "${FANCY_DONE}" "$*" - fi - elif [[ -n "$REPORT_TRYING" ]]; then - report_done - REPORT_TRYING= - fi -} - -function report_append { - printf -- "${RESTORE_POSITION}${FANCY_OTHER}-${FANCY_NORMAL} %s " "$*" -} - -function report_busy { - printf "${CURSOR_STATUS} [${FANCY_BUSY} BUSY ${FANCY_NORMAL}] " -} - -function report_failed { - printf "${CURSOR_STATUS} [${FANCY_FAILED}FAILED${FANCY_NORMAL}]\n" -} - -function report_done { - printf "${CURSOR_STATUS} [${FANCY_DONE} DONE ${FANCY_NORMAL}]\n" -} - -function print_prefixed { - local c_prefix=$1 - shift - printf "${c_prefix}${PREFIX_ATTENTION}${FANCY_NORMAL} %s${FANCY_NORMAL}\n" "$*" -} - - -SAVE_POSITION=$(tput sc) -RESTORE_POSITION=$(tput rc) -COLUMNS=$(tput cols) -(( COLUMNS == 0 )) && COLUMNS=80 -CURSOR_STATUS=${SAVE_POSITION}$(tput hpa $(( COLUMNS - 10 )) ) - -FANCY_NORMAL=$(tput sgr0) -FANCY_HIGHLIGHT=${FANCY_NORMAL}$(tput bold) -FANCY_BUSY=${FANCY_NORMAL}$(tput setaf 6) # cyan -FANCY_FAILED=${FANCY_HIGHLIGHT}$(tput setaf 1) # red -FANCY_DONE=${FANCY_HIGHLIGHT}$(tput setaf 2) # green -FANCY_OTHER=${FANCY_HIGHLIGHT}$(tput setaf 4) # blue - -PREFIX_BUSY="::" -PREFIX_ATTENTION=" >" - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/hooks/initscripts b/src/hooks/initscripts deleted file mode 100755 index 07003c8..0000000 --- a/src/hooks/initscripts +++ /dev/null @@ -1,35 +0,0 @@ -# Use initscripts output formatting. -# This hook must be loaded after 'fancy'. - -[[ ${FANCY_NORMAL+x} = x && -f /etc/rc.d/functions ]] || return -. /etc/rc.conf -. /etc/rc.d/functions - - -function report_try { - stat_busy "$*" - REPORT_TRYING=1 -} - -function report_append { - stat_append "- $*" -} - -function report_failed { - stat_fail -} - -function report_done { - stat_done -} - - -FANCY_NORMAL=$C_CLEAR -FANCY_HIGHLIGHT=$C_H1 -FANCY_FAILED=$C_FAIL -FANCY_DONE=$C_DONE -FANCY_OTHER=$C_OTHER - -PREFIX_ATTENTION=$PREFIX_HL - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/ifplugd.action b/src/ifplugd.action new file mode 100755 index 0000000..ea3a16c --- /dev/null +++ b/src/ifplugd.action @@ -0,0 +1,49 @@ +#!/bin/bash +# +# ifplugd.action script for netcfg + +. /usr/lib/network/network + +case "$2" in + up) + # Look for a dhcp based profile to try first + # dhcp can actually outright fail, whereas + # it's difficult to tell if static succeeded + # Also check profile is same iface and is right connection + echo "up" + declare -a preferred_profiles + declare -a dhcp_profiles + declare -a static_profiles + for profile in $(list_profiles); do + ( + echo "loading $profile" + load_profile "$profile" + [[ "$INTERFACE" == "$1" && "$CONNECTION" == "ethernet" ]] || continue + checkyesno "${AUTO_WIRED:-no}" && exit 1 # user preferred AUTO profile + [[ "$IP" == "dhcp" ]] && exit 2 # dhcp profile + exit 3 # static profile + ) + case $? in + 1) preferred_profiles+=("$profile");; + 2) dhcp_profiles+=("$profile");; + 3) static_profiles+=("$profile");; + esac + done + if [[ ${#preferred_profiles[@]} > 1 ]]; then + echo "AUTO_WIRED flag for $1 set in more than one profile (${preferred_profiles[*]})" + fi + for profile in "${preferred_profiles[@]}" "${dhcp_profiles[@]}" "${static_profiles[@]}"; do + profile_up "$profile" && exit 0 + done + ;; + down) + if check_iface "$1"; then + interface_down "$1" && exit 0 + fi + ;; + *) + echo "Wrong arguments" > /dev/stderr + ;; +esac + +exit 1 diff --git a/src/lib/8021x b/src/lib/8021x new file mode 100644 index 0000000..d2ddfe4 --- /dev/null +++ b/src/lib/8021x @@ -0,0 +1,275 @@ +# Usage: wpa_call $interface $call ... +# Wrapper around wpa_cli to deal with supplicant configurations that set a +# non-standard control path. +wpa_call() +{ + local args=("-i" "$1") + shift + + if [[ -n "$WPA_CTRL_DIR" ]]; then + args+=("-p" "$WPA_CTRL_DIR") + elif [[ -n "$WPA_CONF" ]] && grep -q "^[[:space:]]*ctrl_interface=" "$WPA_CONF"; then + WPA_CTRL_DIR=$(grep -m 1 "^[[:space:]]*ctrl_interface=" "$WPA_CONF") + WPA_CTRL_DIR=${WPA_CTRL_DIR#*ctrl_interface=} + if [[ "$WPA_CTRL_DIR" == DIR=* ]]; then + WPA_CTRL_DIR=${WPA_CTRL_DIR:4} + WPA_CTRL_DIR=${WPA_CTRL_DIR%% GROUP=*} + fi + args+=("-p" "$WPA_CTRL_DIR") + fi + report_debug wpa_cli "${args[@]}" "$@" + wpa_cli "${args[@]}" "$@" +} + +# Uses wpa_supplicant to check for association to a network +# wpa_check interface [timeout] +wpa_check() +{ + local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}" CONDITION="${3:-COMPLETED}" + # CONDITION is required as wired connections are ready at ASSOCIATED not COMPLETED FS#20150 + + while (( timeout < TIMEOUT )); do + ( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors + if (( timeout < 2 )); then + eval $(wpa_call "$INTERFACE" status 2> /dev/null | grep -F "wpa_state=") + else + eval $(wpa_call "$INTERFACE" status | grep -F "wpa_state=") + fi + [[ "$wpa_state" = "$CONDITION" ]] + ) && return 0 + sleep 1 + (( ++timeout )) + done + echo "$wpa_state" + # wpa_cli -i "$INTERFACE" terminate >/dev/null 2>&1 # callers sometimes called stop_wpa, which does more but seems redundant + # termination should either be handled properly here, or by callers + stop_wpa "$INTERFACE" + return 1 +} + +start_wpa() +{ + local INTERFACE="$1" WPA_CONF="$2" WPA_DRIVER="$3" + shift 3 + local WPA_OPTS="$@" PIDFILE="/run/wpa_supplicant_${INTERFACE}.pid" + + if [[ -n "$WPA_CONF" ]]; then + WPA_CONF="-c$WPA_CONF" + else + WPA_CTRL_DIR="/run/wpa_supplicant" + WPA_CONF="-C$WPA_CTRL_DIR" + fi + + wpa_supplicant -B -P "$PIDFILE" -i "$INTERFACE" -D "$WPA_DRIVER" "$WPA_CONF" $WPA_OPTS + + # wait up to one second for the pid file to appear + timeout_wait 1 '[[ -f "$PIDFILE" ]]'; + return $? +} + +stop_wpa() +{ + local INTERFACE="$1" + # we need this as long as wpa_cli has a different default than netcfg + [[ -z "$WPA_CTRL_DIR" && -z "$WPA_CONF" ]] && WPA_CTRL_DIR="/run/wpa_supplicant" + + # done if wpa_supplicant is already terminated for this interface + [[ -e "$WPA_CTRL_DIR/$INTERFACE" ]] || return + + wpa_call "$INTERFACE" terminate > /dev/null + + # wait up to one second for the pid file to be removed + timeout_wait 1 '[[ ! -f "/run/wpa_supplicant_${INTERFACE}.pid" ]]' || \ + kill "$(< "/run/wpa_supplicant_${INTERFACE}.pid")" &> /dev/null & +} + +wpa_reconfigure() { + wpa_call "$1" reconfigure > /dev/null + return $? +} + +wpa_check_current_essid() { + # usage: wpa_check_current_essid $interface $essid + # check that wpa_supplicant is connected to the right essid + local INTERFACE=$1 ESSID=$2 status + status=$(wpa_call "$INTERFACE" status | grep "^ssid=") + if (( $? == 0 )) && [[ "$status" == "ssid=$ESSID" ]]; then + return 0 + else + return 1 + fi +} + +wpa_find_essid() { + # usage: wpa_find_essid $INTERFACE $ESSID + # look for existence of a given essid. Assumes wpa_supplicant is + # running + result=$(wpa_supplicant_scan_and_find "$1" 5 "$2") + ret=$? + echo $result + report_debug wpa_find_essid "\"$result\"" + return $ret +} + +wpa_find_ap() { + # usage: wpa_find_essid $INTERFACE $ESSID + # look for existence of a given essid. Assumes wpa_supplicant is + # running + bssid=${2,,} # set to lowercase + result=$(wpa_supplicant_scan_and_find "$1" 1 "$bssid") + ret=$? + echo $result + report_debug wpa_find_ap "\"$result\"" + return $ret +} + +wpa_supplicant_scan_and_find() { + #usage: wpa_supplicant_scan_and_find $INTERFACE $FIELD $ITEM + # field = 1 for bssid, 5 for essid + # item = string to lookup + local INTERFACE="$1" FIELD="$2" ITEM="$3" RETRIES=5 scan_ok=0 try + for ((try=0; try < $RETRIES; try++)); do + local found + wpa_call "$INTERFACE" scan > /dev/null + sleep 2 + found=$(wpa_call "$INTERFACE" scan_results | tail -n+2 | cut -f "$FIELD" | grep -F -x -m 1 -- "$ITEM") + (( $? == 0 )) && scan_ok=1 + + # ITEM has been found, echo it + if [[ -n "$found" ]]; then + echo "$found" + return 0 + fi + done + if (( $scan_ok != 1 )); then + report_debug wpa_supplicant_scan_and_find "unable to retrieve scan results" + fi + return 1 +} + +wpa_supplicant_scan() { + local INTERFACE="$1" fields="$2" spawned_wpa=0 essids + # temp file used, as keeping ESSID's with spaces in their name in arrays + # is hard, obscure and kinda nasty. This is simpler and clearer. + + [[ -z "$INTERFACE" ]] && return 1 + essids=$(mktemp --tmpdir essid.XXXXXXXX) + + if [[ "$(wpa_call "$INTERFACE" ping 2> /dev/null)" != "PONG" ]]; then + start_wpa "$INTERFACE" "" "${WPA_DRIVER:-nl80211,wext}" || return 1 + spawned_wpa=1 + fi + + wpa_call "$INTERFACE" scan > /dev/null + # Wait at least 3 seconds for scan results + sleep 3 + # Sometimes, that is not enough (FS#29946) + timeout_wait 7 '! wpa_call "$INTERFACE" status | grep -F -q "wpa_state=SCANNING"' + wpa_call "$INTERFACE" scan_results | + tail -n+2 | + sort -rn -k3 | + sort -u -k5 | + sort -rn -k3 | + cut -f"$fields" > "$essids" + + # Fields are tab delimited + # Remove extraneous output from wpa_cli + # Sort by strength + # Remove duplicates + # Re-sort by strength as the removal disorders the list + # Cut to the AP/essid fields only + + (( $spawned_wpa == 1 )) && stop_wpa "$INTERFACE" + + # File of 0 length, ie. no ssid's. + if [[ ! -s "$essids" ]]; then + rm -f "$essids" + return 1 + fi + + echo "$essids" + return 0 +} + +# Requires already loaded profile +make_wpa_config_file() { + local WPA_CONFD="$STATE_DIR/wpa.$1" + + # make empty tmp dir with correct permissions, rename it + check_make_state_dir + mkdir -p /run/wpa_supplicant + rm -rf "$WPA_CONFD" + mv -f "$(mktemp -d --tmpdir=$STATE_DIR)" "$WPA_CONFD" || return 1 + echo "ctrl_interface=/run/wpa_supplicant" >> "$WPA_CONFD/wpa.conf" + echo "ctrl_interface_group=${WPA_GROUP:-wheel}" >> "$WPA_CONFD/wpa.conf" + [[ $WPA_COUNTRY ]] && echo "country=$WPA_COUNTRY" >> "$WPA_CONFD/wpa.conf" + [[ -n "$ADHOC" ]] && echo "ap_scan=2" >> "$WPA_CONFD/wpa.conf" + echo "$WPA_CONFD/wpa.conf" +} + +# Requires already loaded profile +make_wpa_config() { + case $SECURITY in + none|wep|wpa) + case "${ESSID_TYPE:-ascii}" in + ascii) + echo "ssid=\"$ESSID\"" + ;; + hex) + # Hex ESSID is written unquoted and in lowercase (FS#24333) + echo "ssid=${ESSID,,}" + ;; + *) + report_fail "ESSID_TYPE must be set to 'ascii' or 'hex'." + return 1 + ;; + esac + if [[ -n "$AP" ]]; then + echo "bssid=${AP,,}" + fi + [[ -n "$ADHOC" ]] && echo "mode=1" + ;; + wpa-configsection) + echo "$CONFIGSECTION" + ;; + *) + return 1 + ;; + esac + + # Key management + case $SECURITY in + none) + echo "key_mgmt=NONE" + ;; + wep) + echo "key_mgmt=NONE" + echo "wep_tx_keyidx=0" + if [[ ${KEY:0:2} == "s:" ]]; then # TODO: does wpa_supplicant handle this as expected? + echo "wep_key0=\"${KEY:2}\"" + else + echo "wep_key0=$KEY" + fi + ;; + wpa) + echo "proto=RSN WPA" + if [[ "${#KEY}" -eq 64 ]]; then + echo "psk=$KEY" + else + echo "psk=\"$KEY\"" + fi + ;; + esac + + # Hidden SSID + if checkyesno ${HIDDEN:-no}; then + echo "scan_ssid=1" + fi + + # Priority group for the network + if [[ -n "$PRIORITY" ]]; then + echo "priority=$PRIORITY" + fi +} + +# vim: ft=sh ts=4 et sw=4 tw=0: diff --git a/src/lib/auto.action b/src/lib/auto.action new file mode 100755 index 0000000..1f29364 --- /dev/null +++ b/src/lib/auto.action @@ -0,0 +1,56 @@ +#! /bin/bash + +interface="$1" +ssid="$2" +profile="$3" +action="$4" + +. /usr/lib/network/network +[[ "$profile" ]] && load_profile "$profile" + +case $action in + CONNECT) + if [[ -z $profile ]]; then + # Load interface specific config + [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" + dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" -K $DHCP_OPTIONS "$interface" + exit $? + fi + if ! DHCPCD_INTERNAL_OPTIONS="-K" $CONN_DIR/ethernet up "$profile"; then + exit 1 # what to do if fail? + fi + + set_profile up "$profile" + + if ! ( eval $POST_UP ); then # JP: sandbox the eval + # failing POST_UP will take interface down + "$CONN_DIR/$ethernet" down "$profile" + exit 1 + fi + ;; + DISCONNECT) + if [[ -z $profile ]]; then + dhcpcd -k "$interface" + exit $? + fi + if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval + exit 1 + fi + if ! "$CONN_DIR/ethernet" down "$profile"; then + exit 1 + fi + if ! ( eval $POST_DOWN ); then # JP: sandbox the eval + exit 1 + fi + set_profile down "$profile" + ;; + LOST|REESTABLISHED) + # Not handled. + exit 0 + ;; + *) + # ??? + exit 1 + ;; +esac + diff --git a/src/lib/connections/README b/src/lib/connections/README new file mode 100644 index 0000000..38ef11a --- /dev/null +++ b/src/lib/connections/README @@ -0,0 +1,28 @@ +Support for connection types is implemented by connection files in + + /usr/lib/network/connections/ + +The file name determines the name of the connection type, so support +for the aviancarrier connection type will be provided by the file: + + /usr/lib/network/connections/aviancarrier + +Files that implement support for a connection type should NOT be +executable. Such files should contain valid Bash code, among which two +functions, namely _up and _down. For +the aviancarrier file this would be: + + aviancarrier_up + aviancarrier_down + +These functions are responsible for bringing the network up and down, +respectively. When the functions are called, three bash files are +already sourced, so all functions and variables in those files are +available. The readily sourced files are: + + /usr/lib/network/network + /usr/lib/network/globals + /etc/network.d/ + +Here, is the profile file specifying the desired network +configuration. diff --git a/src/lib/connections/bond b/src/lib/connections/bond new file mode 100644 index 0000000..bc5aa95 --- /dev/null +++ b/src/lib/connections/bond @@ -0,0 +1,40 @@ +#! /bin/bash +. /usr/lib/network/network +IFENSLAVE="/sbin/ifenslave" + +bond_up() { + load_profile "$1" + + if [[ -e "/sys/class/net/$INTERFACE" ]]; then + report_fail "Interface $INTERFACE already exists." + exit 1 + else + ip link add dev $INTERFACE type bond + fi + bring_interface up "$INTERFACE" + + for slave in "${SLAVE_INTERFACES[@]}"; do + bring_interface up "$slave" + $IFENSLAVE $INTERFACE $slave + done + + "$CONN_DIR/ethernet" up "$1" + return 0 +} + +bond_down() { + load_profile "$1" + + for slave in "${SLAVE_INTERFACES[@]}"; do + $IFENSLAVE $INTERFACE -d $slave + done + + "$CONN_DIR/ethernet" down "$1" + ip link delete "$INTERFACE" + return 0 +} + +bond_$1 "$2" +exit $? + +# vim: set ts=4 et sw=4: diff --git a/src/lib/connections/bridge b/src/lib/connections/bridge new file mode 100644 index 0000000..6b3ab67 --- /dev/null +++ b/src/lib/connections/bridge @@ -0,0 +1,47 @@ +#! /bin/bash +. /usr/lib/network/network +BRCTL="/usr/sbin/brctl" + +bridge_up() { + local bridge_interface + load_profile "$1" + + if [[ -e "/sys/class/net/$INTERFACE" ]]; then + if [[ ! -d "/sys/class/net/$INTERFACE/brif" ]]; then + report_fail "Interface $INTERFACE already exists and is not a bridge." + exit 1 + fi + else + $BRCTL addbr "$INTERFACE" + fi + + for bridge_client in $BRIDGE_INTERFACES; do + ip link set "$bridge_client" promisc on up + ip addr flush dev "$bridge_client" + $BRCTL addif "$INTERFACE" "$bridge_client" + done + # Set options + [[ "$FWD_DELAY" ]] && $BRCTL setfd "$INTERFACE" "$FWD_DELAY" + [[ "$MAX_AGE" ]] && $BRCTL setmaxage "$INTERFACE" "$MAX_AGE" + + "$CONN_DIR/ethernet" up "$1" + return 0 +} + +bridge_down() { + local bridge_interface + load_profile "$1" + + for bridge_client in $BRIDGE_INTERFACES; do + ip link set "$bridge_client" promisc off down + $BRCTL delif "$INTERFACE" "$bridge_client" + done + + "$CONN_DIR/ethernet" down "$1" + $BRCTL delbr "$INTERFACE" + return 0 +} + +bridge_$1 "$2" +exit $? +# vim: set ts=4 et sw=4: diff --git a/src/lib/connections/ethernet b/src/lib/connections/ethernet new file mode 100644 index 0000000..487adf8 --- /dev/null +++ b/src/lib/connections/ethernet @@ -0,0 +1,279 @@ +#! /bin/bash +# Source file for the 'ethernet' connection +# ethernet_up $profile +# ethernet_down $profile +# ethernet_status + +. /usr/lib/network/network + +report_iproute() +{ + report_fail "$*" + bring_interface down "$INTERFACE" + exit 1 +} + +ethernet_up() { + load_profile "$1" + SYSCTL_INTERFACE="${INTERFACE/.//}" + + if ! is_interface "$INTERFACE"; then + report_iproute "Interface $INTERFACE does not exist" + fi + + # Disable IPv6 before bringing the interface up to prevent SLAAC + if [[ "$IP6" == "no" ]]; then + sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.disable_ipv6=1" + fi + + report_debug ethernet_up bring_interface up "$INTERFACE" + bring_interface up "$INTERFACE" + + if ! checkyesno "${SKIPNOCARRIER:-no}"; then + # Some cards are plain slow to come up. Don't fail immediately. + if ! timeout_wait "${CARRIER_TIMEOUT:-5}" '(( $(< "/sys/class/net/$INTERFACE/carrier") ))'; then + report_iproute "No connection" + fi + fi + + + if checkyesno "${AUTH8021X:-no}"; then + . "$SUBR_DIR/8021x" + [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" + [[ -z "$WPA_DRIVER" ]] && WPA_DRIVER="wired" + + report_debug ethernet_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS" + if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then + report_fail "wpa_supplicant did not start, possible configuration error" + return 1 + fi + + if ! wpa_check "$INTERFACE" "$TIMEOUT" "ASSOCIATED"; then + bring_interface down "$INTERFACE" + report_fail "WPA Authentication/Association Failed" + return 1 + fi + fi + + if [[ -z "$IP" && -z "$IP6" ]]; then + report_iproute "At least one of IP or IP6 should be specified" + return 1 + fi + + case "$IP" in + dhcp) + if checkyesno "${DHCLIENT:-no}"; then + rm -r "/run/dhclient-${INTERFACE}.pid" >/dev/null 2>&1 + report_debug ethernet_up dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/run/dhclient-$INTERFACE.pid" "$INTERFACE" + if ! dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/run/dhclient-${INTERFACE}.pid" ${DHCLIENT_OPTIONS} "$INTERFACE"; then + report_fail "DHCP IP lease attempt failed." + stop_80211x + return 1 + fi + else + # Clear remaining pid files. + rm -f "/run/dhcpcd-$INTERFACE".{pid,cache} >/dev/null 2>&1 + # If using own dns, tell dhcpcd to NOT replace resolv.conf + [[ -n "$DNS" ]] && DHCP_OPTIONS="-C resolv.conf $DHCP_OPTIONS" + # Start dhcpcd + report_debug ethernet_up dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCPCD_INTERNAL_OPTIONS $DHCP_OPTIONS "$INTERFACE" + dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCPCD_INTERNAL_OPTIONS $DHCP_OPTIONS "$INTERFACE" 2>&1 | report_debug "$(cat)" + if [[ "$PIPESTATUS" -ne 0 ]]; then + report_fail "DHCP IP lease attempt failed." + stop_80211x + return 1 + fi + fi + ;; + static) + if [[ -n "$ADDR" ]]; then + [[ -z $NETMASK ]] && NETMASK=24 + report_debug ethernet_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE" + if ! ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"; then + report_iproute "Could not configure interface" + fi + fi + if [[ -n "$GATEWAY" ]]; then + report_debug ethernet_up ip route add default via "$GATEWAY" dev "$INTERFACE" + if ! ip route add default via "$GATEWAY" dev "$INTERFACE"; then + report_iproute "Adding gateway $GATEWAY failed" + fi + fi + ;; + ""|no) + ;; + *) + report_iproute "IP must be either 'dhcp', 'static' or 'no'" + ;; + esac + + if [[ -n "$IP" && -n "$ROUTES" ]]; then + for route in "${ROUTES[@]}"; do + report_debug ethernet_up ip route add $route dev "$INTERFACE" + if ! ip route add $route dev "$INTERFACE"; then + report_iproute "Adding route '$route' failed" + fi + done + fi + + # Load ipv6 module if necessary (FS#25530) + case "$IP6" in + dhcp*|stateless|static) + [[ -d "/proc/sys/net/ipv6" ]] || modprobe ipv6 + ;; + no) + [[ -d "/proc/sys/net/ipv6" ]] && sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=0" + ;; + "") # undefined IP6 does not prevent RA's from being received -> nop + ;; + *) + report_iproute "IP6 must be 'dhcp', 'dhcp-noaddr', 'stateless', 'static' or 'no'" + ;; + esac + + case "$IP6" in + dhcp*) + if ! type dhclient &>/dev/null; then + report_fail "You need to install dhclient to use DHCPv6." + stop_80211x + return 1 + fi + sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=1" + if [[ "$IP6" == "dhcp-noaddr" ]]; then + DHCLIENT6_OPTIONS="-S ${DHCLIENT6_OPTIONS}" + fi + _DHCLIENT_PIDFILE="/run/dhclient6-${INTERFACE}.pid" + rm -r ${_DHCLIENT_PIDFILE} &>/dev/null + report_debug ethernet_up dhclient -6 -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf ${_DHCLIENT_PIDFILE} "$INTERFACE" + if ! dhclient -6 -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf ${_DHCLIENT_PIDFILE} ${DHCLIENT6_OPTIONS} "$INTERFACE"; then + report_fail "DHCPv6 IP lease attempt failed." + stop_80211x + return 1 + fi + ;; + stateless) + sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=1" + ;; + static) + sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=0" + if [[ -n "$ADDR6" ]]; then + for addr in "${ADDR6[@]}"; do + report_debug ethernet_up ip -6 addr add $addr dev "$INTERFACE" + if ! ip -6 addr add $addr dev "$INTERFACE"; then + report_iproute "Could not add address '$addr' to interface" + fi + done + fi + ;; + esac + + if [[ -n "$IP6" ]]; then + # Wait for DAD to finish (FS#28887) + report_debug ethernet_up ip -6 addr show dev "$INTERFACE" tentative + if ! timeout_wait "${DAD_TIMEOUT:-3}" '[[ -z "$(ip -6 addr show dev "$INTERFACE" tentative)" ]]'; then + report_iproute "Duplicate Address Detection is taking too long" + fi + + # Add static IPv6 routes + if [[ -n "$ROUTES6" ]]; then + for route in "${ROUTES6[@]}"; do + report_debug ethernet_up ip -6 route add $route dev "$INTERFACE" + if ! ip -6 route add $route dev "$INTERFACE"; then + report_iproute "Adding route '$route' failed" + fi + done + fi + + # Set a custom gateway after waiting for DAD to finish + if [[ "$IP6" == "static" && -n "$GATEWAY6" ]]; then + report_debug ethernet_up ip -6 route replace default via "$GATEWAY6" dev "$INTERFACE" + if ! ip -6 route replace default via "$GATEWAY6" dev "$INTERFACE"; then + report_iproute "Adding gateway $GATEWAY6 failed" + fi + fi + fi + + if [[ -n "$IPCFG" ]]; then + for line in "${IPCFG[@]}"; do + report_debug ethernet_up ip "$line" + if ! ip $line; then + report_iproute "Could not configure interface ($line)." + fi + done + fi + + # Set hostname + if [[ -n "$HOSTNAME" ]]; then + report_debug ethernet_up hostname "$HOSTNAME" + if ! echo "$HOSTNAME" >/proc/sys/kernel/hostname; then + report_iproute "Cannot set hostname to $HOSTNAME" + fi + fi + + # Generate a new resolv.conf + if [[ -n "$DNS" ]]; then + : >/etc/resolv.conf + [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf + [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf + for dns in "${DNS[@]}"; do + echo "nameserver $dns" >>/etc/resolv.conf + done + for dnsoption in "${DNS_OPTIONS[@]}"; do + echo "options $dnsoption" >>/etc/resolv.conf + done + fi + + return 0 +} + +ethernet_down() { + load_profile "$1" + + if [[ "$IP" == "dhcp" ]]; then + if checkyesno "${DHCLIENT:-no}"; then + if [[ -f "/run/dhclient-$INTERFACE.pid" ]]; then + report_debug ethernet_down dhclient -q -x "$INTERFACE" -pf "/run/dhclient-$INTERFACE.pid" + dhclient -q -x "$INTERFACE" -pf "/run/dhclient-$INTERFACE.pid" &>/dev/null + #dhclient -q -r "$INTERFACE" &>/dev/null + fi + else + if [[ -f "/run/dhcpcd-$INTERFACE.pid" ]]; then + report_debug ethernet_down dhcpcd -qk "$INTERFACE" + dhcpcd -qk "$INTERFACE" &>/dev/null + fi + fi + fi + if [[ "$IP6" == dhcp* ]]; then + if [[ -f "/run/dhclient6-$INTERFACE.pid" ]]; then + report_debug ethernet_down dhclient -6 -q -x "$INTERFACE" -pf "/run/dhclient6-$INTERFACE.pid" + dhclient -6 -q -x "$INTERFACE" -pf "/run/dhclient6-$INTERFACE.pid" &>/dev/null + report_debug ethernet_down /bin/kill $(< /run/dhclient6-$INTERFACE.pid) + /bin/kill $(< /run/dhclient6-$INTERFACE.pid) &>/dev/null + fi + fi + + stop_80211x + + if [[ "$CONNECTION" == "wireless" ]]; then + report_debug ethernet_down bring_interface flush "$INTERFACE" + bring_interface flush "$INTERFACE" + else + report_debug ethernet_down bring_interface down "$INTERFACE" + bring_interface down "$INTERFACE" + fi + return 0 +} + +# Stop wpa_supplicant if neccessary +stop_80211x() { + if checkyesno "${AUTH8021X:-no}"; then + . "$SUBR_DIR/8021x" + [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" + report_debug ethernet_down stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" + fi +} + +ethernet_$1 "$2" +exit $? +# vim: set ts=4 et sw=4: diff --git a/src/lib/connections/pppoe b/src/lib/connections/pppoe new file mode 100644 index 0000000..17fe42d --- /dev/null +++ b/src/lib/connections/pppoe @@ -0,0 +1,77 @@ +#! /bin/bash +. /usr/lib/network/network + +_quotestring() { + echo "\"${1/\"/\\\"}\"" +} + +pppoe_up() { + local cfg + load_profile "$1" + + mkdir -p "$STATE_DIR/pppoe.${INTERFACE}.$1/" + chmod 700 "$STATE_DIR/pppoe.${INTERFACE}.$1/" + cfg="$STATE_DIR/pppoe.${INTERFACE}.$1/options" + : > "${cfg}" + chmod 600 "${cfg}" + + echo "plugin rp-pppoe.so" >> "${cfg}" + echo "nic-${INTERFACE}" >> "${cfg}" + echo "noauth" >> "${cfg}" + if checkyesno ${DEFAULTROUTE:-1}; then + echo "defaultroute" >> "${cfg}" + else + echo "nodefaultroute" >> "${cfg}" + fi + if checkyesno ${USEPEERDNS:-1}; then + echo "usepeerdns" >> "${cfg}" + fi + echo "linkname $(_quotestring "$1")" >> "${cfg}" + echo "maxfail 5" >> "${cfg}" + echo "updetach" >> "${cfg}" + if [[ ${CONNECTION_MODE} == demand ]]; then + echo "demand" >> "${cfg}" + echo "idle ${IDLE_TIMEOUT}" >> "${cfg}" + else + echo "persist" >> "${cfg}" + fi + echo "user $(_quotestring "${USER}")" >> "${cfg}" + echo "password $(_quotestring "${PASSWORD}")" >> "${cfg}" + [[ -n ${LCP_ECHO_INTERVAL} ]] && echo "lcp-echo-interval ${LCP_ECHO_INTERVAL}" >> "${cfg}" + [[ -n ${LCP_ECHO_FAILURE} ]] && echo "lcp-echo-failure ${LCP_ECHO_FAILURE}" >> "${cfg}" + [[ -n ${PPPOE_SERVICE} ]] && echo "rp_pppoe_service $(_quotestring "${PPPOE_SERVICE}")" >> "${cfg}" + [[ -n ${PPPOE_AC} ]] && echo "rp_pppoe_ac $(_quotestring "${PPPOE_AC}")" >> "${cfg}" + [[ -n ${PPPOE_SESSION} ]] && echo "rp_pppoe_sess $(_quotestring "${PPPOE_SESSION}")" >> "${cfg}" + [[ -n ${PPPOE_MAC} ]] && echo "pppoe-mac $(_quotestring "${PPPOE_MAC}")" >> "${cfg}" + [[ ${PPPOE_IP6} == yes ]] && echo "+ipv6" >> "${cfg}" + + /sbin/ip link set dev "${INTERFACE}" up + /usr/sbin/pppd file "${cfg}" + + if [[ $? -ne 0 ]]; then + rm "${cfg}" + rmdir "$STATE_DIR/pppoe.${INTERFACE}.$1/" + report_fail "Couldn't make pppd connection." + return 1 + fi +} + +pppoe_down() { + load_profile "$1" + local cfg + cfg="$STATE_DIR/pppoe.${INTERFACE}.$1/options" + PIDFILE="/var/run/ppp-$1.pid" + + if [[ -e $PIDFILE ]]; then + read PID < "$PIDFILE" + [[ "$PID" ]] && kill "$PID" + fi + + rm "${cfg}" + rmdir "$STATE_DIR/pppoe.${INTERFACE}.$1/" +} + +pppoe_$1 "$2" +exit $? + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/lib/connections/tunnel b/src/lib/connections/tunnel new file mode 100644 index 0000000..6cefc5c --- /dev/null +++ b/src/lib/connections/tunnel @@ -0,0 +1,34 @@ +#! /bin/bash +. /usr/lib/network/network + +tunnel_up() { + load_profile "$1" + + if [[ -e "/sys/class/net/$INTERFACE" ]]; then + report_fail "Interface $INTERFACE already exists." + exit 1 + else + ip tunnel add "$INTERFACE" mode "$MODE" remote "$REMOTE" + fi + + if [[ -n "$LOCAL" ]]; then + ip tunnel change "$INTERFACE" local "$LOCAL" + fi + + "$CONN_DIR/ethernet" up "$1" + return 0 +} + +tunnel_down() { + load_profile "$1" + + "$CONN_DIR/ethernet" down "$1" + ip tunnel del "$INTERFACE" + + return 0 +} + +tunnel_$1 "$2" +exit $? + +# vim: set ts=4 et sw=4: diff --git a/src/lib/connections/tuntap b/src/lib/connections/tuntap new file mode 100644 index 0000000..6985c8c --- /dev/null +++ b/src/lib/connections/tuntap @@ -0,0 +1,28 @@ +#! /bin/bash +. /usr/lib/network/network + +tuntap_up() { + load_profile "$1" + + if [[ -e /sys/class/net/$INTERFACE ]]; then + report_fail "Interface $INTERFACE already exists." + exit 1 + else + ip tuntap add dev "$INTERFACE" mode "$MODE" \ + user "$USER" group "$GROUP" + fi + IP=${IP-no} "$CONN_DIR/ethernet" up "$1" + return 0 +} + +tuntap_down() { + load_profile "$1" + + "$CONN_DIR/ethernet" down "$1" + ip tuntap del dev "$INTERFACE" mode "$MODE" + return 0 +} + +tuntap_$1 "$2" +exit $? +# vim: set ts=4 et sw=4 tw=0: diff --git a/src/lib/connections/vlan b/src/lib/connections/vlan new file mode 100644 index 0000000..75c7fa9 --- /dev/null +++ b/src/lib/connections/vlan @@ -0,0 +1,28 @@ +#! /bin/bash +. /usr/lib/network/network + +vlan_up() { + load_profile "$1" + + if [[ -e "/sys/class/net/$INTERFACE" ]]; then + report_fail "Interface $INTERFACE already exists." + exit 1 + else + bring_interface up "$VLAN_PHYS_DEV" + ip link add link "$VLAN_PHYS_DEV" name "$INTERFACE" type vlan id "$VLAN_ID" + fi + "$CONN_DIR/ethernet" up "$1" + return 0 +} + +vlan_down() { + load_profile "$1" + + "$CONN_DIR/ethernet" down "$1" + ip link delete "$INTERFACE" + return 0 +} + +vlan_$1 "$2" +exit $? +# vim: set ts=4 et sw=4: diff --git a/src/lib/connections/wireless b/src/lib/connections/wireless new file mode 100644 index 0000000..135bec7 --- /dev/null +++ b/src/lib/connections/wireless @@ -0,0 +1,116 @@ +#! /bin/bash +. /usr/lib/network/network +. "$SUBR_DIR/8021x" +. "$SUBR_DIR/rfkill" + +wireless_up() { + PROFILE="$1" + load_profile "$PROFILE" + + # Default settings + SECURITY=${SECURITY:-none} + WPA_DRIVER=${WPA_DRIVER:-nl80211,wext} + + enable_rf $INTERFACE $RFKILL $RFKILL_NAME || return 1 + + # Check if interface exists + is_interface "$INTERFACE" || { report_fail "interface $INTERFACE does not exist"; return 1; } + + # Kill any lingering wpa_supplicants. + stop_wpa "$INTERFACE" &> /dev/null + + # Start wpa_supplicant + if [[ "$SECURITY" = "wpa-config" ]]; then + WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}" + else + WPA_CONF=$(make_wpa_config_file $INTERFACE) + fi + report_debug wireless_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS" + if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then + report_fail "wpa_supplicant did not start, possible configuration error" + return 1 + fi + + # Scan for network's existence first + if checkyesno "${SCAN:-no}"; then + report_debug wireless_up scanning + local OLDESSID="$ESSID" + if [[ -n "$AP" ]]; then + BSSID=$(wpa_find_ap "$INTERFACE" "$AP") + else + ESSID=$(wpa_find_essid "$INTERFACE" "$ESSID") + fi + if [[ $? -gt 0 ]]; then + report_fail "Wireless network \"$OLDESSID\" not present." + report_debug wireless_up stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" + return 1 + fi + fi + + # Build configuration file + case "$SECURITY" in + wpa-config) + ;; + none|wep|wpa|wpa-configsection) + printf "%s\n" "network={" "$(make_wpa_config)" "}" >> "$WPA_CONF" + report_debug wireless_up "Configuration generated at $WPA_CONF" + report_debug wireless_up wpa_reconfigure "$INTERFACE" + if ! wpa_reconfigure "$INTERFACE"; then + report_fail "WPA configuration failed!" + stop_wpa "$INTERFACE" + return 1 + fi + ;; + *) + report_fail "Invalid SECURITY setting: $SECURITY" + ;; + esac + + # Bring interface up after starting wpa_supplicant + # This is important since cards such as iwl3945 do not support + # mode switching when they are already up. + report_debug wireless_up ifup + bring_interface up "$INTERFACE" || return 1 + + report_debug wireless_up wpa_check + if ! wpa_check "$INTERFACE" "$TIMEOUT"; then + report_fail "WPA Authentication/Association Failed" + return 1 + fi + + if ! "$CONN_DIR/ethernet" up "$PROFILE"; then + wireless_down "$PROFILE" YES + return 1 + fi +} + +# wireless_down PROFILE [ LEAVE ifconfig up? default no ] +wireless_down() { + local PROFILE="$1" + load_profile "$PROFILE" + + "$CONN_DIR/ethernet" down "$PROFILE" + + # The config file can contain a non-standard control socket path + if [[ "$SECURITY" = "wpa-config" ]]; then + WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}" + fi + report_debug wireless_down stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" + rm -rf "$STATE_DIR/wpa.$INTERFACE" + + bring_interface down "$INTERFACE" + + # Handle wireless kill switches + # Any reason why a hardware switch should be considered on interface down? + if [[ "$RFKILL" == "soft" ]]; then + set_rf_state "$INTERFACE" disabled $RFKILL_NAME || return 1 + fi +} + +wireless_$1 "$2" "$3" +exit $? + +# vim: ft=sh ts=4 et sw=4 tw=0: + diff --git a/src/lib/globals b/src/lib/globals new file mode 100644 index 0000000..491f9d6 --- /dev/null +++ b/src/lib/globals @@ -0,0 +1,136 @@ +# /usr/lib/networks/globals +# +# All +x files in /usr/lib/network/hooks will be sourced when this file is. +# Hook files can override any of the utility functions defined here for custom +# behavior (such as logging error messages to syslog). This lets us keep netcfg +# simple but gives it the flexibility for users to make modular use of it to do +# more complex things + + +### Globals +PROFILE_DIR="/etc/network.d" +IFACE_DIR="$PROFILE_DIR/interfaces" +SUBR_DIR="/usr/lib/network" +HOOKS_DIR="$SUBR_DIR/hooks" +CONN_DIR="$SUBR_DIR/connections" +STATE_DIR="/run/network" + + + +### Logging/Error reporting + +function report_err { + echo "$*" +} + +function report_notice { + echo "$*" +} + +function report_debug { + checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 +} + +function report_try { + # This needs -n and a trailing space. + echo -n ":: $* " + REPORT_TRYING=1 +} + +function report_fail { + if [[ -n "$*" ]]; then + if (( REPORT_TRYING )); then + echo "- $* [fail]" + REPORT_TRYING= + else + echo "$*" + fi + elif (( REPORT_TRYING )); then + echo "[fail]" + REPORT_TRYING= + fi +} + +function report_success { + if [[ -n "$*" ]]; then + # This needs -n and a trailing space. + echo -n "- $* " + fi + echo "[done]" + REPORT_TRYING= +} + +### For calling scripts only; don't use in library functions +function exit_stderr { echo "$*" >&2; exit 1; } +function exit_err { report_err "$*"; exit 1; } +function exit_fail { report_fail "$*"; exit 1; } + + +### From FreeBSD's /etc/rc.subr +## +# checkyesno var +# Test $1 variable, and warn if not set to YES or NO. +# Return 0 if it's "yes" (et al), nonzero otherwise. +# To default to yes, do: "checkyesno ${VAR:-yes}". +# +function checkyesno() { + local _value="$1" + #debug "checkyesno: $1 is set to $_value." + case "$_value" in + + # "yes", "true", "on", or "1" + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + return 0 + ;; + + # "no", "false", "off", or "0" + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + return 1 + ;; + *) + #warn "\$${1} is not set properly - see rc.conf(5)." + return 1 + ;; + esac +} + +## Check if variable is a member of an array +# $1: the variable to find +# $2...: the array elements +function inarray() { + local item search="$1" + shift + for item in "$@"; do + if [[ "$item" == "$search" ]]; then + return 0 + fi + done + return 1 +} + +## Waits until a statement succeeds or a timeout occurs +# $1: timeout in seconds +# $2...: condition command +function timeout_wait() { + local timeout="$1" + (( timeout *= 10 )) + shift + while ! eval "$*"; do + (( timeout-- > 0 )) || return 1 + sleep 0.1 + done + return 0 +} + + +### Load all +x files in $HOOKS_DIR +function load_hooks() { + local hook + for hook in $(find -L "$HOOKS_DIR/" -maxdepth 1 -type f -executable | sort -u); do + source "$hook" + done +} + +load_hooks + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/lib/network b/src/lib/network new file mode 100644 index 0000000..1aa384c --- /dev/null +++ b/src/lib/network @@ -0,0 +1,368 @@ +### Globals +. /usr/lib/network/globals +# will load hooks + +## Loads a profile. +# $1: profile name +load_profile() +{ + unset ROUTES + [[ -z "$1" ]] && return 1 + if [[ ! -f "$PROFILE_DIR/$1" ]]; then + report_err "Profile \"$1\" does not exist" + return 1 + fi + report_debug "Loading profile $1" + INTERFACE=$(. "$PROFILE_DIR/$1"; echo "$INTERFACE") + report_debug "Configuring interface $INTERFACE" + if [[ -z "$INTERFACE" ]]; then + report_err "Profile missing an interface to configure" + return 1 + fi + if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then + report_debug "Interface level configuration enabled: $IFACE_DIR/$INTERFACE" + . "$IFACE_DIR/$INTERFACE" + fi + . "$PROFILE_DIR/$1" # we want profile settings to override, so need to source profile again + if [[ ! -f "$CONN_DIR/$CONNECTION" ]]; then + report_err "$CONNECTION is not a valid connection, check spelling or look at examples" + return 1 + fi +} + +################## +# Profile up/down +################## + +## Take all registered profiles down. +all_down() +{ + find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \ + | while read prof; do + profile_down "$prof" + done +} + +## Create the state dir and sub directories if they don't already exist. +check_make_state_dir() +{ + [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles} + for d in interfaces profiles suspend; do + [[ ! -d "$STATE_DIR/$d" ]] && mkdir "$STATE_DIR/$d" + done +} + +## Save the list of running profiles and take them down if needed +# $1: interface name or "all" +# $2: take associated profiles down (optional, default="yes") +interface_suspend() +{ + report_debug interface_suspend "$@" + + check_make_state_dir + find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \ + | while read prof; do + # the pipe to "while read" will create a subshell + INTERFACE=$(. "$STATE_DIR/profiles/$prof"; echo "$INTERFACE") + if [[ "$1" == all || "$1" == "$INTERFACE" ]]; then + report_notice "suspending interface $INTERFACE with profile $prof" + cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/" + if checkyesno "${2:-yes}"; then + profile_down "$prof" + fi + fi + done +} + +## Save the list of all running profiles and take them down +all_suspend() { + interface_suspend all +} + +## Restore saved profiles (for resume purposes). +# $@: a list of interfaces not to resume (e.g., because they're disabled) +all_resume() +{ + report_debug all_resume "$@" + find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \ + | while read prof; do + # the pipe to "while read" will create a subshell + INTERFACE=$(. "$STATE_DIR/suspend/$prof"; echo "$INTERFACE") + if [[ $# -eq 0 || ! " $* " =~ " $INTERFACE " ]]; then + report_notice "resuming interface $INTERFACE with profile $prof" + profile_up "$prof" + rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this + fi + done +} + +## Puts up a profile. +# $1: the profile name +profile_up() +{ + ( + # Keep inside subshell so that options from one profile don't cross to others + # exit 1 used in a subshell is effectively exiting a new process + check_make_state_dir + + local status PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks + + load_profile "$PROFILE" || exit 1 + + if check_profile "$PROFILE"; then + report_err "$PROFILE already connected" + exit 1 + fi + + # EXCLUSIVE, network.d/profile: Individual profile is mutually exclusive + if checkyesno "$EXCLUSIVE"; then + all_down + fi + + report_try "$PROFILE up" + + status=$(check_iface "$INTERFACE") + report_debug "status reported to profile_up as: $status" + case "$status" in + external) + report_fail "Interface $INTERFACE externally controlled" + exit 1 + ;; + disabled) + report_fail "Interface $INTERFACE is disabled" + exit 1 + ;; + "") + ;; + *) + if checkyesno "$CHECK"; then + report_fail "Interface $INTERFACE already in use" + exit 1 + + # not necessary to sandbox this call or reload PROFILE afterwards + elif ! interface_down "$INTERFACE"; then + report_fail + exit 1 + fi + ;; + esac + + if ! ( eval $PRE_UP ); then # JP: sandbox the eval so variables don't bleed into current function + report_debug profile_up "PRE_UP failed" + report_fail + exit 1 + fi + + if ! "$CONN_DIR/$CONNECTION" up "$PROFILE"; then + report_debug profile_up "connect failed" + report_fail + # "$CONN_DIR/$CONNECTION" down "$PROFILE" # JP: should we do this to make sure? + exit 1 + fi + + if ! ( eval $POST_UP ); then # JP: sandbox the eval + report_debug profile_up "POST_UP failed" + report_fail + # failing POST_UP will take interface down + "$CONN_DIR/$CONNECTION" down "$PROFILE" + exit 1 + fi + + set_profile up "$PROFILE" + unset EXCLUSIVE + + # Successfully running a new profile; erase any suspended profiles on this interface + local iface="$INTERFACE" + find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \ + | while read prof; do + # the pipe to "while read" will create a subshell + INTERFACE=$(. "$STATE_DIR/suspend/$prof"; echo "$INTERFACE") + if [[ "$iface" == "$INTERFACE" ]]; then + rm "$STATE_DIR/suspend/$prof" + fi + done + + report_success + ); return $? +} + +## Puts a profile down. +# $1: the profile name +profile_down() +{ + ( + check_make_state_dir + + local status PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks + + load_profile "$PROFILE" || exit 1 + + status=$(check_iface "$INTERFACE") + report_debug "status reported to profile_down as: $status" + + if [[ "$status" != "$PROFILE" ]]; then + # if interface not available to be controlled by netcfg, then + # any profiles should have been removed by check_iface + # else we get here if another profile is running + report_err "Profile not connected" + exit 1 + fi + + report_try "$PROFILE down" + if [[ "$(check_iface "$INTERFACE")" == "external" ]]; then + report_fail "$interface was connected by another application" + exit 1 + fi + + if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval + report_debug profile_down "PRE_DOWN failed" + # true # JP: did we want failing PRE_DOWN to leave the profile active? + report_fail + exit 1 + fi + + if ! "$CONN_DIR/$CONNECTION" down "$PROFILE"; then + report_debug profile_up "disconnect failed" + report_fail + exit 1 + fi + + if ! ( eval $POST_DOWN ); then # JP: sandbox the eval + report_debug profile_down "POST_DOWN failed" + report_fail + exit 1 + fi + + set_profile down "$PROFILE" + report_success + ); return $? +} + +# interface_down interface +# take interface down +# +interface_down() +{ + local profile=$(check_iface "$1") + case "$profile" in + ""|disabled) return 0 ;; + external) return 1 ;; + *) profile_down "$profile" ;; + esac +} + +# interface_reconnect interface +# reconnects the profile active on interface +interface_reconnect() +{ + local profile=$(check_iface "$1") + case "$profile" in + ""|disabled|external) + return 1 + ;; + *) + profile_down "$profile" + profile_up "$profile" + ;; + esac +} + +## +# check_iface interface +# Return 0 if interface unavailable (in use by a profile or externally, or disabled) +# Return 1 if interface down and available to be used +# +check_iface() { + if [[ -f "$STATE_DIR/interfaces/$1" ]]; then + cat "$STATE_DIR/interfaces/$1" + return 0 + else + return 1 + fi +} + +# list_profiles +# Outputs a list of all profiles +list_profiles() { + # JP: follow aliases with -L, also skip profiles that start with '.' or end with '~' or '.conf' (so profile.conf can be the wpa.conf file for profile) + find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf "%f\n" +} + +# check_profile profile +# Return 0 if profile registered as being up +# Return 1 if profile not registered +# +check_profile() { + [[ -f "$STATE_DIR/profiles/$1" && ! -f "$STATE_DIR/suspend/$1" ]] && return 0 + return 1 +} + +### Status setting functions +## +# set_profile up/down profile +# Set profile state, either up or down +# +set_profile() { + local INTERFACE + if [[ "$1" == "up" ]]; then + INTERFACE=$(. "$PROFILE_DIR/$2"; echo "$INTERFACE") + cp "$PROFILE_DIR/$2" "$STATE_DIR/profiles/" + set_iface up "$INTERFACE" "$2" + elif [[ "$1" == "down" && -f "$STATE_DIR/profiles/$2" ]]; then # JP: skip if profile not already up + INTERFACE=$(. "$STATE_DIR/profiles/$2"; echo "$INTERFACE") + rm "$STATE_DIR/profiles/$2" + set_iface down "$INTERFACE" "$2" + fi +} + +# set_iface up/down interface [profile] +# Set interface status to up/down +# optionally link it to a profile. +# +set_iface() { + local PROFILE="${3:-external}" + if [[ "$1" == "up" ]]; then + echo "$PROFILE" > "$STATE_DIR/interfaces/$2" + elif [[ "$1" == "down" ]]; then + rm -f "$STATE_DIR/interfaces/$2" # JP: add -f so we don't complain if the interface isn't up + fi +} + +is_interface() { + local INTERFACE="$1" + if [[ ! -e "/sys/class/net/$INTERFACE" ]]; then + if ! echo "$INTERFACE" | grep -F -q ":"; then + return 1 + fi + fi + return 0 +} + +interface_is_up() { + local flags + read flags < "/sys/class/net/$1/flags" + # IFF_UP is defined as 0x1 in linux/if.h + (( flags & 0x1 )) +} + +## Changes a network interface state. +# $1: up, flush, or down. +# $2: the interface name +bring_interface() +{ + local INTERFACE="$2" + case "$1" in + up) + ip link set dev "$INTERFACE" up &>/dev/null + timeout_wait "${UP_TIMEOUT:-5}" 'interface_is_up "$INTERFACE"' || return 1 + ;; + flush|down) + ip addr flush dev "$INTERFACE" &>/dev/null + ;;& + down) + ip link set dev "$INTERFACE" down &>/dev/null + ;; + esac +} + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/lib/rfkill b/src/lib/rfkill new file mode 100644 index 0000000..1832dc1 --- /dev/null +++ b/src/lib/rfkill @@ -0,0 +1,61 @@ +set_rf_state() { + local INTERFACE="$1" state="$2" RFKILL_NAME="$3" + + if [[ "$RFKILL" == "hard" ]]; then + report_fail "Cannot set state on hardware rfkill switch" + return 1 + fi + local path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 + case "$state" in + enabled) + echo 0 > "$path/soft" + ;; + disabled) + echo 1 > "$path/soft" + ;; + esac +} + +get_rf_path() { + local INTERFACE="$1" RFKILL_NAME="$2" path + + if [[ -n "$RFKILL_NAME" ]]; then + for path in /sys/class/rfkill/*; do + if [[ "$(< "$path/name")" == "$RFKILL_NAME" ]]; then + echo "$path" + return 0 + fi + done + report_fail "no rfkill switch with name $RFKILL_NAME" + else + path=$(find -L "/sys/class/net/$INTERFACE/" -maxdepth 2 -type d -name "rfkill*" 2> /dev/null | head -n 1) + if [[ -n "$path" ]]; then + echo "$path" + return 0 + fi + report_fail "no rfkill switch available on interface $INTERFACE" + fi + return 1 +} + +enable_rf() { + local INTERFACE="$1" RFKILL="$2" RFKILL_NAME="$3" path hard soft + + # Enable rfkill if necessary, or fail if it is hardware + if [[ -n "$RFKILL" ]]; then + path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 + read hard < "$path/hard" + read soft < "$path/soft" + + if (( hard )); then + report_fail "radio is disabled on $INTERFACE" + return 1 + elif (( soft )); then + set_rf_state "$INTERFACE" enabled "$RFKILL_NAME" || return 1 + timeout_wait 1 "(( ! \$(< \"$path/soft\") ))" + fi + fi +} + +# vim: ft=sh ts=4 et sw=4: + diff --git a/src/netctl b/src/netctl new file mode 100755 index 0000000..f1d79e8 --- /dev/null +++ b/src/netctl @@ -0,0 +1,106 @@ +#!/bin/bash + +. /usr/lib/network/network + +NETCFG_VER=2-notpackaged + +version() +{ + echo "netcfg v$NETCFG_VER" +} + +usage() +{ + version + cat << END +Usage: + Start specified profile: netcfg profile + Other functions: netcfg argument profile +Arguments: + current Report currently running profiles +-a, all-down Take all active profiles down +-c, check-iface Do not start profile if interface is already up +-d, down Take specified profile down +-D, iface-down Take down profile active on specified interface +-h, help This help message +-l, list List all available profiles +-r, reconnect Disconnect and reconnect specified profile +-R, iface-recon Reconnect profile active on specified interface +-u, up Start specified profile +-v, version Output version information and exit + all-resume Resume previously suspended profiles and reconnect them + all-suspend Store a list of current running profiles and suspend them +END +} + +# TODO: Re-add ROOT check and rewrite with getopts from BashFAQ + +case "$1" in + --version|-v|version) + version + exit 0;; + --help|-h|help) + usage + exit 0;; + list|-l) + list_profiles + exit 0;; + current|-s|status) + if [[ -d "$STATE_DIR/profiles/" ]]; then + ls "$STATE_DIR/profiles/" + exit 0 + else + exit_stderr "No active profiles." + fi;; +esac + +if [[ $(id -u) -gt 0 ]]; then + exit_stderr "This script should be run as root." +fi + +# Ensure cwd is not in a transient directory, which may prevent unmounting due to netcfg children +cd / + +case "$1" in + -c|check-iface|-u|up) + CHECK="YES" + profile_up "$2";; + -d|down) + profile_down "$2";; + -D|iface-down) + interface_down "$2";; + -a|all-down) + all_down;; + -r|reconnect) + profile_down "$2" + profile_up "$2";; + -R|iface-recon) + interface_reconnect "$2";; + all-resume) + all_resume;; + all-suspend) + all_suspend;; + clean) + rm "$STATE_DIR/interfaces"/* 2> /dev/null + rm "$STATE_DIR/profiles"/* 2> /dev/null + rm "$STATE_DIR/suspend"/* 2> /dev/null + rm "$STATE_DIR/netcfg-daemon" 2> /dev/null + killall wpa_supplicant 2> /dev/null + killall dhcpcd 2> /dev/null + killall dhclient 2> /dev/null + ;; + -*|--*) + usage + exit 1;; + *) + if [[ -n "$1" ]]; then + profile_up "$1" + else + usage + exit 1 + fi + ;; +esac +exit $? + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/netctl-auto b/src/netctl-auto new file mode 100755 index 0000000..c6aaf67 --- /dev/null +++ b/src/netctl-auto @@ -0,0 +1,87 @@ +#! /bin/bash +. /usr/lib/network/network +. "$SUBR_DIR/8021x" +. "$SUBR_DIR/rfkill" +. /etc/conf.d/netcfg + +AUTOWIFI="/usr/sbin/wpa_actiond -p /run/wpa_supplicant" +ACTION_SCRIPT="/usr/bin/netcfg-wpa_actiond-action" + +case $1 in + help) + echo "netcfg-wpa_actiond " + echo "netcfg-wpa_actiond stop " + exit + ;; + stop) + [[ -z $2 ]] && echo "Please specify an interface to stop" && exit 1 + interface=$2 + PIDFILE="/run/wpa_actiond_${interface}.pid" + [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" + netcfg -D "$interface" + timeout_wait 1 '[[ ! -f "$PIDFILE" ]]' || kill "$(< "$PIDFILE")" + # only try to disable software rfkill switches (FS#25514) + if [[ "$RFKILL" == "soft" ]]; then + set_rf_state "$interface" disabled $RFKILL_NAME || exit $? + fi + exit + ;; + *) + interface=$1; shift + PIDFILE="/run/wpa_actiond_${interface}.pid" + EXTRA_AUTOWIFI_OPTIONS="$*" + ;; +esac + +if [[ -z $interface ]]; then + echo "No interface specified" + exit 1 +fi + +# Load interface specific config +[[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" + +if [[ -f "$CONN_DIR/interfaces/$interface" ]]; then + netcfg -D "$interface" +fi + +if [[ -n "$RFKILL" ]]; then # Enable radio if necessary + enable_rf "$interface" "$RFKILL" "$RFKILL_NAME" || exit $? +fi + +WPA_CONF="$(make_wpa_config_file "$interface")" + +if [[ -n "${AUTO_PROFILES}" ]]; then + for prof in "${AUTO_PROFILES[@]}"; do echo "$prof"; done +else + list_profiles +fi | while read profile; do + echo "$profile" + ( + load_profile "$profile" + + [[ $CONNECTION != "wireless" ]] && exit 1 + [[ $INTERFACE != $interface ]] && exit 1 + # Exclude wpa-config, the wpa_conf is 'complete' and doesn't fit in this scheme + [[ -z "$SECURITY" ]] && SECURITY="none" + [[ $SECURITY == "wpa-config" ]] && exit 1 + + printf "%s\n" "network={" "$(make_wpa_config)" "id_str=\"$profile\"" "}" >> "$WPA_CONF" + ) +done + + +[[ -z $WPA_DRIVER ]] && WPA_DRIVER="nl80211,wext" +WPA_OPTS="-W $WPA_OPTS" + +# Kill any existing wpa_supplicant on this interface +stop_wpa "$interface" &> /dev/null + +if start_wpa "$interface" "$WPA_CONF" "$WPA_DRIVER" $WPA_OPTS; then + if $AUTOWIFI -i "$interface" -P "$PIDFILE" -a "$ACTION_SCRIPT" $EXTRA_AUTOWIFI_OPTIONS; then + exit 0 + fi +fi + +exit 1 + diff --git a/src/network b/src/network deleted file mode 100644 index 1aa384c..0000000 --- a/src/network +++ /dev/null @@ -1,368 +0,0 @@ -### Globals -. /usr/lib/network/globals -# will load hooks - -## Loads a profile. -# $1: profile name -load_profile() -{ - unset ROUTES - [[ -z "$1" ]] && return 1 - if [[ ! -f "$PROFILE_DIR/$1" ]]; then - report_err "Profile \"$1\" does not exist" - return 1 - fi - report_debug "Loading profile $1" - INTERFACE=$(. "$PROFILE_DIR/$1"; echo "$INTERFACE") - report_debug "Configuring interface $INTERFACE" - if [[ -z "$INTERFACE" ]]; then - report_err "Profile missing an interface to configure" - return 1 - fi - if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then - report_debug "Interface level configuration enabled: $IFACE_DIR/$INTERFACE" - . "$IFACE_DIR/$INTERFACE" - fi - . "$PROFILE_DIR/$1" # we want profile settings to override, so need to source profile again - if [[ ! -f "$CONN_DIR/$CONNECTION" ]]; then - report_err "$CONNECTION is not a valid connection, check spelling or look at examples" - return 1 - fi -} - -################## -# Profile up/down -################## - -## Take all registered profiles down. -all_down() -{ - find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do - profile_down "$prof" - done -} - -## Create the state dir and sub directories if they don't already exist. -check_make_state_dir() -{ - [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles} - for d in interfaces profiles suspend; do - [[ ! -d "$STATE_DIR/$d" ]] && mkdir "$STATE_DIR/$d" - done -} - -## Save the list of running profiles and take them down if needed -# $1: interface name or "all" -# $2: take associated profiles down (optional, default="yes") -interface_suspend() -{ - report_debug interface_suspend "$@" - - check_make_state_dir - find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do - # the pipe to "while read" will create a subshell - INTERFACE=$(. "$STATE_DIR/profiles/$prof"; echo "$INTERFACE") - if [[ "$1" == all || "$1" == "$INTERFACE" ]]; then - report_notice "suspending interface $INTERFACE with profile $prof" - cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/" - if checkyesno "${2:-yes}"; then - profile_down "$prof" - fi - fi - done -} - -## Save the list of all running profiles and take them down -all_suspend() { - interface_suspend all -} - -## Restore saved profiles (for resume purposes). -# $@: a list of interfaces not to resume (e.g., because they're disabled) -all_resume() -{ - report_debug all_resume "$@" - find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do - # the pipe to "while read" will create a subshell - INTERFACE=$(. "$STATE_DIR/suspend/$prof"; echo "$INTERFACE") - if [[ $# -eq 0 || ! " $* " =~ " $INTERFACE " ]]; then - report_notice "resuming interface $INTERFACE with profile $prof" - profile_up "$prof" - rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this - fi - done -} - -## Puts up a profile. -# $1: the profile name -profile_up() -{ - ( - # Keep inside subshell so that options from one profile don't cross to others - # exit 1 used in a subshell is effectively exiting a new process - check_make_state_dir - - local status PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks - - load_profile "$PROFILE" || exit 1 - - if check_profile "$PROFILE"; then - report_err "$PROFILE already connected" - exit 1 - fi - - # EXCLUSIVE, network.d/profile: Individual profile is mutually exclusive - if checkyesno "$EXCLUSIVE"; then - all_down - fi - - report_try "$PROFILE up" - - status=$(check_iface "$INTERFACE") - report_debug "status reported to profile_up as: $status" - case "$status" in - external) - report_fail "Interface $INTERFACE externally controlled" - exit 1 - ;; - disabled) - report_fail "Interface $INTERFACE is disabled" - exit 1 - ;; - "") - ;; - *) - if checkyesno "$CHECK"; then - report_fail "Interface $INTERFACE already in use" - exit 1 - - # not necessary to sandbox this call or reload PROFILE afterwards - elif ! interface_down "$INTERFACE"; then - report_fail - exit 1 - fi - ;; - esac - - if ! ( eval $PRE_UP ); then # JP: sandbox the eval so variables don't bleed into current function - report_debug profile_up "PRE_UP failed" - report_fail - exit 1 - fi - - if ! "$CONN_DIR/$CONNECTION" up "$PROFILE"; then - report_debug profile_up "connect failed" - report_fail - # "$CONN_DIR/$CONNECTION" down "$PROFILE" # JP: should we do this to make sure? - exit 1 - fi - - if ! ( eval $POST_UP ); then # JP: sandbox the eval - report_debug profile_up "POST_UP failed" - report_fail - # failing POST_UP will take interface down - "$CONN_DIR/$CONNECTION" down "$PROFILE" - exit 1 - fi - - set_profile up "$PROFILE" - unset EXCLUSIVE - - # Successfully running a new profile; erase any suspended profiles on this interface - local iface="$INTERFACE" - find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do - # the pipe to "while read" will create a subshell - INTERFACE=$(. "$STATE_DIR/suspend/$prof"; echo "$INTERFACE") - if [[ "$iface" == "$INTERFACE" ]]; then - rm "$STATE_DIR/suspend/$prof" - fi - done - - report_success - ); return $? -} - -## Puts a profile down. -# $1: the profile name -profile_down() -{ - ( - check_make_state_dir - - local status PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks - - load_profile "$PROFILE" || exit 1 - - status=$(check_iface "$INTERFACE") - report_debug "status reported to profile_down as: $status" - - if [[ "$status" != "$PROFILE" ]]; then - # if interface not available to be controlled by netcfg, then - # any profiles should have been removed by check_iface - # else we get here if another profile is running - report_err "Profile not connected" - exit 1 - fi - - report_try "$PROFILE down" - if [[ "$(check_iface "$INTERFACE")" == "external" ]]; then - report_fail "$interface was connected by another application" - exit 1 - fi - - if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval - report_debug profile_down "PRE_DOWN failed" - # true # JP: did we want failing PRE_DOWN to leave the profile active? - report_fail - exit 1 - fi - - if ! "$CONN_DIR/$CONNECTION" down "$PROFILE"; then - report_debug profile_up "disconnect failed" - report_fail - exit 1 - fi - - if ! ( eval $POST_DOWN ); then # JP: sandbox the eval - report_debug profile_down "POST_DOWN failed" - report_fail - exit 1 - fi - - set_profile down "$PROFILE" - report_success - ); return $? -} - -# interface_down interface -# take interface down -# -interface_down() -{ - local profile=$(check_iface "$1") - case "$profile" in - ""|disabled) return 0 ;; - external) return 1 ;; - *) profile_down "$profile" ;; - esac -} - -# interface_reconnect interface -# reconnects the profile active on interface -interface_reconnect() -{ - local profile=$(check_iface "$1") - case "$profile" in - ""|disabled|external) - return 1 - ;; - *) - profile_down "$profile" - profile_up "$profile" - ;; - esac -} - -## -# check_iface interface -# Return 0 if interface unavailable (in use by a profile or externally, or disabled) -# Return 1 if interface down and available to be used -# -check_iface() { - if [[ -f "$STATE_DIR/interfaces/$1" ]]; then - cat "$STATE_DIR/interfaces/$1" - return 0 - else - return 1 - fi -} - -# list_profiles -# Outputs a list of all profiles -list_profiles() { - # JP: follow aliases with -L, also skip profiles that start with '.' or end with '~' or '.conf' (so profile.conf can be the wpa.conf file for profile) - find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf "%f\n" -} - -# check_profile profile -# Return 0 if profile registered as being up -# Return 1 if profile not registered -# -check_profile() { - [[ -f "$STATE_DIR/profiles/$1" && ! -f "$STATE_DIR/suspend/$1" ]] && return 0 - return 1 -} - -### Status setting functions -## -# set_profile up/down profile -# Set profile state, either up or down -# -set_profile() { - local INTERFACE - if [[ "$1" == "up" ]]; then - INTERFACE=$(. "$PROFILE_DIR/$2"; echo "$INTERFACE") - cp "$PROFILE_DIR/$2" "$STATE_DIR/profiles/" - set_iface up "$INTERFACE" "$2" - elif [[ "$1" == "down" && -f "$STATE_DIR/profiles/$2" ]]; then # JP: skip if profile not already up - INTERFACE=$(. "$STATE_DIR/profiles/$2"; echo "$INTERFACE") - rm "$STATE_DIR/profiles/$2" - set_iface down "$INTERFACE" "$2" - fi -} - -# set_iface up/down interface [profile] -# Set interface status to up/down -# optionally link it to a profile. -# -set_iface() { - local PROFILE="${3:-external}" - if [[ "$1" == "up" ]]; then - echo "$PROFILE" > "$STATE_DIR/interfaces/$2" - elif [[ "$1" == "down" ]]; then - rm -f "$STATE_DIR/interfaces/$2" # JP: add -f so we don't complain if the interface isn't up - fi -} - -is_interface() { - local INTERFACE="$1" - if [[ ! -e "/sys/class/net/$INTERFACE" ]]; then - if ! echo "$INTERFACE" | grep -F -q ":"; then - return 1 - fi - fi - return 0 -} - -interface_is_up() { - local flags - read flags < "/sys/class/net/$1/flags" - # IFF_UP is defined as 0x1 in linux/if.h - (( flags & 0x1 )) -} - -## Changes a network interface state. -# $1: up, flush, or down. -# $2: the interface name -bring_interface() -{ - local INTERFACE="$2" - case "$1" in - up) - ip link set dev "$INTERFACE" up &>/dev/null - timeout_wait "${UP_TIMEOUT:-5}" 'interface_is_up "$INTERFACE"' || return 1 - ;; - flush|down) - ip addr flush dev "$INTERFACE" &>/dev/null - ;;& - down) - ip link set dev "$INTERFACE" down &>/dev/null - ;; - esac -} - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/rfkill b/src/rfkill deleted file mode 100644 index 1832dc1..0000000 --- a/src/rfkill +++ /dev/null @@ -1,61 +0,0 @@ -set_rf_state() { - local INTERFACE="$1" state="$2" RFKILL_NAME="$3" - - if [[ "$RFKILL" == "hard" ]]; then - report_fail "Cannot set state on hardware rfkill switch" - return 1 - fi - local path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 - case "$state" in - enabled) - echo 0 > "$path/soft" - ;; - disabled) - echo 1 > "$path/soft" - ;; - esac -} - -get_rf_path() { - local INTERFACE="$1" RFKILL_NAME="$2" path - - if [[ -n "$RFKILL_NAME" ]]; then - for path in /sys/class/rfkill/*; do - if [[ "$(< "$path/name")" == "$RFKILL_NAME" ]]; then - echo "$path" - return 0 - fi - done - report_fail "no rfkill switch with name $RFKILL_NAME" - else - path=$(find -L "/sys/class/net/$INTERFACE/" -maxdepth 2 -type d -name "rfkill*" 2> /dev/null | head -n 1) - if [[ -n "$path" ]]; then - echo "$path" - return 0 - fi - report_fail "no rfkill switch available on interface $INTERFACE" - fi - return 1 -} - -enable_rf() { - local INTERFACE="$1" RFKILL="$2" RFKILL_NAME="$3" path hard soft - - # Enable rfkill if necessary, or fail if it is hardware - if [[ -n "$RFKILL" ]]; then - path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 - read hard < "$path/hard" - read soft < "$path/soft" - - if (( hard )); then - report_fail "radio is disabled on $INTERFACE" - return 1 - elif (( soft )); then - set_rf_state "$INTERFACE" enabled "$RFKILL_NAME" || return 1 - timeout_wait 1 "(( ! \$(< \"$path/soft\") ))" - fi - fi -} - -# vim: ft=sh ts=4 et sw=4: - diff --git a/src/wifi-menu b/src/wifi-menu new file mode 100755 index 0000000..f46db0d --- /dev/null +++ b/src/wifi-menu @@ -0,0 +1,263 @@ +#! /bin/bash + +. /usr/lib/network/network +. "$SUBR_DIR/8021x" +. /etc/conf.d/netcfg + +usage() +{ + cat << END +Usage: wifi-menu [-o | --obscure] [-h | --help] [interface] + +Interactively connect to a wireless network. + +Arguments: + -o, --obscure Show asterisks for the characters of the password + and store the password as a hexadecimal string. + -h, --help Show this help. + interface The wireless interface to use. + (default: WIRELESS_INTERFACE from /etc/conf.d/netcfg) + +For choosing from all available profiles, use netcfg-menu. +END +} + +# Fills PROFILES and ESSIDS with the profile names and essids of the profiles +# for interface $1. +init_profiles() +{ + local i=0 essid profile + while read profile; do + essid=$( + unset INTERFACE ESSID + . "$PROFILE_DIR/$profile" &> /dev/null + if [[ "$INTERFACE" = "$1" && -n "$ESSID" ]]; then + printf "%s" "$ESSID" + if [[ "$DESCRIPTION" =~ "Automatically generated" ]]; then + return 2 + else + return 1 + fi + fi + return 0 + ) + case $? in + 2) + GENERATED+=("$profile") + ;& + 1) + PROFILES[i]=$profile + ESSIDS[i]=$essid + (( ++i )) + ;; + esac + done < <(list_profiles) +} + +# Builds ENTRIES as an argument list for dialog based on scan results in $1. +init_entries() +{ + local i=0 flags signal ssid + while IFS=$'\t' read signal flags ssid; do + ENTRIES[i++]="--" # $ssid might look like an option to dialog. + ENTRIES[i++]=$ssid + if inarray "$ssid" "${ESSIDS[@]}"; then + if inarray "$(ssid_to_profile "$ssid")" "${GENERATED[@]}"; then + ENTRIES[i]="+" # Automatically generated + else + ENTRIES[i]="*" # Handmade + fi + else + ENTRIES[i]="-" # Not present + fi + if [[ "$ssid" = "$CONNECTION" ]]; then + ENTRIES[i]="!" # Currently connected + fi + if [[ "$flags" =~ WPA2|WPA|WEP ]]; then + ENTRIES[i]+=":${BASH_REMATCH[0],,}" + else + ENTRIES[i]+=":none" + fi + ENTRIES[i]+=" :$signal" + (( ++i )) + done < "$1" +} + +# Finds a profile name for ssid $1. +ssid_to_profile() +{ + local i + for i in $(seq 0 $((${#ESSIDS[@]}-1))); do + if [[ "$1" = "${ESSIDS[i]}" ]]; then + printf "%s" "${PROFILES[i]}" + return 0 + fi + done + return 1 +} + +# Creates a profile for ssid $1. +create_profile() +{ + local box flags key msg security + PROFILE="$INTERFACE-${1//\//_}" + [[ -e "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu" + flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2) + if [[ "$flags" =~ WPA|WEP ]]; then + security=${BASH_REMATCH[0],,} + else + security=none + fi + if [[ "$flags" =~ PSK|WEP ]]; then + [[ "$OBSCURE" ]] && box="--insecure --passwordbox" || box="--inputbox" + msg="Enter $security security key for\n'$1'" + key=$(dialog $box "$msg" 10 40 --stdout) || return $? + if [[ "${#key}" -ge 8 && "${#key}" -le 63 ]]; then + if [[ "$OBSCURE" ]]; then + key=$(wpa_passphrase "$1" "$key" | grep -m 1 "^[[:space:]]*psk=") + key=${key#*psk=} + else + key=$(printf "%q" "$key") + fi + elif ! [[ "${#key}" -eq 64 && "$key" = +([[:xdigit:]]) ]]; then + return 4 + fi + fi + cat << EOF > "$PROFILE_DIR/$PROFILE" +CONNECTION='wireless' +DESCRIPTION='Automatically generated profile by wifi-menu' +INTERFACE='$INTERFACE' +SECURITY='$security' +ESSID=$(printf "%q" "$1") +IP='dhcp' +${key+KEY=$key} +EOF + printf "%s" "$PROFILE" + return 0 +} + +# Connects to ssid $1 using an available profile or an automatically created +# one if none exists. +connect_to_ssid() +{ + local msg + PROFILE=$(ssid_to_profile "$1") + if [[ $? -eq 0 ]]; then + clear + check_profile "$PROFILE" && profile_down "$PROFILE" + else + PROFILE=$(create_profile "$1") + RETURN=$? + (( RETURN == 0 )) || return $RETURN + SPAWNED_PROFILE=1 + clear + fi + if ! profile_up "$PROFILE"; then + if (( SPAWNED_PROFILE )); then + msg=" CONNECTING FAILED + +Do you want to keep the generated profile ('$PROFILE')?" + dialog --yesno "$msg" 10 40 --stdout || rm "$PROFILE_DIR/$PROFILE" + clear + fi + return 2 + fi + return 0 +} + +while [[ "$1" = -* ]]; do + case "$1" in + -h|--help) + usage + exit + ;; + -o|--obscure) + OBSCURE=1 + shift + ;; + -*) + report_err "Invalid option: $1" + usage + exit 255 + ;; + esac +done +if [[ $# -gt 1 ]]; then + report_err "Too many arguments" + usage + exit 255 +fi + +if [[ $(id -u) -ne 0 ]]; then + exit_stderr "This script needs to be run with root privileges" +fi +if ! type dialog &> /dev/null; then + exit_stderr "Please install 'dialog' to use wifi-menu" +fi + +INTERFACE=${1-$WIRELESS_INTERFACE} +if [[ -z "$INTERFACE" ]]; then + report_err "Missing interface specification" + usage + exit 255 +fi + +cd / # We do not want to spawn anything that can block unmounting +is_interface "$INTERFACE" || exit_fail "No such interface: $INTERFACE" +if ! interface_is_up "$INTERFACE"; then + [[ -f "$IFACE_DIR/$INTERFACE" ]] && . "$IFACE_DIR/$INTERFACE" + bring_interface up "$INTERFACE" || exit_fail "Interface unavailable" + SPAWNED_INTERFACE=1 +fi + +report_try "Scanning for networks" +CONNECTION=$(wpa_call "$INTERFACE" status 2> /dev/null | grep -m 1 "^ssid=") +CONNECTION=${CONNECTION#ssid=} +NETWORKS=$(wpa_supplicant_scan "$INTERFACE" 3,4,5) +if [[ $? -eq 0 ]]; then + trap 'rm -f "$NETWORKS"' EXIT + report_success + init_profiles "$INTERFACE" + init_entries "$NETWORKS" + MSG="Select the network you wish to use +Flags description: + * - handmade profile present + + - automatically generated profile present + - - no profile present + ! - active connection present" + CHOICE=$(dialog --column-separator : --menu "$MSG" 24 50 12 \ + "${ENTRIES[@]}" --stdout) + RETURN=$? + if (( RETURN == 0 )); then + connect_to_ssid "$CHOICE" + RETURN=$? + fi +else + report_fail + RETURN=3 +fi + +case $RETURN in + 0|2) # Connected | Connecting failed + ;; + 1) # Canceled + clear + ;; + 3) # No networks found + report_err "No networks found" + ;; + 4) # Invalid passphrase length (WEP keys have tighter restrictions) + clear + report_err "Passphrase must be 8..63 characters" + ;; + 255) # ESC or error + clear + report_err "Aborted" + ;; + *) # Should not happen + report_err "Unexpected return code from dialog: $RETURN" + RETURN=7 + ;; +esac +(( RETURN && SPAWNED_INTERFACE )) && bring_interface down "$INTERFACE" +exit $RETURN diff --git a/systemd/net-auto-wired.service b/systemd/net-auto-wired.service deleted file mode 100644 index 8948ac6..0000000 --- a/systemd/net-auto-wired.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Automatic wired network connection via netcfg - -[Service] -EnvironmentFile=/etc/conf.d/netcfg -ExecStart=/usr/bin/ifplugd -i $WIRED_INTERFACE -r /etc/ifplugd/netcfg.action -fIns -ExecStop=/usr/bin/netcfg iface-down $WIRED_INTERFACE - -[Install] -WantedBy=multi-user.target diff --git a/systemd/net-auto-wireless.service b/systemd/net-auto-wireless.service deleted file mode 100644 index 81f2369..0000000 --- a/systemd/net-auto-wireless.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Automatic wireless network connection via netcfg -Before=network.target -Wants=network.target - -[Service] -EnvironmentFile=/etc/conf.d/netcfg -ExecStart=/usr/bin/netcfg-wpa_actiond $WIRELESS_INTERFACE -ExecStop=/usr/bin/netcfg-wpa_actiond stop $WIRELESS_INTERFACE -RemainAfterExit=yes -Type=forking - -[Install] -WantedBy=multi-user.target diff --git a/systemd/netcfg.service b/systemd/netcfg.service deleted file mode 100644 index f400be0..0000000 --- a/systemd/netcfg.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Netcfg multi-profile daemon -Before=network.target -Wants=network.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/bin/netcfg-daemon start -ExecStop=/usr/bin/netcfg-daemon stop -KillMode=none - -[Install] -WantedBy=multi-user.target diff --git a/systemd/netcfg@.service b/systemd/netcfg@.service deleted file mode 100644 index 57229f8..0000000 --- a/systemd/netcfg@.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Netcfg networking service for profile %i -Before=network.target -Wants=network.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/bin/netcfg check-iface %i -ExecStop=-/usr/bin/netcfg down %i -KillMode=none - -[Install] -WantedBy=multi-user.target -- cgit v1.2.3-24-g4f1b