2020-07-26 09:36:31 +00:00
|
|
|
#!/bin/sh
|
2020-08-24 08:58:39 +00:00
|
|
|
|
2020-08-26 09:35:18 +00:00
|
|
|
set -e
|
|
|
|
|
2020-08-24 08:58:39 +00:00
|
|
|
[ -n "$VERBOSE" ] && set -x
|
|
|
|
|
|
|
|
IF_LINK_OPTIONS="$IF_LINK_OPTIONS"
|
|
|
|
[ -n "$IF_MTU" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS mtu $IF_MTU"
|
2020-08-26 08:22:30 +00:00
|
|
|
[ -n "$IF_HWADDRESS" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS address $IF_HWADDRESS"
|
2020-08-24 08:58:39 +00:00
|
|
|
|
|
|
|
is_vlan() {
|
|
|
|
case "$IFACE" in
|
|
|
|
*#*) return 1 ;;
|
|
|
|
*:*) return 1 ;;
|
|
|
|
vlan*.*) return 1 ;;
|
|
|
|
vlan*)
|
|
|
|
IF_VLAN_ID="${IFACE#vlan}"
|
|
|
|
[ -n "${IF_VLAN_RAW_DEVICE:-}" ] && return 0
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
*.*)
|
|
|
|
IF_VLAN_RAW_DEVICE="${IFACE%.*}"
|
|
|
|
IF_VLAN_ID="${IFACE##*.}"
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -z "${IF_VLAN_ID:-}" ] && return 1
|
|
|
|
[ -z "${IF_VLAN_RAW_DEVICE:-}" ] && return 1
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-07-26 13:41:27 +00:00
|
|
|
case "$PHASE" in
|
2020-08-26 21:02:48 +00:00
|
|
|
pre-up)
|
|
|
|
if [ "${IF_LINK_TYPE}" = "dummy" ]; then
|
2020-08-30 20:38:38 +00:00
|
|
|
if [ -d "/sys/class/net/${IFACE}" ]; then
|
|
|
|
iface_type=$(ip -d link show dev "${IFACE}" | head -n3 | tail -n1 | awk '{ print $1 }')
|
|
|
|
if [ "${iface_type}" = 'dummy' ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-08-26 21:02:48 +00:00
|
|
|
ip link add "${IFACE}" type dummy
|
|
|
|
fi
|
|
|
|
;;
|
2020-08-25 14:14:55 +00:00
|
|
|
up|down)
|
2020-08-24 08:58:39 +00:00
|
|
|
if is_vlan; then
|
|
|
|
ADD_DEL="add"
|
2020-08-25 14:14:55 +00:00
|
|
|
[ "$PHASE" = "down" ] && ADD_DEL="delete"
|
2020-08-24 08:58:39 +00:00
|
|
|
|
2020-08-25 14:14:55 +00:00
|
|
|
if [ "$PHASE" = "up" -a -e /sys/class/net/$IFACE ]; then
|
2020-08-24 08:58:39 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$MOCK" ]; then
|
|
|
|
if ! ip link show "$IF_VLAN_RAW_DEVICE" >/dev/null; then
|
|
|
|
echo "Device $IF_VLAN_RAW_DEVICE for $IFACE does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-08-24 17:07:40 +00:00
|
|
|
if ! [ -d /proc/net/vlan ]; then
|
|
|
|
echo "Loading 8021q kernel module for VLAN support"
|
|
|
|
${MOCK} modprobe 8021q
|
|
|
|
fi
|
2020-08-24 08:58:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
${MOCK} ip link $ADD_DEL link "$IF_VLAN_RAW_DEVICE" name "$IFACE" type vlan id "$IF_VLAN_ID"
|
2020-08-25 14:14:55 +00:00
|
|
|
[ "$PHASE" = "down" ] && exit 0
|
2020-08-26 20:41:32 +00:00
|
|
|
fi
|
2020-08-24 16:56:56 +00:00
|
|
|
|
2020-08-26 22:47:51 +00:00
|
|
|
${MOCK} ip link set $PHASE dev $IFACE $IF_LINK_OPTIONS
|
2020-09-03 22:48:44 +00:00
|
|
|
|
|
|
|
# Set alias is configured
|
|
|
|
if [ "${IF_ALIAS}" ]; then
|
|
|
|
${MOCK} ip link set alias "${IF_ALIAS}" dev "${IFACE}"
|
|
|
|
fi
|
2020-08-24 08:58:39 +00:00
|
|
|
;;
|
2020-08-30 20:38:58 +00:00
|
|
|
post-down)
|
|
|
|
if [ "${IF_LINK_TYPE}" = "dummy" ]; then
|
|
|
|
if [ -d "/sys/class/net/${IFACE}" ]; then
|
|
|
|
ip link del "${IFACE}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
2020-08-24 08:58:39 +00:00
|
|
|
depend)
|
2020-08-24 09:01:38 +00:00
|
|
|
if is_vlan; then
|
|
|
|
echo "$IF_VLAN_RAW_DEVICE"
|
|
|
|
fi
|
2020-08-18 21:57:01 +00:00
|
|
|
;;
|
2020-07-26 13:41:27 +00:00
|
|
|
esac
|