2 * Copyright (C) 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static const char rcsid
[] =
36 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.38 2002-07-22 02:55:20 hannes Exp $";
39 #include <sys/param.h>
41 #include <sys/types.h>
42 #include <sys/socket.h>
44 #include <netinet/in.h>
51 #include "interface.h"
52 #include "addrtoname.h"
56 u_int8_t bgp_marker
[16];
60 #define BGP_SIZE 19 /* unaligned */
64 #define BGP_NOTIFICATION 3
65 #define BGP_KEEPALIVE 4
66 #define BGP_ROUTE_REFRESH 5
68 static struct tok bgp_msg_values
[] = {
70 { BGP_UPDATE
, "Update"},
71 { BGP_NOTIFICATION
, "Notification"},
72 { BGP_KEEPALIVE
, "Keepalive"},
73 { BGP_ROUTE_REFRESH
, "Route Refresh"},
78 u_int8_t bgpo_marker
[16];
81 u_int8_t bgpo_version
;
83 u_int16_t bgpo_holdtime
;
86 /* options should follow */
88 #define BGP_OPEN_SIZE 29 /* unaligned */
95 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
97 struct bgp_notification
{
98 u_int8_t bgpn_marker
[16];
103 /* data should follow */
105 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
114 #define bgp_attr_len(p) \
115 (((p)->bgpa_flags & 0x10) ? \
116 ntohs((p)->bgpa_len.elen) : (p)->bgpa_len.len)
117 #define bgp_attr_off(p) \
118 (((p)->bgpa_flags & 0x10) ? 4 : 3)
121 #define BGPTYPE_ORIGIN 1
122 #define BGPTYPE_AS_PATH 2
123 #define BGPTYPE_NEXT_HOP 3
124 #define BGPTYPE_MULTI_EXIT_DISC 4
125 #define BGPTYPE_LOCAL_PREF 5
126 #define BGPTYPE_ATOMIC_AGGREGATE 6
127 #define BGPTYPE_AGGREGATOR 7
128 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
129 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
130 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
131 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
132 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
133 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
134 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
135 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
136 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
138 static struct tok bgp_attr_values
[] = {
139 { BGPTYPE_ORIGIN
, "Origin"},
140 { BGPTYPE_AS_PATH
, "AS Path"},
141 { BGPTYPE_NEXT_HOP
, "Next Hop"},
142 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
143 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
144 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
145 { BGPTYPE_AGGREGATOR
, "Aggregator"},
146 { BGPTYPE_COMMUNITIES
, "Community"},
147 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
148 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
149 { BGPTYPE_DPA
, "DPA"},
150 { BGPTYPE_ADVERTISERS
, "Advertisers"},
151 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
152 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
153 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
154 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
155 { 255, "Reserved for development"},
159 #define BGP_OPT_AUTH 1
160 #define BGP_OPT_CAP 2
163 static struct tok bgp_opt_values
[] = {
164 { BGP_OPT_AUTH
, "Authentication Information"},
165 { BGP_OPT_CAP
, "Capabilities Advertisement"},
169 #define BGP_CAPCODE_MP 1
170 #define BGP_CAPCODE_RR 2
171 #define BGP_CAPCODE_RR_CISCO 128
173 static struct tok bgp_capcode_values
[] = {
174 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
175 { BGP_CAPCODE_RR
, "Route Refresh"},
176 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
180 #define BGP_NOTIFY_MAJOR_MSG 1
181 #define BGP_NOTIFY_MAJOR_OPEN 2
182 #define BGP_NOTIFY_MAJOR_UPDATE 3
183 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
184 #define BGP_NOTIFY_MAJOR_FSM 5
185 #define BGP_NOTIFY_MAJOR_CEASE 6
187 static struct tok bgp_notify_major_values
[] = {
188 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
189 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
190 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
191 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
192 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
193 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
197 static struct tok bgp_notify_minor_msg_values
[] = {
198 { 1, "Connection Not Synchronized"},
199 { 2, "Bad Message Length"},
200 { 3, "Bad Message Type"},
204 static struct tok bgp_notify_minor_open_values
[] = {
205 { 1, "Unsupported Version Number"},
207 { 3, "Bad BGP Identifier"},
208 { 4, "Unsupported Optional Parameter"},
209 { 5, "Authentication Failure"},
210 { 6, "Unacceptable Hold Time"},
214 static struct tok bgp_notify_minor_update_values
[] = {
215 { 1, "Malformed Attribute List"},
216 { 2, "Unrecognized Well-known Attribute"},
217 { 3, "Missing Well-known Attribute"},
218 { 4, "Attribute Flags Error"},
219 { 5, "Attribute Length Error"},
220 { 6, "Invalid ORIGIN Attribute"},
221 { 7, "AS Routing Loop"},
222 { 8, "Invalid NEXT_HOP Attribute"},
223 { 9, "Optional Attribute Error"},
224 { 10, "Invalid Network Field"},
225 { 11, "Malformed AS_PATH"},
229 static struct tok bgp_origin_values
[] = {
236 /* Subsequent address family identifier, RFC2283 section 7 */
238 #define SAFNUM_UNICAST 1
239 #define SAFNUM_MULTICAST 2
240 #define SAFNUM_UNIMULTICAST 3
241 /* labeled BGP RFC3107 */
242 #define SAFNUM_LABUNICAST 4
243 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
244 #define SAFNUM_VPNUNICAST 128
245 #define SAFNUM_VPNMULTICAST 129
246 #define SAFNUM_VPNUNIMULTICAST 130
248 static struct tok bgp_safi_values
[] = {
249 { SAFNUM_RES
, "Reserved"},
250 { SAFNUM_UNICAST
, "Unicast"},
251 { SAFNUM_MULTICAST
, "Multicast"},
252 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
253 { SAFNUM_LABUNICAST
, "labeled Unicast"},
254 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
255 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
256 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
260 /* well-known community */
261 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
262 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
263 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
265 /* RFC1700 address family numbers */
267 #define AFNUM_INET6 2
270 #define AFNUM_BBN1822 5
275 #define AFNUM_X121 10
277 #define AFNUM_ATALK 12
278 #define AFNUM_DECNET 13
279 #define AFNUM_BANYAN 14
280 #define AFNUM_E164NSAP 15
281 /* draft-kompella-ppvpn-l2vpn */
282 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
284 static struct tok bgp_afi_values
[] = {
286 { AFNUM_INET
, "IPv4"},
287 { AFNUM_INET6
, "IPv6"},
288 { AFNUM_NSAP
, "NSAP"},
289 { AFNUM_HDLC
, "HDLC"},
290 { AFNUM_BBN1822
, "BBN 1822"},
292 { AFNUM_E163
, "E.163"},
293 { AFNUM_E164
, "E.164"},
294 { AFNUM_F69
, "F.69"},
295 { AFNUM_X121
, "X.121"},
296 { AFNUM_IPX
, "Novell IPX"},
297 { AFNUM_ATALK
, "Appletalk"},
298 { AFNUM_DECNET
, "Decnet IV"},
299 { AFNUM_BANYAN
, "Banyan Vines"},
300 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
301 { AFNUM_L2VPN
, "Layer-2 VPN"},
305 static struct tok bgp_extd_comm_subtype_values
[] = {
313 decode_prefix4(const u_char
*pd
, char *buf
, u_int buflen
)
319 if (plen
< 0 || 32 < plen
)
322 memset(&addr
, 0, sizeof(addr
));
323 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
325 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
326 ((0xff00 >> (plen
% 8)) & 0xff);
328 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
329 return 1 + (plen
+ 7) / 8;
333 decode_labeled_prefix4(const u_char
*pd
, char *buf
, u_int buflen
)
338 plen
= pd
[0]; /* get prefix length */
340 /* this is one of the weirdnesses of rfc3107
341 the label length (actually the label + COS bits)
342 is added of the prefix length;
343 we also do only read out just one label -
344 there is no real application for advertisment of
345 stacked labels in a a single BGP message
348 plen
-=24; /* adjust prefixlen - labellength */
350 if (plen
< 0 || 32 < plen
)
353 memset(&addr
, 0, sizeof(addr
));
354 memcpy(&addr
, &pd
[4], (plen
+ 7) / 8);
356 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
357 ((0xff00 >> (plen
% 8)) & 0xff);
359 /* the label may get offsetted by 4 bits so lets shift it right */
360 snprintf(buf
, buflen
, "%s/%d label:%u %s",
361 getname((u_char
*)&addr
),
363 EXTRACT_24BITS(pd
+1)>>4,
364 ((pd
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
366 return 4 + (plen
+ 7) / 8;
371 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
373 struct in6_addr addr
;
377 if (plen
< 0 || 128 < plen
)
380 memset(&addr
, 0, sizeof(addr
));
381 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
383 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
384 ((0xff00 >> (plen
% 8)) & 0xff);
386 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
387 return 1 + (plen
+ 7) / 8;
392 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*dat
, int len
)
400 char buf
[MAXHOSTNAMELEN
+ 100];
405 switch (attr
->bgpa_type
) {
408 printf("invalid len");
410 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", p
[0]));
412 case BGPTYPE_AS_PATH
:
414 printf("invalid len");
421 while (p
< dat
+ len
) {
423 * under RFC1965, p[0] means:
424 * 1: AS_SET 2: AS_SEQUENCE
425 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
427 if (p
[0] == 3 || p
[0] == 4)
429 printf("%s", (p
[0] & 1) ? "{" : "");
430 for (i
= 0; i
< p
[1] * 2; i
+= 2) {
431 printf("%s%u", i
== 0 ? "" : " ",
432 EXTRACT_16BITS(&p
[2 + i
]));
434 printf("%s", (p
[0] & 1) ? "}" : "");
438 case BGPTYPE_NEXT_HOP
:
440 printf("invalid len");
442 printf("%s", getname(p
));
444 case BGPTYPE_MULTI_EXIT_DISC
:
445 case BGPTYPE_LOCAL_PREF
:
447 printf("invalid len");
449 printf("%u", EXTRACT_32BITS(p
));
451 case BGPTYPE_ATOMIC_AGGREGATE
:
453 printf("invalid len");
455 case BGPTYPE_AGGREGATOR
:
457 printf("invalid len");
460 printf(" AS #%u, origin %s", EXTRACT_16BITS(p
),
463 case BGPTYPE_COMMUNITIES
:
465 printf("invalid len");
470 comm
= EXTRACT_32BITS(p
);
472 case BGP_COMMUNITY_NO_EXPORT
:
473 printf(" NO_EXPORT");
475 case BGP_COMMUNITY_NO_ADVERT
:
476 printf(" NO_ADVERTISE");
478 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
479 printf(" NO_EXPORT_SUBCONFED");
483 (comm
>> 16) & 0xffff,
485 (tlen
>4) ? ", " : "");
492 case BGPTYPE_ORIGINATOR_ID
:
494 printf("invalid len");
497 printf("%s",getname(p
));
499 case BGPTYPE_CLUSTER_LIST
:
503 (tlen
>4) ? ", " : "");
508 case BGPTYPE_MP_REACH_NLRI
:
509 af
= EXTRACT_16BITS(p
);
512 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
513 tok2str(bgp_afi_values
, "Unknown AFI", af
),
515 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
516 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
519 if (af
== AFNUM_INET
)
522 else if (af
== AFNUM_INET6
)
526 printf("\n\t no AFI %u decoder",af
);
527 print_unknown_data(p
,"\n\t ",tlen
);
534 printf("\n\t nexthop: ");
541 case SAFNUM_MULTICAST
:
542 case SAFNUM_UNIMULTICAST
:
543 case SAFNUM_LABUNICAST
:
544 printf("%s", getname(p
+ 1 + i
));
545 i
+= sizeof(struct in_addr
);
548 printf("no SAFI %u decoder",safi
);
549 print_unknown_data(p
,"\n\t ",tlen
);
558 case SAFNUM_MULTICAST
:
559 case SAFNUM_UNIMULTICAST
:
560 case SAFNUM_LABUNICAST
:
561 printf("%s", getname6(p
+ 1 + i
));
562 i
+= sizeof(struct in6_addr
);
565 printf("no SAFI %u decoder",safi
);
566 print_unknown_data(p
,"\n\t ",tlen
);
572 printf("no AFI %u decoder",af
);
573 print_unknown_data(p
,"\n\t ",tlen
);
574 i
= tlen
; /*exit loop*/
584 printf("\n\t %u SNPA", snpa
);
585 for (/*nothing*/; snpa
> 0; snpa
--) {
586 printf("\n\t %d bytes", p
[0]);
593 while (len
- (p
- dat
) > 0) {
598 case SAFNUM_MULTICAST
:
599 case SAFNUM_UNIMULTICAST
:
600 advance
= decode_prefix4(p
, buf
, sizeof(buf
));
601 printf("\n\t %s", buf
);
603 case SAFNUM_LABUNICAST
:
604 advance
= decode_labeled_prefix4(p
, buf
, sizeof(buf
));
605 printf("\n\t %s", buf
);
608 printf("\n\t no SAFI %u decoder",safi
);
609 print_unknown_data(p
-3,"\n\t ",tlen
);
619 case SAFNUM_MULTICAST
:
620 case SAFNUM_UNIMULTICAST
:
621 advance
= decode_prefix6(p
, buf
, sizeof(buf
));
622 printf("\n\t %s", buf
);
625 printf("\n\t no SAFI %u decoder ",safi
);
626 print_unknown_data(p
-3,"\n\t ",tlen
);
634 printf("\n\t no AFI %u decoder ",af
);
635 print_unknown_data(p
-3,"\n\t ",tlen
);
646 case BGPTYPE_MP_UNREACH_NLRI
:
647 af
= EXTRACT_16BITS(p
);
650 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
651 tok2str(bgp_afi_values
, "Unknown AFI", af
),
653 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
654 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
659 while (len
- (p
- dat
) > 0) {
664 case SAFNUM_MULTICAST
:
665 case SAFNUM_UNIMULTICAST
:
666 advance
= decode_prefix4(p
, buf
, sizeof(buf
));
667 printf("\n\t %s", buf
);
669 case SAFNUM_LABUNICAST
:
670 advance
= decode_labeled_prefix4(p
, buf
, sizeof(buf
));
671 printf("\n\t %s", buf
);
674 printf("\n\t no SAFI %u decoder",safi
);
675 print_unknown_data(p
-3,"\n\t ",tlen
);
686 case SAFNUM_MULTICAST
:
687 case SAFNUM_UNIMULTICAST
:
688 advance
= decode_prefix6(p
, buf
, sizeof(buf
));
689 printf("\n\t %s", buf
);
692 printf("\n\t no SAFI %u decoder",safi
);
693 print_unknown_data(p
-3,"\n\t ",tlen
);
701 printf("\n\t no AFI %u decoder",af
);
702 print_unknown_data(p
-3,"\n\t ",tlen
);
711 case BGPTYPE_EXTD_COMMUNITIES
:
713 printf("invalid len");
717 u_int8_t extd_comm
,extd_comm_type
,extd_comm_subtype
;
719 extd_comm_type
=extd_comm
&0x3f;
720 extd_comm_subtype
=*(p
+1);
721 switch(extd_comm_type
) {
723 printf("%s%s%s:%u:%s%s",
724 (extd_comm
&0x80) ? "vendor-specific: " : "",
725 (extd_comm
&0x40) ? "non-transitive:" : "",
726 tok2str(bgp_extd_comm_subtype_values
,
728 extd_comm_subtype
&0x3f),
731 (tlen
>8) ? ", " : "");
734 printf("%s%s%s:%s:%u%s",
735 (extd_comm
&0x80) ? "vendor-specific: " : "",
736 (extd_comm
&0x40) ? "non-transitive:" : "",
737 tok2str(bgp_extd_comm_subtype_values
,
739 extd_comm_subtype
&0x3f),
742 (tlen
>8) ? ", " : "");
745 printf("%s%s%s:%u:%u%s",
746 (extd_comm
&0x80) ? "vendor-specific: " : "",
747 (extd_comm
&0x40) ? "non-transitive:" : "",
748 tok2str(bgp_extd_comm_subtype_values
,
750 extd_comm_subtype
&0x3f),
753 (tlen
>8) ? ", " : "");
757 printf("\n\t no typecode %u decoder",
759 print_unknown_data(p
,"\n\t ",8);
768 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
769 print_unknown_data(p
,"\n\t ",tlen
);
775 bgp_open_print(const u_char
*dat
, int length
)
777 struct bgp_open bgpo
;
778 struct bgp_opt bgpopt
;
781 int i
,cap_type
,cap_len
;
783 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
784 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
785 hlen
= ntohs(bgpo
.bgpo_len
);
787 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
788 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
789 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
790 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
791 printf("\n\t Optional parameters, length %u", bgpo
.bgpo_optlen
);
794 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
798 while (i
< bgpo
.bgpo_optlen
) {
799 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
800 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
801 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
802 printf("\n\t Option %d, length %d", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
806 printf("\n\t Option %s (%u), length %d",
807 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
811 /* now lets decode the options we know*/
812 switch(bgpopt
.bgpopt_type
) {
814 cap_type
=opt
[i
+BGP_OPT_SIZE
];
815 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
816 printf("\n\t %s, length %u",
817 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
821 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
822 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
823 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
824 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
825 opt
[i
+BGP_OPT_SIZE
+5]);
828 case BGP_CAPCODE_RR_CISCO
:
831 printf("\n\t\tno decoder for Capability %u",
838 printf("\n\t no decoder for option %u",
843 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
851 bgp_update_print(const u_char
*dat
, int length
)
854 struct bgp_attr bgpa
;
860 TCHECK2(dat
[0], BGP_SIZE
);
861 memcpy(&bgp
, dat
, BGP_SIZE
);
862 hlen
= ntohs(bgp
.bgp_len
);
863 p
= dat
+ BGP_SIZE
; /*XXX*/
865 /* Unfeasible routes */
866 len
= EXTRACT_16BITS(p
);
869 * Without keeping state from the original NLRI message,
870 * it's not possible to tell if this a v4 or v6 route,
871 * so only try to decode it if we're not v6 enabled.
874 printf("\n\t Withdrawn routes: %d bytes", len
);
876 char buf
[MAXHOSTNAMELEN
+ 100];
881 printf("\n\t Withdrawn routes:");
884 i
+= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
885 printf("\n\t %s", buf
);
892 len
= EXTRACT_16BITS(p
);
894 /* do something more useful!*/
896 while (i
< 2 + len
) {
899 TCHECK2(p
[i
], sizeof(bgpa
));
900 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
901 alen
= bgp_attr_len(&bgpa
);
902 aoff
= bgp_attr_off(&bgpa
);
904 printf("\n\t %s (%u), length: %u",
905 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
909 if (bgpa
.bgpa_flags
) {
910 printf(", flags [%s%s%s%s",
911 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
912 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
913 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
914 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
915 if (bgpa
.bgpa_flags
& 0xf)
916 printf("+%x", bgpa
.bgpa_flags
& 0xf);
919 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
925 if (dat
+ length
> p
) {
926 printf("\n\t Updated routes:");
927 while (dat
+ length
> p
) {
928 char buf
[MAXHOSTNAMELEN
+ 100];
929 i
= decode_prefix4(p
, buf
, sizeof(buf
));
930 printf("\n\t %s", buf
);
942 bgp_notification_print(const u_char
*dat
, int length
)
944 struct bgp_notification bgpn
;
947 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
948 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
949 hlen
= ntohs(bgpn
.bgpn_len
);
951 printf(", Error - %s", tok2str(bgp_notify_major_values
, "Unknown", bgpn
.bgpn_major
));
953 switch (bgpn
.bgpn_major
) {
955 case BGP_NOTIFY_MAJOR_MSG
:
956 printf(" subcode %s", tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
));
958 case BGP_NOTIFY_MAJOR_OPEN
:
959 printf(" subcode %s", tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
));
961 case BGP_NOTIFY_MAJOR_UPDATE
:
962 printf(" subcode %s", tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
));
974 bgp_header_print(const u_char
*dat
, int length
)
978 TCHECK2(dat
[0], BGP_SIZE
);
979 memcpy(&bgp
, dat
, BGP_SIZE
);
980 printf("\n\t%s Message (%u), length: %u ",
981 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
985 switch (bgp
.bgp_type
) {
987 bgp_open_print(dat
, length
);
990 bgp_update_print(dat
, length
);
992 case BGP_NOTIFICATION
:
993 bgp_notification_print(dat
, length
);
998 /* we have no decoder for the BGP message */
999 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1000 print_unknown_data(dat
,"\n\t ",length
);
1009 bgp_print(const u_char
*dat
, int length
)
1013 const u_char
*start
;
1014 const u_char marker
[] = {
1015 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1016 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1022 if (snapend
< dat
+ length
)
1029 while (p
< snapend
) {
1030 if (!TTEST2(p
[0], 1))
1037 if (!TTEST2(p
[0], sizeof(marker
)))
1039 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1044 /* found BGP header */
1045 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1046 memcpy(&bgp
, p
, BGP_SIZE
);
1051 hlen
= ntohs(bgp
.bgp_len
);
1053 if (TTEST2(p
[0], hlen
)) {
1054 bgp_header_print(p
, hlen
);
1058 printf("[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));