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
29 * Extensively modified by Hannes Gredler (hannes@juniper.net) for more
30 * complete BGP support.
33 #define NETDISSECT_REWORKED
38 #include <tcpdump-stdinc.h>
43 #include "interface.h"
44 #include "addrtoname.h"
50 uint8_t bgp_marker
[16];
54 #define BGP_SIZE 19 /* unaligned */
58 #define BGP_NOTIFICATION 3
59 #define BGP_KEEPALIVE 4
60 #define BGP_ROUTE_REFRESH 5
62 static const struct tok bgp_msg_values
[] = {
64 { BGP_UPDATE
, "Update"},
65 { BGP_NOTIFICATION
, "Notification"},
66 { BGP_KEEPALIVE
, "Keepalive"},
67 { BGP_ROUTE_REFRESH
, "Route Refresh"},
72 uint8_t bgpo_marker
[16];
77 uint16_t bgpo_holdtime
;
80 /* options should follow */
82 #define BGP_OPEN_SIZE 29 /* unaligned */
89 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
90 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
92 struct bgp_notification
{
93 uint8_t bgpn_marker
[16];
99 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
101 struct bgp_route_refresh
{
102 uint8_t bgp_marker
[16];
105 uint8_t afi
[2]; /* the compiler messes this structure up */
106 uint8_t res
; /* when doing misaligned sequences of int8 and int16 */
107 uint8_t safi
; /* afi should be int16 - so we have to access it using */
108 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
109 #define BGP_ROUTE_REFRESH_SIZE 23
111 #define bgp_attr_lenlen(flags, p) \
112 (((flags) & 0x10) ? 2 : 1)
113 #define bgp_attr_len(flags, p) \
114 (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p))
116 #define BGPTYPE_ORIGIN 1
117 #define BGPTYPE_AS_PATH 2
118 #define BGPTYPE_NEXT_HOP 3
119 #define BGPTYPE_MULTI_EXIT_DISC 4
120 #define BGPTYPE_LOCAL_PREF 5
121 #define BGPTYPE_ATOMIC_AGGREGATE 6
122 #define BGPTYPE_AGGREGATOR 7
123 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
124 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
125 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
126 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
127 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
128 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
129 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
130 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
131 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
132 #define BGPTYPE_AS4_PATH 17 /* RFC4893 */
133 #define BGPTYPE_AGGREGATOR4 18 /* RFC4893 */
134 #define BGPTYPE_PMSI_TUNNEL 22 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
135 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
137 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
139 static const struct tok bgp_attr_values
[] = {
140 { BGPTYPE_ORIGIN
, "Origin"},
141 { BGPTYPE_AS_PATH
, "AS Path"},
142 { BGPTYPE_AS4_PATH
, "AS4 Path"},
143 { BGPTYPE_NEXT_HOP
, "Next Hop"},
144 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
145 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
146 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
147 { BGPTYPE_AGGREGATOR
, "Aggregator"},
148 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
149 { BGPTYPE_COMMUNITIES
, "Community"},
150 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
151 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
152 { BGPTYPE_DPA
, "DPA"},
153 { BGPTYPE_ADVERTISERS
, "Advertisers"},
154 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
155 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
156 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
157 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
158 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
159 { BGPTYPE_ATTR_SET
, "Attribute Set"},
160 { 255, "Reserved for development"},
165 #define BGP_AS_SEQUENCE 2
166 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
167 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
169 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
170 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
172 static const struct tok bgp_as_path_segment_open_values
[] = {
173 { BGP_AS_SEQUENCE
, ""},
175 { BGP_CONFED_AS_SEQUENCE
, "( "},
176 { BGP_CONFED_AS_SET
, "({ "},
180 static const struct tok bgp_as_path_segment_close_values
[] = {
181 { BGP_AS_SEQUENCE
, ""},
183 { BGP_CONFED_AS_SEQUENCE
, ")"},
184 { BGP_CONFED_AS_SET
, "})"},
188 #define BGP_OPT_AUTH 1
189 #define BGP_OPT_CAP 2
192 static const struct tok bgp_opt_values
[] = {
193 { BGP_OPT_AUTH
, "Authentication Information"},
194 { BGP_OPT_CAP
, "Capabilities Advertisement"},
198 #define BGP_CAPCODE_MP 1
199 #define BGP_CAPCODE_RR 2
200 #define BGP_CAPCODE_ORF 3 /* XXX */
201 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
202 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
203 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
204 #define BGP_CAPCODE_RR_CISCO 128
206 static const struct tok bgp_capcode_values
[] = {
207 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
208 { BGP_CAPCODE_RR
, "Route Refresh"},
209 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
210 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
211 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
212 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
213 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
217 #define BGP_NOTIFY_MAJOR_MSG 1
218 #define BGP_NOTIFY_MAJOR_OPEN 2
219 #define BGP_NOTIFY_MAJOR_UPDATE 3
220 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
221 #define BGP_NOTIFY_MAJOR_FSM 5
222 #define BGP_NOTIFY_MAJOR_CEASE 6
223 #define BGP_NOTIFY_MAJOR_CAP 7
225 static const struct tok bgp_notify_major_values
[] = {
226 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
227 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
228 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
229 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
230 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
231 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
232 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
236 /* draft-ietf-idr-cease-subcode-02 */
237 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
238 static const struct tok bgp_notify_minor_cease_values
[] = {
239 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
240 { 2, "Administratively Shutdown"},
241 { 3, "Peer Unconfigured"},
242 { 4, "Administratively Reset"},
243 { 5, "Connection Rejected"},
244 { 6, "Other Configuration Change"},
245 { 7, "Connection Collision Resolution"},
249 static const struct tok bgp_notify_minor_msg_values
[] = {
250 { 1, "Connection Not Synchronized"},
251 { 2, "Bad Message Length"},
252 { 3, "Bad Message Type"},
256 static const struct tok bgp_notify_minor_open_values
[] = {
257 { 1, "Unsupported Version Number"},
259 { 3, "Bad BGP Identifier"},
260 { 4, "Unsupported Optional Parameter"},
261 { 5, "Authentication Failure"},
262 { 6, "Unacceptable Hold Time"},
263 { 7, "Capability Message Error"},
267 static const struct tok bgp_notify_minor_update_values
[] = {
268 { 1, "Malformed Attribute List"},
269 { 2, "Unrecognized Well-known Attribute"},
270 { 3, "Missing Well-known Attribute"},
271 { 4, "Attribute Flags Error"},
272 { 5, "Attribute Length Error"},
273 { 6, "Invalid ORIGIN Attribute"},
274 { 7, "AS Routing Loop"},
275 { 8, "Invalid NEXT_HOP Attribute"},
276 { 9, "Optional Attribute Error"},
277 { 10, "Invalid Network Field"},
278 { 11, "Malformed AS_PATH"},
282 static const struct tok bgp_notify_minor_cap_values
[] = {
283 { 1, "Invalid Action Value" },
284 { 2, "Invalid Capability Length" },
285 { 3, "Malformed Capability Value" },
286 { 4, "Unsupported Capability Code" },
290 static const struct tok bgp_origin_values
[] = {
297 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
298 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
299 #define BGP_PMSI_TUNNEL_PIM_SSM 3
300 #define BGP_PMSI_TUNNEL_PIM_SM 4
301 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
302 #define BGP_PMSI_TUNNEL_INGRESS 6
303 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
305 static const struct tok bgp_pmsi_tunnel_values
[] = {
306 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
307 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
308 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
309 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
310 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
311 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
312 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
316 static const struct tok bgp_pmsi_flag_values
[] = {
317 { 0x01, "Leaf Information required"},
322 /* Subsequent address family identifier, RFC2283 section 7 */
324 #define SAFNUM_UNICAST 1
325 #define SAFNUM_MULTICAST 2
326 #define SAFNUM_UNIMULTICAST 3
327 /* labeled BGP RFC3107 */
328 #define SAFNUM_LABUNICAST 4
329 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
330 #define SAFNUM_MULTICAST_VPN 5
331 #define SAFNUM_TUNNEL 64 /* XXX */
332 #define SAFNUM_VPLS 65 /* XXX */
333 /* draft-nalawade-idr-mdt-safi-03 */
334 #define SAFNUM_MDT 66
335 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
336 #define SAFNUM_VPNUNICAST 128
337 #define SAFNUM_VPNMULTICAST 129
338 #define SAFNUM_VPNUNIMULTICAST 130
339 /* draft-marques-ppvpn-rt-constrain-01.txt */
340 #define SAFNUM_RT_ROUTING_INFO 132
342 #define BGP_VPN_RD_LEN 8
344 static const struct tok bgp_safi_values
[] = {
345 { SAFNUM_RES
, "Reserved"},
346 { SAFNUM_UNICAST
, "Unicast"},
347 { SAFNUM_MULTICAST
, "Multicast"},
348 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
349 { SAFNUM_LABUNICAST
, "labeled Unicast"},
350 { SAFNUM_TUNNEL
, "Tunnel"},
351 { SAFNUM_VPLS
, "VPLS"},
352 { SAFNUM_MDT
, "MDT"},
353 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
354 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
355 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
356 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
357 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
361 /* well-known community */
362 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
363 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
364 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
366 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
367 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
368 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
369 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
370 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
371 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
372 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
373 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
374 /* rfc2547 bgp-mpls-vpns */
375 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
376 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
377 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
378 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
380 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
381 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
383 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
384 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
386 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
388 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
389 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
390 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
391 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
394 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
395 #define BGP_EXT_COM_EIGRP_GEN 0x8800
396 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
397 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
398 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
399 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
400 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
402 static const struct tok bgp_extd_comm_flag_values
[] = {
403 { 0x8000, "vendor-specific"},
404 { 0x4000, "non-transitive"},
408 static const struct tok bgp_extd_comm_subtype_values
[] = {
409 { BGP_EXT_COM_RT_0
, "target"},
410 { BGP_EXT_COM_RT_1
, "target"},
411 { BGP_EXT_COM_RT_2
, "target"},
412 { BGP_EXT_COM_RO_0
, "origin"},
413 { BGP_EXT_COM_RO_1
, "origin"},
414 { BGP_EXT_COM_RO_2
, "origin"},
415 { BGP_EXT_COM_LINKBAND
, "link-BW"},
416 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
417 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
418 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
419 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
420 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
421 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
422 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
423 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
424 { BGP_EXT_COM_L2INFO
, "layer2-info"},
425 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
426 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
427 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
428 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
429 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
430 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
431 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
432 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
433 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
434 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
438 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
439 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
440 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
441 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
442 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
443 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
444 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
445 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
447 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
448 { BGP_OSPF_RTYPE_RTR
, "Router" },
449 { BGP_OSPF_RTYPE_NET
, "Network" },
450 { BGP_OSPF_RTYPE_SUM
, "Summary" },
451 { BGP_OSPF_RTYPE_EXT
, "External" },
452 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
453 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
457 #define TOKBUFSIZE 128
458 static char astostr
[20];
463 * Convert an AS number into a string and return string pointer.
465 * Depending on bflag is set or not, AS number is converted into ASDOT notation
466 * or plain number notation.
470 as_printf(netdissect_options
*ndo
,
471 char *str
, int size
, u_int asnum
)
473 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
474 snprintf(str
, size
, "%u", asnum
);
476 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
481 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
484 decode_prefix4(netdissect_options
*ndo
,
485 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
488 u_int plen
, plenbytes
;
497 memset(&addr
, 0, sizeof(addr
));
498 plenbytes
= (plen
+ 7) / 8;
499 ND_TCHECK2(pptr
[1], plenbytes
);
500 ITEMCHECK(plenbytes
);
501 memcpy(&addr
, &pptr
[1], plenbytes
);
503 ((u_char
*)&addr
)[plenbytes
- 1] &=
504 ((0xff00 >> (plen
% 8)) & 0xff);
506 snprintf(buf
, buflen
, "%s/%d", getname(ndo
, (u_char
*)&addr
), plen
);
507 return 1 + plenbytes
;
517 decode_labeled_prefix4(netdissect_options
*ndo
,
518 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
521 u_int plen
, plenbytes
;
523 /* prefix length and label = 4 bytes */
524 ND_TCHECK2(pptr
[0], 4);
526 plen
= pptr
[0]; /* get prefix length */
528 /* this is one of the weirdnesses of rfc3107
529 the label length (actually the label + COS bits)
530 is added to the prefix length;
531 we also do only read out just one label -
532 there is no real application for advertisement of
533 stacked labels in a single BGP message
539 plen
-=24; /* adjust prefixlen - labellength */
545 memset(&addr
, 0, sizeof(addr
));
546 plenbytes
= (plen
+ 7) / 8;
547 ND_TCHECK2(pptr
[4], plenbytes
);
548 ITEMCHECK(plenbytes
);
549 memcpy(&addr
, &pptr
[4], plenbytes
);
551 ((u_char
*)&addr
)[plenbytes
- 1] &=
552 ((0xff00 >> (plen
% 8)) & 0xff);
554 /* the label may get offsetted by 4 bits so lets shift it right */
555 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
556 getname(ndo
, (u_char
*)&addr
),
558 EXTRACT_24BITS(pptr
+1)>>4,
559 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
561 return 4 + plenbytes
;
573 * print an ipv4 or ipv6 address into a buffer dependend on address length.
576 bgp_vpn_ip_print(netdissect_options
*ndo
,
577 const u_char
*pptr
, u_int addr_length
) {
579 /* worst case string is s fully formatted v6 address */
580 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
583 switch(addr_length
) {
584 case (sizeof(struct in_addr
) << 3): /* 32 */
585 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
586 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
589 case (sizeof(struct in6_addr
) << 3): /* 128 */
590 ND_TCHECK2(pptr
[0], sizeof(struct in6_addr
));
591 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
595 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
608 * print an multicast s,g entry into a buffer.
609 * the s,g entry is encoded like this.
611 * +-----------------------------------+
612 * | Multicast Source Length (1 octet) |
613 * +-----------------------------------+
614 * | Multicast Source (Variable) |
615 * +-----------------------------------+
616 * | Multicast Group Length (1 octet) |
617 * +-----------------------------------+
618 * | Multicast Group (Variable) |
619 * +-----------------------------------+
621 * return the number of bytes read from the wire.
624 bgp_vpn_sg_print(netdissect_options
*ndo
,
625 const u_char
*pptr
, char *buf
, u_int buflen
) {
628 u_int total_length
, offset
;
632 /* Source address length, encoded in bits */
633 ND_TCHECK2(pptr
[0], 1);
634 addr_length
= *pptr
++;
637 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
638 total_length
+= (addr_length
>> 3) + 1;
639 offset
= strlen(buf
);
641 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
642 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
643 pptr
+= (addr_length
>> 3);
646 /* Group address length, encoded in bits */
647 ND_TCHECK2(pptr
[0], 1);
648 addr_length
= *pptr
++;
651 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
652 total_length
+= (addr_length
>> 3) + 1;
653 offset
= strlen(buf
);
655 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
656 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
657 pptr
+= (addr_length
>> 3);
661 return (total_length
);
665 /* RDs and RTs share the same semantics
666 * we use bgp_vpn_rd_print for
667 * printing route targets inside a NLRI */
669 bgp_vpn_rd_print(netdissect_options
*ndo
,
670 const u_char
*pptr
) {
672 /* allocate space for the largest possible string */
673 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
676 /* ok lets load the RD format */
677 switch (EXTRACT_16BITS(pptr
)) {
679 /* 2-byte-AS:number fmt*/
681 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
682 EXTRACT_16BITS(pptr
+2),
683 EXTRACT_32BITS(pptr
+4),
684 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
686 /* IP-address:AS fmt*/
689 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
690 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
693 /* 4-byte-AS:number fmt*/
695 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
696 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+2)),
697 EXTRACT_16BITS(pptr
+6), *(pptr
+2), *(pptr
+3), *(pptr
+4),
698 *(pptr
+5), EXTRACT_16BITS(pptr
+6));
701 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
710 decode_rt_routing_info(netdissect_options
*ndo
,
711 const u_char
*pptr
, char *buf
, u_int buflen
)
713 uint8_t route_target
[8];
717 plen
= pptr
[0]; /* get prefix length */
720 snprintf(buf
, buflen
, "default route target");
727 plen
-=32; /* adjust prefix length */
732 memset(&route_target
, 0, sizeof(route_target
));
733 ND_TCHECK2(pptr
[1], (plen
+ 7) / 8);
734 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
736 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
737 ((0xff00 >> (plen
% 8)) & 0xff);
739 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
740 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+1)),
741 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
743 return 5 + (plen
+ 7) / 8;
750 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
751 const u_char
*pptr
, char *buf
, u_int buflen
)
757 plen
= pptr
[0]; /* get prefix length */
762 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
767 memset(&addr
, 0, sizeof(addr
));
768 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
769 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
771 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
772 ((0xff00 >> (plen
% 8)) & 0xff);
774 /* the label may get offsetted by 4 bits so lets shift it right */
775 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
776 bgp_vpn_rd_print(ndo
, pptr
+4),
777 getname(ndo
, (u_char
*)&addr
),
779 EXTRACT_24BITS(pptr
+1)>>4,
780 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
782 return 12 + (plen
+ 7) / 8;
789 * +-------------------------------+
791 * | RD:IPv4-address (12 octets) |
793 * +-------------------------------+
794 * | MDT Group-address (4 octets) |
795 * +-------------------------------+
798 #define MDT_VPN_NLRI_LEN 16
801 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
802 const u_char
*pptr
, char *buf
, u_int buflen
)
806 const u_char
*vpn_ip
;
810 /* if the NLRI is not predefined length, quit.*/
811 if (*pptr
!= MDT_VPN_NLRI_LEN
* 8)
816 ND_TCHECK2(pptr
[0], 8);
821 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
823 pptr
+=sizeof(struct in_addr
);
825 /* MDT Group Address */
826 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
828 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
829 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
831 return MDT_VPN_NLRI_LEN
+ 1;
838 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
839 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
840 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
841 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
842 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
843 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
844 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
846 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
847 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
848 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
849 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
850 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
851 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
852 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
853 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
857 decode_multicast_vpn(netdissect_options
*ndo
,
858 const u_char
*pptr
, char *buf
, u_int buflen
)
860 uint8_t route_type
, route_length
, addr_length
, sg_length
;
863 ND_TCHECK2(pptr
[0], 2);
864 route_type
= *pptr
++;
865 route_length
= *pptr
++;
867 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
868 tok2str(bgp_multicast_vpn_route_type_values
,
869 "Unknown", route_type
),
870 route_type
, route_length
);
873 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
874 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
875 offset
= strlen(buf
);
876 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
877 bgp_vpn_rd_print(ndo
, pptr
),
878 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
879 (route_length
- BGP_VPN_RD_LEN
) << 3));
881 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
882 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
883 offset
= strlen(buf
);
884 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
885 bgp_vpn_rd_print(ndo
, pptr
),
886 as_printf(ndo
, astostr
, sizeof(astostr
),
887 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
890 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
891 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
892 offset
= strlen(buf
);
893 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
894 bgp_vpn_rd_print(ndo
, pptr
));
895 pptr
+= BGP_VPN_RD_LEN
;
897 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
898 addr_length
= route_length
- sg_length
;
900 ND_TCHECK2(pptr
[0], addr_length
);
901 offset
= strlen(buf
);
902 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
903 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
906 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
907 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
908 offset
= strlen(buf
);
909 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
910 bgp_vpn_rd_print(ndo
, pptr
));
911 pptr
+= BGP_VPN_RD_LEN
;
913 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
916 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
917 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
918 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
919 offset
= strlen(buf
);
920 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
921 bgp_vpn_rd_print(ndo
, pptr
),
922 as_printf(ndo
, astostr
, sizeof(astostr
),
923 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
924 pptr
+= BGP_VPN_RD_LEN
;
926 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
930 * no per route-type printing yet.
932 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
937 return route_length
+ 2;
944 * As I remember, some versions of systems have an snprintf() that
945 * returns -1 if the buffer would have overflowed. If the return
946 * value is negative, set buflen to 0, to indicate that we've filled
949 * If the return value is greater than buflen, that means that
950 * the buffer would have overflowed; again, set buflen to 0 in
953 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
956 else if ((u_int)strlen>buflen) \
964 decode_labeled_vpn_l2(netdissect_options
*ndo
,
965 const u_char
*pptr
, char *buf
, u_int buflen
)
967 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
969 ND_TCHECK2(pptr
[0], 2);
970 plen
=EXTRACT_16BITS(pptr
);
973 /* Old and new L2VPN NLRI share AFI/SAFI
974 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
975 * and > 17 as old format. Complain for the middle case
978 /* assume AD-only with RD, BGPNH */
979 ND_TCHECK2(pptr
[0],12);
981 strlen
=snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
982 bgp_vpn_rd_print(ndo
, pptr
),
983 /* need something like getname(ndo, ) here */
986 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
990 } else if (plen
>17) {
991 /* assume old format */
992 /* RD, ID, LBLKOFF, LBLBASE */
994 ND_TCHECK2(pptr
[0],15);
996 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
997 bgp_vpn_rd_print(ndo
, pptr
),
998 EXTRACT_16BITS(pptr
+8),
999 EXTRACT_16BITS(pptr
+10),
1000 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1001 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1005 /* ok now the variable part - lets read out TLVs*/
1009 ND_TCHECK2(pptr
[0], 3);
1011 tlv_len
=EXTRACT_16BITS(pptr
);
1018 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1021 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1023 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1024 while (ttlv_len
>0) {
1027 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
1028 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1035 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1038 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1042 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1047 /* complain bitterly ? */
1058 decode_prefix6(netdissect_options
*ndo
,
1059 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1061 struct in6_addr addr
;
1062 u_int plen
, plenbytes
;
1071 memset(&addr
, 0, sizeof(addr
));
1072 plenbytes
= (plen
+ 7) / 8;
1073 ND_TCHECK2(pd
[1], plenbytes
);
1074 ITEMCHECK(plenbytes
);
1075 memcpy(&addr
, &pd
[1], plenbytes
);
1077 addr
.s6_addr
[plenbytes
- 1] &=
1078 ((0xff00 >> (plen
% 8)) & 0xff);
1080 snprintf(buf
, buflen
, "%s/%d", getname6(ndo
, (u_char
*)&addr
), plen
);
1081 return 1 + plenbytes
;
1091 decode_labeled_prefix6(netdissect_options
*ndo
,
1092 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1094 struct in6_addr addr
;
1095 u_int plen
, plenbytes
;
1097 /* prefix length and label = 4 bytes */
1098 ND_TCHECK2(pptr
[0], 4);
1100 plen
= pptr
[0]; /* get prefix length */
1105 plen
-=24; /* adjust prefixlen - labellength */
1111 memset(&addr
, 0, sizeof(addr
));
1112 plenbytes
= (plen
+ 7) / 8;
1113 ND_TCHECK2(pptr
[4], plenbytes
);
1114 memcpy(&addr
, &pptr
[4], plenbytes
);
1116 addr
.s6_addr
[plenbytes
- 1] &=
1117 ((0xff00 >> (plen
% 8)) & 0xff);
1119 /* the label may get offsetted by 4 bits so lets shift it right */
1120 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1121 getname6(ndo
, (u_char
*)&addr
),
1123 EXTRACT_24BITS(pptr
+1)>>4,
1124 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1126 return 4 + plenbytes
;
1136 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1137 const u_char
*pptr
, char *buf
, u_int buflen
)
1139 struct in6_addr addr
;
1143 plen
= pptr
[0]; /* get prefix length */
1148 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1153 memset(&addr
, 0, sizeof(addr
));
1154 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1155 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1157 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1158 ((0xff00 >> (plen
% 8)) & 0xff);
1160 /* the label may get offsetted by 4 bits so lets shift it right */
1161 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1162 bgp_vpn_rd_print(ndo
, pptr
+4),
1163 getname6(ndo
, (u_char
*)&addr
),
1165 EXTRACT_24BITS(pptr
+1)>>4,
1166 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1168 return 12 + (plen
+ 7) / 8;
1176 decode_clnp_prefix(netdissect_options
*ndo
,
1177 const u_char
*pptr
, char *buf
, u_int buflen
)
1183 plen
= pptr
[0]; /* get prefix length */
1188 memset(&addr
, 0, sizeof(addr
));
1189 ND_TCHECK2(pptr
[4], (plen
+ 7) / 8);
1190 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1192 addr
[(plen
+ 7) / 8 - 1] &=
1193 ((0xff00 >> (plen
% 8)) & 0xff);
1195 snprintf(buf
, buflen
, "%s/%d",
1196 isonsap_string(addr
,(plen
+ 7) / 8),
1199 return 1 + (plen
+ 7) / 8;
1206 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1207 const u_char
*pptr
, char *buf
, u_int buflen
)
1213 plen
= pptr
[0]; /* get prefix length */
1218 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1223 memset(&addr
, 0, sizeof(addr
));
1224 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1225 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1227 addr
[(plen
+ 7) / 8 - 1] &=
1228 ((0xff00 >> (plen
% 8)) & 0xff);
1230 /* the label may get offsetted by 4 bits so lets shift it right */
1231 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1232 bgp_vpn_rd_print(ndo
, pptr
+4),
1233 isonsap_string(addr
,(plen
+ 7) / 8),
1235 EXTRACT_24BITS(pptr
+1)>>4,
1236 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1238 return 12 + (plen
+ 7) / 8;
1245 * bgp_attr_get_as_size
1247 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1248 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1249 * support, exchange AS-Path with the same path-attribute type value 0x02.
1252 bgp_attr_get_as_size(netdissect_options
*ndo
,
1253 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1255 const u_char
*tptr
= pptr
;
1258 * If the path attribute is the optional AS4 path type, then we already
1259 * know, that ASs must be encoded in 4 byte format.
1261 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1266 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1267 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1270 while (tptr
< pptr
+ len
) {
1274 * If we do not find a valid segment type, our guess might be wrong.
1276 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1280 tptr
+= 2 + tptr
[1] * 2;
1284 * If we correctly reached end of the AS path attribute data content,
1285 * then most likely ASs were indeed encoded as 2 bytes.
1287 if (tptr
== pptr
+ len
) {
1294 * We can come here, either we did not have enough data, or if we
1295 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1296 * so that calller can try to decode each AS as of 4 bytes. If indeed
1297 * there was not enough data, it will crib and end the parse anyways.
1303 bgp_attr_print(netdissect_options
*ndo
,
1304 u_int atype
, const u_char
*pptr
, u_int len
)
1308 uint8_t safi
, snpa
, nhlen
;
1309 union { /* copy buffer for bandwidth values */
1316 char buf
[MAXHOSTNAMELEN
+ 100];
1317 char tokbuf
[TOKBUFSIZE
];
1324 case BGPTYPE_ORIGIN
:
1326 ND_PRINT((ndo
, "invalid len"));
1329 ND_PRINT((ndo
, "%s", tok2strbuf(bgp_origin_values
,
1330 "Unknown Origin Typecode",
1332 tokbuf
, sizeof(tokbuf
))));
1338 * Process AS4 byte path and AS2 byte path attributes here.
1340 case BGPTYPE_AS4_PATH
:
1341 case BGPTYPE_AS_PATH
:
1343 ND_PRINT((ndo
, "invalid len"));
1347 ND_PRINT((ndo
, "empty"));
1352 * BGP updates exchanged between New speakers that support 4
1353 * byte AS, ASs are always encoded in 4 bytes. There is no
1354 * definitive way to find this, just by the packet's
1355 * contents. So, check for packet's TLV's sanity assuming
1356 * 2 bytes first, and it does not pass, assume that ASs are
1357 * encoded in 4 bytes format and move on.
1359 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1361 while (tptr
< pptr
+ len
) {
1363 ND_PRINT((ndo
, "%s", tok2strbuf(bgp_as_path_segment_open_values
,
1365 tokbuf
, sizeof(tokbuf
))));
1366 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1367 ND_TCHECK2(tptr
[2 + i
], as_size
);
1368 ND_PRINT((ndo
, "%s ",
1369 as_printf(ndo
, astostr
, sizeof(astostr
),
1371 EXTRACT_16BITS(&tptr
[2 + i
]) :
1372 EXTRACT_32BITS(&tptr
[2 + i
]))));
1375 ND_PRINT((ndo
, "%s", tok2strbuf(bgp_as_path_segment_close_values
,
1377 tokbuf
, sizeof(tokbuf
))));
1379 tptr
+= 2 + tptr
[1] * as_size
;
1382 case BGPTYPE_NEXT_HOP
:
1384 ND_PRINT((ndo
, "invalid len"));
1386 ND_TCHECK2(tptr
[0], 4);
1387 ND_PRINT((ndo
, "%s", getname(ndo
, tptr
)));
1390 case BGPTYPE_MULTI_EXIT_DISC
:
1391 case BGPTYPE_LOCAL_PREF
:
1393 ND_PRINT((ndo
, "invalid len"));
1395 ND_TCHECK2(tptr
[0], 4);
1396 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(tptr
)));
1399 case BGPTYPE_ATOMIC_AGGREGATE
:
1401 ND_PRINT((ndo
, "invalid len"));
1403 case BGPTYPE_AGGREGATOR
:
1406 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1407 * the length of this PA can be either 6 bytes or 8 bytes.
1409 if (len
!= 6 && len
!= 8) {
1410 ND_PRINT((ndo
, "invalid len"));
1413 ND_TCHECK2(tptr
[0], len
);
1415 ND_PRINT((ndo
, " AS #%s, origin %s",
1416 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_16BITS(tptr
)),
1417 getname(ndo
, tptr
+ 2)));
1419 ND_PRINT((ndo
, " AS #%s, origin %s",
1420 as_printf(ndo
, astostr
, sizeof(astostr
),
1421 EXTRACT_32BITS(tptr
)), getname(ndo
, tptr
+ 4)));
1424 case BGPTYPE_AGGREGATOR4
:
1426 ND_PRINT((ndo
, "invalid len"));
1429 ND_TCHECK2(tptr
[0], 8);
1430 ND_PRINT((ndo
, " AS #%s, origin %s",
1431 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
)),
1432 getname(ndo
, tptr
+ 4)));
1434 case BGPTYPE_COMMUNITIES
:
1436 ND_PRINT((ndo
, "invalid len"));
1441 ND_TCHECK2(tptr
[0], 4);
1442 comm
= EXTRACT_32BITS(tptr
);
1444 case BGP_COMMUNITY_NO_EXPORT
:
1445 ND_PRINT((ndo
, " NO_EXPORT"));
1447 case BGP_COMMUNITY_NO_ADVERT
:
1448 ND_PRINT((ndo
, " NO_ADVERTISE"));
1450 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1451 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1454 ND_PRINT((ndo
, "%u:%u%s",
1455 (comm
>> 16) & 0xffff,
1457 (tlen
>4) ? ", " : ""));
1464 case BGPTYPE_ORIGINATOR_ID
:
1466 ND_PRINT((ndo
, "invalid len"));
1469 ND_TCHECK2(tptr
[0], 4);
1470 ND_PRINT((ndo
, "%s",getname(ndo
, tptr
)));
1472 case BGPTYPE_CLUSTER_LIST
:
1474 ND_PRINT((ndo
, "invalid len"));
1478 ND_TCHECK2(tptr
[0], 4);
1479 ND_PRINT((ndo
, "%s%s",
1481 (tlen
>4) ? ", " : ""));
1486 case BGPTYPE_MP_REACH_NLRI
:
1487 ND_TCHECK2(tptr
[0], 3);
1488 af
= EXTRACT_16BITS(tptr
);
1491 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1492 tok2strbuf(af_values
, "Unknown AFI", af
,
1493 tokbuf
, sizeof(tokbuf
)),
1495 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1496 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1497 tokbuf
, sizeof(tokbuf
)),
1500 switch(af
<<8 | safi
) {
1501 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1502 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1503 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1504 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1505 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1506 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1507 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1508 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1509 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1510 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1512 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1513 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1514 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1515 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1516 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1517 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1518 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1520 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1521 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1522 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1523 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1524 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1525 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1526 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1527 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1528 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1529 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1532 ND_TCHECK2(tptr
[0], tlen
);
1533 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1534 if (ndo
->ndo_vflag
<= 1)
1535 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1549 ND_PRINT((ndo
, "\n\t nexthop: "));
1552 ND_PRINT((ndo
, ", " ));
1554 switch(af
<<8 | safi
) {
1555 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1556 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1557 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1558 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1559 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1560 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1561 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1562 if (tlen
< (int)sizeof(struct in_addr
)) {
1563 ND_PRINT((ndo
, "invalid len"));
1566 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1567 ND_PRINT((ndo
, "%s",getname(ndo
, tptr
)));
1568 tlen
-= sizeof(struct in_addr
);
1569 tptr
+= sizeof(struct in_addr
);
1572 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1573 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1574 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1575 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1576 ND_PRINT((ndo
, "invalid len"));
1579 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1580 ND_PRINT((ndo
, "RD: %s, %s",
1581 bgp_vpn_rd_print(ndo
, tptr
),
1582 getname(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1583 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1584 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1588 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1589 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1590 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1591 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1592 if (tlen
< (int)sizeof(struct in6_addr
)) {
1593 ND_PRINT((ndo
, "invalid len"));
1596 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1597 ND_PRINT((ndo
, "%s", getname6(ndo
, tptr
)));
1598 tlen
-= sizeof(struct in6_addr
);
1599 tptr
+= sizeof(struct in6_addr
);
1602 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1603 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1604 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1605 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1606 ND_PRINT((ndo
, "invalid len"));
1609 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1610 ND_PRINT((ndo
, "RD: %s, %s",
1611 bgp_vpn_rd_print(ndo
, tptr
),
1612 getname6(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1613 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1614 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1618 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1619 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1620 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1621 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1622 if (tlen
< (int)sizeof(struct in_addr
)) {
1623 ND_PRINT((ndo
, "invalid len"));
1626 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1627 ND_PRINT((ndo
, "%s", getname(ndo
, tptr
)));
1628 tlen
-= (sizeof(struct in_addr
));
1629 tptr
+= (sizeof(struct in_addr
));
1632 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1633 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1634 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1635 ND_TCHECK2(tptr
[0], tlen
);
1636 ND_PRINT((ndo
, "%s", isonsap_string(tptr
, tlen
)));
1641 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1642 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1643 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1644 if (tlen
< BGP_VPN_RD_LEN
+1) {
1645 ND_PRINT((ndo
, "invalid len"));
1648 ND_TCHECK2(tptr
[0], tlen
);
1649 ND_PRINT((ndo
, "RD: %s, %s",
1650 bgp_vpn_rd_print(ndo
, tptr
),
1651 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1652 /* rfc986 mapped IPv4 address ? */
1653 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1654 ND_PRINT((ndo
, " = %s", getname(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1656 /* rfc1888 mapped IPv6 address ? */
1657 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1658 ND_PRINT((ndo
, " = %s", getname6(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1665 ND_TCHECK2(tptr
[0], tlen
);
1666 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1667 if (ndo
->ndo_vflag
<= 1)
1668 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1676 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1684 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1685 for (/*nothing*/; snpa
> 0; snpa
--) {
1687 ND_PRINT((ndo
, "\n\t %d bytes", tptr
[0]));
1688 tptr
+= tptr
[0] + 1;
1691 ND_PRINT((ndo
, ", no SNPA"));
1694 while (len
- (tptr
- pptr
) > 0) {
1695 switch (af
<<8 | safi
) {
1696 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1697 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1698 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1699 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1701 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1702 else if (advance
== -2)
1704 else if (advance
== -3)
1705 break; /* bytes left, but not enough */
1707 ND_PRINT((ndo
, "\n\t %s", buf
));
1709 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1710 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1712 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1713 else if (advance
== -2)
1715 else if (advance
== -3)
1716 break; /* bytes left, but not enough */
1718 ND_PRINT((ndo
, "\n\t %s", buf
));
1720 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1721 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1722 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1723 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1725 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1726 else if (advance
== -2)
1729 ND_PRINT((ndo
, "\n\t %s", buf
));
1731 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1732 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1734 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1735 else if (advance
== -2)
1738 ND_PRINT((ndo
, "\n\t %s", buf
));
1740 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1741 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1742 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1744 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1745 else if (advance
== -2)
1748 ND_PRINT((ndo
, "\n\t %s", buf
));
1751 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1752 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1754 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1755 else if (advance
== -2)
1758 ND_PRINT((ndo
, "\n\t %s", buf
));
1761 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1762 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1763 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1764 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1766 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1767 else if (advance
== -2)
1769 else if (advance
== -3)
1770 break; /* bytes left, but not enough */
1772 ND_PRINT((ndo
, "\n\t %s", buf
));
1774 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1775 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1777 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1778 else if (advance
== -2)
1780 else if (advance
== -3)
1781 break; /* bytes left, but not enough */
1783 ND_PRINT((ndo
, "\n\t %s", buf
));
1785 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1786 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1787 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1788 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1790 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1791 else if (advance
== -2)
1794 ND_PRINT((ndo
, "\n\t %s", buf
));
1797 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1798 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1799 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1800 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1801 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1803 ND_PRINT((ndo
, "\n\t (illegal length)"));
1804 else if (advance
== -2)
1807 ND_PRINT((ndo
, "\n\t %s", buf
));
1809 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1810 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1811 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1812 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1814 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1815 else if (advance
== -2)
1818 ND_PRINT((ndo
, "\n\t %s", buf
));
1820 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1821 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1822 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1823 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1825 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1826 else if (advance
== -2)
1829 ND_PRINT((ndo
, "\n\t %s", buf
));
1832 ND_TCHECK2(*tptr
,tlen
);
1833 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1834 if (ndo
->ndo_vflag
<= 1)
1835 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1847 case BGPTYPE_MP_UNREACH_NLRI
:
1848 ND_TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1849 af
= EXTRACT_16BITS(tptr
);
1852 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1853 tok2strbuf(af_values
, "Unknown AFI", af
,
1854 tokbuf
, sizeof(tokbuf
)),
1856 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1857 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1858 tokbuf
, sizeof(tokbuf
)),
1861 if (len
== BGP_MP_NLRI_MINSIZE
)
1862 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1866 while (len
- (tptr
- pptr
) > 0) {
1867 switch (af
<<8 | safi
) {
1868 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1869 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1870 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1871 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1873 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1874 else if (advance
== -2)
1876 else if (advance
== -3)
1877 break; /* bytes left, but not enough */
1879 ND_PRINT((ndo
, "\n\t %s", buf
));
1881 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1882 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1884 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1885 else if (advance
== -2)
1887 else if (advance
== -3)
1888 break; /* bytes left, but not enough */
1890 ND_PRINT((ndo
, "\n\t %s", buf
));
1892 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1893 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1894 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1895 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1897 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1898 else if (advance
== -2)
1901 ND_PRINT((ndo
, "\n\t %s", buf
));
1904 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1905 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1906 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1907 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1909 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1910 else if (advance
== -2)
1912 else if (advance
== -3)
1913 break; /* bytes left, but not enough */
1915 ND_PRINT((ndo
, "\n\t %s", buf
));
1917 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1918 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1920 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1921 else if (advance
== -2)
1923 else if (advance
== -3)
1924 break; /* bytes left, but not enough */
1926 ND_PRINT((ndo
, "\n\t %s", buf
));
1928 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1929 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1930 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1931 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1933 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1934 else if (advance
== -2)
1937 ND_PRINT((ndo
, "\n\t %s", buf
));
1940 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1941 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1942 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1943 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1944 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1946 ND_PRINT((ndo
, "\n\t (illegal length)"));
1947 else if (advance
== -2)
1950 ND_PRINT((ndo
, "\n\t %s", buf
));
1952 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1953 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1954 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1955 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1957 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1958 else if (advance
== -2)
1961 ND_PRINT((ndo
, "\n\t %s", buf
));
1963 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1964 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1965 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1966 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1968 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1969 else if (advance
== -2)
1972 ND_PRINT((ndo
, "\n\t %s", buf
));
1974 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1975 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1977 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1978 else if (advance
== -2)
1981 ND_PRINT((ndo
, "\n\t %s", buf
));
1983 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1984 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1985 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1987 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1988 else if (advance
== -2)
1991 ND_PRINT((ndo
, "\n\t %s", buf
));
1994 ND_TCHECK2(*(tptr
-3),tlen
);
1995 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
1996 if (ndo
->ndo_vflag
<= 1)
1997 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2007 case BGPTYPE_EXTD_COMMUNITIES
:
2009 ND_PRINT((ndo
, "invalid len"));
2015 ND_TCHECK2(tptr
[0], 2);
2016 extd_comm
=EXTRACT_16BITS(tptr
);
2018 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2019 tok2strbuf(bgp_extd_comm_subtype_values
,
2020 "unknown extd community typecode",
2021 extd_comm
, tokbuf
, sizeof(tokbuf
)),
2023 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2025 ND_TCHECK2(*(tptr
+2), 6);
2027 case BGP_EXT_COM_RT_0
:
2028 case BGP_EXT_COM_RO_0
:
2029 case BGP_EXT_COM_L2VPN_RT_0
:
2030 ND_PRINT((ndo
, ": %u:%u (= %s)",
2031 EXTRACT_16BITS(tptr
+2),
2032 EXTRACT_32BITS(tptr
+4),
2033 getname(ndo
, tptr
+4)));
2035 case BGP_EXT_COM_RT_1
:
2036 case BGP_EXT_COM_RO_1
:
2037 case BGP_EXT_COM_L2VPN_RT_1
:
2038 case BGP_EXT_COM_VRF_RT_IMP
:
2039 ND_PRINT((ndo
, ": %s:%u",
2040 getname(ndo
, tptr
+2),
2041 EXTRACT_16BITS(tptr
+6)));
2043 case BGP_EXT_COM_RT_2
:
2044 case BGP_EXT_COM_RO_2
:
2045 ND_PRINT((ndo
, ": %s:%u",
2046 as_printf(ndo
, astostr
, sizeof(astostr
),
2047 EXTRACT_32BITS(tptr
+2)), EXTRACT_16BITS(tptr
+6)));
2049 case BGP_EXT_COM_LINKBAND
:
2050 bw
.i
= EXTRACT_32BITS(tptr
+2);
2051 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2054 case BGP_EXT_COM_VPN_ORIGIN
:
2055 case BGP_EXT_COM_VPN_ORIGIN2
:
2056 case BGP_EXT_COM_VPN_ORIGIN3
:
2057 case BGP_EXT_COM_VPN_ORIGIN4
:
2058 case BGP_EXT_COM_OSPF_RID
:
2059 case BGP_EXT_COM_OSPF_RID2
:
2060 ND_PRINT((ndo
, "%s", getname(ndo
, tptr
+2)));
2062 case BGP_EXT_COM_OSPF_RTYPE
:
2063 case BGP_EXT_COM_OSPF_RTYPE2
:
2064 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2065 getname(ndo
, tptr
+2),
2066 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
2069 tokbuf
, sizeof(tokbuf
)),
2070 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2071 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2073 case BGP_EXT_COM_L2INFO
:
2074 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2075 tok2strbuf(l2vpn_encaps_values
,
2078 tokbuf
, sizeof(tokbuf
)),
2080 EXTRACT_16BITS(tptr
+4)));
2082 case BGP_EXT_COM_SOURCE_AS
:
2083 ND_PRINT((ndo
, ": AS %u", EXTRACT_16BITS(tptr
+2)));
2086 ND_TCHECK2(*tptr
,8);
2087 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2095 case BGPTYPE_PMSI_TUNNEL
:
2097 uint8_t tunnel_type
, flags
;
2099 tunnel_type
= *(tptr
+1);
2103 ND_TCHECK2(tptr
[0], 5);
2104 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2105 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2107 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2108 EXTRACT_24BITS(tptr
+2)>>4));
2113 switch (tunnel_type
) {
2114 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2115 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2116 ND_TCHECK2(tptr
[0], 8);
2117 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2118 ipaddr_string(ndo
, tptr
),
2119 ipaddr_string(ndo
, tptr
+4)));
2122 case BGP_PMSI_TUNNEL_PIM_SSM
:
2123 ND_TCHECK2(tptr
[0], 8);
2124 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2125 ipaddr_string(ndo
, tptr
),
2126 ipaddr_string(ndo
, tptr
+4)));
2128 case BGP_PMSI_TUNNEL_INGRESS
:
2129 ND_TCHECK2(tptr
[0], 4);
2130 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2131 ipaddr_string(ndo
, tptr
)));
2133 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2134 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2135 ND_TCHECK2(tptr
[0], 8);
2136 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2137 ipaddr_string(ndo
, tptr
),
2138 EXTRACT_32BITS(tptr
+4)));
2140 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2141 ND_TCHECK2(tptr
[0], 8);
2142 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2143 ipaddr_string(ndo
, tptr
),
2144 EXTRACT_32BITS(tptr
+4)));
2147 if (ndo
->ndo_vflag
<= 1) {
2148 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2153 case BGPTYPE_ATTR_SET
:
2154 ND_TCHECK2(tptr
[0], 4);
2157 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2158 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
))));
2163 u_int aflags
, atype
, alenlen
, alen
;
2165 ND_TCHECK2(tptr
[0], 2);
2169 atype
= *(tptr
+ 1);
2172 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2173 ND_TCHECK2(tptr
[0], alenlen
);
2176 alen
= bgp_attr_len(aflags
, tptr
);
2180 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2181 tok2strbuf(bgp_attr_values
,
2182 "Unknown Attribute", atype
,
2183 tokbuf
, sizeof(tokbuf
)),
2188 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2189 aflags
& 0x80 ? "O" : "",
2190 aflags
& 0x40 ? "T" : "",
2191 aflags
& 0x20 ? "P" : "",
2192 aflags
& 0x10 ? "E" : ""));
2194 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2195 ND_PRINT((ndo
, "]: "));
2197 /* FIXME check for recursion */
2198 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2207 ND_TCHECK2(*pptr
,len
);
2208 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2209 if (ndo
->ndo_vflag
<= 1)
2210 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2213 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2214 ND_TCHECK2(*pptr
,len
);
2215 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2224 bgp_capabilities_print(netdissect_options
*ndo
,
2225 const u_char
*opt
, int caps_len
)
2227 char tokbuf
[TOKBUFSIZE
];
2228 char tokbuf2
[TOKBUFSIZE
];
2229 int cap_type
, cap_len
, tcap_len
, cap_offset
;
2232 while (i
< caps_len
) {
2233 ND_TCHECK2(opt
[i
], BGP_CAP_HEADER_SIZE
);
2237 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2238 tok2strbuf(bgp_capcode_values
, "Unknown",
2239 cap_type
, tokbuf
, sizeof(tokbuf
)),
2242 ND_TCHECK2(opt
[i
+2], cap_len
);
2244 case BGP_CAPCODE_MP
:
2245 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2246 tok2strbuf(af_values
, "Unknown",
2247 EXTRACT_16BITS(opt
+i
+2),
2248 tokbuf
, sizeof(tokbuf
)),
2249 EXTRACT_16BITS(opt
+i
+2),
2250 tok2strbuf(bgp_safi_values
, "Unknown",
2252 tokbuf
, sizeof(tokbuf
)),
2255 case BGP_CAPCODE_RESTART
:
2256 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2257 ((opt
[i
+2])&0x80) ? "R" : "none",
2258 EXTRACT_16BITS(opt
+i
+2)&0xfff));
2261 while(tcap_len
>=4) {
2262 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2263 tok2strbuf(af_values
,"Unknown",
2264 EXTRACT_16BITS(opt
+i
+cap_offset
),
2265 tokbuf
, sizeof(tokbuf
)),
2266 EXTRACT_16BITS(opt
+i
+cap_offset
),
2267 tok2strbuf(bgp_safi_values
,"Unknown",
2268 opt
[i
+cap_offset
+2],
2269 tokbuf2
, sizeof(tokbuf2
)),
2270 opt
[i
+cap_offset
+2],
2271 ((opt
[i
+cap_offset
+3])&0x80) ? "yes" : "no" ));
2276 case BGP_CAPCODE_RR
:
2277 case BGP_CAPCODE_RR_CISCO
:
2279 case BGP_CAPCODE_AS_NEW
:
2282 * Extract the 4 byte AS number encoded.
2285 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2286 as_printf(ndo
, astostr
, sizeof(astostr
),
2287 EXTRACT_32BITS(opt
+ i
+ 2))));
2291 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2293 if (ndo
->ndo_vflag
<= 1)
2294 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2297 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2298 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2300 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2305 ND_PRINT((ndo
, "[|BGP]"));
2309 bgp_open_print(netdissect_options
*ndo
,
2310 const u_char
*dat
, int length
)
2312 struct bgp_open bgpo
;
2313 struct bgp_opt bgpopt
;
2316 char tokbuf
[TOKBUFSIZE
];
2318 ND_TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2319 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2321 ND_PRINT((ndo
, "\n\t Version %d, ", bgpo
.bgpo_version
));
2322 ND_PRINT((ndo
, "my AS %s, ",
2323 as_printf(ndo
, astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
))));
2324 ND_PRINT((ndo
, "Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
)));
2325 ND_PRINT((ndo
, "ID %s", getname(ndo
, (u_char
*)&bgpo
.bgpo_id
)));
2326 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
));
2328 /* some little sanity checking */
2329 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2333 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2337 while (i
< bgpo
.bgpo_optlen
) {
2338 ND_TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2339 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2340 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2341 ND_PRINT((ndo
, "\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
));
2345 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2346 tok2strbuf(bgp_opt_values
,"Unknown",
2348 tokbuf
, sizeof(tokbuf
)),
2350 bgpopt
.bgpopt_len
));
2352 /* now let's decode the options we know*/
2353 switch(bgpopt
.bgpopt_type
) {
2356 bgp_capabilities_print(ndo
, &opt
[i
+BGP_OPT_SIZE
],
2362 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2363 bgpopt
.bgpopt_type
));
2366 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2370 ND_PRINT((ndo
, "[|BGP]"));
2374 bgp_update_print(netdissect_options
*ndo
,
2375 const u_char
*dat
, int length
)
2379 int withdrawn_routes_len
;
2382 char tokbuf
[TOKBUFSIZE
];
2384 char buf
[MAXHOSTNAMELEN
+ 100];
2388 ND_TCHECK2(dat
[0], BGP_SIZE
);
2389 if (length
< BGP_SIZE
)
2391 memcpy(&bgp
, dat
, BGP_SIZE
);
2392 p
= dat
+ BGP_SIZE
; /*XXX*/
2395 /* Unfeasible routes */
2396 ND_TCHECK2(p
[0], 2);
2399 withdrawn_routes_len
= EXTRACT_16BITS(p
);
2402 if (withdrawn_routes_len
) {
2404 * Without keeping state from the original NLRI message,
2405 * it's not possible to tell if this a v4 or v6 route,
2406 * so only try to decode it if we're not v6 enabled.
2408 ND_TCHECK2(p
[0], withdrawn_routes_len
);
2409 if (length
< withdrawn_routes_len
)
2412 ND_PRINT((ndo
, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len
));
2413 p
+= withdrawn_routes_len
;
2414 length
-= withdrawn_routes_len
;
2416 if (withdrawn_routes_len
< 2)
2419 withdrawn_routes_len
-= 2;
2422 ND_PRINT((ndo
, "\n\t Withdrawn routes:"));
2424 while(withdrawn_routes_len
> 0) {
2425 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2427 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2429 } else if (wpfx
== -2)
2431 else if (wpfx
== -3)
2432 goto trunc
; /* bytes left, but not enough */
2434 ND_PRINT((ndo
, "\n\t %s", buf
));
2437 withdrawn_routes_len
-= wpfx
;
2443 ND_TCHECK2(p
[0], 2);
2446 len
= EXTRACT_16BITS(p
);
2450 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2451 /* No withdrawn routes, no path attributes, no NLRI */
2452 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2457 /* do something more useful!*/
2459 int aflags
, atype
, alenlen
, alen
;
2461 ND_TCHECK2(p
[0], 2);
2471 alenlen
= bgp_attr_lenlen(aflags
, p
);
2472 ND_TCHECK2(p
[0], alenlen
);
2475 if (length
< alenlen
)
2477 alen
= bgp_attr_len(aflags
, p
);
2482 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2483 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
2485 tokbuf
, sizeof(tokbuf
)),
2490 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2491 aflags
& 0x80 ? "O" : "",
2492 aflags
& 0x40 ? "T" : "",
2493 aflags
& 0x20 ? "P" : "",
2494 aflags
& 0x10 ? "E" : ""));
2496 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2497 ND_PRINT((ndo
, "]: "));
2503 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2513 * XXX - what if they're using the "Advertisement of
2514 * Multiple Paths in BGP" feature:
2516 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2518 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2520 ND_PRINT((ndo
, "\n\t Updated routes:"));
2522 char buf
[MAXHOSTNAMELEN
+ 100];
2523 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2525 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2530 goto trunc
; /* bytes left, but not enough */
2532 ND_PRINT((ndo
, "\n\t %s", buf
));
2540 ND_PRINT((ndo
, "[|BGP]"));
2544 bgp_notification_print(netdissect_options
*ndo
,
2545 const u_char
*dat
, int length
)
2547 struct bgp_notification bgpn
;
2549 char tokbuf
[TOKBUFSIZE
];
2550 char tokbuf2
[TOKBUFSIZE
];
2552 ND_TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2553 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2555 /* some little sanity checking */
2556 if (length
<BGP_NOTIFICATION_SIZE
)
2559 ND_PRINT((ndo
, ", %s (%u)",
2560 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
2561 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
2564 switch (bgpn
.bgpn_major
) {
2566 case BGP_NOTIFY_MAJOR_MSG
:
2567 ND_PRINT((ndo
, ", subcode %s (%u)",
2568 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
2569 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2572 case BGP_NOTIFY_MAJOR_OPEN
:
2573 ND_PRINT((ndo
, ", subcode %s (%u)",
2574 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
2575 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2578 case BGP_NOTIFY_MAJOR_UPDATE
:
2579 ND_PRINT((ndo
, ", subcode %s (%u)",
2580 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
2581 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2584 case BGP_NOTIFY_MAJOR_CAP
:
2585 ND_PRINT((ndo
, " subcode %s (%u)",
2586 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
2587 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2589 case BGP_NOTIFY_MAJOR_CEASE
:
2590 ND_PRINT((ndo
, ", subcode %s (%u)",
2591 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2592 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2595 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2596 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2598 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2599 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2600 ND_TCHECK2(*tptr
, 7);
2601 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2602 tok2strbuf(af_values
, "Unknown",
2603 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2604 EXTRACT_16BITS(tptr
),
2605 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2606 tokbuf2
, sizeof(tokbuf
)),
2608 EXTRACT_32BITS(tptr
+3)));
2617 ND_PRINT((ndo
, "[|BGP]"));
2621 bgp_route_refresh_print(netdissect_options
*ndo
,
2622 const u_char
*pptr
, int len
) {
2624 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2625 char tokbuf
[TOKBUFSIZE
];
2626 char tokbuf2
[TOKBUFSIZE
];
2628 ND_TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2630 /* some little sanity checking */
2631 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2634 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2636 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2637 tok2strbuf(af_values
,"Unknown",
2638 /* this stinks but the compiler pads the structure
2640 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2641 tokbuf
, sizeof(tokbuf
)),
2642 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2643 tok2strbuf(bgp_safi_values
,"Unknown",
2644 bgp_route_refresh_header
->safi
,
2645 tokbuf2
, sizeof(tokbuf2
)),
2646 bgp_route_refresh_header
->safi
));
2648 if (ndo
->ndo_vflag
> 1) {
2649 ND_TCHECK2(*pptr
, len
);
2650 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2655 ND_PRINT((ndo
, "[|BGP]"));
2659 bgp_header_print(netdissect_options
*ndo
,
2660 const u_char
*dat
, int length
)
2663 char tokbuf
[TOKBUFSIZE
];
2665 ND_TCHECK2(dat
[0], BGP_SIZE
);
2666 memcpy(&bgp
, dat
, BGP_SIZE
);
2667 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2668 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2669 tokbuf
, sizeof(tokbuf
)),
2673 switch (bgp
.bgp_type
) {
2675 bgp_open_print(ndo
, dat
, length
);
2678 bgp_update_print(ndo
, dat
, length
);
2680 case BGP_NOTIFICATION
:
2681 bgp_notification_print(ndo
, dat
, length
);
2685 case BGP_ROUTE_REFRESH
:
2686 bgp_route_refresh_print(ndo
, dat
, length
);
2689 /* we have no decoder for the BGP message */
2690 ND_TCHECK2(*dat
, length
);
2691 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp
.bgp_type
));
2692 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2697 ND_PRINT((ndo
, "[|BGP]"));
2702 bgp_print(netdissect_options
*ndo
,
2703 const u_char
*dat
, int length
)
2707 const u_char
*start
;
2708 const u_char marker
[] = {
2709 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2710 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2714 char tokbuf
[TOKBUFSIZE
];
2717 if (ndo
->ndo_snapend
< dat
+ length
)
2718 ep
= ndo
->ndo_snapend
;
2720 ND_PRINT((ndo
, ": BGP"));
2722 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2728 if (!ND_TTEST2(p
[0], 1))
2735 if (!ND_TTEST2(p
[0], sizeof(marker
)))
2737 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2742 /* found BGP header */
2743 ND_TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2744 memcpy(&bgp
, p
, BGP_SIZE
);
2747 ND_PRINT((ndo
, " [|BGP]"));
2749 hlen
= ntohs(bgp
.bgp_len
);
2750 if (hlen
< BGP_SIZE
) {
2751 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
2756 if (ND_TTEST2(p
[0], hlen
)) {
2757 if (!bgp_header_print(ndo
, p
, hlen
))
2762 ND_PRINT((ndo
, "\n[|BGP %s]",
2763 tok2strbuf(bgp_msg_values
,
2764 "Unknown Message Type",
2766 tokbuf
, sizeof(tokbuf
))));
2774 ND_PRINT((ndo
, " [|BGP]"));
2779 * c-style: whitesmith