Skip to content

Commit

Permalink
delete sync.Map
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Skrynnik <[email protected]>
  • Loading branch information
NikitaSkrynnik committed Jun 29, 2023
1 parent ee53ce3 commit df502da
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 190 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:

golangci-lint:
uses: networkservicemesh/.github/.github/workflows/golangci-lint.yaml@main
with:
linter-version: v1.53.3

exclude-fmt-errorf:
uses: networkservicemesh/.github/.github/workflows/exclude-fmt-errorf.yaml@main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"golang.org/x/sys/unix"

"github.com/edwarnicke/genericsync"
"github.com/pkg/errors"
"github.com/vishvananda/netlink"

Expand All @@ -42,7 +43,9 @@ import (
link "github.com/networkservicemesh/sdk-kernel/pkg/kernel"
)

func create(ctx context.Context, conn *networkservice.Connection, tableIDs *Map, nsRTableNextIDToConnID *NetnsRTableNextIDToConnMap) error {
type policies map[int]*networkservice.PolicyRoute

func create(ctx context.Context, conn *networkservice.Connection, tableIDs *genericsync.Map[string, policies], nsRTableNextIDToConnID *genericsync.Map[NetnsRTableNextID, string]) error {
if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism != nil && mechanism.GetVLAN() == 0 {
// Construct the netlink handle for the target namespace for this kernel interface
netlinkHandle, err := link.GetNetlinkHandle(mechanism.GetNetNSURL())
Expand Down Expand Up @@ -102,7 +105,7 @@ func create(ctx context.Context, conn *networkservice.Connection, tableIDs *Map,
return nil
}

func addPolicy(ctx context.Context, netlinkHandle *netlink.Handle, policy *networkservice.PolicyRoute, l netlink.Link, ps policies, tableIDs *Map, tableID int, connID string, nsrtid NetnsRTableNextID, nsRTableNextIDToConnID *NetnsRTableNextIDToConnMap) error {
func addPolicy(ctx context.Context, netlinkHandle *netlink.Handle, policy *networkservice.PolicyRoute, l netlink.Link, ps policies, tableIDs *genericsync.Map[string, policies], tableID int, connID string, nsrtid NetnsRTableNextID, nsRTableNextIDToConnID *genericsync.Map[NetnsRTableNextID, string]) error {
// release the lock if something fails
defer nsRTableNextIDToConnID.Delete(nsrtid)
// If policy doesn't contain any route - add default
Expand Down Expand Up @@ -265,7 +268,7 @@ func routeAdd(ctx context.Context, handle *netlink.Handle, l netlink.Link, route
return nil
}

func del(ctx context.Context, conn *networkservice.Connection, tableIDs *Map, nsRTableNextIDToConnID *NetnsRTableNextIDToConnMap) error {
func del(ctx context.Context, conn *networkservice.Connection, tableIDs *genericsync.Map[string, policies], nsRTableNextIDToConnID *genericsync.Map[NetnsRTableNextID, string]) error {
if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism != nil && mechanism.GetVLAN() == 0 {
netlinkHandle, err := link.GetNetlinkHandle(mechanism.GetNetNSURL())
if err != nil {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package iprule
import (
"context"

"github.com/edwarnicke/genericsync"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk/pkg/tools/log"
Expand All @@ -35,7 +36,7 @@ import (
link "github.com/networkservicemesh/sdk-kernel/pkg/kernel"
)

func recoverTableIDs(ctx context.Context, conn *networkservice.Connection, tableIDs *Map) error {
func recoverTableIDs(ctx context.Context, conn *networkservice.Connection, tableIDs *genericsync.Map[string, policies]) error {
if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism != nil && mechanism.GetVLAN() == 0 {
_, ok := tableIDs.Load(conn.GetId())
if ok {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package iprule
import (
"context"

"github.com/edwarnicke/genericsync"
"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
Expand All @@ -34,11 +35,11 @@ import (
)

type ipruleServer struct {
tables Map
tables genericsync.Map[string, policies]
// Protecting route and rule setting with this sync.Map
// The next table ID is calculated based on a dump
// other connection from same client can add new table in parallel
nsRTableNextIDToConnID NetnsRTableNextIDToConnMap
nsRTableNextIDToConnID genericsync.Map[NetnsRTableNextID, string]
}

// NewServer creates a new server chain element setting ip rules
Expand Down

This file was deleted.

0 comments on commit df502da

Please sign in to comment.