Skip to content

Commit

Permalink
mgmt-net: properly setting the master on the veth with a mgmt-net lin…
Browse files Browse the repository at this point in the history
…k endpoint (#1741)
  • Loading branch information
steiler authored Nov 23, 2023
1 parent c02c840 commit d945895
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
25 changes: 25 additions & 0 deletions links/link_mgmt-net.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package links

import (
"context"
"fmt"

"github.com/containernetworking/plugins/pkg/ns"
log "github.com/sirupsen/logrus"
"github.com/srl-labs/containerlab/utils"
"github.com/vishvananda/netlink"
)

type LinkMgmtNetRaw struct {
Expand Down Expand Up @@ -112,6 +114,29 @@ func (*mgmtBridgeLinkNode) GetLinkEndpointType() LinkEndpointType {
return LinkEndpointTypeBridge
}

func (b *mgmtBridgeLinkNode) AddLinkToContainer(ctx context.Context, link netlink.Link, f func(ns.NetNS) error) error {
// retrieve the namespace handle
ns, err := ns.GetCurrentNS()
if err != nil {
return err
}

// get the bridge as netlink.Link
br, err := utils.LinkByNameOrAlias(b.shortname)
if err != nil {
return err
}

// assign the bridge to the link as master
err = netlink.LinkSetMaster(link, br)
if err != nil {
return err
}

// execute the given function
return ns.Do(f)
}

func getMgmtBrLinkNode() *mgmtBridgeLinkNode {
if _mgmtBrLinkMgmtBrInstance == nil {
currns, err := ns.GetCurrentNS()
Expand Down
45 changes: 45 additions & 0 deletions tests/01-smoke/16-mgmtnet.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
*** Settings ***
Library OperatingSystem
Library String
Library Process
Resource ../common.robot

Suite Setup Setup
Suite Teardown Run Keyword Teardown


*** Variables ***
${lab-name} mgmtnetif
${topo} ${CURDIR}/16-mgmtnetinterface.clab.yml
${runtime} docker


*** Test Cases ***
Deploy ${lab-name} lab
${result} = Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} deploy -t ${topo}
... shell=True
Log ${result.stdout}
Should Be Equal As Integers ${result.rc} 0

Check host side interface is attached to mgmt bridge and up
${params} = Set Variable docker network inspect clab --format '{{ $opt := index .Options "com.docker.network.bridge.name"}}{{ $opt }}'
${mgmtbrname} = Run Process ${params}
... shell=True
Log ${mgmtbrname.stdout}
${result} = Run Process
... sudo -E ip link show dev l1eth1
... shell=True
Log ${result.stdout}
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} state UP
Should Contain ${result.stdout} master ${mgmtbrname.stdout}

*** Keywords ***
Teardown
# destroy all labs
Run sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -c -a

Setup
# skipping this test suite for podman for now
Skip If '${runtime}' == 'podman'
10 changes: 10 additions & 0 deletions tests/01-smoke/16-mgmtnetinterface.clab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: mgmtnetif

topology:
nodes:
l1:
kind: linux
image: alpine:latest
cmd: sleep infinity
links:
- endpoints: [l1:eth1, mgmt-net:l1eth1]

0 comments on commit d945895

Please sign in to comment.