Skip to content

Commit

Permalink
zebra: Add ability to pretend routes are offloaded
Browse files Browse the repository at this point in the history
In the fpm_listener add a -r option to allow for
routes to be notified back to zebra that the route
has been `offloaded` properly.

fpm_listener output:
New route 4.5.6.7/32, Prot: Static(196), Metric: 20, nhgid: 23
  Route Static(196) reflecting back
FPM message - Type: 1, Length 56
New route 169.254.0.0/16, Prot: Kernel(2), Metric: 20, nhgid: 2
FPM message - Type: 1, Length 56
New route 192.168.99.0/24, Prot: Kernel(2), Metric: 20, nhgid: 42
FPM message - Type: 1, Length 56
New route 192.168.99.1/32, Prot: Kernel(2), Metric: 20, nhgid: 42
FPM message - Type: 1, Length 56
New route 192.168.119.0/24, Prot: OSPF(188), Metric: 20, nhgid: 20
  Route OSPF(188) reflecting back

Zebra output:

2024-03-06 21:48:54.613 [DEBG] zebra: [TJXPZ-RC5XQ] default(0:254):4.5.6.7/32 Processing dplane notif ctx 0x7160b4008780
2024-03-06 21:48:54.613 [DEBG] zebra: [TJXPZ-RC5XQ] default(0:254):192.168.119.0/24 Processing dplane notif ctx 0x7160b4008780

eva# show ip route 4.5.6.7 json
{
  "4.5.6.7/32":[
    {
      "prefix":"4.5.6.7/32",
      "prefixLen":32,
      "protocol":"static",
      "vrfId":0,
      "vrfName":"default",
      "selected":true,
      "destSelected":true,
      "distance":1,
      "metric":0,
      "installed":true,
      "offloaded":true,
....

and

eva# show ip route 192.168.119.0 json
{
  "192.168.119.0/24":[
    {
      "prefix":"192.168.119.0/24",
      "prefixLen":24,
      "protocol":"ospf",
      "vrfId":0,
      "vrfName":"default",
      "selected":true,
      "destSelected":true,
      "distance":110,
      "metric":100,
      "installed":true,
      "offloaded":true,
...

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Mar 7, 2024
1 parent 40288e1 commit 5e09014
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions zebra/fpm_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
struct glob {
int server_sock;
int sock;
bool reflect;
};

struct glob glob_space;
Expand Down Expand Up @@ -526,11 +527,12 @@ static int netlink_msg_ctx_snprint(struct netlink_msg_ctx *ctx, char *buf,
cur = buf;
end = buf + buf_len;

cur += snprintf(cur, end - cur, "%s %s/%d, Prot: %s",
cur += snprintf(cur, end - cur, "%s %s/%d, Prot: %s(%u)",
netlink_msg_type_to_s(hdr->nlmsg_type),
addr_to_s(rtmsg->rtm_family, RTA_DATA(ctx->dest)),
rtmsg->rtm_dst_len,
netlink_prot_to_s(rtmsg->rtm_protocol));
netlink_prot_to_s(rtmsg->rtm_protocol),
rtmsg->rtm_protocol);

if (ctx->metric)
cur += snprintf(cur, end - cur, ", Metric: %d", *ctx->metric);
Expand Down Expand Up @@ -570,8 +572,7 @@ static void print_netlink_msg_ctx(struct netlink_msg_ctx *ctx)
/*
* parse_netlink_msg
*/
static void
parse_netlink_msg(char *buf, size_t buf_len)
static void parse_netlink_msg(char *buf, size_t buf_len, fpm_msg_hdr_t *fpm)
{
struct netlink_msg_ctx ctx_space, *ctx;
struct nlmsghdr *hdr;
Expand Down Expand Up @@ -599,6 +600,16 @@ parse_netlink_msg(char *buf, size_t buf_len)
}

print_netlink_msg_ctx(ctx);

if (glob->reflect && hdr->nlmsg_type == RTM_NEWROUTE &&
ctx->rtmsg->rtm_protocol > RTPROT_STATIC) {
printf(" Route %s(%u) reflecting back\n",
netlink_prot_to_s(
ctx->rtmsg->rtm_protocol),
ctx->rtmsg->rtm_protocol);
ctx->rtmsg->rtm_flags |= RTM_F_OFFLOAD;
write(glob->sock, fpm, fpm_msg_len(fpm));
}
break;

default:
Expand All @@ -623,7 +634,7 @@ static void process_fpm_msg(fpm_msg_hdr_t *hdr)
return;
}

parse_netlink_msg(fpm_msg_data(hdr), fpm_msg_data_len(hdr));
parse_netlink_msg(fpm_msg_data(hdr), fpm_msg_data_len(hdr), hdr);
}

/*
Expand All @@ -648,6 +659,13 @@ int main(int argc, char **argv)
{
pid_t daemon;
int d;
int r;

memset(glob, 0, sizeof(*glob));

r = getopt(argc, argv, "r");
if (r == 'r')
glob->reflect = true;

d = getopt(argc, argv, "d");
if (d == 'd') {
Expand All @@ -657,8 +675,6 @@ int main(int argc, char **argv)
exit(0);
}

memset(glob, 0, sizeof(*glob));

if (!create_listen_sock(FPM_DEFAULT_PORT, &glob->server_sock))
exit(1);

Expand Down

0 comments on commit 5e09014

Please sign in to comment.