Skip to content

Commit 7ec7496

Browse files
committed
libnetwork: correctly assign free names
If no name is given we have to set a free one, however the logic was broken since the beginning due some copy paste. This function as the name suggests must return all network names so we know to not reuse an existing one. I just found this by accident no user ever reported this in almost two years. This likely means no one uses the automatic names and everybody set's their own name on the cli instead. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
1 parent 5271d40 commit 7ec7496

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

libnetwork/internal/util/util.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ func GetBridgeInterfaceNames(n NetUtil) []string {
2828
func GetUsedNetworkNames(n NetUtil) []string {
2929
names := make([]string, 0, n.Len())
3030
n.ForEach(func(net types.Network) {
31-
if net.Driver == types.BridgeNetworkDriver {
32-
names = append(names, net.NetworkInterface)
33-
}
31+
names = append(names, net.Name)
3432
})
3533
return names
3634
}

libnetwork/netavark/config_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,19 @@ var _ = Describe("Config", func() {
10011001
Expect(network1.IPAMOptions[types.Driver]).To(Equal(types.DHCPIPAMDriver))
10021002
})
10031003

1004+
It("create two macvlan networks without name", func() {
1005+
network := types.Network{Driver: "macvlan"}
1006+
network1, err := libpodNet.NetworkCreate(network, nil)
1007+
Expect(err).ToNot(HaveOccurred())
1008+
Expect(network1.IPAMOptions[types.Driver]).To(Equal(types.DHCPIPAMDriver))
1009+
Expect(network1.Name).To(Equal("podman1"))
1010+
1011+
network2, err := libpodNet.NetworkCreate(network, nil)
1012+
Expect(err).ToNot(HaveOccurred())
1013+
Expect(network2.IPAMOptions[types.Driver]).To(Equal(types.DHCPIPAMDriver))
1014+
Expect(network2.Name).To(Equal("podman2"), "second name should be different then first")
1015+
})
1016+
10041017
It("create macvlan config without subnet and host-local", func() {
10051018
network := types.Network{
10061019
Driver: "macvlan",

0 commit comments

Comments
 (0)