Skip to content

Commit 154b0e0

Browse files
committed
Verify that EgressIPs are on the expected subnet
1 parent 3fe9146 commit 154b0e0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/network/node/egressip.go

+10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type egressIPWatcher struct {
5252
namespacesByEgressIP map[string]*namespaceEgress
5353

5454
localEgressLink netlink.Link
55+
localEgressNet *net.IPNet
5556
localEgressIPMaskLen int
5657

5758
testModeChan chan string
@@ -269,6 +270,12 @@ func (eip *egressIPWatcher) claimEgressIP(egressIP, egressHex string) error {
269270

270271
for _, addr := range addrs {
271272
if addr.IP.String() == eip.localIP {
273+
_, eip.localEgressNet, err = net.ParseCIDR(addr.IPNet.String())
274+
if err != nil {
275+
glog.Warningf("Could not parse CIDR network from address %q: %v", addr.IP.String(), err)
276+
break linkLoop
277+
}
278+
272279
eip.localEgressLink = link
273280
eip.localEgressIPMaskLen, _ = addr.Mask.Size()
274281
break linkLoop
@@ -286,6 +293,9 @@ func (eip *egressIPWatcher) claimEgressIP(egressIP, egressHex string) error {
286293
if err != nil {
287294
return fmt.Errorf("could not parse egress IP %q: %v", egressIPNet, err)
288295
}
296+
if !eip.localEgressNet.Contains(addr.IP) {
297+
return fmt.Errorf("egress IP %q is not in local network %s of interface %s", egressIP, eip.localEgressNet.String(), eip.localEgressLink.Attrs().Name)
298+
}
289299
err = netlink.AddrAdd(eip.localEgressLink, addr)
290300
if err != nil {
291301
return fmt.Errorf("could not add egress IP %q to %s: %v", egressIPNet, eip.localEgressLink.Attrs().Name, err)

0 commit comments

Comments
 (0)