summaryrefslogtreecommitdiffstats
path: root/src/lib/connections
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/connections')
-rw-r--r--src/lib/connections/bond41
-rw-r--r--src/lib/connections/bridge53
-rw-r--r--src/lib/connections/ethernet276
-rw-r--r--src/lib/connections/pppoe55
-rw-r--r--src/lib/connections/tunnel34
-rw-r--r--src/lib/connections/tuntap32
-rw-r--r--src/lib/connections/vlan34
-rw-r--r--src/lib/connections/wireless137
8 files changed, 202 insertions, 460 deletions
diff --git a/src/lib/connections/bond b/src/lib/connections/bond
index bc5aa95..09e51c6 100644
--- a/src/lib/connections/bond
+++ b/src/lib/connections/bond
@@ -1,40 +1,35 @@
-#! /bin/bash
-. /usr/lib/network/network
+# Contributed by: Byron Williams <byron@112percent.com>
+
+. "$SUBR_DIR/ip"
+
IFENSLAVE="/sbin/ifenslave"
bond_up() {
- load_profile "$1"
-
- if [[ -e "/sys/class/net/$INTERFACE" ]]; then
- report_fail "Interface $INTERFACE already exists."
- exit 1
+ if is_interface "$Interface"; then
+ report_error "Interface '$Interface' already exists"
+ return 1
else
- ip link add dev $INTERFACE type bond
+ ip link add dev "$Interface" type bond
fi
- bring_interface up "$INTERFACE"
+ bring_interface_up "$Interface"
- for slave in "${SLAVE_INTERFACES[@]}"; do
- bring_interface up "$slave"
- $IFENSLAVE $INTERFACE $slave
+ for slave in "${BindsToInterfaces[@]}"; do
+ bring_interface_up "$slave"
+ $IFENSLAVE "$Interface" "$slave"
done
- "$CONN_DIR/ethernet" up "$1"
- return 0
+ ip_set
}
bond_down() {
- load_profile "$1"
-
- for slave in "${SLAVE_INTERFACES[@]}"; do
- $IFENSLAVE $INTERFACE -d $slave
+ for slave in "${BindsToInterfaces[@]}"; do
+ $IFENSLAVE "$Interface" -d "$slave"
done
- "$CONN_DIR/ethernet" down "$1"
- ip link delete "$INTERFACE"
- return 0
+ ip_unset
+ bring_interface_down "$Interface"
+ ip link delete "$Interface"
}
-bond_$1 "$2"
-exit $?
# vim: set ts=4 et sw=4:
diff --git a/src/lib/connections/bridge b/src/lib/connections/bridge
index 6b3ab67..929a76b 100644
--- a/src/lib/connections/bridge
+++ b/src/lib/connections/bridge
@@ -1,47 +1,42 @@
-#! /bin/bash
-. /usr/lib/network/network
+# Contributed by: Thomas Bächler <thomas@archlinux.org>
+
+. "$SUBR_DIR/ip"
+
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
+ if is_interface "$Interface"; then
+ if [[ ! -d "/sys/class/net/$Interface/brif" ]]; then
+ report_error "Interface '$Interface' already exists and is not a bridge"
+ return 1
fi
else
- $BRCTL addbr "$INTERFACE"
+ $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"
+ for member in "${BindsToInterfaces[@]}"; do
+ ip link set "$member" promisc on up
+ ip addr flush dev "$member"
+ $BRCTL addif "$Interface" "$member"
done
# Set options
- [[ "$FWD_DELAY" ]] && $BRCTL setfd "$INTERFACE" "$FWD_DELAY"
- [[ "$MAX_AGE" ]] && $BRCTL setmaxage "$INTERFACE" "$MAX_AGE"
+ [[ "$FwdDelay" ]] && $BRCTL setfd "$Interface" "$FwdDelay"
+ [[ "$MaxAge" ]] && $BRCTL setmaxage "$Interface" "$MaxAge"
- "$CONN_DIR/ethernet" up "$1"
- return 0
+ bring_interface_up "$Interface"
+ ip_set
}
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"
+ for member in "${BindsToInterfaces[@]}"; do
+ ip link set "$member" promisc off down
+ $BRCTL delif "$Interface" "$member"
done
- "$CONN_DIR/ethernet" down "$1"
- $BRCTL delbr "$INTERFACE"
- return 0
+ ip_unset
+ bring_interface_down "$Interface"
+ $BRCTL delbr "$Interface"
}
-bridge_$1 "$2"
-exit $?
+
# vim: set ts=4 et sw=4:
diff --git a/src/lib/connections/ethernet b/src/lib/connections/ethernet
index 487adf8..0fff668 100644
--- a/src/lib/connections/ethernet
+++ b/src/lib/connections/ethernet
@@ -1,279 +1,75 @@
-#! /bin/bash
-# Source file for the 'ethernet' connection
-# ethernet_up $profile
-# ethernet_down $profile
-# ethernet_status
+# Ethernet connection support for netctl
-. /usr/lib/network/network
+. "$SUBR_DIR/ip"
-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"
+ if ! is_interface "$Interface"; then
+ report_error "Interface '$Interface' does not exist"
+ return 1
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"
+ if [[ $IP6 == "no" ]]; then
+ sysctl -q -w "net.ipv6.conf.${Interface/.//}.disable_ipv6=1"
fi
- report_debug ethernet_up bring_interface up "$INTERFACE"
- bring_interface up "$INTERFACE"
+ if ! bring_interface_up "$Interface"; then
+ report_error "Failed to bring interface '$Interface' up"
+ return 1
+ fi
- if ! checkyesno "${SKIPNOCARRIER:-no}"; then
+ if ! is_yes "${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"
+ if ! timeout_wait "${TimeoutCarrier:-5}" '(( $(< "/sys/class/net/$Interface/carrier") ))'; then
+ report_error "No connection on interface '$Interface'"
+ bring_interface_down "$Interface"
+ return 1
fi
fi
- if checkyesno "${AUTH8021X:-no}"; then
+ if is_yes "${Auth8021X:-no}"; then
. "$SUBR_DIR/8021x"
- [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf"
- [[ -z "$WPA_DRIVER" ]] && WPA_DRIVER="wired"
+ : ${WPAConfigFile:=/etc/wpa_supplicant.conf}
+ : ${WPADriver:=wired}
+ : ${TimeoutWPA:=15}
- 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"
+ if ! wpa_start "$Interface" "$WPADriver" "$WPAConfigFile"; then
+ report_error "The WPA supplicant did not start for interface '$Interface'"
+ bring_interface_down "$Interface"
return 1
fi
- if ! wpa_check "$INTERFACE" "$TIMEOUT" "ASSOCIATED"; then
- bring_interface down "$INTERFACE"
- report_fail "WPA Authentication/Association Failed"
+ if ! wpa_wait_until_state "$TimeoutWPA" "$Interface" "ASSOCIATED"; then
+ wpa_stop "$Interface"
+ bring_interface_down "$Interface"
+ report_error "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"
+ if ! ip_set; then
+ stop_80211x
+ bring_interface_down "$Interface"
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
-
+ ip_unset
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
+ bring_interface_down "$Interface"
}
# Stop wpa_supplicant if neccessary
stop_80211x() {
- if checkyesno "${AUTH8021X:-no}"; then
+ if is_yes "${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"
+ : ${WPAConfigFile:=/etc/wpa_supplicant.conf}
+ do_debug wpa_stop "$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
index 17fe42d..b24b503 100644
--- a/src/lib/connections/pppoe
+++ b/src/lib/connections/pppoe
@@ -1,5 +1,4 @@
-#! /bin/bash
-. /usr/lib/network/network
+# Contributed by: Thomas Bächler <thomas@archlinux.org>
_quotestring() {
echo "\"${1/\"/\\\"}\""
@@ -7,60 +6,58 @@ _quotestring() {
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"
+ mkdir -p "$STATE_DIR/pppoe.${Interface}.$1/"
+ chmod 700 "$STATE_DIR/pppoe.${Interface}.${Profile}/"
+ cfg="$STATE_DIR/pppoe.${Interface}.${Profile}/options"
: > "${cfg}"
chmod 600 "${cfg}"
echo "plugin rp-pppoe.so" >> "${cfg}"
- echo "nic-${INTERFACE}" >> "${cfg}"
+ echo "nic-${Interface}" >> "${cfg}"
echo "noauth" >> "${cfg}"
- if checkyesno ${DEFAULTROUTE:-1}; then
+ if is_yes "${DefaultRoute:-yes}"; then
echo "defaultroute" >> "${cfg}"
else
echo "nodefaultroute" >> "${cfg}"
fi
- if checkyesno ${USEPEERDNS:-1}; then
+ if is_yes "${UsePeerDNS:-yes}"; then
echo "usepeerdns" >> "${cfg}"
fi
- echo "linkname $(_quotestring "$1")" >> "${cfg}"
+ echo "linkname $(_quotestring "${Profile}")" >> "${cfg}"
echo "maxfail 5" >> "${cfg}"
echo "updetach" >> "${cfg}"
- if [[ ${CONNECTION_MODE} == demand ]]; then
+ if [[ ${ConnectionMode} == demand ]]; then
echo "demand" >> "${cfg}"
- echo "idle ${IDLE_TIMEOUT}" >> "${cfg}"
+ echo "idle ${IdleTimeout}" >> "${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}"
+ echo "user $(_quotestring "${User}")" >> "${cfg}"
+ echo "password $(_quotestring "${Password}")" >> "${cfg}"
+ [[ -n ${LCPEchoInterval} ]] && echo "lcp-echo-interval ${LCPEchoInterval}" >> "${cfg}"
+ [[ -n ${LCPEchoFailure} ]] && echo "lcp-echo-failure ${LCPEchoFailure}" >> "${cfg}"
+ [[ -n ${PPPoEService} ]] && echo "rp_pppoe_service $(_quotestring "${PPPoEService}")" >> "${cfg}"
+ [[ -n ${PPPoEAC} ]] && echo "rp_pppoe_ac $(_quotestring "${PPPoEAC}")" >> "${cfg}"
+ [[ -n ${PPPoESession} ]] && echo "rp_pppoe_sess $(_quotestring "${PPPoESession}")" >> "${cfg}"
+ [[ -n ${PPPoEMAC} ]] && echo "pppoe-mac $(_quotestring "${PPPoEMAC}")" >> "${cfg}"
+ [[ ${PPPoEIP6} == yes ]] && echo "+ipv6" >> "${cfg}"
- /sbin/ip link set dev "${INTERFACE}" up
+ /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."
+ rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
+ report_error "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"
+ cfg="$STATE_DIR/pppoe.${Interface}.${Profile}/options"
+ PIDFILE="/var/run/ppp-${Profile}.pid"
if [[ -e $PIDFILE ]]; then
read PID < "$PIDFILE"
@@ -68,10 +65,8 @@ pppoe_down() {
fi
rm "${cfg}"
- rmdir "$STATE_DIR/pppoe.${INTERFACE}.$1/"
+ rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
}
-pppoe_$1 "$2"
-exit $?
# vim: ft=sh ts=4 et sw=4:
diff --git a/src/lib/connections/tunnel b/src/lib/connections/tunnel
index 6cefc5c..f202371 100644
--- a/src/lib/connections/tunnel
+++ b/src/lib/connections/tunnel
@@ -1,34 +1,28 @@
-#! /bin/bash
-. /usr/lib/network/network
+# Contributed by: Kyle Fuller <inbox@kylefuller.co.uk>
-tunnel_up() {
- load_profile "$1"
+. "$SUBR_DIR/ip"
- if [[ -e "/sys/class/net/$INTERFACE" ]]; then
- report_fail "Interface $INTERFACE already exists."
- exit 1
+tunnel_up() {
+ if is_interface "$Interface"; then
+ report_error "Interface '$Interface' already exists"
+ return 1
else
- ip tunnel add "$INTERFACE" mode "$MODE" remote "$REMOTE"
+ ip tunnel add "$Interface" mode "$Mode" remote "$Remote"
fi
- if [[ -n "$LOCAL" ]]; then
- ip tunnel change "$INTERFACE" local "$LOCAL"
+ if [[ -n "$Local" ]]; then
+ ip tunnel change "$Interface" local "$Local"
fi
- "$CONN_DIR/ethernet" up "$1"
- return 0
+ bring_interface_up "$Interface"
+ ip_set
}
tunnel_down() {
- load_profile "$1"
-
- "$CONN_DIR/ethernet" down "$1"
- ip tunnel del "$INTERFACE"
-
- return 0
+ ip_unset
+ bring_interface_down "$Interface"
+ ip tunnel del "$Interface"
}
-tunnel_$1 "$2"
-exit $?
# vim: set ts=4 et sw=4:
diff --git a/src/lib/connections/tuntap b/src/lib/connections/tuntap
index 6985c8c..1ff5203 100644
--- a/src/lib/connections/tuntap
+++ b/src/lib/connections/tuntap
@@ -1,28 +1,24 @@
-#! /bin/bash
-. /usr/lib/network/network
+# Contributed by: Rémy Oudompheng <remy@archlinux.org>
-tuntap_up() {
- load_profile "$1"
+. "$SUBR_DIR/ip"
- if [[ -e /sys/class/net/$INTERFACE ]]; then
- report_fail "Interface $INTERFACE already exists."
- exit 1
+tuntap_up() {
+ if is_interface "$Interface"; then
+ report_error "Interface '$Interface' already exists"
+ return 1
else
- ip tuntap add dev "$INTERFACE" mode "$MODE" \
- user "$USER" group "$GROUP"
+ ip tuntap add dev "$Interface" mode "$Mode" \
+ user "$User" group "$Group"
fi
- IP=${IP-no} "$CONN_DIR/ethernet" up "$1"
- return 0
+ bring_interface_up "$Interface"
+ IP=${IP-no} ip_set
}
tuntap_down() {
- load_profile "$1"
-
- "$CONN_DIR/ethernet" down "$1"
- ip tuntap del dev "$INTERFACE" mode "$MODE"
- return 0
+ ip_unset
+ bring_interface_down "$Interface"
+ ip tuntap del dev "$Interface" mode "$Mode"
}
-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
index 75c7fa9..86d1a2d 100644
--- a/src/lib/connections/vlan
+++ b/src/lib/connections/vlan
@@ -1,28 +1,26 @@
-#! /bin/bash
-. /usr/lib/network/network
+# Contributed by: Thomas S Hatch <thatch45@gmail.com>
-vlan_up() {
- load_profile "$1"
+. "$CONN_DIR/ethernet"
- if [[ -e "/sys/class/net/$INTERFACE" ]]; then
- report_fail "Interface $INTERFACE already exists."
- exit 1
+vlan_up() {
+ if [[ ${#BindsToInterfaces} -ne 1 ]]; then
+ report_error "No unique physical device for VLAN interface '$Interface' specified"
+ return 1
+ fi
+ if is_interface "$Interface"; then
+ report_error "Interface '$Interface' already exists"
+ return 1
else
- bring_interface up "$VLAN_PHYS_DEV"
- ip link add link "$VLAN_PHYS_DEV" name "$INTERFACE" type vlan id "$VLAN_ID"
+ bring_interface_up "$BindsToInterfaces"
+ ip link add link "$BindsToInterfaces" name "$Interface" type vlan id "$VLANID"
fi
- "$CONN_DIR/ethernet" up "$1"
- return 0
+
+ ethernet_up
}
vlan_down() {
- load_profile "$1"
-
- "$CONN_DIR/ethernet" down "$1"
- ip link delete "$INTERFACE"
- return 0
+ ethernet_down
+ ip link delete "$Interface"
}
-vlan_$1 "$2"
-exit $?
# vim: set ts=4 et sw=4:
diff --git a/src/lib/connections/wireless b/src/lib/connections/wireless
index 135bec7..a3b324b 100644
--- a/src/lib/connections/wireless
+++ b/src/lib/connections/wireless
@@ -1,116 +1,89 @@
-#! /bin/bash
-. /usr/lib/network/network
+# Wireless connection support for netctl
+
. "$SUBR_DIR/8021x"
+. "$SUBR_DIR/ip"
. "$SUBR_DIR/rfkill"
-wireless_up() {
- PROFILE="$1"
- load_profile "$PROFILE"
- # Default settings
- SECURITY=${SECURITY:-none}
- WPA_DRIVER=${WPA_DRIVER:-nl80211,wext}
+wireless_up() {
+ local config_file
- enable_rf $INTERFACE $RFKILL $RFKILL_NAME || return 1
+ if ! is_interface "$Interface"; then
+ report_error "Interface '$Interface' does not exist"
+ return 1
+ fi
- # Check if interface exists
- is_interface "$INTERFACE" || { report_fail "interface $INTERFACE does not exist"; return 1; }
+ # Default settings
+ : ${Security:=none}
+ : ${WPADriver:=nl80211,wext}
+ : ${TimeoutWPA:=15}
+
+ if [[ $RFKill ]]; then
+ enable_rf "$Interface" "$RFKill" || return 1
+ fi
- # Kill any lingering wpa_supplicants.
- stop_wpa "$INTERFACE" &> /dev/null
+ # Kill any lingering WPA supplicants
+ WPAConfigFile= wpa_stop "$Interface" &> /dev/null
- # Start wpa_supplicant
- if [[ "$SECURITY" = "wpa-config" ]]; then
- WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}"
+ if [[ $Security == "wpa-config" ]]; then
+ : ${WPAConfigFile:=/etc/wpa_supplicant.conf}
+ config_file=$WPAConfigFile
else
- WPA_CONF=$(make_wpa_config_file $INTERFACE)
+ config_file=$(wpa_make_config_file "$Interface")
+ if [[ -z $config_file ]]; then
+ report_error "Could not create a wpa config file for interface '$Interface'"
+ bring_interface_down "$Interface"
+ return 1
+ fi
+ printf "%s\n" "network={" "$(wpa_make_config_block)" "}" >> "$config_file"
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"
+
+ # Start the WPA supplicant
+ if ! do_debug wpa_start "$Interface" "$WPADriver" "$config_file"; then
+ report_error "The WPA supplicant did not start for interface '$Interface'"
+ bring_interface_down "$Interface"
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"
+ if is_yes "${Scan:-no}"; then
+ if ! wpa_wait_while_state "$TimeoutWPA" "$Interface" "DISCONNECTED" "SCANNING"; then
+ report_error "Wireless network '$ESSID' (or access point) not present"
+ wpa_stop "$Interface"
+ bring_interface_down "$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
+ bring_interface_up "$Interface" || return 1
- report_debug wireless_up wpa_check
- if ! wpa_check "$INTERFACE" "$TIMEOUT"; then
- report_fail "WPA Authentication/Association Failed"
+ if ! wpa_wait_until_state "$TimeoutWPA" "$Interface" "COMPLETED"; then
+ report_error "WPA association/authentication failed for interface '$Interface'"
+ wpa_stop "$Interface"
+ bring_interface_down "$Interface"
return 1
fi
- if ! "$CONN_DIR/ethernet" up "$PROFILE"; then
- wireless_down "$PROFILE" YES
+ if ! ip_set; then
+ wpa_stop "$Interface"
+ bring_interface_down "$Interface"
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}"
+ ip_unset
+ if [[ $Security == "wpa-config" ]]; then
+ : ${WPAConfigFile:=/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
+ wpa_stop "$Interface"
+ bring_interface_down "$Interface" || return 1
+ if [[ $RFKill ]]; then
+ disable_rf "$Interface" "$RFKill"
fi
}
-wireless_$1 "$2" "$3"
-exit $?
# vim: ft=sh ts=4 et sw=4 tw=0:
-