1 /* BGP dump to ascii converter
2 Copyright (C) 1999 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
32 #include "bgpd/bgpd.h"
33 #include "bgpd/bgp_dump.h"
34 #include "bgpd/bgp_attr.h"
35 #include "bgpd/bgp_aspath.h"
38 static zebra_capabilities_t _caps_p [] =
45 struct zebra_privs_t bgpd_privs =
47 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
49 .group = QUAGGA_GROUP,
52 .vty_group = VTY_GROUP,
55 .cap_num_p = array_size(_caps_p),
61 MSG_START, /* sender is starting up */
62 MSG_DIE, /* receiver should shut down */
63 MSG_I_AM_DEAD, /* sender is shutting down */
64 MSG_PEER_DOWN, /* sender's peer is down */
65 MSG_PROTOCOL_BGP, /* msg is a BGP packet */
66 MSG_PROTOCOL_RIP, /* msg is a RIP packet */
67 MSG_PROTOCOL_IDRP, /* msg is an IDRP packet */
68 MSG_PROTOCOL_RIPNG, /* msg is a RIPNG packet */
69 MSG_PROTOCOL_BGP4PLUS, /* msg is a BGP4+ packet */
70 MSG_PROTOCOL_BGP4PLUS_01, /* msg is a BGP4+ (draft 01) packet */
71 MSG_PROTOCOL_OSPF, /* msg is an OSPF packet */
72 MSG_TABLE_DUMP /* routing table dump */
76 attr_parse (struct stream *s, u_int16_t len)
85 printf ("attr_parse s->getp %zd, len %d, lim %d\n", s->getp, len, lim);
89 flag = stream_getc (s);
90 type = stream_getc (s);
92 if (flag & BGP_ATTR_FLAG_EXTLEN)
93 length = stream_getw (s);
95 length = stream_getc (s);
97 printf ("FLAG: %d\n", flag);
98 printf ("TYPE: %d\n", type);
99 printf ("Len: %d\n", length);
103 case BGP_ATTR_ORIGIN:
106 origin = stream_getc (s);
107 printf ("ORIGIN: %d\n", origin);
110 case BGP_ATTR_AS_PATH:
112 struct aspath *aspath;
114 aspath = aspath_parse (s, length, 1);
115 printf ("ASPATH: %s\n", aspath->str);
119 case BGP_ATTR_NEXT_HOP:
121 struct in_addr nexthop;
122 nexthop.s_addr = stream_get_ipv4 (s);
123 printf ("NEXTHOP: %s\n", inet_ntoa (nexthop));
127 stream_getw_from (s, length);
136 main (int argc, char **argv)
151 u_int16_t viewno, seq_num;
152 struct prefix_ipv4 p;
154 s = stream_new (10000);
158 fprintf (stderr, "Usage: %s FILENAME\n", argv[0]);
161 fp = fopen (argv[1], "r");
172 ret = fread (s->data, 12, 1, fp);
173 if (!ret || feof (fp))
175 printf ("END OF FILE\n");
180 printf ("ERROR OF FREAD\n");
184 /* Extract header. */
185 now = stream_getl (s);
186 type = stream_getw (s);
187 subtype = stream_getw (s);
188 len = stream_getl (s);
190 printf ("TIME: %s", ctime (&now));
192 /* printf ("TYPE: %d/%d\n", type, subtype); */
194 if (type == MSG_PROTOCOL_BGP4MP)
195 printf ("TYPE: BGP4MP");
196 else if (type == MSG_PROTOCOL_BGP4MP_ET)
197 printf ("TYPE: BGP4MP_ET");
198 else if (type == MSG_TABLE_DUMP)
199 printf ("TYPE: MSG_TABLE_DUMP");
201 printf ("TYPE: Unknown %d", type);
203 if (type == MSG_TABLE_DUMP)
207 printf ("/AFI_IP\n");
210 printf ("/AFI_IP6\n");
213 printf ("/UNKNOWN %d", subtype);
220 case BGP4MP_STATE_CHANGE:
221 printf ("/CHANGE\n");
224 printf ("/MESSAGE\n");
229 case BGP4MP_SNAPSHOT:
230 printf ("/SNAPSHOT\n");
233 printf ("/UNKNOWN %d", subtype);
238 printf ("len: %zd\n", len);
240 ret = fread (s->data + 12, len, 1, fp);
243 printf ("ENDOF FILE 2\n");
248 printf ("ERROR OF FREAD 2\n");
252 /* printf ("now read %d\n", len); */
254 if (type == MSG_TABLE_DUMP)
261 viewno = stream_getw (s);
262 seq_num = stream_getw (s);
263 printf ("VIEW: %d\n", viewno);
264 printf ("SEQUENCE: %d\n", seq_num);
267 while (s->getp < len - 16)
269 p.prefix.s_addr = stream_get_ipv4 (s);
270 p.prefixlen = stream_getc (s);
271 printf ("PREFIX: %s/%d\n", inet_ntoa (p.prefix), p.prefixlen);
273 status = stream_getc (s);
274 originated = stream_getl (s);
275 peer.s_addr = stream_get_ipv4 (s);
276 source_as = stream_getw(s);
278 printf ("FROM: %s AS%d\n", inet_ntoa (peer), source_as);
279 printf ("ORIGINATED: %s", ctime (&originated));
281 attrlen = stream_getw (s);
282 printf ("ATTRLEN: %d\n", attrlen);
284 attr_parse (s, attrlen);
286 printf ("STATUS: 0x%x\n", status);
291 source_as = stream_getw (s);
292 dest_as = stream_getw (s);
293 printf ("source_as: %d\n", source_as);
294 printf ("dest_as: %d\n", dest_as);
296 ifindex = stream_getw (s);
297 family = stream_getw (s);
299 printf ("ifindex: %d\n", ifindex);
300 printf ("family: %d\n", family);
302 sip.s_addr = stream_get_ipv4 (s);
303 dip.s_addr = stream_get_ipv4 (s);
305 printf ("saddr: %s\n", inet_ntoa (sip));
306 printf ("daddr: %s\n", inet_ntoa (dip));