diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2011-12-12 18:48:11 -0800 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2011-12-12 19:20:39 -0800 |
commit | 2569eb644e6e8e010a44a693e7dfa86e73c0d750 (patch) | |
tree | 41d43ad6a9f2ae0c724339d3969967a5340143f5 /net/iproute2.sh | |
parent | dd45506a40f3332cef96cc8ca7e258561a200ec0 (diff) |
net/ifconfig, net/iproute2: admin/oper state check functions
Provide consistent methods using iproute2/ifconfig to check operational
and administrative up/down state of interfaces. This is not the same as
ethtool's "Link detected" field, which is the state of the layer 2
medium.
TODO: How to check operational state in BSD?
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'net/iproute2.sh')
-rw-r--r-- | net/iproute2.sh | 23 |
1 files changed, 23 insertions, 0 deletions
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" ] +} |