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