diff options
-rw-r--r-- | net/ifconfig.sh.BSD.in | 20 | ||||
-rw-r--r-- | net/ifconfig.sh.Linux.in | 23 | ||||
-rw-r--r-- | net/iproute2.sh | 23 |
3 files changed, 66 insertions, 0 deletions
diff --git a/net/ifconfig.sh.BSD.in b/net/ifconfig.sh.BSD.in index 15c8fb8e..c7e98a28 100644 --- a/net/ifconfig.sh.BSD.in +++ b/net/ifconfig.sh.BSD.in @@ -242,3 +242,23 @@ ifconfig_post_start() eend 0 fi } + +# Is the interface administratively/operationally up? +# The 'UP' status in ifconfig is the administrative status +# Operational state does not seem to be available in BSD? +# 0: up +# 1: down +# 2: invalid arguments +is_admin_up() +{ + local iface="$1" + [ -z "$iface" ] && iface="$IFACE" + ifconfig "${iface}" | \ + sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; ' +} + +is_oper_up() +{ + eerror "TODO: is_oper_up not available on BSD" + return 2 +} diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in index dcbd6286..1ac0dd52 100644 --- a/net/ifconfig.sh.Linux.in +++ b/net/ifconfig.sh.Linux.in @@ -297,3 +297,26 @@ ifconfig_post_stop() iptunnel del "${IFACE}" eend $? } + +# Is the interface administratively/operationally up? +# The 'UP' status in ifconfig/iproute2 is the administrative status +# Operational state is available in iproute2 output as 'state UP', or the +# operstate sysfs variable. +# 0: up +# 1: down +# 2: invalid arguments +is_admin_up() +{ + local iface="$1" + [ -z "$iface" ] && iface="$IFACE" + ifconfig "${iface}" | \ + sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; ' +} + +is_oper_up() +{ + local iface="$1" + [ -z "$iface" ] && iface="$IFACE" + read state </sys/class/net/"${iface}"/operstate + [ "x$state" = "up" ] +} diff --git a/net/iproute2.sh b/net/iproute2.sh index 214841e4..e177c6d9 100644 --- a/net/iproute2.sh +++ b/net/iproute2.sh @@ -327,3 +327,26 @@ iproute2_post_stop() fi fi } + +# Is the interface administratively/operationally up? +# The 'UP' status in ifconfig/iproute2 is the administrative status +# Operational state is available in iproute2 output as 'state UP', or the +# operstate sysfs variable. +# 0: up +# 1: down +# 2: invalid arguments +is_admin_up() +{ + local iface="$1" + [ -z "$iface" ] && iface="$IFACE" + ip link show dev $iface | \ + sed -n '1,1{ /[<,]UP[,>]/{ q 0 }}; q 1; ' +} + +is_oper_up() +{ + local iface="$1" + [ -z "$iface" ] && iface="$IFACE" + read state </sys/class/net/"${iface}"/operstate + [ "x$state" = "up" ] +} |