Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: fix missing kernel routes (backport #17326) #17358

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"0.0.0.0/0":[
{
"prefix":"0.0.0.0/0",
"prefixLen":0,
"protocol":"kernel",
"vrfName":"default",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"table":254,
"nexthops":[
{
"fib":true,
"unreachable":true,
"blackhole":true,
"active":true
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,70 @@ def test_zebra_noprefix_connected():
assert result, "Connected Route should not have been added"


<<<<<<< HEAD
=======
def test_zebra_noprefix_connected_add():
"Test that a noprefixroute created with a manual route works as expected, this is for NetworkManager"

tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

router = tgen.gears["r1"]
router.run("ip route add 192.168.44.0/24 dev r1-eth1")

connected = "{}/{}/ip_route_connected.json".format(CWD, router.name)
expected = json.loads(open(connected).read())

test_func = partial(
topotest.router_json_cmp, router, "show ip route 192.168.44.0/24 json", expected
)
result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
assert result, "Connected Route should have been added\n{}".format(_)


def test_zebra_kernel_route_add():
"Test that a random kernel route is properly handled as expected"

tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

router = tgen.gears["r1"]
router.run("ip route add 4.5.6.7/32 dev r1-eth1")

kernel = "{}/{}/ip_route_kernel.json".format(CWD, router.name)
expected = json.loads(open(kernel).read())

test_func = partial(
topotest.router_json_cmp, router, "show ip route 4.5.6.7/32 json", expected
)
result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
assert result, "Connected Route should have been added\n{}".format(_)


def test_zebra_kernel_route_blackhole_add():
"Test that a blackhole route is not affected by interface's link change"

tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

router = tgen.gears["r1"]
router.run("ip route add blackhole default")
router.run("ip link set dev r1-eth1 down")

kernel = "{}/{}/ip_route_kernel_blackhole.json".format(CWD, router.name)
expected = json.loads(open(kernel).read())

test_func = partial(
topotest.router_json_cmp, router, "show ip route 0.0.0.0/0 json", expected
)
result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
assert result, "Blackhole Route should have not been removed\n{}".format(_)


>>>>>>> 0073a870d1 (test: add test case for kernel blackhole routes)
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))
40 changes: 40 additions & 0 deletions zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -4464,6 +4464,46 @@ static const char *rib_update_event2str(enum rib_update_event event)
return ret;
}

<<<<<<< HEAD
=======
/*
* We now keep kernel routes, but we don't have any
* trigger events for them when they are implicitly
* deleted. Since we are already walking the
* entire table on a down event let's look at
* the few kernel routes we may have
*/
static void
rib_update_handle_kernel_route_down_possibility(struct route_node *rn,
struct route_entry *re)
{
struct nexthop *nexthop = NULL;
bool alive = false;

for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) {
struct interface *ifp = if_lookup_by_index(nexthop->ifindex,
nexthop->vrf_id);

if ((ifp && if_is_up(ifp)) || nexthop->type == NEXTHOP_TYPE_BLACKHOLE) {
alive = true;
break;
}
}

if (!alive) {
struct rib_table_info *rib_table = srcdest_rnode_table_info(rn);
const struct prefix *p;
const struct prefix_ipv6 *src_p;

srcdest_rnode_prefixes(rn, &p, (const struct prefix **)&src_p);

rib_delete(rib_table->afi, rib_table->safi, re->vrf_id,
re->type, re->instance, re->flags, p, src_p, NULL, 0,
re->table, re->metric, re->distance, true);
}
}

>>>>>>> 44a82da405 (zebra: fix missing kernel routes)

/* Schedule route nodes to be processed if they match the type */
static void rib_update_route_node(struct route_node *rn, int type)
Expand Down
Loading