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
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_RTBRICK,
} bgpq_vendor_t;

typedef enum {
Expand Down
13 changes: 12 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,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:UuwXxsvz")) != EOF) {
switch (c) {
case '2':
if (expander.vendor != V_NOKIA_MD) {
Expand Down Expand Up @@ -450,6 +450,11 @@ main(int argc, char* argv[])
vendor_exclusive();
expander.vendor = V_CISCO_XR;
break;
case 'x':
if (expander.vendor)
vendor_exclusive();
expander.vendor = V_RTBRICK;
break;
case 'v':
version();
break;
Expand Down Expand Up @@ -541,6 +546,12 @@ main(int argc, char* argv[])
"supported for JSON output\n");
}

if (expander.vendor == V_RTBRICK
&& expander.generation != T_PREFIXLIST) {
sx_report(SX_FATAL, "Sorry, only prefix-lists "
"supported for RtBrick output\n");
}

if (expander.vendor == V_FORMAT
&& expander.generation != T_PREFIXLIST)
sx_report(SX_FATAL, "Sorry, only prefix-lists supported in formatted "
Expand Down
72 changes: 67 additions & 5 deletions printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "sx_report.h"

extern int debug_expander;
static int needscomma = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of a global variable, can you use a function-scope-specific int nc (like other printer functions do)?


#define max(a,b) \
({ \
Expand Down Expand Up @@ -662,8 +663,6 @@ bgpq4_print_jprefix(struct sx_radix_node *n, void *ff)
fprintf(f," %s;\n", prefix);
}

static int needscomma = 0;

static void
bgpq4_print_json_prefix(struct sx_radix_node *n, void *ff)
{
Expand Down Expand Up @@ -1410,13 +1409,13 @@ bgpq4_print_nokia_srl_prefix(struct sx_radix_node *n, void *ff)
typedef struct {
FILE *f;
int seq;
} NOKIA_SRL_IPFILTER_PARAMS;
} SEQUENCE_NUMBER_PARAMS;

static void
bgpq4_print_nokia_srl_ipfilter(struct sx_radix_node *n, void *ff)
{
char prefix[128];
NOKIA_SRL_IPFILTER_PARAMS *params = (NOKIA_SRL_IPFILTER_PARAMS*) ff;
SEQUENCE_NUMBER_PARAMS *params = (SEQUENCE_NUMBER_PARAMS*) ff;

if (n->isGlue)
goto checkSon;
Expand Down Expand Up @@ -1547,6 +1546,66 @@ bgpq4_print_cisco_prefixlist(FILE *f, struct bgpq_expander *b)
}
}


static void
bgpq4_print_rtbrickrefix(struct sx_radix_node *n, void *ff)
{
char prefix[128];
SEQUENCE_NUMBER_PARAMS *params = (SEQUENCE_NUMBER_PARAMS *) ff;

if (n->isGlue)
goto checkSon;

if (!params->f)
params->f = stdout;

sx_prefix_snprintf(n->prefix, prefix, sizeof(prefix));
fprintf(params->f, "%s\n", needscomma ? "," : "");
fprintf(params->f, " {\n");
fprintf(params->f, " \"ordinal\": %d,\n", params->seq);
fprintf(params->f, " \"value\": \"%s\"\n", prefix);
fprintf(params->f, " }");

params->seq += 1;
needscomma = 1;

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


}


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

fprintf(f, "{\n");
fprintf(f, " \"ietf-restconf:data\": {\n");
fprintf(f, " \"rtbrick-config:policy\": {\n");
fprintf(f, " \"list\": [\n");
fprintf(f, " {\n");
fprintf(f, " \"name\": \"%s\",\n", bname);
fprintf(f, " \"type\": \"%s-prefix\",\n",
b->family == AF_INET ? "ipv4" : "ipv6");
fprintf(f, " \"ordinal\": [");

if (!sx_radix_tree_empty(b->tree)) {
SEQUENCE_NUMBER_PARAMS params = { f, 1 };
sx_radix_tree_foreach(b->tree, bgpq4_print_rtbrickrefix, &params);
}

fprintf(f, "\n ]\n");
fprintf(f, " }\n");
fprintf(f, " ]\n");
fprintf(f, " }\n");
fprintf(f, " }\n");
fprintf(f, "}\n");
}

static void
bgpq4_print_ciscoxr_prefixlist(FILE *f, struct bgpq_expander *b)
{
Expand Down Expand Up @@ -1810,7 +1869,7 @@ bgpq4_print_nokia_srl_aclipfilter(FILE *f, struct bgpq_expander *b)
b->tree->family == AF_INET ? '4' : '6', bname);

if (!sx_radix_tree_empty(b->tree)) {
NOKIA_SRL_IPFILTER_PARAMS params = { f, 10 };
SEQUENCE_NUMBER_PARAMS params = { f, 10 };
sx_radix_tree_foreach(b->tree, bgpq4_print_nokia_srl_ipfilter, &params);
} else {
fprintf(f,"# generated ipv%c-filter '%s' is empty\n",
Expand Down Expand Up @@ -1947,6 +2006,9 @@ bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b)
case V_ARISTA:
bgpq4_print_arista_prefixlist(f, b);
break;
case V_RTBRICK:
bgpq4_print_rtbrick_prefixlist(f, b);
break;
}
}

Expand Down