Skip to content

Commit

Permalink
Fix neighbor discovering
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 Nov 29, 2023
1 parent 442f83b commit d2d1d42
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions internal/vppinit/vppinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func LinkToSocket(ctx context.Context, vppConn api.Connection, tunnelIP net.IP,
WithField("duration", time.Since(now)).
WithField("vppapi", "SwInterfaceSetFlags").Debug("completed")

err = addIPNeighbor(ctx, vppConn, swIfIndex, link.Attrs().Index)
err = addIPNeighbor(ctx, vppConn, swIfIndex, link.Attrs().Index, routes)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -376,23 +376,6 @@ func createAfXDP(ctx context.Context, vppConn api.Connection, link netlink.Link)
}

func afxdpHostSettings(ctx context.Context, link netlink.Link) (uint16, error) {
// Get all gateways for a given interface and send ping requests.
// This will allow us to resolve the neighbors.
rl, _ := netlink.RouteList(link, netlink.FAMILY_ALL)
for i := 0; i < len(rl); i++ {
if rl[i].Gw != nil {
continue
}
pi := ping.New(rl[i].Gw.String())
pi.Count = 1
pi.Timeout = time.Millisecond * 100
pi.SetPrivileged(true)
err := pi.Run()
if err == nil {
log.FromContext(ctx).Infof("Gateway %v was resolved", rl[0].Gw.String())
}
}

// /sys/fs/bpf - the default dir of BPF filesystem
err := syscall.Mount("bpffs", "/sys/fs/bpf", "bpf", 0, "")
if err != nil {
Expand Down Expand Up @@ -448,7 +431,23 @@ func afxdpHostSettings(ctx context.Context, link netlink.Link) (uint16, error) {
return uint16(channels.CombinedCount), err
}

func addIPNeighbor(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex, linkIdx int) error {
func addIPNeighbor(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex, linkIdx int, routes []netlink.Route) error {
// Get all gateways for a given interface and send ping requests.
// This will allow us to resolve the neighbors.
for i := 0; i < len(routes); i++ {
if routes[i].Gw == nil {
continue
}
pi := ping.New(routes[i].Gw.String())
pi.Count = 1
pi.Timeout = time.Millisecond * 100
pi.SetPrivileged(true)
err := pi.Run()
if err == nil {
log.FromContext(ctx).Infof("Gateway %v was resolved", routes[0].Gw.String())
}
}

neighList, err := netlink.NeighList(linkIdx, netlink.FAMILY_ALL)
if err != nil {
return err
Expand Down

0 comments on commit d2d1d42

Please sign in to comment.