Browse Source

Pass interface argument to arp/ip command if there is only one interface

Douglas Thrift 1 year ago
parent
commit
99dfa88234
2 changed files with 10 additions and 0 deletions
  1. 5 0
      neighbors/arp_freebsd.go
  2. 5 0
      neighbors/arp_linux.go

+ 5 - 0
neighbors/arp_freebsd.go

@@ -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 {

+ 5 - 0
neighbors/arp_linux.go

@@ -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 {