| Lorenz Brun | 0dca6c9 | 2025-01-28 15:04:13 +0100 | [diff] [blame] | 1 | From a2c65ec075a9376e3b8e9fb72a96db36a613a1d0 Mon Sep 17 00:00:00 2001 |
| 2 | From: Lorenz Brun <lorenz@brun.one> |
| 3 | Date: Thu, 2 Jan 2025 00:36:05 +0100 |
| 4 | Subject: [PATCH] Add linkGroup setting |
| 5 | |
| 6 | --- |
| 7 | plugins/main/ptp/ptp.go | 11 +++++++++-- |
| 8 | 1 file changed, 9 insertions(+), 2 deletions(-) |
| 9 | |
| 10 | diff --git a/plugins/main/ptp/ptp.go b/plugins/main/ptp/ptp.go |
| 11 | index 129146f2..aee37b11 100644 |
| 12 | --- a/plugins/main/ptp/ptp.go |
| 13 | +++ b/plugins/main/ptp/ptp.go |
| 14 | @@ -46,6 +46,7 @@ type NetConf struct { |
| 15 | IPMasq bool `json:"ipMasq"` |
| 16 | IPMasqBackend *string `json:"ipMasqBackend,omitempty"` |
| 17 | MTU int `json:"mtu"` |
| 18 | + LinkGroup int `json:"linkGroup,omitempty"` |
| 19 | } |
| 20 | |
| 21 | func setupContainerVeth(netns ns.NetNS, ifName string, mtu int, pr *current.Result) (*current.Interface, *current.Interface, error) { |
| 22 | @@ -145,7 +146,7 @@ func setupContainerVeth(netns ns.NetNS, ifName string, mtu int, pr *current.Resu |
| 23 | return hostInterface, containerInterface, nil |
| 24 | } |
| 25 | |
| 26 | -func setupHostVeth(vethName string, result *current.Result) error { |
| 27 | +func setupHostVeth(vethName string, group int, result *current.Result) error { |
| 28 | // hostVeth moved namespaces and may have a new ifindex |
| 29 | veth, err := netlink.LinkByName(vethName) |
| 30 | if err != nil { |
| 31 | @@ -177,6 +178,12 @@ func setupHostVeth(vethName string, result *current.Result) error { |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | + if group != 0 { |
| 36 | + if err := netlink.LinkSetGroup(veth, group); err != nil { |
| 37 | + return fmt.Errorf("failed to set link group for if %q: %v", vethName, err) |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | return nil |
| 42 | } |
| 43 | |
| 44 | @@ -224,7 +231,7 @@ func cmdAdd(args *skel.CmdArgs) error { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | - if err = setupHostVeth(hostInterface.Name, result); err != nil { |
| 49 | + if err = setupHostVeth(hostInterface.Name, conf.LinkGroup, result); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | -- |
| 54 | 2.47.1 |
| 55 | |