From 74fe64cec00d359ce98938754e9cb1b0c96e49a8 Mon Sep 17 00:00:00 2001 From: James Rayner Date: Mon, 10 Aug 2009 20:09:14 +1000 Subject: merge logging code from Jim Pryor --- src/connections/ethernet | 44 ++++++++++++++++++++++--------- src/connections/ethernet-iproute | 42 ++++++++++++++++++----------- src/connections/wireless | 57 +++++++++++++++++++++++++++++----------- 3 files changed, 100 insertions(+), 43 deletions(-) (limited to 'src/connections') diff --git a/src/connections/ethernet b/src/connections/ethernet index 006dd42..2105ec2 100644 --- a/src/connections/ethernet +++ b/src/connections/ethernet @@ -6,16 +6,17 @@ ethernet_up() { if [[ ! -e /sys/class/net/"$INTERFACE" ]]; then if ! echo "$INTERFACE"|grep ":"; then - err_append "interface $INTERFACE does not exist" + report_fail "interface $INTERFACE does not exist" return 1 fi fi + report_debug ethernet_up ifup ip link set $INTERFACE up sleep 2 if ip link show $INTERFACE|grep -q "NO-CARRIER"; then - err_append "No connection" + report_fail "No connection" return 1 fi @@ -23,7 +24,11 @@ ethernet_up() { . "${SUBR_DIR}"/8021x [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired" - start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_OPTS" + report_debug ethernet_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 ifconfig "$INTERFACE" down return 1 @@ -34,8 +39,9 @@ ethernet_up() { dhcp) if checkyesno "${DHCLIENT:-no}"; then rm -r /var/run/dhclient-${INTERFACE}.pid >/dev/null 2>&1 + report_debug ethernet_up dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/var/run/dhclient-$INTERFACE.pid" "$INTERFACE" if ! dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf /var/run/dhclient-${INTERFACE}.pid $INTERFACE; then - err_append "DHCP IP lease attempt failed." + report_fail "DHCP IP lease attempt failed." return 1 fi else @@ -44,37 +50,44 @@ ethernet_up() { # If using own dns, tell dhcpcd to NOT replace resolv.conf [[ -n "$DNS1" ]] && DHCP_OPTIONS="-C resolv.conf $DHCP_OPTIONS" # Start dhcpcd + report_debug ethernet_up dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" if ! dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE"; then - err_append "DHCP IP lease attempt failed." + report_fail "DHCP IP lease attempt failed." return 1 fi fi - [[ -n "$IFOPTS" ]] && ifconfig "$INTERFACE" $IFOPTS + 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 - err_append "Bringing interface up failed." + report_fail "Bringing interface up failed." return 1 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 - err_append "Adding gateway failed." + report_fail "Adding gateway failed." return 1 fi fi ;; *) - err_append "IP=\"\" must be either 'dhcp' or 'static'." + report_fail "IP=\"\" must be either 'dhcp' or 'static'." return 1 ;; esac # set the hostname if [[ -n "$HOSTNAME" ]]; then + report_debug ethernet_up hostname "$HOSTNAME" if ! hostname "$HOSTNAME"; then - err_append "Setting hostname failed." + report_fail "Setting hostname failed." return 1 fi fi @@ -103,18 +116,25 @@ ethernet_down() { dhcp) if checkyesno "${DHCLIENT:-no}"; then if [[ -f /var/run/dhclient-${INTERFACE}.pid ]]; then - kill `cat /var/run/dhclient-${INTERFACE}.pid` + 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" fi fi ;; static) - [[ -n "$GATEWAY" ]] && route del default gw $GATEWAY + if [[ -n "$GATEWAY" ]]; then + report_debug ethernet_down route del default gw "$GATEWAY" + route del default gw $GATEWAY + fi ;; esac + + report_debug ethernet_down ifdown ifconfig $INTERFACE 0.0.0.0 case "$CONNECTION" in # Keep interface up for wireless diff --git a/src/connections/ethernet-iproute b/src/connections/ethernet-iproute index 3d5f5d3..75c99f3 100644 --- a/src/connections/ethernet-iproute +++ b/src/connections/ethernet-iproute @@ -1,9 +1,9 @@ #! /bin/bash . /usr/lib/network/network -error() +report_iproute() { - err_append "$*" + report_fail "$*" ip addr flush $INTERFACE &>/dev/null quirk "nodown" || ip link set $INTERFACE down &>/dev/null exit 1 @@ -14,15 +14,16 @@ ethernet_up() { if [[ ! -e /sys/class/net/$INTERFACE ]]; then if ! echo "$INTERFACE"|grep ":"; then - error "Interface $INTERFACE does not exist" + report_iproute "Interface $INTERFACE does not exist" fi fi + report_debug ethernet_iproute_up ifup ip link set $INTERFACE up sleep 2 - if ip link show $INTERFACE|grep -q "NO-CARRIER"; then - err_append "No connection" + if ip link show $INTERFACE|grep -Fq "NO-CARRIER"; then + report_fail "No connection" return 1 fi @@ -31,7 +32,11 @@ ethernet_up() { [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired" - 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 ip link set $INTERFACE down return 1 @@ -45,41 +50,46 @@ ethernet_up() { # 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" if ! dhcpcd -qL -t ${DHCP_TIMEOUT:-10} $DHCP_OPTIONS $INTERFACE; then - error "DHCP IP lease attempt failed" + 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 - error "Could not configure interface" + 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 - error "Adding gateway failed" + report_iproute "Adding gateway failed" fi fi ;; *) - error "Profile error: IP must be either 'dhcp' or 'static'" + report_iproute "Profile 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 - error "Could not configure interface" + report_iproute "Could not configure interface" fi done fi # Set hostname if [[ -n "$HOSTNAME" ]]; then + report_debug ethernet_iproute_up hostname "$HOSTNAME" if ! hostname $HOSTNAME; then - error "Cannot set hostname" + report_iproute "Cannot set hostname" fi fi @@ -103,10 +113,12 @@ ethernet_down() { if [[ "$IP" == "dhcp" ]]; then if [[ -f /var/run/dhcpcd-${INTERFACE}.pid ]]; then + report_debug ethernet_iproute_down dhcpcd -qx "$INTERFACE" dhcpcd -qx $INTERFACE fi fi - + + report_debug ethernet_iproute_down if_down ip addr flush $INTERFACE quirk "nodown" || ip link set $INTERFACE down diff --git a/src/connections/wireless b/src/connections/wireless index 0fcf56e..2516042 100644 --- a/src/connections/wireless +++ b/src/connections/wireless @@ -24,42 +24,50 @@ wireless_up() { if [[ -n "$RFKILL_NAME" ]]; then path=$(rfkill_from_name $RFKILL_NAME) if [[ $? -ne 0 ]]; then - err_append "no rfkill switch with the name $RFKILL_NAME"; + report_fail "no rfkill switch with the name $RFKILL_NAME"; fi echo 1 > ${path}/state + sleep 1 fi # Check if interface exists if [[ ! -e /sys/class/net/"$INTERFACE" ]]; then if ! echo "$INTERFACE"|grep ":"; then - err_append "interface $INTERFACE does not exist" + report_fail "interface $INTERFACE does not exist" return 1 fi fi # Kill any lingering wpa_supplicants. + report_debug wireless_up stop_wpa "$INTERFACE" stop_wpa $INTERFACE # Most drivers (mac80211) need mode set before device is brought up # Drivers generally default to managed, but set this to be sure. if [[ "$(iwgetid -sm $INTERFACE)" -ne "Managed" ]]; then + report_debug wireless_up iwconfig "$INTERFACE" mode managed iwconfig $INTERFACE mode managed fi - ifconfig $INTERFACE up + report_debug wireless_up ifup + ifconfig $INTERFACE up || return 1 quirk "prescan" && iwlist $INTERFACE scan &> /dev/null # bcm43xx quirk "preessid" && eval "iwconfig $INTERFACE mode managed essid \"$ESSID\"" # ipw3945 if checkyesno ${SCAN:-no}; then + report_debug wireless_up scanning if ! find_essid $INTERFACE "$ESSID"; then - err_append "Network not present." + report_fail "Network not present." return 1 fi fi # Manually set iwconfig options - [[ "$IWCONFIG" ]] && iwconfig $INTERFACE $IWCONFIG + if [[ "$IWCONFIG" ]]; then + report_debug wireless_up iwconfig "$INTERFACE" $IWCONFIG + iwconfig $INTERFACE $IWCONFIG + fi # Set to 'none' if not set [[ -z "$SECURITY" ]] && SECURITY="none" @@ -74,15 +82,21 @@ wireless_up() { fi quirk "predown" && ifconfig $INTERFACE down # madwifi FS#10585 - + + report_debug wireless_up iwconfig "$INTERFACE" $WEP_OPTS if ! eval iwconfig $INTERFACE $WEP_OPTS; then - err_append "Could not set wireless configuration." + report_fail "Could not set wireless configuration." return 1 fi quirk "predown" && ifconfig $INTERFACE up # madwifi FS#10585 - wep_check $INTERFACE $TIMEOUT||return 1 + report_debug ethernet_up wep_check + + if ! wep_check $INTERFACE $TIMEOUT; then + report_fail "WEP Association Failed" + return 1 + fi ;; wpa) @@ -98,14 +112,17 @@ wireless_up() { if [[ "${#KEY}" == "64" ]]; then echo -e "network={ \nssid=\"$ESSID\" \npsk=$KEY \n}">> $WPA_CONF elif ! echo "$KEY" | wpa_passphrase "$ESSID" >> $WPA_CONF; then - err_append "Configuration generation failed. $(cat $WPA_CONF)" + report_fail "Configuration generation failed. $(cat $WPA_CONF)" return 1 fi # Connect! [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwext" + report_debug wireless_up start_wpa "$INTERFACE" "$WPA_CONF/wpa.conf" "$WPA_OPTS" start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1 + report_debug wireless_up wpa_check if ! wpa_check $INTERFACE $TIMEOUT; then + report_fail "WPA Authentication/Association Failed" stop_wpa $INTERFACE return 1 fi @@ -114,8 +131,14 @@ wireless_up() { . ${SUBR_DIR}/8021x [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" # defaults [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwext" - start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1 + report_debug wireless_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 + report_debug wireless_up wpa_check if ! wpa_check $INTERFACE $TIMEOUT; then + report_fail "WPA Authentication/Association Failed" stop_wpa $INTERFACE return 1 fi @@ -131,16 +154,18 @@ wireless_up() { } wireless_down() { - load_profile $1 - . ${SUBR_DIR}/8021x - PROFILE=$1 NOETHERNETDOWN=$2 + PROFILE=$1 NOETHERNETDOWN=$2 + load_profile $PROFILE + . ${SUBR_DIR}/8021x if ! checkyesno $NOETHERNETDOWN; then conn=ethernet checkyesno ${IPROUTE:-no} && conn=ethernet-iproute - $CONN_DIR/$conn down $1 + $CONN_DIR/$conn down $PROFILE fi + report_debug wireless_down stop_wpa "$INTERFACE" stop_wpa $INTERFACE - [[ "$SECURITY" == "wpa" ]] && rm -f "/tmp/wpa.${1// /}" # remove wpa config + [[ "$SECURITY" == "wpa" ]] && rm -f "/tmp/wpa.${PROFILE// /}" # remove wpa config + report_debug wireless_down iwconfig "$INTERFACE" essid off key off iwconfig $INTERFACE essid off key off &> /dev/null ifconfig $INTERFACE down @@ -148,7 +173,7 @@ wireless_down() { if [[ -n "$RFKILL_NAME" ]]; then path=$(rfkill_from_name $RFKILL_NAME) if [[ $? -ne 0 ]]; then - err_append "no rfkill switch with the name $RFKILL_NAME"; + report_fail "no rfkill switch with the name $RFKILL_NAME"; fi echo 0 > ${path}/state fi -- cgit v1.2.3-24-g4f1b