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
31 #include "bgpd/bgpd.h"
32 #include "bgpd/bgp_dump.h"
33 #include "bgpd/bgp_attr.h"
34 #include "bgpd/bgp_aspath.h"
37 static zebra_capabilities_t _caps_p
[] =
44 struct zebra_privs_t bgpd_privs
=
46 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
48 .group
= QUAGGA_GROUP
,
51 .vty_group
= VTY_GROUP
,
54 .cap_num_p
= array_size(_caps_p
),
60 MSG_START
, /* sender is starting up */
61 MSG_DIE
, /* receiver should shut down */
62 MSG_I_AM_DEAD
, /* sender is shutting down */
63 MSG_PEER_DOWN
, /* sender's peer is down */
64 MSG_PROTOCOL_BGP
, /* msg is a BGP packet */
65 MSG_PROTOCOL_RIP
, /* msg is a RIP packet */
66 MSG_PROTOCOL_IDRP
, /* msg is an IDRP packet */
67 MSG_PROTOCOL_RIPNG
, /* msg is a RIPNG packet */
68 MSG_PROTOCOL_BGP4PLUS
, /* msg is a BGP4+ packet */
69 MSG_PROTOCOL_BGP4PLUS_01
, /* msg is a BGP4+ (draft 01) packet */
70 MSG_PROTOCOL_OSPF
, /* msg is an OSPF packet */
71 MSG_TABLE_DUMP
/* routing table dump */
75 attr_parse (struct stream
*s
, u_int16_t len
)
84 printf ("attr_parse s->getp %zd, len %d, lim %d\n", s
->getp
, len
, lim
);
88 flag
= stream_getc (s
);
89 type
= stream_getc (s
);
91 if (flag
& BGP_ATTR_FLAG_EXTLEN
)
92 length
= stream_getw (s
);
94 length
= stream_getc (s
);
96 printf ("FLAG: %d\n", flag
);
97 printf ("TYPE: %d\n", type
);
98 printf ("Len: %d\n", length
);
102 case BGP_ATTR_ORIGIN
:
105 origin
= stream_getc (s
);
106 printf ("ORIGIN: %d\n", origin
);
109 case BGP_ATTR_AS_PATH
:
111 struct aspath
*aspath
;
113 aspath
= aspath_parse (s
, length
, 1);
114 printf ("ASPATH: %s\n", aspath
->str
);
118 case BGP_ATTR_NEXT_HOP
:
120 struct in_addr nexthop
;
121 nexthop
.s_addr
= stream_get_ipv4 (s
);
122 printf ("NEXTHOP: %s\n", inet_ntoa (nexthop
));
126 stream_getw_from (s
, length
);
135 main (int argc
, char **argv
)
150 u_int16_t viewno
, seq_num
;
151 struct prefix_ipv4 p
;
153 s
= stream_new (10000);
157 fprintf (stderr
, "Usage: %s FILENAME\n", argv
[0]);
160 fp
= fopen (argv
[1], "r");
171 ret
= fread (s
->data
, 12, 1, fp
);
172 if (!ret
|| feof (fp
))
174 printf ("END OF FILE\n");
179 printf ("ERROR OF FREAD\n");
183 /* Extract header. */
184 now
= stream_getl (s
);
185 type
= stream_getw (s
);
186 subtype
= stream_getw (s
);
187 len
= stream_getl (s
);
189 printf ("TIME: %s", ctime (&now
));
191 /* printf ("TYPE: %d/%d\n", type, subtype); */
193 if (type
== MSG_PROTOCOL_BGP4MP
)
194 printf ("TYPE: BGP4MP");
195 else if (type
== MSG_PROTOCOL_BGP4MP_ET
)
196 printf ("TYPE: BGP4MP_ET");
197 else if (type
== MSG_TABLE_DUMP
)
198 printf ("TYPE: MSG_TABLE_DUMP");
200 printf ("TYPE: Unknown %d", type
);
202 if (type
== MSG_TABLE_DUMP
)
206 printf ("/AFI_IP\n");
209 printf ("/AFI_IP6\n");
212 printf ("/UNKNOWN %d", subtype
);
219 case BGP4MP_STATE_CHANGE
:
220 printf ("/CHANGE\n");
223 printf ("/MESSAGE\n");
228 case BGP4MP_SNAPSHOT
:
229 printf ("/SNAPSHOT\n");
232 printf ("/UNKNOWN %d", subtype
);
237 printf ("len: %zd\n", len
);
239 ret
= fread (s
->data
+ 12, len
, 1, fp
);
242 printf ("ENDOF FILE 2\n");
247 printf ("ERROR OF FREAD 2\n");
251 /* printf ("now read %d\n", len); */
253 if (type
== MSG_TABLE_DUMP
)
260 viewno
= stream_getw (s
);
261 seq_num
= stream_getw (s
);
262 printf ("VIEW: %d\n", viewno
);
263 printf ("SEQUENCE: %d\n", seq_num
);
266 while (s
->getp
< len
- 16)
268 p
.prefix
.s_addr
= stream_get_ipv4 (s
);
269 p
.prefixlen
= stream_getc (s
);
270 printf ("PREFIX: %s/%d\n", inet_ntoa (p
.prefix
), p
.prefixlen
);
272 status
= stream_getc (s
);
273 originated
= stream_getl (s
);
274 peer
.s_addr
= stream_get_ipv4 (s
);
275 source_as
= stream_getw(s
);
277 printf ("FROM: %s AS%d\n", inet_ntoa (peer
), source_as
);
278 printf ("ORIGINATED: %s", ctime (&originated
));
280 attrlen
= stream_getw (s
);
281 printf ("ATTRLEN: %d\n", attrlen
);
283 attr_parse (s
, attrlen
);
285 printf ("STATUS: 0x%x\n", status
);
290 source_as
= stream_getw (s
);
291 dest_as
= stream_getw (s
);
292 printf ("source_as: %d\n", source_as
);
293 printf ("dest_as: %d\n", dest_as
);
295 ifindex
= stream_getw (s
);
296 family
= stream_getw (s
);
298 printf ("ifindex: %d\n", ifindex
);
299 printf ("family: %d\n", family
);
301 sip
.s_addr
= stream_get_ipv4 (s
);
302 dip
.s_addr
= stream_get_ipv4 (s
);
304 printf ("saddr: %s\n", inet_ntoa (sip
));
305 printf ("daddr: %s\n", inet_ntoa (dip
));