Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2dde61f

Browse files
committedOct 13, 2017
Do Egress IP link initialization stuff from Start()
1 parent 3fe9146 commit 2dde61f

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed
 

‎pkg/network/node/egressip.go

+28-31
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func newEgressIPWatcher(localIP string, oc *ovsController) *egressIPWatcher {
7171
}
7272

7373
func (eip *egressIPWatcher) Start(networkClient networkclient.Interface, iptables *NodeIPTables) error {
74+
if err := eip.findEgressLink(); err != nil {
75+
return fmt.Errorf("Could not find egress network interface: %v", err)
76+
}
77+
7478
eip.iptables = iptables
7579
eip.networkClient = networkClient
7680

@@ -79,6 +83,30 @@ func (eip *egressIPWatcher) Start(networkClient networkclient.Interface, iptable
7983
return nil
8084
}
8185

86+
func (eip *egressIPWatcher) findEgressLink() error {
87+
links, err := netlink.LinkList()
88+
if err != nil {
89+
return err
90+
}
91+
for _, link := range links {
92+
addrs, err := netlink.AddrList(link, syscall.AF_INET)
93+
if err != nil {
94+
glog.Warningf("Could not get addresses of interface %q while trying to find egress interface: %v", link.Attrs().Name, err)
95+
continue
96+
}
97+
98+
for _, addr := range addrs {
99+
if addr.IP.String() == eip.localIP {
100+
eip.localEgressLink = link
101+
eip.localEgressIPMaskLen, _ = addr.Mask.Size()
102+
return nil
103+
}
104+
}
105+
}
106+
107+
return fmt.Errorf("could not find network interface with the address %q", eip.localIP)
108+
}
109+
82110
func ipToHex(ip string) string {
83111
bytes := net.ParseIP(ip)
84112
if bytes == nil {
@@ -254,33 +282,6 @@ func (eip *egressIPWatcher) claimEgressIP(egressIP, egressHex string) error {
254282
return nil
255283
}
256284

257-
if eip.localEgressLink == nil {
258-
links, err := netlink.LinkList()
259-
if err != nil {
260-
return fmt.Errorf("could not get list of network interfaces while adding egress IP: %v", err)
261-
}
262-
linkLoop:
263-
for _, link := range links {
264-
addrs, err := netlink.AddrList(link, syscall.AF_INET)
265-
if err != nil {
266-
glog.Warningf("Could not get addresses of interface %q while trying to find egress interface: %v", link.Attrs().Name, err)
267-
continue
268-
}
269-
270-
for _, addr := range addrs {
271-
if addr.IP.String() == eip.localIP {
272-
eip.localEgressLink = link
273-
eip.localEgressIPMaskLen, _ = addr.Mask.Size()
274-
break linkLoop
275-
}
276-
}
277-
}
278-
279-
if eip.localEgressLink == nil {
280-
return fmt.Errorf("could not find network interface with the address %q while adding egress IP", eip.localIP)
281-
}
282-
}
283-
284285
egressIPNet := fmt.Sprintf("%s/%d", egressIP, eip.localEgressIPMaskLen)
285286
addr, err := netlink.ParseAddr(egressIPNet)
286287
if err != nil {
@@ -308,10 +309,6 @@ func (eip *egressIPWatcher) releaseEgressIP(egressIP, egressHex string) error {
308309
return nil
309310
}
310311

311-
if eip.localEgressLink == nil {
312-
return nil
313-
}
314-
315312
egressIPNet := fmt.Sprintf("%s/%d", egressIP, eip.localEgressIPMaskLen)
316313
addr, err := netlink.ParseAddr(egressIPNet)
317314
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.