From f0be4d126dacb19a35046536b041a5989ff0dc95 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 1 Oct 2022 22:39:23 +0200 Subject: [PATCH] libnetwork: use object-literal for some structs Signed-off-by: Sebastiaan van Stijn --- libnetwork/drivers/overlay/ov_network.go | 28 +++++++++++------------- libnetwork/sandbox.go | 11 +++++----- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/libnetwork/drivers/overlay/ov_network.go b/libnetwork/drivers/overlay/ov_network.go index f611d11d89..4c77ff620d 100644 --- a/libnetwork/drivers/overlay/ov_network.go +++ b/libnetwork/drivers/overlay/ov_network.go @@ -539,25 +539,23 @@ func checkOverlap(nw *net.IPNet) error { } func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) error { - sbox := n.sbox - // restore overlay osl sandbox - Ifaces := make(map[string][]osl.IfaceOption) - brIfaceOption := make([]osl.IfaceOption, 2) - brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Address(s.gwIP)) - brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Bridge(true)) - Ifaces[brName+"+br"] = brIfaceOption - - err := sbox.Restore(Ifaces, nil, nil, nil) - if err != nil { + ifaces := map[string][]osl.IfaceOption{ + brName + "+br": { + n.sbox.InterfaceOptions().Address(s.gwIP), + n.sbox.InterfaceOptions().Bridge(true), + }, + } + if err := n.sbox.Restore(ifaces, nil, nil, nil); err != nil { return err } - Ifaces = make(map[string][]osl.IfaceOption) - vxlanIfaceOption := make([]osl.IfaceOption, 1) - vxlanIfaceOption = append(vxlanIfaceOption, sbox.InterfaceOptions().Master(brName)) - Ifaces[vxlanName+"+vxlan"] = vxlanIfaceOption - return sbox.Restore(Ifaces, nil, nil, nil) + ifaces = map[string][]osl.IfaceOption{ + vxlanName + "+vxlan": { + n.sbox.InterfaceOptions().Master(brName), + }, + } + return n.sbox.Restore(ifaces, nil, nil, nil) } func (n *network) setupSubnetSandbox(s *subnet, brName, vxlanName string) error { diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index f7a6b20fcb..8b3db16843 100644 --- a/libnetwork/sandbox.go +++ b/libnetwork/sandbox.go @@ -795,7 +795,6 @@ func (sb *sandbox) restoreOslSandbox() error { // restore osl sandbox Ifaces := make(map[string][]osl.IfaceOption) for _, ep := range sb.endpoints { - var ifaceOptions []osl.IfaceOption ep.Lock() joinInfo := ep.joinInfo i := ep.iface @@ -806,7 +805,10 @@ func (sb *sandbox) restoreOslSandbox() error { continue } - ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().Address(i.addr), sb.osSbox.InterfaceOptions().Routes(i.routes)) + ifaceOptions := []osl.IfaceOption{ + sb.osSbox.InterfaceOptions().Address(i.addr), + sb.osSbox.InterfaceOptions().Routes(i.routes), + } if i.addrv6 != nil && i.addrv6.IP.To16() != nil { ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().AddressIPv6(i.addrv6)) } @@ -816,7 +818,7 @@ func (sb *sandbox) restoreOslSandbox() error { if len(i.llAddrs) != 0 { ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().LinkLocalAddresses(i.llAddrs)) } - Ifaces[fmt.Sprintf("%s+%s", i.srcName, i.dstPrefix)] = ifaceOptions + Ifaces[i.srcName+i.dstPrefix] = ifaceOptions if joinInfo != nil { routes = append(routes, joinInfo.StaticRoutes...) } @@ -831,8 +833,7 @@ func (sb *sandbox) restoreOslSandbox() error { } // restore osl sandbox - err := sb.osSbox.Restore(Ifaces, routes, gwep.joinInfo.gw, gwep.joinInfo.gw6) - return err + return sb.osSbox.Restore(Ifaces, routes, gwep.joinInfo.gw, gwep.joinInfo.gw6) } func (sb *sandbox) populateNetworkResources(ep *endpoint) error {