From bbda06abd3bf8bed042c120bf1ced62355f5062f Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Sun, 9 Sep 2018 09:31:42 +0200 Subject: [PATCH 1/2] Simplify the printer for OpenBGPD. In most cases there is no need for line continuations with '\' --- bgpq3_printer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bgpq3_printer.c b/bgpq3_printer.c index cc9a5a0..caeae65 100644 --- a/bgpq3_printer.c +++ b/bgpq3_printer.c @@ -691,17 +691,16 @@ bgpq3_print_openbgpd_prefix(struct sx_radix_node* n, void* ff) f=stdout; sx_prefix_snprintf(&n->prefix, prefix, sizeof(prefix)); if (!n->isAggregate) { - fprintf(f, "\n\t%s \\", prefix); + fprintf(f, "\n\t%s", prefix); } else if (n->aggregateLow == n->aggregateHi) { - fprintf(f, "\n\t%s prefixlen = %u \\", prefix, n->aggregateHi); + fprintf(f, "\n\t%s prefixlen = %u", prefix, n->aggregateHi); } else if (n->aggregateLow > n->prefix.masklen) { - fprintf(f, "\n\t%s prefixlen %u - %u \\", + fprintf(f, "\n\t%s prefixlen %u - %u", prefix, n->aggregateLow, n->aggregateHi); } else { - fprintf(f, "\n\t%s prefixlen %u - %u \\", + fprintf(f, "\n\t%s prefixlen %u - %u", prefix, n->prefix.masklen, n->aggregateHi); }; - needscomma=1; checkSon: if(n->son) bgpq3_print_openbgpd_prefix(n->son, ff); @@ -1010,7 +1009,7 @@ bgpq3_print_openbgpd_prefixlist(FILE* f, struct bgpq_expander* b) fprintf(f, "%s=\"", b->name); } } - fprintf(f,"prefix { \\"); + fprintf(f,"prefix { "); sx_radix_tree_foreach(b->tree,bgpq3_print_openbgpd_prefix,f); fprintf(f, "\n\t}"); if(b->name){ @@ -1037,9 +1036,9 @@ bgpq3_print_openbgpd_prefixset(FILE* f, struct bgpq_expander* b) "instead of this list\n"); }; if (!sx_radix_tree_empty(b->tree) || !b->asnumber) { - fprintf(f,"prefix-set %s { \\", b->name); + fprintf(f,"prefix-set %s {", b->name); sx_radix_tree_foreach(b->tree,bgpq3_print_openbgpd_prefix,f); - fprintf(f, "\n\t}\n"); + fprintf(f, "\n}\n"); } else { fprintf(f, "deny from AS %u\n", b->asnumber); }; From caf01e414315dc0f4d139d0c6c7bebc8aee4c368 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Sun, 9 Sep 2018 10:29:08 +0200 Subject: [PATCH 2/2] prefix-sets can be empty and they work just fine so no need to special case this in -E mode. --- bgpq3_printer.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/bgpq3_printer.c b/bgpq3_printer.c index caeae65..848af74 100644 --- a/bgpq3_printer.c +++ b/bgpq3_printer.c @@ -1028,24 +1028,13 @@ int bgpq3_print_openbgpd_prefixset(FILE* f, struct bgpq_expander* b) { bname=b->name ? b->name : "NN"; - if (sx_radix_tree_empty(b->tree)) { - fprintf(f, "# generated prefix-set %s (AS %u) is empty\n", bname, - b->asnumber); - if (!b->asnumber) - fprintf(f, "# use -a to generate \"deny from ASN \" " - "instead of this list\n"); - }; - if (!sx_radix_tree_empty(b->tree) || !b->asnumber) { - fprintf(f,"prefix-set %s {", b->name); + fprintf(f,"prefix-set %s {", b->name); + if (!sx_radix_tree_empty(b->tree)) sx_radix_tree_foreach(b->tree,bgpq3_print_openbgpd_prefix,f); - fprintf(f, "\n}\n"); - } else { - fprintf(f, "deny from AS %u\n", b->asnumber); - }; + fprintf(f, "\n}\n"); return 0; }; - int bgpq3_print_cisco_prefixlist(FILE* f, struct bgpq_expander* b) {