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>
This commit is contained in:
@ -242,3 +242,23 @@ ifconfig_post_start()
|
|||||||
eend 0
|
eend 0
|
||||||
fi
|
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
|
||||||
|
}
|
||||||
|
@ -297,3 +297,26 @@ ifconfig_post_stop()
|
|||||||
iptunnel del "${IFACE}"
|
iptunnel del "${IFACE}"
|
||||||
eend $?
|
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" ]
|
||||||
|
}
|
||||||
|
@ -327,3 +327,26 @@ iproute2_post_stop()
|
|||||||
fi
|
fi
|
||||||
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" ]
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user