Skip to content

Commit

Permalink
Verify that EgressIPs are on the expected subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
danwinship committed Oct 13, 2017
1 parent 2dde61f commit 84109c9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/network/node/egressip.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type egressIPWatcher struct {
namespacesByEgressIP map[string]*namespaceEgress

localEgressLink netlink.Link
localEgressNet *net.IPNet
localEgressIPMaskLen int

testModeChan chan string
Expand Down Expand Up @@ -97,6 +98,10 @@ func (eip *egressIPWatcher) findEgressLink() error {

for _, addr := range addrs {
if addr.IP.String() == eip.localIP {
_, eip.localEgressNet, err = net.ParseCIDR(addr.IPNet.String())
if err != nil {
return fmt.Errorf("could not parse CIDR network from address %q: %v", addr.IP.String(), err)
}
eip.localEgressLink = link
eip.localEgressIPMaskLen, _ = addr.Mask.Size()
return nil
Expand Down Expand Up @@ -287,6 +292,9 @@ func (eip *egressIPWatcher) claimEgressIP(egressIP, egressHex string) error {
if err != nil {
return fmt.Errorf("could not parse egress IP %q: %v", egressIPNet, err)
}
if !eip.localEgressNet.Contains(addr.IP) {
return fmt.Errorf("egress IP %q is not in local network %s of interface %s", egressIP, eip.localEgressNet.String(), eip.localEgressLink.Attrs().Name)
}
err = netlink.AddrAdd(eip.localEgressLink, addr)
if err != nil {
return fmt.Errorf("could not add egress IP %q to %s: %v", egressIPNet, eip.localEgressLink.Attrs().Name, err)
Expand Down

0 comments on commit 84109c9

Please sign in to comment.