summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2012-05-16 15:50:41 +0200
committerJouke Witteveen <j.witteveen@gmail.com>2012-05-16 19:43:04 +0200
commitce28459bc22b4de1a2dc57cf4ae1cf7fdefdb356 (patch)
tree5a4192f9b48c16197fce1e86b4366b6d0ce10b86 /src
parent4c141e44b54fa80aac57c31269a25c7669054c66 (diff)
downloadnetctl-ce28459bc22b4de1a2dc57cf4ae1cf7fdefdb356.tar.gz
netctl-ce28459bc22b4de1a2dc57cf4ae1cf7fdefdb356.tar.xz
Code inspection
Some changes after reading through a few files. Only two modifications impact functionality. - Not having dhclient is now fatal for IPv6 connections that use dhcp. - Allow authentication/associaton time-out of wpa to be set through TIMEOUT for wired connections too. dhclient no longer needs to be killed manually, so those lines are removed.
Diffstat (limited to 'src')
-rw-r--r--src/8021x4
-rw-r--r--src/connections/ethernet57
2 files changed, 30 insertions, 31 deletions
diff --git a/src/8021x b/src/8021x
index 779e741..ceced36 100644
--- a/src/8021x
+++ b/src/8021x
@@ -6,9 +6,9 @@ wpa_check()
# CONDITION is required as wired connections are ready at ASSOCIATED not COMPLETED FS#20150
report_debug wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status
- while [[ $timeout -lt "$TIMEOUT" ]]; do
+ while (( timeout < TIMEOUT )); do
( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors
- if [[ $timeout -lt 2 ]]; then
+ if (( timeout < 2 )); then
eval $(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status 2> /dev/null | fgrep "wpa_state=")
else
eval $(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | fgrep "wpa_state=")
diff --git a/src/connections/ethernet b/src/connections/ethernet
index 1c527ee..41d0274 100644
--- a/src/connections/ethernet
+++ b/src/connections/ethernet
@@ -28,7 +28,7 @@ ethernet_up() {
sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.disable_ipv6=1"
fi
- report_debug ethernet_iproute_up ifup
+ report_debug ethernet_up ifup
bring_interface up "$INTERFACE"
@@ -50,13 +50,13 @@ ethernet_up() {
WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | tail -n 1 | cut -d= -f 2- | sed -r 's/DIR=(.*) +GROUP=.*/\1/')
fi
- report_debug ethernet_iproute_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"
+ 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" 15 "ASSOCIATED"; then
+ if ! wpa_check "$INTERFACE" "$TIMEOUT" "ASSOCIATED"; then
bring_interface down "$INTERFACE"
report_fail "WPA Authentication/Association Failed"
return 1
@@ -96,21 +96,21 @@ ethernet_up() {
static)
if [[ -n "$ADDR" ]]; then
[[ -z $NETMASK ]] && NETMASK=24
- report_debug ethernet_iproute_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"
+ 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 "$ROUTES" ]]; then
for route in "${ROUTES[@]}"; do
- report_debug ethernet_iproute_up ip route add $route dev "$INTERFACE"
+ 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
if [[ -n "$GATEWAY" ]]; then
- report_debug ethernet_iproute_up ip route add default via "$GATEWAY" dev "$INTERFACE"
+ 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
@@ -118,7 +118,7 @@ ethernet_up() {
;;
""|no)
;;
- *)
+ *)
report_iproute "IP must be either 'dhcp', 'static' or 'no'"
;;
esac
@@ -126,7 +126,7 @@ ethernet_up() {
if [[ -n "$IPCFG" ]]; then
for line in "${IPCFG[@]}"; do
- report_debug ethernet_iproute_up ip "$line"
+ report_debug ethernet_up ip "$line"
if ! ip $line; then
report_iproute "Could not configure interface ($line)."
fi
@@ -150,21 +150,22 @@ ethernet_up() {
case "$IP6" in
dhcp*)
- if [[ -x /usr/sbin/dhclient ]]; then
- _DHCLIENT_PIDFILE="/run/dhclient6-${INTERFACE}.pid"
- if [[ "$IP6" = "dhcp-noaddr" ]]; then
- DHCLIENT6_OPTIONS="-S ${DHCLIENT6_OPTIONS}"
- fi
- sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=1"
- 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
- else
+ if [[ ! -x /usr/sbin/dhclient ]]; 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)
@@ -174,14 +175,14 @@ ethernet_up() {
sysctl -q -w "net.ipv6.conf.$SYSCTL_INTERFACE.accept_ra=0"
if [[ -n "$ADDR6" ]]; then
for addr in "${ADDR6[@]}"; do
- report_debug ethernet_iproute_up ip -6 addr add "$addr" dev "$INTERFACE"
+ 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
if [[ -n "$GATEWAY6" ]]; then
- report_debug ethernet_iproute_up ip -6 route replace default via "$GATEWAY6" dev "$INTERFACE"
+ 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
@@ -190,7 +191,7 @@ ethernet_up() {
# Add static IPv6 routes
if [[ -n "$ROUTES6" ]]; then
for route in "${ROUTES6[@]}"; do
- report_debug ethernet_iproute_up ip -6 route add "$route" dev "$INTERFACE"
+ 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
@@ -201,7 +202,7 @@ ethernet_up() {
# Set hostname
if [[ -n "$HOSTNAME" ]]; then
- report_debug ethernet_iproute_up hostname "$HOSTNAME"
+ report_debug ethernet_up hostname "$HOSTNAME"
if ! echo "$HOSTNAME" > /proc/sys/kernel/hostname; then
report_iproute "Cannot set hostname to $HOSTNAME"
fi
@@ -226,11 +227,9 @@ ethernet_down() {
if [[ "$IP" == "dhcp" ]]; then
if checkyesno "${DHCLIENT:-no}"; then
if [[ -f "/run/dhclient-$INTERFACE.pid" ]]; then
- report_debug ethernet_down dhclient -q -r "$INTERFACE"
+ report_debug ethernet_down dhclient -q -x "$INTERFACE"
dhclient -q -x "$INTERFACE" &>/dev/null
#dhclient -q -r "$INTERFACE" &>/dev/null
- report_debug ethernet_down /bin/kill $(< /run/dhclient-$INTERFACE.pid)
- /bin/kill $(< /run/dhclient-$INTERFACE.pid) &>/dev/null
fi
else
if [[ -f "/run/dhcpcd-$INTERFACE.pid" ]]; then