[netstack] Tersify NUD logs

Make NUD logs visually denser and easier to pick out state transitions.

Before:
  [00030.126] 1827363203:00000> [netstack, nud] INFO: fuchsia_net_neighbor.go(38): added neighbor fe80::1cf2:deff:fece:3b22 with linkAddr = 1e:f2:de:ce:3b:22 on NIC 2 with state = Stale, updatedAt = 2020-1
  0-27 15:01:29.632275846 +0000 UTC m=+10.798173449
  [00032.731] 1827363203:00000> [netstack, nud] INFO: fuchsia_net_neighbor.go(45): changed neighbor fe80::1cf2:deff:fece:3b22 with linkAddr = 1e:f2:de:ce:3b:22 on NIC 2 with state = Delay, updatedAt = 2020-10-27 15:01:32.23655398 +0000 UTC m=+13.402451392
  [00037.731] 1827363203:00000> [netstack, nud] INFO: fuchsia_net_neighbor.go(45): changed neighbor fe80::1cf2:deff:fece:3b22 with linkAddr = 1e:f2:de:ce:3b:22 on NIC 2 with state = Probe, updatedAt = 2020
  -10-27 15:01:37.236956634 +0000 UTC m=+18.402854281
  [00037.732] 1827363203:00000> [netstack, nud] INFO: fuchsia_net_neighbor.go(45): changed neighbor fe80::1cf2:deff:fece:3b22 with linkAddr = 1e:f2:de:ce:3b:22 on NIC 2 with state = Reachable, updatedAt =
2020-10-27 15:01:37.238260177 +0000 UTC m=+18.4041574

After:
  [00028.058] 2301666203:00000> [netstack, NUD] INFO: fuchsia_net_neighbor.go(39): ADD fe80::1cf2:deff:fece:3b22 NIC=ethp0002 LinkAddress=1e:f2:de:ce:3b:22 Stal
  e
  [00030.556] 2301666203:00000> [netstack, NUD] INFO: fuchsia_net_neighbor.go(46): MOD fe80::1cf2:deff:fece:3b22 NIC=ethp0002 LinkAddress=1e:f2:de:ce:3b:22 Dela
  y
  [00035.556] 2301666203:00000> [netstack, NUD] INFO: fuchsia_net_neighbor.go(46): MOD fe80::1cf2:deff:fece:3b22 NIC=ethp0002 LinkAddress=1e:f2:de:ce:3b:22 Prob
  e
  [00035.569] 2301666203:00000> [netstack, NUD] INFO: fuchsia_net_neighbor.go(46): MOD fe80::1cf2:deff:fece:3b22 NIC=ethp0002 LinkAddress=1e:f2:de:ce:3b:22 Reac
hable

Change-Id: I1e2842464c3c634ea37d226ad51a9a0502466d72
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/443557
Commit-Queue: Tamir Duberstein <tamird@google.com>
Reviewed-by: Ghanan Gowripalan <ghanan@google.com>
Testability-Review: Ghanan Gowripalan <ghanan@google.com>
diff --git a/src/connectivity/network/netstack/fuchsia_net_neighbor.go b/src/connectivity/network/netstack/fuchsia_net_neighbor.go
index d461ac3..e133596 100644
--- a/src/connectivity/network/netstack/fuchsia_net_neighbor.go
+++ b/src/connectivity/network/netstack/fuchsia_net_neighbor.go
@@ -7,6 +7,7 @@
 import (
 	"errors"
 	"fmt"
+	"syscall/zx"
 	"syscall/zx/fidl"
 	"time"
 
@@ -22,38 +23,38 @@
 )
 
 const (
-	nudTag = "nud"
+	nudTag = "NUD"
 )
 
-var ErrNotImplemented = errors.New("not implemented")
-
-type nudDispatcher struct{}
+type nudDispatcher struct {
+	ns *Netstack
+}
 
 var _ stack.NUDDispatcher = (*nudDispatcher)(nil)
 
 // OnNeighborAdded implements stack.NUDDispatcher.
