From 3ee7b326ad6d60b0d713cfd5c958c18e111b9e28 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 19 Aug 2011 13:17:41 -0400 Subject: network: error out on missing or unknown interface This was caused by commit fc9ce46483fc4d -- if the user has no interface defined but also has no legacy variables defined, our legacy check fails, and we try to bring up the network using an empty declaration. Add in an additional safeguard of checking sysfs to see that the interface really does exist. Fixes FS#25671 Signed-off-by: Dave Reisner --- network | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'network') diff --git a/network b/network index 4fafb97..b94d170 100755 --- a/network +++ b/network @@ -23,7 +23,21 @@ deprecated() { printf " connection, or use a utility such as netcfg.\n" } +have_interface() { + if [[ -z $1 ]]; then + printf "\n${C_FAIL}Error:${C_CLEAR} \`interface' is undefined in /etc/rc.conf\n" + return 1 + fi + + if [[ ! -d /sys/class/net/$1 ]]; then + printf "\n${C_FAIL}Error:${C_CLEAR} unknown interface in /etc/rc.conf: \`%s'\n" "$1" + return 1 + fi +} + network_up() { + have_interface "$interface" || return 1 + ip link set dev $interface up || return 1 if [[ $address ]]; then @@ -35,6 +49,8 @@ network_up() { } network_down() { + have_interface "$interface" || return 1 + if [[ -f /var/run/dhcpcd-$interface.pid ]]; then dhcpcd -k $interface || return 1 else -- cgit v1.2.3