1
0
mirror of https://github.com/bgp/bgpq4.git synced 2024-05-11 05:55:05 +00:00

JSON output for as-paths

This commit is contained in:
Alexandre Snarskii
2014-10-29 19:27:47 +03:00
parent 9c25c7a780
commit 61c23c53b3
6 changed files with 347 additions and 283 deletions

13
CHANGES
View File

@@ -1,3 +1,16 @@
0.1.25 (2014-10-29)
- JSON support extended to handle "as-paths" too. Well, actually, as
there are no defined format for as-path in json, bgpq3 just creates
simple object like following:
snar@fri:~/compile/bgpq3>./bgpq3 -j3f 20597 as-eltel
{"NN": [
112,5495,6857,8377,20597,34102,35357,43951,
52007,56764,197759,197888,198610,201499
]}
Based on suggestion by Henrik Thostrup Jensen.
0.1.24 (2014-07-31) 0.1.24 (2014-07-31)
- empty prefix-lists (Cisco), extended access-lists (Cisco), as-path - empty prefix-lists (Cisco), extended access-lists (Cisco), as-path
filters (Cisco and Juniper) and route-filters (Juniper) handling: filters (Cisco and Juniper) and route-filters (Juniper) handling:

10
bgpq3.c
View File

@@ -281,9 +281,10 @@ main(int argc, char* argv[])
sx_report(SX_FATAL, "Sorry, only prefix-lists supported for BIRD " sx_report(SX_FATAL, "Sorry, only prefix-lists supported for BIRD "
"output\n"); "output\n");
}; };
if(expander.vendor==V_JSON && expander.generation!=T_PREFIXLIST) { if(expander.vendor==V_JSON && expander.generation!=T_PREFIXLIST &&
sx_report(SX_FATAL, "Sorry, only prefix-lists supported for JSON " expander.generation!=T_ASPATH) {
"output\n"); sx_report(SX_FATAL, "Sorry, only prefix-lists and as-paths supported "
"for JSON output\n");
}; };
if(expander.asdot && expander.vendor!=V_CISCO) { if(expander.asdot && expander.vendor!=V_CISCO) {
@@ -380,7 +381,8 @@ main(int argc, char* argv[])
if(expander.match != NULL && (expander.vendor != V_JUNIPER || if(expander.match != NULL && (expander.vendor != V_JUNIPER ||
expander.generation != T_EACL)) { expander.generation != T_EACL)) {
sx_report(SX_FATAL, "Sorry, extra match conditions (-M) can be used only with Juniper route-filters\n"); sx_report(SX_FATAL, "Sorry, extra match conditions (-M) can be used "
"only with Juniper route-filters\n");
}; };
if(!argv[0]) usage(1); if(!argv[0]) usage(1);

View File

@@ -1,12 +1,12 @@
Name: bgpq3 Name: bgpq3
Version: 0.1.21 Version: 0.1.25
Release: 0%{?dist} Release: 0%{?dist}
Group: System/Utilities Group: System/Utilities
Summary: Automate BGP filter generation based on routing database information Summary: Automate BGP filter generation based on routing database information
URL: http://snar.spb.ru/prog/bgpq3/ URL: http://snar.spb.ru/prog/bgpq3/
License: BSD License: BSD
Source0: http://snar.spb.ru/prog/bgpq3/bgpq3-0.1.21.tgz Source0: http://snar.spb.ru/prog/bgpq3/bgpq3-0.1.25.tgz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%description %description
@@ -35,6 +35,9 @@ rm -rf $RPM_BUILD_ROOT
%changelog %changelog
* Wed Oct 29 Alexandre Snarskii <snar@snar.spb.ru> 0.1.25
- Version updated
* Thu Jun 5 2014 Alexandre Snarskii <snar@snar.spb.ru> 0.1.21-0.snar * Thu Jun 5 2014 Alexandre Snarskii <snar@snar.spb.ru> 0.1.21-0.snar
- Version updated - Version updated

View File

@@ -14,6 +14,8 @@
#include "bgpq3.h" #include "bgpq3.h"
#include "sx_report.h" #include "sx_report.h"
int bgpq3_print_json_aspath(FILE* f, struct bgpq_expander* b);
int int
bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b) bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b)
{ {
@@ -228,6 +230,8 @@ bgpq3_print_aspath(FILE* f, struct bgpq_expander* b)
return bgpq3_print_juniper_aspath(f,b); return bgpq3_print_juniper_aspath(f,b);
} else if(b->vendor==V_CISCO) { } else if(b->vendor==V_CISCO) {
return bgpq3_print_cisco_aspath(f,b); return bgpq3_print_cisco_aspath(f,b);
} else if(b->vendor==V_JSON) {
return bgpq3_print_json_aspath(f,b);
} else { } else {
sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor); sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor);
}; };
@@ -289,6 +293,48 @@ checkSon:
bgpq3_print_json_prefix(n->son, ff); bgpq3_print_json_prefix(n->son, ff);
}; };
int
bgpq3_print_json_aspath(FILE* f, struct bgpq_expander* b)
{
int nc=0, i, j, k;
fprintf(f,"{\"%s\": [", b->name?b->name:"NN");
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)) {
if(!nc) {
if(b->asdot && k>0) {
fprintf(f,"%s\n %i.%i",needscomma?",":"", k,i*8+j);
needscomma=1;
} else {
fprintf(f,"%s\n %i",needscomma?",":"",
k*65536+i*8+j);
needscomma=1;
};
} else {
if(b->asdot && k>0) {
fprintf(f,"%s%i.%i,",needscomma?",":"", k,i*8+j);
needscomma=1;
} else {
fprintf(f,"%s%i",needscomma?",":"", k*65536+i*8+j);
needscomma=1;
};
}
nc++;
if(nc==b->aswidth) {
nc=0;
};
};
};
};
};
fprintf(f,"\n]}\n");
return 0;
};
void void
bgpq3_print_bird_prefix(struct sx_radix_node* n, void* ff) bgpq3_print_bird_prefix(struct sx_radix_node* n, void* ff)
{ {

18
configure vendored
View File

@@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# Guess values for system-dependent variables and create Makefiles. # Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for bgpq3 0.1.24. # Generated by GNU Autoconf 2.69 for bgpq3 0.1.25.
# #
# Report bugs to <snar@snar.spb.ru>. # Report bugs to <snar@snar.spb.ru>.
# #
@@ -579,8 +579,8 @@ MAKEFLAGS=
# Identity of this package. # Identity of this package.
PACKAGE_NAME='bgpq3' PACKAGE_NAME='bgpq3'
PACKAGE_TARNAME='bgpq3' PACKAGE_TARNAME='bgpq3'
PACKAGE_VERSION='0.1.24' PACKAGE_VERSION='0.1.25'
PACKAGE_STRING='bgpq3 0.1.24' PACKAGE_STRING='bgpq3 0.1.25'
PACKAGE_BUGREPORT='snar@snar.spb.ru' PACKAGE_BUGREPORT='snar@snar.spb.ru'
PACKAGE_URL='' 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. # 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. # This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF cat <<_ACEOF
\`configure' configures bgpq3 0.1.24 to adapt to many kinds of systems. \`configure' configures bgpq3 0.1.25 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]... Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1248,7 +1248,7 @@ fi
if test -n "$ac_init_help"; then if test -n "$ac_init_help"; then
case $ac_init_help in case $ac_init_help in
short | recursive ) echo "Configuration of bgpq3 0.1.24:";; short | recursive ) echo "Configuration of bgpq3 0.1.25:";;
esac esac
cat <<\_ACEOF cat <<\_ACEOF
@@ -1327,7 +1327,7 @@ fi
test -n "$ac_init_help" && exit $ac_status test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then if $ac_init_version; then
cat <<\_ACEOF cat <<\_ACEOF
bgpq3 configure 0.1.24 bgpq3 configure 0.1.25
generated by GNU Autoconf 2.69 generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc. Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1495,7 +1495,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake. running configure, to aid debugging if configure makes a mistake.
It was created by bgpq3 $as_me 0.1.24, which was It was created by bgpq3 $as_me 0.1.25, which was
generated by GNU Autoconf 2.69. Invocation command line was generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@ $ $0 $@
@@ -3413,7 +3413,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their # report actual input values of CONFIG_FILES etc. instead of their
# values after options handling. # values after options handling.
ac_log=" ac_log="
This file was extended by bgpq3 $as_me 0.1.24, which was This file was extended by bgpq3 $as_me 0.1.25, which was
generated by GNU Autoconf 2.69. Invocation command line was generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES CONFIG_FILES = $CONFIG_FILES
@@ -3475,7 +3475,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\ ac_cs_version="\\
bgpq3 config.status 0.1.24 bgpq3 config.status 0.1.25
configured by $0, generated by GNU Autoconf 2.69, configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\" with options \\"\$ac_cs_config\\"

View File

@@ -1,4 +1,4 @@
AC_INIT(bgpq3,0.1.24,snar@snar.spb.ru) AC_INIT(bgpq3,0.1.25,snar@snar.spb.ru)
AC_CONFIG_HEADER(config.h) AC_CONFIG_HEADER(config.h)
AC_PROG_CC AC_PROG_CC
AC_PROG_INSTALL AC_PROG_INSTALL