Skip to content
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
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.deps/
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
bgpq4
compat/.deps/
compat/.libs/
compat/Makefile
compat/Makefile.in
compat/libcompat.la
compat/strlcpy.lo
compat/strlcpy.o
compile
config.guess
config.log
config.status
config.sub
configure
depcomp
expander.o
include/Makefile
include/Makefile.in
install-sh
libtool
ltmain.sh
m4/
main.o
missing
printer.o
sx_prefix.o
sx_report.o
sx_slentry.o
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ It's options are as follows:

> generate output in Arista EOS format (default: Cisco).

**-V**

> generate output in VyOS format (default: Cisco).

**-E**

> generate extended access-list (Cisco), policy-statement term using
Expand Down
2 changes: 2 additions & 0 deletions 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 V
generate output in VyOS 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
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_VYOS,
} bgpq_vendor_t;

typedef enum {
Expand Down
10 changes: 8 additions & 2 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(" -V : VyOS\n");
printf(" -F fmt : User defined format (example: '-F %%n/%%l')\n");

printf("\nInput filters:\n");
Expand Down Expand Up @@ -139,7 +140,7 @@ vendor_exclusive(void)
fprintf(stderr, "-b (BIRD), -B (OpenBGPD), -F (formatted), -J (Junos),"
" -j (JSON), -K[7] (Microtik ROS), -N (Nokia SR OS Classic),"
" -n (Nokia SR OS MD-CLI), -U (Huawei), -u (Huawei XPL),"
"-e (Arista) and -X (IOS XR) options are mutually exclusive\n");
" -e (Arista), -X (IOS XR) and -V (VyOS) options are mutually exclusive\n");
exit(1);
}

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:UuwXsVvz")) != EOF) {
switch (c) {
case '2':
if (expander.vendor != V_NOKIA_MD) {
Expand Down Expand Up @@ -453,6 +454,11 @@ main(int argc, char* argv[])
case 'v':
version();
break;
case 'V':
if (expander.vendor)
vendor_exclusive();
expander.vendor = V_VYOS;
break;
case 'z':
if (expander.generation)
exclusive();
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,44 @@ bgpq4_print_eprefix(struct sx_radix_node *n, void *ff)
bgpq4_print_eprefix(n->son, ff);
}

static void
bgpq4_print_vyos_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), "%i", seq++);
} else {
seq = 1;
snprintf(seqno, sizeof(seqno), "%i", seq);
}

fprintf(f, "set rule %s action 'permit'\n", seqno);
fprintf(f, "set rule %s prefix '%s'\n", seqno, prefix);

if (n->isAggregate) {
if (n->aggregateLow > n->prefix->masklen) {
fprintf(f, "set rule %s ge '%u'\n", seqno, n->aggregateLow);
fprintf(f, "set rule %s le '%u'\n", seqno, n->aggregateHi);
} else {
fprintf(f, "set rule %s le '%u'\n", seqno, n->aggregateHi);
}
}

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

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

static void
bgpq4_print_vyos_prefixlist(FILE *f, struct bgpq_expander *b)
{
bname = b->name ? b->name : "NN";

fprintf(f,"delete policy prefix-list%s %s\n", b->family == AF_INET ? "" : "6", bname);
fprintf(f,"edit policy prefix-list%s %s\n", b->family == AF_INET ? "" : "6", bname);
sx_radix_tree_foreach(b->tree, bgpq4_print_vyos_prefix, f);
fprintf(f,"exit\ncommit\n");
}

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_VYOS:
bgpq4_print_vyos_prefixlist(f, b);
break;
}
}

Expand Down