-
Notifications
You must be signed in to change notification settings - Fork 1
/
arp_entry_remover.go
52 lines (41 loc) · 1018 Bytes
/
arp_entry_remover.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package monitor
import (
"errors"
"fmt"
"net"
"os/exec"
)
const (
FlushARPBinPath = "/var/vcap/packages/switchboard/bin/flusharp"
)
//go:generate counterfeiter . ArpEntryRemover
type ArpEntryRemover interface {
RemoveEntry(ip net.IP) error
}
//go:generate counterfeiter . CmdRunner
type CmdRunner interface {
Run(name string, cmd ...string) ([]byte, error)
}
type ExecCmdRunner struct{}
func (r *ExecCmdRunner) Run(name string, arg ...string) ([]byte, error) {
return exec.Command(name, arg...).CombinedOutput()
}
type ARPFlusher struct {
runner CmdRunner
}
func NewARPFlusher(runner CmdRunner) ArpEntryRemover {
return &ARPFlusher{
runner: runner,
}
}
func (a ARPFlusher) RemoveEntry(ip net.IP) error {
if ip == nil {
return errors.New("failed to delete arp entry: invalid IP")
}
output, err := a.runner.Run(FlushARPBinPath, ip.String())
if err != nil {
return errors.New(fmt.Sprintf("failed to delete arp entry: OUTPUT=%s, ERROR=%s", output, err.Error()))
} else {
return nil
}
}