Skip to content

Commit

Permalink
Add arp and ndp sub-command for easy debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Apr 28, 2024
1 parent df7d2e6 commit 7eb77be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var commands = []command{
{"cache-stats", ctlCmd, "display cache statistics"},
{"cache-keys", ctlCmd, "dump the list of cached entries"},
{"trace", ctlCmd, "display a stack trace dump"},
{"arp", ctlCmd, "dump the ARP table"},
{"ndp", ctlCmd, "dump the NDP table"},

{"version", showVersion, "show current version"},
}
Expand Down
24 changes: 24 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import (
"github.com/denisbrodbeck/machineid"
lru "github.com/hashicorp/golang-lru"

"github.com/nextdns/nextdns/arp"
"github.com/nextdns/nextdns/config"
"github.com/nextdns/nextdns/ctl"
"github.com/nextdns/nextdns/discovery"
"github.com/nextdns/nextdns/host"
"github.com/nextdns/nextdns/host/service"
"github.com/nextdns/nextdns/hosts"
"github.com/nextdns/nextdns/ndp"
"github.com/nextdns/nextdns/netstatus"
"github.com/nextdns/nextdns/proxy"
"github.com/nextdns/nextdns/resolver"
Expand Down Expand Up @@ -177,6 +179,28 @@ func run(args []string) error {
n := runtime.Stack(buf, true)
return string(buf[:n])
})
ctl.Command("ndp", func(data interface{}) interface{} {
t, err := ndp.Get()
if err != nil {
return err.Error()
}
var sb strings.Builder
for _, i := range t {
fmt.Fprintf(&sb, "%s %s\n", i.IP, i.MAC)
}
return sb.String()
})
ctl.Command("arp", func(data interface{}) interface{} {
t, err := arp.Get()
if err != nil {
return err.Error()
}
var sb strings.Builder
for _, i := range t {
fmt.Fprintf(&sb, "%s %s\n", i.IP, i.MAC)
}
return sb.String()
})

if c.SetupRouter {
r := router.New()
Expand Down

0 comments on commit 7eb77be

Please sign in to comment.