From 9954a5c5cb4fcf6313f643101579024de80c85e6 Mon Sep 17 00:00:00 2001 From: Michael Zimmermann Date: Wed, 13 Nov 2024 22:35:17 +0100 Subject: [PATCH] libnetwork: support `mode` option for bridge L2 will be used to allow using existing bridges which netavark will neither create nor delete. Signed-off-by: Michael Zimmermann --- libnetwork/netavark/config.go | 4 ++++ libnetwork/types/const.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/libnetwork/netavark/config.go b/libnetwork/netavark/config.go index 8b43a787e..33ef26acf 100644 --- a/libnetwork/netavark/config.go +++ b/libnetwork/netavark/config.go @@ -207,6 +207,10 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo if len(value) == 0 { return nil, errors.New("invalid vrf name") } + case types.ModeOption: + if !slices.Contains(types.ValidBridgeModes, value) { + return nil, fmt.Errorf("unknown bridge mode %q", value) + } default: return nil, fmt.Errorf("unsupported bridge network option %s", key) } diff --git a/libnetwork/types/const.go b/libnetwork/types/const.go index a91618200..6e2c3fbf4 100644 --- a/libnetwork/types/const.go +++ b/libnetwork/types/const.go @@ -24,6 +24,9 @@ const ( // DefaultSubnet is the subnet that will be used for the default CNI network. DefaultSubnet = "10.88.0.0/16" + BridgeModeManaged = "managed" + BridgeModeUnmanaged = "unmanaged" + // valid macvlan driver mode values MacVLANModeBridge = "bridge" MacVLANModePrivate = "private" @@ -53,6 +56,9 @@ const ( Netavark NetworkBackend = "netavark" ) +// ValidBridgeModes is the list of valid mode options for the bridge driver +var ValidBridgeModes = []string{BridgeModeManaged, BridgeModeUnmanaged} + // ValidMacVLANModes is the list of valid mode options for the macvlan driver var ValidMacVLANModes = []string{MacVLANModeBridge, MacVLANModePrivate, MacVLANModeVepa, MacVLANModePassthru}