forked from openshift/ovn-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getDefaultGatewayInterfaceByFamily: custom filter for MultiHop
Due to the way how IPv6 multipath is implemented, it is not possible to filter by ifindex as the ifindex for multihop routes will always be 0. Instead, implement a custom filter. Reported-at: https://issues.redhat.com/browse/OCPBUGS-1318 Signed-off-by: Andreas Karis <ak.karis@gmail.com>
- Loading branch information
1 parent
0590d6a
commit 980694d
Showing
2 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
package node | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/vishvananda/netlink" | ||
) | ||
|
||
func TestFilterRoutesByIfIndex(t *testing.T) { | ||
tcs := []struct { | ||
routesUnfiltered []netlink.Route | ||
gwIfIdx int | ||
routesFiltered []netlink.Route | ||
}{ | ||
// tc0 - baseline. | ||
{ | ||
routesUnfiltered: []netlink.Route{}, | ||
gwIfIdx: 0, | ||
routesFiltered: []netlink.Route{}, | ||
}, | ||
// tc1 - do not filter. | ||
{ | ||
routesUnfiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
LinkIndex: 2, | ||
Gw: []byte{2, 2, 2, 2}, | ||
}, | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{3, 3, 3, 3}, | ||
}, | ||
}, | ||
gwIfIdx: 0, | ||
routesFiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
LinkIndex: 2, | ||
Gw: []byte{2, 2, 2, 2}, | ||
}, | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{3, 3, 3, 3}, | ||
}, | ||
}, | ||
}, | ||
// tc2 - filter by link index. | ||
{ | ||
routesUnfiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
LinkIndex: 2, | ||
Gw: []byte{2, 2, 2, 2}, | ||
}, | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{3, 3, 3, 3}, | ||
}, | ||
}, | ||
gwIfIdx: 1, | ||
routesFiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{3, 3, 3, 3}, | ||
}, | ||
}, | ||
}, | ||
// tc3 - filter by MultiPath index. | ||
{ | ||
routesUnfiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
LinkIndex: 2, | ||
Gw: []byte{2, 2, 2, 2}, | ||
}, | ||
{ | ||
LinkIndex: 0, | ||
MultiPath: []*netlink.NexthopInfo{ | ||
{ | ||
LinkIndex: 1, | ||
Hops: 0, | ||
Gw: []byte{3, 3, 3, 3}, | ||
}, | ||
{ | ||
LinkIndex: 1, | ||
Hops: 0, | ||
Gw: []byte{4, 4, 4, 4}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
gwIfIdx: 1, | ||
routesFiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
LinkIndex: 0, | ||
MultiPath: []*netlink.NexthopInfo{ | ||
{ | ||
LinkIndex: 1, | ||
Hops: 0, | ||
Gw: []byte{3, 3, 3, 3}, | ||
}, | ||
{ | ||
LinkIndex: 1, | ||
Hops: 0, | ||
Gw: []byte{4, 4, 4, 4}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
// tc4 - filter by MultiPath index - MultiPath with multiple interfaces. | ||
{ | ||
routesUnfiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
LinkIndex: 2, | ||
Gw: []byte{2, 2, 2, 2}, | ||
}, | ||
{ | ||
LinkIndex: 0, | ||
MultiPath: []*netlink.NexthopInfo{ | ||
{ | ||
LinkIndex: 1, | ||
Hops: 0, | ||
Gw: []byte{3, 3, 3, 3}, | ||
}, | ||
{ | ||
LinkIndex: 2, | ||
Hops: 0, | ||
Gw: []byte{4, 4, 4, 4}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
gwIfIdx: 1, | ||
routesFiltered: []netlink.Route{ | ||
{ | ||
LinkIndex: 1, | ||
Gw: []byte{1, 1, 1, 1}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for i, tc := range tcs { | ||
routesFiltered := filterRoutesByIfIndex(tc.routesUnfiltered, tc.gwIfIdx) | ||
if !reflect.DeepEqual(tc.routesFiltered, routesFiltered) { | ||
t.Fatalf("TestFilterRoutesByIfIndex(%d): Filtering '%v' by index '%d' should have yielded '%v' but got '%v'", | ||
i, tc.routesUnfiltered, tc.gwIfIdx, tc.routesFiltered, routesFiltered) | ||
} | ||
} | ||
} |