@@ -51,9 +51,8 @@ type egressIPWatcher struct {
51
51
namespacesByVNID map [uint32 ]* namespaceEgress
52
52
namespacesByEgressIP map [string ]* namespaceEgress
53
53
54
- localEgressLink netlink.Link
55
- localEgressNet * net.IPNet
56
- localEgressIPMaskLen int
54
+ localEgressLink netlink.Link
55
+ localEgressNet * net.IPNet
57
56
58
57
testModeChan chan string
59
58
}
@@ -72,8 +71,11 @@ func newEgressIPWatcher(localIP string, oc *ovsController) *egressIPWatcher {
72
71
}
73
72
74
73
func (eip * egressIPWatcher ) Start (networkClient networkclient.Interface , iptables * NodeIPTables ) error {
75
- if err := eip .findEgressLink (); err != nil {
76
- return fmt .Errorf ("could not find egress network interface: %v" , err )
74
+ var err error
75
+ eip .localEgressLink , eip .localEgressNet , err = common .GetLinkDetails (eip .localIP )
76
+ if err != nil {
77
+ // Not expected, should already be caught by node.New()
78
+ return err
77
79
}
78
80
79
81
eip .iptables = iptables
@@ -84,34 +86,6 @@ func (eip *egressIPWatcher) Start(networkClient networkclient.Interface, iptable
84
86
return nil
85
87
}
86
88
87
- func (eip * egressIPWatcher ) findEgressLink () error {
88
- links , err := netlink .LinkList ()
89
- if err != nil {
90
- return err
91
- }
92
- for _ , link := range links {
93
- addrs , err := netlink .AddrList (link , syscall .AF_INET )
94
- if err != nil {
95
- glog .Warningf ("Could not get addresses of interface %q while trying to find egress interface: %v" , link .Attrs ().Name , err )
96
- continue
97
- }
98
-
99
- for _ , addr := range addrs {
100
- if addr .IP .String () == eip .localIP {
101
- _ , eip .localEgressNet , err = net .ParseCIDR (addr .IPNet .String ())
102
- if err != nil {
103
- return fmt .Errorf ("could not parse CIDR network from address %q: %v" , addr .IP .String (), err )
104
- }
105
- eip .localEgressLink = link
106
- eip .localEgressIPMaskLen , _ = addr .Mask .Size ()
107
- return nil
108
- }
109
- }
110
- }
111
-
112
- return fmt .Errorf ("could not find network interface with the address %q" , eip .localIP )
113
- }
114
-
115
89
func ipToHex (ip string ) string {
116
90
bytes := net .ParseIP (ip )
117
91
if bytes == nil {
@@ -287,7 +261,8 @@ func (eip *egressIPWatcher) claimEgressIP(egressIP, egressHex string) error {
287
261
return nil
288
262
}
289
263
290
- egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , eip .localEgressIPMaskLen )
264
+ localEgressIPMaskLen , _ := eip .localEgressNet .Mask .Size ()
265
+ egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , localEgressIPMaskLen )
291
266
addr , err := netlink .ParseAddr (egressIPNet )
292
267
if err != nil {
293
268
return fmt .Errorf ("could not parse egress IP %q: %v" , egressIPNet , err )
@@ -317,7 +292,8 @@ func (eip *egressIPWatcher) releaseEgressIP(egressIP, egressHex string) error {
317
292
return nil
318
293
}
319
294
320
- egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , eip .localEgressIPMaskLen )
295
+ localEgressIPMaskLen , _ := eip .localEgressNet .Mask .Size ()
296
+ egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , localEgressIPMaskLen )
321
297
addr , err := netlink .ParseAddr (egressIPNet )
322
298
if err != nil {
323
299
return fmt .Errorf ("could not parse egress IP %q: %v" , egressIPNet , err )
0 commit comments