@@ -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,10 @@ 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
+ if eip .localEgressLink , eip .localEgressNet , err = common .GetLinkDetails (eip .localIP ); err != nil {
76
+ // Not expected, should already be caught by node.New()
77
+ return err
77
78
}
78
79
79
80
eip .iptables = iptables
@@ -84,34 +85,6 @@ func (eip *egressIPWatcher) Start(networkClient networkclient.Interface, iptable
84
85
return nil
85
86
}
86
87
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
88
func ipToHex (ip string ) string {
116
89
bytes := net .ParseIP (ip )
117
90
if bytes == nil {
@@ -287,7 +260,8 @@ func (eip *egressIPWatcher) claimEgressIP(egressIP, egressHex string) error {
287
260
return nil
288
261
}
289
262
290
- egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , eip .localEgressIPMaskLen )
263
+ localEgressIPMaskLen , _ := eip .localEgressNet .Mask .Size ()
264
+ egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , localEgressIPMaskLen )
291
265
addr , err := netlink .ParseAddr (egressIPNet )
292
266
if err != nil {
293
267
return fmt .Errorf ("could not parse egress IP %q: %v" , egressIPNet , err )
@@ -321,7 +295,8 @@ func (eip *egressIPWatcher) releaseEgressIP(egressIP, egressHex string) error {
321
295
return nil
322
296
}
323
297
324
- egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , eip .localEgressIPMaskLen )
298
+ localEgressIPMaskLen , _ := eip .localEgressNet .Mask .Size ()
299
+ egressIPNet := fmt .Sprintf ("%s/%d" , egressIP , localEgressIPMaskLen )
325
300
addr , err := netlink .ParseAddr (egressIPNet )
326
301
if err != nil {
327
302
return fmt .Errorf ("could not parse egress IP %q: %v" , egressIPNet , err )
0 commit comments