From db0b5b1811e18df8c975363961ea1ab9aba2ca76 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 25 Feb 2022 14:34:15 +0100 Subject: [PATCH] cni: macvlan allow internal networks When we have the host-local ipam plugin we can support internal for macvlan networks. In this case we just do not add the default route. Since we cannot control this for dhcp we do not support internal there. Signed-off-by: Paul Holzinger --- common/libnetwork/cni/config.go | 6 +++--- common/libnetwork/cni/config_test.go | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/common/libnetwork/cni/config.go b/common/libnetwork/cni/config.go index b5877879c3..e801e14693 100644 --- a/common/libnetwork/cni/config.go +++ b/common/libnetwork/cni/config.go @@ -187,9 +187,6 @@ func (n *cniNetwork) NetworkInspect(nameOrID string) (types.Network, error) { } func createIPMACVLAN(network *types.Network) error { - if network.Internal { - return errors.New("internal is not supported with macvlan") - } if network.NetworkInterface != "" { interfaceNames, err := internalutil.GetLiveNetworkNames() if err != nil { @@ -201,6 +198,9 @@ func createIPMACVLAN(network *types.Network) error { } if len(network.Subnets) == 0 { network.IPAMOptions["driver"] = types.DHCPIPAMDriver + if network.Internal { + return errors.New("internal is not supported with macvlan and dhcp ipam driver") + } } else { network.IPAMOptions["driver"] = types.HostLocalIPAMDriver } diff --git a/common/libnetwork/cni/config_test.go b/common/libnetwork/cni/config_test.go index b0e7d42ff9..2c90480ec7 100644 --- a/common/libnetwork/cni/config_test.go +++ b/common/libnetwork/cni/config_test.go @@ -344,7 +344,25 @@ var _ = Describe("Config", func() { Expect(err.Error()).To(ContainSubstring("parent interface idonotexists does not exist")) }) - It("create macvlan config with internal should fail", func() { + It("create macvlan config with internal and dhcp should fail", func() { + subnet := "10.1.0.0/24" + n, _ := types.ParseCIDR(subnet) + network := types.Network{ + Driver: "macvlan", + Internal: true, + Subnets: []types.Subnet{ + {Subnet: n}, + }, + } + net1, err := libpodNet.NetworkCreate(network) + Expect(err).ToNot(HaveOccurred()) + Expect(net1.Internal).To(Equal(true)) + path := filepath.Join(cniConfDir, net1.Name+".conflist") + Expect(path).To(BeARegularFile()) + grepNotFile(path, `"0.0.0.0/0"`) + }) + + It("create macvlan config with internal and subnet should not fail", func() { network := types.Network{ Driver: "macvlan", Internal: true,