Skip to content

Commit

Permalink
Pass interface argument to arp/ip command if there is only one interface
Browse files Browse the repository at this point in the history
  • Loading branch information
douglaswth committed Jul 27, 2022
1 parent 7cd34ff commit 99dfa88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions neighbors/arp_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func (a *arp) Present(ctx context.Context, ifs Interfaces, state State, addrStat
}

cmd := exec.CommandContext(ctx, a.cmd, "--libxo=json", "-an")
if len(ifs) == 1 {
for ifi := range ifs {
cmd.Args = append(cmd.Args, "-i", ifi)
}
}
log.Debug(ctx, log.KV{K: "cmd", V: cmd})
b, err := cmd.Output()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions neighbors/arp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func (a *arp) Present(ctx context.Context, ifs Interfaces, state State, addrStat
}

cmd := exec.CommandContext(ctx, a.cmd, "-family", "inet", "-json", "neighbor", "show", "nud", "reachable")
if len(ifs) == 1 {
for ifi := range ifs {
cmd.Args = append(cmd.Args, "dev", ifi)
}
}
log.Debug(ctx, log.KV{K: "cmd", V: cmd})
b, err := cmd.Output()
if err != nil {
Expand Down

0 comments on commit 99dfa88

Please sign in to comment.