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.
37 #include <netdissect-stdinc.h>
42 #include "netdissect.h"
43 #include "addrtoname.h"
49 uint8_t bgp_marker
[16];
53 #define BGP_SIZE 19 /* unaligned */
57 #define BGP_NOTIFICATION 3
58 #define BGP_KEEPALIVE 4
59 #define BGP_ROUTE_REFRESH 5
61 static const struct tok bgp_msg_values
[] = {
63 { BGP_UPDATE
, "Update"},
64 { BGP_NOTIFICATION
, "Notification"},
65 { BGP_KEEPALIVE
, "Keepalive"},
66 { BGP_ROUTE_REFRESH
, "Route Refresh"},
71 uint8_t bgpo_marker
[16];
76 uint16_t bgpo_holdtime
;
79 /* options should follow */
81 #define BGP_OPEN_SIZE 29 /* unaligned */
88 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
89 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
91 struct bgp_notification
{
92 uint8_t bgpn_marker
[16];
98 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
100 struct bgp_route_refresh
{
101 uint8_t bgp_marker
[16];
104 uint8_t afi
[2]; /* the compiler messes this structure up */
105 uint8_t res
; /* when doing misaligned sequences of int8 and int16 */
106 uint8_t safi
; /* afi should be int16 - so we have to access it using */
107 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
108 #define BGP_ROUTE_REFRESH_SIZE 23
110 #define bgp_attr_lenlen(flags, p) \
111 (((flags) & 0x10) ? 2 : 1)
112 #define bgp_attr_len(flags, p) \
113 (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p))
115 #define BGPTYPE_ORIGIN 1
116 #define BGPTYPE_AS_PATH 2
117 #define BGPTYPE_NEXT_HOP 3
118 #define BGPTYPE_MULTI_EXIT_DISC 4
119 #define BGPTYPE_LOCAL_PREF 5
120 #define BGPTYPE_ATOMIC_AGGREGATE 6
121 #define BGPTYPE_AGGREGATOR 7
122 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
123 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
124 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
125 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
126 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
127 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
128 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
129 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
130 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
131 #define BGPTYPE_AS4_PATH 17 /* RFC4893 */
132 #define BGPTYPE_AGGREGATOR4 18 /* RFC4893 */
133 #define BGPTYPE_PMSI_TUNNEL 22 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
134 #define BGPTYPE_AIGP 26 /* RFC7311 */
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_AIGP
, "Accumulated IGP Metric"},
160 { BGPTYPE_ATTR_SET
, "Attribute Set"},
161 { 255, "Reserved for development"},
166 #define BGP_AS_SEQUENCE 2
167 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
168 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
170 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
171 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
173 static const struct tok bgp_as_path_segment_open_values
[] = {
174 { BGP_AS_SEQUENCE
, ""},
176 { BGP_CONFED_AS_SEQUENCE
, "( "},
177 { BGP_CONFED_AS_SET
, "({ "},
181 static const struct tok bgp_as_path_segment_close_values
[] = {
182 { BGP_AS_SEQUENCE
, ""},
184 { BGP_CONFED_AS_SEQUENCE
, ")"},
185 { BGP_CONFED_AS_SET
, "})"},
189 #define BGP_OPT_AUTH 1
190 #define BGP_OPT_CAP 2
193 static const struct tok bgp_opt_values
[] = {
194 { BGP_OPT_AUTH
, "Authentication Information"},
195 { BGP_OPT_CAP
, "Capabilities Advertisement"},
199 #define BGP_CAPCODE_MP 1
200 #define BGP_CAPCODE_RR 2
201 #define BGP_CAPCODE_ORF 3 /* XXX */
202 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
203 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
204 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
205 #define BGP_CAPCODE_ADD_PATH 69 /* draft-ietf-idr-add-paths-10 */
206 #define BGP_CAPCODE_RR_CISCO 128
208 static const struct tok bgp_capcode_values
[] = {
209 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
210 { BGP_CAPCODE_RR
, "Route Refresh"},
211 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
212 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
213 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
214 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
215 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
216 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
220 #define BGP_NOTIFY_MAJOR_MSG 1
221 #define BGP_NOTIFY_MAJOR_OPEN 2
222 #define BGP_NOTIFY_MAJOR_UPDATE 3
223 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
224 #define BGP_NOTIFY_MAJOR_FSM 5
225 #define BGP_NOTIFY_MAJOR_CEASE 6
226 #define BGP_NOTIFY_MAJOR_CAP 7
228 static const struct tok bgp_notify_major_values
[] = {
229 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
230 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
231 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
232 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
233 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
234 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
235 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
239 /* draft-ietf-idr-cease-subcode-02 */
240 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
241 static const struct tok bgp_notify_minor_cease_values
[] = {
242 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
243 { 2, "Administratively Shutdown"},
244 { 3, "Peer Unconfigured"},
245 { 4, "Administratively Reset"},
246 { 5, "Connection Rejected"},
247 { 6, "Other Configuration Change"},
248 { 7, "Connection Collision Resolution"},
252 static const struct tok bgp_notify_minor_msg_values
[] = {
253 { 1, "Connection Not Synchronized"},
254 { 2, "Bad Message Length"},
255 { 3, "Bad Message Type"},
259 static const struct tok bgp_notify_minor_open_values
[] = {
260 { 1, "Unsupported Version Number"},
262 { 3, "Bad BGP Identifier"},
263 { 4, "Unsupported Optional Parameter"},
264 { 5, "Authentication Failure"},
265 { 6, "Unacceptable Hold Time"},
266 { 7, "Capability Message Error"},
270 static const struct tok bgp_notify_minor_update_values
[] = {
271 { 1, "Malformed Attribute List"},
272 { 2, "Unrecognized Well-known Attribute"},
273 { 3, "Missing Well-known Attribute"},
274 { 4, "Attribute Flags Error"},
275 { 5, "Attribute Length Error"},
276 { 6, "Invalid ORIGIN Attribute"},
277 { 7, "AS Routing Loop"},
278 { 8, "Invalid NEXT_HOP Attribute"},
279 { 9, "Optional Attribute Error"},
280 { 10, "Invalid Network Field"},
281 { 11, "Malformed AS_PATH"},
285 static const struct tok bgp_notify_minor_cap_values
[] = {
286 { 1, "Invalid Action Value" },
287 { 2, "Invalid Capability Length" },
288 { 3, "Malformed Capability Value" },
289 { 4, "Unsupported Capability Code" },
293 static const struct tok bgp_origin_values
[] = {
300 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
301 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
302 #define BGP_PMSI_TUNNEL_PIM_SSM 3
303 #define BGP_PMSI_TUNNEL_PIM_SM 4
304 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
305 #define BGP_PMSI_TUNNEL_INGRESS 6
306 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
308 static const struct tok bgp_pmsi_tunnel_values
[] = {
309 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
310 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
311 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
312 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
313 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
314 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
315 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
319 static const struct tok bgp_pmsi_flag_values
[] = {
320 { 0x01, "Leaf Information required"},
324 #define BGP_AIGP_TLV 1
326 static const struct tok bgp_aigp_values
[] = {
327 { BGP_AIGP_TLV
, "AIGP"},
332 /* Subsequent address family identifier, RFC2283 section 7 */
334 #define SAFNUM_UNICAST 1
335 #define SAFNUM_MULTICAST 2
336 #define SAFNUM_UNIMULTICAST 3
337 /* labeled BGP RFC3107 */
338 #define SAFNUM_LABUNICAST 4
339 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
340 #define SAFNUM_MULTICAST_VPN 5
341 #define SAFNUM_TUNNEL 64 /* XXX */
342 #define SAFNUM_VPLS 65 /* XXX */
343 /* draft-nalawade-idr-mdt-safi-03 */
344 #define SAFNUM_MDT 66
345 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
346 #define SAFNUM_VPNUNICAST 128
347 #define SAFNUM_VPNMULTICAST 129
348 #define SAFNUM_VPNUNIMULTICAST 130
349 /* draft-marques-ppvpn-rt-constrain-01.txt */
350 #define SAFNUM_RT_ROUTING_INFO 132
352 #define BGP_VPN_RD_LEN 8
354 static const struct tok bgp_safi_values
[] = {
355 { SAFNUM_RES
, "Reserved"},
356 { SAFNUM_UNICAST
, "Unicast"},
357 { SAFNUM_MULTICAST
, "Multicast"},
358 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
359 { SAFNUM_LABUNICAST
, "labeled Unicast"},
360 { SAFNUM_TUNNEL
, "Tunnel"},
361 { SAFNUM_VPLS
, "VPLS"},
362 { SAFNUM_MDT
, "MDT"},
363 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
364 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
365 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
366 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
367 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
371 /* well-known community */
372 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
373 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
374 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
376 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
377 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
378 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
379 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
380 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
381 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
382 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
383 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
384 /* rfc2547 bgp-mpls-vpns */
385 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
386 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
387 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
388 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
390 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
391 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
393 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
394 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
396 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
398 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
399 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
400 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
401 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
404 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
405 #define BGP_EXT_COM_EIGRP_GEN 0x8800
406 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
407 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
408 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
409 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
410 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
412 static const struct tok bgp_extd_comm_flag_values
[] = {
413 { 0x8000, "vendor-specific"},
414 { 0x4000, "non-transitive"},
418 static const struct tok bgp_extd_comm_subtype_values
[] = {
419 { BGP_EXT_COM_RT_0
, "target"},
420 { BGP_EXT_COM_RT_1
, "target"},
421 { BGP_EXT_COM_RT_2
, "target"},
422 { BGP_EXT_COM_RO_0
, "origin"},
423 { BGP_EXT_COM_RO_1
, "origin"},
424 { BGP_EXT_COM_RO_2
, "origin"},
425 { BGP_EXT_COM_LINKBAND
, "link-BW"},
426 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
427 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
428 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
429 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
430 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
431 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
432 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
433 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
434 { BGP_EXT_COM_L2INFO
, "layer2-info"},
435 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
436 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
437 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
438 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
439 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
440 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
441 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
442 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
443 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
444 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
448 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
449 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
450 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
451 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
452 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
453 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
454 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
455 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
457 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
458 { BGP_OSPF_RTYPE_RTR
, "Router" },
459 { BGP_OSPF_RTYPE_NET
, "Network" },
460 { BGP_OSPF_RTYPE_SUM
, "Summary" },
461 { BGP_OSPF_RTYPE_EXT
, "External" },
462 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
463 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
467 /* ADD-PATH Send/Receive field values */
468 static const struct tok bgp_add_path_recvsend
[] = {
475 static char astostr
[20];
480 * Convert an AS number into a string and return string pointer.
482 * Depending on bflag is set or not, AS number is converted into ASDOT notation
483 * or plain number notation.
487 as_printf(netdissect_options
*ndo
,
488 char *str
, int size
, u_int asnum
)
490 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
491 snprintf(str
, size
, "%u", asnum
);
493 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
498 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
501 decode_prefix4(netdissect_options
*ndo
,
502 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
505 u_int plen
, plenbytes
;
514 memset(&addr
, 0, sizeof(addr
));
515 plenbytes
= (plen
+ 7) / 8;
516 ND_TCHECK2(pptr
[1], plenbytes
);
517 ITEMCHECK(plenbytes
);
518 memcpy(&addr
, &pptr
[1], plenbytes
);
520 ((u_char
*)&addr
)[plenbytes
- 1] &=
521 ((0xff00 >> (plen
% 8)) & 0xff);
523 snprintf(buf
, buflen
, "%s/%d", ipaddr_string(ndo
, &addr
), plen
);
524 return 1 + plenbytes
;
534 decode_labeled_prefix4(netdissect_options
*ndo
,
535 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
538 u_int plen
, plenbytes
;
540 /* prefix length and label = 4 bytes */
541 ND_TCHECK2(pptr
[0], 4);
543 plen
= pptr
[0]; /* get prefix length */
545 /* this is one of the weirdnesses of rfc3107
546 the label length (actually the label + COS bits)
547 is added to the prefix length;
548 we also do only read out just one label -
549 there is no real application for advertisement of
550 stacked labels in a single BGP message
556 plen
-=24; /* adjust prefixlen - labellength */
562 memset(&addr
, 0, sizeof(addr
));
563 plenbytes
= (plen
+ 7) / 8;
564 ND_TCHECK2(pptr
[4], plenbytes
);
565 ITEMCHECK(plenbytes
);
566 memcpy(&addr
, &pptr
[4], plenbytes
);
568 ((u_char
*)&addr
)[plenbytes
- 1] &=
569 ((0xff00 >> (plen
% 8)) & 0xff);
571 /* the label may get offsetted by 4 bits so lets shift it right */
572 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
573 ipaddr_string(ndo
, &addr
),
575 EXTRACT_24BITS(pptr
+1)>>4,
576 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
578 return 4 + plenbytes
;
590 * print an ipv4 or ipv6 address into a buffer dependend on address length.
593 bgp_vpn_ip_print(netdissect_options
*ndo
,
594 const u_char
*pptr
, u_int addr_length
)
597 /* worst case string is s fully formatted v6 address */
598 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
601 switch(addr_length
) {
602 case (sizeof(struct in_addr
) << 3): /* 32 */
603 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
604 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
606 case (sizeof(struct in6_addr
) << 3): /* 128 */
607 ND_TCHECK2(pptr
[0], sizeof(struct in6_addr
));
608 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
611 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
624 * print an multicast s,g entry into a buffer.
625 * the s,g entry is encoded like this.
627 * +-----------------------------------+
628 * | Multicast Source Length (1 octet) |
629 * +-----------------------------------+
630 * | Multicast Source (Variable) |
631 * +-----------------------------------+
632 * | Multicast Group Length (1 octet) |
633 * +-----------------------------------+
634 * | Multicast Group (Variable) |
635 * +-----------------------------------+
637 * return the number of bytes read from the wire.
640 bgp_vpn_sg_print(netdissect_options
*ndo
,
641 const u_char
*pptr
, char *buf
, u_int buflen
)
644 u_int total_length
, offset
;
648 /* Source address length, encoded in bits */
649 ND_TCHECK2(pptr
[0], 1);
650 addr_length
= *pptr
++;
653 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
654 total_length
+= (addr_length
>> 3) + 1;
655 offset
= strlen(buf
);
657 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
658 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
659 pptr
+= (addr_length
>> 3);
662 /* Group address length, encoded in bits */
663 ND_TCHECK2(pptr
[0], 1);
664 addr_length
= *pptr
++;
667 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
668 total_length
+= (addr_length
>> 3) + 1;
669 offset
= strlen(buf
);
671 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
672 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
673 pptr
+= (addr_length
>> 3);
677 return (total_length
);
681 /* RDs and RTs share the same semantics
682 * we use bgp_vpn_rd_print for
683 * printing route targets inside a NLRI */
685 bgp_vpn_rd_print(netdissect_options
*ndo
,
688 /* allocate space for the largest possible string */
689 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
692 /* ok lets load the RD format */
693 switch (EXTRACT_16BITS(pptr
)) {
695 /* 2-byte-AS:number fmt*/
697 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
698 EXTRACT_16BITS(pptr
+2),
699 EXTRACT_32BITS(pptr
+4),
700 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
702 /* IP-address:AS fmt*/
705 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
706 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
709 /* 4-byte-AS:number fmt*/
711 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
712 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+2)),
713 EXTRACT_16BITS(pptr
+6), *(pptr
+2), *(pptr
+3), *(pptr
+4),
714 *(pptr
+5), EXTRACT_16BITS(pptr
+6));
717 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
726 decode_rt_routing_info(netdissect_options
*ndo
,
727 const u_char
*pptr
, char *buf
, u_int buflen
)
729 uint8_t route_target
[8];
733 plen
= pptr
[0]; /* get prefix length */
736 snprintf(buf
, buflen
, "default route target");
743 plen
-=32; /* adjust prefix length */
748 memset(&route_target
, 0, sizeof(route_target
));
749 ND_TCHECK2(pptr
[1], (plen
+ 7) / 8);
750 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
752 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
753 ((0xff00 >> (plen
% 8)) & 0xff);
755 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
756 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+1)),
757 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
759 return 5 + (plen
+ 7) / 8;
766 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
767 const u_char
*pptr
, char *buf
, u_int buflen
)
773 plen
= pptr
[0]; /* get prefix length */
778 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
783 memset(&addr
, 0, sizeof(addr
));
784 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
785 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
787 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
788 ((0xff00 >> (plen
% 8)) & 0xff);
790 /* the label may get offsetted by 4 bits so lets shift it right */
791 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
792 bgp_vpn_rd_print(ndo
, pptr
+4),
793 ipaddr_string(ndo
, &addr
),
795 EXTRACT_24BITS(pptr
+1)>>4,
796 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
798 return 12 + (plen
+ 7) / 8;
805 * +-------------------------------+
807 * | RD:IPv4-address (12 octets) |
809 * +-------------------------------+
810 * | MDT Group-address (4 octets) |
811 * +-------------------------------+
814 #define MDT_VPN_NLRI_LEN 16
817 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
818 const u_char
*pptr
, char *buf
, u_int buflen
)
822 const u_char
*vpn_ip
;
826 /* if the NLRI is not predefined length, quit.*/
827 if (*pptr
!= MDT_VPN_NLRI_LEN
* 8)
832 ND_TCHECK2(pptr
[0], 8);
837 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
839 pptr
+=sizeof(struct in_addr
);
841 /* MDT Group Address */
842 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
844 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
845 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
847 return MDT_VPN_NLRI_LEN
+ 1;
854 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
855 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
856 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
857 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
858 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
859 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
860 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
862 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
863 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
864 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
865 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
866 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
867 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
868 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
869 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
873 decode_multicast_vpn(netdissect_options
*ndo
,
874 const u_char
*pptr
, char *buf
, u_int buflen
)
876 uint8_t route_type
, route_length
, addr_length
, sg_length
;
879 ND_TCHECK2(pptr
[0], 2);
880 route_type
= *pptr
++;
881 route_length
= *pptr
++;
883 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
884 tok2str(bgp_multicast_vpn_route_type_values
,
885 "Unknown", route_type
),
886 route_type
, route_length
);
889 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
890 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
891 offset
= strlen(buf
);
892 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
893 bgp_vpn_rd_print(ndo
, pptr
),
894 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
895 (route_length
- BGP_VPN_RD_LEN
) << 3));
897 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
898 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
899 offset
= strlen(buf
);
900 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
901 bgp_vpn_rd_print(ndo
, pptr
),
902 as_printf(ndo
, astostr
, sizeof(astostr
),
903 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
906 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
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 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
914 addr_length
= route_length
- sg_length
;
916 ND_TCHECK2(pptr
[0], addr_length
);
917 offset
= strlen(buf
);
918 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
919 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
922 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
923 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
924 offset
= strlen(buf
);
925 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
926 bgp_vpn_rd_print(ndo
, pptr
));
927 pptr
+= BGP_VPN_RD_LEN
;
929 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
932 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
933 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
934 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
935 offset
= strlen(buf
);
936 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
937 bgp_vpn_rd_print(ndo
, pptr
),
938 as_printf(ndo
, astostr
, sizeof(astostr
),
939 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
940 pptr
+= BGP_VPN_RD_LEN
;
942 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
946 * no per route-type printing yet.
948 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
953 return route_length
+ 2;
960 * As I remember, some versions of systems have an snprintf() that
961 * returns -1 if the buffer would have overflowed. If the return
962 * value is negative, set buflen to 0, to indicate that we've filled
965 * If the return value is greater than buflen, that means that
966 * the buffer would have overflowed; again, set buflen to 0 in
969 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
972 else if ((u_int)stringlen>buflen) \
980 decode_labeled_vpn_l2(netdissect_options
*ndo
,
981 const u_char
*pptr
, char *buf
, u_int buflen
)
983 int plen
,tlen
,stringlen
,tlv_type
,tlv_len
,ttlv_len
;
985 ND_TCHECK2(pptr
[0], 2);
986 plen
=EXTRACT_16BITS(pptr
);
989 /* Old and new L2VPN NLRI share AFI/SAFI
990 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
991 * and > 17 as old format. Complain for the middle case
994 /* assume AD-only with RD, BGPNH */
995 ND_TCHECK2(pptr
[0],12);
997 stringlen
=snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
998 bgp_vpn_rd_print(ndo
, pptr
),
999 ipaddr_string(ndo
, pptr
+8)
1001 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1005 } else if (plen
>17) {
1006 /* assume old format */
1007 /* RD, ID, LBLKOFF, LBLBASE */
1009 ND_TCHECK2(pptr
[0],15);
1011 stringlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1012 bgp_vpn_rd_print(ndo
, pptr
),
1013 EXTRACT_16BITS(pptr
+8),
1014 EXTRACT_16BITS(pptr
+10),
1015 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1016 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1020 /* ok now the variable part - lets read out TLVs*/
1024 ND_TCHECK2(pptr
[0], 3);
1026 tlv_len
=EXTRACT_16BITS(pptr
);
1033 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1036 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1038 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1039 while (ttlv_len
>0) {
1042 stringlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
1043 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1050 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1053 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1057 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1062 /* complain bitterly ? */
1072 decode_prefix6(netdissect_options
*ndo
,
1073 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1075 struct in6_addr addr
;
1076 u_int plen
, plenbytes
;
1085 memset(&addr
, 0, sizeof(addr
));
1086 plenbytes
= (plen
+ 7) / 8;
1087 ND_TCHECK2(pd
[1], plenbytes
);
1088 ITEMCHECK(plenbytes
);
1089 memcpy(&addr
, &pd
[1], plenbytes
);
1091 addr
.s6_addr
[plenbytes
- 1] &=
1092 ((0xff00 >> (plen
% 8)) & 0xff);
1094 snprintf(buf
, buflen
, "%s/%d", ip6addr_string(ndo
, &addr
), plen
);
1095 return 1 + plenbytes
;
1105 decode_labeled_prefix6(netdissect_options
*ndo
,
1106 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1108 struct in6_addr addr
;
1109 u_int plen
, plenbytes
;
1111 /* prefix length and label = 4 bytes */
1112 ND_TCHECK2(pptr
[0], 4);
1114 plen
= pptr
[0]; /* get prefix length */
1119 plen
-=24; /* adjust prefixlen - labellength */
1125 memset(&addr
, 0, sizeof(addr
));
1126 plenbytes
= (plen
+ 7) / 8;
1127 ND_TCHECK2(pptr
[4], plenbytes
);
1128 memcpy(&addr
, &pptr
[4], plenbytes
);
1130 addr
.s6_addr
[plenbytes
- 1] &=
1131 ((0xff00 >> (plen
% 8)) & 0xff);
1133 /* the label may get offsetted by 4 bits so lets shift it right */
1134 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1135 ip6addr_string(ndo
, &addr
),
1137 EXTRACT_24BITS(pptr
+1)>>4,
1138 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1140 return 4 + plenbytes
;
1150 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1151 const u_char
*pptr
, char *buf
, u_int buflen
)
1153 struct in6_addr addr
;
1157 plen
= pptr
[0]; /* get prefix length */
1162 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1167 memset(&addr
, 0, sizeof(addr
));
1168 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1169 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1171 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1172 ((0xff00 >> (plen
% 8)) & 0xff);
1174 /* the label may get offsetted by 4 bits so lets shift it right */
1175 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1176 bgp_vpn_rd_print(ndo
, pptr
+4),
1177 ip6addr_string(ndo
, &addr
),
1179 EXTRACT_24BITS(pptr
+1)>>4,
1180 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1182 return 12 + (plen
+ 7) / 8;
1189 decode_clnp_prefix(netdissect_options
*ndo
,
1190 const u_char
*pptr
, char *buf
, u_int buflen
)
1196 plen
= pptr
[0]; /* get prefix length */
1201 memset(&addr
, 0, sizeof(addr
));
1202 ND_TCHECK2(pptr
[4], (plen
+ 7) / 8);
1203 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1205 addr
[(plen
+ 7) / 8 - 1] &=
1206 ((0xff00 >> (plen
% 8)) & 0xff);
1208 snprintf(buf
, buflen
, "%s/%d",
1209 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1212 return 1 + (plen
+ 7) / 8;
1219 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1220 const u_char
*pptr
, char *buf
, u_int buflen
)
1226 plen
= pptr
[0]; /* get prefix length */
1231 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1236 memset(&addr
, 0, sizeof(addr
));
1237 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1238 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1240 addr
[(plen
+ 7) / 8 - 1] &=
1241 ((0xff00 >> (plen
% 8)) & 0xff);
1243 /* the label may get offsetted by 4 bits so lets shift it right */
1244 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1245 bgp_vpn_rd_print(ndo
, pptr
+4),
1246 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1248 EXTRACT_24BITS(pptr
+1)>>4,
1249 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1251 return 12 + (plen
+ 7) / 8;
1258 * bgp_attr_get_as_size
1260 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1261 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1262 * support, exchange AS-Path with the same path-attribute type value 0x02.
1265 bgp_attr_get_as_size(netdissect_options
*ndo
,
1266 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1268 const u_char
*tptr
= pptr
;
1271 * If the path attribute is the optional AS4 path type, then we already
1272 * know, that ASs must be encoded in 4 byte format.
1274 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1279 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1280 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1283 while (tptr
< pptr
+ len
) {
1287 * If we do not find a valid segment type, our guess might be wrong.
1289 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1293 tptr
+= 2 + tptr
[1] * 2;
1297 * If we correctly reached end of the AS path attribute data content,
1298 * then most likely ASs were indeed encoded as 2 bytes.
1300 if (tptr
== pptr
+ len
) {
1307 * We can come here, either we did not have enough data, or if we
1308 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1309 * so that calller can try to decode each AS as of 4 bytes. If indeed
1310 * there was not enough data, it will crib and end the parse anyways.
1316 bgp_attr_print(netdissect_options
*ndo
,
1317 u_int atype
, const u_char
*pptr
, u_int len
)
1321 uint8_t safi
, snpa
, nhlen
;
1322 union { /* copy buffer for bandwidth values */
1329 char buf
[MAXHOSTNAMELEN
+ 100];
1336 case BGPTYPE_ORIGIN
:
1338 ND_PRINT((ndo
, "invalid len"));
1341 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1342 "Unknown Origin Typecode",
1349 * Process AS4 byte path and AS2 byte path attributes here.
1351 case BGPTYPE_AS4_PATH
:
1352 case BGPTYPE_AS_PATH
:
1354 ND_PRINT((ndo
, "invalid len"));
1358 ND_PRINT((ndo
, "empty"));
1363 * BGP updates exchanged between New speakers that support 4
1364 * byte AS, ASs are always encoded in 4 bytes. There is no
1365 * definitive way to find this, just by the packet's
1366 * contents. So, check for packet's TLV's sanity assuming
1367 * 2 bytes first, and it does not pass, assume that ASs are
1368 * encoded in 4 bytes format and move on.
1370 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1372 while (tptr
< pptr
+ len
) {
1374 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1376 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1377 ND_TCHECK2(tptr
[2 + i
], as_size
);
1378 ND_PRINT((ndo
, "%s ",
1379 as_printf(ndo
, astostr
, sizeof(astostr
),
1381 EXTRACT_16BITS(&tptr
[2 + i
]) :
1382 EXTRACT_32BITS(&tptr
[2 + i
]))));
1385 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1388 tptr
+= 2 + tptr
[1] * as_size
;
1391 case BGPTYPE_NEXT_HOP
:
1393 ND_PRINT((ndo
, "invalid len"));
1395 ND_TCHECK2(tptr
[0], 4);
1396 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1399 case BGPTYPE_MULTI_EXIT_DISC
:
1400 case BGPTYPE_LOCAL_PREF
:
1402 ND_PRINT((ndo
, "invalid len"));
1404 ND_TCHECK2(tptr
[0], 4);
1405 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(tptr
)));
1408 case BGPTYPE_ATOMIC_AGGREGATE
:
1410 ND_PRINT((ndo
, "invalid len"));
1412 case BGPTYPE_AGGREGATOR
:
1415 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1416 * the length of this PA can be either 6 bytes or 8 bytes.
1418 if (len
!= 6 && len
!= 8) {
1419 ND_PRINT((ndo
, "invalid len"));
1422 ND_TCHECK2(tptr
[0], len
);
1424 ND_PRINT((ndo
, " AS #%s, origin %s",
1425 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_16BITS(tptr
)),
1426 ipaddr_string(ndo
, tptr
+ 2)));
1428 ND_PRINT((ndo
, " AS #%s, origin %s",
1429 as_printf(ndo
, astostr
, sizeof(astostr
),
1430 EXTRACT_32BITS(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1433 case BGPTYPE_AGGREGATOR4
:
1435 ND_PRINT((ndo
, "invalid len"));
1438 ND_TCHECK2(tptr
[0], 8);
1439 ND_PRINT((ndo
, " AS #%s, origin %s",
1440 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
)),
1441 ipaddr_string(ndo
, tptr
+ 4)));
1443 case BGPTYPE_COMMUNITIES
:
1445 ND_PRINT((ndo
, "invalid len"));
1450 ND_TCHECK2(tptr
[0], 4);
1451 comm
= EXTRACT_32BITS(tptr
);
1453 case BGP_COMMUNITY_NO_EXPORT
:
1454 ND_PRINT((ndo
, " NO_EXPORT"));
1456 case BGP_COMMUNITY_NO_ADVERT
:
1457 ND_PRINT((ndo
, " NO_ADVERTISE"));
1459 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1460 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1463 ND_PRINT((ndo
, "%u:%u%s",
1464 (comm
>> 16) & 0xffff,
1466 (tlen
>4) ? ", " : ""));
1473 case BGPTYPE_ORIGINATOR_ID
:
1475 ND_PRINT((ndo
, "invalid len"));
1478 ND_TCHECK2(tptr
[0], 4);
1479 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1481 case BGPTYPE_CLUSTER_LIST
:
1483 ND_PRINT((ndo
, "invalid len"));
1487 ND_TCHECK2(tptr
[0], 4);
1488 ND_PRINT((ndo
, "%s%s",
1489 ipaddr_string(ndo
, tptr
),
1490 (tlen
>4) ? ", " : ""));
1495 case BGPTYPE_MP_REACH_NLRI
:
1496 ND_TCHECK2(tptr
[0], 3);
1497 af
= EXTRACT_16BITS(tptr
);
1500 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1501 tok2str(af_values
, "Unknown AFI", af
),
1503 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1504 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1507 switch(af
<<8 | safi
) {
1508 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1509 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1510 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1511 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1512 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1513 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1514 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1515 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1516 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1517 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1518 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1519 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1520 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1521 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1522 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1523 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1524 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1525 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1526 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1527 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1528 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1529 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1530 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1531 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1532 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1533 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1534 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1537 ND_TCHECK2(tptr
[0], tlen
);
1538 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1539 if (ndo
->ndo_vflag
<= 1)
1540 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1554 ND_PRINT((ndo
, "\n\t nexthop: "));
1557 ND_PRINT((ndo
, ", " ));
1559 switch(af
<<8 | safi
) {
1560 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1561 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1562 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1563 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1564 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1565 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1566 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1567 if (tlen
< (int)sizeof(struct in_addr
)) {
1568 ND_PRINT((ndo
, "invalid len"));
1571 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1572 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1573 tlen
-= sizeof(struct in_addr
);
1574 tptr
+= sizeof(struct in_addr
);
1577 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1578 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1579 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1580 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1581 ND_PRINT((ndo
, "invalid len"));
1584 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1585 ND_PRINT((ndo
, "RD: %s, %s",
1586 bgp_vpn_rd_print(ndo
, tptr
),
1587 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1588 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1589 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1592 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1593 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1594 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1595 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1596 if (tlen
< (int)sizeof(struct in6_addr
)) {
1597 ND_PRINT((ndo
, "invalid len"));
1600 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1601 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, tptr
)));
1602 tlen
-= sizeof(struct in6_addr
);
1603 tptr
+= sizeof(struct in6_addr
);
1606 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1607 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1608 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1609 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1610 ND_PRINT((ndo
, "invalid len"));
1613 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1614 ND_PRINT((ndo
, "RD: %s, %s",
1615 bgp_vpn_rd_print(ndo
, tptr
),
1616 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1617 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1618 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1621 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1622 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1623 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1624 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1625 if (tlen
< (int)sizeof(struct in_addr
)) {
1626 ND_PRINT((ndo
, "invalid len"));
1629 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1630 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1631 tlen
-= (sizeof(struct in_addr
));
1632 tptr
+= (sizeof(struct in_addr
));
1635 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1636 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1637 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1638 ND_TCHECK2(tptr
[0], tlen
);
1639 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1644 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1645 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1646 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1647 if (tlen
< BGP_VPN_RD_LEN
+1) {
1648 ND_PRINT((ndo
, "invalid len"));
1651 ND_TCHECK2(tptr
[0], tlen
);
1652 ND_PRINT((ndo
, "RD: %s, %s",
1653 bgp_vpn_rd_print(ndo
, tptr
),
1654 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1655 /* rfc986 mapped IPv4 address ? */
1656 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1657 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1658 /* rfc1888 mapped IPv6 address ? */
1659 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1660 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1666 ND_TCHECK2(tptr
[0], tlen
);
1667 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1668 if (ndo
->ndo_vflag
<= 1)
1669 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1677 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1685 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1686 for (/*nothing*/; snpa
> 0; snpa
--) {
1688 ND_PRINT((ndo
, "\n\t %d bytes", tptr
[0]));
1689 tptr
+= tptr
[0] + 1;
1692 ND_PRINT((ndo
, ", no SNPA"));
1695 while (len
- (tptr
- pptr
) > 0) {
1696 switch (af
<<8 | safi
) {
1697 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1698 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1699 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1700 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1702 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1703 else if (advance
== -2)
1705 else if (advance
== -3)
1706 break; /* bytes left, but not enough */
1708 ND_PRINT((ndo
, "\n\t %s", buf
));
1710 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1711 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1713 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1714 else if (advance
== -2)
1716 else if (advance
== -3)
1717 break; /* bytes left, but not enough */
1719 ND_PRINT((ndo
, "\n\t %s", buf
));
1721 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1722 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1723 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1724 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1726 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1727 else if (advance
== -2)
1730 ND_PRINT((ndo
, "\n\t %s", buf
));
1732 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1733 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1735 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1736 else if (advance
== -2)
1739 ND_PRINT((ndo
, "\n\t %s", buf
));
1741 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1742 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1743 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1745 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1746 else if (advance
== -2)
1749 ND_PRINT((ndo
, "\n\t %s", buf
));
1752 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1753 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1755 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1756 else if (advance
== -2)
1759 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
));
1796 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1797 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1798 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1799 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1800 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1802 ND_PRINT((ndo
, "\n\t (illegal length)"));
1803 else if (advance
== -2)
1806 ND_PRINT((ndo
, "\n\t %s", buf
));
1808 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1809 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1810 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1811 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1813 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1814 else if (advance
== -2)
1817 ND_PRINT((ndo
, "\n\t %s", buf
));
1819 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1820 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1821 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1822 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1824 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1825 else if (advance
== -2)
1828 ND_PRINT((ndo
, "\n\t %s", buf
));
1831 ND_TCHECK2(*tptr
,tlen
);
1832 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1833 if (ndo
->ndo_vflag
<= 1)
1834 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1846 case BGPTYPE_MP_UNREACH_NLRI
:
1847 ND_TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1848 af
= EXTRACT_16BITS(tptr
);
1851 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1852 tok2str(af_values
, "Unknown AFI", af
),
1854 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1855 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1858 if (len
== BGP_MP_NLRI_MINSIZE
)
1859 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1863 while (len
- (tptr
- pptr
) > 0) {
1864 switch (af
<<8 | safi
) {
1865 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1866 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1867 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1868 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1870 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1871 else if (advance
== -2)
1873 else if (advance
== -3)
1874 break; /* bytes left, but not enough */
1876 ND_PRINT((ndo
, "\n\t %s", buf
));
1878 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1879 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1881 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1882 else if (advance
== -2)
1884 else if (advance
== -3)
1885 break; /* bytes left, but not enough */
1887 ND_PRINT((ndo
, "\n\t %s", buf
));
1889 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1890 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1891 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1892 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1894 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1895 else if (advance
== -2)
1898 ND_PRINT((ndo
, "\n\t %s", buf
));
1900 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1901 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1902 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1903 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1905 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1906 else if (advance
== -2)
1908 else if (advance
== -3)
1909 break; /* bytes left, but not enough */
1911 ND_PRINT((ndo
, "\n\t %s", buf
));
1913 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1914 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1916 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1917 else if (advance
== -2)
1919 else if (advance
== -3)
1920 break; /* bytes left, but not enough */
1922 ND_PRINT((ndo
, "\n\t %s", buf
));
1924 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1925 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1926 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1927 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1929 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1930 else if (advance
== -2)
1933 ND_PRINT((ndo
, "\n\t %s", buf
));
1935 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1936 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1937 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1938 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1939 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1941 ND_PRINT((ndo
, "\n\t (illegal length)"));
1942 else if (advance
== -2)
1945 ND_PRINT((ndo
, "\n\t %s", buf
));
1947 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1948 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1949 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1950 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1952 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1953 else if (advance
== -2)
1956 ND_PRINT((ndo
, "\n\t %s", buf
));
1958 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1959 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1960 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1961 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1963 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1964 else if (advance
== -2)
1967 ND_PRINT((ndo
, "\n\t %s", buf
));
1969 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1970 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1972 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1973 else if (advance
== -2)
1976 ND_PRINT((ndo
, "\n\t %s", buf
));
1978 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1979 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1980 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1982 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1983 else if (advance
== -2)
1986 ND_PRINT((ndo
, "\n\t %s", buf
));
1989 ND_TCHECK2(*(tptr
-3),tlen
);
1990 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
1991 if (ndo
->ndo_vflag
<= 1)
1992 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2002 case BGPTYPE_EXTD_COMMUNITIES
:
2004 ND_PRINT((ndo
, "invalid len"));
2010 ND_TCHECK2(tptr
[0], 2);
2011 extd_comm
=EXTRACT_16BITS(tptr
);
2013 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2014 tok2str(bgp_extd_comm_subtype_values
,
2015 "unknown extd community typecode",
2018 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2020 ND_TCHECK2(*(tptr
+2), 6);
2022 case BGP_EXT_COM_RT_0
:
2023 case BGP_EXT_COM_RO_0
:
2024 case BGP_EXT_COM_L2VPN_RT_0
:
2025 ND_PRINT((ndo
, ": %u:%u (= %s)",
2026 EXTRACT_16BITS(tptr
+2),
2027 EXTRACT_32BITS(tptr
+4),
2028 ipaddr_string(ndo
, tptr
+4)));
2030 case BGP_EXT_COM_RT_1
:
2031 case BGP_EXT_COM_RO_1
:
2032 case BGP_EXT_COM_L2VPN_RT_1
:
2033 case BGP_EXT_COM_VRF_RT_IMP
:
2034 ND_PRINT((ndo
, ": %s:%u",
2035 ipaddr_string(ndo
, tptr
+2),
2036 EXTRACT_16BITS(tptr
+6)));
2038 case BGP_EXT_COM_RT_2
:
2039 case BGP_EXT_COM_RO_2
:
2040 ND_PRINT((ndo
, ": %s:%u",
2041 as_printf(ndo
, astostr
, sizeof(astostr
),
2042 EXTRACT_32BITS(tptr
+2)), EXTRACT_16BITS(tptr
+6)));
2044 case BGP_EXT_COM_LINKBAND
:
2045 bw
.i
= EXTRACT_32BITS(tptr
+2);
2046 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2049 case BGP_EXT_COM_VPN_ORIGIN
:
2050 case BGP_EXT_COM_VPN_ORIGIN2
:
2051 case BGP_EXT_COM_VPN_ORIGIN3
:
2052 case BGP_EXT_COM_VPN_ORIGIN4
:
2053 case BGP_EXT_COM_OSPF_RID
:
2054 case BGP_EXT_COM_OSPF_RID2
:
2055 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2057 case BGP_EXT_COM_OSPF_RTYPE
:
2058 case BGP_EXT_COM_OSPF_RTYPE2
:
2059 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2060 ipaddr_string(ndo
, tptr
+2),
2061 tok2str(bgp_extd_comm_ospf_rtype_values
,
2064 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2065 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2067 case BGP_EXT_COM_L2INFO
:
2068 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2069 tok2str(l2vpn_encaps_values
,
2073 EXTRACT_16BITS(tptr
+4)));
2075 case BGP_EXT_COM_SOURCE_AS
:
2076 ND_PRINT((ndo
, ": AS %u", EXTRACT_16BITS(tptr
+2)));
2079 ND_TCHECK2(*tptr
,8);
2080 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2088 case BGPTYPE_PMSI_TUNNEL
:
2090 uint8_t tunnel_type
, flags
;
2092 tunnel_type
= *(tptr
+1);
2096 ND_TCHECK2(tptr
[0], 5);
2097 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2098 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2100 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2101 EXTRACT_24BITS(tptr
+2)>>4));
2106 switch (tunnel_type
) {
2107 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2108 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2109 ND_TCHECK2(tptr
[0], 8);
2110 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2111 ipaddr_string(ndo
, tptr
),
2112 ipaddr_string(ndo
, tptr
+4)));
2115 case BGP_PMSI_TUNNEL_PIM_SSM
:
2116 ND_TCHECK2(tptr
[0], 8);
2117 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2118 ipaddr_string(ndo
, tptr
),
2119 ipaddr_string(ndo
, tptr
+4)));
2121 case BGP_PMSI_TUNNEL_INGRESS
:
2122 ND_TCHECK2(tptr
[0], 4);
2123 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2124 ipaddr_string(ndo
, tptr
)));
2126 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2127 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2128 ND_TCHECK2(tptr
[0], 8);
2129 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2130 ipaddr_string(ndo
, tptr
),
2131 EXTRACT_32BITS(tptr
+4)));
2133 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2134 ND_TCHECK2(tptr
[0], 8);
2135 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2136 ipaddr_string(ndo
, tptr
),
2137 EXTRACT_32BITS(tptr
+4)));
2140 if (ndo
->ndo_vflag
<= 1) {
2141 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2151 ND_TCHECK2(tptr
[0], 3);
2158 length
= EXTRACT_16BITS(tptr
+1);
2160 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2161 tok2str(bgp_aigp_values
, "Unknown", type
),
2166 * Check if we can read the TLV data.
2168 ND_TCHECK2(tptr
[3], length
- 3);
2173 ND_TCHECK2(tptr
[3], 8);
2174 ND_PRINT((ndo
, ", metric %" PRIu64
,
2175 EXTRACT_64BITS(tptr
+3)));
2179 if (ndo
->ndo_vflag
<= 1) {
2180 print_unknown_data(ndo
, tptr
+3,"\n\t ", length
-3);
2189 case BGPTYPE_ATTR_SET
:
2190 ND_TCHECK2(tptr
[0], 4);
2193 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2194 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
))));
2199 u_int aflags
, alenlen
, alen
;
2201 ND_TCHECK2(tptr
[0], 2);
2205 atype
= *(tptr
+ 1);
2208 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2209 ND_TCHECK2(tptr
[0], alenlen
);
2212 alen
= bgp_attr_len(aflags
, tptr
);
2216 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2217 tok2str(bgp_attr_values
,
2218 "Unknown Attribute", atype
),
2223 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2224 aflags
& 0x80 ? "O" : "",
2225 aflags
& 0x40 ? "T" : "",
2226 aflags
& 0x20 ? "P" : "",
2227 aflags
& 0x10 ? "E" : ""));
2229 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2230 ND_PRINT((ndo
, "]: "));
2232 /* FIXME check for recursion */
2233 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2242 ND_TCHECK2(*pptr
,len
);
2243 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2244 if (ndo
->ndo_vflag
<= 1)
2245 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2248 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2249 ND_TCHECK2(*pptr
,len
);
2250 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2259 bgp_capabilities_print(netdissect_options
*ndo
,
2260 const u_char
*opt
, int caps_len
)
2262 int cap_type
, cap_len
, tcap_len
, cap_offset
;
2265 while (i
< caps_len
) {
2266 ND_TCHECK2(opt
[i
], BGP_CAP_HEADER_SIZE
);
2270 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2271 tok2str(bgp_capcode_values
, "Unknown",
2275 ND_TCHECK2(opt
[i
+2], cap_len
);
2277 case BGP_CAPCODE_MP
:
2278 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2279 tok2str(af_values
, "Unknown",
2280 EXTRACT_16BITS(opt
+i
+2)),
2281 EXTRACT_16BITS(opt
+i
+2),
2282 tok2str(bgp_safi_values
, "Unknown",
2286 case BGP_CAPCODE_RESTART
:
2287 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2288 ((opt
[i
+2])&0x80) ? "R" : "none",
2289 EXTRACT_16BITS(opt
+i
+2)&0xfff));
2292 while(tcap_len
>=4) {
2293 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2294 tok2str(af_values
,"Unknown",
2295 EXTRACT_16BITS(opt
+i
+cap_offset
)),
2296 EXTRACT_16BITS(opt
+i
+cap_offset
),
2297 tok2str(bgp_safi_values
,"Unknown",
2298 opt
[i
+cap_offset
+2]),
2299 opt
[i
+cap_offset
+2],
2300 ((opt
[i
+cap_offset
+3])&0x80) ? "yes" : "no" ));
2305 case BGP_CAPCODE_RR
:
2306 case BGP_CAPCODE_RR_CISCO
:
2308 case BGP_CAPCODE_AS_NEW
:
2311 * Extract the 4 byte AS number encoded.
2314 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2315 as_printf(ndo
, astostr
, sizeof(astostr
),
2316 EXTRACT_32BITS(opt
+ i
+ 2))));
2319 case BGP_CAPCODE_ADD_PATH
:
2321 if (tcap_len
== 0) {
2322 ND_PRINT((ndo
, " (bogus)")); /* length */
2325 while (tcap_len
> 0) {
2327 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2330 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2331 tok2str(af_values
,"Unknown",EXTRACT_16BITS(opt
+i
+cap_offset
)),
2332 EXTRACT_16BITS(opt
+i
+cap_offset
),
2333 tok2str(bgp_safi_values
,"Unknown",opt
[i
+cap_offset
+2]),
2334 opt
[i
+cap_offset
+2],
2335 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",opt
[i
+cap_offset
+3])
2342 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2344 if (ndo
->ndo_vflag
<= 1)
2345 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2348 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2349 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2351 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2356 ND_PRINT((ndo
, "[|BGP]"));
2360 bgp_open_print(netdissect_options
*ndo
,
2361 const u_char
*dat
, int length
)
2363 struct bgp_open bgpo
;
2364 struct bgp_opt bgpopt
;
2368 ND_TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2369 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2371 ND_PRINT((ndo
, "\n\t Version %d, ", bgpo
.bgpo_version
));
2372 ND_PRINT((ndo
, "my AS %s, ",
2373 as_printf(ndo
, astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
))));
2374 ND_PRINT((ndo
, "Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
)));
2375 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgpo
.bgpo_id
)));
2376 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
));
2378 /* some little sanity checking */
2379 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2383 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2387 while (i
< bgpo
.bgpo_optlen
) {
2388 ND_TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2389 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2390 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2391 ND_PRINT((ndo
, "\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
));
2395 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2396 tok2str(bgp_opt_values
,"Unknown",
2397 bgpopt
.bgpopt_type
),
2399 bgpopt
.bgpopt_len
));
2401 /* now let's decode the options we know*/
2402 switch(bgpopt
.bgpopt_type
) {
2405 bgp_capabilities_print(ndo
, &opt
[i
+BGP_OPT_SIZE
],
2411 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2412 bgpopt
.bgpopt_type
));
2415 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2419 ND_PRINT((ndo
, "[|BGP]"));
2423 bgp_update_print(netdissect_options
*ndo
,
2424 const u_char
*dat
, int length
)
2428 int withdrawn_routes_len
;
2432 ND_TCHECK2(dat
[0], BGP_SIZE
);
2433 if (length
< BGP_SIZE
)
2435 memcpy(&bgp
, dat
, BGP_SIZE
);
2436 p
= dat
+ BGP_SIZE
; /*XXX*/
2439 /* Unfeasible routes */
2440 ND_TCHECK2(p
[0], 2);
2443 withdrawn_routes_len
= EXTRACT_16BITS(p
);
2446 if (withdrawn_routes_len
) {
2448 * Without keeping state from the original NLRI message,
2449 * it's not possible to tell if this a v4 or v6 route,
2450 * so only try to decode it if we're not v6 enabled.
2452 ND_TCHECK2(p
[0], withdrawn_routes_len
);
2453 if (length
< withdrawn_routes_len
)
2455 ND_PRINT((ndo
, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len
));
2456 p
+= withdrawn_routes_len
;
2457 length
-= withdrawn_routes_len
;
2460 ND_TCHECK2(p
[0], 2);
2463 len
= EXTRACT_16BITS(p
);
2467 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2468 /* No withdrawn routes, no path attributes, no NLRI */
2469 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2474 /* do something more useful!*/
2476 int aflags
, atype
, alenlen
, alen
;
2478 ND_TCHECK2(p
[0], 2);
2488 alenlen
= bgp_attr_lenlen(aflags
, p
);
2489 ND_TCHECK2(p
[0], alenlen
);
2492 if (length
< alenlen
)
2494 alen
= bgp_attr_len(aflags
, p
);
2499 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2500 tok2str(bgp_attr_values
, "Unknown Attribute",
2506 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2507 aflags
& 0x80 ? "O" : "",
2508 aflags
& 0x40 ? "T" : "",
2509 aflags
& 0x20 ? "P" : "",
2510 aflags
& 0x10 ? "E" : ""));
2512 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2513 ND_PRINT((ndo
, "]: "));
2519 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2529 * XXX - what if they're using the "Advertisement of
2530 * Multiple Paths in BGP" feature:
2532 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2534 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2536 ND_PRINT((ndo
, "\n\t Updated routes:"));
2538 char buf
[MAXHOSTNAMELEN
+ 100];
2539 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2541 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2546 goto trunc
; /* bytes left, but not enough */
2548 ND_PRINT((ndo
, "\n\t %s", buf
));
2556 ND_PRINT((ndo
, "[|BGP]"));
2560 bgp_notification_print(netdissect_options
*ndo
,
2561 const u_char
*dat
, int length
)
2563 struct bgp_notification bgpn
;
2566 ND_TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2567 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2569 /* some little sanity checking */
2570 if (length
<BGP_NOTIFICATION_SIZE
)
2573 ND_PRINT((ndo
, ", %s (%u)",
2574 tok2str(bgp_notify_major_values
, "Unknown Error",
2578 switch (bgpn
.bgpn_major
) {
2580 case BGP_NOTIFY_MAJOR_MSG
:
2581 ND_PRINT((ndo
, ", subcode %s (%u)",
2582 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2586 case BGP_NOTIFY_MAJOR_OPEN
:
2587 ND_PRINT((ndo
, ", subcode %s (%u)",
2588 tok2str(bgp_notify_minor_open_values
, "Unknown",
2592 case BGP_NOTIFY_MAJOR_UPDATE
:
2593 ND_PRINT((ndo
, ", subcode %s (%u)",
2594 tok2str(bgp_notify_minor_update_values
, "Unknown",
2598 case BGP_NOTIFY_MAJOR_CAP
:
2599 ND_PRINT((ndo
, " subcode %s (%u)",
2600 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2603 case BGP_NOTIFY_MAJOR_CEASE
:
2604 ND_PRINT((ndo
, ", subcode %s (%u)",
2605 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2609 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2610 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2612 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2613 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2614 ND_TCHECK2(*tptr
, 7);
2615 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2616 tok2str(af_values
, "Unknown",
2617 EXTRACT_16BITS(tptr
)),
2618 EXTRACT_16BITS(tptr
),
2619 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
2621 EXTRACT_32BITS(tptr
+3)));
2630 ND_PRINT((ndo
, "[|BGP]"));
2634 bgp_route_refresh_print(netdissect_options
*ndo
,
2635 const u_char
*pptr
, int len
)
2637 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2639 ND_TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2641 /* some little sanity checking */
2642 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2645 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2647 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2648 tok2str(af_values
,"Unknown",
2649 /* this stinks but the compiler pads the structure
2651 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)),
2652 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2653 tok2str(bgp_safi_values
,"Unknown",
2654 bgp_route_refresh_header
->safi
),
2655 bgp_route_refresh_header
->safi
));
2657 if (ndo
->ndo_vflag
> 1) {
2658 ND_TCHECK2(*pptr
, len
);
2659 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2664 ND_PRINT((ndo
, "[|BGP]"));
2668 bgp_header_print(netdissect_options
*ndo
,
2669 const u_char
*dat
, int length
)
2673 ND_TCHECK2(dat
[0], BGP_SIZE
);
2674 memcpy(&bgp
, dat
, BGP_SIZE
);
2675 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2676 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
2680 switch (bgp
.bgp_type
) {
2682 bgp_open_print(ndo
, dat
, length
);
2685 bgp_update_print(ndo
, dat
, length
);
2687 case BGP_NOTIFICATION
:
2688 bgp_notification_print(ndo
, dat
, length
);
2692 case BGP_ROUTE_REFRESH
:
2693 bgp_route_refresh_print(ndo
, dat
, length
);
2696 /* we have no decoder for the BGP message */
2697 ND_TCHECK2(*dat
, length
);
2698 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp
.bgp_type
));
2699 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2704 ND_PRINT((ndo
, "[|BGP]"));
2709 bgp_print(netdissect_options
*ndo
,
2710 const u_char
*dat
, int length
)
2714 const u_char
*start
;
2715 const u_char marker
[] = {
2716 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2717 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2723 if (ndo
->ndo_snapend
< dat
+ length
)
2724 ep
= ndo
->ndo_snapend
;
2726 ND_PRINT((ndo
, ": BGP"));
2728 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2734 if (!ND_TTEST2(p
[0], 1))
2741 if (!ND_TTEST2(p
[0], sizeof(marker
)))
2743 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2748 /* found BGP header */
2749 ND_TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2750 memcpy(&bgp
, p
, BGP_SIZE
);
2753 ND_PRINT((ndo
, " [|BGP]"));
2755 hlen
= ntohs(bgp
.bgp_len
);
2756 if (hlen
< BGP_SIZE
) {
2757 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
2762 if (ND_TTEST2(p
[0], hlen
)) {
2763 if (!bgp_header_print(ndo
, p
, hlen
))
2768 ND_PRINT((ndo
, "\n[|BGP %s]",
2769 tok2str(bgp_msg_values
,
2770 "Unknown Message Type",
2779 ND_PRINT((ndo
, " [|BGP]"));
2784 * c-style: whitesmith