diff options
author | Jim Pryor <profjim@jimpryor.net> | 2009-09-14 05:43:44 +0200 |
---|---|---|
committer | James Rayner <james@archlinux.org> | 2009-09-14 08:26:16 +0200 |
commit | b6c8f97e5e6fd2b5f331e37d891b22ef8598cc09 (patch) | |
tree | f7ec082076a859b113394602b333ebc9d6d09edb /src/network | |
parent | 0b2a5ddd786f2e7b6ce0f1b6d7ac7efd424aadbd (diff) | |
download | netctl-b6c8f97e5e6fd2b5f331e37d891b22ef8598cc09.tar.gz netctl-b6c8f97e5e6fd2b5f331e37d891b22ef8598cc09.tar.xz |
src/network tweaks
* changed some report_fails that were called without any preceding
report_try --> report_err
* deploy new check_iface functionality to profile_up and profile_down
and interface_down
* have profile_up/down report_debug the results of check_iface
* the call to interface_down doesn't need to be sandboxed; all the profile
sourcing functions it calls as subroutines do their own sandboxing.
Don't they?
* added missing INTERFACE="$1" to check_iface
* tweaks to bring_interface
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/network b/src/network index 996d0d1..03a2831 100644 --- a/src/network +++ b/src/network @@ -10,14 +10,14 @@ load_profile() { [[ -z "$1" ]] && return 1 if [[ ! -f "$PROFILE_DIR/$1" ]]; then - report_fail "Profile \"$1\" does not exist" + report_err "Profile \"$1\" does not exist" return 1 fi report_debug "Loading profile $1" . "$PROFILE_DIR/$1" report_debug "Configuring interface $INTERFACE" if [[ -z "$INTERFACE" ]]; then - report_fail "Profile missing an interface to configure" + report_err "Profile missing an interface to configure" return 1 fi if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then @@ -26,7 +26,7 @@ load_profile() . "$PROFILE_DIR/$1" # we want profile settings to override, so need to source profile again fi if [[ ! -f "$CONN_DIR/$CONNECTION" ]]; then - report_fail "$CONNECTION is not a valid connection, check spelling or look at examples" + report_err "$CONNECTION is not a valid connection, check spelling or look at examples" return 1 fi } @@ -104,12 +104,12 @@ profile_up() # exit 1 used in a subshell is effectively exiting a new process [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend} - local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks + 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_fail "$PROFILE already connected" + report_err "$PROFILE already connected" exit 1 fi @@ -121,20 +121,30 @@ profile_up() report_try "$PROFILE up" - case $(check_iface "$INTERFACE") in - 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 - else - interface_down "$INTERFACE" || exit 1 - load_profile "$PROFILE" + + # not necessary to sandbox this call or reload PROFILE afterwards + elif ! interface_down "$INTERFACE"; then + report_fail + exit 1 fi - ;; - external) - report_fail "Interface $INTERFACE externally controlled" - exit 1 - ;; + ;; esac if ! ( eval $PRE_UP ); then # JP: sandbox the eval so variables don't bleed into current function @@ -186,12 +196,18 @@ profile_down() ( [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend} - local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks + 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_fail "Profile not connected" + 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 @@ -337,7 +353,7 @@ set_interface() if [ "$1" = old ]; then ifconfig "$INTERFACE" up else - ip link set dev "$INTERFACE" up + ip link set dev "$INTERFACE" up &>/dev/null # man ip is inconsistent about whether to use "dev" fi sleep "${UP_SLEEP:-2}" ;; @@ -347,14 +363,14 @@ set_interface() 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 + ip link set dev "$INTERFACE" down &>/dev/null # man ip is inconsistent about whether to use "dev" fi fi ;; |