aa3e94acf8
Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
93 lines
2 KiB
Bash
Executable file
93 lines
2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
[ -n "$VERBOSE" ] && set -x
|
|
|
|
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
|
|
}
|
|
|
|
case "$PHASE" in
|
|
pre-up)
|
|
if [ "${IF_LINK_TYPE}" = "dummy" ]; then
|
|
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
|
|
echo "Interface ${IFACE} exists but is of type ${iface_type} instead of dummy"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
${MOCK} ip link add "${IFACE}" type dummy
|
|
fi
|
|
|
|
if is_vlan; then
|
|
if [ -d "/sys/class/net/${IFACE}" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [ -z "${MOCK}" ]; then
|
|
if [ ! -d "/sys/class/net/${IF_VLAN_RAW_DEVICE}" ]; then
|
|
echo "Underlay device ${IF_VLAN_RAW_DEVICE} for ${IFACE} does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
if ! [ -d /proc/net/vlan ]; then
|
|
echo "Loading 8021q kernel module for VLAN support"
|
|
${MOCK} modprobe 8021q
|
|
fi
|
|
fi
|
|
|
|
${MOCK} ip link add link "${IF_VLAN_RAW_DEVICE}" name "${IFACE}" type vlan id "${IF_VLAN_ID}"
|
|
fi
|
|
;;
|
|
up)
|
|
IF_LINK_OPTIONS="$IF_LINK_OPTIONS"
|
|
[ -n "$IF_MTU" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS mtu $IF_MTU"
|
|
[ -n "$IF_HWADDRESS" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS address $IF_HWADDRESS"
|
|
|
|
${MOCK} ip link set up dev "${IFACE}" ${IF_LINK_OPTIONS}
|
|
|
|
# Set alias is configured
|
|
if [ "${IF_ALIAS}" ]; then
|
|
${MOCK} ip link set alias "${IF_ALIAS}" dev "${IFACE}"
|
|
fi
|
|
;;
|
|
down)
|
|
${MOCK} ip link set down dev "${IFACE}"
|
|
;;
|
|
post-down)
|
|
if [ "${IF_LINK_TYPE}" = "dummy" ] || is_vlan; then
|
|
if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
${MOCK} ip link del "${IFACE}"
|
|
fi
|
|
;;
|
|
depend)
|
|
if is_vlan; then
|
|
echo "$IF_VLAN_RAW_DEVICE"
|
|
fi
|
|
;;
|
|
esac
|