From: Donald Sharp Date: Wed, 19 Mar 2025 16:22:04 +0000 (-0400) Subject: zebra: Allow fpm_listener to reject all routes X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=04d6adc94bfebde195a7ff245388d7e8d5e6d563;p=matthieu%2Ffrr.git zebra: Allow fpm_listener to reject all routes Now usage of `-r -f` with fpm_listener now causes all routes to be rejected. r1# sharp install routes 10.0.0.0 nexthop 192.168.44.5 5 r1# show ip route Codes: K - kernel route, C - connected, L - local, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, t - Table-Direct, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure IPv4 unicast VRF default: D>o 10.0.0.0/32 [150/0] via 192.168.44.5, r1-eth0, weight 1, 00:00:02 D>o 10.0.0.1/32 [150/0] via 192.168.44.5, r1-eth0, weight 1, 00:00:02 D>o 10.0.0.2/32 [150/0] via 192.168.44.5, r1-eth0, weight 1, 00:00:02 D>o 10.0.0.3/32 [150/0] via 192.168.44.5, r1-eth0, weight 1, 00:00:02 D>o 10.0.0.4/32 [150/0] via 192.168.44.5, r1-eth0, weight 1, 00:00:02 C>* 192.168.44.0/24 is directly connected, r1-eth0, weight 1, 00:00:37 L>* 192.168.44.1/32 is directly connected, r1-eth0, weight 1, 00:00:37 r1# Signed-off-by: Donald Sharp --- diff --git a/zebra/fpm_listener.c b/zebra/fpm_listener.c index 43ca6e47b8..00c3c3e6f5 100644 --- a/zebra/fpm_listener.c +++ b/zebra/fpm_listener.c @@ -43,6 +43,7 @@ struct glob { int server_sock; int sock; bool reflect; + bool reflect_fail_all; bool dump_hex; FILE *output_file; }; @@ -711,10 +712,14 @@ static void parse_netlink_msg(char *buf, size_t buf_len, fpm_msg_hdr_t *fpm) if (glob->reflect && hdr->nlmsg_type == RTM_NEWROUTE && ctx->rtmsg->rtm_protocol > RTPROT_STATIC) { - fprintf(glob->output_file, " Route %s(%u) reflecting back\n", + fprintf(glob->output_file, " Route %s(%u) reflecting back as %s\n", netlink_prot_to_s(ctx->rtmsg->rtm_protocol), - ctx->rtmsg->rtm_protocol); - ctx->rtmsg->rtm_flags |= RTM_F_OFFLOAD; + ctx->rtmsg->rtm_protocol, + glob->reflect_fail_all ? "Offload Failed" : "Offloaded"); + if (glob->reflect_fail_all) + ctx->rtmsg->rtm_flags |= RTM_F_OFFLOAD_FAILED; + else + ctx->rtmsg->rtm_flags |= RTM_F_OFFLOAD; write(glob->sock, fpm, fpm_msg_len(fpm)); } break; @@ -772,11 +777,14 @@ int main(int argc, char **argv) memset(glob, 0, sizeof(*glob)); glob->output_file = stdout; - while ((r = getopt(argc, argv, "rdvo:")) != -1) { + while ((r = getopt(argc, argv, "rfdvo:")) != -1) { switch (r) { case 'r': glob->reflect = true; break; + case 'f': + glob->reflect_fail_all = true; + break; case 'd': fork_daemon = true; break;