Skip to content

Commit e6e162a

Browse files
committed
libnetwork/netavark: allow same subnet with different vlan
When a vlan is used there should be no subnet conflict check. As the vlan separates the routing it should be valid. Fixes: containers/podman#25736 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
1 parent 3459017 commit e6e162a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

libnetwork/netavark/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo
185185
if err != nil {
186186
return nil, err
187187
}
188+
// Unset used networks here to ensure that when using vlan networks
189+
// we do not error if the subnet is already in use on the host.
190+
// https://github.com/containers/podman/issues/25736
191+
usedNetworks = nil
188192
// If there is no vlan there should be no other config with the same bridge.
189193
// However with vlan we want to allow that so that you can have different
190194
// configs on the same bridge but different vlans

libnetwork/netavark/config_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,28 @@ var _ = Describe("Config", func() {
957957
Expect(network2.Options).To(HaveKeyWithValue("vlan", "99"))
958958
})
959959

960+
It("create two networks with vlan option and same subnet", func() {
961+
subnet := "10.0.0.0/24"
962+
n, _ := types.ParseCIDR(subnet)
963+
networkOpts := types.Network{
964+
Subnets: []types.Subnet{{Subnet: n}},
965+
}
966+
network1, err := libpodNet.NetworkCreate(networkOpts, nil)
967+
Expect(err).ToNot(HaveOccurred())
968+
Expect(network1.Driver).To(Equal("bridge"))
969+
Expect(network1.Subnets).To(HaveLen(1))
970+
971+
// set a new vlan on the options
972+
networkOpts.Options = map[string]string{types.VLANOption: "99"}
973+
974+
network2, err := libpodNet.NetworkCreate(networkOpts, nil)
975+
Expect(err).ToNot(HaveOccurred())
976+
Expect(network2.Driver).To(Equal("bridge"))
977+
Expect(network2.Options).To(HaveKeyWithValue("vlan", "99"))
978+
Expect(network2.Subnets).To(HaveLen(1))
979+
Expect(network2.Subnets).To(Equal(network1.Subnets))
980+
})
981+
960982
It("create network with vrf option", func() {
961983
network := types.Network{
962984
Options: map[string]string{

0 commit comments

Comments
 (0)