]> The Tcpdump Group git mirrors - tcpdump/blob - print-bgp.c
Fixup the reference for BGPTYPE_AIGP
[tcpdump] / print-bgp.c
1 /*
2 * Copyright (C) 1999 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 *
29 * Extensively modified by Hannes Gredler (hannes@juniper.net) for more
30 * complete BGP support.
31 */
32
33 /* \summary: Border Gateway Protocol (BGP) printer */
34
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
38
39 #include <netdissect-stdinc.h>
40
41 #include <stdio.h>
42 #include <string.h>
43
44 #include "netdissect.h"
45 #include "addrtoname.h"
46 #include "extract.h"
47 #include "af.h"
48 #include "l2vpn.h"
49
50 struct bgp {
51 uint8_t bgp_marker[16];
52 uint16_t bgp_len;
53 uint8_t bgp_type;
54 };
55 #define BGP_SIZE 19 /* unaligned */
56
57 #define BGP_OPEN 1
58 #define BGP_UPDATE 2
59 #define BGP_NOTIFICATION 3
60 #define BGP_KEEPALIVE 4
61 #define BGP_ROUTE_REFRESH 5
62
63 static const struct tok bgp_msg_values[] = {
64 { BGP_OPEN, "Open"},
65 { BGP_UPDATE, "Update"},
66 { BGP_NOTIFICATION, "Notification"},
67 { BGP_KEEPALIVE, "Keepalive"},
68 { BGP_ROUTE_REFRESH, "Route Refresh"},
69 { 0, NULL}
70 };
71
72 struct bgp_open {
73 uint8_t bgpo_marker[16];
74 uint16_t bgpo_len;
75 uint8_t bgpo_type;
76 uint8_t bgpo_version;
77 uint16_t bgpo_myas;
78 uint16_t bgpo_holdtime;
79 uint32_t bgpo_id;
80 uint8_t bgpo_optlen;
81 /* options should follow */
82 };
83 #define BGP_OPEN_SIZE 29 /* unaligned */
84
85 struct bgp_opt {
86 uint8_t bgpopt_type;
87 uint8_t bgpopt_len;
88 /* variable length */
89 };
90 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
91 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
92
93 struct bgp_notification {
94 uint8_t bgpn_marker[16];
95 uint16_t bgpn_len;
96 uint8_t bgpn_type;
97 uint8_t bgpn_major;
98 uint8_t bgpn_minor;
99 };
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
101
102 struct bgp_route_refresh {
103 uint8_t bgp_marker[16];
104 uint16_t len;
105 uint8_t type;
106 uint8_t afi[2]; /* the compiler messes this structure up */
107 uint8_t res; /* when doing misaligned sequences of int8 and int16 */
108 uint8_t safi; /* afi should be int16 - so we have to access it using */
109 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
110 #define BGP_ROUTE_REFRESH_SIZE 23
111
112 #define bgp_attr_lenlen(flags, p) \
113 (((flags) & 0x10) ? 2 : 1)
114 #define bgp_attr_len(flags, p) \
115 (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p))
116
117 #define BGPTYPE_ORIGIN 1
118 #define BGPTYPE_AS_PATH 2
119 #define BGPTYPE_NEXT_HOP 3
120 #define BGPTYPE_MULTI_EXIT_DISC 4
121 #define BGPTYPE_LOCAL_PREF 5
122 #define BGPTYPE_ATOMIC_AGGREGATE 6
123 #define BGPTYPE_AGGREGATOR 7
124 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
125 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
126 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
127 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
128 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
129 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
130 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
131 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
132 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
133 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
134 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
135 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
136 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
137 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
138 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
139 #define BGPTYPE_AIGP 26 /* RFC7311 */
140 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
141 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
142 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
143
144 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
145
146 static const struct tok bgp_attr_values[] = {
147 { BGPTYPE_ORIGIN, "Origin"},
148 { BGPTYPE_AS_PATH, "AS Path"},
149 { BGPTYPE_AS4_PATH, "AS4 Path"},
150 { BGPTYPE_NEXT_HOP, "Next Hop"},
151 { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"},
152 { BGPTYPE_LOCAL_PREF, "Local Preference"},
153 { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"},
154 { BGPTYPE_AGGREGATOR, "Aggregator"},
155 { BGPTYPE_AGGREGATOR4, "Aggregator4"},
156 { BGPTYPE_COMMUNITIES, "Community"},
157 { BGPTYPE_ORIGINATOR_ID, "Originator ID"},
158 { BGPTYPE_CLUSTER_LIST, "Cluster List"},
159 { BGPTYPE_DPA, "DPA"},
160 { BGPTYPE_ADVERTISERS, "Advertisers"},
161 { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"},
162 { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"},
163 { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"},
164 { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"},
165 { BGPTYPE_PMSI_TUNNEL, "PMSI Tunnel"},
166 { BGPTYPE_TUNNEL_ENCAP, "Tunnel Encapsulation"},
167 { BGPTYPE_TRAFFIC_ENG, "Traffic Engineering"},
168 { BGPTYPE_IPV6_EXTD_COMMUNITIES, "IPv6 Extended Community"},
169 { BGPTYPE_AIGP, "Accumulated IGP Metric"},
170 { BGPTYPE_PE_DISTINGUISHER_LABEL, "PE Distinguisher Label"},
171 { BGPTYPE_ENTROPY_LABEL, "Entropy Label"},
172 { BGPTYPE_ATTR_SET, "Attribute Set"},
173 { 255, "Reserved for development"},
174 { 0, NULL}
175 };
176
177 #define BGP_AS_SET 1
178 #define BGP_AS_SEQUENCE 2
179 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
180 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
181
182 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
183 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
184
185 static const struct tok bgp_as_path_segment_open_values[] = {
186 { BGP_AS_SEQUENCE, ""},
187 { BGP_AS_SET, "{ "},
188 { BGP_CONFED_AS_SEQUENCE, "( "},
189 { BGP_CONFED_AS_SET, "({ "},
190 { 0, NULL}
191 };
192
193 static const struct tok bgp_as_path_segment_close_values[] = {
194 { BGP_AS_SEQUENCE, ""},
195 { BGP_AS_SET, "}"},
196 { BGP_CONFED_AS_SEQUENCE, ")"},
197 { BGP_CONFED_AS_SET, "})"},
198 { 0, NULL}
199 };
200
201 #define BGP_OPT_AUTH 1
202 #define BGP_OPT_CAP 2
203
204
205 static const struct tok bgp_opt_values[] = {
206 { BGP_OPT_AUTH, "Authentication Information"},
207 { BGP_OPT_CAP, "Capabilities Advertisement"},
208 { 0, NULL}
209 };
210
211 #define BGP_CAPCODE_MP 1 /* RFC2858 */
212 #define BGP_CAPCODE_RR 2 /* RFC2918 */
213 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
214 #define BGP_CAPCODE_MR 4 /* RFC3107 */
215 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
216 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
217 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
218 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
219 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
220 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
221 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
222 #define BGP_CAPCODE_RR_CISCO 128
223
224 static const struct tok bgp_capcode_values[] = {
225 { BGP_CAPCODE_MP, "Multiprotocol Extensions"},
226 { BGP_CAPCODE_RR, "Route Refresh"},
227 { BGP_CAPCODE_ORF, "Cooperative Route Filtering"},
228 { BGP_CAPCODE_MR, "Multiple Routes to a Destination"},
229 { BGP_CAPCODE_EXT_NH, "Extended Next Hop Encoding"},
230 { BGP_CAPCODE_RESTART, "Graceful Restart"},
231 { BGP_CAPCODE_AS_NEW, "32-Bit AS Number"},
232 { BGP_CAPCODE_DYN_CAP, "Dynamic Capability"},
233 { BGP_CAPCODE_MULTISESS, "Multisession BGP"},
234 { BGP_CAPCODE_ADD_PATH, "Multiple Paths"},
235 { BGP_CAPCODE_ENH_RR, "Enhanced Route Refresh"},
236 { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"},
237 { 0, NULL}
238 };
239
240 #define BGP_NOTIFY_MAJOR_MSG 1
241 #define BGP_NOTIFY_MAJOR_OPEN 2
242 #define BGP_NOTIFY_MAJOR_UPDATE 3
243 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
244 #define BGP_NOTIFY_MAJOR_FSM 5
245 #define BGP_NOTIFY_MAJOR_CEASE 6
246 #define BGP_NOTIFY_MAJOR_CAP 7
247
248 static const struct tok bgp_notify_major_values[] = {
249 { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"},
250 { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"},
251 { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"},
252 { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"},
253 { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"},
254 { BGP_NOTIFY_MAJOR_CEASE, "Cease"},
255 { BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"},
256 { 0, NULL}
257 };
258
259 /* draft-ietf-idr-cease-subcode-02 */
260 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
261 static const struct tok bgp_notify_minor_cease_values[] = {
262 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"},
263 { 2, "Administratively Shutdown"},
264 { 3, "Peer Unconfigured"},
265 { 4, "Administratively Reset"},
266 { 5, "Connection Rejected"},
267 { 6, "Other Configuration Change"},
268 { 7, "Connection Collision Resolution"},
269 { 0, NULL}
270 };
271
272 static const struct tok bgp_notify_minor_msg_values[] = {
273 { 1, "Connection Not Synchronized"},
274 { 2, "Bad Message Length"},
275 { 3, "Bad Message Type"},
276 { 0, NULL}
277 };
278
279 static const struct tok bgp_notify_minor_open_values[] = {
280 { 1, "Unsupported Version Number"},
281 { 2, "Bad Peer AS"},
282 { 3, "Bad BGP Identifier"},
283 { 4, "Unsupported Optional Parameter"},
284 { 5, "Authentication Failure"},
285 { 6, "Unacceptable Hold Time"},
286 { 7, "Capability Message Error"},
287 { 0, NULL}
288 };
289
290 static const struct tok bgp_notify_minor_update_values[] = {
291 { 1, "Malformed Attribute List"},
292 { 2, "Unrecognized Well-known Attribute"},
293 { 3, "Missing Well-known Attribute"},
294 { 4, "Attribute Flags Error"},
295 { 5, "Attribute Length Error"},
296 { 6, "Invalid ORIGIN Attribute"},
297 { 7, "AS Routing Loop"},
298 { 8, "Invalid NEXT_HOP Attribute"},
299 { 9, "Optional Attribute Error"},
300 { 10, "Invalid Network Field"},
301 { 11, "Malformed AS_PATH"},
302 { 0, NULL}
303 };
304
305 static const struct tok bgp_notify_minor_fsm_values[] = {
306 { 1, "In OpenSent State"},
307 { 2, "In OpenConfirm State"},
308 { 3, "In Established State"},
309 { 0, NULL }
310 };
311
312 static const struct tok bgp_notify_minor_cap_values[] = {
313 { 1, "Invalid Action Value" },
314 { 2, "Invalid Capability Length" },
315 { 3, "Malformed Capability Value" },
316 { 4, "Unsupported Capability Code" },
317 { 0, NULL }
318 };
319
320 static const struct tok bgp_origin_values[] = {
321 { 0, "IGP"},
322 { 1, "EGP"},
323 { 2, "Incomplete"},
324 { 0, NULL}
325 };
326
327 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
328 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
329 #define BGP_PMSI_TUNNEL_PIM_SSM 3
330 #define BGP_PMSI_TUNNEL_PIM_SM 4
331 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
332 #define BGP_PMSI_TUNNEL_INGRESS 6
333 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
334
335 static const struct tok bgp_pmsi_tunnel_values[] = {
336 { BGP_PMSI_TUNNEL_RSVP_P2MP, "RSVP-TE P2MP LSP"},
337 { BGP_PMSI_TUNNEL_LDP_P2MP, "LDP P2MP LSP"},
338 { BGP_PMSI_TUNNEL_PIM_SSM, "PIM-SSM Tree"},
339 { BGP_PMSI_TUNNEL_PIM_SM, "PIM-SM Tree"},
340 { BGP_PMSI_TUNNEL_PIM_BIDIR, "PIM-Bidir Tree"},
341 { BGP_PMSI_TUNNEL_INGRESS, "Ingress Replication"},
342 { BGP_PMSI_TUNNEL_LDP_MP2MP, "LDP MP2MP LSP"},
343 { 0, NULL}
344 };
345
346 static const struct tok bgp_pmsi_flag_values[] = {
347 { 0x01, "Leaf Information required"},
348 { 0, NULL}
349 };
350
351 #define BGP_AIGP_TLV 1
352
353 static const struct tok bgp_aigp_values[] = {
354 { BGP_AIGP_TLV, "AIGP"},
355 { 0, NULL}
356 };
357
358
359 /* Subsequent address family identifier, RFC2283 section 7 */
360 #define SAFNUM_RES 0
361 #define SAFNUM_UNICAST 1
362 #define SAFNUM_MULTICAST 2
363 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
364 /* labeled BGP RFC3107 */
365 #define SAFNUM_LABUNICAST 4
366 /* RFC6514 */
367 #define SAFNUM_MULTICAST_VPN 5
368 /* draft-nalawade-kapoor-tunnel-safi */
369 #define SAFNUM_TUNNEL 64
370 /* RFC4761 */
371 #define SAFNUM_VPLS 65
372 /* RFC6037 */
373 #define SAFNUM_MDT 66
374 /* RFC4364 */
375 #define SAFNUM_VPNUNICAST 128
376 /* RFC6513 */
377 #define SAFNUM_VPNMULTICAST 129
378 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
379 /* RFC4684 */
380 #define SAFNUM_RT_ROUTING_INFO 132
381
382 #define BGP_VPN_RD_LEN 8
383
384 static const struct tok bgp_safi_values[] = {
385 { SAFNUM_RES, "Reserved"},
386 { SAFNUM_UNICAST, "Unicast"},
387 { SAFNUM_MULTICAST, "Multicast"},
388 { SAFNUM_UNIMULTICAST, "Unicast+Multicast"},
389 { SAFNUM_LABUNICAST, "labeled Unicast"},
390 { SAFNUM_TUNNEL, "Tunnel"},
391 { SAFNUM_VPLS, "VPLS"},
392 { SAFNUM_MDT, "MDT"},
393 { SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
394 { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
395 { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
396 { SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"},
397 { SAFNUM_MULTICAST_VPN, "Multicast VPN"},
398 { 0, NULL }
399 };
400
401 /* well-known community */
402 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
403 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
404 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
405
406 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
407 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
408 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
409 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
410 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
411 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
412 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
413 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
414 /* rfc2547 bgp-mpls-vpns */
415 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
416 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
417 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
418 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
419
420 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
421 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
422
423 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
424 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
425
426 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
427
428 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
429 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
430 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
431 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
432
433
434 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
435 #define BGP_EXT_COM_EIGRP_GEN 0x8800
436 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
437 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
438 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
439 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
440 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
441
442 static const struct tok bgp_extd_comm_flag_values[] = {
443 { 0x8000, "vendor-specific"},
444 { 0x4000, "non-transitive"},
445 { 0, NULL},
446 };
447
448 static const struct tok bgp_extd_comm_subtype_values[] = {
449 { BGP_EXT_COM_RT_0, "target"},
450 { BGP_EXT_COM_RT_1, "target"},
451 { BGP_EXT_COM_RT_2, "target"},
452 { BGP_EXT_COM_RO_0, "origin"},
453 { BGP_EXT_COM_RO_1, "origin"},
454 { BGP_EXT_COM_RO_2, "origin"},
455 { BGP_EXT_COM_LINKBAND, "link-BW"},
456 { BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"},
457 { BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"},
458 { BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"},
459 { BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"},
460 { BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"},
461 { BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"},
462 { BGP_EXT_COM_OSPF_RID, "ospf-router-id"},
463 { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"},
464 { BGP_EXT_COM_L2INFO, "layer2-info"},
465 { BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" },
466 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" },
467 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" },
468 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" },
469 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" },
470 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" },
471 { BGP_EXT_COM_SOURCE_AS, "source-AS" },
472 { BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"},
473 { BGP_EXT_COM_L2VPN_RT_0, "l2vpn-id"},
474 { BGP_EXT_COM_L2VPN_RT_1, "l2vpn-id"},
475 { 0, NULL},
476 };
477
478 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
479 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
480 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
481 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
482 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
483 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
484 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
485 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
486
487 static const struct tok bgp_extd_comm_ospf_rtype_values[] = {
488 { BGP_OSPF_RTYPE_RTR, "Router" },
489 { BGP_OSPF_RTYPE_NET, "Network" },
490 { BGP_OSPF_RTYPE_SUM, "Summary" },
491 { BGP_OSPF_RTYPE_EXT, "External" },
492 { BGP_OSPF_RTYPE_NSSA,"NSSA External" },
493 { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
494 { 0, NULL },
495 };
496
497 /* ADD-PATH Send/Receive field values */
498 static const struct tok bgp_add_path_recvsend[] = {
499 { 1, "Receive" },
500 { 2, "Send" },
501 { 3, "Both" },
502 { 0, NULL },
503 };
504
505 static char astostr[20];
506
507 /*
508 * as_printf
509 *
510 * Convert an AS number into a string and return string pointer.
511 *
512 * Depending on bflag is set or not, AS number is converted into ASDOT notation
513 * or plain number notation.
514 *
515 */
516 static char *
517 as_printf(netdissect_options *ndo,
518 char *str, int size, u_int asnum)
519 {
520 if (!ndo->ndo_bflag || asnum <= 0xFFFF) {
521 snprintf(str, size, "%u", asnum);
522 } else {
523 snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF);
524 }
525 return str;
526 }
527
528 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
529
530 int
531 decode_prefix4(netdissect_options *ndo,
532 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
533 {
534 struct in_addr addr;
535 u_int plen, plenbytes;
536
537 ND_TCHECK(pptr[0]);
538 ITEMCHECK(1);
539 plen = pptr[0];
540 if (32 < plen)
541 return -1;
542 itemlen -= 1;
543
544 memset(&addr, 0, sizeof(addr));
545 plenbytes = (plen + 7) / 8;
546 ND_TCHECK2(pptr[1], plenbytes);
547 ITEMCHECK(plenbytes);
548 memcpy(&addr, &pptr[1], plenbytes);
549 if (plen % 8) {
550 ((u_char *)&addr)[plenbytes - 1] &=
551 ((0xff00 >> (plen % 8)) & 0xff);
552 }
553 snprintf(buf, buflen, "%s/%d", ipaddr_string(ndo, &addr), plen);
554 return 1 + plenbytes;
555
556 trunc:
557 return -2;
558
559 badtlv:
560 return -3;
561 }
562
563 static int
564 decode_labeled_prefix4(netdissect_options *ndo,
565 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
566 {
567 struct in_addr addr;
568 u_int plen, plenbytes;
569
570 /* prefix length and label = 4 bytes */
571 ND_TCHECK2(pptr[0], 4);
572 ITEMCHECK(4);
573 plen = pptr[0]; /* get prefix length */
574
575 /* this is one of the weirdnesses of rfc3107
576 the label length (actually the label + COS bits)
577 is added to the prefix length;
578 we also do only read out just one label -
579 there is no real application for advertisement of
580 stacked labels in a single BGP message
581 */
582
583 if (24 > plen)
584 return -1;
585
586 plen-=24; /* adjust prefixlen - labellength */
587
588 if (32 < plen)
589 return -1;
590 itemlen -= 4;
591
592 memset(&addr, 0, sizeof(addr));
593 plenbytes = (plen + 7) / 8;
594 ND_TCHECK2(pptr[4], plenbytes);
595 ITEMCHECK(plenbytes);
596 memcpy(&addr, &pptr[4], plenbytes);
597 if (plen % 8) {
598 ((u_char *)&addr)[plenbytes - 1] &=
599 ((0xff00 >> (plen % 8)) & 0xff);
600 }
601 /* the label may get offsetted by 4 bits so lets shift it right */
602 snprintf(buf, buflen, "%s/%d, label:%u %s",
603 ipaddr_string(ndo, &addr),
604 plen,
605 EXTRACT_24BITS(pptr+1)>>4,
606 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
607
608 return 4 + plenbytes;
609
610 trunc:
611 return -2;
612
613 badtlv:
614 return -3;
615 }
616
617 /*
618 * bgp_vpn_ip_print
619 *
620 * print an ipv4 or ipv6 address into a buffer dependend on address length.
621 */
622 static char *
623 bgp_vpn_ip_print(netdissect_options *ndo,
624 const u_char *pptr, u_int addr_length)
625 {
626
627 /* worst case string is s fully formatted v6 address */
628 static char addr[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
629 char *pos = addr;
630
631 switch(addr_length) {
632 case (sizeof(struct in_addr) << 3): /* 32 */
633 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
634 snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr));
635 break;
636 case (sizeof(struct in6_addr) << 3): /* 128 */
637 ND_TCHECK2(pptr[0], sizeof(struct in6_addr));
638 snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr));
639 break;
640 default:
641 snprintf(pos, sizeof(addr), "bogus address length %u", addr_length);
642 break;
643 }
644 pos += strlen(pos);
645
646 trunc:
647 *(pos) = '\0';
648 return (addr);
649 }
650
651 /*
652 * bgp_vpn_sg_print
653 *
654 * print an multicast s,g entry into a buffer.
655 * the s,g entry is encoded like this.
656 *
657 * +-----------------------------------+
658 * | Multicast Source Length (1 octet) |
659 * +-----------------------------------+
660 * | Multicast Source (Variable) |
661 * +-----------------------------------+
662 * | Multicast Group Length (1 octet) |
663 * +-----------------------------------+
664 * | Multicast Group (Variable) |
665 * +-----------------------------------+
666 *
667 * return the number of bytes read from the wire.
668 */
669 static int
670 bgp_vpn_sg_print(netdissect_options *ndo,
671 const u_char *pptr, char *buf, u_int buflen)
672 {
673 uint8_t addr_length;
674 u_int total_length, offset;
675
676 total_length = 0;
677
678 /* Source address length, encoded in bits */
679 ND_TCHECK2(pptr[0], 1);
680 addr_length = *pptr++;
681
682 /* Source address */
683 ND_TCHECK2(pptr[0], (addr_length >> 3));
684 total_length += (addr_length >> 3) + 1;
685 offset = strlen(buf);
686 if (addr_length) {
687 snprintf(buf + offset, buflen - offset, ", Source %s",
688 bgp_vpn_ip_print(ndo, pptr, addr_length));
689 pptr += (addr_length >> 3);
690 }
691
692 /* Group address length, encoded in bits */
693 ND_TCHECK2(pptr[0], 1);
694 addr_length = *pptr++;
695
696 /* Group address */
697 ND_TCHECK2(pptr[0], (addr_length >> 3));
698 total_length += (addr_length >> 3) + 1;
699 offset = strlen(buf);
700 if (addr_length) {
701 snprintf(buf + offset, buflen - offset, ", Group %s",
702 bgp_vpn_ip_print(ndo, pptr, addr_length));
703 pptr += (addr_length >> 3);
704 }
705
706 trunc:
707 return (total_length);
708 }
709
710
711 /* RDs and RTs share the same semantics
712 * we use bgp_vpn_rd_print for
713 * printing route targets inside a NLRI */
714 char *
715 bgp_vpn_rd_print(netdissect_options *ndo,
716 const u_char *pptr)
717 {
718 /* allocate space for the largest possible string */
719 static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
720 char *pos = rd;
721
722 /* ok lets load the RD format */
723 switch (EXTRACT_16BITS(pptr)) {
724
725 /* 2-byte-AS:number fmt*/
726 case 0:
727 snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)",
728 EXTRACT_16BITS(pptr+2),
729 EXTRACT_32BITS(pptr+4),
730 *(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7));
731 break;
732 /* IP-address:AS fmt*/
733
734 case 1:
735 snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u",
736 *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6));
737 break;
738
739 /* 4-byte-AS:number fmt*/
740 case 2:
741 snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
742 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr+2)),
743 EXTRACT_16BITS(pptr+6), *(pptr+2), *(pptr+3), *(pptr+4),
744 *(pptr+5), EXTRACT_16BITS(pptr+6));
745 break;
746 default:
747 snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format");
748 break;
749 }
750 pos += strlen(pos);
751 *(pos) = '\0';
752 return (rd);
753 }
754
755 static int
756 decode_rt_routing_info(netdissect_options *ndo,
757 const u_char *pptr, char *buf, u_int buflen)
758 {
759 uint8_t route_target[8];
760 u_int plen;
761
762 ND_TCHECK(pptr[0]);
763 plen = pptr[0]; /* get prefix length */
764
765 if (0 == plen) {
766 snprintf(buf, buflen, "default route target");
767 return 1;
768 }
769
770 if (32 > plen)
771 return -1;
772
773 plen-=32; /* adjust prefix length */
774
775 if (64 < plen)
776 return -1;
777
778 memset(&route_target, 0, sizeof(route_target));
779 ND_TCHECK2(pptr[1], (plen + 7) / 8);
780 memcpy(&route_target, &pptr[1], (plen + 7) / 8);
781 if (plen % 8) {
782 ((u_char *)&route_target)[(plen + 7) / 8 - 1] &=
783 ((0xff00 >> (plen % 8)) & 0xff);
784 }
785 snprintf(buf, buflen, "origin AS: %s, route target %s",
786 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr+1)),
787 bgp_vpn_rd_print(ndo, (u_char *)&route_target));
788
789 return 5 + (plen + 7) / 8;
790
791 trunc:
792 return -2;
793 }
794
795 static int
796 decode_labeled_vpn_prefix4(netdissect_options *ndo,
797 const u_char *pptr, char *buf, u_int buflen)
798 {
799 struct in_addr addr;
800 u_int plen;
801
802 ND_TCHECK(pptr[0]);
803 plen = pptr[0]; /* get prefix length */
804
805 if ((24+64) > plen)
806 return -1;
807
808 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
809
810 if (32 < plen)
811 return -1;
812
813 memset(&addr, 0, sizeof(addr));
814 ND_TCHECK2(pptr[12], (plen + 7) / 8);
815 memcpy(&addr, &pptr[12], (plen + 7) / 8);
816 if (plen % 8) {
817 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
818 ((0xff00 >> (plen % 8)) & 0xff);
819 }
820 /* the label may get offsetted by 4 bits so lets shift it right */
821 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
822 bgp_vpn_rd_print(ndo, pptr+4),
823 ipaddr_string(ndo, &addr),
824 plen,
825 EXTRACT_24BITS(pptr+1)>>4,
826 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
827
828 return 12 + (plen + 7) / 8;
829
830 trunc:
831 return -2;
832 }
833
834 /*
835 * +-------------------------------+
836 * | |
837 * | RD:IPv4-address (12 octets) |
838 * | |
839 * +-------------------------------+
840 * | MDT Group-address (4 octets) |
841 * +-------------------------------+
842 */
843
844 #define MDT_VPN_NLRI_LEN 16
845
846 static int
847 decode_mdt_vpn_nlri(netdissect_options *ndo,
848 const u_char *pptr, char *buf, u_int buflen)
849 {
850
851 const u_char *rd;
852 const u_char *vpn_ip;
853
854 ND_TCHECK(pptr[0]);
855
856 /* if the NLRI is not predefined length, quit.*/
857 if (*pptr != MDT_VPN_NLRI_LEN * 8)
858 return -1;
859 pptr++;
860
861 /* RD */
862 ND_TCHECK2(pptr[0], 8);
863 rd = pptr;
864 pptr+=8;
865
866 /* IPv4 address */
867 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
868 vpn_ip = pptr;
869 pptr+=sizeof(struct in_addr);
870
871 /* MDT Group Address */
872 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
873
874 snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
875 bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr));
876
877 return MDT_VPN_NLRI_LEN + 1;
878
879 trunc:
880
881 return -2;
882 }
883
884 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
885 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
886 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
887 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
888 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
889 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
890 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
891
892 static const struct tok bgp_multicast_vpn_route_type_values[] = {
893 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"},
894 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"},
895 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"},
896 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"},
897 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
898 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
899 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
900 };
901
902 static int
903 decode_multicast_vpn(netdissect_options *ndo,
904 const u_char *pptr, char *buf, u_int buflen)
905 {
906 uint8_t route_type, route_length, addr_length, sg_length;
907 u_int offset;
908
909 ND_TCHECK2(pptr[0], 2);
910 route_type = *pptr++;
911 route_length = *pptr++;
912
913 snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
914 tok2str(bgp_multicast_vpn_route_type_values,
915 "Unknown", route_type),
916 route_type, route_length);
917
918 switch(route_type) {
919 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
920 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
921 offset = strlen(buf);
922 snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
923 bgp_vpn_rd_print(ndo, pptr),
924 bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN,
925 (route_length - BGP_VPN_RD_LEN) << 3));
926 break;
927 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
928 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
929 offset = strlen(buf);
930 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
931 bgp_vpn_rd_print(ndo, pptr),
932 as_printf(ndo, astostr, sizeof(astostr),
933 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
934 break;
935
936 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
937 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
938 offset = strlen(buf);
939 snprintf(buf + offset, buflen - offset, ", RD: %s",
940 bgp_vpn_rd_print(ndo, pptr));
941 pptr += BGP_VPN_RD_LEN;
942
943 sg_length = bgp_vpn_sg_print(ndo, pptr, buf, buflen);
944 addr_length = route_length - sg_length;
945
946 ND_TCHECK2(pptr[0], addr_length);
947 offset = strlen(buf);
948 snprintf(buf + offset, buflen - offset, ", Originator %s",
949 bgp_vpn_ip_print(ndo, pptr, addr_length << 3));
950 break;
951
952 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
953 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
954 offset = strlen(buf);
955 snprintf(buf + offset, buflen - offset, ", RD: %s",
956 bgp_vpn_rd_print(ndo, pptr));
957 pptr += BGP_VPN_RD_LEN;
958
959 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
960 break;
961
962 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
963 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
964 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
965 offset = strlen(buf);
966 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
967 bgp_vpn_rd_print(ndo, pptr),
968 as_printf(ndo, astostr, sizeof(astostr),
969 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
970 pptr += BGP_VPN_RD_LEN;
971
972 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
973 break;
974
975 /*
976 * no per route-type printing yet.
977 */
978 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF:
979 default:
980 break;
981 }
982
983 return route_length + 2;
984
985 trunc:
986 return -2;
987 }
988
989 /*
990 * As I remember, some versions of systems have an snprintf() that
991 * returns -1 if the buffer would have overflowed. If the return
992 * value is negative, set buflen to 0, to indicate that we've filled
993 * the buffer up.
994 *
995 * If the return value is greater than buflen, that means that
996 * the buffer would have overflowed; again, set buflen to 0 in
997 * that case.
998 */
999 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1000 if (stringlen<0) \
1001 buflen=0; \
1002 else if ((u_int)stringlen>buflen) \
1003 buflen=0; \
1004 else { \
1005 buflen-=stringlen; \
1006 buf+=stringlen; \
1007 }
1008
1009 static int
1010 decode_labeled_vpn_l2(netdissect_options *ndo,
1011 const u_char *pptr, char *buf, u_int buflen)
1012 {
1013 int plen,tlen,stringlen,tlv_type,tlv_len,ttlv_len;
1014
1015 ND_TCHECK2(pptr[0], 2);
1016 plen=EXTRACT_16BITS(pptr);
1017 tlen=plen;
1018 pptr+=2;
1019 /* Old and new L2VPN NLRI share AFI/SAFI
1020 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1021 * and > 17 as old format. Complain for the middle case
1022 */
1023 if (plen==12) {
1024 /* assume AD-only with RD, BGPNH */
1025 ND_TCHECK2(pptr[0],12);
1026 buf[0]='\0';
1027 stringlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s",
1028 bgp_vpn_rd_print(ndo, pptr),
1029 ipaddr_string(ndo, pptr+8)
1030 );
1031 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1032 pptr+=12;
1033 tlen-=12;
1034 return plen;
1035 } else if (plen>17) {
1036 /* assume old format */
1037 /* RD, ID, LBLKOFF, LBLBASE */
1038
1039 ND_TCHECK2(pptr[0],15);
1040 buf[0]='\0';
1041 stringlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1042 bgp_vpn_rd_print(ndo, pptr),
1043 EXTRACT_16BITS(pptr+8),
1044 EXTRACT_16BITS(pptr+10),
1045 EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1046 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1047 pptr+=15;
1048 tlen-=15;
1049
1050 /* ok now the variable part - lets read out TLVs*/
1051 while (tlen>0) {
1052 if (tlen < 3)
1053 return -1;
1054 ND_TCHECK2(pptr[0], 3);
1055 tlv_type=*pptr++;
1056 tlv_len=EXTRACT_16BITS(pptr);
1057 ttlv_len=tlv_len;
1058 pptr+=2;
1059
1060 switch(tlv_type) {
1061 case 1:
1062 if (buflen!=0) {
1063 stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1064 tlv_type,
1065 tlv_len);
1066 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1067 }
1068 ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
1069 while (ttlv_len>0) {
1070 ND_TCHECK(pptr[0]);
1071 if (buflen!=0) {
1072 stringlen=snprintf(buf,buflen, "%02x",*pptr++);
1073 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1074 }
1075 ttlv_len--;
1076 }
1077 break;
1078 default:
1079 if (buflen!=0) {
1080 stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u",
1081 tlv_type,
1082 tlv_len);
1083 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1084 }
1085 break;
1086 }
1087 tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */
1088 }
1089 return plen+2;
1090
1091 } else {
1092 /* complain bitterly ? */
1093 /* fall through */
1094 goto trunc;
1095 }
1096
1097 trunc:
1098 return -2;
1099 }
1100
1101 int
1102 decode_prefix6(netdissect_options *ndo,
1103 const u_char *pd, u_int itemlen, char *buf, u_int buflen)
1104 {
1105 struct in6_addr addr;
1106 u_int plen, plenbytes;
1107
1108 ND_TCHECK(pd[0]);
1109 ITEMCHECK(1);
1110 plen = pd[0];
1111 if (128 < plen)
1112 return -1;
1113 itemlen -= 1;
1114
1115 memset(&addr, 0, sizeof(addr));
1116 plenbytes = (plen + 7) / 8;
1117 ND_TCHECK2(pd[1], plenbytes);
1118 ITEMCHECK(plenbytes);
1119 memcpy(&addr, &pd[1], plenbytes);
1120 if (plen % 8) {
1121 addr.s6_addr[plenbytes - 1] &=
1122 ((0xff00 >> (plen % 8)) & 0xff);
1123 }
1124 snprintf(buf, buflen, "%s/%d", ip6addr_string(ndo, &addr), plen);
1125 return 1 + plenbytes;
1126
1127 trunc:
1128 return -2;
1129
1130 badtlv:
1131 return -3;
1132 }
1133
1134 static int
1135 decode_labeled_prefix6(netdissect_options *ndo,
1136 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
1137 {
1138 struct in6_addr addr;
1139 u_int plen, plenbytes;
1140
1141 /* prefix length and label = 4 bytes */
1142 ND_TCHECK2(pptr[0], 4);
1143 ITEMCHECK(4);
1144 plen = pptr[0]; /* get prefix length */
1145
1146 if (24 > plen)
1147 return -1;
1148
1149 plen-=24; /* adjust prefixlen - labellength */
1150
1151 if (128 < plen)
1152 return -1;
1153 itemlen -= 4;
1154
1155 memset(&addr, 0, sizeof(addr));
1156 plenbytes = (plen + 7) / 8;
1157 ND_TCHECK2(pptr[4], plenbytes);
1158 memcpy(&addr, &pptr[4], plenbytes);
1159 if (plen % 8) {
1160 addr.s6_addr[plenbytes - 1] &=
1161 ((0xff00 >> (plen % 8)) & 0xff);
1162 }
1163 /* the label may get offsetted by 4 bits so lets shift it right */
1164 snprintf(buf, buflen, "%s/%d, label:%u %s",
1165 ip6addr_string(ndo, &addr),
1166 plen,
1167 EXTRACT_24BITS(pptr+1)>>4,
1168 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1169
1170 return 4 + plenbytes;
1171
1172 trunc:
1173 return -2;
1174
1175 badtlv:
1176 return -3;
1177 }
1178
1179 static int
1180 decode_labeled_vpn_prefix6(netdissect_options *ndo,
1181 const u_char *pptr, char *buf, u_int buflen)
1182 {
1183 struct in6_addr addr;
1184 u_int plen;
1185
1186 ND_TCHECK(pptr[0]);
1187 plen = pptr[0]; /* get prefix length */
1188
1189 if ((24+64) > plen)
1190 return -1;
1191
1192 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1193
1194 if (128 < plen)
1195 return -1;
1196
1197 memset(&addr, 0, sizeof(addr));
1198 ND_TCHECK2(pptr[12], (plen + 7) / 8);
1199 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1200 if (plen % 8) {
1201 addr.s6_addr[(plen + 7) / 8 - 1] &=
1202 ((0xff00 >> (plen % 8)) & 0xff);
1203 }
1204 /* the label may get offsetted by 4 bits so lets shift it right */
1205 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
1206 bgp_vpn_rd_print(ndo, pptr+4),
1207 ip6addr_string(ndo, &addr),
1208 plen,
1209 EXTRACT_24BITS(pptr+1)>>4,
1210 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1211
1212 return 12 + (plen + 7) / 8;
1213
1214 trunc:
1215 return -2;
1216 }
1217
1218 static int
1219 decode_clnp_prefix(netdissect_options *ndo,
1220 const u_char *pptr, char *buf, u_int buflen)
1221 {
1222 uint8_t addr[19];
1223 u_int plen;
1224
1225 ND_TCHECK(pptr[0]);
1226 plen = pptr[0]; /* get prefix length */
1227
1228 if (152 < plen)
1229 return -1;
1230
1231 memset(&addr, 0, sizeof(addr));
1232 ND_TCHECK2(pptr[4], (plen + 7) / 8);
1233 memcpy(&addr, &pptr[4], (plen + 7) / 8);
1234 if (plen % 8) {
1235 addr[(plen + 7) / 8 - 1] &=
1236 ((0xff00 >> (plen % 8)) & 0xff);
1237 }
1238 snprintf(buf, buflen, "%s/%d",
1239 isonsap_string(ndo, addr,(plen + 7) / 8),
1240 plen);
1241
1242 return 1 + (plen + 7) / 8;
1243
1244 trunc:
1245 return -2;
1246 }
1247
1248 static int
1249 decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
1250 const u_char *pptr, char *buf, u_int buflen)
1251 {
1252 uint8_t addr[19];
1253 u_int plen;
1254
1255 ND_TCHECK(pptr[0]);
1256 plen = pptr[0]; /* get prefix length */
1257
1258 if ((24+64) > plen)
1259 return -1;
1260
1261 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1262
1263 if (152 < plen)
1264 return -1;
1265
1266 memset(&addr, 0, sizeof(addr));
1267 ND_TCHECK2(pptr[12], (plen + 7) / 8);
1268 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1269 if (plen % 8) {
1270 addr[(plen + 7) / 8 - 1] &=
1271 ((0xff00 >> (plen % 8)) & 0xff);
1272 }
1273 /* the label may get offsetted by 4 bits so lets shift it right */
1274 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
1275 bgp_vpn_rd_print(ndo, pptr+4),
1276 isonsap_string(ndo, addr,(plen + 7) / 8),
1277 plen,
1278 EXTRACT_24BITS(pptr+1)>>4,
1279 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1280
1281 return 12 + (plen + 7) / 8;
1282
1283 trunc:
1284 return -2;
1285 }
1286
1287 /*
1288 * bgp_attr_get_as_size
1289 *
1290 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1291 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1292 * support, exchange AS-Path with the same path-attribute type value 0x02.
1293 */
1294 static int
1295 bgp_attr_get_as_size(netdissect_options *ndo,
1296 uint8_t bgpa_type, const u_char *pptr, int len)
1297 {
1298 const u_char *tptr = pptr;
1299
1300 /*
1301 * If the path attribute is the optional AS4 path type, then we already
1302 * know, that ASs must be encoded in 4 byte format.
1303 */
1304 if (bgpa_type == BGPTYPE_AS4_PATH) {
1305 return 4;
1306 }
1307
1308 /*
1309 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1310 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1311 * each.
1312 */
1313 while (tptr < pptr + len) {
1314 ND_TCHECK(tptr[0]);
1315
1316 /*
1317 * If we do not find a valid segment type, our guess might be wrong.
1318 */
1319 if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) {
1320 goto trunc;
1321 }
1322 ND_TCHECK(tptr[1]);
1323 tptr += 2 + tptr[1] * 2;
1324 }
1325
1326 /*
1327 * If we correctly reached end of the AS path attribute data content,
1328 * then most likely ASs were indeed encoded as 2 bytes.
1329 */
1330 if (tptr == pptr + len) {
1331 return 2;
1332 }
1333
1334 trunc:
1335
1336 /*
1337 * We can come here, either we did not have enough data, or if we
1338 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1339 * so that calller can try to decode each AS as of 4 bytes. If indeed
1340 * there was not enough data, it will crib and end the parse anyways.
1341 */
1342 return 4;
1343 }
1344
1345 static int
1346 bgp_attr_print(netdissect_options *ndo,
1347 u_int atype, const u_char *pptr, u_int len)
1348 {
1349 int i;
1350 uint16_t af;
1351 uint8_t safi, snpa, nhlen;
1352 union { /* copy buffer for bandwidth values */
1353 float f;
1354 uint32_t i;
1355 } bw;
1356 int advance;
1357 u_int tlen;
1358 const u_char *tptr;
1359 char buf[MAXHOSTNAMELEN + 100];
1360 int as_size;
1361
1362 tptr = pptr;
1363 tlen=len;
1364
1365 switch (atype) {
1366 case BGPTYPE_ORIGIN:
1367 if (len != 1)
1368 ND_PRINT((ndo, "invalid len"));
1369 else {
1370 ND_TCHECK(*tptr);
1371 ND_PRINT((ndo, "%s", tok2str(bgp_origin_values,
1372 "Unknown Origin Typecode",
1373 tptr[0])));
1374 }
1375 break;
1376
1377
1378 /*
1379 * Process AS4 byte path and AS2 byte path attributes here.
1380 */
1381 case BGPTYPE_AS4_PATH:
1382 case BGPTYPE_AS_PATH:
1383 if (len % 2) {
1384 ND_PRINT((ndo, "invalid len"));
1385 break;
1386 }
1387 if (!len) {
1388 ND_PRINT((ndo, "empty"));
1389 break;
1390 }
1391
1392 /*
1393 * BGP updates exchanged between New speakers that support 4
1394 * byte AS, ASs are always encoded in 4 bytes. There is no
1395 * definitive way to find this, just by the packet's
1396 * contents. So, check for packet's TLV's sanity assuming
1397 * 2 bytes first, and it does not pass, assume that ASs are
1398 * encoded in 4 bytes format and move on.
1399 */
1400 as_size = bgp_attr_get_as_size(ndo, atype, pptr, len);
1401
1402 while (tptr < pptr + len) {
1403 ND_TCHECK(tptr[0]);
1404 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_open_values,
1405 "?", tptr[0])));
1406 for (i = 0; i < tptr[1] * as_size; i += as_size) {
1407 ND_TCHECK2(tptr[2 + i], as_size);
1408 ND_PRINT((ndo, "%s ",
1409 as_printf(ndo, astostr, sizeof(astostr),
1410 as_size == 2 ?
1411 EXTRACT_16BITS(&tptr[2 + i]) :
1412 EXTRACT_32BITS(&tptr[2 + i]))));
1413 }
1414 ND_TCHECK(tptr[0]);
1415 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_close_values,
1416 "?", tptr[0])));
1417 ND_TCHECK(tptr[1]);
1418 tptr += 2 + tptr[1] * as_size;
1419 }
1420 break;
1421 case BGPTYPE_NEXT_HOP:
1422 if (len != 4)
1423 ND_PRINT((ndo, "invalid len"));
1424 else {
1425 ND_TCHECK2(tptr[0], 4);
1426 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
1427 }
1428 break;
1429 case BGPTYPE_MULTI_EXIT_DISC:
1430 case BGPTYPE_LOCAL_PREF:
1431 if (len != 4)
1432 ND_PRINT((ndo, "invalid len"));
1433 else {
1434 ND_TCHECK2(tptr[0], 4);
1435 ND_PRINT((ndo, "%u", EXTRACT_32BITS(tptr)));
1436 }
1437 break;
1438 case BGPTYPE_ATOMIC_AGGREGATE:
1439 if (len != 0)
1440 ND_PRINT((ndo, "invalid len"));
1441 break;
1442 case BGPTYPE_AGGREGATOR:
1443
1444 /*
1445 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1446 * the length of this PA can be either 6 bytes or 8 bytes.
1447 */
1448 if (len != 6 && len != 8) {
1449 ND_PRINT((ndo, "invalid len"));
1450 break;
1451 }
1452 ND_TCHECK2(tptr[0], len);
1453 if (len == 6) {
1454 ND_PRINT((ndo, " AS #%s, origin %s",
1455 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_16BITS(tptr)),
1456 ipaddr_string(ndo, tptr + 2)));
1457 } else {
1458 ND_PRINT((ndo, " AS #%s, origin %s",
1459 as_printf(ndo, astostr, sizeof(astostr),
1460 EXTRACT_32BITS(tptr)), ipaddr_string(ndo, tptr + 4)));
1461 }
1462 break;
1463 case BGPTYPE_AGGREGATOR4:
1464 if (len != 8) {
1465 ND_PRINT((ndo, "invalid len"));
1466 break;
1467 }
1468 ND_TCHECK2(tptr[0], 8);
1469 ND_PRINT((ndo, " AS #%s, origin %s",
1470 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)),
1471 ipaddr_string(ndo, tptr + 4)));
1472 break;
1473 case BGPTYPE_COMMUNITIES:
1474 if (len % 4) {
1475 ND_PRINT((ndo, "invalid len"));
1476 break;
1477 }
1478 while (tlen>0) {
1479 uint32_t comm;
1480 ND_TCHECK2(tptr[0], 4);
1481 comm = EXTRACT_32BITS(tptr);
1482 switch (comm) {
1483 case BGP_COMMUNITY_NO_EXPORT:
1484 ND_PRINT((ndo, " NO_EXPORT"));
1485 break;
1486 case BGP_COMMUNITY_NO_ADVERT:
1487 ND_PRINT((ndo, " NO_ADVERTISE"));
1488 break;
1489 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
1490 ND_PRINT((ndo, " NO_EXPORT_SUBCONFED"));
1491 break;
1492 default:
1493 ND_PRINT((ndo, "%u:%u%s",
1494 (comm >> 16) & 0xffff,
1495 comm & 0xffff,
1496 (tlen>4) ? ", " : ""));
1497 break;
1498 }
1499 tlen -=4;
1500 tptr +=4;
1501 }
1502 break;
1503 case BGPTYPE_ORIGINATOR_ID:
1504 if (len != 4) {
1505 ND_PRINT((ndo, "invalid len"));
1506 break;
1507 }
1508 ND_TCHECK2(tptr[0], 4);
1509 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
1510 break;
1511 case BGPTYPE_CLUSTER_LIST:
1512 if (len % 4) {
1513 ND_PRINT((ndo, "invalid len"));
1514 break;
1515 }
1516 while (tlen>0) {
1517 ND_TCHECK2(tptr[0], 4);
1518 ND_PRINT((ndo, "%s%s",
1519 ipaddr_string(ndo, tptr),
1520 (tlen>4) ? ", " : ""));
1521 tlen -=4;
1522 tptr +=4;
1523 }
1524 break;
1525 case BGPTYPE_MP_REACH_NLRI:
1526 ND_TCHECK2(tptr[0], 3);
1527 af = EXTRACT_16BITS(tptr);
1528 safi = tptr[2];
1529
1530 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1531 tok2str(af_values, "Unknown AFI", af),
1532 af,
1533 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1534 tok2str(bgp_safi_values, "Unknown SAFI", safi),
1535 safi));
1536
1537 switch(af<<8 | safi) {
1538 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1539 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1540 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1541 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1542 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1543 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1544 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1545 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1546 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1547 case (AFNUM_INET<<8 | SAFNUM_MDT):
1548 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1549 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1550 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1551 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1552 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1553 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1554 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1555 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1556 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1557 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1558 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1559 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1560 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1561 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1562 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1563 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1564 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1565 break;
1566 default:
1567 ND_TCHECK2(tptr[0], tlen);
1568 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1569 if (ndo->ndo_vflag <= 1)
1570 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1571 goto done;
1572 break;
1573 }
1574
1575 tptr +=3;
1576
1577 ND_TCHECK(tptr[0]);
1578 nhlen = tptr[0];
1579 tlen = nhlen;
1580 tptr++;
1581
1582 if (tlen) {
1583 int nnh = 0;
1584 ND_PRINT((ndo, "\n\t nexthop: "));
1585 while (tlen > 0) {
1586 if ( nnh++ > 0 ) {
1587 ND_PRINT((ndo, ", " ));
1588 }
1589 switch(af<<8 | safi) {
1590 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1591 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1592 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1593 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1594 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1595 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1596 case (AFNUM_INET<<8 | SAFNUM_MDT):
1597 if (tlen < (int)sizeof(struct in_addr)) {
1598 ND_PRINT((ndo, "invalid len"));
1599 tlen = 0;
1600 } else {
1601 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
1602 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
1603 tlen -= sizeof(struct in_addr);
1604 tptr += sizeof(struct in_addr);
1605 }
1606 break;
1607 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1608 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1609 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1610 if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) {
1611 ND_PRINT((ndo, "invalid len"));
1612 tlen = 0;
1613 } else {
1614 ND_TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1615 ND_PRINT((ndo, "RD: %s, %s",
1616 bgp_vpn_rd_print(ndo, tptr),
1617 ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN)));
1618 tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1619 tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1620 }
1621 break;
1622 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1623 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1624 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1625 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1626 if (tlen < (int)sizeof(struct in6_addr)) {
1627 ND_PRINT((ndo, "invalid len"));
1628 tlen = 0;
1629 } else {
1630 ND_TCHECK2(tptr[0], sizeof(struct in6_addr));
1631 ND_PRINT((ndo, "%s", ip6addr_string(ndo, tptr)));
1632 tlen -= sizeof(struct in6_addr);
1633 tptr += sizeof(struct in6_addr);
1634 }
1635 break;
1636 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1637 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1638 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1639 if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) {
1640 ND_PRINT((ndo, "invalid len"));
1641 tlen = 0;
1642 } else {
1643 ND_TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1644 ND_PRINT((ndo, "RD: %s, %s",
1645 bgp_vpn_rd_print(ndo, tptr),
1646 ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN)));
1647 tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1648 tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1649 }
1650 break;
1651 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1652 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1653 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1654 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1655 if (tlen < (int)sizeof(struct in_addr)) {
1656 ND_PRINT((ndo, "invalid len"));
1657 tlen = 0;
1658 } else {
1659 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
1660 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
1661 tlen -= (sizeof(struct in_addr));
1662 tptr += (sizeof(struct in_addr));
1663 }
1664 break;
1665 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1666 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1667 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1668 ND_TCHECK2(tptr[0], tlen);
1669 ND_PRINT((ndo, "%s", isonsap_string(ndo, tptr, tlen)));
1670 tptr += tlen;
1671 tlen = 0;
1672 break;
1673
1674 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1675 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1676 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1677 if (tlen < BGP_VPN_RD_LEN+1) {
1678 ND_PRINT((ndo, "invalid len"));
1679 tlen = 0;
1680 } else {
1681 ND_TCHECK2(tptr[0], tlen);
1682 ND_PRINT((ndo, "RD: %s, %s",
1683 bgp_vpn_rd_print(ndo, tptr),
1684 isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)));
1685 /* rfc986 mapped IPv4 address ? */
1686 if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601)
1687 ND_PRINT((ndo, " = %s", ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN+4)));
1688 /* rfc1888 mapped IPv6 address ? */
1689 else if (EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000)
1690 ND_PRINT((ndo, " = %s", ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN+3)));
1691 tptr += tlen;
1692 tlen = 0;
1693 }
1694 break;
1695 default:
1696 ND_TCHECK2(tptr[0], tlen);
1697 ND_PRINT((ndo, "no AFI %u/SAFI %u decoder", af, safi));
1698 if (ndo->ndo_vflag <= 1)
1699 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1700 tptr += tlen;
1701 tlen = 0;
1702 goto done;
1703 break;
1704 }
1705 }
1706 }
1707 ND_PRINT((ndo, ", nh-length: %u", nhlen));
1708 tptr += tlen;
1709
1710 ND_TCHECK(tptr[0]);
1711 snpa = tptr[0];
1712 tptr++;
1713
1714 if (snpa) {
1715 ND_PRINT((ndo, "\n\t %u SNPA", snpa));
1716 for (/*nothing*/; snpa > 0; snpa--) {
1717 ND_TCHECK(tptr[0]);
1718 ND_PRINT((ndo, "\n\t %d bytes", tptr[0]));
1719 tptr += tptr[0] + 1;
1720 }
1721 } else {
1722 ND_PRINT((ndo, ", no SNPA"));
1723 }
1724
1725 while (len - (tptr - pptr) > 0) {
1726 switch (af<<8 | safi) {
1727 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1728 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1729 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1730 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
1731 if (advance == -1)
1732 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1733 else if (advance == -2)
1734 goto trunc;
1735 else if (advance == -3)
1736 break; /* bytes left, but not enough */
1737 else
1738 ND_PRINT((ndo, "\n\t %s", buf));
1739 break;
1740 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1741 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
1742 if (advance == -1)
1743 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1744 else if (advance == -2)
1745 goto trunc;
1746 else if (advance == -3)
1747 break; /* bytes left, but not enough */
1748 else
1749 ND_PRINT((ndo, "\n\t %s", buf));
1750 break;
1751 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1752 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1753 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1754 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
1755 if (advance == -1)
1756 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1757 else if (advance == -2)
1758 goto trunc;
1759 else
1760 ND_PRINT((ndo, "\n\t %s", buf));
1761 break;
1762 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1763 advance = decode_rt_routing_info(ndo, tptr, buf, sizeof(buf));
1764 if (advance == -1)
1765 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1766 else if (advance == -2)
1767 goto trunc;
1768 else
1769 ND_PRINT((ndo, "\n\t %s", buf));
1770 break;
1771 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
1772 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
1773 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
1774 if (advance == -1)
1775 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1776 else if (advance == -2)
1777 goto trunc;
1778 else
1779 ND_PRINT((ndo, "\n\t %s", buf));
1780 break;
1781
1782 case (AFNUM_INET<<8 | SAFNUM_MDT):
1783 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
1784 if (advance == -1)
1785 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1786 else if (advance == -2)
1787 goto trunc;
1788 else
1789 ND_PRINT((ndo, "\n\t %s", buf));
1790 break;
1791 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1792 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1793 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1794 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
1795 if (advance == -1)
1796 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1797 else if (advance == -2)
1798 goto trunc;
1799 else if (advance == -3)
1800 break; /* bytes left, but not enough */
1801 else
1802 ND_PRINT((ndo, "\n\t %s", buf));
1803 break;
1804 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1805 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
1806 if (advance == -1)
1807 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1808 else if (advance == -2)
1809 goto trunc;
1810 else if (advance == -3)
1811 break; /* bytes left, but not enough */
1812 else
1813 ND_PRINT((ndo, "\n\t %s", buf));
1814 break;
1815 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1816 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1817 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1818 advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf));
1819 if (advance == -1)
1820 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1821 else if (advance == -2)
1822 goto trunc;
1823 else
1824 ND_PRINT((ndo, "\n\t %s", buf));
1825 break;
1826 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1827 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1828 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1829 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1830 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
1831 if (advance == -1)
1832 ND_PRINT((ndo, "\n\t (illegal length)"));
1833 else if (advance == -2)
1834 goto trunc;
1835 else
1836 ND_PRINT((ndo, "\n\t %s", buf));
1837 break;
1838 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1839 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1840 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1841 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1842 if (advance == -1)
1843 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1844 else if (advance == -2)
1845 goto trunc;
1846 else
1847 ND_PRINT((ndo, "\n\t %s", buf));
1848 break;
1849 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1850 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1851 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1852 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1853 if (advance == -1)
1854 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1855 else if (advance == -2)
1856 goto trunc;
1857 else
1858 ND_PRINT((ndo, "\n\t %s", buf));
1859 break;
1860 default:
1861 ND_TCHECK2(*tptr,tlen);
1862 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1863 if (ndo->ndo_vflag <= 1)
1864 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1865 advance = 0;
1866 tptr = pptr + len;
1867 break;
1868 }
1869 if (advance < 0)
1870 break;
1871 tptr += advance;
1872 }
1873 done:
1874 break;
1875
1876 case BGPTYPE_MP_UNREACH_NLRI:
1877 ND_TCHECK2(tptr[0], BGP_MP_NLRI_MINSIZE);
1878 af = EXTRACT_16BITS(tptr);
1879 safi = tptr[2];
1880
1881 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1882 tok2str(af_values, "Unknown AFI", af),
1883 af,
1884 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1885 tok2str(bgp_safi_values, "Unknown SAFI", safi),
1886 safi));
1887
1888 if (len == BGP_MP_NLRI_MINSIZE)
1889 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
1890
1891 tptr += 3;
1892
1893 while (len - (tptr - pptr) > 0) {
1894 switch (af<<8 | safi) {
1895 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1896 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1897 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1898 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
1899 if (advance == -1)
1900 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1901 else if (advance == -2)
1902 goto trunc;
1903 else if (advance == -3)
1904 break; /* bytes left, but not enough */
1905 else
1906 ND_PRINT((ndo, "\n\t %s", buf));
1907 break;
1908 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1909 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
1910 if (advance == -1)
1911 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1912 else if (advance == -2)
1913 goto trunc;
1914 else if (advance == -3)
1915 break; /* bytes left, but not enough */
1916 else
1917 ND_PRINT((ndo, "\n\t %s", buf));
1918 break;
1919 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1920 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1921 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1922 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
1923 if (advance == -1)
1924 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1925 else if (advance == -2)
1926 goto trunc;
1927 else
1928 ND_PRINT((ndo, "\n\t %s", buf));
1929 break;
1930 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1931 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1932 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1933 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
1934 if (advance == -1)
1935 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1936 else if (advance == -2)
1937 goto trunc;
1938 else if (advance == -3)
1939 break; /* bytes left, but not enough */
1940 else
1941 ND_PRINT((ndo, "\n\t %s", buf));
1942 break;
1943 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1944 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
1945 if (advance == -1)
1946 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1947 else if (advance == -2)
1948 goto trunc;
1949 else if (advance == -3)
1950 break; /* bytes left, but not enough */
1951 else
1952 ND_PRINT((ndo, "\n\t %s", buf));
1953 break;
1954 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1955 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1956 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1957 advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf));
1958 if (advance == -1)
1959 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1960 else if (advance == -2)
1961 goto trunc;
1962 else
1963 ND_PRINT((ndo, "\n\t %s", buf));
1964 break;
1965 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1966 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1967 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1968 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1969 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
1970 if (advance == -1)
1971 ND_PRINT((ndo, "\n\t (illegal length)"));
1972 else if (advance == -2)
1973 goto trunc;
1974 else
1975 ND_PRINT((ndo, "\n\t %s", buf));
1976 break;
1977 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1978 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1979 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1980 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1981 if (advance == -1)
1982 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1983 else if (advance == -2)
1984 goto trunc;
1985 else
1986 ND_PRINT((ndo, "\n\t %s", buf));
1987 break;
1988 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1989 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1990 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1991 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1992 if (advance == -1)
1993 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1994 else if (advance == -2)
1995 goto trunc;
1996 else
1997 ND_PRINT((ndo, "\n\t %s", buf));
1998 break;
1999 case (AFNUM_INET<<8 | SAFNUM_MDT):
2000 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
2001 if (advance == -1)
2002 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2003 else if (advance == -2)
2004 goto trunc;
2005 else
2006 ND_PRINT((ndo, "\n\t %s", buf));
2007 break;
2008 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
2009 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
2010 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
2011 if (advance == -1)
2012 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2013 else if (advance == -2)
2014 goto trunc;
2015 else
2016 ND_PRINT((ndo, "\n\t %s", buf));
2017 break;
2018 default:
2019 ND_TCHECK2(*(tptr-3),tlen);
2020 ND_PRINT((ndo, "no AFI %u / SAFI %u decoder", af, safi));
2021 if (ndo->ndo_vflag <= 1)
2022 print_unknown_data(ndo, tptr-3, "\n\t ", tlen);
2023 advance = 0;
2024 tptr = pptr + len;
2025 break;
2026 }
2027 if (advance < 0)
2028 break;
2029 tptr += advance;
2030 }
2031 break;
2032 case BGPTYPE_EXTD_COMMUNITIES:
2033 if (len % 8) {
2034 ND_PRINT((ndo, "invalid len"));
2035 break;
2036 }
2037 while (tlen>0) {
2038 uint16_t extd_comm;
2039
2040 ND_TCHECK2(tptr[0], 2);
2041 extd_comm=EXTRACT_16BITS(tptr);
2042
2043 ND_PRINT((ndo, "\n\t %s (0x%04x), Flags [%s]",
2044 tok2str(bgp_extd_comm_subtype_values,
2045 "unknown extd community typecode",
2046 extd_comm),
2047 extd_comm,
2048 bittok2str(bgp_extd_comm_flag_values, "none", extd_comm)));
2049
2050 ND_TCHECK2(*(tptr+2), 6);
2051 switch(extd_comm) {
2052 case BGP_EXT_COM_RT_0:
2053 case BGP_EXT_COM_RO_0:
2054 case BGP_EXT_COM_L2VPN_RT_0:
2055 ND_PRINT((ndo, ": %u:%u (= %s)",
2056 EXTRACT_16BITS(tptr+2),
2057 EXTRACT_32BITS(tptr+4),
2058 ipaddr_string(ndo, tptr+4)));
2059 break;
2060 case BGP_EXT_COM_RT_1:
2061 case BGP_EXT_COM_RO_1:
2062 case BGP_EXT_COM_L2VPN_RT_1:
2063 case BGP_EXT_COM_VRF_RT_IMP:
2064 ND_PRINT((ndo, ": %s:%u",
2065 ipaddr_string(ndo, tptr+2),
2066 EXTRACT_16BITS(tptr+6)));
2067 break;
2068 case BGP_EXT_COM_RT_2:
2069 case BGP_EXT_COM_RO_2:
2070 ND_PRINT((ndo, ": %s:%u",
2071 as_printf(ndo, astostr, sizeof(astostr),
2072 EXTRACT_32BITS(tptr+2)), EXTRACT_16BITS(tptr+6)));
2073 break;
2074 case BGP_EXT_COM_LINKBAND:
2075 bw.i = EXTRACT_32BITS(tptr+2);
2076 ND_PRINT((ndo, ": bandwidth: %.3f Mbps",
2077 bw.f*8/1000000));
2078 break;
2079 case BGP_EXT_COM_VPN_ORIGIN:
2080 case BGP_EXT_COM_VPN_ORIGIN2:
2081 case BGP_EXT_COM_VPN_ORIGIN3:
2082 case BGP_EXT_COM_VPN_ORIGIN4:
2083 case BGP_EXT_COM_OSPF_RID:
2084 case BGP_EXT_COM_OSPF_RID2:
2085 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr+2)));
2086 break;
2087 case BGP_EXT_COM_OSPF_RTYPE:
2088 case BGP_EXT_COM_OSPF_RTYPE2:
2089 ND_PRINT((ndo, ": area:%s, router-type:%s, metric-type:%s%s",
2090 ipaddr_string(ndo, tptr+2),
2091 tok2str(bgp_extd_comm_ospf_rtype_values,
2092 "unknown (0x%02x)",
2093 *(tptr+6)),
2094 (*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
2095 ((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : ""));
2096 break;
2097 case BGP_EXT_COM_L2INFO:
2098 ND_PRINT((ndo, ": %s Control Flags [0x%02x]:MTU %u",
2099 tok2str(l2vpn_encaps_values,
2100 "unknown encaps",
2101 *(tptr+2)),
2102 *(tptr+3),
2103 EXTRACT_16BITS(tptr+4)));
2104 break;
2105 case BGP_EXT_COM_SOURCE_AS:
2106 ND_PRINT((ndo, ": AS %u", EXTRACT_16BITS(tptr+2)));
2107 break;
2108 default:
2109 ND_TCHECK2(*tptr,8);
2110 print_unknown_data(ndo, tptr, "\n\t ", 8);
2111 break;
2112 }
2113 tlen -=8;
2114 tptr +=8;
2115 }
2116 break;
2117
2118 case BGPTYPE_PMSI_TUNNEL:
2119 {
2120 uint8_t tunnel_type, flags;
2121
2122 tunnel_type = *(tptr+1);
2123 flags = *tptr;
2124 tlen = len;
2125
2126 ND_TCHECK2(tptr[0], 5);
2127 ND_PRINT((ndo, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2128 tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type),
2129 tunnel_type,
2130 bittok2str(bgp_pmsi_flag_values, "none", flags),
2131 EXTRACT_24BITS(tptr+2)>>4));
2132
2133 tptr +=5;
2134 tlen -= 5;
2135
2136 switch (tunnel_type) {
2137 case BGP_PMSI_TUNNEL_PIM_SM: /* fall through */
2138 case BGP_PMSI_TUNNEL_PIM_BIDIR:
2139 ND_TCHECK2(tptr[0], 8);
2140 ND_PRINT((ndo, "\n\t Sender %s, P-Group %s",
2141 ipaddr_string(ndo, tptr),
2142 ipaddr_string(ndo, tptr+4)));
2143 break;
2144
2145 case BGP_PMSI_TUNNEL_PIM_SSM:
2146 ND_TCHECK2(tptr[0], 8);
2147 ND_PRINT((ndo, "\n\t Root-Node %s, P-Group %s",
2148 ipaddr_string(ndo, tptr),
2149 ipaddr_string(ndo, tptr+4)));
2150 break;
2151 case BGP_PMSI_TUNNEL_INGRESS:
2152 ND_TCHECK2(tptr[0], 4);
2153 ND_PRINT((ndo, "\n\t Tunnel-Endpoint %s",
2154 ipaddr_string(ndo, tptr)));
2155 break;
2156 case BGP_PMSI_TUNNEL_LDP_P2MP: /* fall through */
2157 case BGP_PMSI_TUNNEL_LDP_MP2MP:
2158 ND_TCHECK2(tptr[0], 8);
2159 ND_PRINT((ndo, "\n\t Root-Node %s, LSP-ID 0x%08x",
2160 ipaddr_string(ndo, tptr),
2161 EXTRACT_32BITS(tptr+4)));
2162 break;
2163 case BGP_PMSI_TUNNEL_RSVP_P2MP:
2164 ND_TCHECK2(tptr[0], 8);
2165 ND_PRINT((ndo, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2166 ipaddr_string(ndo, tptr),
2167 EXTRACT_32BITS(tptr+4)));
2168 break;
2169 default:
2170 if (ndo->ndo_vflag <= 1) {
2171 print_unknown_data(ndo, tptr, "\n\t ", tlen);
2172 }
2173 }
2174 break;
2175 }
2176 case BGPTYPE_AIGP:
2177 {
2178 uint8_t type;
2179 uint16_t length;
2180
2181 ND_TCHECK2(tptr[0], 3);
2182
2183 tlen = len;
2184
2185 while (tlen >= 3) {
2186
2187 type = *tptr;
2188 length = EXTRACT_16BITS(tptr+1);
2189
2190 ND_PRINT((ndo, "\n\t %s TLV (%u), length %u",
2191 tok2str(bgp_aigp_values, "Unknown", type),
2192 type, length));
2193
2194
2195 /*
2196 * Check if we can read the TLV data.
2197 */
2198 ND_TCHECK2(tptr[3], length - 3);
2199
2200 switch (type) {
2201
2202 case BGP_AIGP_TLV:
2203 ND_TCHECK2(tptr[3], 8);
2204 ND_PRINT((ndo, ", metric %" PRIu64,
2205 EXTRACT_64BITS(tptr+3)));
2206 break;
2207
2208 default:
2209 if (ndo->ndo_vflag <= 1) {
2210 print_unknown_data(ndo, tptr+3,"\n\t ", length-3);
2211 }
2212 }
2213
2214 tptr += length;
2215 tlen -= length;
2216 }
2217 break;
2218 }
2219 case BGPTYPE_ATTR_SET:
2220 ND_TCHECK2(tptr[0], 4);
2221 if (len < 4)
2222 goto trunc;
2223 ND_PRINT((ndo, "\n\t Origin AS: %s",
2224 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr))));
2225 tptr+=4;
2226 len -=4;
2227
2228 while (len) {
2229 u_int aflags, alenlen, alen;
2230
2231 ND_TCHECK2(tptr[0], 2);
2232 if (len < 2)
2233 goto trunc;
2234 aflags = *tptr;
2235 atype = *(tptr + 1);
2236 tptr += 2;
2237 len -= 2;
2238 alenlen = bgp_attr_lenlen(aflags, tptr);
2239 ND_TCHECK2(tptr[0], alenlen);
2240 if (len < alenlen)
2241 goto trunc;
2242 alen = bgp_attr_len(aflags, tptr);
2243 tptr += alenlen;
2244 len -= alenlen;
2245
2246 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2247 tok2str(bgp_attr_values,
2248 "Unknown Attribute", atype),
2249 atype,
2250 alen));
2251
2252 if (aflags) {
2253 ND_PRINT((ndo, ", Flags [%s%s%s%s",
2254 aflags & 0x80 ? "O" : "",
2255 aflags & 0x40 ? "T" : "",
2256 aflags & 0x20 ? "P" : "",
2257 aflags & 0x10 ? "E" : ""));
2258 if (aflags & 0xf)
2259 ND_PRINT((ndo, "+%x", aflags & 0xf));
2260 ND_PRINT((ndo, "]: "));
2261 }
2262 /* FIXME check for recursion */
2263 if (!bgp_attr_print(ndo, atype, tptr, alen))
2264 return 0;
2265 tptr += alen;
2266 len -= alen;
2267 }
2268 break;
2269
2270
2271 default:
2272 ND_TCHECK2(*pptr,len);
2273 ND_PRINT((ndo, "\n\t no Attribute %u decoder", atype)); /* we have no decoder for the attribute */
2274 if (ndo->ndo_vflag <= 1)
2275 print_unknown_data(ndo, pptr, "\n\t ", len);
2276 break;
2277 }
2278 if (ndo->ndo_vflag > 1 && len) { /* omit zero length attributes*/
2279 ND_TCHECK2(*pptr,len);
2280 print_unknown_data(ndo, pptr, "\n\t ", len);
2281 }
2282 return 1;
2283
2284 trunc:
2285 return 0;
2286 }
2287
2288 static void
2289 bgp_capabilities_print(netdissect_options *ndo,
2290 const u_char *opt, int caps_len)
2291 {
2292 int cap_type, cap_len, tcap_len, cap_offset;
2293 int i = 0;
2294
2295 while (i < caps_len) {
2296 ND_TCHECK2(opt[i], BGP_CAP_HEADER_SIZE);
2297 cap_type=opt[i];
2298 cap_len=opt[i+1];
2299 tcap_len=cap_len;
2300 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2301 tok2str(bgp_capcode_values, "Unknown",
2302 cap_type),
2303 cap_type,
2304 cap_len));
2305 ND_TCHECK2(opt[i+2], cap_len);
2306 switch (cap_type) {
2307 case BGP_CAPCODE_MP:
2308 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2309 tok2str(af_values, "Unknown",
2310 EXTRACT_16BITS(opt+i+2)),
2311 EXTRACT_16BITS(opt+i+2),
2312 tok2str(bgp_safi_values, "Unknown",
2313 opt[i+5]),
2314 opt[i+5]));
2315 break;
2316 case BGP_CAPCODE_RESTART:
2317 ND_PRINT((ndo, "\n\t\tRestart Flags: [%s], Restart Time %us",
2318 ((opt[i+2])&0x80) ? "R" : "none",
2319 EXTRACT_16BITS(opt+i+2)&0xfff));
2320 tcap_len-=2;
2321 cap_offset=4;
2322 while(tcap_len>=4) {
2323 ND_PRINT((ndo, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2324 tok2str(af_values,"Unknown",
2325 EXTRACT_16BITS(opt+i+cap_offset)),
2326 EXTRACT_16BITS(opt+i+cap_offset),
2327 tok2str(bgp_safi_values,"Unknown",
2328 opt[i+cap_offset+2]),
2329 opt[i+cap_offset+2],
2330 ((opt[i+cap_offset+3])&0x80) ? "yes" : "no" ));
2331 tcap_len-=4;
2332 cap_offset+=4;
2333 }
2334 break;
2335 case BGP_CAPCODE_RR:
2336 case BGP_CAPCODE_RR_CISCO:
2337 break;
2338 case BGP_CAPCODE_AS_NEW:
2339
2340 /*
2341 * Extract the 4 byte AS number encoded.
2342 */
2343 if (cap_len == 4) {
2344 ND_PRINT((ndo, "\n\t\t 4 Byte AS %s",
2345 as_printf(ndo, astostr, sizeof(astostr),
2346 EXTRACT_32BITS(opt + i + 2))));
2347 }
2348 break;
2349 case BGP_CAPCODE_ADD_PATH:
2350 cap_offset=2;
2351 if (tcap_len == 0) {
2352 ND_PRINT((ndo, " (bogus)")); /* length */
2353 break;
2354 }
2355 while (tcap_len > 0) {
2356 if (tcap_len < 4) {
2357 ND_PRINT((ndo, "\n\t\t(invalid)"));
2358 break;
2359 }
2360 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2361 tok2str(af_values,"Unknown",EXTRACT_16BITS(opt+i+cap_offset)),
2362 EXTRACT_16BITS(opt+i+cap_offset),
2363 tok2str(bgp_safi_values,"Unknown",opt[i+cap_offset+2]),
2364 opt[i+cap_offset+2],
2365 tok2str(bgp_add_path_recvsend,"Bogus (0x%02x)",opt[i+cap_offset+3])
2366 ));
2367 tcap_len-=4;
2368 cap_offset+=4;
2369 }
2370 break;
2371 default:
2372 ND_PRINT((ndo, "\n\t\tno decoder for Capability %u",
2373 cap_type));
2374 if (ndo->ndo_vflag <= 1)
2375 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
2376 break;
2377 }
2378 if (ndo->ndo_vflag > 1 && cap_len > 0) {
2379 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
2380 }
2381 i += BGP_CAP_HEADER_SIZE + cap_len;
2382 }
2383 return;
2384
2385 trunc:
2386 ND_PRINT((ndo, "[|BGP]"));
2387 }
2388
2389 static void
2390 bgp_open_print(netdissect_options *ndo,
2391 const u_char *dat, int length)
2392 {
2393 struct bgp_open bgpo;
2394 struct bgp_opt bgpopt;
2395 const u_char *opt;
2396 int i;
2397
2398 ND_TCHECK2(dat[0], BGP_OPEN_SIZE);
2399 memcpy(&bgpo, dat, BGP_OPEN_SIZE);
2400
2401 ND_PRINT((ndo, "\n\t Version %d, ", bgpo.bgpo_version));
2402 ND_PRINT((ndo, "my AS %s, ",
2403 as_printf(ndo, astostr, sizeof(astostr), ntohs(bgpo.bgpo_myas))));
2404 ND_PRINT((ndo, "Holdtime %us, ", ntohs(bgpo.bgpo_holdtime)));
2405 ND_PRINT((ndo, "ID %s", ipaddr_string(ndo, &bgpo.bgpo_id)));
2406 ND_PRINT((ndo, "\n\t Optional parameters, length: %u", bgpo.bgpo_optlen));
2407
2408 /* some little sanity checking */
2409 if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE)
2410 return;
2411
2412 /* ugly! */
2413 opt = &((const struct bgp_open *)dat)->bgpo_optlen;
2414 opt++;
2415
2416 i = 0;
2417 while (i < bgpo.bgpo_optlen) {
2418 ND_TCHECK2(opt[i], BGP_OPT_SIZE);
2419 memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE);
2420 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
2421 ND_PRINT((ndo, "\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len));
2422 break;
2423 }
2424
2425 ND_PRINT((ndo, "\n\t Option %s (%u), length: %u",
2426 tok2str(bgp_opt_values,"Unknown",
2427 bgpopt.bgpopt_type),
2428 bgpopt.bgpopt_type,
2429 bgpopt.bgpopt_len));
2430
2431 /* now let's decode the options we know*/
2432 switch(bgpopt.bgpopt_type) {
2433
2434 case BGP_OPT_CAP:
2435 bgp_capabilities_print(ndo, &opt[i+BGP_OPT_SIZE],
2436 bgpopt.bgpopt_len);
2437 break;
2438
2439 case BGP_OPT_AUTH:
2440 default:
2441 ND_PRINT((ndo, "\n\t no decoder for option %u",
2442 bgpopt.bgpopt_type));
2443 break;
2444 }
2445 i += BGP_OPT_SIZE + bgpopt.bgpopt_len;
2446 }
2447 return;
2448 trunc:
2449 ND_PRINT((ndo, "[|BGP]"));
2450 }
2451
2452 static void
2453 bgp_update_print(netdissect_options *ndo,
2454 const u_char *dat, int length)
2455 {
2456 struct bgp bgp;
2457 const u_char *p;
2458 int withdrawn_routes_len;
2459 int len;
2460 int i;
2461
2462 ND_TCHECK2(dat[0], BGP_SIZE);
2463 if (length < BGP_SIZE)
2464 goto trunc;
2465 memcpy(&bgp, dat, BGP_SIZE);
2466 p = dat + BGP_SIZE; /*XXX*/
2467 length -= BGP_SIZE;
2468
2469 /* Unfeasible routes */
2470 ND_TCHECK2(p[0], 2);
2471 if (length < 2)
2472 goto trunc;
2473 withdrawn_routes_len = EXTRACT_16BITS(p);
2474 p += 2;
2475 length -= 2;
2476 if (withdrawn_routes_len) {
2477 /*
2478 * Without keeping state from the original NLRI message,
2479 * it's not possible to tell if this a v4 or v6 route,
2480 * so only try to decode it if we're not v6 enabled.
2481 */
2482 ND_TCHECK2(p[0], withdrawn_routes_len);
2483 if (length < withdrawn_routes_len)
2484 goto trunc;
2485 ND_PRINT((ndo, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len));
2486 p += withdrawn_routes_len;
2487 length -= withdrawn_routes_len;
2488 }
2489
2490 ND_TCHECK2(p[0], 2);
2491 if (length < 2)
2492 goto trunc;
2493 len = EXTRACT_16BITS(p);
2494 p += 2;
2495 length -= 2;
2496
2497 if (withdrawn_routes_len == 0 && len == 0 && length == 0) {
2498 /* No withdrawn routes, no path attributes, no NLRI */
2499 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
2500 return;
2501 }
2502
2503 if (len) {
2504 /* do something more useful!*/
2505 while (len) {
2506 int aflags, atype, alenlen, alen;
2507
2508 ND_TCHECK2(p[0], 2);
2509 if (len < 2)
2510 goto trunc;
2511 if (length < 2)
2512 goto trunc;
2513 aflags = *p;
2514 atype = *(p + 1);
2515 p += 2;
2516 len -= 2;
2517 length -= 2;
2518 alenlen = bgp_attr_lenlen(aflags, p);
2519 ND_TCHECK2(p[0], alenlen);
2520 if (len < alenlen)
2521 goto trunc;
2522 if (length < alenlen)
2523 goto trunc;
2524 alen = bgp_attr_len(aflags, p);
2525 p += alenlen;
2526 len -= alenlen;
2527 length -= alenlen;
2528
2529 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2530 tok2str(bgp_attr_values, "Unknown Attribute",
2531 atype),
2532 atype,
2533 alen));
2534
2535 if (aflags) {
2536 ND_PRINT((ndo, ", Flags [%s%s%s%s",
2537 aflags & 0x80 ? "O" : "",
2538 aflags & 0x40 ? "T" : "",
2539 aflags & 0x20 ? "P" : "",
2540 aflags & 0x10 ? "E" : ""));
2541 if (aflags & 0xf)
2542 ND_PRINT((ndo, "+%x", aflags & 0xf));
2543 ND_PRINT((ndo, "]: "));
2544 }
2545 if (len < alen)
2546 goto trunc;
2547 if (length < alen)
2548 goto trunc;
2549 if (!bgp_attr_print(ndo, atype, p, alen))
2550 goto trunc;
2551 p += alen;
2552 len -= alen;
2553 length -= alen;
2554 }
2555 }
2556
2557 if (length) {
2558 /*
2559 * XXX - what if they're using the "Advertisement of
2560 * Multiple Paths in BGP" feature:
2561 *
2562 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2563 *
2564 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2565 */
2566 ND_PRINT((ndo, "\n\t Updated routes:"));
2567 while (length) {
2568 char buf[MAXHOSTNAMELEN + 100];
2569 i = decode_prefix4(ndo, p, length, buf, sizeof(buf));
2570 if (i == -1) {
2571 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2572 break;
2573 } else if (i == -2)
2574 goto trunc;
2575 else if (i == -3)
2576 goto trunc; /* bytes left, but not enough */
2577 else {
2578 ND_PRINT((ndo, "\n\t %s", buf));
2579 p += i;
2580 length -= i;
2581 }
2582 }
2583 }
2584 return;
2585 trunc:
2586 ND_PRINT((ndo, "[|BGP]"));
2587 }
2588
2589 static void
2590 bgp_notification_print(netdissect_options *ndo,
2591 const u_char *dat, int length)
2592 {
2593 struct bgp_notification bgpn;
2594 const u_char *tptr;
2595
2596 ND_TCHECK2(dat[0], BGP_NOTIFICATION_SIZE);
2597 memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE);
2598
2599 /* some little sanity checking */
2600 if (length<BGP_NOTIFICATION_SIZE)
2601 return;
2602
2603 ND_PRINT((ndo, ", %s (%u)",
2604 tok2str(bgp_notify_major_values, "Unknown Error",
2605 bgpn.bgpn_major),
2606 bgpn.bgpn_major));
2607
2608 switch (bgpn.bgpn_major) {
2609
2610 case BGP_NOTIFY_MAJOR_MSG:
2611 ND_PRINT((ndo, ", subcode %s (%u)",
2612 tok2str(bgp_notify_minor_msg_values, "Unknown",
2613 bgpn.bgpn_minor),
2614 bgpn.bgpn_minor));
2615 break;
2616 case BGP_NOTIFY_MAJOR_OPEN:
2617 ND_PRINT((ndo, ", subcode %s (%u)",
2618 tok2str(bgp_notify_minor_open_values, "Unknown",
2619 bgpn.bgpn_minor),
2620 bgpn.bgpn_minor));
2621 break;
2622 case BGP_NOTIFY_MAJOR_UPDATE:
2623 ND_PRINT((ndo, ", subcode %s (%u)",
2624 tok2str(bgp_notify_minor_update_values, "Unknown",
2625 bgpn.bgpn_minor),
2626 bgpn.bgpn_minor));
2627 break;
2628 case BGP_NOTIFY_MAJOR_FSM:
2629 ND_PRINT((ndo, " subcode %s (%u)",
2630 tok2str(bgp_notify_minor_fsm_values, "Unknown",
2631 bgpn.bgpn_minor),
2632 bgpn.bgpn_minor));
2633 case BGP_NOTIFY_MAJOR_CAP:
2634 ND_PRINT((ndo, " subcode %s (%u)",
2635 tok2str(bgp_notify_minor_cap_values, "Unknown",
2636 bgpn.bgpn_minor),
2637 bgpn.bgpn_minor));
2638 case BGP_NOTIFY_MAJOR_CEASE:
2639 ND_PRINT((ndo, ", subcode %s (%u)",
2640 tok2str(bgp_notify_minor_cease_values, "Unknown",
2641 bgpn.bgpn_minor),
2642 bgpn.bgpn_minor));
2643
2644 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2645 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2646 */
2647 if(bgpn.bgpn_minor == BGP_NOTIFY_MINOR_CEASE_MAXPRFX && length >= BGP_NOTIFICATION_SIZE + 7) {
2648 tptr = dat + BGP_NOTIFICATION_SIZE;
2649 ND_TCHECK2(*tptr, 7);
2650 ND_PRINT((ndo, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2651 tok2str(af_values, "Unknown",
2652 EXTRACT_16BITS(tptr)),
2653 EXTRACT_16BITS(tptr),
2654 tok2str(bgp_safi_values, "Unknown", *(tptr+2)),
2655 *(tptr+2),
2656 EXTRACT_32BITS(tptr+3)));
2657 }
2658 break;
2659 default:
2660 break;
2661 }
2662
2663 return;
2664 trunc:
2665 ND_PRINT((ndo, "[|BGP]"));
2666 }
2667
2668 static void
2669 bgp_route_refresh_print(netdissect_options *ndo,
2670 const u_char *pptr, int len)
2671 {
2672 const struct bgp_route_refresh *bgp_route_refresh_header;
2673
2674 ND_TCHECK2(pptr[0], BGP_ROUTE_REFRESH_SIZE);
2675
2676 /* some little sanity checking */
2677 if (len<BGP_ROUTE_REFRESH_SIZE)
2678 return;
2679
2680 bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
2681
2682 ND_PRINT((ndo, "\n\t AFI %s (%u), SAFI %s (%u)",
2683 tok2str(af_values,"Unknown",
2684 /* this stinks but the compiler pads the structure
2685 * weird */
2686 EXTRACT_16BITS(&bgp_route_refresh_header->afi)),
2687 EXTRACT_16BITS(&bgp_route_refresh_header->afi),
2688 tok2str(bgp_safi_values,"Unknown",
2689 bgp_route_refresh_header->safi),
2690 bgp_route_refresh_header->safi));
2691
2692 if (ndo->ndo_vflag > 1) {
2693 ND_TCHECK2(*pptr, len);
2694 print_unknown_data(ndo, pptr, "\n\t ", len);
2695 }
2696
2697 return;
2698 trunc:
2699 ND_PRINT((ndo, "[|BGP]"));
2700 }
2701
2702 static int
2703 bgp_header_print(netdissect_options *ndo,
2704 const u_char *dat, int length)
2705 {
2706 struct bgp bgp;
2707
2708 ND_TCHECK2(dat[0], BGP_SIZE);
2709 memcpy(&bgp, dat, BGP_SIZE);
2710 ND_PRINT((ndo, "\n\t%s Message (%u), length: %u",
2711 tok2str(bgp_msg_values, "Unknown", bgp.bgp_type),
2712 bgp.bgp_type,
2713 length));
2714
2715 switch (bgp.bgp_type) {
2716 case BGP_OPEN:
2717 bgp_open_print(ndo, dat, length);
2718 break;
2719 case BGP_UPDATE:
2720 bgp_update_print(ndo, dat, length);
2721 break;
2722 case BGP_NOTIFICATION:
2723 bgp_notification_print(ndo, dat, length);
2724 break;
2725 case BGP_KEEPALIVE:
2726 break;
2727 case BGP_ROUTE_REFRESH:
2728 bgp_route_refresh_print(ndo, dat, length);
2729 break;
2730 default:
2731 /* we have no decoder for the BGP message */
2732 ND_TCHECK2(*dat, length);
2733 ND_PRINT((ndo, "\n\t no Message %u decoder", bgp.bgp_type));
2734 print_unknown_data(ndo, dat, "\n\t ", length);
2735 break;
2736 }
2737 return 1;
2738 trunc:
2739 ND_PRINT((ndo, "[|BGP]"));
2740 return 0;
2741 }
2742
2743 void
2744 bgp_print(netdissect_options *ndo,
2745 const u_char *dat, int length)
2746 {
2747 const u_char *p;
2748 const u_char *ep;
2749 const u_char *start;
2750 const u_char marker[] = {
2751 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2752 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2753 };
2754 struct bgp bgp;
2755 uint16_t hlen;
2756
2757 ep = dat + length;
2758 if (ndo->ndo_snapend < dat + length)
2759 ep = ndo->ndo_snapend;
2760
2761 ND_PRINT((ndo, ": BGP"));
2762
2763 if (ndo->ndo_vflag < 1) /* lets be less chatty */
2764 return;
2765
2766 p = dat;
2767 start = p;
2768 while (p < ep) {
2769 if (!ND_TTEST2(p[0], 1))
2770 break;
2771 if (p[0] != 0xff) {
2772 p++;
2773 continue;
2774 }
2775
2776 if (!ND_TTEST2(p[0], sizeof(marker)))
2777 break;
2778 if (memcmp(p, marker, sizeof(marker)) != 0) {
2779 p++;
2780 continue;
2781 }
2782
2783 /* found BGP header */
2784 ND_TCHECK2(p[0], BGP_SIZE); /*XXX*/
2785 memcpy(&bgp, p, BGP_SIZE);
2786
2787 if (start != p)
2788 ND_PRINT((ndo, " [|BGP]"));
2789
2790 hlen = ntohs(bgp.bgp_len);
2791 if (hlen < BGP_SIZE) {
2792 ND_PRINT((ndo, "\n[|BGP Bogus header length %u < %u]", hlen,
2793 BGP_SIZE));
2794 break;
2795 }
2796
2797 if (ND_TTEST2(p[0], hlen)) {
2798 if (!bgp_header_print(ndo, p, hlen))
2799 return;
2800 p += hlen;
2801 start = p;
2802 } else {
2803 ND_PRINT((ndo, "\n[|BGP %s]",
2804 tok2str(bgp_msg_values,
2805 "Unknown Message Type",
2806 bgp.bgp_type)));
2807 break;
2808 }
2809 }
2810
2811 return;
2812
2813 trunc:
2814 ND_PRINT((ndo, " [|BGP]"));
2815 }
2816
2817 /*
2818 * Local Variables:
2819 * c-style: whitesmith
2820 * c-basic-offset: 4
2821 * End:
2822 */