#if HAVE_CONFIG_H #include #endif #include #include #include /* memset() */ #include "../types/types.h" #include "../integrat/readbgp.h" #include "../integrat/subnet.h" #include "../wattcp/tcp.h" /* inet_addr() inet_ntoa() */ #include "../dpmi32/flat.h" #include "../intel/byteswap.h" /* ntohl() htonl() */ #define MAX_ADDRESS_LENGTH 1000 #define MAX_AS 65535 Bit32 *exit_as_subnets; Bit32 *src_as_subnets; /* called by WalkSubnetsRecurse twice per routing, * once before recursion and once after * * returns TRUE if successful, FALSE if failure * (FALSE causes recursion to stop) * * never fails because it doesn't use up any resource * (wouldn't get called if arrays couldn't be allocated) * * uses global variables instead of the argument pointer * that PrintSubnetsHelper() in SUBNET.C uses */ #pragma warn -par static boolean accumulate_as_helper( boolean is_before, Subnet *external, void *unused_args ) { /* only do add up the array once per routing table line */ if( !is_before ) { exit_as_subnets[ external->exit_as ]++; src_as_subnets[ external->src_as ]++; } return TRUE; } #pragma warn .par void accumulate_as_stats( void ) { boolean result; Bit32 count; Bit32 used; /* allocate the arrays */ exit_as_subnets = (Bit32 *) flat_alloc( sizeof(Bit32)*MAX_AS ); if( !exit_as_subnets ) { fprintf( stderr, "cannot allocate exit AS counters\n" ); return; } src_as_subnets = (Bit32 *) flat_alloc( sizeof(Bit32)*MAX_AS ); if( !src_as_subnets ) { fprintf( stderr, "cannot allocate exit AS counters\n" ); flat_free( exit_as_subnets ); return; } /* initialize all counters to zero */ memset( exit_as_subnets, 0, sizeof(Bit32)*MAX_AS ); memset( src_as_subnets, 0, sizeof(Bit32)*MAX_AS ); /* walk the radix trie and fill in both arrays */ result = WalkSubnets( accumulate_as_helper, NULL ); if( !result ) { fprintf( stderr, "couldn't walk radix trie\n" ); flat_free( src_as_subnets ); flat_free( exit_as_subnets ); return; } /* print out the counts of routing table lines per exit AS */ fprintf( stdout, "\nexit AS : count of preferred subnets\n" ); used = 0; for( count=0; countline); */ fprintf( stdout, "net=%s/%d ", inet_ntoa(temp,ntohl(my_subnet->addr)), bits_in_mask(my_subnet->mask) ); /* fprintf( stdout, "mask=%s ", inet_ntoa(temp,ntohl(my_subnet->mask)) ); */ fprintf( stdout, "nexthop_ip=%s ", inet_ntoa(temp,my_subnet->nexthop_addr) ); /* fprintf( stdout, "exit_as=%d source_as=%d ", my_subnet->exit_as, my_subnet->src_as ); */ fprintf( stdout, "AS_path='%s' IP=%s", #if !NF_OCX_BGP my_subnet->as_path, #else "<>", #endif my_address_string ); } return 0; }