Skip to content

Commit 65585e4

Browse files
committed
compat/network: Remove temporary ipvAddress variables.
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
1 parent 56e555b commit 65585e4

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

pkg/api/handlers/compat/networks.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,37 +77,30 @@ func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, statuses []abi
7777
containerEndpoints := make(map[string]dockerNetwork.EndpointResource, len(statuses))
7878
for _, st := range statuses {
7979
if netData, ok := st.Status[network.Name]; ok {
80-
ipv4Address := ""
81-
ipv6Address := ""
80+
var err error
81+
var ipv4_pfx netip.Prefix
82+
var ipv6_pfx netip.Prefix
8283
macAddr := nettypes.HardwareAddr{}
8384
for _, dev := range netData.Interfaces {
8485
for _, subnet := range dev.Subnets {
8586
// Note the docker API really wants the full CIDR subnet not just a single ip.
8687
// https://github.com/containers/podman/pull/12328
8788
if netutil.IsIPv4(subnet.IPNet.IP) {
88-
ipv4Address = subnet.IPNet.String()
89+
ipv4_pfx, err = netip.ParsePrefix(subnet.IPNet.String())
90+
if err != nil {
91+
return nil, fmt.Errorf("invalid IPv4Address %q: %w", subnet.IPNet.String(), err)
92+
}
8993
} else {
90-
ipv6Address = subnet.IPNet.String()
94+
ipv6_pfx, err = netip.ParsePrefix(subnet.IPNet.String())
95+
if err != nil {
96+
return nil, fmt.Errorf("invalid IPv6Address %q: %w", subnet.IPNet.String(), err)
97+
}
9198
}
9299
}
93100
macAddr = dev.MacAddress
94101
break
95102
}
96-
var err error
97-
var ipv4_pfx netip.Prefix
98-
if ipv4Address != "" {
99-
ipv4_pfx, err = netip.ParsePrefix(ipv4Address)
100-
if err != nil {
101-
return nil, fmt.Errorf("invalid IPv4Address %q: %w", ipv4Address, err)
102-
}
103-
}
104-
var ipv6_pfx netip.Prefix
105-
if ipv6Address != "" {
106-
ipv6_pfx, err = netip.ParsePrefix(ipv6Address)
107-
if err != nil {
108-
return nil, fmt.Errorf("invalid IPv6Address %q: %w", ipv6Address, err)
109-
}
110-
}
103+
111104
containerEndpoint := dockerNetwork.EndpointResource{
112105
Name: st.Name,
113106
MacAddress: dockerNetwork.HardwareAddr(net.HardwareAddr(macAddr)),

0 commit comments

Comments
 (0)