Skip to content

Commit 299385f

Browse files
committed
sbr: Move source interface rule creation out of ipCfg loop
The outbound interface rule does not reference anything from ipCfg so should not be in the loop. Signed-off-by: Neil Cook <[email protected]>
1 parent 421da89 commit 299385f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

plugins/meta/sbr/main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,6 @@ func doRoutes(ipCfgs []*current.IPConfig, iface string) error {
259259
return fmt.Errorf("Failed to add src rule: %v", err)
260260
}
261261

262-
// Only add an interface rule if there is 1 IP address configured on the interface
263-
if len(ipCfgs) == 1 {
264-
interfaceRule := netlink.NewRule()
265-
interfaceRule.Table = table
266-
log.Printf("Interface to use %s", iface)
267-
interfaceRule.OifName = iface
268-
269-
if err = netlink.RuleAdd(interfaceRule); err != nil {
270-
return fmt.Errorf("Failed to add interface rule: %v", err)
271-
}
272-
}
273262
// Add a default route, since this may have been removed by previous
274263
// plugin.
275264
if ipCfg.Gateway != nil {
@@ -330,6 +319,18 @@ func doRoutes(ipCfgs []*current.IPConfig, iface string) error {
330319
table = getNextTableID(rules, routes, table)
331320
}
332321

322+
// Add an interface rule, only if there is a single IP address configured on the interface
323+
if len(ipCfgs) == 1 {
324+
interfaceRule := netlink.NewRule()
325+
interfaceRule.Table = table
326+
log.Printf("Interface to use %s", iface)
327+
interfaceRule.OifName = iface
328+
329+
if err = netlink.RuleAdd(interfaceRule); err != nil {
330+
return fmt.Errorf("Failed to add interface rule: %v", err)
331+
}
332+
}
333+
333334
// Delete all the interface routes in the default routing table, which were
334335
// copied to source based routing tables.
335336
// Not deleting them while copying to accommodate for multiple ipCfgs from

0 commit comments

Comments
 (0)