summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Rayner <james@archlinux.org>2009-09-22 14:15:02 +0200
committerJames Rayner <james@archlinux.org>2009-09-22 14:15:02 +0200
commit1c6760ebd6b7d6630fbab75885fac5dbea90c78b (patch)
tree05e67c2ab4fab972984fae3671b2b5cae116d2e7 /src
parent57bed3df9310db328d80b32b31fdefa8418bbd1e (diff)
downloadnetctl-1c6760ebd6b7d6630fbab75885fac5dbea90c78b.tar.gz
netctl-1c6760ebd6b7d6630fbab75885fac5dbea90c78b.tar.xz
Merge connections ethernet/ethernet-iproute
Diffstat (limited to 'src')
-rw-r--r--src/connections/ethernet135
-rw-r--r--src/connections/ethernet-iproute138
-rw-r--r--src/connections/wireless16
-rw-r--r--src/network23
-rw-r--r--src/wireless3
5 files changed, 83 insertions, 232 deletions
diff --git a/src/connections/ethernet b/src/connections/ethernet
index e24cc3e..1775247 100644
--- a/src/connections/ethernet
+++ b/src/connections/ethernet
@@ -1,38 +1,48 @@
#! /bin/bash
. /usr/lib/network/network
+report_iproute()
+{
+ report_fail "$*"
+ bring_interface down "$INTERFACE"
+ exit 1
+}
+
ethernet_up() {
load_profile "$1"
if [[ ! -e "/sys/class/net/$INTERFACE" ]]; then
if ! echo "$INTERFACE" | fgrep -q ":"; then
- report_fail "interface $INTERFACE does not exist"
- return 1
+ report_iproute "Interface $INTERFACE does not exist"
fi
fi
- report_debug ethernet_up ifup
- bring_interface up-old "$INTERFACE"
+ report_debug ethernet_iproute_up ifup
+ bring_interface up "$INTERFACE"
- # don't think it's possible to detect carrier using ifconfig alone (at least, not without ifdown/ifupping the interface)
- if [[ $(cat "/sys/class/net/$INTERFACE/carrier" 2>/dev/null) -ne 1 ]]; then # gives err if iface inactive (i.e. ifdown)
- report_fail "No connection"
- return 1
+
+ if ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then
+ sleep ${CARRIER_TIMEOUT:-2} # Some cards are plain slow to come up. Don't fail immediately.
+ if ip link show dev "$INTERFACE" | fgrep -q "NO-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_OPTS" ]] && WPA_OPTS="-Dwired"
- report_debug ethernet_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_OPTS"
+
+ report_debug ethernet_iproute_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_OPTS"
if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_OPTS"; then
report_fail "wpa_supplicant did not start, possible configuration error"
return 1
fi
+
if ! wpa_check "$INTERFACE"; then
- # ignore quirk nodown---is that appropriate?
+ # ignore quirk nodown---is that appropriate? or should we just use report_iproute?
# this adds a flush call as well---is that appropriate?
- bring_interface forcedown-old "$INTERFACE"
+ bring_interface forcedown "$INTERFACE"
report_fail "WPA Authentication/Association Failed"
return 1
fi
@@ -60,102 +70,95 @@ ethernet_up() {
return 1
fi
fi
- if [[ -n "$IFOPTS" ]]; then
- report_debug ethernet_up ifup $IFOPTS
- ifconfig "$INTERFACE" $IFOPTS
- fi
;;
static)
- report_debug ethernet_up ifup $IFOPTS
- if ! ifconfig "$INTERFACE" $IFOPTS up; then
- report_fail "Bringing interface up failed."
- return 1
+ if [[ -n "$ADDR" ]]; then
+ report_debug ethernet_iproute_up ip addr add "$ADDR/24" brd + dev "$INTERFACE"
+ if ! ip addr add "$ADDR/24" brd + dev "$INTERFACE"; then
+ report_iproute "Could not configure interface"
+ fi
fi
-
- # bring up the default route (gateway)
- if [[ -n "$GATEWAY" ]]; then
- report_debug ethernet_up route add default gw "$GATEWAY"
- if ! route add default gw "$GATEWAY"; then
- # JP: don't we want to add this to all the aborts?
- # ignore quirk nodown---is that appropriate?
- # this adds a flush call as well---is that appropriate?
- bring_interface forcedown-old "$INTERFACE"
- report_fail "Adding gateway $GATEWAY failed."
+ if [[ -n "$IFOPTS" ]]; then
+ if ! ifconfig "$INTERFACE" $IFOPTS up; then
+ report_iproute "Bringing interface up failed."
return 1
fi
fi
+ if [[ -n "$GATEWAY" ]]; then
+ report_debug ethernet_iproute_up ip route add default via "$GATEWAY"
+ if ! ip route add default via "$GATEWAY"; then
+ report_iproute "Adding gateway $GATEWAY failed"
+ fi
+ fi
;;
*)
- report_fail "IP must be either 'dhcp' or 'static'."
- return 1
+ report_iproute "IP must be either 'dhcp' or 'static'"
;;
esac
- # set the hostname
+ if [[ -n "$IPCFG" ]]; then
+ for line in "${IPCFG[@]}"; do
+
+ report_debug ethernet_iproute_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"
+ report_debug ethernet_iproute_up hostname "$HOSTNAME"
if ! hostname "$HOSTNAME"; then
- report_fail "Setting hostname $HOSTNAME failed."
- return 1
+ report_iproute "Cannot set hostname to $HOSTNAME"
fi
fi
# Generate a new resolv.conf
- if [[ -n "$DNS1" || -n "$DNS" ]]; then
+ 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
+ elif [[ -n "$DNS1" ]]; then # support older 'ethernet' syntax.
: >/etc/resolv.conf
[[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
[[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
[[ -n "$DNS1" ]] && echo "nameserver $DNS1" >>/etc/resolv.conf
[[ -n "$DNS2" ]] && echo "nameserver $DNS2" >>/etc/resolv.conf
-
- if [[ -n "$DNS" ]]; then
- for dns in "${DNS[@]}"; do
- echo "nameserver $dns" >>/etc/resolv.conf
- done
- fi
fi
+
return 0
}
ethernet_down() {
load_profile "$1"
- case "$IP" in
- dhcp)
- if checkyesno "${DHCLIENT:-no}"; then
- if [[ -f "/var/run/dhclient-${INTERFACE}.pid" ]]; then
- report_debug ethernet_down kill dhclient
- kill "$(cat "/var/run/dhclient-${INTERFACE}.pid")"
- fi
- else
- if [[ -f "/var/run/dhcpcd-${INTERFACE}.pid" ]]; then
- report_debug ethernet_down dhcpcd -qx "$INTERFACE"
- dhcpcd -qx "$INTERFACE" &>/dev/null
- fi
- fi
- ;;
- static)
- if [[ -n "$GATEWAY" ]]; then
- report_debug ethernet_down route del default gw "$GATEWAY"
- route del default gw "$GATEWAY"
+
+ if [[ "$IP" == "dhcp" ]]; then
+ if [[ -f "/var/run/dhcpcd-${INTERFACE}.pid" ]]; then
+ report_debug ethernet_iproute_down dhcpcd -qx "$INTERFACE"
+ dhcpcd -qx "$INTERFACE" &>/dev/null
fi
- ;;
- esac
+ fi
- report_debug ethernet_down ifdown
+ report_debug ethernet_iproute_down if_down
# ignore quirk nodown---is that appropriate?
# this adds a flush call as well---is that appropriate?
- bring_interface forcedown-old "$INTERFACE"
+ bring_interface forcedown "$INTERFACE"
+
}
# Returns status of profile - is it still functional?
ethernet_status() {
- if ! ip link show dev ra0 | fgrep -q "state UP"; then
+ if ! ip link show dev "$INTERFACE" | fgrep -q "state UP"; then
return 1
fi
}
ethernet_$1 "$2"
exit $?
+# vim: set ts=4 et sw=4:
-# vim: ft=sh ts=4 et sw=4:
diff --git a/src/connections/ethernet-iproute b/src/connections/ethernet-iproute
deleted file mode 100644
index 088d25b..0000000
--- a/src/connections/ethernet-iproute
+++ /dev/null
@@ -1,138 +0,0 @@
-#! /bin/bash
-. /usr/lib/network/network
-
-report_iproute()
-{
- report_fail "$*"
- bring_interface down "$INTERFACE"
- exit 1
-}
-
-ethernet_up() {
- load_profile "$1"
-
- if [[ ! -e "/sys/class/net/$INTERFACE" ]]; then
- if ! echo "$INTERFACE" | fgrep -q ":"; then
- report_iproute "Interface $INTERFACE does not exist"
- fi
- fi
-
- report_debug ethernet_iproute_up ifup
- bring_interface up "$INTERFACE"
-
-
- if ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then
- report_iproute "No connection"
- fi
-
- if checkyesno "${AUTH8021X:-no}"; then
- . "$SUBR_DIR/8021x"
- [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf"
- [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired"
-
- report_debug ethernet_iproute_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_OPTS"
- if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_OPTS"; then
- report_fail "wpa_supplicant did not start, possible configuration error"
- return 1
- fi
-
- if ! wpa_check "$INTERFACE"; then
- # ignore quirk nodown---is that appropriate? or should we just use report_iproute?
- # this adds a flush call as well---is that appropriate?
- bring_interface forcedown "$INTERFACE"
- report_fail "WPA Authentication/Association Failed"
- return 1
- fi
- fi
-
- case "$IP" in
- dhcp)
- # Clear remaining pid files.
- rm -f "/var/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"
-
- report_debug ethernet_iproute_up dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE"
- dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" 2>&1 | report_debug "$(cat)"
- if [[ "$PIPESTATUS" -ne 0 ]]; then
- report_iproute "DHCP IP lease attempt failed"
- fi
- ;;
- static)
- if [[ -n "$ADDR" ]]; then
- report_debug ethernet_iproute_up ip addr add "$ADDR/24" brd + dev "$INTERFACE"
- if ! ip addr add "$ADDR/24" brd + dev "$INTERFACE"; then
- report_iproute "Could not configure interface"
- fi
- fi
- if [[ -n "$GATEWAY" ]]; then
- report_debug ethernet_iproute_up ip route add default via "$GATEWAY"
- if ! ip route add default via "$GATEWAY"; then
- report_iproute "Adding gateway $GATEWAY failed"
- fi
- fi
- ;;
- *)
- report_iproute "IP must be either 'dhcp' or 'static'"
- ;;
- esac
-
- if [[ -n "$IPCFG" ]]; then
- for line in "${IPCFG[@]}"; do
-
- report_debug ethernet_iproute_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_iproute_up hostname "$HOSTNAME"
- if ! hostname "$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
- fi
- return 0
-}
-
-ethernet_down() {
- load_profile "$1"
-
- if [[ "$IP" == "dhcp" ]]; then
- if [[ -f "/var/run/dhcpcd-${INTERFACE}.pid" ]]; then
- report_debug ethernet_iproute_down dhcpcd -qx "$INTERFACE"
- dhcpcd -qx "$INTERFACE" &>/dev/null
- fi
- fi
-
- report_debug ethernet_iproute_down if_down
- # ignore quirk nodown---is that appropriate?
- # this adds a flush call as well---is that appropriate?
- bring_interface forcedown "$INTERFACE"
-
-}
-
-# Returns status of profile - is it still functional?
-ethernet_status() {
- if ! ip link show dev "$INTERFACE" | fgrep -q "state UP"; then
- return 1
- fi
-}
-
-ethernet_$1 "$2"
-exit $?
-# vim: set ts=4 et sw=4:
diff --git a/src/connections/wireless b/src/connections/wireless
index e1d4a44..6e9ecd2 100644
--- a/src/connections/wireless
+++ b/src/connections/wireless
@@ -42,7 +42,7 @@ wireless_up() {
fi
report_debug wireless_up ifup
- bring_interface up-old "$INTERFACE" || return 1
+ bring_interface up "$INTERFACE" || return 1
quirk prescan && iwlist "$INTERFACE" scan &> /dev/null # bcm43xx
if quirk preessid; then # ipw3945
@@ -102,7 +102,7 @@ wireless_up() {
if quirk "predown"; then # madwifi FS#10585
# ignore quirk nodown---is that appropriate?
# this adds a flush call as well---is that appropriate?
- bring_interface forcedown-old "$INTERFACE"
+ bring_interface forcedown "$INTERFACE"
fi
report_debug wireless_up iwconfig "$INTERFACE" $WEP_OPTS
@@ -114,7 +114,7 @@ wireless_up() {
fi
if quirk "predown"; then # madwifi FS#10585
- bring_interface up-old "$INTERFACE"
+ bring_interface up "$INTERFACE"
fi
report_debug ethernet_up wep_check
@@ -186,9 +186,7 @@ wireless_up() {
;;
esac
- conn=ethernet
- checkyesno "${IPROUTE:-no}" && conn=ethernet-iproute
- if ! "$CONN_DIR/$conn" up "$1"; then
+ if ! $CONN_DIR/ethernet up "$1"; then
wireless_down "$1" YES
return 1
fi
@@ -200,9 +198,7 @@ wireless_down() {
load_profile "$PROFILE"
. "$SUBR_DIR/8021x"
if ! checkyesno "$NOETHERNETDOWN"; then
- conn=ethernet
- checkyesno "${IPROUTE:-no}" && conn=ethernet-iproute
- "$CONN_DIR/$conn" down "$PROFILE"
+ "$CONN_DIR/ethernet" down "$PROFILE"
fi
report_debug wireless_down stop_wpa "$INTERFACE"
stop_wpa "$INTERFACE"
@@ -212,7 +208,7 @@ wireless_down() {
# respects quirk nodown---is that appropriate?
# wasn't this already called in ethernet_down? but does the call there respect quirk nodown?
# this adds a flush call as well---is that appropriate?
- bring_interface down-old "$INTERFACE"
+ bring_interface down "$INTERFACE"
# Handle wireless kill switches
# Any reason why a hardware switch should be considered on interface down?
diff --git a/src/network b/src/network
index 165d6e3..be814d4 100644
--- a/src/network
+++ b/src/network
@@ -337,32 +337,21 @@ bring_interface()
{
INTERFACE="$2"
case "$1" in
- up|up-old)
+ up)
if ! ( eval $IFACE_UP ); then
return 1
fi
- if [ "$1" = old ]; then
- ifconfig "$INTERFACE" up
- else
- ip link set dev "$INTERFACE" up &>/dev/null # man ip is inconsistent about whether to use "dev"
- fi
+ ip link set dev "$INTERFACE" up &>/dev/null # man ip is inconsistent about whether to use "dev"
sleep "${UP_SLEEP:-2}"
;;
- down|forcedown|down-old|forcedown-old)
+ down|forcedown)
# should this be placed elsewhere?
if ! ( eval $IFACE_DOWN ); then
return 1
fi
- if [ "${1%-old}" != "$1" ]; then
- ifconfig "$INTERFACE" 0.0.0.0
- if ! quirk nodown || [ "$1" = forcedown-old ]; then
- ifconfig "$INTERFACE" down
- fi
- else
- ip addr flush dev "$INTERFACE" &>/dev/null
- if ! quirk nodown || [ "$1" = forcedown ]; then
- ip link set dev "$INTERFACE" down &>/dev/null # man ip is inconsistent about whether to use "dev"
- fi
+ ip addr flush dev "$INTERFACE" &>/dev/null
+ if ! quirk nodown || [ "$1" = forcedown ]; then
+ ip link set dev "$INTERFACE" down &>/dev/null # man ip is inconsistent about whether to use "dev"
fi
;;
*)
diff --git a/src/wireless b/src/wireless
index 2a5b4a3..0bd4dc1 100644
--- a/src/wireless
+++ b/src/wireless
@@ -119,7 +119,7 @@ wpa_supplicant_scan_info() {
set_rf_state() {
local INTERFACE="$1" state="$2" PROFILE="$3"
- if [[ "$RFKILL" == "hard" ]]
+ if [[ "$RFKILL" == "hard" ]]; then
report_fail "Cannot set state on hardware rfkill switch"
return 1
fi
@@ -173,3 +173,4 @@ get_rf_state() {
}
# vim: ft=sh ts=4 et sw=4:
+