Skip to content

Commit

Permalink
lib, zebra: Add ability to read kernel notice of TRAP/OFFLOAD
Browse files Browse the repository at this point in the history
The linux kernel is getting RTM_F_TRAP and RTM_F_OFFLOAD for
kernel routes that have an underlying asic offload.  Write the
code to receive these notifications from the linux kernel and
to store that data for display about the routes.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed Sep 22, 2020
1 parent 4c56ce1 commit 5a3cf85
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/route_types.pl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ sub codelist {
}
$str =~ s/ $//;
push @lines, $str . "\\n\" \\\n";
push @lines, " \" > - selected route, * - FIB route, q - queued, r - rejected, b - backup\\n\\n\"";
push @lines, " \" > - selected route, * - FIB route, q - queued, r - rejected, b - backup\\n\"";
push @lines, " \" t - trapped, o - offload failure\\n\"";


return join("", @lines);
}

Expand Down
14 changes: 14 additions & 0 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,20 @@ struct zapi_route {
* route entry. This mainly is used for backup static routes.
*/
#define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
/*
* This flag tells everyone that the route was intentionally
* not offloaded and the route will be sent to the cpu for
* forwarding. This flag makes no sense unless you are in
* an asic offload situation
*/
#define ZEBRA_FLAG_TRAPPED 0x80
/*
* This flag tells everyone that the route has been
* successfully offloaded to an asic for forwarding.
* This flag makes no sense unless you are in an asic
* offload situation.
*/
#define ZEBRA_FLAG_OFFLOADED 0x100

/* The older XXX_MESSAGE flags live here */
uint32_t message;
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/lib/topotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def ip4_route_zebra(node, vrf_name=None):
lines = output.splitlines()
header_found = False
while lines and (not lines[0].strip() or not header_found):
if "> - selected route" in lines[0]:
if "o - offload failure" in lines[0]:
header_found = True
lines = lines[1:]
return "\n".join(lines)
Expand All @@ -654,7 +654,7 @@ def ip6_route_zebra(node, vrf_name=None):
lines = output.splitlines()
header_found = False
while lines and (not lines[0].strip() or not header_found):
if "> - selected route" in lines[0]:
if "o - offload failure" in lines[0]:
header_found = True
lines = lines[1:]

Expand Down
5 changes: 5 additions & 0 deletions zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
return 0;
}

if (rtm->rtm_flags & RTM_F_TRAP)
flags |= ZEBRA_FLAG_TRAPPED;
if (rtm->rtm_flags & RTM_F_OFFLOAD)
flags |= ZEBRA_FLAG_OFFLOADED;

/* Route which inserted by Zebra. */
if (selfroute) {
flags |= ZEBRA_FLAG_SELFROUTE;
Expand Down
14 changes: 14 additions & 0 deletions zebra/zebra_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ static char re_status_output_char(const struct route_entry *re,
star_p = true;
}

if (zrouter.asic_offloaded
&& CHECK_FLAG(re->flags, ZEBRA_FLAG_TRAPPED))
return 't';

if (zrouter.asic_offloaded
&& !CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED))
return 'o';

if (star_p)
return '*';
else
Expand Down Expand Up @@ -862,6 +870,12 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
if (CHECK_FLAG(re->status, ROUTE_ENTRY_QUEUED))
json_object_boolean_true_add(json_route, "queued");

if (CHECK_FLAG(re->flags, ZEBRA_FLAG_TRAPPED))
json_object_boolean_true_add(json_route, "trapped");

if (CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED))
json_object_boolean_true_add(json_route, "offloaded");

if (re->tag)
json_object_int_add(json_route, "tag", re->tag);

Expand Down

0 comments on commit 5a3cf85

Please sign in to comment.