summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2020-12-16 20:28:07 +0100
committerPaul Holzinger <paul.holzinger@web.de>2020-12-16 20:59:45 +0100
commitedf0e918e32f4f109329881310b798f3b2c7defb (patch)
tree56006ac73fd1462c5c7141f1b67567cb3cb19d83 /libpod
parentbacb2fc526dba7214e3c8420eccc5cf22bbb1a29 (diff)
downloadpodman-edf0e918e32f4f109329881310b798f3b2c7defb.tar.gz
podman-edf0e918e32f4f109329881310b798f3b2c7defb.tar.bz2
podman-edf0e918e32f4f109329881310b798f3b2c7defb.zip
Always add the default gateway to the cni config file
`podman network create` should always add a gateway to the cni config. If no gateway is given use the first ip in the subnet. CNI does not require the gateway field but we need it because of network inspect. This worked with previous version but was dropped in Commit(e7a72d72fd59). Fixes #8748 Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/network/netconflist.go4
-rw-r--r--libpod/network/netconflist_test.go6
2 files changed, 8 insertions, 2 deletions
diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go
index d61b96ecb..af25ee59c 100644
--- a/libpod/network/netconflist.go
+++ b/libpod/network/netconflist.go
@@ -95,6 +95,10 @@ func NewIPAMLocalHostRange(subnet *net.IPNet, ipRange *net.IPNet, gw net.IP) ([]
}
if gw != nil {
hostRange.Gateway = gw.String()
+ } else {
+ // Add first ip in subnet as gateway. It is not required
+ // by cni but should be included because of network inspect.
+ hostRange.Gateway = CalcGatewayIP(subnet).String()
}
ranges = append(ranges, hostRange)
return ranges, nil
diff --git a/libpod/network/netconflist_test.go b/libpod/network/netconflist_test.go
index 6bf1a9777..5ff733f0f 100644
--- a/libpod/network/netconflist_test.go
+++ b/libpod/network/netconflist_test.go
@@ -51,7 +51,8 @@ func TestNewIPAMLocalHostRange(t *testing.T) {
subnet: &net.IPNet{IP: net.IPv4(192, 168, 0, 0), Mask: net.IPv4Mask(255, 255, 255, 0)},
want: []IPAMLocalHostRangeConf{
{
- Subnet: "192.168.0.0/24",
+ Subnet: "192.168.0.0/24",
+ Gateway: "192.168.0.1",
},
},
},
@@ -74,7 +75,8 @@ func TestNewIPAMLocalHostRange(t *testing.T) {
subnet: &net.IPNet{IP: net.ParseIP("2001:DB8::"), Mask: net.IPMask(net.ParseIP("ffff:ffff:ffff::"))},
want: []IPAMLocalHostRangeConf{
{
- Subnet: "2001:db8::/48",
+ Subnet: "2001:db8::/48",
+ Gateway: "2001:db8::1",
},
},
},