ping

On 2016 Oct 04 (Tue) at 14:41:15 +0200 (+0200), Peter Hessler wrote:
:On 2016 Oct 04 (Tue) at 14:28:43 +0200 (+0200), Peter Hessler wrote:
::This updates bgpq3 to the now-released 0.1.32 version.
:
:Here is a patch that adds OpenBGPD support to bgpq3, expects the above
:version.  I ignored adding support for as.dot notation (-D), and always
:set -3 (32bit asn).  I didn't add -M (match condition), but that is
:marked as a Juniper-only feature, and I implemented -l to create a macro
:named 'name'.
:
:We use -B to declare "OpenBGPD" output format, and I tested:
:
: <as>
: -l <name>
: -A <as>
: -f <asnum> <as>
: -G <asnum> <as>
: -R 32 <as>
:
:where <as> is either as-set or aut-num.
:
:OK?  (I will send to upstream once we like the output)
:
:
:Index: patches/patch-bgpq3_c
:===================================================================
:RCS file: patches/patch-bgpq3_c
:diff -N patches/patch-bgpq3_c
:--- /dev/null  1 Jan 1970 00:00:00 -0000
:+++ patches/patch-bgpq3_c      4 Oct 2016 11:16:52 -0000
:@@ -0,0 +1,50 @@
:+$OpenBSD$
:+--- bgpq3.c.orig      Wed Sep 23 18:29:08 2015
:++++ bgpq3.c   Tue Oct  4 13:16:40 2016
:+@@ -27,7 +27,7 @@ int
:+ usage(int ecode)
:+ {
:+      printf("\nUsage: bgpq3 [-h host[:port]] [-S sources] [-P|E|G <num>|f 
<num>]"
:+-             " [-2346AbDJjXd] [-R len] <OBJECTS>...\n");
:++             " [-2346AbBDJjXd] [-R len] <OBJECTS>...\n");
:+      printf(" -2        : allow routes belonging to as23456 (transition-as) "
:+              "(default: false)\n");
:+      printf(" -3        : assume that your device is asn32-safe\n");
:+@@ -36,6 +36,7 @@ usage(int ecode)
:+      printf(" -A        : try to aggregate Cisco prefix-lists or Juniper "
:+                      "route-filters\n             as much as possible\n");
:+      printf(" -b        : generate BIRD output (Cisco IOS by default)\n");
:++     printf(" -B        : generate OpenBGPD output (Cisco IOS by 
default)\n");
:+      printf(" -d        : generate some debugging output\n");
:+      printf(" -D        : use asdot notation in as-path (Cisco only)\n");
:+      printf(" -E        : generate extended access-list(Cisco) or "
:+@@ -81,7 +82,7 @@ exclusive()
:+ void
:+ vendor_exclusive()
:+ {
:+-     fprintf(stderr, "-b (BIRD), -F (formatted), -J (JunOS), -j (JSON) "
:++     fprintf(stderr, "-b (BIRD), -B (OpenBGPD), -F (formatted), -J (JunOS), 
-j (JSON) "
:+              "and -X (IOS XR) options are mutually exclusive\n");
:+      exit(1);
:+ };
:+@@ -134,7 +135,7 @@ main(int argc, char* argv[])
:+      if (getenv("IRRD_SOURCES"))
:+              expander.sources=getenv("IRRD_SOURCES");
:+ 
:+-     while((c=getopt(argc,argv,"2346AbdDEF:S:jJf:l:L:m:M:W:Ppr:R:G:Th:Xs"))
:++     while((c=getopt(argc,argv,"2346AbBdDEF:S:jJf:l:L:m:M:W:Ppr:R:G:Th:Xs"))
:+              !=EOF) {
:+      switch(c) {
:+              case '2':
:+@@ -167,6 +168,11 @@ main(int argc, char* argv[])
:+              case 'b':
:+                      if(expander.vendor) vendor_exclusive();
:+                      expander.vendor=V_BIRD;
:++                     break;
:++             case 'B':
:++                     if(expander.vendor) vendor_exclusive();
:++                     expander.vendor=V_OPENBGPD;
:++                     expander.asn32=1;
:+                      break;
:+              case 'd': debug_expander++;
:+                      break;
:Index: patches/patch-bgpq3_h
:===================================================================
:RCS file: patches/patch-bgpq3_h
:diff -N patches/patch-bgpq3_h
:--- /dev/null  1 Jan 1970 00:00:00 -0000
:+++ patches/patch-bgpq3_h      8 Jan 2016 17:52:43 -0000
:@@ -0,0 +1,11 @@
:+$OpenBSD$
:+--- bgpq3.h.orig      Fri Jan  8 18:52:16 2016
:++++ bgpq3.h   Fri Jan  8 18:52:39 2016
:+@@ -16,6 +16,7 @@ typedef enum {
:+      V_CISCO_XR,
:+      V_JSON,
:+      V_BIRD,
:++     V_OPENBGPD,
:+      V_FORMAT
:+ } bgpq_vendor_t;
:+ 
:Index: patches/patch-bgpq3_printer_c
:===================================================================
:RCS file: patches/patch-bgpq3_printer_c
:diff -N patches/patch-bgpq3_printer_c
:--- /dev/null  1 Jan 1970 00:00:00 -0000
:+++ patches/patch-bgpq3_printer_c      4 Oct 2016 11:34:36 -0000
:@@ -0,0 +1,159 @@
:+$OpenBSD$
:+--- bgpq3_printer.c.orig      Sun Aug 28 18:18:20 2016
:++++ bgpq3_printer.c   Tue Oct  4 13:34:25 2016
:+@@ -18,6 +18,7 @@ extern int debug_expander;
:+ 
:+ int bgpq3_print_json_aspath(FILE* f, struct bgpq_expander* b);
:+ int bgpq3_print_bird_aspath(FILE* f, struct bgpq_expander* b);
:++int bgpq3_print_openbgpd_aspath(FILE* f, struct bgpq_expander* b);
:+ 
:+ int
:+ bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b)
:+@@ -304,6 +305,25 @@ bgpq3_print_juniper_oaspath(FILE* f, struct bgpq_expan
:+ };
:+ 
:+ int
:++bgpq3_print_openbgpd_oaspath(FILE* f, struct bgpq_expander* b)
:++{
:++     int i, j, k;
:++
:++     for(k=0;k<65536;k++) {
:++             if(!b->asn32s[k]) continue;
:++
:++             for(i=0;i<8192;i++) {
:++                     for(j=0;j<8;j++) {
:++                             if(b->asn32s[k][i]&(0x80>>j)) {
:++                                     fprintf(f, "%s%u%s%u\n", "allow to AS 
", b->asnumber, " AS ", k*65536+i*8+j);
:++                             };
:++                     };
:++             };
:++     };
:++     return 0;
:++};
:++
:++int
:+ bgpq3_print_aspath(FILE* f, struct bgpq_expander* b)
:+ {
:+      if(b->vendor==V_JUNIPER) {
:+@@ -316,6 +336,8 @@ bgpq3_print_aspath(FILE* f, struct bgpq_expander* b)
:+              return bgpq3_print_json_aspath(f,b);
:+      } else if(b->vendor==V_BIRD) {
:+              return bgpq3_print_bird_aspath(f,b);
:++     } else if(b->vendor==V_OPENBGPD) {
:++             return bgpq3_print_openbgpd_aspath(f,b);
:+      } else {
:+              sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor);
:+      };
:+@@ -331,6 +353,8 @@ bgpq3_print_oaspath(FILE* f, struct bgpq_expander* b)
:+              return bgpq3_print_cisco_oaspath(f,b);
:+      } else if(b->vendor==V_CISCO_XR) {
:+              return bgpq3_print_cisco_xr_oaspath(f,b);
:++     } else if(b->vendor==V_OPENBGPD) {
:++             return bgpq3_print_openbgpd_oaspath(f,b);
:+      } else {
:+              sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor);
:+      };
:+@@ -472,6 +496,53 @@ bgpq3_print_bird_aspath(FILE* f, struct bgpq_expander*
:+ };
:+ 
:+ void
:++bgpq3_print_openbgpd_prefix(struct sx_radix_node* n, void* ff)
:++{
:++     char prefix[128];
:++     FILE* f=(FILE*)ff;
:++     if(n->isGlue)
:++             goto checkSon;
:++     if(!f)
:++             f=stdout;
:++     sx_prefix_snprintf(&n->prefix, prefix, sizeof(prefix));
:++     if (!n->isAggregate) {
:++             fprintf(f, "\n\t%s \\", prefix);
:++     } else if (n->aggregateLow == 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 \\",
:++                     prefix, n->aggregateLow, n->aggregateHi);
:++     } else {
:++             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);
:++};
:++
:++int
:++bgpq3_print_openbgpd_aspath(FILE* f, struct bgpq_expander* b)
:++{
:++     int i, j, k;
:++
:++     for(k=0;k<65536;k++) {
:++             if(!b->asn32s[k]) continue;
:++
:++             for(i=0;i<8192;i++) {
:++                     for(j=0;j<8;j++) {
:++                             if(b->asn32s[k][i]&(0x80>>j)) {
:++                                     fprintf(f, "%s%u%s%u\n", "allow from AS 
", b->asnumber, " AS ", k*65536+i*8+j);
:++                             };
:++                     };
:++             };
:++     };
:++     return 0;
:++};
:++
:++void
:+ bgpq3_print_jrfilter(struct sx_radix_node* n, void* ff)
:+ {
:+      char prefix[128];
:+@@ -658,7 +729,33 @@ bgpq3_print_juniper_routefilter(FILE* f, struct bgpq_e
:+      return 0;
:+ };
:+ 
:++
:+ int
:++bgpq3_print_openbgpd_prefixlist(FILE* f, struct bgpq_expander* b)
:++{
:++     if (!sx_radix_tree_empty(b->tree)) {
:++             if(b->name){
:++                     if(strcmp(b->name, "NN") != 0) {
:++                             fprintf(f, "%s=\"", b->name);
:++                     }
:++             }
:++             fprintf(f,"prefix { \\");
:++             sx_radix_tree_foreach(b->tree,bgpq3_print_openbgpd_prefix,f);
:++             fprintf(f, "\n\t}");
:++             if(b->name){
:++                     if(strcmp(b->name, "NN") != 0) {
:++                             fprintf(f, "\"");
:++                     }
:++             }
:++             fprintf(f, "\n");
:++     } else {
:++             fprintf(f, "# generated prefix-list %s (AS %u) is empty\n", 
bname, b->asnumber);
:++             fprintf(f, "deny from AS %u\n", b->asnumber);
:++     };
:++     return 0;
:++};
:++
:++int
:+ bgpq3_print_cisco_prefixlist(FILE* f, struct bgpq_expander* b)
:+ {
:+      bname=b->name ? b->name : "NN";
:+@@ -767,6 +864,7 @@ bgpq3_print_prefixlist(FILE* f, struct bgpq_expander* 
:+              case V_CISCO_XR: return bgpq3_print_ciscoxr_prefixlist(f,b);
:+              case V_JSON: return bgpq3_print_json_prefixlist(f,b);
:+              case V_BIRD: return bgpq3_print_bird_prefixlist(f,b);
:++             case V_OPENBGPD: return bgpq3_print_openbgpd_prefixlist(f,b);
:+              case V_FORMAT: return bgpq3_print_format_prefixlist(f,b);
:+      };
:+      return 0;
:+@@ -781,6 +879,7 @@ bgpq3_print_eacl(FILE* f, struct bgpq_expander* b)
:+              case V_CISCO_XR: sx_report(SX_FATAL, "unreachable point\n");
:+              case V_JSON: sx_report(SX_FATAL, "unreachable point\n");
:+              case V_BIRD: sx_report(SX_FATAL, "unreachable point\n");
:++             case V_OPENBGPD: return bgpq3_print_openbgpd_prefixlist(f,b);
:+              case V_FORMAT: sx_report(SX_FATAL, "unreachable point\n");
:+      };
:+      return 0;
:
:
:-- 
:Never let your sense of morals prevent you from doing what is right.
:               -- Salvor Hardin, "Foundation"
:

-- 
New systems generate new problems.

Reply via email to