-func (*nudDispatcher) OnNeighborAdded(nicID tcpip.NICID, ipAddr tcpip.Address, linkAddr tcpip.LinkAddress, state stack.NeighborState, updatedAt time.Time) {
+func (d *nudDispatcher) OnNeighborAdded(nicID tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress, state stack.NeighborState, _ time.Time) {
 	// TODO(fxbug.dev/62788): Change log level to Debug once the neighbor table
 	// is able to be inspected.
-	_ = syslog.InfoTf(nudTag, "added neighbor %s with linkAddr = %s on NIC %d with state = %s, updatedAt = %s", ipAddr, linkAddr, nicID, state, updatedAt)
+	_ = syslog.InfoTf(nudTag, "ADD %s NIC=%s LinkAddress=%s %s", addr, d.ns.name(nicID), linkAddr, state)
 }
 
 // OnNeighborChanged implements stack.NUDDispatcher.
-func (*nudDispatcher) OnNeighborChanged(nicID tcpip.NICID, ipAddr tcpip.Address, linkAddr tcpip.LinkAddress, state stack.NeighborState, updatedAt time.Time) {
+func (d *nudDispatcher) OnNeighborChanged(nicID tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress, state stack.NeighborState, _ time.Time) {
 	// TODO(fxbug.dev/62788): Change log level to Debug once the neighbor table
 	// is able to be inspected.
-	_ = syslog.InfoTf(nudTag, "changed neighbor %s with linkAddr = %s on NIC %d with state = %s, updatedAt = %s", ipAddr, linkAddr, nicID, state, updatedAt)
+	_ = syslog.InfoTf(nudTag, "MOD %s NIC=%s LinkAddress=%s %s", addr, d.ns.name(nicID), linkAddr, state)
 }
 
 // OnNeighborRemoved implements stack.NUDDispatcher.
-func (*nudDispatcher) OnNeighborRemoved(nicID tcpip.NICID, ipAddr tcpip.Address, linkAddr tcpip.LinkAddress, state stack.NeighborState, updatedAt time.Time) {
+func (d *nudDispatcher) OnNeighborRemoved(nicID tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress, state stack.NeighborState, _ time.Time) {
 	// TODO(fxbug.dev/62788): Change log level to Debug once the neighbor table
 	// is able to be inspected.
-	_ = syslog.InfoTf(nudTag, "removed neighbor %s with linkAddr = %s on NIC %d with state = %s, updatedAt = %s", ipAddr, linkAddr, nicID, state, updatedAt)
+	_ = syslog.InfoTf(nudTag, "DEL %s NIC=%s LinkAddress=%s %s", addr, d.ns.name(nicID), linkAddr, state)
 }
 
 type neighborImpl struct {
-	ns *Netstack
+	stack *stack.Stack
 }
 
 var _ neighbor.ViewWithCtx = (*neighborImpl)(nil)
@@ -62,8 +63,8 @@
 	// TODO(fxbug.dev/59425): Watch for changes.
 	var items []neighbor.EntryIteratorItem
 
-	for nicID := range n.ns.stack.NICInfo() {
-		neighbors, err := n.ns.stack.Neighbors(nicID)
+	for nicID := range n.stack.NICInfo() {
+		neighbors, err := n.stack.Neighbors(nicID)
 		switch err {
 		case nil:
 		case tcpip.ErrNotSupported:
@@ -102,7 +103,7 @@
 
 func (n *neighborImpl) GetUnreachabilityConfig(ctx fidl.Context, interfaceID uint64) (neighbor.ViewGetUnreachabilityConfigResult, error) {
 	// TODO(fxbug.dev/51776): Implement fuchsia.net.neighbor/View.GetUnreachabilityConfigs
-	return neighbor.ViewGetUnreachabilityConfigResult{}, ErrNotImplemented
+	return neighbor.ViewGetUnreachabilityConfigResult{}, &zx.Error{Status: zx.ErrNotSupported}
 }
 
 var _ neighbor.ControllerWithCtx = (*neighborImpl)(nil)
@@ -111,28 +112,28 @@
 	// TODO(fxbug.dev/51777): Implement fuchsia.net.neighbor/Controller.AddEntry
 	resp := neighbor.ControllerAddEntryResponse{}
 	result := neighbor.ControllerAddEntryResultWithResponse(resp)
-	return result, ErrNotImplemented
+	return result, &zx.Error{Status: zx.ErrNotSupported}
 }
 
 func (n *neighborImpl) RemoveEntry(ctx fidl.Context, interfaceID uint64, neighborIP net.IpAddress) (neighbor.ControllerRemoveEntryResult, error) {
 	// TODO(fxbug.dev/51778): Implement fuchsia.net.neighbor/Controller.RemoveEntry
 	resp := neighbor.ControllerRemoveEntryResponse{}
 	result := neighbor.ControllerRemoveEntryResultWithResponse(resp)
-	return result, ErrNotImplemented
+	return result, &zx.Error{Status: zx.ErrNotSupported}
 }
 
 func (n *neighborImpl) ClearEntries(ctx fidl.Context, interfaceID uint64) (neighbor.ControllerClearEntriesResult, error) {
 	// TODO(fxbug.dev/51779): Implement fuchsia.net.neighbor/Controller.ClearEntries
 	resp := neighbor.ControllerClearEntriesResponse{}
 	result := neighbor.ControllerClearEntriesResultWithResponse(resp)
-	return result, ErrNotImplemented
+	return result, &zx.Error{Status: zx.ErrNotSupported}
 }
 
 func (n *neighborImpl) UpdateUnreachabilityConfig(ctx fidl.Context, interfaceID uint64, config neighbor.UnreachabilityConfig) (neighbor.ControllerUpdateUnreachabilityConfigResult, error) {
 	// TODO(fxbug.dev/51780): Implement fuchsia.net.neighbor/Controller.UpdateUnreachabilityConfig
 	resp := neighbor.ControllerUpdateUnreachabilityConfigResponse{}
 	result := neighbor.ControllerUpdateUnreachabilityConfigResultWithResponse(resp)
-	return result, ErrNotImplemented
+	return result, &zx.Error{Status: zx.ErrNotSupported}
 }
 
 // neighborEntryIterator queues events received from the neighbor table for
diff --git a/src/connectivity/network/netstack/main.go b/src/connectivity/network/netstack/main.go
index 7cf7b4a..a8f1d7c 100644
--- a/src/connectivity/network/netstack/main.go
+++ b/src/connectivity/network/netstack/main.go
@@ -216,6 +216,7 @@
 	}
 
 	ndpDisp := newNDPDispatcher()
+	var nudDisp nudDispatcher
 
 	stk := tcpipstack.New(tcpipstack.Options{
 		NetworkProtocols: []tcpipstack.NetworkProtocolFactory{
@@ -267,7 +268,7 @@
 		// (fxbug.dev/61723) for Neighbor Unreachability Detection. This enables
 		// inspection and modification of entries in the neighbor cache.
 		UseNeighborCache: true,
-		NUDDisp:          &nudDispatcher{},
+		NUDDisp:          &nudDisp,
 
 		// Raw sockets are typically used for implementing custom protocols. We intend
 		// to support custom protocols through structured FIDL APIs in the future, so
@@ -306,6 +307,7 @@
 	ns.interfaceWatchers.mu.lastObserved = make(map[tcpip.NICID]interfaces.Properties)
 
 	cobaltClient := NewCobaltClient()
+	nudDisp.ns = ns
 	ndpDisp.ns = ns
 	ndpDisp.dhcpv6Obs.init(func() {
 		cobaltClient.Register(&ndpDisp.dhcpv6Obs)
@@ -506,7 +508,7 @@
 	}
 
 	{
-		impl := &neighborImpl{ns: ns}
+		impl := &neighborImpl{stack: stk}
 
 		viewStub := neighbor.ViewWithCtxStub{Impl: impl}
 		appCtx.OutgoingService.AddService(
diff --git a/src/connectivity/network/netstack/netstack.go b/src/connectivity/network/netstack/netstack.go
index 4fc58a8..c46786d 100644
--- a/src/connectivity/network/netstack/netstack.go
+++ b/src/connectivity/network/netstack/netstack.go
@@ -443,7 +443,7 @@
 func (ns *Netstack) name(nicid tcpip.NICID) string {
 	name := ns.stack.FindNICNameFromID(nicid)
 	if len(name) == 0 {
-		name = fmt.Sprintf("unknown NIC(id=%d)", nicid)
+		name = fmt.Sprintf("unknown(NICID=%d)", nicid)
 	}
 	return name
 }
diff --git a/src/connectivity/network/netstack/netstack_test.go b/src/connectivity/network/netstack/netstack_test.go
index 4f5f87f..b91347b 100644
--- a/src/connectivity/network/netstack/netstack_test.go
+++ b/src/connectivity/network/netstack/netstack_test.go
@@ -396,7 +396,7 @@
 func TestNICName(t *testing.T) {
 	ns := newNetstack(t)
 
-	if want, got := "unknown NIC(id=0)", ns.name(0); got != want {
+	if want, got := "unknown(NICID=0)", ns.name(0); got != want {
 		t.Fatalf("got ns.name(0) = %q, want %q", got, want)
 	}