Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art committed Mar 25, 2022
1 parent 1ed5010 commit 982980d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -101,21 +97,20 @@ 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{
tableID: tableID,
policyRoute: policy,
}
}
for _, policy := range new {
for _, policy := range newPolicies {
if _, ok := currentMap[policyKey(policy)]; !ok {
toAdd = append(toAdd, policy)
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 982980d

Please sign in to comment.