12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856 |
- /*
- Copyright (c) 2007 - 2010 RIPE NCC - All Rights Reserved
-
- Permission to use, copy, modify, and distribute this software and its
- documentation for any purpose and without fee is hereby granted, provided
- that the above copyright notice appear in all copies and that both that
- copyright notice and this permission notice appear in supporting
- documentation, and that the name of the author not be used in advertising or
- publicity pertaining to distribution of the software without specific,
- written prior permission.
-
- THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
- AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
- DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- Parts of this code have been engineered after analiyzing GNU Zebra's
- source code and therefore might contain declarations/code from GNU
- Zebra, Copyright (C) 1999 Kunihiro Ishiguro. Zebra is a free routing
- software, distributed under the GNU General Public License. A copy of
- this license is included with libbgpdump.
- Original Author: Shufu Mao(msf98@mails.tsinghua.edu.cn)
- */
- #include "bgpdump-config.h"
- #include "bgpdump_lib.h"
- #include "util.h"
- #include <time.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <netinet/in.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <stdbool.h>
- static void process(BGPDUMP_ENTRY *entry);
- static void process_bgpdump_mrtd_bgp(BGPDUMP_ENTRY *entry);
- static void show_ipv4_address(struct in_addr ip);
- static void show_attr(attributes_t *attr);
- static void show_prefixes(int count,struct prefix *prefix);
- static void table_line_announce_1(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
- static void table_line_announce(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
- static void mrtd_table_line_withdraw(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str);
- static void mrtd_table_line_announce(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str);
- static void table_line_withdraw(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
- static void table_line_mrtd_route(BGPDUMP_MRTD_TABLE_DUMP *route,BGPDUMP_ENTRY *entry);
- static void table_line_dump_v2_prefix(BGPDUMP_TABLE_DUMP_V2_PREFIX *e,BGPDUMP_ENTRY *entry);
- static char *describe_origin(int origin);
- static int bgp4mp_message_direction_receive(BGPDUMP_ENTRY *entry);
- #ifdef BGPDUMP_HAVE_IPV6
- void show_prefixes6(int count,struct prefix *prefix);
- static void table_line_withdraw6(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
- static void table_line_announce6(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
- #endif
- static void show_line_prefix(const char* format, const char* time_str, const char* type);
- /* If no aspath was present as a string in the packet, return an empty string
- * so everything stays machine parsable */
- static char *attr_aspath(attributes_t *a) {
- if(a->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATH) && a->aspath && a->aspath->str) {
- return a->aspath->str;
- }
- return "";
- }
- /* Helper function to return the direction of a BGP4MP_MESSAGE
- * returns true if it is a received message, false if it is a sent message */
- static int bgp4mp_message_direction_receive(BGPDUMP_ENTRY *entry) {
- switch(entry->subtype) {
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL:
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL:
- return 0;
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE:
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4:
- default:
- return 1;
- }
- }
- /* Helper function that returns the format of a BGP4MP_MESSAGE as a string:
- - BGP4MP (Standard)
- - BGP4MP_ET (Extended Header)
- - BGP4MP_LOCAL (Local)
- - BGP4MP_ET_LOCAL (Local and Extended Header)
- */
- static const char* get_bgp4mp_format(BGPDUMP_ENTRY *entry) {
- if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP_ET &&
- !bgp4mp_message_direction_receive(entry)) {
- return "BGP4MP_ET_LOCAL";
- } else if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP_ET) {
- return "BGP4MP_ET";
- } else if (!bgp4mp_message_direction_receive(entry)) {
- return "BGP4MP_LOCAL";
- } else {
- return "BGP4MP";
- }
- }
- static int mode=0;
- static int timetype=0;
- static int show_packet_index = 0;
- static int packet_index = 0;
- static const char USAGE[] = "\
- bgpdump version " PACKAGE_VERSION "\n\
- Usage: bgpdump [-m|-M] [-t dump|-t change] [-O <output-file>] <input-file>\n\
- bgpdump translates binary MRT files (possibly compressed) into readable output\n\
- Output mode:\n\
- -H multi-line, human-readable (the default)\n\
- -m one-line per entry with unix timestamps\n\
- -M one-line per entry with human readable timestamps\n\
- (there are other differences between -m and -M)\n\
- \n\
- Common options:\n\
- -O <file> output to <file> instead of STDOUT\n\
- -s log to syslog (the default)\n\
- -v log to STDERR\n\
- \n\
- Options for -m and -M modes:\n\
- -t dump timestamps for RIB dumps reflect the time of the dump (the default)\n\
- -t change timestamps for RIB dumps reflect the last route modification\n\
- -p show packet index at second position\n\
- \n\
- Special options:\n\
- -T run unit tests and exit\n\
- \n";
- extern char *optarg;
- extern int optind;
- int main(int argc, char *argv[]) {
-
- char c;
- int fd;
- bool usage_error = false;
- bool use_syslog = true;
-
- log_to_stderr();
-
- while ((c=getopt(argc,argv,"if:o:t:mMHO:svTp"))!=-1)
- switch(c)
- {
- case 'H':
- mode=0;
- break;
- case 'm':
- mode=1;
- break;
- case 'M':
- mode=2;
- break;
- case 't':
- if(strcmp(optarg,"dump")==0){
- timetype=0;
- } else if(strcmp(optarg,"change")==0){
- timetype=1;
- } else {
- printf("unknown -t option\n");
- exit(1);
- }
- break;
- case 'O':
- fprintf(stderr, "redirecting output to '%s'\n", optarg);
- fd = open(optarg, O_WRONLY|O_CREAT, 0666);
- if(fd < 0 || 0 > dup2(fd, STDOUT_FILENO)) {
- perror("can't open output file");
- exit(1);
- }
- break;
- case 's':
- use_syslog = true;
- break;
- case 'v':
- use_syslog = false;
- break;
- case 'i':
- case 'f':
- case 'o':
- warn("ignoring option '-%c'", c);
- break;
- case 'T':
- test_fmt_ip();
- test_utils();
- exit(0);
- case 'p':
- show_packet_index = 1;
- break;
- case '?':
- default:
- usage_error = true;
- }
- argc -= optind;
- argv += optind;
-
- if(use_syslog) {
- debug("logging to syslog");
- log_to_syslog();
- }
-
- if(usage_error || argc != 1) {
- if(argc != 1)
- err("you must supply exactly one file to process");
- fprintf(stderr, "%s", USAGE);
- exit(1);
- }
- // more efficient then line buffering
- // static char buffer[16000];
- // setbuffer(stdout, buffer, sizeof buffer);
-
- BGPDUMP *my_dump = bgpdump_open_dump(argv[0]);
- if(! my_dump)
- return 1;
-
- do {
- BGPDUMP_ENTRY *my_entry = bgpdump_read_next(my_dump);
- if(my_entry) {
- process(my_entry);
- bgpdump_free_mem(my_entry);
- packet_index++;
- }
- } while(my_dump->eof==0);
- bgpdump_close_dump(my_dump);
-
- return 0;
- }
- const char *bgp_state_name[] = {
- "Unknown",
- "Idle",
- "Connect",
- "Active",
- "Opensent",
- "Openconfirm",
- "Established",
- NULL
- };
- void process(BGPDUMP_ENTRY *entry) {
- struct tm *date;
- char time_str[128];
- char time_str2[128];
- char time_str_fixed[128];
- char prefix[BGPDUMP_ADDRSTRLEN];
- char *bgp4mp_format;
-
- date=gmtime(&entry->time);
- time2str(date,time_str_fixed);
-
- if (mode == 1) {
- // Timestamp mode
- sprintf(time_str, "%ld", entry->time);
- } else {
- time2str(date,time_str);
- }
- // Appending microseconds to time_str if needed
- if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP_ET) {
- sprintf(time_str, "%s.%06ld", time_str, entry->ms);
- }
-
- if (mode==0)
- {
- printf("TIME: %s\n", time_str);
- }
- //printf("TIME: %s",asctime(gmtime(&entry->time)));
- //printf("LENGTH : %u\n", entry->length);
- switch(entry->type) {
- case BGPDUMP_TYPE_MRTD_TABLE_DUMP:
- if(mode==0){
- const char *prefix_str = NULL;
- switch(entry->subtype){
- #ifdef BGPDUMP_HAVE_IPV6
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6:
- printf("TYPE: TABLE_DUMP/INET6\n");
- prefix_str = fmt_ipv6(entry->body.mrtd_table_dump.prefix,prefix);
- break;
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6_32BIT_AS:
- printf("TYPE: TABLE_DUMP/INET6_32BIT_AS\n");
- prefix_str = fmt_ipv6(entry->body.mrtd_table_dump.prefix,prefix);
- break;
- #endif
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP:
- printf("TYPE: TABLE_DUMP/INET\n");
- prefix_str = inet_ntoa(entry->body.mrtd_table_dump.prefix.v4_addr);
- break;
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP_32BIT_AS:
- printf("TYPE: TABLE_DUMP/INET_32BIT_AS\n");
- prefix_str = inet_ntoa(entry->body.mrtd_table_dump.prefix.v4_addr);
- break;
- default:
- printf("Error: unknown table type %d\n", entry->subtype);
- return;
- }
- printf("VIEW: %d\n",entry->body.mrtd_table_dump.view);
- printf("SEQUENCE: %d\n",entry->body.mrtd_table_dump.sequence);
- printf("PREFIX: %s/%d\n",prefix_str,entry->body.mrtd_table_dump.mask);
- printf("FROM:");
- switch(entry->subtype)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6:
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6_32BIT_AS:
- fmt_ipv6(entry->body.mrtd_table_dump.peer_ip,prefix);
- printf("%s ",prefix);
- break;
- #endif
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP:
- case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP_32BIT_AS:
- if (entry->body.mrtd_table_dump.peer_ip.v4_addr.s_addr != 0x00000000L)
- printf("%s ",inet_ntoa(entry->body.mrtd_table_dump.peer_ip.v4_addr));
- else
- printf("N/A ");
- }
- printf("AS%u\n",entry->body.mrtd_table_dump.peer_as);
- //printf("FROM: %s AS%d\n",inet_ntoa(entry->body.mrtd_table_dump.peer_ip.v4_addr),entry->body.mrtd_table_dump.peer_as);
- //time2str(localtime(&entry->body.mrtd_table_dump.uptime),time_str2);
- time2str(gmtime(&entry->body.mrtd_table_dump.uptime),time_str2);
- printf("ORIGINATED: %s\n",time_str2);
- if (entry->attr && entry->attr->len)
- show_attr(entry->attr);
- printf("STATUS: 0x%x\n",entry->body.mrtd_table_dump.status);
-
-
- //printf(" UPTIME : %s",asctime(gmtime(&entry->body.mrtd_table_dump.uptime)));
- //printf(" PEER IP : %s\n",inet_ntoa(entry->body.mrtd_table_dump.peer_ip));
- //printf(" PEER IP : %s\n",inet_ntoa(entry->body.mrtd_table_dump.peer_ip.v4_addr));
- //printf(" PEER AS : %d\n",entry->body.mrtd_table_dump.peer_as);
- }
- else if (mode ==1 || mode ==2) // -m -M
- {
- table_line_mrtd_route(&entry->body.mrtd_table_dump,entry);
- }
- break;
- case BGPDUMP_TYPE_TABLE_DUMP_V2:
- if(mode == 0){
- char peer_ip[BGPDUMP_ADDRSTRLEN];
- //char time_str[30];
- int i;
- BGPDUMP_TABLE_DUMP_V2_PREFIX *e;
- e = &entry->body.mrtd_table_dump_v2_prefix;
- if(e->afi == AFI_IP){
- strncpy(prefix, inet_ntoa(e->prefix.v4_addr), BGPDUMP_ADDRSTRLEN);
- #ifdef BGPDUMP_HAVE_IPV6
- } else if(e->afi == AFI_IP6){
- fmt_ipv6(e->prefix, prefix);
- #endif
- }
- for(i = 0; i < e->entry_count; i++){
- // This is slightly nasty - as we want to print multiple entries
- // for multiple peers, we may need to print another TIME ourselves
- if(i) printf("\nTIME: %s\n",time_str_fixed);
- if(e->afi == AFI_IP){
- printf("TYPE: TABLE_DUMP_V2/IPV4_UNICAST\n");
- #ifdef BGPDUMP_HAVE_IPV6
- } else if(e->afi == AFI_IP6){
- printf("TYPE: TABLE_DUMP_V2/IPV6_UNICAST\n");
- #endif
- }
- printf("PREFIX: %s/%d\n",prefix, e->prefix_length);
- printf("SEQUENCE: %d\n",e->seq);
- if(e->entries[i].peer->afi == AFI_IP){
- fmt_ipv4(e->entries[i].peer->peer_ip, peer_ip);
- #ifdef BGPDUMP_HAVE_IPV6
- } else if (e->entries[i].peer->afi == AFI_IP6){
- fmt_ipv6(e->entries[i].peer->peer_ip, peer_ip);
- #endif
- } else {
- sprintf(peer_ip, "[N/A, unsupported AF]");
- }
- printf("FROM: %s AS%u\n", peer_ip, e->entries[i].peer->peer_as);
- time_t time_temp = (time_t)((e->entries[i]).originated_time);
- time2str(gmtime(&time_temp),time_str);
- printf("ORIGINATED: %s\n",time_str);
- if (e->entries[i].attr && e->entries[i].attr->len)
- show_attr(e->entries[i].attr);
- }
- } else if (mode==1 || mode==2) { // -m -M
- table_line_dump_v2_prefix(&entry->body.mrtd_table_dump_v2_prefix,entry);
- }
- break;
- case BGPDUMP_TYPE_MRTD_BGP:
- process_bgpdump_mrtd_bgp(entry);
- break;
-
- case BGPDUMP_TYPE_ZEBRA_BGP:
- case BGPDUMP_TYPE_ZEBRA_BGP_ET:
- if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP) {
- bgp4mp_format = "BGP4MP";
- } else {
- bgp4mp_format = "BGP4MP_ET";
- }
-
- switch(entry->subtype)
- {
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE:
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4:
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL:
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL:
- switch(entry->body.zebra_message.type)
- {
- case BGP_MSG_UPDATE:
- if (mode ==0)
- {
- bgp4mp_message_direction_receive(entry)
- ? printf("TYPE: %s/MESSAGE/Update\n", bgp4mp_format)
- : printf("TYPE: %s/MESSAGE_LOCAL/Update\n", bgp4mp_format);
- if (entry->body.zebra_message.source_as)
- {
- printf("FROM:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.source_as);
- }
- if (entry->body.zebra_message.destination_as)
- {
- printf("TO:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.destination_as);
- }
- if (entry->attr && entry->attr->len)
- show_attr(entry->attr);
- if (entry->body.zebra_message.cut_bytes)
- {
- u_int16_t cutted,idx;
- u_int8_t buf[128];
-
- printf(" INCOMPLETE PACKET: %d bytes cutted\n",entry->body.zebra_message.cut_bytes);
- printf(" INCOMPLETE PART: ");
- if (entry->body.zebra_message.incomplete.orig_len)
- {
- cutted=entry->body.zebra_message.incomplete.prefix.len/8+1;
- buf[0]=entry->body.zebra_message.incomplete.orig_len;
- memcpy(buf+1,&entry->body.zebra_message.incomplete.prefix.address,cutted-1);
-
- for (idx=0;idx<cutted;idx++)
- {
- if (buf[idx]<0x10)
- printf("0%x ",buf[idx]);
- else
- printf("%x ",buf[idx]);
- }
- }
- printf("\n");
- }
- if(! entry->attr)
- return;
- if ((entry->body.zebra_message.withdraw_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))
- {
- #ifdef BGPDUMP_HAVE_IPV6
- if ((entry->body.zebra_message.withdraw_count)||(entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count) || (entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count) || (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count) ||(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count) || (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count) || (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count) )
- #else
- if ((entry->body.zebra_message.withdraw_count)||(entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count) || (entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count) || (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count))
- #endif
- printf("WITHDRAW\n");
- if (entry->body.zebra_message.withdraw_count)
- show_prefixes(entry->body.zebra_message.withdraw_count,entry->body.zebra_message.withdraw);
- if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count)
- show_prefixes(entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->nlri);
-
- if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count)
- show_prefixes(entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->nlri);
- if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
- show_prefixes(entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->nlri);
- #ifdef BGPDUMP_HAVE_IPV6
- if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count)
- show_prefixes6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->nlri);
-
- if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count)
- show_prefixes6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->nlri);
- if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
- show_prefixes6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->nlri);
- #endif
- }
- if ( (entry->body.zebra_message.announce_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)))
- {
- printf("ANNOUNCE\n");
- if (entry->body.zebra_message.announce_count)
- show_prefixes(entry->body.zebra_message.announce_count,entry->body.zebra_message.announce);
- if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->prefix_count)
- show_prefixes(entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nlri);
-
- if (entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->prefix_count)
- show_prefixes(entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nlri);
- if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
- show_prefixes(entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->nlri);
- #ifdef BGPDUMP_HAVE_IPV6
- if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->prefix_count)
- show_prefixes6(entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nlri);
-
- if (entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->prefix_count)
- show_prefixes6(entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nlri);
- if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
- show_prefixes6(entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->nlri);
- #endif
- }
- }
- else if (mode == 1 || mode == 2) //-m -M
- {
- if ((entry->body.zebra_message.withdraw_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))
- {
- table_line_withdraw(entry->body.zebra_message.withdraw,entry->body.zebra_message.withdraw_count,entry,time_str);
- if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count)
- table_line_withdraw(entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->nlri,entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count,entry,time_str);
- if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count)
- table_line_withdraw(entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->nlri,entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count,entry,time_str);
-
- if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
- table_line_withdraw(entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->nlri,entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count,entry,time_str);
- #ifdef BGPDUMP_HAVE_IPV6
- if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count)
- table_line_withdraw6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->nlri,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count,entry,time_str);
-
- if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count)
- table_line_withdraw6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->nlri,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count,entry,time_str);
-
- if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
- table_line_withdraw6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->nlri,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count,entry,time_str);
- #endif
-
- }
- if ( (entry->body.zebra_message.announce_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)))
- {
- table_line_announce(entry->body.zebra_message.announce,entry->body.zebra_message.announce_count,entry,time_str);
- if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->prefix_count)
- table_line_announce_1(entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST],entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->prefix_count,entry,time_str);
- if (entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->prefix_count)
- table_line_announce_1(entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST],entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->prefix_count,entry,time_str);
- if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
- table_line_announce_1(entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST],entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count,entry,time_str);
- #ifdef BGPDUMP_HAVE_IPV6
- if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->prefix_count)
- table_line_announce6(entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST],entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->prefix_count,entry,time_str);
- if (entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->prefix_count)
- table_line_announce6(entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST],entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->prefix_count,entry,time_str);
- if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
- table_line_announce6(entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST],entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count,entry,time_str);
- #endif
-
- }
- }
- break;
-
- case BGP_MSG_OPEN:
- if (mode != 0)
- break;
- bgp4mp_message_direction_receive(entry)
- ? printf("TYPE: %s/MESSAGE/Open\n", bgp4mp_format)
- : printf("TYPE: %s/MESSAGE_LOCAL/Open\n", bgp4mp_format);
- if (entry->body.zebra_message.source_as)
- {
- printf("FROM:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.source_as);
- }
- if (entry->body.zebra_message.destination_as)
- {
- printf("TO:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.destination_as);
- }
- printf("VERSION: %d\n",entry->body.zebra_message.version);
- printf("AS: %u\n",entry->body.zebra_message.my_as);
- printf("HOLD_TIME: %d\n",entry->body.zebra_message.hold_time);
- printf("ID: %s\n",inet_ntoa(entry->body.zebra_message.bgp_id));
- printf("OPT_PARM_LEN: %d\n",entry->body.zebra_message.opt_len);
- break;
-
- case BGP_MSG_NOTIFY:
- if (mode != 0)
- break;
- bgp4mp_message_direction_receive(entry)
- ? printf("TYPE: %s/MESSAGE/Notify\n", bgp4mp_format)
- : printf("TYPE: %s/MESSAGE_LOCAL/Notify\n", bgp4mp_format);
- if (entry->body.zebra_message.source_as)
- {
- printf("FROM:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.source_as);
- }
- if (entry->body.zebra_message.destination_as)
- {
- printf("TO:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.destination_as);
- }
- switch (entry->body.zebra_message.error_code)
- {
- case 1:
- printf(" ERROR CODE : 1 (Message Header Error)\n");
- switch(entry->body.zebra_message.sub_error_code)
- {
- case 1:
- printf(" SUB ERROR : 1 (Connection Not Synchronized)\n");
- break;
-
- case 2:
- printf(" SUB ERROR : 2 (Bad Message Length)\n");
- break;
- case 3:
- printf(" SUB ERROR : 3 (Bad Message Type)\n");
- break;
-
- default:
- printf(" SUB ERROR : %d\n",entry->body.zebra_message.sub_error_code);
- break;
- }
- break;
- case 2:
- printf(" ERROR CODE : 2 (OPEN Message Error)\n");
- switch(entry->body.zebra_message.sub_error_code)
- {
- case 1:
- printf(" SUB ERROR : 1 (Unsupported Version Number)\n");
- break;
-
- case 2:
- printf(" SUB ERROR : 2 (Bad Peer AS)\n");
- break;
- case 3:
- printf(" SUB ERROR : 3 (Bad BGP Identifier)\n");
- break;
-
- case 4:
- printf(" SUB ERROR : 4 (Unsupported Optional Parameter)\n");
- break;
- case 5:
- printf(" SUB ERROR : 5 (Authentication Failure)\n");
- break;
- case 6:
- printf(" SUB ERROR : 6 (Unacceptable Hold Time)\n");
- break;
-
- default:
- printf(" SUB ERROR : %d\n",entry->body.zebra_message.sub_error_code);
- break;
- }
- break;
- case 3:
- printf(" ERROR CODE : 3 (UPDATE Message Error)\n");
- switch(entry->body.zebra_message.sub_error_code)
- {
- case 1:
- printf(" SUB ERROR : 1 (Malformed Attribute List)\n");
- break;
-
- case 2:
- printf(" SUB ERROR : 2 (Unrecognized Well-known Attribute)\n");
- break;
- case 3:
- printf(" SUB ERROR : 3 (Missing Well-known Attribute)\n");
- break;
-
- case 4:
- printf(" SUB ERROR : 4 (Attribute Flags Error)\n");
- break;
- case 5:
- printf(" SUB ERROR : 5 (Attribute Length Error)\n");
- break;
- case 6:
- printf(" SUB ERROR : 6 (Invalid ORIGIN Attribute)\n");
- break;
-
- case 7:
- printf(" SUB ERROR : 7 (AS Routing Loop)\n");
- break;
-
- case 8:
- printf(" SUB ERROR : 8 (Invalid NEXT-HOP Attribute)\n");
- break;
- case 9:
- printf(" SUB ERROR : 9 (Optional Attribute Error)\n");
- break;
-
- case 10:
- printf(" SUB ERROR : 10 (Invalid Network Field)\n");
- break;
- case 11:
- printf(" SUB ERROR : 11 (Malformed AS-PATH)\n");
- break;
-
- default:
- printf(" SUB ERROR : %d\n",entry->body.zebra_message.sub_error_code);
- break;
- }
- break;
- case 4:
- printf(" ERROR CODE : 4 (Hold Timer Expired)\n");
- break;
- case 5:
- printf(" ERROR CODE : 5 (Finite State Machine Error)\n");
- break;
- case 6:
- printf(" ERROR CODE : 6 (Cease)\n");
- break;
- default:
- printf(" ERROR CODE : %d\n",entry->body.zebra_message.error_code);
- break;
-
- }
- break;
-
- case BGP_MSG_KEEPALIVE:
- if ( mode != 0)
- break;
- bgp4mp_message_direction_receive(entry)
- ? printf("TYPE: %s/MESSAGE/Keepalive\n", bgp4mp_format)
- : printf("TYPE: %s/MESSAGE_LOCAL/Keepalive\n", bgp4mp_format);
- if (entry->body.zebra_message.source_as)
- {
- printf("FROM:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.source_as);
- }
- if (entry->body.zebra_message.destination_as)
- {
- printf("TO:");
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
- else
- printf(" N/A ");
- }
- printf("AS%u\n",entry->body.zebra_message.destination_as);
- }
- break;
- }
- break;
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE:
- case BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE_AS4:
- if (mode==0)
- {
- printf("TYPE: %s/STATE_CHANGE\n", bgp4mp_format);
- printf("PEER:");
- switch(entry->body.zebra_state_change.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_state_change.source_ip,prefix);
- printf(" %s ",prefix);
- break;
- #endif
- case AFI_IP:
- default:
- if (entry->body.zebra_state_change.source_ip.v4_addr.s_addr != 0x00000000L)
- printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
- else
- printf(" N/A ");
- }
- //if (entry->body.zebra_message.source_ip.s_addr != 0x00000000L)
- // printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip));
- //else
- // printf(" N/A ");
- printf("AS%u\n",entry->body.zebra_state_change.source_as);
- printf("STATE: %s/%s\n",bgp_state_name[entry->body.zebra_state_change.old_state],bgp_state_name[entry->body.zebra_state_change.new_state]);
- }
- else if (mode==1 || mode==2 ) //-m -M
- {
- switch(entry->body.zebra_state_change.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- fmt_ipv6(entry->body.zebra_state_change.source_ip, prefix);
- break;
- #endif
- case AFI_IP:
- default:
- sprintf(prefix, "%s", inet_ntoa(entry->body.zebra_state_change.source_ip.v4_addr));
- break;
- }
- show_line_prefix(bgp4mp_format, time_str, "STATE");
- printf("%s|%u|%d|%d\n", prefix,
- entry->body.zebra_state_change.source_as,
- entry->body.zebra_state_change.old_state,
- entry->body.zebra_state_change.new_state);
-
- }
- break;
-
- }
- break;
- }
- if (mode==0)
- printf("\n");
- }
- // print line prefix with respect of mode and show_packet_index flags
- // output will have format:
- // format|[packet_index|]time|type|
- void show_line_prefix(const char* format, const char* time_str, const char* type)
- {
- printf("%s|", format);
- if (show_packet_index)
- printf("%d|", packet_index);
-
- printf("%s|%s|", time_str, type);
- }
- void process_bgpdump_mrtd_bgp(BGPDUMP_ENTRY *entry) {
- struct tm *date;
- char time_str[128];
- date=gmtime(&entry->time);
- if (mode == 1) {
- sprintf(time_str, "%ld", entry->time);
- } else {
-
- time2str(date, time_str);
- }
-
- switch (entry->subtype) {
- case BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE:
- case BGPDUMP_SUBTYPE_MRTD_BGP_KEEPALIVE:
- if (mode == 0) {
- if (entry->subtype == BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE)
- printf("TYPE: BGP/MESSAGE/Update\n");
- else
- printf("TYPE: BGP/MESSAGE/Keepalive\n");
- if (entry->body.mrtd_message.source_as) {
- printf("FROM:");
- show_ipv4_address(entry->body.mrtd_message.source_ip);
- printf("AS%u\n", entry->body.mrtd_message.source_as);
- }
- if (entry->body.mrtd_message.destination_as) {
- printf("TO:");
- show_ipv4_address(entry->body.mrtd_message.destination_ip);
- printf("AS%u\n", entry->body.mrtd_message.destination_as);
- }
- if (entry->attr && entry->attr->len)
- show_attr(entry->attr);
- if (entry->body.mrtd_message.withdraw_count) {
- printf("WITHDRAW\n");
- show_prefixes(entry->body.mrtd_message.withdraw_count, entry->body.mrtd_message.withdraw);
- }
- if (entry->body.mrtd_message.announce_count) {
- printf("ANNOUNCE\n");
- show_prefixes(entry->body.mrtd_message.announce_count, entry->body.mrtd_message.announce);
- }
- }
- else {
- if (entry->subtype != BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE)
- break;
- if (entry->body.mrtd_message.withdraw_count)
- mrtd_table_line_withdraw(entry->body.mrtd_message.withdraw, entry->body.mrtd_message.withdraw_count,
- entry, time_str);
- if (entry->body.mrtd_message.announce_count)
- mrtd_table_line_announce(entry->body.mrtd_message.announce, entry->body.mrtd_message.announce_count,
- entry, time_str);
- }
- break;
- case BGPDUMP_SUBTYPE_MRTD_BGP_STATE_CHANGE:
- if (mode == 0) {
- printf("TYPE: BGP/STATE_CHANGE\n");
- printf("PEER:");
- show_ipv4_address(entry->body.mrtd_state_change.destination_ip);
- printf("AS%u\n", entry->body.mrtd_state_change.destination_as);
- printf("STATE: %s/%s\n", bgp_state_name[entry->body.mrtd_state_change.old_state],
- bgp_state_name[entry->body.mrtd_state_change.new_state]);
- }
- else if (mode == 1 || mode == 2) {
- show_line_prefix("BGP", time_str, "STATE");
- printf("%s|%u|%d|%d\n",
- inet_ntoa(entry->body.mrtd_state_change.destination_ip),
- entry->body.mrtd_state_change.destination_as,
- entry->body.mrtd_state_change.old_state,
- entry->body.mrtd_state_change.new_state);
- }
- break;
- default:
- if (mode == 0) {
- printf("TYPE: Subtype %d not supported yet\n", entry->subtype);
- }
- }
- }
- void mrtd_table_line_withdraw(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str) {
- int i;
- for (i = 0; i < count; i++) {
- show_line_prefix("BGP", time_str, "W");
- printf("%s|%u|%s/%d\n", inet_ntoa(entry->body.mrtd_message.source_ip),
- entry->body.mrtd_message.source_as,
- inet_ntoa(prefix[i].address.v4_addr), prefix[i].len);
- }
- }
- void mrtd_table_line_announce(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str) {
- int i, npref, nmed;
- char *aggregate = entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE) ? "AG" : "NAG";
- for (i = 0; i < count; i++) {
- show_line_prefix("BGP", time_str, "A");
- printf("%s|%u", inet_ntoa(entry->body.mrtd_message.source_ip),
- entry->body.mrtd_message.source_as);
- printf("|%s/%d|%s|%s", inet_ntoa(prefix[i].address.v4_addr), prefix[i].len,
- attr_aspath(entry->attr), describe_origin(entry->attr->origin));
- if (mode == 1) {
- npref = ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) == 0) ? 0 : entry->attr->local_pref;
- nmed = ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) == 0) ? 0 : entry->attr->med;
- printf("|%s|%u|%u", inet_ntoa(entry->attr->nexthop), npref, nmed);
- if ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) != 0)
- printf("%s|%s|", entry->attr->community->str+1, aggregate);
- else
- printf("|%s|", aggregate);
-
- if (entry->attr->aggregator_addr.s_addr != -1)
- printf("%u %s|\n", entry->attr->aggregator_as, inet_ntoa(entry->attr->aggregator_addr));
- else
- printf("|\n");
- }
- else
- printf("\n");
- }
- }
- void show_ipv4_address(struct in_addr ip) {
- if (ip.s_addr != 0x00000000L)
- printf(" %s ", inet_ntoa(ip));
- else
- printf(" N/A ");
- }
- void show_attr(attributes_t *attr) {
-
- if(attr != NULL) {
- if( (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGIN) ) !=0 )
- {
- switch (attr->origin)
- {
- case 0:
- printf("ORIGIN: IGP\n");
- break;
- case 1:
- printf("ORIGIN: EGP\n");
- break;
- case 2:
- printf("ORIGIN: INCOMPLETE\n");
-
- }
-
- }
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATH) ) !=0)
- printf("ASPATH: %s\n",attr->aspath->str);
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP) ) !=0)
- printf("NEXT_HOP: %s\n",inet_ntoa(attr->nexthop));
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) !=0)
- printf("MULTI_EXIT_DISC: %u\n",attr->med);
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) !=0)
- printf("LOCAL_PREF: %u\n",attr->local_pref);
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE) ) !=0)
- printf("ATOMIC_AGGREGATE\n");
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR) ) !=0)
- printf("AGGREGATOR: AS%u %s\n",attr->aggregator_as,inet_ntoa(attr->aggregator_addr));
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID) ) !=0)
- printf("ORIGINATOR_ID: %s\n",inet_ntoa(attr->originator_id));
-
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST) ) !=0)
- {
- int cluster_index;
- printf("CLUSTER_LIST: ");
- for (cluster_index = 0;cluster_index<attr->cluster->length;cluster_index++)
- printf("%s ",inet_ntoa(attr->cluster->list[cluster_index]));
- printf("\n");
- }
- int idx;
- for (idx=0;idx<attr->unknown_num;idx++)
- {
- struct unknown_attr *unknown = attr->unknown + idx;
- printf(" UNKNOWN_ATTR(%i, %i, %i):", unknown->flag, unknown->type, unknown->len);
- int b;
- for(b = 0; b < unknown->len; ++b)
- printf(" %02x", unknown->raw[b]);
- printf("\n");
- }
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI) )!=0)
- {
- printf("MP_REACH_NLRI");
- #ifdef BGPDUMP_HAVE_IPV6
- if (attr->mp_info->announce[AFI_IP6][SAFI_UNICAST] || attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST] || attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST])
- {
- char buf[128];
-
- if (attr->mp_info->announce[AFI_IP6][SAFI_UNICAST])
- {
- printf("(IPv6 Unicast)\n");
- printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop,buf));
- if (attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop_len==32)
- printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop_local,buf));
- }
- else if (attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST])
- {
- printf("(IPv6 Multicast)\n");
- printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nexthop,buf));
- if (attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nexthop_len==32)
- printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nexthop_local,buf));
- }
- else
- {
- printf("(IPv6 Both unicast and multicast)\n");
- printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->nexthop,buf));
- if (attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->nexthop_len==32)
- printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->nexthop_local,buf));
- }
- }
- else
- #endif
- {
-
- if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST])
- {
- printf("(IPv4 Unicast)\n");
- printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nexthop.v4_addr));
- if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nexthop_len==32)
- printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nexthop_local.v4_addr));
-
- }
- else if (attr->mp_info->announce[AFI_IP][SAFI_MULTICAST])
- {
- printf("(IPv4 Multicast)\n");
- printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nexthop.v4_addr));
- if (attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nexthop_len==32)
- printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nexthop_local.v4_addr));
-
-
- }
- else if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST])
- {
- printf("(IPv4 Both unicast and multicast)\n");
- printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->nexthop.v4_addr));
- if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->nexthop_len==32)
- printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->nexthop_local.v4_addr));
-
- }
-
- }
- }
-
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI) )!=0)
- {
- printf("MP_UNREACH_NLRI");
- #ifdef BGPDUMP_HAVE_IPV6
- if (attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST] || attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST] || attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST])
- {
-
- if (attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST])
- {
- printf("(IPv6 Unicast)\n");
- }
- else if (attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST])
- {
- printf("(IPv6 Multicast)\n");
- }
- else
- {
- printf("(IPv6 Both unicast and multicast)\n");
- }
- }
- else
- #endif
- {
-
- if (attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST])
- {
- printf("(IPv4 Unicast)\n");
-
- }
- else if (attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST])
- {
- printf("(IPv4 Multicast)\n");
-
-
- }
- else if (attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST])
- {
- printf("(IPv4 Both unicast and multicast)\n");
-
- }
-
- }
- }
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
- printf("COMMUNITY:%s\n",attr->community->str);
- }
-
- }
- void show_prefixes(int count,struct prefix *prefix) {
- int i;
- for(i=0;i<count;i++)
- printf(" %s/%d\n",inet_ntoa(prefix[i].address.v4_addr),prefix[i].len);
- }
- #ifdef BGPDUMP_HAVE_IPV6
- void show_prefixes6(int count,struct prefix *prefix)
- {
- int i;
- char buf[128];
- for (i=0;i<count;i++)
- printf(" %s/%d\n",fmt_ipv6(prefix[i].address,buf),prefix[i].len);
- }
- #endif
- static void table_line_withdraw(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
- {
- int idx;
- char buf[128];
-
- for (idx=0;idx<count;idx++)
- {
- show_line_prefix(get_bgp4mp_format(entry), time_str, "W");
- switch(entry->body.zebra_message.address_family) {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",
- fmt_ipv6(entry->body.zebra_message.source_ip,buf),
- entry->body.zebra_message.source_as)
- : printf("%s|%u|",
- fmt_ipv6(entry->body.zebra_message.destination_ip,buf),
- entry->body.zebra_message.destination_as);
- break;
- #endif
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",
- inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),
- entry->body.zebra_message.source_as)
- : printf("%s|%u|",
- inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),
- entry->body.zebra_message.destination_as);
- break;
- }
- printf("%s/%d\n",inet_ntoa(prefix[idx].address.v4_addr),prefix[idx].len);
- }
- }
- #ifdef BGPDUMP_HAVE_IPV6
- static void table_line_withdraw6(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
- {
- int idx;
- char buf[128];
- char buf1[128];
- for (idx=0;idx<count;idx++)
- {
- show_line_prefix(get_bgp4mp_format(entry), time_str, "W");
- switch(entry->body.zebra_message.address_family) {
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|%s/%d\n",
- fmt_ipv6(entry->body.zebra_message.source_ip,buf1),
- entry->body.zebra_message.source_as,
- fmt_ipv6(prefix[idx].address,buf),prefix[idx].len)
- : printf("%s|%u|%s/%d\n",
- fmt_ipv6(entry->body.zebra_message.destination_ip,buf1),
- entry->body.zebra_message.destination_as,
- fmt_ipv6(prefix[idx].address,buf),prefix[idx].len);
- break;
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|%s/%d\n",
- fmt_ipv4(entry->body.zebra_message.source_ip,buf1),
- entry->body.zebra_message.source_as,
- fmt_ipv6(prefix[idx].address,buf),prefix[idx].len)
- : printf("%s|%u|%s/%d\n",
- fmt_ipv6(entry->body.zebra_message.destination_ip,buf1),
- entry->body.zebra_message.destination_as,
- fmt_ipv6(prefix[idx].address,buf),prefix[idx].len);
- break;
- }
- }
- }
- #endif
- static void table_line_announce(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
- {
- int idx ;
- char buf[128];
- char tmp2[20];
- unsigned int npref;
- unsigned int nmed;
- if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
- sprintf(tmp2,"AG");
- else
- sprintf(tmp2,"NAG");
- for (idx=0;idx<count;idx++)
- {
- show_line_prefix(get_bgp4mp_format(entry), time_str, "A");
- if (mode == 1)
- {
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
- : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
- break;
- #endif
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
- : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
- break;
- }
- printf("%s/%d|%s|%s|",inet_ntoa(prefix[idx].address.v4_addr),prefix[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
- npref=entry->attr->local_pref;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
- npref=0;
- nmed=entry->attr->med;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
- nmed=0;
-
- printf("%s|%u|%u|",inet_ntoa(entry->attr->nexthop),npref,nmed);
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
- printf("%s|%s|",entry->attr->community->str+1,tmp2);
- else
- printf("|%s|",tmp2);
-
- if (entry->attr->aggregator_addr.s_addr != -1)
- printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
- else
- printf("|\n");
- }
- else
- {
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
- : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
- break;
- #endif
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
- : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
- break;
- }
- printf("%s/%d|%s|%s\n",inet_ntoa(prefix[idx].address.v4_addr),prefix[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
-
- }
- }
- }
- static void table_line_announce_1(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
- {
- int idx ;
- char buf[128];
- char tmp2[20];
- unsigned int npref;
- unsigned int nmed;
- if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
- sprintf(tmp2,"AG");
- else
- sprintf(tmp2,"NAG");
- for (idx=0;idx<count;idx++)
- {
- show_line_prefix(get_bgp4mp_format(entry), time_str, "A");
- if (mode == 1)
- {
- if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI))
- {
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
- : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
- break;
- #endif
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
- : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
- break;
- }
- printf("%s/%d|%s|%s|",inet_ntoa(prefix->nlri[idx].address.v4_addr),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
- npref=entry->attr->local_pref;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
- npref=0;
- nmed=entry->attr->med;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
- nmed=0;
-
- printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),npref,nmed);
- //printf("%s|%d|%d|",inet_ntoa(prefix->nexthop.v4_addr),entry->attr->local_pref,entry->attr->med);
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
- printf("%s|%s|",entry->attr->community->str+1,tmp2);
- else
- printf("|%s|",tmp2);
- }
- else
- {
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
- : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
- break;
- #endif
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
- : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
- break;
- }
- printf("%s/%d|%s|%s|",inet_ntoa(prefix->nlri[idx].address.v4_addr),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
- npref=entry->attr->local_pref;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
- npref=0;
- nmed=entry->attr->med;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
- nmed=0;
-
- printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),npref,nmed);
- //printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),entry->attr->local_pref,entry->attr->med);
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
- printf("%s|%s|",entry->attr->community->str+1,tmp2);
- else
- printf("|%s|",tmp2);
- }
- if (entry->attr->aggregator_addr.s_addr != -1)
- printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
- else
- printf("|\n");
- }
- else
- {
- switch(entry->body.zebra_message.address_family)
- {
- #ifdef BGPDUMP_HAVE_IPV6
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
- : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
- break;
- #endif
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
- : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
- break;
- }
- printf("%s/%d|%s|%s\n",inet_ntoa(prefix->nlri[idx].address.v4_addr),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
-
- }
- }
- }
- #ifdef BGPDUMP_HAVE_IPV6
- static void table_line_announce6(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
- {
- int idx ;
- char buf[128];
- char buf1[128];
- char buf2[128];
- char tmp2[20];
- unsigned int npref;
- unsigned int nmed;
- if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
- sprintf(tmp2,"AG");
- else
- sprintf(tmp2,"NAG");
- for (idx=0;idx<count;idx++)
- {
- show_line_prefix(get_bgp4mp_format(entry), time_str, "A");
- if (mode == 1)
- {
- switch(entry->body.zebra_message.address_family)
- {
- case AFI_IP6:
-
- npref=entry->attr->local_pref;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
- npref=0;
- nmed=entry->attr->med;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
- nmed=0;
-
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|%s/%d|%s|%s|%s|%u|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf1),entry->body.zebra_message.source_as,fmt_ipv6(prefix->nlri[idx].address,buf2),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin),fmt_ipv6(prefix->nexthop,buf),npref,nmed)
- : printf("%s|%u|%s/%d|%s|%s|%s|%u|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf1),entry->body.zebra_message.destination_as,fmt_ipv6(prefix->nlri[idx].address,buf2),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin),fmt_ipv6(prefix->nexthop,buf),npref,nmed);
- break;
- case AFI_IP:
- default:
- npref=entry->attr->local_pref;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
- npref=0;
- nmed=entry->attr->med;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
- nmed=0;
-
- //printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),nprof,nmed);
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|%s/%d|%s|%s|%s|%u|%u|",fmt_ipv4(entry->body.zebra_message.source_ip,buf1),entry->body.zebra_message.source_as,fmt_ipv6(prefix->nlri[idx].address,buf2),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin),fmt_ipv6(prefix->nexthop,buf),npref,nmed)
- : printf("%s|%u|%s/%d|%s|%s|%s|%u|%u|",fmt_ipv4(entry->body.zebra_message.destination_ip,buf1),entry->body.zebra_message.destination_as,fmt_ipv6(prefix->nlri[idx].address,buf2),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin),fmt_ipv6(prefix->nexthop,buf),npref,nmed);
- break;
- }
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
- printf("%s|%s|",entry->attr->community->str+1,tmp2);
- else
- printf("|%s|",tmp2);
- if (entry->attr->aggregator_addr.s_addr != -1)
- printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
- else
- printf("|\n");
- }
- else
- {
- switch(entry->body.zebra_message.address_family)
- {
- case AFI_IP6:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|%s/%d|%s|%s\n",fmt_ipv6(entry->body.zebra_message.source_ip,buf1),entry->body.zebra_message.source_as,fmt_ipv6(prefix->nlri[idx].address,buf),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin))
- : printf("%s|%u|%s/%d|%s|%s\n",fmt_ipv6(entry->body.zebra_message.destination_ip,buf1),entry->body.zebra_message.destination_as,fmt_ipv6(prefix->nlri[idx].address,buf),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
- break;
- case AFI_IP:
- default:
- bgp4mp_message_direction_receive(entry)
- ? printf("%s|%u|%s/%d|%s|%s\n",fmt_ipv4(entry->body.zebra_message.source_ip,buf1),entry->body.zebra_message.source_as,fmt_ipv6(prefix->nlri[idx].address,buf),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin))
- : printf("%s|%u|%s/%d|%s|%s\n",fmt_ipv4(entry->body.zebra_message.destination_ip,buf1),entry->body.zebra_message.destination_as,fmt_ipv6(prefix->nlri[idx].address,buf),prefix->nlri[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
- break;
- }
- }
- }
- }
- #endif
- static void table_line_mrtd_route(BGPDUMP_MRTD_TABLE_DUMP *route,BGPDUMP_ENTRY *entry)
- {
-
- struct tm *date = NULL;
- char tmp2[20];
- unsigned int npref;
- unsigned int nmed;
- char time_str[20];
- char peer[BGPDUMP_ADDRSTRLEN], prefix[BGPDUMP_ADDRSTRLEN], nexthop[BGPDUMP_ADDRSTRLEN];
- if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
- sprintf(tmp2,"AG");
- else
- sprintf(tmp2,"NAG");
- time_t *t;
- if (timetype==0) {
- t = &entry->time;
- } else {
- t = &route->uptime;
- }
- if (mode == 1) {
- sprintf(time_str, "%ld", *t);
- } else {
- date=gmtime(t);
- time2str(date, time_str);
- }
- show_line_prefix("TABLE_DUMP", time_str, "B");
- #ifdef BGPDUMP_HAVE_IPV6
- if (entry->subtype == AFI_IP6)
- {
- fmt_ipv6(route->peer_ip,peer);
- fmt_ipv6(route->prefix,prefix);
- }
- else
- #endif
- {
- strncpy(peer, inet_ntoa(route->peer_ip.v4_addr), BGPDUMP_ADDRSTRLEN);
- strncpy(prefix, inet_ntoa(route->prefix.v4_addr), BGPDUMP_ADDRSTRLEN);
- }
- if (mode == 1)
- {
- printf("%s|%u|",peer,route->peer_as);
- printf("%s/%d|%s|%s|",prefix,route->mask,
- attr_aspath(entry->attr),describe_origin(entry->attr->origin));
- npref=entry->attr->local_pref;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
- npref=0;
- nmed=entry->attr->med;
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
- nmed=0;
-
- #ifdef BGPDUMP_HAVE_IPV6
- if ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST])
- {
- fmt_ipv6(entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop,nexthop);
- }
- else
- #endif
- {
- strncpy(nexthop, inet_ntoa(entry->attr->nexthop), BGPDUMP_ADDRSTRLEN);
- }
- printf("%s|%u|%u|",nexthop,npref,nmed);
- if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
- printf("%s|%s|",entry->attr->community->str+1,tmp2);
- else
- printf("|%s|",tmp2);
-
- if (entry->attr->aggregator_addr.s_addr != -1)
- printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
- else
- printf("|\n");
- }
- else
- {
- printf("%s|%u|",peer,route->peer_as);
- printf("%s/%d|%s|%s\n",prefix,route->mask,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
- }
- }
- static char *describe_origin(int origin) {
- if(origin == 0) return "IGP";
- if(origin == 1) return "EGP";
- return "INCOMPLETE";
- }
- static void table_line_dump_v2_prefix(BGPDUMP_TABLE_DUMP_V2_PREFIX *e,BGPDUMP_ENTRY *entry)
- {
- struct tm *date = NULL;
- unsigned int npref;
- unsigned int nmed;
- char time_str[20];
- char peer[BGPDUMP_ADDRSTRLEN], prefix[BGPDUMP_ADDRSTRLEN], nexthop[BGPDUMP_ADDRSTRLEN];
-
- int i;
-
- for(i = 0; i < e->entry_count; i++) {
- attributes_t *attr = e->entries[i].attr;
- if(! attr)
- continue;
-
- char *origin = describe_origin(attr->origin);
- char *aspath_str = (attr->aspath) ? attr->aspath->str: "";
- char *aggregate = attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE) ? "AG" : "NAG";
-
- if(e->entries[i].peer->afi == AFI_IP){
- fmt_ipv4(e->entries[i].peer->peer_ip, peer);
- #ifdef BGPDUMP_HAVE_IPV6
- } else if(e->entries[i].peer->afi == AFI_IP6){
- fmt_ipv6(e->entries[i].peer->peer_ip, peer);
- #endif
- }
-
- if(e->afi == AFI_IP) {
- fmt_ipv4(e->prefix, prefix);
- #ifdef BGPDUMP_HAVE_IPV6
- } else if(e->afi == AFI_IP6) {
- fmt_ipv6(e->prefix, prefix);
- #endif
- }
- time_t *t;
- if (timetype==0) {
- t = &entry->time;
- } else {
- time_t tmp = (time_t)((e->entries[i]).originated_time);
- t = &tmp;
- }
- if (mode == 1) {
- sprintf(time_str, "%ld", *t);
- } else {
- date=gmtime(t);
- time2str(date, time_str);
- }
- show_line_prefix("TABLE_DUMP2", time_str, "B");
-
- if (mode == 1)
- {
- printf("%s|%u|",peer,e->entries[i].peer->peer_as);
- printf("%s/%d|%s|%s|",prefix,e->prefix_length,aspath_str,origin);
-
- npref=attr->local_pref;
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
- npref=0;
- nmed=attr->med;
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
- nmed=0;
-
- #ifdef BGPDUMP_HAVE_IPV6
- if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) && attr->mp_info->announce[AFI_IP6][SAFI_UNICAST])
- {
- fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop,nexthop);
- }
- else
- #endif
- {
- strncpy(nexthop, inet_ntoa(attr->nexthop), BGPDUMP_ADDRSTRLEN);
- }
- printf("%s|%u|%u|",nexthop,npref,nmed);
-
- if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
- printf("%s|%s|",attr->community->str+1,aggregate);
- else
- printf("|%s|",aggregate);
-
- if (attr->aggregator_addr.s_addr != -1)
- printf("%u %s|\n",attr->aggregator_as,inet_ntoa(attr->aggregator_addr));
- else
- printf("|\n");
- }
- else
- {
- printf("%s|%u|",peer,e->entries[i].peer->peer_as);
- printf("%s/%d|%s|%s\n",prefix,e->prefix_length,aspath_str,origin);
-
- }
- }
-
- }
|