From 2cf7024eac82877cfbf2787acb5d35109367b636 Mon Sep 17 00:00:00 2001 From: Alexandre Snarskii Date: Wed, 1 Jul 2015 18:29:50 +0300 Subject: [PATCH] -s option is back again, for prefix-lists --- CHANGES | 6 +++++- README.md | 6 +++++- bgpq3.8 | 2 ++ bgpq3.c | 17 ++++++++++++++++- bgpq3.h | 1 + bgpq3_printer.c | 23 ++++++++++++++--------- configure | 18 +++++++++--------- configure.in | 2 +- 8 files changed, 53 insertions(+), 22 deletions(-) diff --git a/CHANGES b/CHANGES index 008a0c7..b7747e1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ -0.1.32-rc2 (2015-06-28) +0.1.32-rc3 (2015-07-01) + - feature: option -s can be used to generate sequence numbers in IOS + prefix-lists + +0.1.32-rc2 (2015-07-01) - bugfix: when no sources provided in command line and via IRRD_SOURCES env, no source limitation were sent to IRRd. Thanks to Mikhail A. Grishin. diff --git a/README.md b/README.md index 66fc140..8decbd8 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ SYNOPSIS -------- ``` - bgpq3 [-h host] [-S sources] [-EP] [-f asn | -G asn] [-2346AbDdJjpX] [-r len] [-R len] [-m max] [-W len] OBJECTS [...] + bgpq3 [-h host] [-S sources] [-EP] [-f asn | -G asn] [-2346AbDdJjpsX] [-r len] [-R len] [-m max] [-W len] OBJECTS [...] ``` DESCRIPTION @@ -104,6 +104,10 @@ Allow more-specific routes with masklen starting with specified length. Allow more-specific routes up to specified masklen too. (Please, note: objects with prefix-length greater than specified length will be always allowed.) +#### -s + +Generate sequence numbers in IOS-style prefix-lists. + #### -S `sources` Use specified sources only (default: RADB,RIPE,APNIC). diff --git a/bgpq3.8 b/bgpq3.8 index 09532bf..75e3815 100644 --- a/bgpq3.8 +++ b/bgpq3.8 @@ -93,6 +93,8 @@ generate prefix-list (default, backward compatibility). 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. .It Fl S Ar sources use specified sources only (default: RADB,RIPE,APNIC). .It Fl T diff --git a/bgpq3.c b/bgpq3.c index 2265348..a379b22 100644 --- a/bgpq3.c +++ b/bgpq3.c @@ -54,6 +54,7 @@ usage(int ecode) " compatibility)\n"); printf(" -r len : allow more specific routes from masklen specified\n"); printf(" -R len : allow more specific routes up to specified masklen\n"); + printf(" -s : generate sequence numbers in prefix-lists (IOS only)\n"); printf(" -S sources: use only specified sources (default:" " RADB,RIPE,APNIC)\n"); printf(" -T : disable pipelining (experimental, faster mode)\n"); @@ -129,7 +130,7 @@ main(int argc, char* argv[]) if (getenv("IRRD_SOURCES")) expander.sources=getenv("IRRD_SOURCES"); - while((c=getopt(argc,argv,"2346AbdDES:jJf:l:m:M:W:Ppr:R:G:Th:X"))!=EOF) { + while((c=getopt(argc,argv,"2346AbdDES:jJf:l:m:M:W:Ppr:R:G:Th:Xs"))!=EOF) { switch(c) { case '2': expand_as23456=1; @@ -248,6 +249,8 @@ main(int argc, char* argv[]) break; case 'T': pipelining=0; break; + case 's': expander.sequence=1; + break; case 'S': expander.sources=optarg; break; case 'W': expander.aswidth=atoi(optarg); @@ -326,6 +329,18 @@ main(int argc, char* argv[]) exit(1); }; + if (expander.sequence && expander.vendor!=V_CISCO) { + sx_report(SX_FATAL, "Sorry, prefix-lists sequencing (-s) supported" + " only for IOS\n"); + exit(1); + }; + + if (expander.sequence && expander.generationisGlue) 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,"%s prefix-list %s permit %s ge %u le %u\n", - n->prefix.family==AF_INET?"ip":"ipv6",bname?bname:"NN",prefix, - n->aggregateLow,n->aggregateHi); + fprintf(f,"%s prefix-list %s%s permit %s ge %u le %u\n", + n->prefix.family==AF_INET?"ip":"ipv6",bname?bname:"NN",seqno, + prefix,n->aggregateLow,n->aggregateHi); } else { - fprintf(f,"%s prefix-list %s permit %s le %u\n", - n->prefix.family==AF_INET?"ip":"ipv6",bname?bname:"NN",prefix, - n->aggregateHi); + fprintf(f,"%s prefix-list %s%s permit %s le %u\n", + n->prefix.family==AF_INET?"ip":"ipv6",bname?bname:"NN",seqno, + prefix,n->aggregateHi); }; } else { - fprintf(f,"%s prefix-list %s permit %s\n", - (n->prefix.family==AF_INET)?"ip":"ipv6",bname?bname:"NN",prefix); + fprintf(f,"%s prefix-list %s%s permit %s\n", + (n->prefix.family==AF_INET)?"ip":"ipv6",bname?bname:"NN",seqno, + prefix); }; checkSon: if(n->son) @@ -570,6 +574,7 @@ int bgpq3_print_cisco_prefixlist(FILE* f, struct bgpq_expander* b) { bname=b->name ? b->name : "NN"; + seq=b->sequence; fprintf(f,"no %s prefix-list %s\n", (b->family==AF_INET)?"ip":"ipv6",bname); if (!sx_radix_tree_empty(b->tree)) { diff --git a/configure b/configure index 9ffc455..c816722 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for bgpq3 0.1.32-rc2. +# Generated by GNU Autoconf 2.69 for bgpq3 0.1.32-rc3. # # Report bugs to . # @@ -579,8 +579,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='bgpq3' PACKAGE_TARNAME='bgpq3' -PACKAGE_VERSION='0.1.32-rc2' -PACKAGE_STRING='bgpq3 0.1.32-rc2' +PACKAGE_VERSION='0.1.32-rc3' +PACKAGE_STRING='bgpq3 0.1.32-rc3' PACKAGE_BUGREPORT='snar@snar.spb.ru' PACKAGE_URL='' @@ -1187,7 +1187,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures bgpq3 0.1.32-rc2 to adapt to many kinds of systems. +\`configure' configures bgpq3 0.1.32-rc3 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1248,7 +1248,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of bgpq3 0.1.32-rc2:";; + short | recursive ) echo "Configuration of bgpq3 0.1.32-rc3:";; esac cat <<\_ACEOF @@ -1327,7 +1327,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -bgpq3 configure 0.1.32-rc2 +bgpq3 configure 0.1.32-rc3 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1495,7 +1495,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by bgpq3 $as_me 0.1.32-rc2, which was +It was created by bgpq3 $as_me 0.1.32-rc3, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3413,7 +3413,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by bgpq3 $as_me 0.1.32-rc2, which was +This file was extended by bgpq3 $as_me 0.1.32-rc3, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -3475,7 +3475,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -bgpq3 config.status 0.1.32-rc2 +bgpq3 config.status 0.1.32-rc3 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.in b/configure.in index 3cc8247..f9d136d 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -AC_INIT(bgpq3,0.1.32-rc2,snar@snar.spb.ru) +AC_INIT(bgpq3,0.1.32-rc3,snar@snar.spb.ru) AC_CONFIG_HEADER(config.h) AC_PROG_CC AC_PROG_INSTALL