Merge pull request #87 from BarbarossaTM/feature/veth

Add support for veth interface pairs
This commit is contained in:
Ariadne Conill 2020-10-05 14:34:39 -06:00 committed by GitHub
commit 37299e312f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 8 deletions

View file

@ -73,6 +73,13 @@ the system will only respond to certain keywords by default:
*link-type* _link-type_
Denotes the link-type of the interface. When set to _dummy_,
the interface is created as a virtual dummy interfaces.
When set to _veth_ the interface is created as virtual veth
interface (pair).
*veth-peer-name* _peer-name_
Denotes the name of the veth peer interfaces. If not set
the kernel will name the veth peer interface as _vethN_
with N being an integer number.
*alias* _alias_
Sets the given alias on the interface.

View file

@ -28,6 +28,17 @@ is_vlan() {
}
case "$PHASE" in
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
;;
create)
if [ "${IF_LINK_TYPE}" = "dummy" ]; then
if [ -d "/sys/class/net/${IFACE}" ]; then
@ -41,9 +52,18 @@ create)
fi
${MOCK} ip link add "${IFACE}" type dummy
fi
if is_vlan; then
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
if [ -d "/sys/class/net/${IFACE}" ]; then
exit 0
fi
@ -84,7 +104,7 @@ down)
${MOCK} ip link set down dev "${IFACE}"
;;
destroy)
if [ "${IF_LINK_TYPE}" = "dummy" ] || is_vlan; then
if [ "${IF_LINK_TYPE}" = "dummy" ] || [ "${IF_LINK_TYPE}" = "veth" ] || is_vlan; then
if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then
exit 0
fi
@ -92,9 +112,4 @@ destroy)
${MOCK} ip link del "${IFACE}"
fi
;;
depend)
if is_vlan; then
echo "$IF_VLAN_RAW_DEVICE"
fi
;;
esac