From 982980d0a9767d61570255a3560c4da45262b0f4 Mon Sep 17 00:00:00 2001 From: Artem Glazychev Date: Fri, 25 Mar 2022 19:33:14 +0700 Subject: [PATCH] Fix linter issues Signed-off-by: Artem Glazychev --- .../ipcontext/ipaddress/common.go | 8 +++----- .../ipcontext/iprule/common.go | 19 +++++++------------ .../ipcontext/iprule/gen.go | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go index 75ac02aa..03c4b75f 100644 --- a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go +++ b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go @@ -94,7 +94,7 @@ func create(ctx context.Context, conn *networkservice.Connection, isClient bool) ch := make(chan netlink.AddrUpdate) done := make(chan struct{}) - if err := netlink.AddrSubscribeAt(targetNetNS, ch, done); err != nil { + if err = netlink.AddrSubscribeAt(targetNetNS, ch, done); err != nil { return errors.Wrapf(err, "failed to subscribe for interface address updates") } @@ -157,9 +157,7 @@ func create(ctx context.Context, conn *networkservice.Connection, isClient bool) return nil } -func getIPAddrDifferences(netlinkHandle *netlink.Handle, l netlink.Link, new []*net.IPNet) ([]*net.IPNet, []*net.IPNet, error) { - var toAdd []*net.IPNet - var toRemove []*net.IPNet +func getIPAddrDifferences(netlinkHandle *netlink.Handle, l netlink.Link, newIPs []*net.IPNet) (toAdd, toRemove []*net.IPNet, err error) { currentIPs, err := netlinkHandle.AddrList(l, netlink.FAMILY_ALL) if err != nil { return nil, nil, errors.Wrapf(err, "failed to list ip addresses") @@ -172,7 +170,7 @@ func getIPAddrDifferences(netlinkHandle *netlink.Handle, l netlink.Link, new []* } currentIPsMap[addr.IPNet.String()] = addr.IPNet } - for _, ipNet := range new { + for _, ipNet := range newIPs { if _, ok := currentIPsMap[ipNet.String()]; !ok { toAdd = append(toAdd, ipNet) } diff --git a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/common.go b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/common.go index 816cbbc4..dc6e640c 100644 --- a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/common.go +++ b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/common.go @@ -52,10 +52,6 @@ func create(ctx context.Context, conn *networkservice.Connection, tableIDs *Map) return errors.WithStack(err) } - if err = netlinkHandle.LinkSetUp(l); err != nil { - return errors.WithStack(err) - } - ps, ok := tableIDs.Load(conn.GetId()) if !ok { if len(conn.Context.IpContext.Policies) == 0 { @@ -101,13 +97,12 @@ func create(ctx context.Context, conn *networkservice.Connection, tableIDs *Map) return nil } -func getPolicyDifferences(current map[int]*networkservice.PolicyRoute, new []*networkservice.PolicyRoute) ([]*networkservice.PolicyRoute, map[int]*networkservice.PolicyRoute) { +func getPolicyDifferences(current map[int]*networkservice.PolicyRoute, newPolicies []*networkservice.PolicyRoute) (toAdd []*networkservice.PolicyRoute, toRemove map[int]*networkservice.PolicyRoute) { type table struct { tableID int policyRoute *networkservice.PolicyRoute } - var toAdd []*networkservice.PolicyRoute - toRemove := map[int]*networkservice.PolicyRoute{} + toRemove = make(map[int]*networkservice.PolicyRoute) currentMap := make(map[string]*table) for tableID, policy := range current { currentMap[policyKey(policy)] = &table{ @@ -115,7 +110,7 @@ func getPolicyDifferences(current map[int]*networkservice.PolicyRoute, new []*ne policyRoute: policy, } } - for _, policy := range new { + for _, policy := range newPolicies { if _, ok := currentMap[policyKey(policy)]; !ok { toAdd = append(toAdd, policy) } @@ -308,8 +303,8 @@ func flushTable(ctx context.Context, handle *netlink.Handle, tableID int) error if err != nil { return errors.Wrapf(errors.WithStack(err), "failed to list routes") } - for _, route := range routes { - err := handle.RouteDel(&route) + for i := 0; i < len(routes); i++ { + err := handle.RouteDel(&routes[i]) if err != nil { return errors.Wrapf(errors.WithStack(err), "failed to delete route") } @@ -333,8 +328,8 @@ func getFreeTableID(ctx context.Context, handle *netlink.Handle) (int, error) { // tableID = 0 is reserved ids := make(map[int]int) ids[0] = 0 - for _, route := range routes { - ids[route.Table] = route.Table + for i := 0; i < len(routes); i++ { + ids[routes[i].Table] = routes[i].Table } // Find first missing table id diff --git a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/gen.go b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/gen.go index 81a68b66..578cd3f2 100644 --- a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/gen.go +++ b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/gen.go @@ -26,5 +26,5 @@ import ( type policies map[int]*networkservice.PolicyRoute -// Map - sync.Map with key == string (netNsURL) and value == policies +// Map - sync.Map with key == string (connID) and value == policies type Map sync.Map