diff --git a/Makefile.in b/Makefile.in index 1a32d1d..511f3cb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,8 +2,10 @@ CC=@CC@ CFLAGS=@CFLAGS@ @DEFS@ -g -Wall -I. -O0 LDADD=@LDFLAGS@ @LIBS@ -OBJECTS=bgpq3.o sx_report.o bgpq_expander.o sx_slentry.o bgpq3_printer.o -SRCS=bgpq3.c bgpq_expander.c sx_slentry.c bgpq3_printer.c +OBJECTS=bgpq3.o sx_report.o bgpq_expander.o sx_slentry.o bgpq3_printer.o +OBJECTS+=sx_prefix.o +SRCS=bgpq3.c sx_report.c bgpq_expander.c sx_slentry.c bgpq3_printer.c +SRCS+=sx_prefix.c all: bgpq3 diff --git a/bgpq3.c b/bgpq3.c index 6649f1a..0b163e3 100644 --- a/bgpq3.c +++ b/bgpq3.c @@ -21,15 +21,28 @@ extern int debug_expander; int usage(int ecode) { - printf("Usage: bgpq3 [-h] [-S sources] ...\n"); - printf(" -h : this help\n"); - printf(" -J : use Juniper replace formatted output\n"); - printf(" -l : use specified name for generated access/prefix/.. list\n"); + printf("Usage: bgpq3 [-h] [-S sources] [-P|G |f ] " + "...\n"); + printf(" -f number : generate input as-path access-list\n"); + printf(" -G number : generate output as-path access-list\n"); + printf(" -h : this help\n"); + printf(" -J : use Juniper replace formatted output\n"); + printf(" -l : use specified name for generated access/prefix/.." + " list\n"); + printf(" -P : generate prefix-list (default)\n"); printf(" -S sources: use only specified sources (default:" " RADB,RIPE,APNIC)\n"); + printf("\nCopyright(c) Alexandre Snarskii , 2007\n\n"); exit(ecode); }; +void +exclusive() +{ + fprintf(stderr,"-f , -P are mutually exclusive\n"); + exit(1); +}; + int main(int argc, char* argv[]) { @@ -41,7 +54,7 @@ main(int argc, char* argv[]) bgpq_expander_init(&expander,af); expander.sources=getenv("IRRD_SOURCES"); - while((c=getopt(argc,argv,"6dhS:Jf:l:W:P"))!=EOF) { + while((c=getopt(argc,argv,"6dhS:Jf:l:W:PG:"))!=EOF) { switch(c) { case '6': af=AF_INET6; expander.family=AF_INET6; @@ -56,9 +69,20 @@ main(int argc, char* argv[]) sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg); exit(1); }; + if(expander.generation) exclusive(); expander.generation=T_ASPATH; break; - case 'P': expander.generation=T_PREFIXLIST; + case 'G': expander.asnumber=atoi(optarg); + if(expander.asnumber<0 || expander.asnumber>65535) { + sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg); + exit(1); + }; + if(expander.generation) exclusive(); + expander.generation=T_OASPATH; + break; + case 'P': + if(expander.generation) exclusive(); + expander.generation=T_PREFIXLIST; break; case 'l': expander.name=optarg; break; @@ -95,6 +119,10 @@ main(int argc, char* argv[]) }; }; + if(!expander.generation) { + expander.generation=T_PREFIXLIST; + }; + if(!argv[0]) usage(1); while(argv[0]) { @@ -115,11 +143,13 @@ main(int argc, char* argv[]) }; switch(expander.generation) { + case T_NONE: sx_report(SX_FATAL,"Unreachable point... call snar\n"); + exit(1); case T_ASPATH: bgpq3_print_aspath(stdout,&expander); break; - case T_PREFIXLIST: bgpq3_print_prefixlist(stdout,&expander); - default : + case T_OASPATH: bgpq3_print_oaspath(stdout,&expander); break; + case T_PREFIXLIST: bgpq3_print_prefixlist(stdout,&expander); }; return 0; diff --git a/bgpq3.h b/bgpq3.h index 0f48221..38c20e6 100644 --- a/bgpq3.h +++ b/bgpq3.h @@ -37,6 +37,7 @@ int bgpq_expand(struct bgpq_expander* b); int bgpq3_print_prefixlist(FILE* f, struct bgpq_expander* b); int bgpq3_print_aspath(FILE* f, struct bgpq_expander* b); +int bgpq3_print_oaspath(FILE* f, struct bgpq_expander* b); #endif diff --git a/bgpq3_printer.c b/bgpq3_printer.c index cc29c27..3bff861 100644 --- a/bgpq3_printer.c +++ b/bgpq3_printer.c @@ -16,10 +16,10 @@ int bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b) { int nc=0, i, j; - fprintf(f,"no ip as-path access-list %s\n", b->name?b->name:"UNKNOWN"); + fprintf(f,"no ip as-path access-list %s\n", b->name?b->name:"NN"); if(b->asnumbers[b->asnumber/8]&(0x80>>(b->asnumber%8))) { fprintf(f,"ip as-path access-list %s permit ^%i(_%i)*$\n", - b->name?b->name:"UNKNOWN",b->asnumber,b->asnumber); + b->name?b->name:"NN",b->asnumber,b->asnumber); }; for(i=0;iasnumbers);i++) { for(j=0;j<8;j++) { @@ -27,7 +27,7 @@ bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b) if(i*8+j==b->asnumber) continue; if(!nc) { fprintf(f,"ip as-path access-list %s permit" - " ^%i(_[0-9]+)*_(%i", b->name?b->name:"UNKNOWN", + " ^%i(_[0-9]+)*_(%i", b->name?b->name:"NN", b->asnumber,i*8+j); } else { fprintf(f,"|%i",i*8+j); @@ -43,13 +43,44 @@ bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b) if(nc) fprintf(f,")$\n"); return 0; }; +int +bgpq3_print_cisco_oaspath(FILE* f, struct bgpq_expander* b) +{ + int nc=0, i, j; + fprintf(f,"no ip as-path access-list %s\n", b->name?b->name:"NN"); + if(b->asnumbers[b->asnumber/8]&(0x80>>(b->asnumber%8))) { + fprintf(f,"ip as-path access-list %s permit ^(_%i)*$\n", + b->name?b->name:"NN",b->asnumber); + }; + for(i=0;iasnumbers);i++) { + for(j=0;j<8;j++) { + if(b->asnumbers[i]&(0x80>>j)) { + if(i*8+j==b->asnumber) continue; + if(!nc) { + fprintf(f,"ip as-path access-list %s permit" + " ^(_[0-9]+)*_(%i", b->name?b->name:"NN", + i*8+j); + } else { + fprintf(f,"|%i",i*8+j); + } + nc++; + if(nc==b->aswidth) { + fprintf(f,")$\n"); + nc=0; + }; + }; + }; + }; + if(nc) fprintf(f,")$\n"); + return 0; +}; int bgpq3_print_juniper_aspath(FILE* f, struct bgpq_expander* b) { int nc=0, lineNo=0, i, j; fprintf(f,"policy-options {\nreplace:\n as-path-group %s {\n", - b->name?b->name:"UNKNOWN"); + b->name?b->name:"NN"); if(b->asnumbers[b->asnumber/8]&(0x80>>(b->asnumber%8))) { fprintf(f," as-path a%i \"^%i(%i)*$\";\n", lineNo, b->asnumber, @@ -80,6 +111,42 @@ bgpq3_print_juniper_aspath(FILE* f, struct bgpq_expander* b) return 0; }; +int +bgpq3_print_juniper_oaspath(FILE* f, struct bgpq_expander* b) +{ + int nc=0, lineNo=0, i, j; + fprintf(f,"policy-options {\nreplace:\n as-path-group %s {\n", + b->name?b->name:"NN"); + + if(b->asnumbers[b->asnumber/8]&(0x80>>(b->asnumber%8))) { + fprintf(f," as-path a%i \"^%i(%i)*$\";\n", lineNo, b->asnumber, + b->asnumber); + lineNo++; + }; + for(i=0;iasnumbers);i++) { + for(j=0;j<8;j++) { + if(b->asnumbers[i]&(0x80>>j)) { + if(i*8+j==b->asnumber) continue; + if(!nc) { + fprintf(f," as-path a%i \"^(.)*(%i", + lineNo,i*8+j); + } else { + fprintf(f,"|%i",i*8+j); + } + nc++; + if(nc==b->aswidth) { + fprintf(f,")$\";\n"); + nc=0; + lineNo++; + }; + }; + }; + }; + if(nc) fprintf(f,")$\";\n"); + fprintf(f," }\n}\n"); + return 0; +}; + int bgpq3_print_aspath(FILE* f, struct bgpq_expander* b) { @@ -93,6 +160,19 @@ bgpq3_print_aspath(FILE* f, struct bgpq_expander* b) return 0; }; +int +bgpq3_print_oaspath(FILE* f, struct bgpq_expander* b) +{ + if(b->vendor==V_JUNIPER) { + return bgpq3_print_juniper_oaspath(f,b); + } else if(b->vendor==V_CISCO) { + return bgpq3_print_cisco_oaspath(f,b); + } else { + sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor); + }; + return 0; +}; + void bgpq3_print_jprefix(struct sx_radix_node* n, void* ff) { @@ -114,14 +194,14 @@ bgpq3_print_cprefix(struct sx_radix_node* n, void* ff) if(n->isGlue) return; if(!f) f=stdout; sx_prefix_snprintf(&n->prefix,prefix,sizeof(prefix)); - fprintf(f,"ip prefix-list %s permit %s\n",bname?bname:"UNKNOWN",prefix); + fprintf(f,"ip prefix-list %s permit %s\n",bname?bname:"NN",prefix); }; int bgpq3_print_juniper_prefixlist(FILE* f, struct bgpq_expander* b) { fprintf(f,"policy-options {\nreplace:\n prefix-list %s {\n", - b->name?b->name:"UNKNOWN"); + b->name?b->name:"NN"); sx_radix_tree_foreach(b->tree,bgpq3_print_jprefix,f); fprintf(f," }\n}\n"); return 0; diff --git a/bgpq_expander.c b/bgpq_expander.c index f7ec337..c6c75ba 100644 --- a/bgpq_expander.c +++ b/bgpq_expander.c @@ -33,7 +33,7 @@ bgpq_expander_init(struct bgpq_expander* b, int af) b->family=af; b->sources="ripe,radb,apnic"; - b->name="UNKNOWN"; + b->name="NN"; b->aswidth=8; return 1; diff --git a/configure b/configure index df16f73..985d068 100755 --- a/configure +++ b/configure @@ -272,44 +272,7 @@ PACKAGE_STRING= PACKAGE_BUGREPORT= ac_unique_file="bgpq3.c" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#if HAVE_SYS_TYPES_H -# include -#endif -#if HAVE_SYS_STAT_H -# include -#endif -#if STDC_HEADERS -# include -# include -#else -# if HAVE_STDLIB_H -# include -# endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#endif -#if HAVE_STRINGS_H -# include -#endif -#if HAVE_INTTYPES_H -# include -#else -# if HAVE_STDINT_H -# include -# endif -#endif -#if HAVE_UNISTD_H -# include -#endif" - -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -766,10 +729,6 @@ ac_env_CPPFLAGS_set=${CPPFLAGS+set} ac_env_CPPFLAGS_value=$CPPFLAGS ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} ac_cv_env_CPPFLAGS_value=$CPPFLAGS -ac_env_CPP_set=${CPP+set} -ac_env_CPP_value=$CPP -ac_cv_env_CPP_set=${CPP+set} -ac_cv_env_CPP_value=$CPP # # Report the --help message. @@ -844,7 +803,6 @@ Some influential environment variables: nonstandard directory CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory - CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. @@ -2217,973 +2175,6 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -d "../libsxreport" ; then - CFLAGS="$CFLAGS -I../libsxreport" - CPPFLAGS="$CPPFLAGS -I../libsxreport" - LDFLAGS="$LDFLAGS -L../libsxreport" -fi - - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 -echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -echo "$as_me:$LINENO: result: $CPP" >&5 -echo "${ECHO_T}$CPP" >&6 -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&5 -echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -echo "$as_me:$LINENO: checking for egrep" >&5 -echo $ECHO_N "checking for egrep... $ECHO_C" >&6 -if test "${ac_cv_prog_egrep+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if echo a | (grep -E '(a|b)') >/dev/null 2>&1 - then ac_cv_prog_egrep='grep -E' - else ac_cv_prog_egrep='egrep' - fi -fi -echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5 -echo "${ECHO_T}$ac_cv_prog_egrep" >&6 - EGREP=$ac_cv_prog_egrep - - -echo "$as_me:$LINENO: checking for ANSI C header files" >&5 -echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 -if test "${ac_cv_header_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_header_stdc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_header_stdc=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - exit(2); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_header_stdc=no -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 -echo "${ECHO_T}$ac_cv_header_stdc" >&6 -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\_ACEOF -#define STDC_HEADERS 1 -_ACEOF - -fi - -# On IRIX 5.3, sys/types and inttypes.h are conflicting. - - - - - - - - - -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default - -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -for ac_header in sx_report.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking $ac_header usability" >&5 -echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_header_compiler=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 - -# Is the header present? -echo "$as_me:$LINENO: checking $ac_header presence" >&5 -echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------------ ## -## Report this to the AC_PACKAGE_NAME lists. ## -## ------------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 - -fi -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -else - { { echo "$as_me:$LINENO: error: no sx_report.h" >&5 -echo "$as_me: error: no sx_report.h" >&2;} - { (exit 1); exit 1; }; } -fi - -done - - -echo "$as_me:$LINENO: checking for sx_report in -lsxreport" >&5 -echo $ECHO_N "checking for sx_report in -lsxreport... $ECHO_C" >&6 -if test "${ac_cv_lib_sxreport_sx_report+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lsxreport $LIBS" -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char sx_report (); -int -main () -{ -sx_report (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_sxreport_sx_report=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_lib_sxreport_sx_report=no -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:$LINENO: result: $ac_cv_lib_sxreport_sx_report" >&5 -echo "${ECHO_T}$ac_cv_lib_sxreport_sx_report" >&6 -if test $ac_cv_lib_sxreport_sx_report = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBSXREPORT 1 -_ACEOF - - LIBS="-lsxreport $LIBS" - -else - { { echo "$as_me:$LINENO: error: no -lsxreport" >&5 -echo "$as_me: error: no -lsxreport" >&2;} - { (exit 1); exit 1; }; } -fi - - -if test -d "../libptree" ; then - CFLAGS="$CFLAGS -I../libptree" - CPPFLAGS="$CPPFLAGS -I../libptree" - LDFLAGS="$LDFLAGS -L../libptree" -fi - - -for ac_header in sx_prefix.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking $ac_header usability" >&5 -echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_header_compiler=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 - -# Is the header present? -echo "$as_me:$LINENO: checking $ac_header presence" >&5 -echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------------ ## -## Report this to the AC_PACKAGE_NAME lists. ## -## ------------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 - -fi -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -else - { { echo "$as_me:$LINENO: error: no sx_prefix.h" >&5 -echo "$as_me: error: no sx_prefix.h" >&2;} - { (exit 1); exit 1; }; } -fi - -done - - -echo "$as_me:$LINENO: checking for sx_prefix_new in -lsxprefix" >&5 -echo $ECHO_N "checking for sx_prefix_new in -lsxprefix... $ECHO_C" >&6 -if test "${ac_cv_lib_sxprefix_sx_prefix_new+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lsxprefix $LIBS" -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char sx_prefix_new (); -int -main () -{ -sx_prefix_new (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_sxprefix_sx_prefix_new=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_lib_sxprefix_sx_prefix_new=no -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:$LINENO: result: $ac_cv_lib_sxprefix_sx_prefix_new" >&5 -echo "${ECHO_T}$ac_cv_lib_sxprefix_sx_prefix_new" >&6 -if test $ac_cv_lib_sxprefix_sx_prefix_new = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBSXPREFIX 1 -_ACEOF - - LIBS="-lsxprefix $LIBS" - -else - { { echo "$as_me:$LINENO: error: no -lsxprefix" >&5 -echo "$as_me: error: no -lsxprefix" >&2;} - { (exit 1); exit 1; }; } -fi - - ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -3802,8 +2793,6 @@ s,@CPPFLAGS@,$CPPFLAGS,;t t s,@ac_ct_CC@,$ac_ct_CC,;t t s,@EXEEXT@,$EXEEXT,;t t s,@OBJEXT@,$OBJEXT,;t t -s,@CPP@,$CPP,;t t -s,@EGREP@,$EGREP,;t t s,@LIBOBJS@,$LIBOBJS,;t t s,@LTLIBOBJS@,$LTLIBOBJS,;t t CEOF diff --git a/configure.in b/configure.in index 3227157..b35bdb8 100644 --- a/configure.in +++ b/configure.in @@ -2,23 +2,5 @@ AC_INIT(bgpq3.c) AC_CONFIG_HEADER(config.h) AC_PROG_CC -if test -d "../libsxreport" ; then - CFLAGS="$CFLAGS -I../libsxreport" - CPPFLAGS="$CPPFLAGS -I../libsxreport" - LDFLAGS="$LDFLAGS -L../libsxreport" -fi - -AC_CHECK_HEADERS(sx_report.h,,[AC_MSG_ERROR([no sx_report.h])]) -AC_CHECK_LIB(sxreport,sx_report,,[AC_MSG_ERROR([no -lsxreport])]) - -if test -d "../libptree" ; then - CFLAGS="$CFLAGS -I../libptree" - CPPFLAGS="$CPPFLAGS -I../libptree" - LDFLAGS="$LDFLAGS -L../libptree" -fi - -AC_CHECK_HEADERS(sx_prefix.h,,[AC_MSG_ERROR([no sx_prefix.h])]) -AC_CHECK_LIB(sxprefix,sx_prefix_new,,[AC_MSG_ERROR([no -lsxprefix])]) - AC_OUTPUT(Makefile) diff --git a/sx_prefix.c b/sx_prefix.c new file mode 100644 index 0000000..004b8c9 --- /dev/null +++ b/sx_prefix.c @@ -0,0 +1,624 @@ +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include "sx_prefix.h" +#include "sx_report.h" + +struct sx_prefix* +sx_prefix_alloc(struct sx_prefix* p) +{ + struct sx_prefix* sp=malloc(sizeof(struct sx_prefix)); + if(!sp) return NULL; + if(p) { + *sp=*p; + } else { + memset(sp,0,sizeof(struct sx_prefix)); + }; + return sp; +}; +void +sx_prefix_destroy(struct sx_prefix* p) +{ + if(p) free(p); +}; + +void +sx_prefix_adjust_masklen(struct sx_prefix* p) +{ + int nbytes=(p->family==AF_INET?4:16); + int i; + if(p->masklen==nbytes*8) return ; /* mask is all ones */ + for(i=nbytes-1;i>p->masklen/8;i--) { + p->addr.addrs[i]=0; + }; + for(i=1;i<=8-p->masklen%8;i++) { + p->addr.addrs[p->masklen/8]&=(0xff<addr)!=1) { + *c='/'; + sx_report(SX_ERROR,"Unable to parse prefix %s, af=%i\n",text,af); + goto fixups; + }; + + if(af==AF_INET) { + if(masklen==-1) p->masklen=32; + else { + if(masklen<0 || masklen>32) { + p->masklen=32; + } else { + p->masklen=masklen; + }; + }; + } else if(af==AF_INET6) { + if(masklen==-1) p->masklen=128; + else { + if(masklen<0 || masklen>128) { + p->masklen=128; + } else { + p->masklen=masklen; + }; + }; + } else { + sx_report(SX_ERROR,"Invalid address family %i\n", af); + goto fixups; + }; + + p->family=af; + sx_prefix_adjust_masklen(p); + if(c) *c='/'; + + return 1; +fixups: + return 0; +}; + + +struct sx_prefix* +sx_prefix_new(int af, char* text) +{ + struct sx_prefix* p=NULL; + + if(!text) return NULL; + + p=sx_prefix_alloc(NULL); + + if(!p) return NULL; + if(!sx_prefix_parse(p,af,text)) { + sx_prefix_destroy(p); + return NULL; + }; + return p; +}; + +int +sx_prefix_fprint(FILE* f, struct sx_prefix* p) +{ + char buffer[128]; + if(!p) { + fprintf(f?f:stdout,"(null)"); + return 0; + }; + inet_ntop(p->family,&p->addr,buffer,sizeof(buffer)); + return fprintf(f?f:stdout,"%s/%i",buffer,p->masklen); +}; + +int +sx_prefix_snprintf(struct sx_prefix* p, char* rbuffer, int srb) +{ + char buffer[128]; + if(!p) { + snprintf(rbuffer,srb,"(null)"); + return 0; + }; + inet_ntop(p->family,&p->addr,buffer,sizeof(buffer)); + return snprintf(rbuffer,srb,"%s/%i",buffer,p->masklen); +}; + +struct sx_radix_tree* +sx_radix_tree_new(int af) +{ + struct sx_radix_tree* rt=malloc(sizeof(struct sx_radix_tree)); + if(!rt) { + return NULL; + }; + memset(rt,0,sizeof(struct sx_radix_tree)); + rt->family=af; + return rt; +}; + +struct sx_radix_node* +sx_radix_node_new(struct sx_prefix* prefix) +{ + struct sx_radix_node* rn=malloc(sizeof(struct sx_radix_node)); + if(!rn) return NULL; + memset(rn,0,sizeof(struct sx_radix_node)); + if(prefix) { + rn->prefix=*prefix; /* structure copy */ + }; + return rn; +}; + +inline int +sx_prefix_eqbits(struct sx_prefix* a, struct sx_prefix* b) +{ + int i; + int nbytes=(a->family==AF_INET?4:16); + for(i=0;iaddr.addrs[i]==b->addr.addrs[i]) continue; + else { + int j; + for(j=0;j<8 && i*8+j<=a->masklen && i*8+j<=b->masklen;j++) { + if((a->addr.addrs[i]&(0x80>>j))!=(b->addr.addrs[i]&(0x80>>j))) + return i*8+j; + }; + }; + }; + if(a->masklenmasklen) return a->masklen; + return b->masklen; +}; + +inline int +sx_prefix_isbitset(struct sx_prefix* p, int n) +{ + unsigned char s; + /* bits outside the prefix considered unset */ + if(p->family==AF_INET && (n<0 || n>32)) return 0; + else if(p->family==AF_INET6 && (n<0 || n>32)) return 0; + s=p->addr.addrs[(n-1)/8]; + return (s&(0x80>>((n-1)%8)))?1:0; +}; + +struct sx_prefix* +sx_prefix_overlay(struct sx_prefix* p, int n) +{ + struct sx_prefix* sp=sx_prefix_alloc(p); + sp->masklen=n; + sx_prefix_adjust_masklen(sp); + return sp; +}; + +void +sx_radix_tree_unlink(struct sx_radix_tree* tree, struct sx_radix_node* node) +{ +next: + if(node->r && node->l) { + node->isGlue=1; + } else if(node->r) { + if(node->parent) { + if(node->parent->r==node) { + node->parent->r=node->r; + node->r->parent=node->parent; + } else if(node->parent->l==node) { + node->parent->l=node->l; + node->r->parent=node->parent; + } else { + sx_report(SX_ERROR,"Unlinking node which is not descendant " + "of its parent\n"); + }; + } else if(tree->head==node) { + /* only one case, really */ + tree->head=node->r; + node->r->parent=NULL; + } else { + sx_report(SX_ERROR,"Unlinking node with no parent and not root\n"); + }; + } else if(node->l) { + if(node->parent) { + if(node->parent->r==node) { + node->parent->r=node->l; + node->l->parent=node->parent; + } else if(node->parent->l==node) { + node->parent->l=node->l; + node->l->parent=node->parent; + } else { + sx_report(SX_ERROR,"Unlinking node which is not descendant " + "of its parent\n"); + }; + } else if(tree->head==node) { + tree->head=node->l; + node->l->parent=NULL; + } else { + sx_report(SX_ERROR,"Unlinking node with no parent and not root\n"); + }; + } else { + /* the only case - node does not have descendants */ + if(node->parent) { + if(node->parent->l==node) node->parent->l=NULL; + else if(node->parent->r==node) node->parent->r=NULL; + else { + sx_report(SX_ERROR,"Unlinking node which is not descendant " + "of its parent\n"); + }; + if(node->parent->isGlue) { + node=node->parent; + goto next; + }; + } else if(tree->head==node) { + tree->head=NULL; + }; + }; +}; + + +struct sx_radix_node* +sx_radix_tree_lookup(struct sx_radix_tree* tree, struct sx_prefix* prefix) +{ + int eb; + struct sx_radix_node* candidate=NULL, *chead; + + if(!tree || !prefix) return NULL; + if(tree->family!=prefix->family) return NULL; + if(!tree->head) return NULL; + + chead=tree->head; + +next: + eb=sx_prefix_eqbits(&chead->prefix,prefix); + if(eb==chead->prefix.masklen && eb==prefix->masklen) { + /* they are equal */ + if(chead->isGlue) return candidate; + return chead; + } else if(ebprefix.masklen) { + return candidate; + } else if(ebmasklen) { + /* it equals chead->masklen */ + if(sx_prefix_isbitset(prefix,eb+1)) { + if(chead->r) { + if(!chead->isGlue) { + candidate=chead; + }; + chead=chead->r; + goto next; + } else { + if(chead->isGlue) return candidate; + return chead; + }; + } else { + if(chead->l) { + if(!chead->isGlue) { + candidate=chead; + }; + chead=chead->l; + goto next; + } else { + if(chead->isGlue) return candidate; + return chead; + }; + }; + } else { + char pbuffer[128], cbuffer[128]; + sx_prefix_snprintf(prefix,pbuffer,sizeof(pbuffer)); + sx_prefix_snprintf(&chead->prefix,cbuffer,sizeof(cbuffer)); + printf("Unreachible point... eb=%i, prefix=%s, chead=%s\n", eb, + pbuffer, cbuffer); + abort(); + }; +}; + + +struct sx_radix_node* +sx_radix_tree_insert(struct sx_radix_tree* tree, struct sx_prefix* prefix) +{ + int eb; + struct sx_radix_node** candidate=NULL, *chead; + + if(!tree || !prefix) return NULL; + if(tree->family!=prefix->family) { + return NULL; + }; + if(!tree->head) { + tree->head=sx_radix_node_new(prefix); + return tree->head; + }; + candidate=&tree->head; + chead=tree->head; + +next: + eb=sx_prefix_eqbits(prefix,&chead->prefix); + if(ebmasklen && ebprefix.masklen) { + struct sx_prefix neoRoot=*prefix; + struct sx_radix_node* rn, *ret=sx_radix_node_new(prefix); + neoRoot.masklen=eb; + sx_prefix_adjust_masklen(&neoRoot); + rn=sx_radix_node_new(&neoRoot); + if(!rn) { + sx_report(SX_ERROR,"Unable to create node: %s\n", strerror(errno)); + return NULL; + }; + if(sx_prefix_isbitset(prefix,eb+1)) { + rn->l=chead; + rn->r=ret; + } else { + rn->l=ret; + rn->r=chead; + }; + chead->parent=rn; + ret->parent=rn; + rn->isGlue=1; + *candidate=rn; + return ret; + } else if(eb==prefix->masklen && ebprefix.masklen) { + struct sx_radix_node* ret=sx_radix_node_new(prefix); + if(sx_prefix_isbitset(&chead->prefix,eb+1)) { + ret->r=chead; + } else { + ret->l=chead; + }; + chead->parent=ret; + *candidate=ret; + return ret; + } else if(eb==chead->prefix.masklen && ebmasklen) { + if(sx_prefix_isbitset(prefix,eb+1)) { + if(chead->r) { + candidate=&chead->r; + chead=chead->r; + goto next; + } else { + chead->r=sx_radix_node_new(prefix); + chead->r->parent=chead; + return chead->r; + }; + } else { + if(chead->l) { + candidate=&chead->l; + chead=chead->l; + goto next; + } else { + chead->l=sx_radix_node_new(prefix); + chead->l->parent=chead; + return chead->l; + }; + }; + } else if(eb==chead->prefix.masklen && eb==prefix->masklen) { + /* equal routes... */ + if(chead->isGlue) { + chead->isGlue=0; + }; + return chead; + } else { + char pbuffer[128], cbuffer[128]; + sx_prefix_snprintf(prefix,pbuffer,sizeof(pbuffer)); + sx_prefix_snprintf(&chead->prefix,cbuffer,sizeof(cbuffer)); + printf("Unreachible point... eb=%i, prefix=%s, chead=%s\n", eb, + pbuffer, cbuffer); + abort(); + }; +}; + +void +sx_radix_node_fprintf(struct sx_radix_node* node, void* udata) +{ + FILE* out=(udata?udata:stdout); + char buffer[128]; + if(!node) { + fprintf(out,"(null)\n"); + } else { + sx_prefix_snprintf(&node->prefix,buffer,sizeof(buffer)); + fprintf(out,"%s %s\n", buffer, node->isGlue?"(glue)":""); + }; +}; + +int +sx_radix_node_foreach(struct sx_radix_node* node, + void (*func)(struct sx_radix_node*, void*), void* udata) +{ + func(node,udata); + if(node->l) sx_radix_node_foreach(node->l,func,udata); + if(node->r) sx_radix_node_foreach(node->r,func,udata); + return 0; +}; + +int +sx_radix_tree_foreach(struct sx_radix_tree* tree, + void (*func)(struct sx_radix_node*, void*), void* udata) +{ + if(!func || !tree || !tree->head) return 0; + sx_radix_node_foreach(tree->head,func,udata); + return 0; +}; + + + + +#if SX_PTREE_TEST +int +main() { + struct sx_prefix* p; + int n; + struct sx_radix_tree* tree; + struct sx_radix_node* node; + + p=sx_prefix_new(0,strdup("10.11.12.13/24")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("10.11.12.13/33")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("10.11.12.13/-133")); + sx_prefix_fprint(stdout,p); + printf("\n"); + + p=sx_prefix_new(AF_INET,strdup("10.11.12.14/24")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(AF_INET,strdup("10.11.12.14/33")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(AF_INET,strdup("10.11.12.14/-133")); + sx_prefix_fprint(stdout,p); + printf("\n"); + + p=sx_prefix_new(AF_INET6,strdup("10.11.12.15/24")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(AF_INET6,strdup("10.11.12.15/33")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(AF_INET6,strdup("10.11.12.15/-133")); + sx_prefix_fprint(stdout,p); + printf("\n"); + + p=sx_prefix_new(0,strdup("2001:1b00::/24")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("2001:1b00::/33")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("2001:1b00::/-133")); + sx_prefix_fprint(stdout,p); + printf("\n"); + + p=sx_prefix_new(AF_INET6,strdup("2001:1b01::/24")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(AF_INET6,strdup("2001:1b01::/33")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(AF_INET6,strdup("2001:1b01::/-133")); + sx_prefix_fprint(stdout,p); + printf("\n"); + +#define SX_TEST_EBITS(a,b,susp) n=sx_prefix_eqbits(sx_prefix_new(0,strdup(a)),\ + sx_prefix_new(0,strdup(b))); \ + if(n!=susp) printf("FAILED: %s eqbits %s=%i, not %i\n", a, b, n, susp);\ + else printf("OK, %s eqbits %s=%i, as suspected\n", a, b, n); + SX_TEST_EBITS("192.168.0.0/24","192.168.1.0/24",23); + SX_TEST_EBITS("192.168.0.0/32","192.168.0.1/32",31); +#if SX_LIBPTREE_IPV6 + SX_TEST_EBITS("2001:1b00::/32","2001:1b01::/32",31); +#endif + + p=sx_prefix_new(0,strdup("10.11.12.255/32")); + sx_prefix_fprint(stdout,p); + printf("\n31'th bit is %i\n",sx_prefix_isbitset(p,31)); + printf("32'th bit is %i\n",sx_prefix_isbitset(p,32)); + printf("33'th bit is %i\n",sx_prefix_isbitset(p,33)); + p=sx_prefix_new(0,strdup("10.11.12.255/31")); + sx_prefix_fprint(stdout,p); + printf("\n31'th bit is %i\n",sx_prefix_isbitset(p,31)); + printf("32'th bit is %i\n",sx_prefix_isbitset(p,32)); + printf("33'th bit is %i\n",sx_prefix_isbitset(p,33)); + p=sx_prefix_new(0,strdup("10.11.12.255/30")); + sx_prefix_fprint(stdout,p); + printf("\n31'th bit is %i\n",sx_prefix_isbitset(p,31)); + p=sx_prefix_new(0,strdup("10.11.12.255/29")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("10.11.12.255/28")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("10.11.12.255/27")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("10.11.12.255/26")); + sx_prefix_fprint(stdout,p); + printf("\n"); + p=sx_prefix_new(0,strdup("10.11.12.255/25")); + sx_prefix_fprint(stdout,p); + printf("\n25'th bit is %i\n",sx_prefix_isbitset(p,25)); + p=sx_prefix_new(0,strdup("10.11.12.255/24")); + sx_prefix_fprint(stdout,p); + printf("\n25'th bit is %i\n",sx_prefix_isbitset(p,25)); + + tree=sx_radix_tree_new(AF_INET); + sx_radix_tree_insert(tree,sx_prefix_new(0,"81.9.100.10/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.83/32")); + + sx_radix_tree_foreach(tree,sx_radix_node_fprintf,NULL); + + tree=sx_radix_tree_new(AF_INET); + sx_radix_tree_insert(tree,sx_prefix_new(0,"81.9.100.10/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.83/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.84/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.85/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.86/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.87/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.90/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.90/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"127.0.0.1/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"127.0.0.1/24")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"127.0.0.0/24")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"128.0.0.0/1")); + + sx_radix_tree_foreach(tree,sx_radix_node_fprintf,NULL); + + printf("lookup 1.1.1.1: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"1.1.1.1")); + sx_radix_node_fprintf(node,NULL); + + printf("lookup 217.170.80.90: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"217.170.80.90")); + sx_radix_node_fprintf(node,NULL); + + sx_radix_tree_unlink(tree,node); + printf("lookup 217.170.80.90 after delete: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"217.170.80.90")); + sx_radix_node_fprintf(node,NULL); + + sx_radix_tree_insert(tree,sx_prefix_new(0,"217.170.80.90/32")); + printf("lookup 217.170.80.90 after reinsert: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"217.170.80.90")); + sx_radix_node_fprintf(node,NULL); + + printf("lookup 217.170.80.81: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"217.170.80.81")); + sx_radix_node_fprintf(node,NULL); + + printf("lookup 127.0.0.1/24: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"127.0.0.1/24")); + sx_radix_node_fprintf(node,NULL); + + printf("lookup 127.0.0.1/26: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"127.0.0.1/26")); + sx_radix_node_fprintf(node,NULL); + + printf("lookup 127.0.0.1/23: "); + node=sx_radix_tree_lookup(tree,sx_prefix_new(0,"127.0.0.1/23")); + sx_radix_node_fprintf(node,NULL); + + tree=sx_radix_tree_new(AF_INET6); + sx_radix_tree_insert(tree,sx_prefix_new(0,"2100:1b00::/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"2100:1b01::/32")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"2100:1b00::/33")); + sx_radix_tree_insert(tree,sx_prefix_new(0,"2100:1b00::1/128")); + sx_radix_tree_foreach(tree,sx_radix_node_fprintf,NULL); + + return 0; +}; + +#endif diff --git a/sx_prefix.h b/sx_prefix.h new file mode 100644 index 0000000..206a110 --- /dev/null +++ b/sx_prefix.h @@ -0,0 +1,56 @@ +#ifndef _SX_PREFIX_H_ +#define _SX_PREFIX_H_ + +#include +#include +#include +#include + +typedef struct sx_prefix { + int family; + int masklen; + union { + struct in_addr addr; + struct in6_addr addr6; + unsigned char addrs[sizeof(struct in6_addr)]; + } addr; +} sx_prefix_t; + +typedef struct sx_radix_node { + struct sx_radix_node* parent, *l, *r; + void* payload; + int isGlue; + struct sx_prefix prefix; +} sx_radix_node_t; + +typedef struct sx_radix_tree { + int family; + struct sx_radix_node* head; +} sx_radix_tree_t; + +/* most common operations with the tree is to: lookup/insert/unlink */ +struct sx_radix_node* sx_radix_tree_lookup(struct sx_radix_tree* tree, + struct sx_prefix* prefix); +struct sx_radix_node* sx_radix_tree_insert(struct sx_radix_tree* tree, + struct sx_prefix* prefix); +void sx_radix_tree_unlink(struct sx_radix_tree* t, struct sx_radix_node* n); +struct sx_radix_node* sx_radix_tree_lookup_exact(struct sx_radix_tree* tree, + struct sx_prefix* prefix); + +struct sx_prefix* sx_prefix_alloc(struct sx_prefix* p); +void sx_prefix_destroy(struct sx_prefix* p); +void sx_prefix_adjust_masklen(struct sx_prefix* p); +struct sx_prefix* sx_prefix_new(int af, char* text); +int sx_prefix_parse(struct sx_prefix* p, int af, char* text); +int sx_prefix_fprint(FILE* f, struct sx_prefix* p); +int sx_prefix_snprintf(struct sx_prefix* p, char* rbuffer, int srb); +struct sx_radix_tree* sx_radix_tree_new(int af); +struct sx_radix_node* sx_radix_node_new(struct sx_prefix* prefix); +struct sx_prefix* sx_prefix_overlay(struct sx_prefix* p, int n); +void sx_radix_node_fprintf(struct sx_radix_node* node, void* udata); +int sx_radix_node_foreach(struct sx_radix_node* node, + void (*func)(struct sx_radix_node*, void*), void* udata); +int sx_radix_tree_foreach(struct sx_radix_tree* tree, + void (*func)(struct sx_radix_node*, void*), void* udata); + +#endif diff --git a/sx_report.c b/sx_report.c index f310036..7a32438 100644 --- a/sx_report.c +++ b/sx_report.c @@ -51,7 +51,7 @@ sx_report(sx_report_t t, char* fmt, ...) syslog(LOG_ERR,"ERROR: %s", buffer); break; case SX_NOTICE: - syslog(LOG_WARNING,"Warning: %s", buffer); + syslog(LOG_WARNING,"Notice: %s", buffer); break; case SX_DEBUG: syslog(LOG_DEBUG,"Debug: %s", buffer);