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