Skip to content

Commit bb11f51

Browse files
Merge pull request #20286 from danwinship/auto-egress-ip-arp
Use arping when claiming egress IPs
2 parents dfe0224 + baeef48 commit bb11f51

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/network/node/egressip.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ package node
55
import (
66
"fmt"
77
"net"
8+
"os/exec"
89
"sync"
910
"syscall"
11+
"time"
1012

1113
"github.com/golang/glog"
1214

@@ -154,6 +156,17 @@ func (eip *egressIPWatcher) assignEgressIP(egressIP, mark string) error {
154156
return fmt.Errorf("could not add egress IP %q to %s: %v", egressIPNet, eip.localEgressLink.Attrs().Name, err)
155157
}
156158
}
159+
// Use arping to try to update other hosts ARP caches, in case this IP was
160+
// previously active on another node. (Based on code from "ifup".)
161+
go func() {
162+
out, err := exec.Command("/sbin/arping", "-q", "-A", "-c", "1", "-I", eip.localEgressLink.Attrs().Name, egressIP).CombinedOutput()
163+
if err != nil {
164+
glog.Warning("Failed to send ARP claim for egress IP %q: %v (%s)", egressIP, err, string(out))
165+
return
166+
}
167+
time.Sleep(2 * time.Second)
168+
_ = exec.Command("/sbin/arping", "-q", "-U", "-c", "1", "-I", eip.localEgressLink.Attrs().Name, egressIP).Run()
169+
}()
157170

158171
if err := eip.iptables.AddEgressIPRules(egressIP, mark); err != nil {
159172
return fmt.Errorf("could not add egress IP iptables rule: %v", err)

0 commit comments

Comments
 (0)