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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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(FRR_USER) && defined(FRR_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");
164 fprintf (stdout
,"%% Can't open configuration file %s due to '%s'.\n",
165 argv
[1], safe_strerror(errno
));
173 ret
= fread (s
->data
, 12, 1, fp
);
174 if (!ret
|| feof (fp
))
176 printf ("END OF FILE\n");
181 printf ("ERROR OF FREAD\n");
185 /* Extract header. */
186 now
= stream_getl (s
);
187 type
= stream_getw (s
);
188 subtype
= stream_getw (s
);
189 len
= stream_getl (s
);
191 printf ("TIME: %s", ctime (&now
));
193 /* printf ("TYPE: %d/%d\n", type, subtype); */
195 if (type
== MSG_PROTOCOL_BGP4MP
)
196 printf ("TYPE: BGP4MP");
197 else if (type
== MSG_PROTOCOL_BGP4MP_ET
)
198 printf ("TYPE: BGP4MP_ET");
199 else if (type
== MSG_TABLE_DUMP
)
200 printf ("TYPE: MSG_TABLE_DUMP");
202 printf ("TYPE: Unknown %d", type
);
204 if (type
== MSG_TABLE_DUMP
)
208 printf ("/AFI_IP\n");
211 printf ("/AFI_IP6\n");
214 printf ("/UNKNOWN %d", subtype
);
221 case BGP4MP_STATE_CHANGE
:
222 printf ("/CHANGE\n");
225 printf ("/MESSAGE\n");
230 case BGP4MP_SNAPSHOT
:
231 printf ("/SNAPSHOT\n");
234 printf ("/UNKNOWN %d", subtype
);
239 printf ("len: %zd\n", len
);
241 fread (s
->data
+ 12, len
, 1, fp
);
244 printf ("ENDOF FILE 2\n");
249 printf ("ERROR OF FREAD 2\n");
253 /* printf ("now read %d\n", len); */
255 if (type
== MSG_TABLE_DUMP
)
262 viewno
= stream_getw (s
);
263 seq_num
= stream_getw (s
);
264 printf ("VIEW: %d\n", viewno
);
265 printf ("SEQUENCE: %d\n", seq_num
);
268 while (s
->getp
< len
- 16)
270 p
.prefix
.s_addr
= stream_get_ipv4 (s
);
271 p
.prefixlen
= stream_getc (s
);
272 printf ("PREFIX: %s/%d\n", inet_ntoa (p
.prefix
), p
.prefixlen
);
274 status
= stream_getc (s
);
275 originated
= stream_getl (s
);
276 peer
.s_addr
= stream_get_ipv4 (s
);
277 source_as
= stream_getw(s
);
279 printf ("FROM: %s AS%d\n", inet_ntoa (peer
), source_as
);
280 printf ("ORIGINATED: %s", ctime (&originated
));
282 attrlen
= stream_getw (s
);
283 printf ("ATTRLEN: %d\n", attrlen
);
285 attr_parse (s
, attrlen
);
287 printf ("STATUS: 0x%x\n", status
);
292 source_as
= stream_getw (s
);
293 dest_as
= stream_getw (s
);
294 printf ("source_as: %d\n", source_as
);
295 printf ("dest_as: %d\n", dest_as
);
297 ifindex
= stream_getw (s
);
298 family
= stream_getw (s
);
300 printf ("ifindex: %d\n", ifindex
);
301 printf ("family: %d\n", family
);
303 sip
.s_addr
= stream_get_ipv4 (s
);
304 dip
.s_addr
= stream_get_ipv4 (s
);
306 printf ("saddr: %s\n", inet_ntoa (sip
));
307 printf ("daddr: %s\n", inet_ntoa (dip
));