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
29 #include "bgpd/bgpd.h"
30 #include "bgpd/bgp_dump.h"
31 #include "bgpd/bgp_attr.h"
32 #include "bgpd/bgp_aspath.h"
36 MSG_START
, /* sender is starting up */
37 MSG_DIE
, /* receiver should shut down */
38 MSG_I_AM_DEAD
, /* sender is shutting down */
39 MSG_PEER_DOWN
, /* sender's peer is down */
40 MSG_PROTOCOL_BGP
, /* msg is a BGP packet */
41 MSG_PROTOCOL_RIP
, /* msg is a RIP packet */
42 MSG_PROTOCOL_IDRP
, /* msg is an IDRP packet */
43 MSG_PROTOCOL_RIPNG
, /* msg is a RIPNG packet */
44 MSG_PROTOCOL_BGP4PLUS
, /* msg is a BGP4+ packet */
45 MSG_PROTOCOL_BGP4PLUS_01
, /* msg is a BGP4+ (draft 01) packet */
46 MSG_PROTOCOL_OSPF
, /* msg is an OSPF packet */
47 MSG_TABLE_DUMP
/* routing table dump */
51 attr_parse (struct stream
*s
, u_int16_t len
)
60 printf ("attr_parse s->getp %d, len %d, lim %d\n", s
->getp
, len
, lim
);
64 flag
= stream_getc (s
);
65 type
= stream_getc (s
);
67 if (flag
& ATTR_FLAG_EXTLEN
)
68 length
= stream_getw (s
);
70 length
= stream_getc (s
);
72 printf ("FLAG: %d\n", flag
);
73 printf ("TYPE: %d\n", type
);
74 printf ("Len: %d\n", length
);
81 origin
= stream_getc (s
);
82 printf ("ORIGIN: %d\n", origin
);
85 case BGP_ATTR_AS_PATH
:
89 aspath
.data
= (s
->data
+ s
->getp
);
90 aspath
.length
= length
;
91 aspath
.str
= aspath_make_str_count (&aspath
);
92 printf ("ASPATH: %s\n", aspath
.str
);
95 stream_forward (s
, length
);
98 case BGP_ATTR_NEXT_HOP
:
100 struct in_addr nexthop
;
101 nexthop
.s_addr
= stream_get_ipv4 (s
);
102 printf ("NEXTHOP: %s\n", inet_ntoa (nexthop
));
103 /* stream_forward (s, length); */
107 stream_forward (s
, length
);
116 main (int argc
, char **argv
)
131 u_int16_t viewno
, seq_num
;
132 struct prefix_ipv4 p
;
134 s
= stream_new (10000);
138 fprintf (stderr
, "Usage: %s FILENAME\n", argv
[0]);
141 fp
= fopen (argv
[1], "r");
152 ret
= fread (s
->data
, 12, 1, fp
);
155 printf ("END OF FILE\n");
160 printf ("ERROR OF FREAD\n");
164 /* Extract header. */
165 now
= stream_getl (s
);
166 type
= stream_getw (s
);
167 subtype
= stream_getw (s
);
168 len
= stream_getl (s
);
170 printf ("TIME: %s", ctime (&now
));
172 /* printf ("TYPE: %d/%d\n", type, subtype); */
174 if (type
== MSG_PROTOCOL_BGP4MP
)
175 printf ("TYPE: BGP4MP");
176 else if (type
== MSG_TABLE_DUMP
)
177 printf ("TYPE: MSG_TABLE_DUMP");
179 printf ("TYPE: Unknown %d", type
);
181 if (type
== MSG_TABLE_DUMP
)
185 printf ("/AFI_IP\n");
188 printf ("/AFI_IP6\n");
191 printf ("/UNKNOWN %d", subtype
);
198 case BGP4MP_STATE_CHANGE
:
199 printf ("/CHANGE\n");
202 printf ("/MESSAGE\n");
207 case BGP4MP_SNAPSHOT
:
208 printf ("/SNAPSHOT\n");
211 printf ("/UNKNOWN %d", subtype
);
216 printf ("len: %d\n", len
);
218 ret
= fread (s
->data
+ 12, len
, 1, fp
);
221 printf ("ENDOF FILE 2\n");
226 printf ("ERROR OF FREAD 2\n");
230 /* printf ("now read %d\n", len); */
232 if (type
== MSG_TABLE_DUMP
)
239 viewno
= stream_getw (s
);
240 seq_num
= stream_getw (s
);
241 printf ("VIEW: %d\n", viewno
);
242 printf ("SEQUENCE: %d\n", seq_num
);
245 while (s
->getp
< len
- 16)
247 p
.prefix
.s_addr
= stream_get_ipv4 (s
);
248 p
.prefixlen
= stream_getc (s
);
249 printf ("PREFIX: %s/%d\n", inet_ntoa (p
.prefix
), p
.prefixlen
);
251 status
= stream_getc (s
);
252 originated
= stream_getl (s
);
253 peer
.s_addr
= stream_get_ipv4 (s
);
254 source_as
= stream_getw(s
);
256 printf ("FROM: %s AS%d\n", inet_ntoa (peer
), source_as
);
257 printf ("ORIGINATED: %s", ctime (&originated
));
259 attrlen
= stream_getw (s
);
260 printf ("ATTRLEN: %d\n", attrlen
);
262 attr_parse (s
, attrlen
);
264 printf ("STATUS: 0x%x\n", status
);
269 source_as
= stream_getw (s
);
270 dest_as
= stream_getw (s
);
271 printf ("source_as: %d\n", source_as
);
272 printf ("dest_as: %d\n", dest_as
);
274 ifindex
= stream_getw (s
);
275 family
= stream_getw (s
);
277 printf ("ifindex: %d\n", ifindex
);
278 printf ("family: %d\n", family
);
280 sip
.s_addr
= stream_get_ipv4 (s
);
281 dip
.s_addr
= stream_get_ipv4 (s
);
283 printf ("saddr: %s\n", inet_ntoa (sip
));
284 printf ("daddr: %s\n", inet_ntoa (dip
));