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.

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Mar 7, 2024
1 parent 40288e1 commit 2771431
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 2771431

Please sign in to comment.