bgpdump.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  1. /*
  2. Copyright (c) 2007 - 2010 RIPE NCC - All Rights Reserved
  3. Permission to use, copy, modify, and distribute this software and its
  4. documentation for any purpose and without fee is hereby granted, provided
  5. that the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation, and that the name of the author not be used in advertising or
  8. publicity pertaining to distribution of the software without specific,
  9. written prior permission.
  10. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  11. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  12. AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  13. DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  14. AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. Parts of this code have been engineered after analiyzing GNU Zebra's
  17. source code and therefore might contain declarations/code from GNU
  18. Zebra, Copyright (C) 1999 Kunihiro Ishiguro. Zebra is a free routing
  19. software, distributed under the GNU General Public License. A copy of
  20. this license is included with libbgpdump.
  21. Original Author: Shufu Mao(msf98@mails.tsinghua.edu.cn)
  22. */
  23. #include "bgpdump-config.h"
  24. #include "bgpdump_lib.h"
  25. #include "util.h"
  26. #include <time.h>
  27. #include <unistd.h>
  28. #include <fcntl.h>
  29. #include <stdlib.h>
  30. #include <netinet/in.h>
  31. #include <sys/socket.h>
  32. #include <arpa/inet.h>
  33. #include <stdbool.h>
  34. static void process(BGPDUMP_ENTRY *entry);
  35. static void process_bgpdump_mrtd_bgp(BGPDUMP_ENTRY *entry);
  36. static void show_ipv4_address(struct in_addr ip);
  37. static void show_attr(attributes_t *attr);
  38. static void show_prefixes(int count,struct prefix *prefix);
  39. static void table_line_announce_1(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
  40. static void table_line_announce(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
  41. static void mrtd_table_line_withdraw(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str);
  42. static void mrtd_table_line_announce(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str);
  43. static void table_line_withdraw(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
  44. static void table_line_mrtd_route(BGPDUMP_MRTD_TABLE_DUMP *route,BGPDUMP_ENTRY *entry);
  45. static void table_line_dump_v2_prefix(BGPDUMP_TABLE_DUMP_V2_PREFIX *e,BGPDUMP_ENTRY *entry);
  46. static char *describe_origin(int origin);
  47. static int bgp4mp_message_direction_receive(BGPDUMP_ENTRY *entry);
  48. #ifdef BGPDUMP_HAVE_IPV6
  49. void show_prefixes6(int count,struct prefix *prefix);
  50. static void table_line_withdraw6(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
  51. static void table_line_announce6(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str);
  52. #endif
  53. static void show_line_prefix(const char* format, const char* time_str, const char* type);
  54. /* If no aspath was present as a string in the packet, return an empty string
  55. * so everything stays machine parsable */
  56. static char *attr_aspath(attributes_t *a) {
  57. if(a->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATH) && a->aspath && a->aspath->str) {
  58. return a->aspath->str;
  59. }
  60. return "";
  61. }
  62. /* Helper function to return the direction of a BGP4MP_MESSAGE
  63. * returns true if it is a received message, false if it is a sent message */
  64. static int bgp4mp_message_direction_receive(BGPDUMP_ENTRY *entry) {
  65. switch(entry->subtype) {
  66. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL:
  67. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL:
  68. return 0;
  69. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE:
  70. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4:
  71. default:
  72. return 1;
  73. }
  74. }
  75. /* Helper function that returns the format of a BGP4MP_MESSAGE as a string:
  76. - BGP4MP (Standard)
  77. - BGP4MP_ET (Extended Header)
  78. - BGP4MP_LOCAL (Local)
  79. - BGP4MP_ET_LOCAL (Local and Extended Header)
  80. */
  81. static const char* get_bgp4mp_format(BGPDUMP_ENTRY *entry) {
  82. if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP_ET &&
  83. !bgp4mp_message_direction_receive(entry)) {
  84. return "BGP4MP_ET_LOCAL";
  85. } else if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP_ET) {
  86. return "BGP4MP_ET";
  87. } else if (!bgp4mp_message_direction_receive(entry)) {
  88. return "BGP4MP_LOCAL";
  89. } else {
  90. return "BGP4MP";
  91. }
  92. }
  93. static int mode=0;
  94. static int timetype=0;
  95. static int show_packet_index = 0;
  96. static int packet_index = 0;
  97. static const char USAGE[] = "\
  98. bgpdump version " PACKAGE_VERSION "\n\
  99. Usage: bgpdump [-m|-M] [-t dump|-t change] [-O <output-file>] <input-file>\n\
  100. bgpdump translates binary MRT files (possibly compressed) into readable output\n\
  101. Output mode:\n\
  102. -H multi-line, human-readable (the default)\n\
  103. -m one-line per entry with unix timestamps\n\
  104. -M one-line per entry with human readable timestamps\n\
  105. (there are other differences between -m and -M)\n\
  106. \n\
  107. Common options:\n\
  108. -O <file> output to <file> instead of STDOUT\n\
  109. -s log to syslog (the default)\n\
  110. -v log to STDERR\n\
  111. \n\
  112. Options for -m and -M modes:\n\
  113. -t dump timestamps for RIB dumps reflect the time of the dump (the default)\n\
  114. -t change timestamps for RIB dumps reflect the last route modification\n\
  115. -p show packet index at second position\n\
  116. \n\
  117. Special options:\n\
  118. -T run unit tests and exit\n\
  119. \n";
  120. extern char *optarg;
  121. extern int optind;
  122. int main(int argc, char *argv[]) {
  123. char c;
  124. int fd;
  125. bool usage_error = false;
  126. bool use_syslog = true;
  127. log_to_stderr();
  128. while ((c=getopt(argc,argv,"if:o:t:mMHO:svTp"))!=-1)
  129. switch(c)
  130. {
  131. case 'H':
  132. mode=0;
  133. break;
  134. case 'm':
  135. mode=1;
  136. break;
  137. case 'M':
  138. mode=2;
  139. break;
  140. case 't':
  141. if(strcmp(optarg,"dump")==0){
  142. timetype=0;
  143. } else if(strcmp(optarg,"change")==0){
  144. timetype=1;
  145. } else {
  146. printf("unknown -t option\n");
  147. exit(1);
  148. }
  149. break;
  150. case 'O':
  151. fprintf(stderr, "redirecting output to '%s'\n", optarg);
  152. fd = open(optarg, O_WRONLY|O_CREAT, 0666);
  153. if(fd < 0 || 0 > dup2(fd, STDOUT_FILENO)) {
  154. perror("can't open output file");
  155. exit(1);
  156. }
  157. break;
  158. case 's':
  159. use_syslog = true;
  160. break;
  161. case 'v':
  162. use_syslog = false;
  163. break;
  164. case 'i':
  165. case 'f':
  166. case 'o':
  167. warn("ignoring option '-%c'", c);
  168. break;
  169. case 'T':
  170. test_fmt_ip();
  171. test_utils();
  172. exit(0);
  173. case 'p':
  174. show_packet_index = 1;
  175. break;
  176. case '?':
  177. default:
  178. usage_error = true;
  179. }
  180. argc -= optind;
  181. argv += optind;
  182. if(use_syslog) {
  183. debug("logging to syslog");
  184. log_to_syslog();
  185. }
  186. if(usage_error || argc != 1) {
  187. if(argc != 1)
  188. err("you must supply exactly one file to process");
  189. fprintf(stderr, "%s", USAGE);
  190. exit(1);
  191. }
  192. // more efficient then line buffering
  193. // static char buffer[16000];
  194. // setbuffer(stdout, buffer, sizeof buffer);
  195. BGPDUMP *my_dump = bgpdump_open_dump(argv[0]);
  196. if(! my_dump)
  197. return 1;
  198. do {
  199. BGPDUMP_ENTRY *my_entry = bgpdump_read_next(my_dump);
  200. if(my_entry) {
  201. process(my_entry);
  202. bgpdump_free_mem(my_entry);
  203. packet_index++;
  204. }
  205. } while(my_dump->eof==0);
  206. bgpdump_close_dump(my_dump);
  207. return 0;
  208. }
  209. const char *bgp_state_name[] = {
  210. "Unknown",
  211. "Idle",
  212. "Connect",
  213. "Active",
  214. "Opensent",
  215. "Openconfirm",
  216. "Established",
  217. NULL
  218. };
  219. void process(BGPDUMP_ENTRY *entry) {
  220. struct tm *date;
  221. char time_str[128];
  222. char time_str2[128];
  223. char time_str_fixed[128];
  224. char prefix[BGPDUMP_ADDRSTRLEN];
  225. char *bgp4mp_format;
  226. date=gmtime(&entry->time);
  227. time2str(date,time_str_fixed);
  228. if (mode == 1) {
  229. // Timestamp mode
  230. sprintf(time_str, "%ld", entry->time);
  231. } else {
  232. time2str(date,time_str);
  233. }
  234. // Appending microseconds to time_str if needed
  235. if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP_ET) {
  236. sprintf(time_str, "%s.%06ld", time_str, entry->ms);
  237. }
  238. if (mode==0)
  239. {
  240. printf("TIME: %s\n", time_str);
  241. }
  242. //printf("TIME: %s",asctime(gmtime(&entry->time)));
  243. //printf("LENGTH : %u\n", entry->length);
  244. switch(entry->type) {
  245. case BGPDUMP_TYPE_MRTD_TABLE_DUMP:
  246. if(mode==0){
  247. const char *prefix_str = NULL;
  248. switch(entry->subtype){
  249. #ifdef BGPDUMP_HAVE_IPV6
  250. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6:
  251. printf("TYPE: TABLE_DUMP/INET6\n");
  252. prefix_str = fmt_ipv6(entry->body.mrtd_table_dump.prefix,prefix);
  253. break;
  254. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6_32BIT_AS:
  255. printf("TYPE: TABLE_DUMP/INET6_32BIT_AS\n");
  256. prefix_str = fmt_ipv6(entry->body.mrtd_table_dump.prefix,prefix);
  257. break;
  258. #endif
  259. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP:
  260. printf("TYPE: TABLE_DUMP/INET\n");
  261. prefix_str = inet_ntoa(entry->body.mrtd_table_dump.prefix.v4_addr);
  262. break;
  263. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP_32BIT_AS:
  264. printf("TYPE: TABLE_DUMP/INET_32BIT_AS\n");
  265. prefix_str = inet_ntoa(entry->body.mrtd_table_dump.prefix.v4_addr);
  266. break;
  267. default:
  268. printf("Error: unknown table type %d\n", entry->subtype);
  269. return;
  270. }
  271. printf("VIEW: %d\n",entry->body.mrtd_table_dump.view);
  272. printf("SEQUENCE: %d\n",entry->body.mrtd_table_dump.sequence);
  273. printf("PREFIX: %s/%d\n",prefix_str,entry->body.mrtd_table_dump.mask);
  274. printf("FROM:");
  275. switch(entry->subtype)
  276. {
  277. #ifdef BGPDUMP_HAVE_IPV6
  278. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6:
  279. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6_32BIT_AS:
  280. fmt_ipv6(entry->body.mrtd_table_dump.peer_ip,prefix);
  281. printf("%s ",prefix);
  282. break;
  283. #endif
  284. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP:
  285. case BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP_32BIT_AS:
  286. if (entry->body.mrtd_table_dump.peer_ip.v4_addr.s_addr != 0x00000000L)
  287. printf("%s ",inet_ntoa(entry->body.mrtd_table_dump.peer_ip.v4_addr));
  288. else
  289. printf("N/A ");
  290. }
  291. printf("AS%u\n",entry->body.mrtd_table_dump.peer_as);
  292. //printf("FROM: %s AS%d\n",inet_ntoa(entry->body.mrtd_table_dump.peer_ip.v4_addr),entry->body.mrtd_table_dump.peer_as);
  293. //time2str(localtime(&entry->body.mrtd_table_dump.uptime),time_str2);
  294. time2str(gmtime(&entry->body.mrtd_table_dump.uptime),time_str2);
  295. printf("ORIGINATED: %s\n",time_str2);
  296. if (entry->attr && entry->attr->len)
  297. show_attr(entry->attr);
  298. printf("STATUS: 0x%x\n",entry->body.mrtd_table_dump.status);
  299. //printf(" UPTIME : %s",asctime(gmtime(&entry->body.mrtd_table_dump.uptime)));
  300. //printf(" PEER IP : %s\n",inet_ntoa(entry->body.mrtd_table_dump.peer_ip));
  301. //printf(" PEER IP : %s\n",inet_ntoa(entry->body.mrtd_table_dump.peer_ip.v4_addr));
  302. //printf(" PEER AS : %d\n",entry->body.mrtd_table_dump.peer_as);
  303. }
  304. else if (mode ==1 || mode ==2) // -m -M
  305. {
  306. table_line_mrtd_route(&entry->body.mrtd_table_dump,entry);
  307. }
  308. break;
  309. case BGPDUMP_TYPE_TABLE_DUMP_V2:
  310. if(mode == 0){
  311. char peer_ip[BGPDUMP_ADDRSTRLEN];
  312. //char time_str[30];
  313. int i;
  314. BGPDUMP_TABLE_DUMP_V2_PREFIX *e;
  315. e = &entry->body.mrtd_table_dump_v2_prefix;
  316. if(e->afi == AFI_IP){
  317. strncpy(prefix, inet_ntoa(e->prefix.v4_addr), BGPDUMP_ADDRSTRLEN);
  318. #ifdef BGPDUMP_HAVE_IPV6
  319. } else if(e->afi == AFI_IP6){
  320. fmt_ipv6(e->prefix, prefix);
  321. #endif
  322. }
  323. for(i = 0; i < e->entry_count; i++){
  324. // This is slightly nasty - as we want to print multiple entries
  325. // for multiple peers, we may need to print another TIME ourselves
  326. if(i) printf("\nTIME: %s\n",time_str_fixed);
  327. if(e->afi == AFI_IP){
  328. printf("TYPE: TABLE_DUMP_V2/IPV4_UNICAST\n");
  329. #ifdef BGPDUMP_HAVE_IPV6
  330. } else if(e->afi == AFI_IP6){
  331. printf("TYPE: TABLE_DUMP_V2/IPV6_UNICAST\n");
  332. #endif
  333. }
  334. printf("PREFIX: %s/%d\n",prefix, e->prefix_length);
  335. printf("SEQUENCE: %d\n",e->seq);
  336. if(e->entries[i].peer->afi == AFI_IP){
  337. fmt_ipv4(e->entries[i].peer->peer_ip, peer_ip);
  338. #ifdef BGPDUMP_HAVE_IPV6
  339. } else if (e->entries[i].peer->afi == AFI_IP6){
  340. fmt_ipv6(e->entries[i].peer->peer_ip, peer_ip);
  341. #endif
  342. } else {
  343. sprintf(peer_ip, "[N/A, unsupported AF]");
  344. }
  345. printf("FROM: %s AS%u\n", peer_ip, e->entries[i].peer->peer_as);
  346. time_t time_temp = (time_t)((e->entries[i]).originated_time);
  347. time2str(gmtime(&time_temp),time_str);
  348. printf("ORIGINATED: %s\n",time_str);
  349. if (e->entries[i].attr && e->entries[i].attr->len)
  350. show_attr(e->entries[i].attr);
  351. }
  352. } else if (mode==1 || mode==2) { // -m -M
  353. table_line_dump_v2_prefix(&entry->body.mrtd_table_dump_v2_prefix,entry);
  354. }
  355. break;
  356. case BGPDUMP_TYPE_MRTD_BGP:
  357. process_bgpdump_mrtd_bgp(entry);
  358. break;
  359. case BGPDUMP_TYPE_ZEBRA_BGP:
  360. case BGPDUMP_TYPE_ZEBRA_BGP_ET:
  361. if (entry->type == BGPDUMP_TYPE_ZEBRA_BGP) {
  362. bgp4mp_format = "BGP4MP";
  363. } else {
  364. bgp4mp_format = "BGP4MP_ET";
  365. }
  366. switch(entry->subtype)
  367. {
  368. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE:
  369. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4:
  370. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL:
  371. case BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL:
  372. switch(entry->body.zebra_message.type)
  373. {
  374. case BGP_MSG_UPDATE:
  375. if (mode ==0)
  376. {
  377. bgp4mp_message_direction_receive(entry)
  378. ? printf("TYPE: %s/MESSAGE/Update\n", bgp4mp_format)
  379. : printf("TYPE: %s/MESSAGE_LOCAL/Update\n", bgp4mp_format);
  380. if (entry->body.zebra_message.source_as)
  381. {
  382. printf("FROM:");
  383. switch(entry->body.zebra_message.address_family)
  384. {
  385. #ifdef BGPDUMP_HAVE_IPV6
  386. case AFI_IP6:
  387. fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
  388. printf(" %s ",prefix);
  389. break;
  390. #endif
  391. case AFI_IP:
  392. default:
  393. if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
  394. printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
  395. else
  396. printf(" N/A ");
  397. }
  398. printf("AS%u\n",entry->body.zebra_message.source_as);
  399. }
  400. if (entry->body.zebra_message.destination_as)
  401. {
  402. printf("TO:");
  403. switch(entry->body.zebra_message.address_family)
  404. {
  405. #ifdef BGPDUMP_HAVE_IPV6
  406. case AFI_IP6:
  407. fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
  408. printf(" %s ",prefix);
  409. break;
  410. #endif
  411. case AFI_IP:
  412. default:
  413. if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
  414. printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
  415. else
  416. printf(" N/A ");
  417. }
  418. printf("AS%u\n",entry->body.zebra_message.destination_as);
  419. }
  420. if (entry->attr && entry->attr->len)
  421. show_attr(entry->attr);
  422. if (entry->body.zebra_message.cut_bytes)
  423. {
  424. u_int16_t cutted,idx;
  425. u_int8_t buf[128];
  426. printf(" INCOMPLETE PACKET: %d bytes cutted\n",entry->body.zebra_message.cut_bytes);
  427. printf(" INCOMPLETE PART: ");
  428. if (entry->body.zebra_message.incomplete.orig_len)
  429. {
  430. cutted=entry->body.zebra_message.incomplete.prefix.len/8+1;
  431. buf[0]=entry->body.zebra_message.incomplete.orig_len;
  432. memcpy(buf+1,&entry->body.zebra_message.incomplete.prefix.address,cutted-1);
  433. for (idx=0;idx<cutted;idx++)
  434. {
  435. if (buf[idx]<0x10)
  436. printf("0%x ",buf[idx]);
  437. else
  438. printf("%x ",buf[idx]);
  439. }
  440. }
  441. printf("\n");
  442. }
  443. if(! entry->attr)
  444. return;
  445. if ((entry->body.zebra_message.withdraw_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))
  446. {
  447. #ifdef BGPDUMP_HAVE_IPV6
  448. 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) )
  449. #else
  450. 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))
  451. #endif
  452. printf("WITHDRAW\n");
  453. if (entry->body.zebra_message.withdraw_count)
  454. show_prefixes(entry->body.zebra_message.withdraw_count,entry->body.zebra_message.withdraw);
  455. if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count)
  456. show_prefixes(entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->nlri);
  457. if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count)
  458. show_prefixes(entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->nlri);
  459. if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
  460. 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);
  461. #ifdef BGPDUMP_HAVE_IPV6
  462. if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count)
  463. show_prefixes6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->nlri);
  464. if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count)
  465. show_prefixes6(entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->nlri);
  466. if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
  467. 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);
  468. #endif
  469. }
  470. if ( (entry->body.zebra_message.announce_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)))
  471. {
  472. printf("ANNOUNCE\n");
  473. if (entry->body.zebra_message.announce_count)
  474. show_prefixes(entry->body.zebra_message.announce_count,entry->body.zebra_message.announce);
  475. if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->prefix_count)
  476. show_prefixes(entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nlri);
  477. if (entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->prefix_count)
  478. show_prefixes(entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nlri);
  479. if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
  480. 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);
  481. #ifdef BGPDUMP_HAVE_IPV6
  482. if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->prefix_count)
  483. show_prefixes6(entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nlri);
  484. if (entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->prefix_count)
  485. show_prefixes6(entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->prefix_count,entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nlri);
  486. if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
  487. 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);
  488. #endif
  489. }
  490. }
  491. else if (mode == 1 || mode == 2) //-m -M
  492. {
  493. if ((entry->body.zebra_message.withdraw_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))
  494. {
  495. table_line_withdraw(entry->body.zebra_message.withdraw,entry->body.zebra_message.withdraw_count,entry,time_str);
  496. if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST]->prefix_count)
  497. 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);
  498. if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST]->prefix_count)
  499. 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);
  500. if (entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
  501. 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);
  502. #ifdef BGPDUMP_HAVE_IPV6
  503. if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST]->prefix_count)
  504. 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);
  505. if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST]->prefix_count)
  506. 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);
  507. if (entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
  508. 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);
  509. #endif
  510. }
  511. if ( (entry->body.zebra_message.announce_count) || (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)))
  512. {
  513. table_line_announce(entry->body.zebra_message.announce,entry->body.zebra_message.announce_count,entry,time_str);
  514. if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->prefix_count)
  515. 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);
  516. if (entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->prefix_count)
  517. 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);
  518. if (entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->prefix_count)
  519. 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);
  520. #ifdef BGPDUMP_HAVE_IPV6
  521. if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->prefix_count)
  522. 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);
  523. if (entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->prefix_count)
  524. 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);
  525. if (entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST] && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->prefix_count)
  526. 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);
  527. #endif
  528. }
  529. }
  530. break;
  531. case BGP_MSG_OPEN:
  532. if (mode != 0)
  533. break;
  534. bgp4mp_message_direction_receive(entry)
  535. ? printf("TYPE: %s/MESSAGE/Open\n", bgp4mp_format)
  536. : printf("TYPE: %s/MESSAGE_LOCAL/Open\n", bgp4mp_format);
  537. if (entry->body.zebra_message.source_as)
  538. {
  539. printf("FROM:");
  540. switch(entry->body.zebra_message.address_family)
  541. {
  542. #ifdef BGPDUMP_HAVE_IPV6
  543. case AFI_IP6:
  544. fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
  545. printf(" %s ",prefix);
  546. break;
  547. #endif
  548. case AFI_IP:
  549. default:
  550. if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
  551. printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
  552. else
  553. printf(" N/A ");
  554. }
  555. printf("AS%u\n",entry->body.zebra_message.source_as);
  556. }
  557. if (entry->body.zebra_message.destination_as)
  558. {
  559. printf("TO:");
  560. switch(entry->body.zebra_message.address_family)
  561. {
  562. #ifdef BGPDUMP_HAVE_IPV6
  563. case AFI_IP6:
  564. fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
  565. printf(" %s ",prefix);
  566. break;
  567. #endif
  568. case AFI_IP:
  569. default:
  570. if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
  571. printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
  572. else
  573. printf(" N/A ");
  574. }
  575. printf("AS%u\n",entry->body.zebra_message.destination_as);
  576. }
  577. printf("VERSION: %d\n",entry->body.zebra_message.version);
  578. printf("AS: %u\n",entry->body.zebra_message.my_as);
  579. printf("HOLD_TIME: %d\n",entry->body.zebra_message.hold_time);
  580. printf("ID: %s\n",inet_ntoa(entry->body.zebra_message.bgp_id));
  581. printf("OPT_PARM_LEN: %d\n",entry->body.zebra_message.opt_len);
  582. break;
  583. case BGP_MSG_NOTIFY:
  584. if (mode != 0)
  585. break;
  586. bgp4mp_message_direction_receive(entry)
  587. ? printf("TYPE: %s/MESSAGE/Notify\n", bgp4mp_format)
  588. : printf("TYPE: %s/MESSAGE_LOCAL/Notify\n", bgp4mp_format);
  589. if (entry->body.zebra_message.source_as)
  590. {
  591. printf("FROM:");
  592. switch(entry->body.zebra_message.address_family)
  593. {
  594. #ifdef BGPDUMP_HAVE_IPV6
  595. case AFI_IP6:
  596. fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
  597. printf(" %s ",prefix);
  598. break;
  599. #endif
  600. case AFI_IP:
  601. default:
  602. if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
  603. printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
  604. else
  605. printf(" N/A ");
  606. }
  607. printf("AS%u\n",entry->body.zebra_message.source_as);
  608. }
  609. if (entry->body.zebra_message.destination_as)
  610. {
  611. printf("TO:");
  612. switch(entry->body.zebra_message.address_family)
  613. {
  614. #ifdef BGPDUMP_HAVE_IPV6
  615. case AFI_IP6:
  616. fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
  617. printf(" %s ",prefix);
  618. break;
  619. #endif
  620. case AFI_IP:
  621. default:
  622. if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
  623. printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
  624. else
  625. printf(" N/A ");
  626. }
  627. printf("AS%u\n",entry->body.zebra_message.destination_as);
  628. }
  629. switch (entry->body.zebra_message.error_code)
  630. {
  631. case 1:
  632. printf(" ERROR CODE : 1 (Message Header Error)\n");
  633. switch(entry->body.zebra_message.sub_error_code)
  634. {
  635. case 1:
  636. printf(" SUB ERROR : 1 (Connection Not Synchronized)\n");
  637. break;
  638. case 2:
  639. printf(" SUB ERROR : 2 (Bad Message Length)\n");
  640. break;
  641. case 3:
  642. printf(" SUB ERROR : 3 (Bad Message Type)\n");
  643. break;
  644. default:
  645. printf(" SUB ERROR : %d\n",entry->body.zebra_message.sub_error_code);
  646. break;
  647. }
  648. break;
  649. case 2:
  650. printf(" ERROR CODE : 2 (OPEN Message Error)\n");
  651. switch(entry->body.zebra_message.sub_error_code)
  652. {
  653. case 1:
  654. printf(" SUB ERROR : 1 (Unsupported Version Number)\n");
  655. break;
  656. case 2:
  657. printf(" SUB ERROR : 2 (Bad Peer AS)\n");
  658. break;
  659. case 3:
  660. printf(" SUB ERROR : 3 (Bad BGP Identifier)\n");
  661. break;
  662. case 4:
  663. printf(" SUB ERROR : 4 (Unsupported Optional Parameter)\n");
  664. break;
  665. case 5:
  666. printf(" SUB ERROR : 5 (Authentication Failure)\n");
  667. break;
  668. case 6:
  669. printf(" SUB ERROR : 6 (Unacceptable Hold Time)\n");
  670. break;
  671. default:
  672. printf(" SUB ERROR : %d\n",entry->body.zebra_message.sub_error_code);
  673. break;
  674. }
  675. break;
  676. case 3:
  677. printf(" ERROR CODE : 3 (UPDATE Message Error)\n");
  678. switch(entry->body.zebra_message.sub_error_code)
  679. {
  680. case 1:
  681. printf(" SUB ERROR : 1 (Malformed Attribute List)\n");
  682. break;
  683. case 2:
  684. printf(" SUB ERROR : 2 (Unrecognized Well-known Attribute)\n");
  685. break;
  686. case 3:
  687. printf(" SUB ERROR : 3 (Missing Well-known Attribute)\n");
  688. break;
  689. case 4:
  690. printf(" SUB ERROR : 4 (Attribute Flags Error)\n");
  691. break;
  692. case 5:
  693. printf(" SUB ERROR : 5 (Attribute Length Error)\n");
  694. break;
  695. case 6:
  696. printf(" SUB ERROR : 6 (Invalid ORIGIN Attribute)\n");
  697. break;
  698. case 7:
  699. printf(" SUB ERROR : 7 (AS Routing Loop)\n");
  700. break;
  701. case 8:
  702. printf(" SUB ERROR : 8 (Invalid NEXT-HOP Attribute)\n");
  703. break;
  704. case 9:
  705. printf(" SUB ERROR : 9 (Optional Attribute Error)\n");
  706. break;
  707. case 10:
  708. printf(" SUB ERROR : 10 (Invalid Network Field)\n");
  709. break;
  710. case 11:
  711. printf(" SUB ERROR : 11 (Malformed AS-PATH)\n");
  712. break;
  713. default:
  714. printf(" SUB ERROR : %d\n",entry->body.zebra_message.sub_error_code);
  715. break;
  716. }
  717. break;
  718. case 4:
  719. printf(" ERROR CODE : 4 (Hold Timer Expired)\n");
  720. break;
  721. case 5:
  722. printf(" ERROR CODE : 5 (Finite State Machine Error)\n");
  723. break;
  724. case 6:
  725. printf(" ERROR CODE : 6 (Cease)\n");
  726. break;
  727. default:
  728. printf(" ERROR CODE : %d\n",entry->body.zebra_message.error_code);
  729. break;
  730. }
  731. break;
  732. case BGP_MSG_KEEPALIVE:
  733. if ( mode != 0)
  734. break;
  735. bgp4mp_message_direction_receive(entry)
  736. ? printf("TYPE: %s/MESSAGE/Keepalive\n", bgp4mp_format)
  737. : printf("TYPE: %s/MESSAGE_LOCAL/Keepalive\n", bgp4mp_format);
  738. if (entry->body.zebra_message.source_as)
  739. {
  740. printf("FROM:");
  741. switch(entry->body.zebra_message.address_family)
  742. {
  743. #ifdef BGPDUMP_HAVE_IPV6
  744. case AFI_IP6:
  745. fmt_ipv6(entry->body.zebra_message.source_ip,prefix);
  746. printf(" %s ",prefix);
  747. break;
  748. #endif
  749. case AFI_IP:
  750. default:
  751. if (entry->body.zebra_message.source_ip.v4_addr.s_addr != 0x00000000L)
  752. printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
  753. else
  754. printf(" N/A ");
  755. }
  756. printf("AS%u\n",entry->body.zebra_message.source_as);
  757. }
  758. if (entry->body.zebra_message.destination_as)
  759. {
  760. printf("TO:");
  761. switch(entry->body.zebra_message.address_family)
  762. {
  763. #ifdef BGPDUMP_HAVE_IPV6
  764. case AFI_IP6:
  765. fmt_ipv6(entry->body.zebra_message.destination_ip,prefix);
  766. printf(" %s ",prefix);
  767. break;
  768. #endif
  769. case AFI_IP:
  770. default:
  771. if (entry->body.zebra_message.destination_ip.v4_addr.s_addr != 0x00000000L)
  772. printf(" %s ",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr));
  773. else
  774. printf(" N/A ");
  775. }
  776. printf("AS%u\n",entry->body.zebra_message.destination_as);
  777. }
  778. break;
  779. }
  780. break;
  781. case BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE:
  782. case BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE_AS4:
  783. if (mode==0)
  784. {
  785. printf("TYPE: %s/STATE_CHANGE\n", bgp4mp_format);
  786. printf("PEER:");
  787. switch(entry->body.zebra_state_change.address_family)
  788. {
  789. #ifdef BGPDUMP_HAVE_IPV6
  790. case AFI_IP6:
  791. fmt_ipv6(entry->body.zebra_state_change.source_ip,prefix);
  792. printf(" %s ",prefix);
  793. break;
  794. #endif
  795. case AFI_IP:
  796. default:
  797. if (entry->body.zebra_state_change.source_ip.v4_addr.s_addr != 0x00000000L)
  798. printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr));
  799. else
  800. printf(" N/A ");
  801. }
  802. //if (entry->body.zebra_message.source_ip.s_addr != 0x00000000L)
  803. // printf(" %s ",inet_ntoa(entry->body.zebra_message.source_ip));
  804. //else
  805. // printf(" N/A ");
  806. printf("AS%u\n",entry->body.zebra_state_change.source_as);
  807. 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]);
  808. }
  809. else if (mode==1 || mode==2 ) //-m -M
  810. {
  811. switch(entry->body.zebra_state_change.address_family)
  812. {
  813. #ifdef BGPDUMP_HAVE_IPV6
  814. case AFI_IP6:
  815. fmt_ipv6(entry->body.zebra_state_change.source_ip, prefix);
  816. break;
  817. #endif
  818. case AFI_IP:
  819. default:
  820. sprintf(prefix, "%s", inet_ntoa(entry->body.zebra_state_change.source_ip.v4_addr));
  821. break;
  822. }
  823. show_line_prefix(bgp4mp_format, time_str, "STATE");
  824. printf("%s|%u|%d|%d\n", prefix,
  825. entry->body.zebra_state_change.source_as,
  826. entry->body.zebra_state_change.old_state,
  827. entry->body.zebra_state_change.new_state);
  828. }
  829. break;
  830. }
  831. break;
  832. }
  833. if (mode==0)
  834. printf("\n");
  835. }
  836. // print line prefix with respect of mode and show_packet_index flags
  837. // output will have format:
  838. // format|[packet_index|]time|type|
  839. void show_line_prefix(const char* format, const char* time_str, const char* type)
  840. {
  841. printf("%s|", format);
  842. if (show_packet_index)
  843. printf("%d|", packet_index);
  844. printf("%s|%s|", time_str, type);
  845. }
  846. void process_bgpdump_mrtd_bgp(BGPDUMP_ENTRY *entry) {
  847. struct tm *date;
  848. char time_str[128];
  849. date=gmtime(&entry->time);
  850. if (mode == 1) {
  851. sprintf(time_str, "%ld", entry->time);
  852. } else {
  853. time2str(date, time_str);
  854. }
  855. switch (entry->subtype) {
  856. case BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE:
  857. case BGPDUMP_SUBTYPE_MRTD_BGP_KEEPALIVE:
  858. if (mode == 0) {
  859. if (entry->subtype == BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE)
  860. printf("TYPE: BGP/MESSAGE/Update\n");
  861. else
  862. printf("TYPE: BGP/MESSAGE/Keepalive\n");
  863. if (entry->body.mrtd_message.source_as) {
  864. printf("FROM:");
  865. show_ipv4_address(entry->body.mrtd_message.source_ip);
  866. printf("AS%u\n", entry->body.mrtd_message.source_as);
  867. }
  868. if (entry->body.mrtd_message.destination_as) {
  869. printf("TO:");
  870. show_ipv4_address(entry->body.mrtd_message.destination_ip);
  871. printf("AS%u\n", entry->body.mrtd_message.destination_as);
  872. }
  873. if (entry->attr && entry->attr->len)
  874. show_attr(entry->attr);
  875. if (entry->body.mrtd_message.withdraw_count) {
  876. printf("WITHDRAW\n");
  877. show_prefixes(entry->body.mrtd_message.withdraw_count, entry->body.mrtd_message.withdraw);
  878. }
  879. if (entry->body.mrtd_message.announce_count) {
  880. printf("ANNOUNCE\n");
  881. show_prefixes(entry->body.mrtd_message.announce_count, entry->body.mrtd_message.announce);
  882. }
  883. }
  884. else {
  885. if (entry->subtype != BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE)
  886. break;
  887. if (entry->body.mrtd_message.withdraw_count)
  888. mrtd_table_line_withdraw(entry->body.mrtd_message.withdraw, entry->body.mrtd_message.withdraw_count,
  889. entry, time_str);
  890. if (entry->body.mrtd_message.announce_count)
  891. mrtd_table_line_announce(entry->body.mrtd_message.announce, entry->body.mrtd_message.announce_count,
  892. entry, time_str);
  893. }
  894. break;
  895. case BGPDUMP_SUBTYPE_MRTD_BGP_STATE_CHANGE:
  896. if (mode == 0) {
  897. printf("TYPE: BGP/STATE_CHANGE\n");
  898. printf("PEER:");
  899. show_ipv4_address(entry->body.mrtd_state_change.destination_ip);
  900. printf("AS%u\n", entry->body.mrtd_state_change.destination_as);
  901. printf("STATE: %s/%s\n", bgp_state_name[entry->body.mrtd_state_change.old_state],
  902. bgp_state_name[entry->body.mrtd_state_change.new_state]);
  903. }
  904. else if (mode == 1 || mode == 2) {
  905. show_line_prefix("BGP", time_str, "STATE");
  906. printf("%s|%u|%d|%d\n",
  907. inet_ntoa(entry->body.mrtd_state_change.destination_ip),
  908. entry->body.mrtd_state_change.destination_as,
  909. entry->body.mrtd_state_change.old_state,
  910. entry->body.mrtd_state_change.new_state);
  911. }
  912. break;
  913. default:
  914. if (mode == 0) {
  915. printf("TYPE: Subtype %d not supported yet\n", entry->subtype);
  916. }
  917. }
  918. }
  919. void mrtd_table_line_withdraw(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str) {
  920. int i;
  921. for (i = 0; i < count; i++) {
  922. show_line_prefix("BGP", time_str, "W");
  923. printf("%s|%u|%s/%d\n", inet_ntoa(entry->body.mrtd_message.source_ip),
  924. entry->body.mrtd_message.source_as,
  925. inet_ntoa(prefix[i].address.v4_addr), prefix[i].len);
  926. }
  927. }
  928. void mrtd_table_line_announce(struct prefix *prefix, int count, BGPDUMP_ENTRY *entry, char *time_str) {
  929. int i, npref, nmed;
  930. char *aggregate = entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE) ? "AG" : "NAG";
  931. for (i = 0; i < count; i++) {
  932. show_line_prefix("BGP", time_str, "A");
  933. printf("%s|%u", inet_ntoa(entry->body.mrtd_message.source_ip),
  934. entry->body.mrtd_message.source_as);
  935. printf("|%s/%d|%s|%s", inet_ntoa(prefix[i].address.v4_addr), prefix[i].len,
  936. attr_aspath(entry->attr), describe_origin(entry->attr->origin));
  937. if (mode == 1) {
  938. npref = ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) == 0) ? 0 : entry->attr->local_pref;
  939. nmed = ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) == 0) ? 0 : entry->attr->med;
  940. printf("|%s|%u|%u", inet_ntoa(entry->attr->nexthop), npref, nmed);
  941. if ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) != 0)
  942. printf("%s|%s|", entry->attr->community->str+1, aggregate);
  943. else
  944. printf("|%s|", aggregate);
  945. if (entry->attr->aggregator_addr.s_addr != -1)
  946. printf("%u %s|\n", entry->attr->aggregator_as, inet_ntoa(entry->attr->aggregator_addr));
  947. else
  948. printf("|\n");
  949. }
  950. else
  951. printf("\n");
  952. }
  953. }
  954. void show_ipv4_address(struct in_addr ip) {
  955. if (ip.s_addr != 0x00000000L)
  956. printf(" %s ", inet_ntoa(ip));
  957. else
  958. printf(" N/A ");
  959. }
  960. void show_attr(attributes_t *attr) {
  961. if(attr != NULL) {
  962. if( (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGIN) ) !=0 )
  963. {
  964. switch (attr->origin)
  965. {
  966. case 0:
  967. printf("ORIGIN: IGP\n");
  968. break;
  969. case 1:
  970. printf("ORIGIN: EGP\n");
  971. break;
  972. case 2:
  973. printf("ORIGIN: INCOMPLETE\n");
  974. }
  975. }
  976. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATH) ) !=0)
  977. printf("ASPATH: %s\n",attr->aspath->str);
  978. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP) ) !=0)
  979. printf("NEXT_HOP: %s\n",inet_ntoa(attr->nexthop));
  980. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) !=0)
  981. printf("MULTI_EXIT_DISC: %u\n",attr->med);
  982. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) !=0)
  983. printf("LOCAL_PREF: %u\n",attr->local_pref);
  984. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE) ) !=0)
  985. printf("ATOMIC_AGGREGATE\n");
  986. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR) ) !=0)
  987. printf("AGGREGATOR: AS%u %s\n",attr->aggregator_as,inet_ntoa(attr->aggregator_addr));
  988. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID) ) !=0)
  989. printf("ORIGINATOR_ID: %s\n",inet_ntoa(attr->originator_id));
  990. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST) ) !=0)
  991. {
  992. int cluster_index;
  993. printf("CLUSTER_LIST: ");
  994. for (cluster_index = 0;cluster_index<attr->cluster->length;cluster_index++)
  995. printf("%s ",inet_ntoa(attr->cluster->list[cluster_index]));
  996. printf("\n");
  997. }
  998. int idx;
  999. for (idx=0;idx<attr->unknown_num;idx++)
  1000. {
  1001. struct unknown_attr *unknown = attr->unknown + idx;
  1002. printf(" UNKNOWN_ATTR(%i, %i, %i):", unknown->flag, unknown->type, unknown->len);
  1003. int b;
  1004. for(b = 0; b < unknown->len; ++b)
  1005. printf(" %02x", unknown->raw[b]);
  1006. printf("\n");
  1007. }
  1008. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI) )!=0)
  1009. {
  1010. printf("MP_REACH_NLRI");
  1011. #ifdef BGPDUMP_HAVE_IPV6
  1012. 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])
  1013. {
  1014. char buf[128];
  1015. if (attr->mp_info->announce[AFI_IP6][SAFI_UNICAST])
  1016. {
  1017. printf("(IPv6 Unicast)\n");
  1018. printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop,buf));
  1019. if (attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop_len==32)
  1020. printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop_local,buf));
  1021. }
  1022. else if (attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST])
  1023. {
  1024. printf("(IPv6 Multicast)\n");
  1025. printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nexthop,buf));
  1026. if (attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nexthop_len==32)
  1027. printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_MULTICAST]->nexthop_local,buf));
  1028. }
  1029. else
  1030. {
  1031. printf("(IPv6 Both unicast and multicast)\n");
  1032. printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->nexthop,buf));
  1033. if (attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->nexthop_len==32)
  1034. printf("NEXT_HOP: %s\n",fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST_MULTICAST]->nexthop_local,buf));
  1035. }
  1036. }
  1037. else
  1038. #endif
  1039. {
  1040. if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST])
  1041. {
  1042. printf("(IPv4 Unicast)\n");
  1043. printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nexthop.v4_addr));
  1044. if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nexthop_len==32)
  1045. printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST]->nexthop_local.v4_addr));
  1046. }
  1047. else if (attr->mp_info->announce[AFI_IP][SAFI_MULTICAST])
  1048. {
  1049. printf("(IPv4 Multicast)\n");
  1050. printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nexthop.v4_addr));
  1051. if (attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nexthop_len==32)
  1052. printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_MULTICAST]->nexthop_local.v4_addr));
  1053. }
  1054. else if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST])
  1055. {
  1056. printf("(IPv4 Both unicast and multicast)\n");
  1057. printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->nexthop.v4_addr));
  1058. if (attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->nexthop_len==32)
  1059. printf("NEXT_HOP: %s\n",inet_ntoa(attr->mp_info->announce[AFI_IP][SAFI_UNICAST_MULTICAST]->nexthop_local.v4_addr));
  1060. }
  1061. }
  1062. }
  1063. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI) )!=0)
  1064. {
  1065. printf("MP_UNREACH_NLRI");
  1066. #ifdef BGPDUMP_HAVE_IPV6
  1067. 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])
  1068. {
  1069. if (attr->mp_info->withdraw[AFI_IP6][SAFI_UNICAST])
  1070. {
  1071. printf("(IPv6 Unicast)\n");
  1072. }
  1073. else if (attr->mp_info->withdraw[AFI_IP6][SAFI_MULTICAST])
  1074. {
  1075. printf("(IPv6 Multicast)\n");
  1076. }
  1077. else
  1078. {
  1079. printf("(IPv6 Both unicast and multicast)\n");
  1080. }
  1081. }
  1082. else
  1083. #endif
  1084. {
  1085. if (attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST])
  1086. {
  1087. printf("(IPv4 Unicast)\n");
  1088. }
  1089. else if (attr->mp_info->withdraw[AFI_IP][SAFI_MULTICAST])
  1090. {
  1091. printf("(IPv4 Multicast)\n");
  1092. }
  1093. else if (attr->mp_info->withdraw[AFI_IP][SAFI_UNICAST_MULTICAST])
  1094. {
  1095. printf("(IPv4 Both unicast and multicast)\n");
  1096. }
  1097. }
  1098. }
  1099. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
  1100. printf("COMMUNITY:%s\n",attr->community->str);
  1101. }
  1102. }
  1103. void show_prefixes(int count,struct prefix *prefix) {
  1104. int i;
  1105. for(i=0;i<count;i++)
  1106. printf(" %s/%d\n",inet_ntoa(prefix[i].address.v4_addr),prefix[i].len);
  1107. }
  1108. #ifdef BGPDUMP_HAVE_IPV6
  1109. void show_prefixes6(int count,struct prefix *prefix)
  1110. {
  1111. int i;
  1112. char buf[128];
  1113. for (i=0;i<count;i++)
  1114. printf(" %s/%d\n",fmt_ipv6(prefix[i].address,buf),prefix[i].len);
  1115. }
  1116. #endif
  1117. static void table_line_withdraw(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
  1118. {
  1119. int idx;
  1120. char buf[128];
  1121. for (idx=0;idx<count;idx++)
  1122. {
  1123. show_line_prefix(get_bgp4mp_format(entry), time_str, "W");
  1124. switch(entry->body.zebra_message.address_family) {
  1125. #ifdef BGPDUMP_HAVE_IPV6
  1126. case AFI_IP6:
  1127. bgp4mp_message_direction_receive(entry)
  1128. ? printf("%s|%u|",
  1129. fmt_ipv6(entry->body.zebra_message.source_ip,buf),
  1130. entry->body.zebra_message.source_as)
  1131. : printf("%s|%u|",
  1132. fmt_ipv6(entry->body.zebra_message.destination_ip,buf),
  1133. entry->body.zebra_message.destination_as);
  1134. break;
  1135. #endif
  1136. case AFI_IP:
  1137. default:
  1138. bgp4mp_message_direction_receive(entry)
  1139. ? printf("%s|%u|",
  1140. inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),
  1141. entry->body.zebra_message.source_as)
  1142. : printf("%s|%u|",
  1143. inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),
  1144. entry->body.zebra_message.destination_as);
  1145. break;
  1146. }
  1147. printf("%s/%d\n",inet_ntoa(prefix[idx].address.v4_addr),prefix[idx].len);
  1148. }
  1149. }
  1150. #ifdef BGPDUMP_HAVE_IPV6
  1151. static void table_line_withdraw6(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
  1152. {
  1153. int idx;
  1154. char buf[128];
  1155. char buf1[128];
  1156. for (idx=0;idx<count;idx++)
  1157. {
  1158. show_line_prefix(get_bgp4mp_format(entry), time_str, "W");
  1159. switch(entry->body.zebra_message.address_family) {
  1160. case AFI_IP6:
  1161. bgp4mp_message_direction_receive(entry)
  1162. ? printf("%s|%u|%s/%d\n",
  1163. fmt_ipv6(entry->body.zebra_message.source_ip,buf1),
  1164. entry->body.zebra_message.source_as,
  1165. fmt_ipv6(prefix[idx].address,buf),prefix[idx].len)
  1166. : printf("%s|%u|%s/%d\n",
  1167. fmt_ipv6(entry->body.zebra_message.destination_ip,buf1),
  1168. entry->body.zebra_message.destination_as,
  1169. fmt_ipv6(prefix[idx].address,buf),prefix[idx].len);
  1170. break;
  1171. case AFI_IP:
  1172. default:
  1173. bgp4mp_message_direction_receive(entry)
  1174. ? printf("%s|%u|%s/%d\n",
  1175. fmt_ipv4(entry->body.zebra_message.source_ip,buf1),
  1176. entry->body.zebra_message.source_as,
  1177. fmt_ipv6(prefix[idx].address,buf),prefix[idx].len)
  1178. : printf("%s|%u|%s/%d\n",
  1179. fmt_ipv6(entry->body.zebra_message.destination_ip,buf1),
  1180. entry->body.zebra_message.destination_as,
  1181. fmt_ipv6(prefix[idx].address,buf),prefix[idx].len);
  1182. break;
  1183. }
  1184. }
  1185. }
  1186. #endif
  1187. static void table_line_announce(struct prefix *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
  1188. {
  1189. int idx ;
  1190. char buf[128];
  1191. char tmp2[20];
  1192. unsigned int npref;
  1193. unsigned int nmed;
  1194. if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  1195. sprintf(tmp2,"AG");
  1196. else
  1197. sprintf(tmp2,"NAG");
  1198. for (idx=0;idx<count;idx++)
  1199. {
  1200. show_line_prefix(get_bgp4mp_format(entry), time_str, "A");
  1201. if (mode == 1)
  1202. {
  1203. switch(entry->body.zebra_message.address_family)
  1204. {
  1205. #ifdef BGPDUMP_HAVE_IPV6
  1206. case AFI_IP6:
  1207. bgp4mp_message_direction_receive(entry)
  1208. ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
  1209. : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
  1210. break;
  1211. #endif
  1212. case AFI_IP:
  1213. default:
  1214. bgp4mp_message_direction_receive(entry)
  1215. ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
  1216. : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
  1217. break;
  1218. }
  1219. printf("%s/%d|%s|%s|",inet_ntoa(prefix[idx].address.v4_addr),prefix[idx].len,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
  1220. npref=entry->attr->local_pref;
  1221. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
  1222. npref=0;
  1223. nmed=entry->attr->med;
  1224. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
  1225. nmed=0;
  1226. printf("%s|%u|%u|",inet_ntoa(entry->attr->nexthop),npref,nmed);
  1227. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
  1228. printf("%s|%s|",entry->attr->community->str+1,tmp2);
  1229. else
  1230. printf("|%s|",tmp2);
  1231. if (entry->attr->aggregator_addr.s_addr != -1)
  1232. printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
  1233. else
  1234. printf("|\n");
  1235. }
  1236. else
  1237. {
  1238. switch(entry->body.zebra_message.address_family)
  1239. {
  1240. #ifdef BGPDUMP_HAVE_IPV6
  1241. case AFI_IP6:
  1242. bgp4mp_message_direction_receive(entry)
  1243. ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
  1244. : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
  1245. break;
  1246. #endif
  1247. case AFI_IP:
  1248. default:
  1249. bgp4mp_message_direction_receive(entry)
  1250. ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
  1251. : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
  1252. break;
  1253. }
  1254. 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));
  1255. }
  1256. }
  1257. }
  1258. static void table_line_announce_1(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
  1259. {
  1260. int idx ;
  1261. char buf[128];
  1262. char tmp2[20];
  1263. unsigned int npref;
  1264. unsigned int nmed;
  1265. if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  1266. sprintf(tmp2,"AG");
  1267. else
  1268. sprintf(tmp2,"NAG");
  1269. for (idx=0;idx<count;idx++)
  1270. {
  1271. show_line_prefix(get_bgp4mp_format(entry), time_str, "A");
  1272. if (mode == 1)
  1273. {
  1274. if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI))
  1275. {
  1276. switch(entry->body.zebra_message.address_family)
  1277. {
  1278. #ifdef BGPDUMP_HAVE_IPV6
  1279. case AFI_IP6:
  1280. bgp4mp_message_direction_receive(entry)
  1281. ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
  1282. : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
  1283. break;
  1284. #endif
  1285. case AFI_IP:
  1286. default:
  1287. bgp4mp_message_direction_receive(entry)
  1288. ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
  1289. : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
  1290. break;
  1291. }
  1292. 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));
  1293. npref=entry->attr->local_pref;
  1294. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
  1295. npref=0;
  1296. nmed=entry->attr->med;
  1297. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
  1298. nmed=0;
  1299. printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),npref,nmed);
  1300. //printf("%s|%d|%d|",inet_ntoa(prefix->nexthop.v4_addr),entry->attr->local_pref,entry->attr->med);
  1301. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
  1302. printf("%s|%s|",entry->attr->community->str+1,tmp2);
  1303. else
  1304. printf("|%s|",tmp2);
  1305. }
  1306. else
  1307. {
  1308. switch(entry->body.zebra_message.address_family)
  1309. {
  1310. #ifdef BGPDUMP_HAVE_IPV6
  1311. case AFI_IP6:
  1312. bgp4mp_message_direction_receive(entry)
  1313. ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
  1314. : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
  1315. break;
  1316. #endif
  1317. case AFI_IP:
  1318. default:
  1319. bgp4mp_message_direction_receive(entry)
  1320. ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
  1321. : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
  1322. break;
  1323. }
  1324. 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));
  1325. npref=entry->attr->local_pref;
  1326. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
  1327. npref=0;
  1328. nmed=entry->attr->med;
  1329. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
  1330. nmed=0;
  1331. printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),npref,nmed);
  1332. //printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),entry->attr->local_pref,entry->attr->med);
  1333. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
  1334. printf("%s|%s|",entry->attr->community->str+1,tmp2);
  1335. else
  1336. printf("|%s|",tmp2);
  1337. }
  1338. if (entry->attr->aggregator_addr.s_addr != -1)
  1339. printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
  1340. else
  1341. printf("|\n");
  1342. }
  1343. else
  1344. {
  1345. switch(entry->body.zebra_message.address_family)
  1346. {
  1347. #ifdef BGPDUMP_HAVE_IPV6
  1348. case AFI_IP6:
  1349. bgp4mp_message_direction_receive(entry)
  1350. ? printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.source_ip,buf),entry->body.zebra_message.source_as)
  1351. : printf("%s|%u|",fmt_ipv6(entry->body.zebra_message.destination_ip,buf),entry->body.zebra_message.destination_as);
  1352. break;
  1353. #endif
  1354. case AFI_IP:
  1355. default:
  1356. bgp4mp_message_direction_receive(entry)
  1357. ? printf("%s|%u|",inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),entry->body.zebra_message.source_as)
  1358. : printf("%s|%u|",inet_ntoa(entry->body.zebra_message.destination_ip.v4_addr),entry->body.zebra_message.destination_as);
  1359. break;
  1360. }
  1361. 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));
  1362. }
  1363. }
  1364. }
  1365. #ifdef BGPDUMP_HAVE_IPV6
  1366. static void table_line_announce6(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY *entry,char *time_str)
  1367. {
  1368. int idx ;
  1369. char buf[128];
  1370. char buf1[128];
  1371. char buf2[128];
  1372. char tmp2[20];
  1373. unsigned int npref;
  1374. unsigned int nmed;
  1375. if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  1376. sprintf(tmp2,"AG");
  1377. else
  1378. sprintf(tmp2,"NAG");
  1379. for (idx=0;idx<count;idx++)
  1380. {
  1381. show_line_prefix(get_bgp4mp_format(entry), time_str, "A");
  1382. if (mode == 1)
  1383. {
  1384. switch(entry->body.zebra_message.address_family)
  1385. {
  1386. case AFI_IP6:
  1387. npref=entry->attr->local_pref;
  1388. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
  1389. npref=0;
  1390. nmed=entry->attr->med;
  1391. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
  1392. nmed=0;
  1393. bgp4mp_message_direction_receive(entry)
  1394. ? 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)
  1395. : 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);
  1396. break;
  1397. case AFI_IP:
  1398. default:
  1399. npref=entry->attr->local_pref;
  1400. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
  1401. npref=0;
  1402. nmed=entry->attr->med;
  1403. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
  1404. nmed=0;
  1405. //printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),nprof,nmed);
  1406. bgp4mp_message_direction_receive(entry)
  1407. ? 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)
  1408. : 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);
  1409. break;
  1410. }
  1411. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
  1412. printf("%s|%s|",entry->attr->community->str+1,tmp2);
  1413. else
  1414. printf("|%s|",tmp2);
  1415. if (entry->attr->aggregator_addr.s_addr != -1)
  1416. printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
  1417. else
  1418. printf("|\n");
  1419. }
  1420. else
  1421. {
  1422. switch(entry->body.zebra_message.address_family)
  1423. {
  1424. case AFI_IP6:
  1425. bgp4mp_message_direction_receive(entry)
  1426. ? 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))
  1427. : 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));
  1428. break;
  1429. case AFI_IP:
  1430. default:
  1431. bgp4mp_message_direction_receive(entry)
  1432. ? 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))
  1433. : 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));
  1434. break;
  1435. }
  1436. }
  1437. }
  1438. }
  1439. #endif
  1440. static void table_line_mrtd_route(BGPDUMP_MRTD_TABLE_DUMP *route,BGPDUMP_ENTRY *entry)
  1441. {
  1442. struct tm *date = NULL;
  1443. char tmp2[20];
  1444. unsigned int npref;
  1445. unsigned int nmed;
  1446. char time_str[20];
  1447. char peer[BGPDUMP_ADDRSTRLEN], prefix[BGPDUMP_ADDRSTRLEN], nexthop[BGPDUMP_ADDRSTRLEN];
  1448. if (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  1449. sprintf(tmp2,"AG");
  1450. else
  1451. sprintf(tmp2,"NAG");
  1452. time_t *t;
  1453. if (timetype==0) {
  1454. t = &entry->time;
  1455. } else {
  1456. t = &route->uptime;
  1457. }
  1458. if (mode == 1) {
  1459. sprintf(time_str, "%ld", *t);
  1460. } else {
  1461. date=gmtime(t);
  1462. time2str(date, time_str);
  1463. }
  1464. show_line_prefix("TABLE_DUMP", time_str, "B");
  1465. #ifdef BGPDUMP_HAVE_IPV6
  1466. if (entry->subtype == AFI_IP6)
  1467. {
  1468. fmt_ipv6(route->peer_ip,peer);
  1469. fmt_ipv6(route->prefix,prefix);
  1470. }
  1471. else
  1472. #endif
  1473. {
  1474. strncpy(peer, inet_ntoa(route->peer_ip.v4_addr), BGPDUMP_ADDRSTRLEN);
  1475. strncpy(prefix, inet_ntoa(route->prefix.v4_addr), BGPDUMP_ADDRSTRLEN);
  1476. }
  1477. if (mode == 1)
  1478. {
  1479. printf("%s|%u|",peer,route->peer_as);
  1480. printf("%s/%d|%s|%s|",prefix,route->mask,
  1481. attr_aspath(entry->attr),describe_origin(entry->attr->origin));
  1482. npref=entry->attr->local_pref;
  1483. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
  1484. npref=0;
  1485. nmed=entry->attr->med;
  1486. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
  1487. nmed=0;
  1488. #ifdef BGPDUMP_HAVE_IPV6
  1489. if ((entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) && entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST])
  1490. {
  1491. fmt_ipv6(entry->attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop,nexthop);
  1492. }
  1493. else
  1494. #endif
  1495. {
  1496. strncpy(nexthop, inet_ntoa(entry->attr->nexthop), BGPDUMP_ADDRSTRLEN);
  1497. }
  1498. printf("%s|%u|%u|",nexthop,npref,nmed);
  1499. if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
  1500. printf("%s|%s|",entry->attr->community->str+1,tmp2);
  1501. else
  1502. printf("|%s|",tmp2);
  1503. if (entry->attr->aggregator_addr.s_addr != -1)
  1504. printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
  1505. else
  1506. printf("|\n");
  1507. }
  1508. else
  1509. {
  1510. printf("%s|%u|",peer,route->peer_as);
  1511. printf("%s/%d|%s|%s\n",prefix,route->mask,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
  1512. }
  1513. }
  1514. static char *describe_origin(int origin) {
  1515. if(origin == 0) return "IGP";
  1516. if(origin == 1) return "EGP";
  1517. return "INCOMPLETE";
  1518. }
  1519. static void table_line_dump_v2_prefix(BGPDUMP_TABLE_DUMP_V2_PREFIX *e,BGPDUMP_ENTRY *entry)
  1520. {
  1521. struct tm *date = NULL;
  1522. unsigned int npref;
  1523. unsigned int nmed;
  1524. char time_str[20];
  1525. char peer[BGPDUMP_ADDRSTRLEN], prefix[BGPDUMP_ADDRSTRLEN], nexthop[BGPDUMP_ADDRSTRLEN];
  1526. int i;
  1527. for(i = 0; i < e->entry_count; i++) {
  1528. attributes_t *attr = e->entries[i].attr;
  1529. if(! attr)
  1530. continue;
  1531. char *origin = describe_origin(attr->origin);
  1532. char *aspath_str = (attr->aspath) ? attr->aspath->str: "";
  1533. char *aggregate = attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE) ? "AG" : "NAG";
  1534. if(e->entries[i].peer->afi == AFI_IP){
  1535. fmt_ipv4(e->entries[i].peer->peer_ip, peer);
  1536. #ifdef BGPDUMP_HAVE_IPV6
  1537. } else if(e->entries[i].peer->afi == AFI_IP6){
  1538. fmt_ipv6(e->entries[i].peer->peer_ip, peer);
  1539. #endif
  1540. }
  1541. if(e->afi == AFI_IP) {
  1542. fmt_ipv4(e->prefix, prefix);
  1543. #ifdef BGPDUMP_HAVE_IPV6
  1544. } else if(e->afi == AFI_IP6) {
  1545. fmt_ipv6(e->prefix, prefix);
  1546. #endif
  1547. }
  1548. time_t *t;
  1549. if (timetype==0) {
  1550. t = &entry->time;
  1551. } else {
  1552. time_t tmp = (time_t)((e->entries[i]).originated_time);
  1553. t = &tmp;
  1554. }
  1555. if (mode == 1) {
  1556. sprintf(time_str, "%ld", *t);
  1557. } else {
  1558. date=gmtime(t);
  1559. time2str(date, time_str);
  1560. }
  1561. show_line_prefix("TABLE_DUMP2", time_str, "B");
  1562. if (mode == 1)
  1563. {
  1564. printf("%s|%u|",peer,e->entries[i].peer->peer_as);
  1565. printf("%s/%d|%s|%s|",prefix,e->prefix_length,aspath_str,origin);
  1566. npref=attr->local_pref;
  1567. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
  1568. npref=0;
  1569. nmed=attr->med;
  1570. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
  1571. nmed=0;
  1572. #ifdef BGPDUMP_HAVE_IPV6
  1573. if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) && attr->mp_info->announce[AFI_IP6][SAFI_UNICAST])
  1574. {
  1575. fmt_ipv6(attr->mp_info->announce[AFI_IP6][SAFI_UNICAST]->nexthop,nexthop);
  1576. }
  1577. else
  1578. #endif
  1579. {
  1580. strncpy(nexthop, inet_ntoa(attr->nexthop), BGPDUMP_ADDRSTRLEN);
  1581. }
  1582. printf("%s|%u|%u|",nexthop,npref,nmed);
  1583. if( (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)
  1584. printf("%s|%s|",attr->community->str+1,aggregate);
  1585. else
  1586. printf("|%s|",aggregate);
  1587. if (attr->aggregator_addr.s_addr != -1)
  1588. printf("%u %s|\n",attr->aggregator_as,inet_ntoa(attr->aggregator_addr));
  1589. else
  1590. printf("|\n");
  1591. }
  1592. else
  1593. {
  1594. printf("%s|%u|",peer,e->entries[i].peer->peer_as);
  1595. printf("%s/%d|%s|%s\n",prefix,e->prefix_length,aspath_str,origin);
  1596. }
  1597. }
  1598. }