Skip to content

Commit

Permalink
Add sequence numbers for FRRouting prefix-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
peterablehmann committed Feb 23, 2025
1 parent ae0a968 commit b18eb66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bgpq4.8
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ allow more specific routes starting with specified masklen too.
.It Fl R Ar len
allow more specific routes up to specified masklen too.
.It Fl s
generate sequence numbers in IOS-style prefix-lists.
generate sequence numbers in prefix-lists (IOS, EOS and FRRouting only).
.It Fl S Ar sources
use specified sources only (recommended: RPKI,AFRINIC,APNIC,ARIN,LACNIC,RIPE).
.It Fl t
Expand Down
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ usage(int ecode)
printf(" -p : allow special ASNs like 23456 or in the private range\n");
printf(" -R len : allow more specific routes up to specified masklen\n");
printf(" -r len : allow more specific routes from masklen specified\n");
printf(" -s : generate sequence numbers in prefix-lists (IOS only)\n");
printf(" -s : generate sequence numbers in prefix-lists (IOS, EOS and FRRouting only)\n");
printf(" -t : generate as-sets for OpenBGPD (OpenBGPD 6.4+), BIRD "
"and JSON formats\n");
printf(" -z : generate route-filter-list (Junos only)\n");
Expand Down Expand Up @@ -619,9 +619,9 @@ main(int argc, char* argv[])
}

if (expander.sequence
&& (expander.vendor != V_CISCO && expander.vendor != V_ARISTA)) {
&& (expander.vendor != V_CISCO && expander.vendor != V_ARISTA && expander.vendor != V_FRR)) {
sx_report(SX_FATAL, "Sorry, prefix-lists sequencing (-s) supported"
" only for IOS and EOS\n");
" only for IOS, EOS and FRRouting\n");
exit(1);
}

Expand Down
18 changes: 11 additions & 7 deletions printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ bgpq4_print_eprefix(struct sx_radix_node *n, void *ff)
static void
bgpq4_print_frr_prefix(struct sx_radix_node *n, void *ff)
{
char prefix[128];
char prefix[128], seqno[16] = "";
FILE *f = (FILE*)ff;

if (!f)
Expand All @@ -1198,18 +1198,21 @@ bgpq4_print_frr_prefix(struct sx_radix_node *n, void *ff)

sx_prefix_snprintf(n->prefix, prefix, sizeof(prefix));

if (seq)
snprintf(seqno, sizeof(seqno), " seq %i", seq++);

if (n->isAggregate) {
if (n->aggregateLow > n->prefix->masklen) {
fprintf(f,"ip prefix-list %s permit %s ge %u le %u\n",
bname ? bname : "NN", prefix,
fprintf(f,"ip prefix-list %s%s permit %s ge %u le %u\n",
bname ? bname : "NN", seqno, prefix,
n->aggregateLow, n->aggregateHi);
} else {
fprintf(f,"ip prefix-list %s permit %s le %u\n",
bname?bname:"NN", prefix, n->aggregateHi);
fprintf(f,"ip prefix-list %s%s permit %s le %u\n",
bname?bname:"NN", seqno, prefix, n->aggregateHi);
}
} else {
fprintf(f,"ip prefix-list %s permit %s\n",
bname ? bname : "NN", prefix);
fprintf(f,"ip prefix-list %s%s permit %s\n",
bname ? bname : "NN", seqno, prefix);
}

checkSon:
Expand Down Expand Up @@ -1937,6 +1940,7 @@ static void
bgpq4_print_frr_prefixlist(FILE *f, struct bgpq_expander *b)
{
bname = b->name ? b->name : "NN";
seq = b->sequence;

if (!sx_radix_tree_empty(b->tree)) {
sx_radix_tree_foreach(b->tree, bgpq4_print_frr_prefix, f);
Expand Down

0 comments on commit b18eb66

Please sign in to comment.