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 <[email protected]>
  • Loading branch information
donaldsharp authored and ton31337 committed Mar 13, 2024
1 parent 4676c23 commit cca4bb6
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 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 @@ -647,18 +658,29 @@ static void fpm_serve(void)
int main(int argc, char **argv)
{
pid_t daemon;
int d;
int r;
bool fork_daemon = false;

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

d = getopt(argc, argv, "d");
if (d == 'd') {
while ((r = getopt(argc, argv, "rd")) != -1) {
switch (r) {
case 'r':
glob->reflect = true;
break;
case 'd':
fork_daemon = true;
break;
}
}

if (fork_daemon) {
daemon = fork();

if (daemon)
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 cca4bb6

Please sign in to comment.