2020-07-26 09:36:31 +00:00
|
|
|
#!/bin/sh
|
2020-08-24 08:58:39 +00:00
|
|
|
[ -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
|
|
|
|
}
|
|
|
|
|
2020-07-26 13:41:27 +00:00
|
|
|
case "$PHASE" in
|
2020-09-25 20:07:10 +00:00
|
|
|
depend)
|
|
|
|
# vlan-raw-device
|
|
|
|
if is_vlan; then
|
|
|
|
echo "$IF_VLAN_RAW_DEVICE"
|
|
|
|
|
|
|
|
# veth-peer-name
|
|
|
|
elif [ "${IF_LINK_TYPE}" = "veth" -a "${IF_VETH_PEER_NAME}" ]; then
|
|
|
|
echo "${IF_VETH_PEER_NAME}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2020-09-09 22:48:35 +00:00
|
|
|
create)
|
2020-08-26 21:02:48 +00:00
|
|
|
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 }')
|
2020-09-04 21:33:27 +00:00
|
|
|
if [ "${iface_type}" != 'dummy' ]; then
|
|
|
|
echo "Interface ${IFACE} exists but is of type ${iface_type} instead of dummy"
|
|
|
|
exit 1
|
2020-08-30 20:38:38 +00:00
|
|
|
fi
|
2020-10-02 00:29:39 +00:00
|
|
|
|
|
|
|
exit 0
|
2020-08-30 20:38:38 +00:00
|
|
|
fi
|
|
|
|
|
2020-09-04 22:15:26 +00:00
|
|
|
${MOCK} ip link add "${IFACE}" type dummy
|
2020-08-24 08:58:39 +00:00
|
|
|
|
2020-09-25 20:04:53 +00:00
|
|
|
elif [ "${IF_LINK_TYPE}" = "veth" ]; then
|
|
|
|
if [ ! -d "/sys/class/net/${IFACE}" ]; then
|
|
|
|
ARGS=""
|
|
|
|
if [ "${IF_VETH_PEER_NAME}" ]; then
|
|
|
|
ARGS="peer ${IF_VETH_PEER_NAME}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
${MOCK} ip link add "${IFACE}" type veth ${ARGS}
|
|
|
|
fi
|
|
|
|
|
|
|
|
elif is_vlan; then
|
2020-09-04 21:21:21 +00:00
|
|
|
if [ -d "/sys/class/net/${IFACE}" ]; then
|
2020-08-24 08:58:39 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-09-04 21:21:21 +00:00
|
|
|
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"
|
2020-08-24 08:58:39 +00:00
|
|
|
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
|
|
|
|
|
2020-09-04 21:21:21 +00:00
|
|
|
${MOCK} ip link add link "${IF_VLAN_RAW_DEVICE}" name "${IFACE}" type vlan id "${IF_VLAN_ID}"
|
2020-08-26 20:41:32 +00:00
|
|
|
fi
|
2020-09-04 21:21:21 +00:00
|
|
|
;;
|
2020-09-04 21:32:51 +00:00
|
|
|
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}
|
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-09-04 21:32:51 +00:00
|
|
|
down)
|
2020-10-02 00:29:04 +00:00
|
|
|
# Don't complain about a vanished interface when downing it
|
|
|
|
if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-09-04 21:32:51 +00:00
|
|
|
${MOCK} ip link set down dev "${IFACE}"
|
|
|
|
;;
|
2020-09-09 22:48:35 +00:00
|
|
|
destroy)
|
2020-09-25 20:04:53 +00:00
|
|
|
if [ "${IF_LINK_TYPE}" = "dummy" ] || [ "${IF_LINK_TYPE}" = "veth" ] || is_vlan; then
|
2020-09-04 22:15:01 +00:00
|
|
|
if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then
|
|
|
|
exit 0
|
2020-08-30 20:38:58 +00:00
|
|
|
fi
|
2020-09-04 22:15:01 +00:00
|
|
|
|
2020-09-04 22:18:43 +00:00
|
|
|
${MOCK} ip link del "${IFACE}"
|
2020-08-30 20:38:58 +00:00
|
|
|
fi
|
|
|
|
;;
|
2020-07-26 13:41:27 +00:00
|
|
|
esac
|