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.42 2002-07-24 00:10:46 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 */
107 struct bgp_route_refresh
{
108 u_int8_t bgp_marker
[16];
111 u_int8_t afi
; /* the compiler messes this structure up */
112 u_int8_t pad
; /* when doing misaligned sequences of int8 and int16 */
113 u_int8_t res
; /* afi should be int16 - so we have to access it using */
114 u_int8_t safi
; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
116 #define BGP_ROUTE_REFRESH_SIZE 23
125 #define bgp_attr_len(p) \
126 (((p)->bgpa_flags & 0x10) ? \
127 ntohs((p)->bgpa_len.elen) : (p)->bgpa_len.len)
128 #define bgp_attr_off(p) \
129 (((p)->bgpa_flags & 0x10) ? 4 : 3)
132 #define BGPTYPE_ORIGIN 1
133 #define BGPTYPE_AS_PATH 2
134 #define BGPTYPE_NEXT_HOP 3
135 #define BGPTYPE_MULTI_EXIT_DISC 4
136 #define BGPTYPE_LOCAL_PREF 5
137 #define BGPTYPE_ATOMIC_AGGREGATE 6
138 #define BGPTYPE_AGGREGATOR 7
139 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
140 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
141 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
142 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
143 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
144 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
145 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
146 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
147 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
149 static struct tok bgp_attr_values
[] = {
150 { BGPTYPE_ORIGIN
, "Origin"},
151 { BGPTYPE_AS_PATH
, "AS Path"},
152 { BGPTYPE_NEXT_HOP
, "Next Hop"},
153 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
154 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
155 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
156 { BGPTYPE_AGGREGATOR
, "Aggregator"},
157 { BGPTYPE_COMMUNITIES
, "Community"},
158 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
159 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
160 { BGPTYPE_DPA
, "DPA"},
161 { BGPTYPE_ADVERTISERS
, "Advertisers"},
162 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
163 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
164 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
165 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
166 { 255, "Reserved for development"},
170 #define BGP_OPT_AUTH 1
171 #define BGP_OPT_CAP 2
174 static struct tok bgp_opt_values
[] = {
175 { BGP_OPT_AUTH
, "Authentication Information"},
176 { BGP_OPT_CAP
, "Capabilities Advertisement"},
180 #define BGP_CAPCODE_MP 1
181 #define BGP_CAPCODE_RR 2
182 #define BGP_CAPCODE_RR_CISCO 128
184 static struct tok bgp_capcode_values
[] = {
185 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
186 { BGP_CAPCODE_RR
, "Route Refresh"},
187 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
191 #define BGP_NOTIFY_MAJOR_MSG 1
192 #define BGP_NOTIFY_MAJOR_OPEN 2
193 #define BGP_NOTIFY_MAJOR_UPDATE 3
194 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
195 #define BGP_NOTIFY_MAJOR_FSM 5
196 #define BGP_NOTIFY_MAJOR_CEASE 6
198 static struct tok bgp_notify_major_values
[] = {
199 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
200 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
201 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
202 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
203 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
204 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
208 static struct tok bgp_notify_minor_msg_values
[] = {
209 { 1, "Connection Not Synchronized"},
210 { 2, "Bad Message Length"},
211 { 3, "Bad Message Type"},
215 static struct tok bgp_notify_minor_open_values
[] = {
216 { 1, "Unsupported Version Number"},
218 { 3, "Bad BGP Identifier"},
219 { 4, "Unsupported Optional Parameter"},
220 { 5, "Authentication Failure"},
221 { 6, "Unacceptable Hold Time"},
225 static struct tok bgp_notify_minor_update_values
[] = {
226 { 1, "Malformed Attribute List"},
227 { 2, "Unrecognized Well-known Attribute"},
228 { 3, "Missing Well-known Attribute"},
229 { 4, "Attribute Flags Error"},
230 { 5, "Attribute Length Error"},
231 { 6, "Invalid ORIGIN Attribute"},
232 { 7, "AS Routing Loop"},
233 { 8, "Invalid NEXT_HOP Attribute"},
234 { 9, "Optional Attribute Error"},
235 { 10, "Invalid Network Field"},
236 { 11, "Malformed AS_PATH"},
240 static struct tok bgp_origin_values
[] = {
247 /* Subsequent address family identifier, RFC2283 section 7 */
249 #define SAFNUM_UNICAST 1
250 #define SAFNUM_MULTICAST 2
251 #define SAFNUM_UNIMULTICAST 3
252 /* labeled BGP RFC3107 */
253 #define SAFNUM_LABUNICAST 4
254 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
255 #define SAFNUM_VPNUNICAST 128
256 #define SAFNUM_VPNMULTICAST 129
257 #define SAFNUM_VPNUNIMULTICAST 130
259 #define BGP_VPN_RD_LEN 8
261 static struct tok bgp_safi_values
[] = {
262 { SAFNUM_RES
, "Reserved"},
263 { SAFNUM_UNICAST
, "Unicast"},
264 { SAFNUM_MULTICAST
, "Multicast"},
265 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
266 { SAFNUM_LABUNICAST
, "labeled Unicast"},
267 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
268 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
269 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
273 /* well-known community */
274 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
275 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
276 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
278 /* RFC1700 address family numbers */
280 #define AFNUM_INET6 2
283 #define AFNUM_BBN1822 5
288 #define AFNUM_X121 10
290 #define AFNUM_ATALK 12
291 #define AFNUM_DECNET 13
292 #define AFNUM_BANYAN 14
293 #define AFNUM_E164NSAP 15
294 /* draft-kompella-ppvpn-l2vpn */
295 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
297 static struct tok bgp_afi_values
[] = {
299 { AFNUM_INET
, "IPv4"},
300 { AFNUM_INET6
, "IPv6"},
301 { AFNUM_NSAP
, "NSAP"},
302 { AFNUM_HDLC
, "HDLC"},
303 { AFNUM_BBN1822
, "BBN 1822"},
305 { AFNUM_E163
, "E.163"},
306 { AFNUM_E164
, "E.164"},
307 { AFNUM_F69
, "F.69"},
308 { AFNUM_X121
, "X.121"},
309 { AFNUM_IPX
, "Novell IPX"},
310 { AFNUM_ATALK
, "Appletalk"},
311 { AFNUM_DECNET
, "Decnet IV"},
312 { AFNUM_BANYAN
, "Banyan Vines"},
313 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
314 { AFNUM_L2VPN
, "Layer-2 VPN"},
318 static struct tok bgp_extd_comm_subtype_values
[] = {
326 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
332 if (plen
< 0 || 32 < plen
)
335 memset(&addr
, 0, sizeof(addr
));
336 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
338 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
339 ((0xff00 >> (plen
% 8)) & 0xff);
341 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
342 return 1 + (plen
+ 7) / 8;
346 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
351 plen
= pptr
[0]; /* get prefix length */
353 /* this is one of the weirdnesses of rfc3107
354 the label length (actually the label + COS bits)
355 is added to the prefix length;
356 we also do only read out just one label -
357 there is no real application for advertisement of
358 stacked labels in a a single BGP message
361 plen
-=24; /* adjust prefixlen - labellength */
363 if (plen
< 0 || 32 < plen
)
366 memset(&addr
, 0, sizeof(addr
));
367 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
369 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
370 ((0xff00 >> (plen
% 8)) & 0xff);
372 /* the label may get offsetted by 4 bits so lets shift it right */
373 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
374 getname((u_char
*)&addr
),
376 EXTRACT_24BITS(pptr
+1)>>4,
377 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
379 return 4 + (plen
+ 7) / 8;
384 bgp_vpn_rd_print (const u_char
*pptr
) {
386 /* allocate space for the following string
387 * xxx.xxx.xxx.xxx:xxxxx
388 * 21 bytes plus one termination byte */
392 /* ok lets load the RD format */
393 switch (EXTRACT_16BITS(pptr
)) {
394 /* AS:IP-address fmt*/
396 pos
+=sprintf(pos
, "%u:%u.%u.%u.%u",
397 EXTRACT_16BITS(pptr
+2),
403 /* IP-address:AS fmt*/
405 pos
+=sprintf(pos
, "%u.%u.%u.%u:%u",
410 EXTRACT_16BITS(pptr
+6));
413 pos
+=sprintf(pos
, "unknown RD format");
421 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
426 plen
= pptr
[0]; /* get prefix length */
428 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
430 if (plen
< 0 || 32 < plen
)
433 memset(&addr
, 0, sizeof(addr
));
434 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
436 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
437 ((0xff00 >> (plen
% 8)) & 0xff);
439 /* the label may get offsetted by 4 bits so lets shift it right */
440 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
441 bgp_vpn_rd_print(pptr
+4),
442 getname((u_char
*)&addr
),
444 EXTRACT_24BITS(pptr
+1)>>4,
445 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
447 return 12 + (plen
+ 7) / 8;
452 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
454 struct in6_addr addr
;
458 if (plen
< 0 || 128 < plen
)
461 memset(&addr
, 0, sizeof(addr
));
462 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
464 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
465 ((0xff00 >> (plen
% 8)) & 0xff);
467 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
468 return 1 + (plen
+ 7) / 8;
473 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
481 char buf
[MAXHOSTNAMELEN
+ 100];
486 switch (attr
->bgpa_type
) {
489 printf("invalid len");
491 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
493 case BGPTYPE_AS_PATH
:
495 printf("invalid len");
502 while (tptr
< pptr
+ len
) {
504 * under RFC1965, p[0] means:
505 * 1: AS_SET 2: AS_SEQUENCE
506 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
508 if (tptr
[0] == 3 || tptr
[0] == 4)
510 printf("%s", (tptr
[0] & 1) ? "{" : "");
511 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
512 printf("%s%u", i
== 0 ? "" : " ",
513 EXTRACT_16BITS(&tptr
[2 + i
]));
515 printf("%s", (tptr
[0] & 1) ? "}" : "");
516 tptr
+= 2 + tptr
[1] * 2;
519 case BGPTYPE_NEXT_HOP
:
521 printf("invalid len");
523 printf("%s", getname(tptr
));
525 case BGPTYPE_MULTI_EXIT_DISC
:
526 case BGPTYPE_LOCAL_PREF
:
528 printf("invalid len");
530 printf("%u", EXTRACT_32BITS(tptr
));
532 case BGPTYPE_ATOMIC_AGGREGATE
:
534 printf("invalid len");
536 case BGPTYPE_AGGREGATOR
:
538 printf("invalid len");
541 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
544 case BGPTYPE_COMMUNITIES
:
546 printf("invalid len");
551 comm
= EXTRACT_32BITS(tptr
);
553 case BGP_COMMUNITY_NO_EXPORT
:
554 printf(" NO_EXPORT");
556 case BGP_COMMUNITY_NO_ADVERT
:
557 printf(" NO_ADVERTISE");
559 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
560 printf(" NO_EXPORT_SUBCONFED");
564 (comm
>> 16) & 0xffff,
566 (tlen
>4) ? ", " : "");
573 case BGPTYPE_ORIGINATOR_ID
:
575 printf("invalid len");
578 printf("%s",getname(tptr
));
580 case BGPTYPE_CLUSTER_LIST
:
584 (tlen
>4) ? ", " : "");
589 case BGPTYPE_MP_REACH_NLRI
:
590 af
= EXTRACT_16BITS(tptr
);
593 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
594 tok2str(bgp_afi_values
, "Unknown AFI", af
),
596 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
597 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
600 if (af
== AFNUM_INET
)
603 else if (af
== AFNUM_INET6
)
607 printf("\n\t no AFI %u decoder",af
);
609 print_unknown_data(tptr
,"\n\t ",tlen
);
619 printf("\n\t nexthop: ");
625 case SAFNUM_MULTICAST
:
626 case SAFNUM_UNIMULTICAST
:
627 case SAFNUM_LABUNICAST
:
628 printf("%s",getname(tptr
));
629 tlen
-= sizeof(struct in_addr
);
630 tptr
+= sizeof(struct in_addr
);
632 case SAFNUM_VPNUNICAST
:
633 case SAFNUM_VPNMULTICAST
:
634 case SAFNUM_VPNUNIMULTICAST
:
636 bgp_vpn_rd_print(tptr
),
637 getname(tptr
+BGP_VPN_RD_LEN
));
638 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
639 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
642 printf("no SAFI %u decoder",safi
);
644 print_unknown_data(tptr
,"\n\t ",tlen
);
652 case SAFNUM_MULTICAST
:
653 case SAFNUM_UNIMULTICAST
:
654 case SAFNUM_LABUNICAST
:
655 printf("%s", getname6(tptr
));
656 tlen
-= sizeof(struct in6_addr
);
657 tptr
+= sizeof(struct in6_addr
);
658 case SAFNUM_VPNUNICAST
:
659 case SAFNUM_VPNMULTICAST
:
660 case SAFNUM_VPNUNIMULTICAST
:
662 bgp_vpn_rd_print(tptr
),
663 getname6(tptr
+BGP_VPN_RD_LEN
));
664 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
665 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
668 printf("no SAFI %u decoder",safi
);
670 print_unknown_data(tptr
,"\n\t ",tlen
);
675 printf("no AFI %u decoder",af
);
677 print_unknown_data(tptr
,"\n\t ",tlen
);
688 printf("\n\t %u SNPA", snpa
);
689 for (/*nothing*/; snpa
> 0; snpa
--) {
690 printf("\n\t %d bytes", tptr
[0]);
697 while (len
- (tptr
- pptr
) > 0) {
702 case SAFNUM_MULTICAST
:
703 case SAFNUM_UNIMULTICAST
:
704 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
705 printf("\n\t %s", buf
);
707 case SAFNUM_LABUNICAST
:
708 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
709 printf("\n\t %s", buf
);
711 case SAFNUM_VPNUNICAST
:
712 case SAFNUM_VPNMULTICAST
:
713 case SAFNUM_VPNUNIMULTICAST
:
714 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
715 printf("\n\t %s", buf
);
718 printf("\n\t no SAFI %u decoder",safi
);
720 print_unknown_data(tptr
-3,"\n\t ",tlen
);
730 case SAFNUM_MULTICAST
:
731 case SAFNUM_UNIMULTICAST
:
732 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
733 printf("\n\t %s", buf
);
736 printf("\n\t no SAFI %u decoder ",safi
);
738 print_unknown_data(tptr
-3,"\n\t ",tlen
);
746 printf("\n\t no AFI %u decoder ",af
);
748 print_unknown_data(tptr
-3,"\n\t ",tlen
);
759 case BGPTYPE_MP_UNREACH_NLRI
:
760 af
= EXTRACT_16BITS(tptr
);
763 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
764 tok2str(bgp_afi_values
, "Unknown AFI", af
),
766 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
767 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
772 while (len
- (tptr
- pptr
) > 0) {
777 case SAFNUM_MULTICAST
:
778 case SAFNUM_UNIMULTICAST
:
779 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
780 printf("\n\t %s", buf
);
782 case SAFNUM_LABUNICAST
:
783 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
784 printf("\n\t %s", buf
);
786 case SAFNUM_VPNUNICAST
:
787 case SAFNUM_VPNMULTICAST
:
788 case SAFNUM_VPNUNIMULTICAST
:
789 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
790 printf("\n\t %s", buf
);
793 printf("\n\t no SAFI %u decoder",safi
);
795 print_unknown_data(tptr
-3,"\n\t ",tlen
);
806 case SAFNUM_MULTICAST
:
807 case SAFNUM_UNIMULTICAST
:
808 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
809 printf("\n\t %s", buf
);
812 printf("\n\t no SAFI %u decoder",safi
);
814 print_unknown_data(tptr
-3,"\n\t ",tlen
);
822 printf("\n\t no AFI %u decoder",af
);
824 print_unknown_data(tptr
-3,"\n\t ",tlen
);
833 case BGPTYPE_EXTD_COMMUNITIES
:
835 printf("invalid len");
839 u_int8_t extd_comm
,extd_comm_type
,extd_comm_subtype
;
841 extd_comm_type
=extd_comm
&0x3f;
842 extd_comm_subtype
=*(tptr
+1);
843 switch(extd_comm_type
) {
845 printf("%s%s%s:%u:%s%s",
846 (extd_comm
&0x80) ? "vendor-specific: " : "",
847 (extd_comm
&0x40) ? "non-transitive:" : "",
848 tok2str(bgp_extd_comm_subtype_values
,
850 extd_comm_subtype
&0x3f),
851 EXTRACT_16BITS(tptr
+2),
853 (tlen
>8) ? ", " : "");
856 printf("%s%s%s:%s:%u%s",
857 (extd_comm
&0x80) ? "vendor-specific: " : "",
858 (extd_comm
&0x40) ? "non-transitive:" : "",
859 tok2str(bgp_extd_comm_subtype_values
,
861 extd_comm_subtype
&0x3f),
863 EXTRACT_16BITS(tptr
+6),
864 (tlen
>8) ? ", " : "");
867 printf("%s%s%s:%u:%u%s",
868 (extd_comm
&0x80) ? "vendor-specific: " : "",
869 (extd_comm
&0x40) ? "non-transitive:" : "",
870 tok2str(bgp_extd_comm_subtype_values
,
872 extd_comm_subtype
&0x3f),
873 EXTRACT_32BITS(tptr
+2),
874 EXTRACT_16BITS(tptr
+6),
875 (tlen
>8) ? ", " : "");
879 printf("\n\t no typecode %u decoder",
881 print_unknown_data(tptr
,"\n\t ",8);
890 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
892 print_unknown_data(pptr
,"\n\t ",len
);
895 if (vflag
&&len
) /* omit zero length attributes*/
896 print_unknown_data(pptr
,"\n\t ",len
);
900 bgp_open_print(const u_char
*dat
, int length
)
902 struct bgp_open bgpo
;
903 struct bgp_opt bgpopt
;
906 int i
,cap_type
,cap_len
;
908 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
909 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
910 hlen
= ntohs(bgpo
.bgpo_len
);
912 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
913 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
914 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
915 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
916 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
919 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
923 while (i
< bgpo
.bgpo_optlen
) {
924 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
925 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
926 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
927 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
931 printf("\n\t Option %s (%u), length: %u",
932 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
936 /* now lets decode the options we know*/
937 switch(bgpopt
.bgpopt_type
) {
939 cap_type
=opt
[i
+BGP_OPT_SIZE
];
940 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
941 printf("\n\t %s, length: %u",
942 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
946 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
947 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
948 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
949 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
950 opt
[i
+BGP_OPT_SIZE
+5]);
953 case BGP_CAPCODE_RR_CISCO
:
956 printf("\n\t\tno decoder for Capability %u",
963 printf("\n\t no decoder for option %u",
968 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
976 bgp_update_print(const u_char
*dat
, int length
)
979 struct bgp_attr bgpa
;
985 TCHECK2(dat
[0], BGP_SIZE
);
986 memcpy(&bgp
, dat
, BGP_SIZE
);
987 hlen
= ntohs(bgp
.bgp_len
);
988 p
= dat
+ BGP_SIZE
; /*XXX*/
990 /* Unfeasible routes */
991 len
= EXTRACT_16BITS(p
);
994 * Without keeping state from the original NLRI message,
995 * it's not possible to tell if this a v4 or v6 route,
996 * so only try to decode it if we're not v6 enabled.
999 printf("\n\t Withdrawn routes: %d bytes", len
);
1001 char buf
[MAXHOSTNAMELEN
+ 100];
1006 printf("\n\t Withdrawn routes:");
1008 while(i
< 2 + len
) {
1009 i
+= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1010 printf("\n\t %s", buf
);
1017 len
= EXTRACT_16BITS(p
);
1019 /* do something more useful!*/
1021 while (i
< 2 + len
) {
1024 TCHECK2(p
[i
], sizeof(bgpa
));
1025 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1026 alen
= bgp_attr_len(&bgpa
);
1027 aoff
= bgp_attr_off(&bgpa
);
1029 printf("\n\t %s (%u), length: %u",
1030 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1034 if (bgpa
.bgpa_flags
) {
1035 printf(", flags [%s%s%s%s",
1036 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1037 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1038 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1039 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1040 if (bgpa
.bgpa_flags
& 0xf)
1041 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1044 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1050 if (dat
+ length
> p
) {
1051 printf("\n\t Updated routes:");
1052 while (dat
+ length
> p
) {
1053 char buf
[MAXHOSTNAMELEN
+ 100];
1054 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1055 printf("\n\t %s", buf
);
1067 bgp_notification_print(const u_char
*dat
, int length
)
1069 struct bgp_notification bgpn
;
1072 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1073 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1074 hlen
= ntohs(bgpn
.bgpn_len
);
1076 printf(", Error - %s", tok2str(bgp_notify_major_values
, "Unknown", bgpn
.bgpn_major
));
1078 switch (bgpn
.bgpn_major
) {
1080 case BGP_NOTIFY_MAJOR_MSG
:
1081 printf(" subcode %s", tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
));
1083 case BGP_NOTIFY_MAJOR_OPEN
:
1084 printf(" subcode %s", tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
));
1086 case BGP_NOTIFY_MAJOR_UPDATE
:
1087 printf(" subcode %s", tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
));
1099 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1101 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1102 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1104 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1105 tok2str(bgp_afi_values
,"Unknown",
1106 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1107 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1108 tok2str(bgp_safi_values
,"Unknown",
1109 bgp_route_refresh_header
->safi
),
1110 bgp_route_refresh_header
->safi
);
1113 print_unknown_data(pptr
,"\n\t ", len
);
1119 bgp_header_print(const u_char
*dat
, int length
)
1123 TCHECK2(dat
[0], BGP_SIZE
);
1124 memcpy(&bgp
, dat
, BGP_SIZE
);
1125 printf("\n\t%s Message (%u), length: %u ",
1126 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1130 switch (bgp
.bgp_type
) {
1132 bgp_open_print(dat
, length
);
1135 bgp_update_print(dat
, length
);
1137 case BGP_NOTIFICATION
:
1138 bgp_notification_print(dat
, length
);
1142 case BGP_ROUTE_REFRESH
:
1143 bgp_route_refresh_print(dat
, length
);
1146 /* we have no decoder for the BGP message */
1147 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1148 print_unknown_data(dat
,"\n\t ",length
);
1157 bgp_print(const u_char
*dat
, int length
)
1161 const u_char
*start
;
1162 const u_char marker
[] = {
1163 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1164 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1170 if (snapend
< dat
+ length
)
1177 while (p
< snapend
) {
1178 if (!TTEST2(p
[0], 1))
1185 if (!TTEST2(p
[0], sizeof(marker
)))
1187 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1192 /* found BGP header */
1193 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1194 memcpy(&bgp
, p
, BGP_SIZE
);
1199 hlen
= ntohs(bgp
.bgp_len
);
1201 if (TTEST2(p
[0], hlen
)) {
1202 bgp_header_print(p
, hlen
);
1206 printf("[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));