Skip to content

Commit

Permalink
Merge pull request containers#12319 from Luap99/nettypes-rename
Browse files Browse the repository at this point in the history
rename libpod nettypes fields
  • Loading branch information
openshift-merge-robot authored Nov 16, 2021
2 parents 059785c + 97c6403 commit c661664
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 90 deletions.
4 changes: 2 additions & 2 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ func (c *Container) cniHosts() string {
var hosts string
for _, status := range c.getNetworkStatus() {
for _, netInt := range status.Interfaces {
for _, netAddress := range netInt.Networks {
hosts += fmt.Sprintf("%s\t%s %s\n", netAddress.Subnet.IP.String(), c.Hostname(), c.config.Name)
for _, netAddress := range netInt.Subnets {
hosts += fmt.Sprintf("%s\t%s %s\n", netAddress.IPNet.IP.String(), c.Hostname(), c.config.Name)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,8 +1341,8 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
perNetOpts.StaticMAC = netInt.MacAddress
}
if !options.IgnoreStaticIP {
for _, netAddress := range netInt.Networks {
perNetOpts.StaticIPs = append(perNetOpts.StaticIPs, netAddress.Subnet.IP)
for _, netAddress := range netInt.Subnets {
perNetOpts.StaticIPs = append(perNetOpts.StaticIPs, netAddress.IPNet.IP)
}
}
// Normally interfaces have a length of 1, only for some special cni configs we could get more.
Expand Down Expand Up @@ -1943,9 +1943,9 @@ func (c *Container) generateResolvConf() (string, error) {
netStatus := c.getNetworkStatus()
for _, status := range netStatus {
for _, netInt := range status.Interfaces {
for _, netAddress := range netInt.Networks {
for _, netAddress := range netInt.Subnets {
// Note: only using To16() does not work since it also returns a valid ip for ipv4
if netAddress.Subnet.IP.To4() == nil && netAddress.Subnet.IP.To16() != nil {
if netAddress.IPNet.IP.To4() == nil && netAddress.IPNet.IP.To16() != nil {
ipv6 = true
}
}
Expand Down Expand Up @@ -2151,7 +2151,7 @@ func (c *Container) getHosts() string {
if depCtr != nil {
for _, status := range depCtr.getNetworkStatus() {
for _, netInt := range status.Interfaces {
for _, netAddress := range netInt.Networks {
for _, netAddress := range netInt.Subnets {
if netAddress.Gateway != nil {
hosts += fmt.Sprintf("%s host.containers.internal\n", netAddress.Gateway.String())
}
Expand Down
8 changes: 4 additions & 4 deletions libpod/network/cni/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func CNIResultToStatus(res cnitypes.Result) (types.StatusBlock, error) {
cniInt := cniResult.Interfaces[*ip.Interface]
netInt, ok := interfaces[cniInt.Name]
if ok {
netInt.Networks = append(netInt.Networks, types.NetAddress{
Subnet: types.IPNet{IPNet: ip.Address},
netInt.Subnets = append(netInt.Subnets, types.NetAddress{
IPNet: types.IPNet{IPNet: ip.Address},
Gateway: ip.Gateway,
})
interfaces[cniInt.Name] = netInt
Expand All @@ -147,8 +147,8 @@ func CNIResultToStatus(res cnitypes.Result) (types.StatusBlock, error) {
}
interfaces[cniInt.Name] = types.NetInterface{
MacAddress: types.HardwareAddr(mac),
Networks: []types.NetAddress{{
Subnet: types.IPNet{IPNet: ip.Address},
Subnets: []types.NetAddress{{
IPNet: types.IPNet{IPNet: ip.Address},
Gateway: ip.Gateway,
}},
}
Expand Down
66 changes: 33 additions & 33 deletions libpod/network/cni/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Networks[0].Subnet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
// default network has no dns
Expect(res[defNet].DNSServerIPs).To(BeEmpty())
Expand Down Expand Up @@ -170,8 +170,8 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Networks[0].Subnet.IP).To(Equal(ip))
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Subnets[0].IPNet.IP).To(Equal(ip))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
// default network has no dns
Expect(res[defNet].DNSServerIPs).To(BeEmpty())
Expand Down Expand Up @@ -209,8 +209,8 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Networks[0].Subnet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
// default network has no dns
Expect(res[defNet].DNSServerIPs).To(BeEmpty())
Expand Down Expand Up @@ -263,8 +263,8 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
containerIP := res[defNet].Interfaces[intName].Networks[0].Subnet.IP.String()
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
containerIP := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()
Expect(containerIP).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
// default network has no dns
Expand Down Expand Up @@ -324,8 +324,8 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Networks[0].Subnet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))

for _, proto := range []string{"tcp", "udp"} {
Expand Down Expand Up @@ -386,8 +386,8 @@ var _ = Describe("run CNI", func() {

Expect(res).To(HaveKey(netName1))
Expect(res[netName1].Interfaces).To(HaveKey(intName1))
Expect(res[netName1].Interfaces[intName1].Networks).To(HaveLen(1))
ipInt1 := res[netName1].Interfaces[intName1].Networks[0].Subnet.IP
Expect(res[netName1].Interfaces[intName1].Subnets).To(HaveLen(1))
ipInt1 := res[netName1].Interfaces[intName1].Subnets[0].IPNet.IP
Expect(ipInt1).ToNot(BeEmpty())
macInt1 := res[netName1].Interfaces[intName1].MacAddress
Expect(macInt1).To(HaveLen(6))
Expand Down Expand Up @@ -436,8 +436,8 @@ var _ = Describe("run CNI", func() {

Expect(res).To(HaveKey(netName2))
Expect(res[netName2].Interfaces).To(HaveKey(intName2))
Expect(res[netName2].Interfaces[intName2].Networks).To(HaveLen(1))
ipInt2 := res[netName2].Interfaces[intName2].Networks[0].Subnet.IP
Expect(res[netName2].Interfaces[intName2].Subnets).To(HaveLen(1))
ipInt2 := res[netName2].Interfaces[intName2].Subnets[0].IPNet.IP
Expect(ipInt2).ToNot(BeEmpty())
macInt2 := res[netName2].Interfaces[intName2].MacAddress
Expect(macInt2).To(HaveLen(6))
Expand Down Expand Up @@ -576,16 +576,16 @@ var _ = Describe("run CNI", func() {

Expect(res).To(HaveKey(netName1))
Expect(res[netName1].Interfaces).To(HaveKey(intName1))
Expect(res[netName1].Interfaces[intName1].Networks).To(HaveLen(1))
ipInt1 := res[netName1].Interfaces[intName1].Networks[0].Subnet.IP
Expect(res[netName1].Interfaces[intName1].Subnets).To(HaveLen(1))
ipInt1 := res[netName1].Interfaces[intName1].Subnets[0].IPNet.IP
Expect(ipInt1.String()).To(ContainSubstring("192.168.0."))
macInt1 := res[netName1].Interfaces[intName1].MacAddress
Expect(macInt1).To(HaveLen(6))

Expect(res).To(HaveKey(netName2))
Expect(res[netName2].Interfaces).To(HaveKey(intName2))
Expect(res[netName2].Interfaces[intName2].Networks).To(HaveLen(1))
ipInt2 := res[netName2].Interfaces[intName2].Networks[0].Subnet.IP
Expect(res[netName2].Interfaces[intName2].Subnets).To(HaveLen(1))
ipInt2 := res[netName2].Interfaces[intName2].Subnets[0].IPNet.IP
Expect(ipInt2.String()).To(ContainSubstring("192.168.1."))
macInt2 := res[netName2].Interfaces[intName2].MacAddress
Expect(macInt2).To(HaveLen(6))
Expand Down Expand Up @@ -701,13 +701,13 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(netName))
Expect(res[netName].Interfaces).To(HaveKey(interfaceName))
Expect(res[netName].Interfaces[interfaceName].Networks).To(HaveLen(2))
Expect(res[netName].Interfaces[interfaceName].Networks[0].Subnet.IP.String()).To(Equal(ip1.String()))
Expect(res[netName].Interfaces[interfaceName].Networks[0].Subnet.Mask).To(Equal(subnet1.Mask))
Expect(res[netName].Interfaces[interfaceName].Networks[0].Gateway).To(Equal(net.ParseIP("192.168.0.1")))
Expect(res[netName].Interfaces[interfaceName].Networks[1].Subnet.IP.String()).To(Equal(ip2.String()))
Expect(res[netName].Interfaces[interfaceName].Networks[1].Subnet.Mask).To(Equal(subnet2.Mask))
Expect(res[netName].Interfaces[interfaceName].Networks[1].Gateway).To(Equal(net.ParseIP("fd41:0a75:2ca0:48a9::1")))
Expect(res[netName].Interfaces[interfaceName].Subnets).To(HaveLen(2))
Expect(res[netName].Interfaces[interfaceName].Subnets[0].IPNet.IP.String()).To(Equal(ip1.String()))
Expect(res[netName].Interfaces[interfaceName].Subnets[0].IPNet.Mask).To(Equal(subnet1.Mask))
Expect(res[netName].Interfaces[interfaceName].Subnets[0].Gateway).To(Equal(net.ParseIP("192.168.0.1")))
Expect(res[netName].Interfaces[interfaceName].Subnets[1].IPNet.IP.String()).To(Equal(ip2.String()))
Expect(res[netName].Interfaces[interfaceName].Subnets[1].IPNet.Mask).To(Equal(subnet2.Mask))
Expect(res[netName].Interfaces[interfaceName].Subnets[1].Gateway).To(Equal(net.ParseIP("fd41:0a75:2ca0:48a9::1")))
Expect(res[netName].Interfaces[interfaceName].MacAddress).To(Equal(types.HardwareAddr(mac)))
// default network has no dns
Expect(res[netName].DNSServerIPs).To(BeEmpty())
Expand Down Expand Up @@ -799,9 +799,9 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(netName))
Expect(res[netName].Interfaces).To(HaveKey(intName))
Expect(res[netName].Interfaces[intName].Networks).To(HaveLen(1))
Expect(res[netName].Interfaces[intName].Networks[0].Subnet.IP.String()).To(Equal(ip))
Expect(res[netName].Interfaces[intName].Networks[0].Subnet.Mask).To(Equal(net.CIDRMask(24, 32)))
Expect(res[netName].Interfaces[intName].Subnets).To(HaveLen(1))
Expect(res[netName].Interfaces[intName].Subnets[0].IPNet.IP.String()).To(Equal(ip))
Expect(res[netName].Interfaces[intName].Subnets[0].IPNet.Mask).To(Equal(net.CIDRMask(24, 32)))

// check in the container namespace if the settings are applied
err = netNSContainer.Do(func(_ ns.NetNS) error {
Expand Down Expand Up @@ -902,11 +902,11 @@ var _ = Describe("run CNI", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(netName))
Expect(res[netName].Interfaces).To(HaveKey(interfaceName))
Expect(res[netName].Interfaces[interfaceName].Networks).To(HaveLen(2))
Expect(res[netName].Interfaces[interfaceName].Networks[0].Subnet.IP.String()).To(Equal(ip1.String()))
Expect(res[netName].Interfaces[interfaceName].Networks[0].Subnet.Mask).To(Equal(mask1))
Expect(res[netName].Interfaces[interfaceName].Networks[1].Subnet.IP.String()).To(Equal(ip2.String()))
Expect(res[netName].Interfaces[interfaceName].Networks[1].Subnet.Mask).To(Equal(mask2))
Expect(res[netName].Interfaces[interfaceName].Subnets).To(HaveLen(2))
Expect(res[netName].Interfaces[interfaceName].Subnets[0].IPNet.IP.String()).To(Equal(ip1.String()))
Expect(res[netName].Interfaces[interfaceName].Subnets[0].IPNet.Mask).To(Equal(mask1))
Expect(res[netName].Interfaces[interfaceName].Subnets[1].IPNet.IP.String()).To(Equal(ip2.String()))
Expect(res[netName].Interfaces[interfaceName].Subnets[1].IPNet.Mask).To(Equal(mask2))
// dualstack network dns
Expect(res[netName].DNSServerIPs).To(HaveLen(2))
Expect(res[netName].DNSSearchDomains).To(HaveLen(1))
Expand Down
48 changes: 24 additions & 24 deletions libpod/network/netavark/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
ip := res[defNet].Interfaces[intName].Networks[0].Subnet.IP
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
ip := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
Expect(ip.String()).To(ContainSubstring("10.88.0."))
gw := res[defNet].Interfaces[intName].Networks[0].Gateway
gw := res[defNet].Interfaces[intName].Subnets[0].Gateway
util.NormalizeIP(&gw)
Expect(gw.String()).To(Equal("10.88.0.1"))
macAddress := res[defNet].Interfaces[intName].MacAddress
Expand Down Expand Up @@ -222,8 +222,8 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
ip1 := res[defNet].Interfaces[intName].Networks[0].Subnet.IP
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
ip1 := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
Expect(ip1.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))

Expand All @@ -246,8 +246,8 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
ip2 := res[defNet].Interfaces[intName].Networks[0].Subnet.IP
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
ip2 := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
Expect(ip2.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
Expect(ip1.Equal(ip2)).To(BeFalse(), "IP1 %s should not be equal to IP2 %s", ip1.String(), ip2.String())
Expand Down Expand Up @@ -286,14 +286,14 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(netName))
Expect(res[netName].Interfaces).To(HaveKey(intName))
Expect(res[netName].Interfaces[intName].Networks).To(HaveLen(2))
ip1 := res[netName].Interfaces[intName].Networks[0].Subnet.IP
Expect(res[netName].Interfaces[intName].Subnets).To(HaveLen(2))
ip1 := res[netName].Interfaces[intName].Subnets[0].IPNet.IP
Expect(ip1.String()).To(ContainSubstring("10.0.0."))
gw1 := res[netName].Interfaces[intName].Networks[0].Gateway
gw1 := res[netName].Interfaces[intName].Subnets[0].Gateway
Expect(gw1.String()).To(Equal("10.0.0.1"))
ip2 := res[netName].Interfaces[intName].Networks[1].Subnet.IP
ip2 := res[netName].Interfaces[intName].Subnets[1].IPNet.IP
Expect(ip2.String()).To(ContainSubstring("fd10:88:a::"))
gw2 := res[netName].Interfaces[intName].Networks[0].Gateway
gw2 := res[netName].Interfaces[intName].Subnets[0].Gateway
Expect(gw2.String()).To(Equal("fd10:88:a::1"))
Expect(res[netName].Interfaces[intName].MacAddress).To(HaveLen(6))

Expand Down Expand Up @@ -380,14 +380,14 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveKey(netName2))
Expect(res[netName1].Interfaces).To(HaveKey(intName1))
Expect(res[netName2].Interfaces).To(HaveKey(intName2))
Expect(res[netName1].Interfaces[intName1].Networks).To(HaveLen(1))
ip1 := res[netName1].Interfaces[intName1].Networks[0].Subnet.IP
Expect(res[netName1].Interfaces[intName1].Subnets).To(HaveLen(1))
ip1 := res[netName1].Interfaces[intName1].Subnets[0].IPNet.IP
Expect(ip1.String()).To(ContainSubstring("10.0.0."))
gw1 := res[netName1].Interfaces[intName1].Networks[0].Gateway
gw1 := res[netName1].Interfaces[intName1].Subnets[0].Gateway
Expect(gw1.String()).To(Equal("10.0.0.1"))
ip2 := res[netName2].Interfaces[intName2].Networks[0].Subnet.IP
ip2 := res[netName2].Interfaces[intName2].Subnets[0].IPNet.IP
Expect(ip2.String()).To(ContainSubstring("10.1.0."))
gw2 := res[netName2].Interfaces[intName2].Networks[0].Gateway
gw2 := res[netName2].Interfaces[intName2].Subnets[0].Gateway
Expect(gw2.String()).To(Equal("10.1.0.1"))
mac1 := res[netName1].Interfaces[intName1].MacAddress
Expect(mac1).To(HaveLen(6))
Expand Down Expand Up @@ -481,8 +481,8 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Networks[0].Subnet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
Expect(res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
// default network has no dns
Expect(res[defNet].DNSServerIPs).To(BeEmpty())
Expand Down Expand Up @@ -535,8 +535,8 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
containerIP := res[defNet].Interfaces[intName].Networks[0].Subnet.IP.String()
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
containerIP := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()
Expect(containerIP).To(ContainSubstring("10.88.0."))
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
// default network has no dns
Expand Down Expand Up @@ -593,10 +593,10 @@ var _ = Describe("run netavark", func() {
Expect(res).To(HaveLen(1))
Expect(res).To(HaveKey(defNet))
Expect(res[defNet].Interfaces).To(HaveKey(intName))
Expect(res[defNet].Interfaces[intName].Networks).To(HaveLen(1))
ip := res[defNet].Interfaces[intName].Networks[0].Subnet.IP
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
ip := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
Expect(ip.String()).To(ContainSubstring("10.88.0."))
gw := res[defNet].Interfaces[intName].Networks[0].Gateway
gw := res[defNet].Interfaces[intName].Subnets[0].Gateway
Expect(gw.String()).To(Equal("10.88.0.1"))
macAddress := res[defNet].Interfaces[intName].MacAddress
Expect(macAddress).To(HaveLen(6))
Expand Down
Loading

0 comments on commit c661664

Please sign in to comment.