Skip to content

Commit

Permalink
Remove kernel part of ip neighbor
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 Jan 24, 2022
1 parent d10fa4c commit 6017f1c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -31,9 +31,10 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk-kernel/pkg/kernel/tools/peer"

"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/up"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/peer"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/types"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/mechanisms/kernel/kernelvethpair/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -32,13 +32,13 @@ import (

kernellink "github.com/networkservicemesh/sdk-kernel/pkg/kernel"
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/tools/nshandle"
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/tools/peer"
"github.com/networkservicemesh/sdk/pkg/tools/log"

"github.com/networkservicemesh/sdk-vpp/pkg/tools/ethtool"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/link"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/mechutils"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/peer"
)

func create(ctx context.Context, conn *networkservice.Connection, isClient bool) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -29,24 +29,20 @@ import (
"github.com/edwarnicke/govpp/binapi/ip_neighbor"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
kernellink "github.com/networkservicemesh/sdk-kernel/pkg/kernel"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/pkg/errors"
"github.com/vishvananda/netlink"

"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/link"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/peer"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/types"
)

func addDel(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection, isClient, isAdd bool) error {
if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism != nil {
srcNets := conn.GetContext().GetIpContext().GetSrcIPNets()
dstNets := conn.GetContext().GetIpContext().GetDstIPNets()
if isClient {
srcNets = conn.GetContext().GetIpContext().GetDstIPNets()
dstNets = conn.GetContext().GetIpContext().GetSrcIPNets()
}
swIfIndex, ok := ifindex.Load(ctx, isClient)
if !ok {
Expand All @@ -66,21 +62,6 @@ func addDel(ctx context.Context, conn *networkservice.Connection, vppConn api.Co
}
}
}

peerLink, ok := peer.Load(ctx, isClient)
if !ok {
return nil
}
if peerLink == nil || peerLink.Attrs() == nil || peerLink.Attrs().HardwareAddr == nil {
panic(fmt.Sprintf("unable to construct peer ip neighborL %+v", peerLink))
}
for _, dstNet := range dstNets {
if dstNet != nil {
if err := addDelKernel(ctx, isAdd, mechanism, l, peerLink, dstNet); err != nil {
return err
}
}
}
}
return nil
}
Expand Down Expand Up @@ -109,42 +90,3 @@ func addDelVPP(ctx context.Context, vppConn api.Connection, isAdd bool, swIfInde
WithField("vppapi", "IPNeighborAddDel").Debug("completed")
return nil
}

func addDelKernel(ctx context.Context, isAdd bool, mechanism *kernel.Mechanism, l, peerLink netlink.Link, dstNet *net.IPNet) error {
now := time.Now()
handle, err := kernellink.GetNetlinkHandle(mechanism.GetNetNSURL())
if err != nil {
return errors.WithStack(err)
}
defer handle.Delete()
neigh := &netlink.Neigh{
LinkIndex: l.Attrs().Index,
IP: dstNet.IP,
State: netlink.NUD_PERMANENT,
HardwareAddr: peerLink.Attrs().HardwareAddr,
}
if isAdd {
if err = handle.NeighSet(neigh); err != nil {
return errors.WithStack(err)
}
log.FromContext(ctx).
WithField("linkIndex", neigh.LinkIndex).
WithField("ip", neigh.IP).
WithField("state", neigh.State).
WithField("hardwareAddr", neigh.HardwareAddr).
WithField("duration", time.Since(now)).
WithField("netlink", "NeighAdd").Debug("completed")
return nil
}
if err = handle.NeighDel(neigh); err != nil {
return errors.WithStack(err)
}
log.FromContext(ctx).
WithField("linkIndex", neigh.LinkIndex).
WithField("ip", neigh.IP).
WithField("state", neigh.State).
WithField("hardwareAddr", neigh.HardwareAddr).
WithField("duration", time.Since(now)).
WithField("netlink", "NeighDel").Debug("completed")
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -29,8 +29,9 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk/pkg/tools/log"

"github.com/networkservicemesh/sdk-kernel/pkg/kernel/tools/peer"

"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/peer"
)

func setMTU(ctx context.Context, conn *networkservice.Connection, isClient bool) error {
Expand Down
75 changes: 0 additions & 75 deletions pkg/tools/peer/metadata.go

This file was deleted.

0 comments on commit 6017f1c

Please sign in to comment.