From f708bb1465f60bd80fb0722671ce7010d601b3b0 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Fri, 25 Sep 2020 22:04:53 +0200 Subject: [PATCH 1/2] link executor: Add support for veth interfaces Signed-off-by: Maximilian Wilhelm --- doc/interfaces.scd | 7 +++++++ executor-scripts/linux/link | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/interfaces.scd b/doc/interfaces.scd index f8ba926..8600b4e 100644 --- a/doc/interfaces.scd +++ b/doc/interfaces.scd @@ -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. diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 02633ef..24db96f 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -39,9 +39,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 @@ -77,7 +86,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 From 3035627c93c1d29cef7f6fb9b98d83f05964931c Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Fri, 25 Sep 2020 22:07:10 +0200 Subject: [PATCH 2/2] link executor: Add dependency between veth pairs Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 24db96f..c8c05ce 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -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 @@ -94,9 +105,4 @@ destroy) ${MOCK} ip link del "${IFACE}" fi ;; -depend) - if is_vlan; then - echo "$IF_VLAN_RAW_DEVICE" - fi - ;; esac