Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for FRRouting IP prefix lists #126

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bgpq4.8
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ generate output in BIRD format (default: Cisco).
enable some debugging output.
.It Fl e
generate output in Arista EOS format (default: Cisco).
.It Fl Z
generate output in FRRouting format (default: Cisco).
.It Fl E
generate extended access-list (Cisco), policy-statement term using
route-filters (Juniper), [ip|ipv6]-prefix-list (Nokia) or prefix-sets
Expand Down Expand Up @@ -121,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
1 change: 1 addition & 0 deletions extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef enum {
V_NOKIA_MD,
V_ARISTA,
V_NOKIA_SRL,
V_FRR,
} bgpq_vendor_t;

typedef enum {
Expand Down
14 changes: 10 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ usage(int ecode)
printf(" -n2 : Nokia SR Linux\n");
printf(" -B : OpenBSD OpenBGPD\n");
printf(" -e : Arista EOS\n");
printf(" -Z : FRRouting\n");
printf(" -F fmt : User defined format (example: '-F %%n/%%l')\n");

printf("\nInput filters:\n");
Expand Down Expand Up @@ -97,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 @@ -201,7 +202,7 @@ main(int argc, char* argv[])
expander.sources=getenv("IRRD_SOURCES");

while ((c = getopt(argc, argv,
"23467a:AbBdDEeF:S:jJKf:l:L:m:M:NnpW:r:R:G:H:tTh:UuwXsvz")) != EOF) {
"23467a:AbBdDEeF:S:jJKf:l:L:m:M:NnpW:r:R:G:H:tTh:UuwXsvZz")) != EOF) {
switch (c) {
case '2':
if (expander.vendor != V_NOKIA_MD) {
Expand Down Expand Up @@ -458,6 +459,11 @@ main(int argc, char* argv[])
exclusive();
expander.generation = T_ROUTE_FILTER_LIST;
break;
case 'Z':
if (expander.vendor)
vendor_exclusive();
expander.vendor = V_FRR;
break;
default:
usage(1);
}
Expand Down Expand Up @@ -613,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
52 changes: 52 additions & 0 deletions printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,42 @@ bgpq4_print_eprefix(struct sx_radix_node *n, void *ff)
bgpq4_print_eprefix(n->son, ff);
}

static void
bgpq4_print_frr_prefix(struct sx_radix_node *n, void *ff)
{
char prefix[128], seqno[16] = "";
FILE *f = (FILE*)ff;

if (!f)
f = stdout;

if (n->isGlue)
goto checkSon;

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%s permit %s ge %u le %u\n",
bname ? bname : "NN", seqno, prefix,
n->aggregateLow, n->aggregateHi);
} else {
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%s permit %s\n",
bname ? bname : "NN", seqno, prefix);
}

checkSon:
if (n->son)
bgpq4_print_frr_prefix(n->son, ff);
}

static void
bgpq4_print_ceacl(struct sx_radix_node *n, void *ff)
{
Expand Down Expand Up @@ -1900,6 +1936,19 @@ bgpq4_print_mikrotik_prefixlist(FILE *f, struct bgpq_expander *b)
}
}

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);
} else {
fprintf(f, "# generated prefix-list %s is empty\n", bname);
}
}

void
bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b)
{
Expand Down Expand Up @@ -1947,6 +1996,9 @@ bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b)
case V_ARISTA:
bgpq4_print_arista_prefixlist(f, b);
break;
case V_FRR:
bgpq4_print_frr_prefixlist(f, b);
break;
}
}

Expand Down