blob: c82f1cc7df10d580f892b77297b307739e41202d [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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 *
Elliott Hughescec480a2017-12-19 16:54:57 -080029 * Extensively modified by Hannes Gredler (hannes@gredler.at) for more
The Android Open Source Project2949f582009-03-03 19:30:46 -080030 * complete BGP support.
31 */
32
Elliott Hughese2e3bd12017-05-15 10:59:29 -070033/* \summary: Border Gateway Protocol (BGP) printer */
34
The Android Open Source Project2949f582009-03-03 19:30:46 -080035#ifdef HAVE_CONFIG_H
36#include "config.h"
37#endif
38
Elliott Hughese2e3bd12017-05-15 10:59:29 -070039#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080040
41#include <stdio.h>
42#include <string.h>
43
Elliott Hughese2e3bd12017-05-15 10:59:29 -070044#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080045#include "addrtoname.h"
46#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080047#include "af.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080048#include "l2vpn.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080049
50struct bgp {
Elliott Hughes892a68b2015-10-19 14:43:53 -070051 uint8_t bgp_marker[16];
52 uint16_t bgp_len;
53 uint8_t bgp_type;
The Android Open Source Project2949f582009-03-03 19:30:46 -080054};
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
JP Abgrall53f17a92014-02-12 14:02:41 -080063static const struct tok bgp_msg_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080064 { 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
72struct bgp_open {
Elliott Hughes892a68b2015-10-19 14:43:53 -070073 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;
The Android Open Source Project2949f582009-03-03 19:30:46 -080081 /* options should follow */
82};
83#define BGP_OPEN_SIZE 29 /* unaligned */
84
85struct bgp_opt {
Elliott Hughes892a68b2015-10-19 14:43:53 -070086 uint8_t bgpopt_type;
87 uint8_t bgpopt_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -080088 /* variable length */
89};
90#define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
JP Abgrall53f17a92014-02-12 14:02:41 -080091#define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
The Android Open Source Project2949f582009-03-03 19:30:46 -080092
93struct bgp_notification {
Elliott Hughes892a68b2015-10-19 14:43:53 -070094 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;
The Android Open Source Project2949f582009-03-03 19:30:46 -080099};
100#define BGP_NOTIFICATION_SIZE 21 /* unaligned */
101
102struct bgp_route_refresh {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700103 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) */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800110#define BGP_ROUTE_REFRESH_SIZE 23
111
JP Abgrall53f17a92014-02-12 14:02:41 -0800112#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))
The Android Open Source Project2949f582009-03-03 19:30:46 -0800116
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 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700125#define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
126#define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
127#define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
128#define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
129#define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
130#define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
131#define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
132#define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
133#define BGPTYPE_AS4_PATH 17 /* RFC6793 */
134#define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
135#define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
136#define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
137#define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
138#define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
139#define BGPTYPE_AIGP 26 /* RFC7311 */
140#define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
141#define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
142#define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
143#define BGPTYPE_ATTR_SET 128 /* RFC6368 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800144
145#define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
146
JP Abgrall53f17a92014-02-12 14:02:41 -0800147static const struct tok bgp_attr_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800148 { BGPTYPE_ORIGIN, "Origin"},
149 { BGPTYPE_AS_PATH, "AS Path"},
JP Abgrall53f17a92014-02-12 14:02:41 -0800150 { BGPTYPE_AS4_PATH, "AS4 Path"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800151 { BGPTYPE_NEXT_HOP, "Next Hop"},
152 { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"},
153 { BGPTYPE_LOCAL_PREF, "Local Preference"},
154 { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"},
155 { BGPTYPE_AGGREGATOR, "Aggregator"},
JP Abgrall53f17a92014-02-12 14:02:41 -0800156 { BGPTYPE_AGGREGATOR4, "Aggregator4"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800157 { BGPTYPE_COMMUNITIES, "Community"},
158 { BGPTYPE_ORIGINATOR_ID, "Originator ID"},
159 { BGPTYPE_CLUSTER_LIST, "Cluster List"},
160 { BGPTYPE_DPA, "DPA"},
161 { BGPTYPE_ADVERTISERS, "Advertisers"},
162 { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"},
163 { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"},
164 { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"},
165 { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"},
JP Abgrall53f17a92014-02-12 14:02:41 -0800166 { BGPTYPE_PMSI_TUNNEL, "PMSI Tunnel"},
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700167 { BGPTYPE_TUNNEL_ENCAP, "Tunnel Encapsulation"},
168 { BGPTYPE_TRAFFIC_ENG, "Traffic Engineering"},
169 { BGPTYPE_IPV6_EXTD_COMMUNITIES, "IPv6 Extended Community"},
170 { BGPTYPE_AIGP, "Accumulated IGP Metric"},
171 { BGPTYPE_PE_DISTINGUISHER_LABEL, "PE Distinguisher Label"},
172 { BGPTYPE_ENTROPY_LABEL, "Entropy Label"},
173 { BGPTYPE_LARGE_COMMUNITY, "Large Community"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800174 { BGPTYPE_ATTR_SET, "Attribute Set"},
175 { 255, "Reserved for development"},
176 { 0, NULL}
177};
178
179#define BGP_AS_SET 1
180#define BGP_AS_SEQUENCE 2
181#define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
182#define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
183
JP Abgrall53f17a92014-02-12 14:02:41 -0800184#define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
185#define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
186
187static const struct tok bgp_as_path_segment_open_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800188 { BGP_AS_SEQUENCE, ""},
189 { BGP_AS_SET, "{ "},
190 { BGP_CONFED_AS_SEQUENCE, "( "},
191 { BGP_CONFED_AS_SET, "({ "},
192 { 0, NULL}
193};
194
JP Abgrall53f17a92014-02-12 14:02:41 -0800195static const struct tok bgp_as_path_segment_close_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800196 { BGP_AS_SEQUENCE, ""},
197 { BGP_AS_SET, "}"},
198 { BGP_CONFED_AS_SEQUENCE, ")"},
199 { BGP_CONFED_AS_SET, "})"},
200 { 0, NULL}
201};
202
203#define BGP_OPT_AUTH 1
204#define BGP_OPT_CAP 2
205
JP Abgrall53f17a92014-02-12 14:02:41 -0800206static const struct tok bgp_opt_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800207 { BGP_OPT_AUTH, "Authentication Information"},
208 { BGP_OPT_CAP, "Capabilities Advertisement"},
209 { 0, NULL}
210};
211
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700212#define BGP_CAPCODE_MP 1 /* RFC2858 */
213#define BGP_CAPCODE_RR 2 /* RFC2918 */
214#define BGP_CAPCODE_ORF 3 /* RFC5291 */
215#define BGP_CAPCODE_MR 4 /* RFC3107 */
216#define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
217#define BGP_CAPCODE_RESTART 64 /* RFC4724 */
218#define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
219#define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
220#define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
221#define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
222#define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800223#define BGP_CAPCODE_RR_CISCO 128
224
JP Abgrall53f17a92014-02-12 14:02:41 -0800225static const struct tok bgp_capcode_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800226 { BGP_CAPCODE_MP, "Multiprotocol Extensions"},
227 { BGP_CAPCODE_RR, "Route Refresh"},
228 { BGP_CAPCODE_ORF, "Cooperative Route Filtering"},
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700229 { BGP_CAPCODE_MR, "Multiple Routes to a Destination"},
230 { BGP_CAPCODE_EXT_NH, "Extended Next Hop Encoding"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800231 { BGP_CAPCODE_RESTART, "Graceful Restart"},
232 { BGP_CAPCODE_AS_NEW, "32-Bit AS Number"},
233 { BGP_CAPCODE_DYN_CAP, "Dynamic Capability"},
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700234 { BGP_CAPCODE_MULTISESS, "Multisession BGP"},
235 { BGP_CAPCODE_ADD_PATH, "Multiple Paths"},
236 { BGP_CAPCODE_ENH_RR, "Enhanced Route Refresh"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800237 { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"},
238 { 0, NULL}
239};
240
241#define BGP_NOTIFY_MAJOR_MSG 1
242#define BGP_NOTIFY_MAJOR_OPEN 2
243#define BGP_NOTIFY_MAJOR_UPDATE 3
244#define BGP_NOTIFY_MAJOR_HOLDTIME 4
245#define BGP_NOTIFY_MAJOR_FSM 5
246#define BGP_NOTIFY_MAJOR_CEASE 6
247#define BGP_NOTIFY_MAJOR_CAP 7
248
JP Abgrall53f17a92014-02-12 14:02:41 -0800249static const struct tok bgp_notify_major_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800250 { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"},
251 { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"},
252 { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"},
253 { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"},
254 { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"},
255 { BGP_NOTIFY_MAJOR_CEASE, "Cease"},
256 { BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"},
257 { 0, NULL}
258};
259
260/* draft-ietf-idr-cease-subcode-02 */
261#define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
JP Abgrall53f17a92014-02-12 14:02:41 -0800262static const struct tok bgp_notify_minor_cease_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800263 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"},
264 { 2, "Administratively Shutdown"},
265 { 3, "Peer Unconfigured"},
266 { 4, "Administratively Reset"},
267 { 5, "Connection Rejected"},
268 { 6, "Other Configuration Change"},
269 { 7, "Connection Collision Resolution"},
270 { 0, NULL}
271};
272
JP Abgrall53f17a92014-02-12 14:02:41 -0800273static const struct tok bgp_notify_minor_msg_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800274 { 1, "Connection Not Synchronized"},
275 { 2, "Bad Message Length"},
276 { 3, "Bad Message Type"},
277 { 0, NULL}
278};
279
JP Abgrall53f17a92014-02-12 14:02:41 -0800280static const struct tok bgp_notify_minor_open_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800281 { 1, "Unsupported Version Number"},
282 { 2, "Bad Peer AS"},
283 { 3, "Bad BGP Identifier"},
284 { 4, "Unsupported Optional Parameter"},
285 { 5, "Authentication Failure"},
286 { 6, "Unacceptable Hold Time"},
JP Abgrall53f17a92014-02-12 14:02:41 -0800287 { 7, "Capability Message Error"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800288 { 0, NULL}
289};
290
JP Abgrall53f17a92014-02-12 14:02:41 -0800291static const struct tok bgp_notify_minor_update_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800292 { 1, "Malformed Attribute List"},
293 { 2, "Unrecognized Well-known Attribute"},
294 { 3, "Missing Well-known Attribute"},
295 { 4, "Attribute Flags Error"},
296 { 5, "Attribute Length Error"},
297 { 6, "Invalid ORIGIN Attribute"},
298 { 7, "AS Routing Loop"},
299 { 8, "Invalid NEXT_HOP Attribute"},
300 { 9, "Optional Attribute Error"},
301 { 10, "Invalid Network Field"},
302 { 11, "Malformed AS_PATH"},
303 { 0, NULL}
304};
305
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700306static const struct tok bgp_notify_minor_fsm_values[] = {
307 { 1, "In OpenSent State"},
308 { 2, "In OpenConfirm State"},
309 { 3, "In Established State"},
310 { 0, NULL }
311};
312
JP Abgrall53f17a92014-02-12 14:02:41 -0800313static const struct tok bgp_notify_minor_cap_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800314 { 1, "Invalid Action Value" },
315 { 2, "Invalid Capability Length" },
316 { 3, "Malformed Capability Value" },
317 { 4, "Unsupported Capability Code" },
318 { 0, NULL }
319};
320
JP Abgrall53f17a92014-02-12 14:02:41 -0800321static const struct tok bgp_origin_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800322 { 0, "IGP"},
323 { 1, "EGP"},
324 { 2, "Incomplete"},
325 { 0, NULL}
326};
327
JP Abgrall53f17a92014-02-12 14:02:41 -0800328#define BGP_PMSI_TUNNEL_RSVP_P2MP 1
329#define BGP_PMSI_TUNNEL_LDP_P2MP 2
330#define BGP_PMSI_TUNNEL_PIM_SSM 3
331#define BGP_PMSI_TUNNEL_PIM_SM 4
332#define BGP_PMSI_TUNNEL_PIM_BIDIR 5
333#define BGP_PMSI_TUNNEL_INGRESS 6
334#define BGP_PMSI_TUNNEL_LDP_MP2MP 7
335
336static const struct tok bgp_pmsi_tunnel_values[] = {
337 { BGP_PMSI_TUNNEL_RSVP_P2MP, "RSVP-TE P2MP LSP"},
338 { BGP_PMSI_TUNNEL_LDP_P2MP, "LDP P2MP LSP"},
339 { BGP_PMSI_TUNNEL_PIM_SSM, "PIM-SSM Tree"},
340 { BGP_PMSI_TUNNEL_PIM_SM, "PIM-SM Tree"},
341 { BGP_PMSI_TUNNEL_PIM_BIDIR, "PIM-Bidir Tree"},
342 { BGP_PMSI_TUNNEL_INGRESS, "Ingress Replication"},
343 { BGP_PMSI_TUNNEL_LDP_MP2MP, "LDP MP2MP LSP"},
344 { 0, NULL}
345};
346
347static const struct tok bgp_pmsi_flag_values[] = {
348 { 0x01, "Leaf Information required"},
349 { 0, NULL}
350};
351
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700352#define BGP_AIGP_TLV 1
353
354static const struct tok bgp_aigp_values[] = {
355 { BGP_AIGP_TLV, "AIGP"},
356 { 0, NULL}
357};
JP Abgrall53f17a92014-02-12 14:02:41 -0800358
The Android Open Source Project2949f582009-03-03 19:30:46 -0800359/* Subsequent address family identifier, RFC2283 section 7 */
360#define SAFNUM_RES 0
361#define SAFNUM_UNICAST 1
362#define SAFNUM_MULTICAST 2
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700363#define SAFNUM_UNIMULTICAST 3 /* deprecated now */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800364/* labeled BGP RFC3107 */
365#define SAFNUM_LABUNICAST 4
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700366/* RFC6514 */
JP Abgrall53f17a92014-02-12 14:02:41 -0800367#define SAFNUM_MULTICAST_VPN 5
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700368/* draft-nalawade-kapoor-tunnel-safi */
369#define SAFNUM_TUNNEL 64
370/* RFC4761 */
371#define SAFNUM_VPLS 65
372/* RFC6037 */
JP Abgrall53f17a92014-02-12 14:02:41 -0800373#define SAFNUM_MDT 66
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700374/* RFC4364 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800375#define SAFNUM_VPNUNICAST 128
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700376/* RFC6513 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800377#define SAFNUM_VPNMULTICAST 129
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700378#define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
379/* RFC4684 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800380#define SAFNUM_RT_ROUTING_INFO 132
381
382#define BGP_VPN_RD_LEN 8
383
JP Abgrall53f17a92014-02-12 14:02:41 -0800384static const struct tok bgp_safi_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800385 { SAFNUM_RES, "Reserved"},
386 { SAFNUM_UNICAST, "Unicast"},
387 { SAFNUM_MULTICAST, "Multicast"},
388 { SAFNUM_UNIMULTICAST, "Unicast+Multicast"},
389 { SAFNUM_LABUNICAST, "labeled Unicast"},
390 { SAFNUM_TUNNEL, "Tunnel"},
391 { SAFNUM_VPLS, "VPLS"},
392 { SAFNUM_MDT, "MDT"},
393 { SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
394 { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
395 { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
JP Abgrall53f17a92014-02-12 14:02:41 -0800396 { SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"},
397 { SAFNUM_MULTICAST_VPN, "Multicast VPN"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800398 { 0, NULL }
399};
400
401/* well-known community */
402#define BGP_COMMUNITY_NO_EXPORT 0xffffff01
403#define BGP_COMMUNITY_NO_ADVERT 0xffffff02
404#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
405
406/* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
407#define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
408#define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
409#define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
410#define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
411#define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
412#define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
413#define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
414 /* rfc2547 bgp-mpls-vpns */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800415#define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
416#define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
417#define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
418#define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
419
420#define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
421#define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
422
423#define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700424#define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800425
426#define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
427
JP Abgrall53f17a92014-02-12 14:02:41 -0800428#define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
429#define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
430#define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
431#define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
432
The Android Open Source Project2949f582009-03-03 19:30:46 -0800433/* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
434#define BGP_EXT_COM_EIGRP_GEN 0x8800
435#define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
436#define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
437#define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
438#define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
439#define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
440
JP Abgrall53f17a92014-02-12 14:02:41 -0800441static const struct tok bgp_extd_comm_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800442 { 0x8000, "vendor-specific"},
443 { 0x4000, "non-transitive"},
444 { 0, NULL},
445};
446
JP Abgrall53f17a92014-02-12 14:02:41 -0800447static const struct tok bgp_extd_comm_subtype_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800448 { BGP_EXT_COM_RT_0, "target"},
449 { BGP_EXT_COM_RT_1, "target"},
450 { BGP_EXT_COM_RT_2, "target"},
451 { BGP_EXT_COM_RO_0, "origin"},
452 { BGP_EXT_COM_RO_1, "origin"},
453 { BGP_EXT_COM_RO_2, "origin"},
454 { BGP_EXT_COM_LINKBAND, "link-BW"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800455 { BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"},
456 { BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"},
457 { BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"},
458 { BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"},
459 { BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"},
460 { BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"},
461 { BGP_EXT_COM_OSPF_RID, "ospf-router-id"},
462 { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"},
Elliott Hughes892a68b2015-10-19 14:43:53 -0700463 { BGP_EXT_COM_L2INFO, "layer2-info"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800464 { BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" },
465 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" },
466 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" },
467 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" },
468 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" },
469 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" },
JP Abgrall53f17a92014-02-12 14:02:41 -0800470 { BGP_EXT_COM_SOURCE_AS, "source-AS" },
471 { BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"},
472 { BGP_EXT_COM_L2VPN_RT_0, "l2vpn-id"},
473 { BGP_EXT_COM_L2VPN_RT_1, "l2vpn-id"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800474 { 0, NULL},
475};
476
477/* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
478#define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
479#define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
480#define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
481#define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
482#define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
483#define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
484#define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
485
JP Abgrall53f17a92014-02-12 14:02:41 -0800486static const struct tok bgp_extd_comm_ospf_rtype_values[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700487 { BGP_OSPF_RTYPE_RTR, "Router" },
488 { BGP_OSPF_RTYPE_NET, "Network" },
489 { BGP_OSPF_RTYPE_SUM, "Summary" },
490 { BGP_OSPF_RTYPE_EXT, "External" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800491 { BGP_OSPF_RTYPE_NSSA,"NSSA External" },
Elliott Hughes892a68b2015-10-19 14:43:53 -0700492 { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800493 { 0, NULL },
494};
495
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700496/* ADD-PATH Send/Receive field values */
497static const struct tok bgp_add_path_recvsend[] = {
498 { 1, "Receive" },
499 { 2, "Send" },
500 { 3, "Both" },
501 { 0, NULL },
502};
503
JP Abgrall53f17a92014-02-12 14:02:41 -0800504static char astostr[20];
505
506/*
507 * as_printf
508 *
509 * Convert an AS number into a string and return string pointer.
510 *
Elliott Hughes892a68b2015-10-19 14:43:53 -0700511 * Depending on bflag is set or not, AS number is converted into ASDOT notation
JP Abgrall53f17a92014-02-12 14:02:41 -0800512 * or plain number notation.
513 *
514 */
515static char *
Elliott Hughes892a68b2015-10-19 14:43:53 -0700516as_printf(netdissect_options *ndo,
517 char *str, int size, u_int asnum)
JP Abgrall53f17a92014-02-12 14:02:41 -0800518{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700519 if (!ndo->ndo_bflag || asnum <= 0xFFFF) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800520 snprintf(str, size, "%u", asnum);
521 } else {
522 snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF);
523 }
524 return str;
525}
526
527#define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
528
The Android Open Source Project2949f582009-03-03 19:30:46 -0800529int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700530decode_prefix4(netdissect_options *ndo,
531 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800532{
533 struct in_addr addr;
JP Abgrall53f17a92014-02-12 14:02:41 -0800534 u_int plen, plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800535
Elliott Hughes892a68b2015-10-19 14:43:53 -0700536 ND_TCHECK(pptr[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800537 ITEMCHECK(1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800538 plen = pptr[0];
539 if (32 < plen)
540 return -1;
JP Abgrall53f17a92014-02-12 14:02:41 -0800541 itemlen -= 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800542
543 memset(&addr, 0, sizeof(addr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800544 plenbytes = (plen + 7) / 8;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700545 ND_TCHECK2(pptr[1], plenbytes);
JP Abgrall53f17a92014-02-12 14:02:41 -0800546 ITEMCHECK(plenbytes);
547 memcpy(&addr, &pptr[1], plenbytes);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800548 if (plen % 8) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800549 ((u_char *)&addr)[plenbytes - 1] &=
The Android Open Source Project2949f582009-03-03 19:30:46 -0800550 ((0xff00 >> (plen % 8)) & 0xff);
551 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700552 snprintf(buf, buflen, "%s/%d", ipaddr_string(ndo, &addr), plen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800553 return 1 + plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800554
555trunc:
556 return -2;
JP Abgrall53f17a92014-02-12 14:02:41 -0800557
558badtlv:
559 return -3;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800560}
561
562static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700563decode_labeled_prefix4(netdissect_options *ndo,
564 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800565{
566 struct in_addr addr;
JP Abgrall53f17a92014-02-12 14:02:41 -0800567 u_int plen, plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800568
JP Abgrall53f17a92014-02-12 14:02:41 -0800569 /* prefix length and label = 4 bytes */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700570 ND_TCHECK2(pptr[0], 4);
JP Abgrall53f17a92014-02-12 14:02:41 -0800571 ITEMCHECK(4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800572 plen = pptr[0]; /* get prefix length */
573
574 /* this is one of the weirdnesses of rfc3107
575 the label length (actually the label + COS bits)
576 is added to the prefix length;
577 we also do only read out just one label -
578 there is no real application for advertisement of
Elliott Hughes892a68b2015-10-19 14:43:53 -0700579 stacked labels in a single BGP message
The Android Open Source Project2949f582009-03-03 19:30:46 -0800580 */
581
582 if (24 > plen)
583 return -1;
584
585 plen-=24; /* adjust prefixlen - labellength */
586
587 if (32 < plen)
588 return -1;
JP Abgrall53f17a92014-02-12 14:02:41 -0800589 itemlen -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800590
591 memset(&addr, 0, sizeof(addr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800592 plenbytes = (plen + 7) / 8;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700593 ND_TCHECK2(pptr[4], plenbytes);
JP Abgrall53f17a92014-02-12 14:02:41 -0800594 ITEMCHECK(plenbytes);
595 memcpy(&addr, &pptr[4], plenbytes);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800596 if (plen % 8) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800597 ((u_char *)&addr)[plenbytes - 1] &=
The Android Open Source Project2949f582009-03-03 19:30:46 -0800598 ((0xff00 >> (plen % 8)) & 0xff);
599 }
600 /* the label may get offsetted by 4 bits so lets shift it right */
601 snprintf(buf, buflen, "%s/%d, label:%u %s",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700602 ipaddr_string(ndo, &addr),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800603 plen,
604 EXTRACT_24BITS(pptr+1)>>4,
605 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
606
JP Abgrall53f17a92014-02-12 14:02:41 -0800607 return 4 + plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800608
609trunc:
610 return -2;
JP Abgrall53f17a92014-02-12 14:02:41 -0800611
612badtlv:
613 return -3;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800614}
615
JP Abgrall53f17a92014-02-12 14:02:41 -0800616/*
617 * bgp_vpn_ip_print
618 *
619 * print an ipv4 or ipv6 address into a buffer dependend on address length.
620 */
621static char *
Elliott Hughes892a68b2015-10-19 14:43:53 -0700622bgp_vpn_ip_print(netdissect_options *ndo,
623 const u_char *pptr, u_int addr_length)
624{
JP Abgrall53f17a92014-02-12 14:02:41 -0800625
626 /* worst case string is s fully formatted v6 address */
627 static char addr[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
628 char *pos = addr;
629
630 switch(addr_length) {
631 case (sizeof(struct in_addr) << 3): /* 32 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700632 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
633 snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800634 break;
JP Abgrall53f17a92014-02-12 14:02:41 -0800635 case (sizeof(struct in6_addr) << 3): /* 128 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700636 ND_TCHECK2(pptr[0], sizeof(struct in6_addr));
637 snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800638 break;
JP Abgrall53f17a92014-02-12 14:02:41 -0800639 default:
640 snprintf(pos, sizeof(addr), "bogus address length %u", addr_length);
641 break;
642 }
643 pos += strlen(pos);
644
645trunc:
646 *(pos) = '\0';
647 return (addr);
648}
649
650/*
651 * bgp_vpn_sg_print
652 *
653 * print an multicast s,g entry into a buffer.
654 * the s,g entry is encoded like this.
655 *
656 * +-----------------------------------+
657 * | Multicast Source Length (1 octet) |
658 * +-----------------------------------+
659 * | Multicast Source (Variable) |
660 * +-----------------------------------+
661 * | Multicast Group Length (1 octet) |
662 * +-----------------------------------+
663 * | Multicast Group (Variable) |
664 * +-----------------------------------+
665 *
666 * return the number of bytes read from the wire.
667 */
668static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700669bgp_vpn_sg_print(netdissect_options *ndo,
670 const u_char *pptr, char *buf, u_int buflen)
671{
672 uint8_t addr_length;
JP Abgrall53f17a92014-02-12 14:02:41 -0800673 u_int total_length, offset;
674
675 total_length = 0;
676
677 /* Source address length, encoded in bits */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700678 ND_TCHECK2(pptr[0], 1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800679 addr_length = *pptr++;
680
681 /* Source address */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700682 ND_TCHECK2(pptr[0], (addr_length >> 3));
JP Abgrall53f17a92014-02-12 14:02:41 -0800683 total_length += (addr_length >> 3) + 1;
684 offset = strlen(buf);
685 if (addr_length) {
686 snprintf(buf + offset, buflen - offset, ", Source %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700687 bgp_vpn_ip_print(ndo, pptr, addr_length));
JP Abgrall53f17a92014-02-12 14:02:41 -0800688 pptr += (addr_length >> 3);
689 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700690
JP Abgrall53f17a92014-02-12 14:02:41 -0800691 /* Group address length, encoded in bits */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700692 ND_TCHECK2(pptr[0], 1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800693 addr_length = *pptr++;
694
695 /* Group address */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700696 ND_TCHECK2(pptr[0], (addr_length >> 3));
JP Abgrall53f17a92014-02-12 14:02:41 -0800697 total_length += (addr_length >> 3) + 1;
698 offset = strlen(buf);
699 if (addr_length) {
700 snprintf(buf + offset, buflen - offset, ", Group %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700701 bgp_vpn_ip_print(ndo, pptr, addr_length));
JP Abgrall53f17a92014-02-12 14:02:41 -0800702 pptr += (addr_length >> 3);
703 }
704
705trunc:
706 return (total_length);
707}
708
The Android Open Source Project2949f582009-03-03 19:30:46 -0800709/* RDs and RTs share the same semantics
710 * we use bgp_vpn_rd_print for
711 * printing route targets inside a NLRI */
712char *
Elliott Hughes892a68b2015-10-19 14:43:53 -0700713bgp_vpn_rd_print(netdissect_options *ndo,
714 const u_char *pptr)
715{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800716 /* allocate space for the largest possible string */
717 static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
718 char *pos = rd;
719
720 /* ok lets load the RD format */
721 switch (EXTRACT_16BITS(pptr)) {
722
JP Abgrall53f17a92014-02-12 14:02:41 -0800723 /* 2-byte-AS:number fmt*/
The Android Open Source Project2949f582009-03-03 19:30:46 -0800724 case 0:
JP Abgrall53f17a92014-02-12 14:02:41 -0800725 snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)",
726 EXTRACT_16BITS(pptr+2),
727 EXTRACT_32BITS(pptr+4),
728 *(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800729 break;
730 /* IP-address:AS fmt*/
731
732 case 1:
733 snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u",
734 *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6));
735 break;
736
737 /* 4-byte-AS:number fmt*/
738 case 2:
JP Abgrall53f17a92014-02-12 14:02:41 -0800739 snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700740 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr+2)),
JP Abgrall53f17a92014-02-12 14:02:41 -0800741 EXTRACT_16BITS(pptr+6), *(pptr+2), *(pptr+3), *(pptr+4),
742 *(pptr+5), EXTRACT_16BITS(pptr+6));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800743 break;
744 default:
745 snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format");
746 break;
747 }
748 pos += strlen(pos);
749 *(pos) = '\0';
750 return (rd);
751}
752
753static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700754decode_rt_routing_info(netdissect_options *ndo,
755 const u_char *pptr, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800756{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700757 uint8_t route_target[8];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800758 u_int plen;
Elliott Hughescec480a2017-12-19 16:54:57 -0800759 char asbuf[sizeof(astostr)]; /* bgp_vpn_rd_print() overwrites astostr */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800760
Elliott Hughescec480a2017-12-19 16:54:57 -0800761 /* NLRI "prefix length" from RFC 2858 Section 4. */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700762 ND_TCHECK(pptr[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800763 plen = pptr[0]; /* get prefix length */
764
Elliott Hughescec480a2017-12-19 16:54:57 -0800765 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
766 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
767 * target" fields inside the "prefix" depending on its length.
768 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700769 if (0 == plen) {
Elliott Hughescec480a2017-12-19 16:54:57 -0800770 /* Without "origin AS", without "route target". */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700771 snprintf(buf, buflen, "default route target");
772 return 1;
773 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800774
775 if (32 > plen)
776 return -1;
777
Elliott Hughescec480a2017-12-19 16:54:57 -0800778 /* With at least "origin AS", possibly with "route target". */
779 ND_TCHECK_32BITS(pptr + 1);
780 as_printf(ndo, asbuf, sizeof(asbuf), EXTRACT_32BITS(pptr + 1));
781
The Android Open Source Project2949f582009-03-03 19:30:46 -0800782 plen-=32; /* adjust prefix length */
783
784 if (64 < plen)
785 return -1;
786
Elliott Hughescec480a2017-12-19 16:54:57 -0800787 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
788 * and gives the number of octets in the variable-length "route
789 * target" field inside this NLRI "prefix". Look for it.
790 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791 memset(&route_target, 0, sizeof(route_target));
Elliott Hughescec480a2017-12-19 16:54:57 -0800792 ND_TCHECK2(pptr[5], (plen + 7) / 8);
793 memcpy(&route_target, &pptr[5], (plen + 7) / 8);
794 /* Which specification says to do this? */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800795 if (plen % 8) {
796 ((u_char *)&route_target)[(plen + 7) / 8 - 1] &=
797 ((0xff00 >> (plen % 8)) & 0xff);
798 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800799 snprintf(buf, buflen, "origin AS: %s, route target %s",
Elliott Hughescec480a2017-12-19 16:54:57 -0800800 asbuf,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700801 bgp_vpn_rd_print(ndo, (u_char *)&route_target));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800802
803 return 5 + (plen + 7) / 8;
804
805trunc:
806 return -2;
807}
808
809static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700810decode_labeled_vpn_prefix4(netdissect_options *ndo,
811 const u_char *pptr, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800812{
813 struct in_addr addr;
814 u_int plen;
815
Elliott Hughes892a68b2015-10-19 14:43:53 -0700816 ND_TCHECK(pptr[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800817 plen = pptr[0]; /* get prefix length */
818
819 if ((24+64) > plen)
820 return -1;
821
822 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
823
824 if (32 < plen)
825 return -1;
826
827 memset(&addr, 0, sizeof(addr));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700828 ND_TCHECK2(pptr[12], (plen + 7) / 8);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800829 memcpy(&addr, &pptr[12], (plen + 7) / 8);
830 if (plen % 8) {
831 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
832 ((0xff00 >> (plen % 8)) & 0xff);
833 }
834 /* the label may get offsetted by 4 bits so lets shift it right */
835 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700836 bgp_vpn_rd_print(ndo, pptr+4),
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700837 ipaddr_string(ndo, &addr),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800838 plen,
839 EXTRACT_24BITS(pptr+1)>>4,
840 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
841
842 return 12 + (plen + 7) / 8;
843
844trunc:
845 return -2;
846}
847
848/*
JP Abgrall53f17a92014-02-12 14:02:41 -0800849 * +-------------------------------+
850 * | |
851 * | RD:IPv4-address (12 octets) |
852 * | |
853 * +-------------------------------+
854 * | MDT Group-address (4 octets) |
855 * +-------------------------------+
856 */
857
858#define MDT_VPN_NLRI_LEN 16
859
860static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700861decode_mdt_vpn_nlri(netdissect_options *ndo,
862 const u_char *pptr, char *buf, u_int buflen)
JP Abgrall53f17a92014-02-12 14:02:41 -0800863{
864
865 const u_char *rd;
866 const u_char *vpn_ip;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700867
868 ND_TCHECK(pptr[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800869
870 /* if the NLRI is not predefined length, quit.*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700871 if (*pptr != MDT_VPN_NLRI_LEN * 8)
JP Abgrall53f17a92014-02-12 14:02:41 -0800872 return -1;
873 pptr++;
874
875 /* RD */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700876 ND_TCHECK2(pptr[0], 8);
JP Abgrall53f17a92014-02-12 14:02:41 -0800877 rd = pptr;
878 pptr+=8;
879
880 /* IPv4 address */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700881 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800882 vpn_ip = pptr;
883 pptr+=sizeof(struct in_addr);
884
885 /* MDT Group Address */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700886 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800887
888 snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700889 bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr));
890
JP Abgrall53f17a92014-02-12 14:02:41 -0800891 return MDT_VPN_NLRI_LEN + 1;
892
893 trunc:
894
895return -2;
896}
897
898#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
899#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
900#define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
901#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
902#define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
903#define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
904#define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
905
906static const struct tok bgp_multicast_vpn_route_type_values[] = {
907 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"},
908 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"},
909 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"},
910 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"},
911 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
912 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
913 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
Elliott Hughescec480a2017-12-19 16:54:57 -0800914 { 0, NULL}
JP Abgrall53f17a92014-02-12 14:02:41 -0800915};
916
917static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700918decode_multicast_vpn(netdissect_options *ndo,
919 const u_char *pptr, char *buf, u_int buflen)
JP Abgrall53f17a92014-02-12 14:02:41 -0800920{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700921 uint8_t route_type, route_length, addr_length, sg_length;
JP Abgrall53f17a92014-02-12 14:02:41 -0800922 u_int offset;
923
Elliott Hughes892a68b2015-10-19 14:43:53 -0700924 ND_TCHECK2(pptr[0], 2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800925 route_type = *pptr++;
926 route_length = *pptr++;
927
928 snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
929 tok2str(bgp_multicast_vpn_route_type_values,
930 "Unknown", route_type),
931 route_type, route_length);
932
933 switch(route_type) {
934 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700935 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
JP Abgrall53f17a92014-02-12 14:02:41 -0800936 offset = strlen(buf);
937 snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700938 bgp_vpn_rd_print(ndo, pptr),
939 bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN,
JP Abgrall53f17a92014-02-12 14:02:41 -0800940 (route_length - BGP_VPN_RD_LEN) << 3));
941 break;
942 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700943 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
JP Abgrall53f17a92014-02-12 14:02:41 -0800944 offset = strlen(buf);
945 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700946 bgp_vpn_rd_print(ndo, pptr),
947 as_printf(ndo, astostr, sizeof(astostr),
JP Abgrall53f17a92014-02-12 14:02:41 -0800948 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
949 break;
950
951 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700952 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
JP Abgrall53f17a92014-02-12 14:02:41 -0800953 offset = strlen(buf);
954 snprintf(buf + offset, buflen - offset, ", RD: %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700955 bgp_vpn_rd_print(ndo, pptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800956 pptr += BGP_VPN_RD_LEN;
957
Elliott Hughes892a68b2015-10-19 14:43:53 -0700958 sg_length = bgp_vpn_sg_print(ndo, pptr, buf, buflen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800959 addr_length = route_length - sg_length;
960
Elliott Hughes892a68b2015-10-19 14:43:53 -0700961 ND_TCHECK2(pptr[0], addr_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800962 offset = strlen(buf);
963 snprintf(buf + offset, buflen - offset, ", Originator %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700964 bgp_vpn_ip_print(ndo, pptr, addr_length << 3));
JP Abgrall53f17a92014-02-12 14:02:41 -0800965 break;
966
967 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700968 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
JP Abgrall53f17a92014-02-12 14:02:41 -0800969 offset = strlen(buf);
970 snprintf(buf + offset, buflen - offset, ", RD: %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700971 bgp_vpn_rd_print(ndo, pptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800972 pptr += BGP_VPN_RD_LEN;
973
Elliott Hughes892a68b2015-10-19 14:43:53 -0700974 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800975 break;
976
977 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
978 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
Elliott Hughescec480a2017-12-19 16:54:57 -0800979 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
JP Abgrall53f17a92014-02-12 14:02:41 -0800980 offset = strlen(buf);
981 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700982 bgp_vpn_rd_print(ndo, pptr),
983 as_printf(ndo, astostr, sizeof(astostr),
JP Abgrall53f17a92014-02-12 14:02:41 -0800984 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
Elliott Hughescec480a2017-12-19 16:54:57 -0800985 pptr += BGP_VPN_RD_LEN + 4;
JP Abgrall53f17a92014-02-12 14:02:41 -0800986
Elliott Hughes892a68b2015-10-19 14:43:53 -0700987 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800988 break;
989
990 /*
991 * no per route-type printing yet.
992 */
993 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF:
994 default:
995 break;
996 }
997
998 return route_length + 2;
999
1000trunc:
1001 return -2;
1002}
1003
1004/*
The Android Open Source Project2949f582009-03-03 19:30:46 -08001005 * As I remember, some versions of systems have an snprintf() that
1006 * returns -1 if the buffer would have overflowed. If the return
1007 * value is negative, set buflen to 0, to indicate that we've filled
1008 * the buffer up.
1009 *
1010 * If the return value is greater than buflen, that means that
1011 * the buffer would have overflowed; again, set buflen to 0 in
1012 * that case.
1013 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001014#define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1015 if (stringlen<0) \
The Android Open Source Project2949f582009-03-03 19:30:46 -08001016 buflen=0; \
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001017 else if ((u_int)stringlen>buflen) \
The Android Open Source Project2949f582009-03-03 19:30:46 -08001018 buflen=0; \
1019 else { \
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001020 buflen-=stringlen; \
1021 buf+=stringlen; \
The Android Open Source Project2949f582009-03-03 19:30:46 -08001022 }
1023
1024static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001025decode_labeled_vpn_l2(netdissect_options *ndo,
1026 const u_char *pptr, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001027{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001028 int plen,tlen,stringlen,tlv_type,tlv_len,ttlv_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001029
Elliott Hughes892a68b2015-10-19 14:43:53 -07001030 ND_TCHECK2(pptr[0], 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001031 plen=EXTRACT_16BITS(pptr);
1032 tlen=plen;
1033 pptr+=2;
JP Abgrall53f17a92014-02-12 14:02:41 -08001034 /* Old and new L2VPN NLRI share AFI/SAFI
1035 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1036 * and > 17 as old format. Complain for the middle case
1037 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001038 if (plen==12) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001039 /* assume AD-only with RD, BGPNH */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001040 ND_TCHECK2(pptr[0],12);
JP Abgrall53f17a92014-02-12 14:02:41 -08001041 buf[0]='\0';
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001042 stringlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s",
1043 bgp_vpn_rd_print(ndo, pptr),
1044 ipaddr_string(ndo, pptr+8)
1045 );
1046 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08001047 pptr+=12;
1048 tlen-=12;
1049 return plen;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001050 } else if (plen>17) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001051 /* assume old format */
1052 /* RD, ID, LBLKOFF, LBLBASE */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001053
Elliott Hughes892a68b2015-10-19 14:43:53 -07001054 ND_TCHECK2(pptr[0],15);
JP Abgrall53f17a92014-02-12 14:02:41 -08001055 buf[0]='\0';
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001056 stringlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1057 bgp_vpn_rd_print(ndo, pptr),
1058 EXTRACT_16BITS(pptr+8),
1059 EXTRACT_16BITS(pptr+10),
1060 EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1061 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08001062 pptr+=15;
1063 tlen-=15;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001064
JP Abgrall53f17a92014-02-12 14:02:41 -08001065 /* ok now the variable part - lets read out TLVs*/
1066 while (tlen>0) {
1067 if (tlen < 3)
1068 return -1;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001069 ND_TCHECK2(pptr[0], 3);
JP Abgrall53f17a92014-02-12 14:02:41 -08001070 tlv_type=*pptr++;
1071 tlv_len=EXTRACT_16BITS(pptr);
1072 ttlv_len=tlv_len;
1073 pptr+=2;
1074
1075 switch(tlv_type) {
1076 case 1:
1077 if (buflen!=0) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001078 stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1079 tlv_type,
1080 tlv_len);
1081 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08001082 }
1083 ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
1084 while (ttlv_len>0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001085 ND_TCHECK(pptr[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -08001086 if (buflen!=0) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001087 stringlen=snprintf(buf,buflen, "%02x",*pptr++);
1088 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08001089 }
1090 ttlv_len--;
1091 }
1092 break;
1093 default:
1094 if (buflen!=0) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001095 stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u",
1096 tlv_type,
1097 tlv_len);
1098 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08001099 }
1100 break;
1101 }
1102 tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */
1103 }
1104 return plen+2;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001105
JP Abgrall53f17a92014-02-12 14:02:41 -08001106 } else {
1107 /* complain bitterly ? */
1108 /* fall through */
1109 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001110 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001111
1112trunc:
1113 return -2;
1114}
1115
The Android Open Source Project2949f582009-03-03 19:30:46 -08001116int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001117decode_prefix6(netdissect_options *ndo,
1118 const u_char *pd, u_int itemlen, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001119{
1120 struct in6_addr addr;
JP Abgrall53f17a92014-02-12 14:02:41 -08001121 u_int plen, plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001122
Elliott Hughes892a68b2015-10-19 14:43:53 -07001123 ND_TCHECK(pd[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -08001124 ITEMCHECK(1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001125 plen = pd[0];
1126 if (128 < plen)
1127 return -1;
JP Abgrall53f17a92014-02-12 14:02:41 -08001128 itemlen -= 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001129
1130 memset(&addr, 0, sizeof(addr));
JP Abgrall53f17a92014-02-12 14:02:41 -08001131 plenbytes = (plen + 7) / 8;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001132 ND_TCHECK2(pd[1], plenbytes);
JP Abgrall53f17a92014-02-12 14:02:41 -08001133 ITEMCHECK(plenbytes);
1134 memcpy(&addr, &pd[1], plenbytes);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001135 if (plen % 8) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001136 addr.s6_addr[plenbytes - 1] &=
The Android Open Source Project2949f582009-03-03 19:30:46 -08001137 ((0xff00 >> (plen % 8)) & 0xff);
1138 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001139 snprintf(buf, buflen, "%s/%d", ip6addr_string(ndo, &addr), plen);
JP Abgrall53f17a92014-02-12 14:02:41 -08001140 return 1 + plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001141
1142trunc:
1143 return -2;
JP Abgrall53f17a92014-02-12 14:02:41 -08001144
1145badtlv:
1146 return -3;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001147}
1148
1149static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001150decode_labeled_prefix6(netdissect_options *ndo,
1151 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001152{
1153 struct in6_addr addr;
JP Abgrall53f17a92014-02-12 14:02:41 -08001154 u_int plen, plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001155
JP Abgrall53f17a92014-02-12 14:02:41 -08001156 /* prefix length and label = 4 bytes */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001157 ND_TCHECK2(pptr[0], 4);
JP Abgrall53f17a92014-02-12 14:02:41 -08001158 ITEMCHECK(4);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001159 plen = pptr[0]; /* get prefix length */
1160
1161 if (24 > plen)
1162 return -1;
1163
1164 plen-=24; /* adjust prefixlen - labellength */
1165
1166 if (128 < plen)
1167 return -1;
JP Abgrall53f17a92014-02-12 14:02:41 -08001168 itemlen -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001169
1170 memset(&addr, 0, sizeof(addr));
JP Abgrall53f17a92014-02-12 14:02:41 -08001171 plenbytes = (plen + 7) / 8;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001172 ND_TCHECK2(pptr[4], plenbytes);
JP Abgrall53f17a92014-02-12 14:02:41 -08001173 memcpy(&addr, &pptr[4], plenbytes);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001174 if (plen % 8) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001175 addr.s6_addr[plenbytes - 1] &=
The Android Open Source Project2949f582009-03-03 19:30:46 -08001176 ((0xff00 >> (plen % 8)) & 0xff);
1177 }
1178 /* the label may get offsetted by 4 bits so lets shift it right */
1179 snprintf(buf, buflen, "%s/%d, label:%u %s",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001180 ip6addr_string(ndo, &addr),
The Android Open Source Project2949f582009-03-03 19:30:46 -08001181 plen,
1182 EXTRACT_24BITS(pptr+1)>>4,
1183 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1184
JP Abgrall53f17a92014-02-12 14:02:41 -08001185 return 4 + plenbytes;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001186
1187trunc:
1188 return -2;
JP Abgrall53f17a92014-02-12 14:02:41 -08001189
1190badtlv:
1191 return -3;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001192}
1193
1194static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001195decode_labeled_vpn_prefix6(netdissect_options *ndo,
1196 const u_char *pptr, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001197{
1198 struct in6_addr addr;
1199 u_int plen;
1200
Elliott Hughes892a68b2015-10-19 14:43:53 -07001201 ND_TCHECK(pptr[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001202 plen = pptr[0]; /* get prefix length */
1203
1204 if ((24+64) > plen)
1205 return -1;
1206
1207 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1208
1209 if (128 < plen)
1210 return -1;
1211
1212 memset(&addr, 0, sizeof(addr));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001213 ND_TCHECK2(pptr[12], (plen + 7) / 8);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001214 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1215 if (plen % 8) {
1216 addr.s6_addr[(plen + 7) / 8 - 1] &=
1217 ((0xff00 >> (plen % 8)) & 0xff);
1218 }
1219 /* the label may get offsetted by 4 bits so lets shift it right */
1220 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -07001221 bgp_vpn_rd_print(ndo, pptr+4),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001222 ip6addr_string(ndo, &addr),
The Android Open Source Project2949f582009-03-03 19:30:46 -08001223 plen,
1224 EXTRACT_24BITS(pptr+1)>>4,
1225 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1226
1227 return 12 + (plen + 7) / 8;
1228
1229trunc:
1230 return -2;
1231}
The Android Open Source Project2949f582009-03-03 19:30:46 -08001232
1233static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001234decode_clnp_prefix(netdissect_options *ndo,
1235 const u_char *pptr, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001236{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001237 uint8_t addr[19];
The Android Open Source Project2949f582009-03-03 19:30:46 -08001238 u_int plen;
1239
Elliott Hughes892a68b2015-10-19 14:43:53 -07001240 ND_TCHECK(pptr[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001241 plen = pptr[0]; /* get prefix length */
1242
1243 if (152 < plen)
1244 return -1;
1245
1246 memset(&addr, 0, sizeof(addr));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001247 ND_TCHECK2(pptr[4], (plen + 7) / 8);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001248 memcpy(&addr, &pptr[4], (plen + 7) / 8);
1249 if (plen % 8) {
1250 addr[(plen + 7) / 8 - 1] &=
1251 ((0xff00 >> (plen % 8)) & 0xff);
1252 }
1253 snprintf(buf, buflen, "%s/%d",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001254 isonsap_string(ndo, addr,(plen + 7) / 8),
The Android Open Source Project2949f582009-03-03 19:30:46 -08001255 plen);
1256
1257 return 1 + (plen + 7) / 8;
1258
1259trunc:
1260 return -2;
1261}
1262
1263static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001264decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
1265 const u_char *pptr, char *buf, u_int buflen)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001266{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001267 uint8_t addr[19];
The Android Open Source Project2949f582009-03-03 19:30:46 -08001268 u_int plen;
1269
Elliott Hughes892a68b2015-10-19 14:43:53 -07001270 ND_TCHECK(pptr[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001271 plen = pptr[0]; /* get prefix length */
1272
1273 if ((24+64) > plen)
1274 return -1;
1275
1276 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1277
1278 if (152 < plen)
1279 return -1;
1280
1281 memset(&addr, 0, sizeof(addr));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001282 ND_TCHECK2(pptr[12], (plen + 7) / 8);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001283 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1284 if (plen % 8) {
1285 addr[(plen + 7) / 8 - 1] &=
1286 ((0xff00 >> (plen % 8)) & 0xff);
1287 }
1288 /* the label may get offsetted by 4 bits so lets shift it right */
1289 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
Elliott Hughes892a68b2015-10-19 14:43:53 -07001290 bgp_vpn_rd_print(ndo, pptr+4),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001291 isonsap_string(ndo, addr,(plen + 7) / 8),
The Android Open Source Project2949f582009-03-03 19:30:46 -08001292 plen,
1293 EXTRACT_24BITS(pptr+1)>>4,
1294 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1295
1296 return 12 + (plen + 7) / 8;
1297
1298trunc:
1299 return -2;
1300}
1301
JP Abgrall53f17a92014-02-12 14:02:41 -08001302/*
1303 * bgp_attr_get_as_size
1304 *
1305 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1306 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1307 * support, exchange AS-Path with the same path-attribute type value 0x02.
1308 */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001309static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001310bgp_attr_get_as_size(netdissect_options *ndo,
1311 uint8_t bgpa_type, const u_char *pptr, int len)
JP Abgrall53f17a92014-02-12 14:02:41 -08001312{
1313 const u_char *tptr = pptr;
1314
1315 /*
1316 * If the path attribute is the optional AS4 path type, then we already
1317 * know, that ASs must be encoded in 4 byte format.
1318 */
1319 if (bgpa_type == BGPTYPE_AS4_PATH) {
1320 return 4;
1321 }
1322
1323 /*
1324 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1325 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1326 * each.
1327 */
1328 while (tptr < pptr + len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001329 ND_TCHECK(tptr[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -08001330
1331 /*
1332 * If we do not find a valid segment type, our guess might be wrong.
1333 */
1334 if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) {
1335 goto trunc;
1336 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001337 ND_TCHECK(tptr[1]);
JP Abgrall53f17a92014-02-12 14:02:41 -08001338 tptr += 2 + tptr[1] * 2;
1339 }
1340
1341 /*
1342 * If we correctly reached end of the AS path attribute data content,
1343 * then most likely ASs were indeed encoded as 2 bytes.
1344 */
1345 if (tptr == pptr + len) {
1346 return 2;
1347 }
1348
1349trunc:
1350
1351 /*
1352 * We can come here, either we did not have enough data, or if we
1353 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1354 * so that calller can try to decode each AS as of 4 bytes. If indeed
1355 * there was not enough data, it will crib and end the parse anyways.
1356 */
1357 return 4;
1358}
1359
1360static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001361bgp_attr_print(netdissect_options *ndo,
1362 u_int atype, const u_char *pptr, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001363{
1364 int i;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001365 uint16_t af;
1366 uint8_t safi, snpa, nhlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001367 union { /* copy buffer for bandwidth values */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001368 float f;
1369 uint32_t i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001370 } bw;
1371 int advance;
JP Abgrall53f17a92014-02-12 14:02:41 -08001372 u_int tlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001373 const u_char *tptr;
1374 char buf[MAXHOSTNAMELEN + 100];
JP Abgrall53f17a92014-02-12 14:02:41 -08001375 int as_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001376
1377 tptr = pptr;
1378 tlen=len;
1379
JP Abgrall53f17a92014-02-12 14:02:41 -08001380 switch (atype) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001381 case BGPTYPE_ORIGIN:
1382 if (len != 1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001383 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001384 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001385 ND_TCHECK(*tptr);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001386 ND_PRINT((ndo, "%s", tok2str(bgp_origin_values,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001387 "Unknown Origin Typecode",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001388 tptr[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001389 }
1390 break;
1391
JP Abgrall53f17a92014-02-12 14:02:41 -08001392 /*
1393 * Process AS4 byte path and AS2 byte path attributes here.
1394 */
1395 case BGPTYPE_AS4_PATH:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001396 case BGPTYPE_AS_PATH:
1397 if (len % 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001398 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001399 break;
1400 }
1401 if (!len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001402 ND_PRINT((ndo, "empty"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001403 break;
1404 }
1405
JP Abgrall53f17a92014-02-12 14:02:41 -08001406 /*
1407 * BGP updates exchanged between New speakers that support 4
1408 * byte AS, ASs are always encoded in 4 bytes. There is no
1409 * definitive way to find this, just by the packet's
1410 * contents. So, check for packet's TLV's sanity assuming
1411 * 2 bytes first, and it does not pass, assume that ASs are
1412 * encoded in 4 bytes format and move on.
1413 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001414 as_size = bgp_attr_get_as_size(ndo, atype, pptr, len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001415
The Android Open Source Project2949f582009-03-03 19:30:46 -08001416 while (tptr < pptr + len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001417 ND_TCHECK(tptr[0]);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001418 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_open_values,
1419 "?", tptr[0])));
Elliott Hughescec480a2017-12-19 16:54:57 -08001420 ND_TCHECK(tptr[1]);
JP Abgrall53f17a92014-02-12 14:02:41 -08001421 for (i = 0; i < tptr[1] * as_size; i += as_size) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001422 ND_TCHECK2(tptr[2 + i], as_size);
1423 ND_PRINT((ndo, "%s ",
1424 as_printf(ndo, astostr, sizeof(astostr),
1425 as_size == 2 ?
JP Abgrall53f17a92014-02-12 14:02:41 -08001426 EXTRACT_16BITS(&tptr[2 + i]) :
Elliott Hughes892a68b2015-10-19 14:43:53 -07001427 EXTRACT_32BITS(&tptr[2 + i]))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001428 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001429 ND_TCHECK(tptr[0]);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001430 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_close_values,
1431 "?", tptr[0])));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001432 ND_TCHECK(tptr[1]);
JP Abgrall53f17a92014-02-12 14:02:41 -08001433 tptr += 2 + tptr[1] * as_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001434 }
1435 break;
1436 case BGPTYPE_NEXT_HOP:
1437 if (len != 4)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001438 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001439 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001440 ND_TCHECK2(tptr[0], 4);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001441 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001442 }
1443 break;
1444 case BGPTYPE_MULTI_EXIT_DISC:
1445 case BGPTYPE_LOCAL_PREF:
1446 if (len != 4)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001447 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001448 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001449 ND_TCHECK2(tptr[0], 4);
1450 ND_PRINT((ndo, "%u", EXTRACT_32BITS(tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001451 }
1452 break;
1453 case BGPTYPE_ATOMIC_AGGREGATE:
1454 if (len != 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001455 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001456 break;
JP Abgrall53f17a92014-02-12 14:02:41 -08001457 case BGPTYPE_AGGREGATOR:
1458
1459 /*
1460 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1461 * the length of this PA can be either 6 bytes or 8 bytes.
1462 */
1463 if (len != 6 && len != 8) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001464 ND_PRINT((ndo, "invalid len"));
JP Abgrall53f17a92014-02-12 14:02:41 -08001465 break;
1466 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001467 ND_TCHECK2(tptr[0], len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001468 if (len == 6) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001469 ND_PRINT((ndo, " AS #%s, origin %s",
1470 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_16BITS(tptr)),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001471 ipaddr_string(ndo, tptr + 2)));
JP Abgrall53f17a92014-02-12 14:02:41 -08001472 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001473 ND_PRINT((ndo, " AS #%s, origin %s",
1474 as_printf(ndo, astostr, sizeof(astostr),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001475 EXTRACT_32BITS(tptr)), ipaddr_string(ndo, tptr + 4)));
JP Abgrall53f17a92014-02-12 14:02:41 -08001476 }
1477 break;
1478 case BGPTYPE_AGGREGATOR4:
1479 if (len != 8) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001480 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001481 break;
1482 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001483 ND_TCHECK2(tptr[0], 8);
1484 ND_PRINT((ndo, " AS #%s, origin %s",
1485 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001486 ipaddr_string(ndo, tptr + 4)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001487 break;
1488 case BGPTYPE_COMMUNITIES:
1489 if (len % 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001490 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001491 break;
1492 }
1493 while (tlen>0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001494 uint32_t comm;
1495 ND_TCHECK2(tptr[0], 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001496 comm = EXTRACT_32BITS(tptr);
1497 switch (comm) {
1498 case BGP_COMMUNITY_NO_EXPORT:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001499 ND_PRINT((ndo, " NO_EXPORT"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001500 break;
1501 case BGP_COMMUNITY_NO_ADVERT:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001502 ND_PRINT((ndo, " NO_ADVERTISE"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001503 break;
1504 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001505 ND_PRINT((ndo, " NO_EXPORT_SUBCONFED"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001506 break;
1507 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001508 ND_PRINT((ndo, "%u:%u%s",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001509 (comm >> 16) & 0xffff,
1510 comm & 0xffff,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001511 (tlen>4) ? ", " : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001512 break;
1513 }
1514 tlen -=4;
1515 tptr +=4;
1516 }
1517 break;
1518 case BGPTYPE_ORIGINATOR_ID:
1519 if (len != 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001520 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001521 break;
1522 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001523 ND_TCHECK2(tptr[0], 4);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001524 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001525 break;
1526 case BGPTYPE_CLUSTER_LIST:
1527 if (len % 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001528 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001529 break;
1530 }
1531 while (tlen>0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001532 ND_TCHECK2(tptr[0], 4);
1533 ND_PRINT((ndo, "%s%s",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001534 ipaddr_string(ndo, tptr),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001535 (tlen>4) ? ", " : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001536 tlen -=4;
1537 tptr +=4;
1538 }
1539 break;
1540 case BGPTYPE_MP_REACH_NLRI:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001541 ND_TCHECK2(tptr[0], 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001542 af = EXTRACT_16BITS(tptr);
1543 safi = tptr[2];
Elliott Hughes892a68b2015-10-19 14:43:53 -07001544
1545 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001546 tok2str(af_values, "Unknown AFI", af),
The Android Open Source Project2949f582009-03-03 19:30:46 -08001547 af,
1548 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001549 tok2str(bgp_safi_values, "Unknown SAFI", safi),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001550 safi));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001551
1552 switch(af<<8 | safi) {
1553 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1554 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1555 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1556 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1557 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1558 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1559 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1560 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
JP Abgrall53f17a92014-02-12 14:02:41 -08001561 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001562 case (AFNUM_INET<<8 | SAFNUM_MDT):
The Android Open Source Project2949f582009-03-03 19:30:46 -08001563 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1564 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1565 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1566 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
The Android Open Source Project2949f582009-03-03 19:30:46 -08001567 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1568 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1569 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
The Android Open Source Project2949f582009-03-03 19:30:46 -08001570 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1571 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1572 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1573 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1574 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1575 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1576 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1577 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1578 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1579 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1580 break;
1581 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001582 ND_TCHECK2(tptr[0], tlen);
1583 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1584 if (ndo->ndo_vflag <= 1)
1585 print_unknown_data(ndo, tptr, "\n\t ", tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001586 goto done;
1587 break;
1588 }
1589
1590 tptr +=3;
1591
Elliott Hughes892a68b2015-10-19 14:43:53 -07001592 ND_TCHECK(tptr[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001593 nhlen = tptr[0];
1594 tlen = nhlen;
1595 tptr++;
1596
1597 if (tlen) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001598 int nnh = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001599 ND_PRINT((ndo, "\n\t nexthop: "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001600 while (tlen > 0) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001601 if ( nnh++ > 0 ) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001602 ND_PRINT((ndo, ", " ));
JP Abgrall53f17a92014-02-12 14:02:41 -08001603 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001604 switch(af<<8 | safi) {
1605 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1606 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1607 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1608 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1609 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
JP Abgrall53f17a92014-02-12 14:02:41 -08001610 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001611 case (AFNUM_INET<<8 | SAFNUM_MDT):
JP Abgrall53f17a92014-02-12 14:02:41 -08001612 if (tlen < (int)sizeof(struct in_addr)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001613 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001614 tlen = 0;
1615 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001616 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001617 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001618 tlen -= sizeof(struct in_addr);
1619 tptr += sizeof(struct in_addr);
1620 }
1621 break;
1622 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1623 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1624 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1625 if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001626 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001627 tlen = 0;
1628 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001629 ND_TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1630 ND_PRINT((ndo, "RD: %s, %s",
1631 bgp_vpn_rd_print(ndo, tptr),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001632 ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001633 tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1634 tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1635 }
1636 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001637 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1638 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1639 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1640 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
The Android Open Source Project2949f582009-03-03 19:30:46 -08001641 if (tlen < (int)sizeof(struct in6_addr)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001642 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001643 tlen = 0;
1644 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001645 ND_TCHECK2(tptr[0], sizeof(struct in6_addr));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001646 ND_PRINT((ndo, "%s", ip6addr_string(ndo, tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001647 tlen -= sizeof(struct in6_addr);
1648 tptr += sizeof(struct in6_addr);
1649 }
1650 break;
1651 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1652 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1653 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1654 if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001655 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001656 tlen = 0;
1657 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001658 ND_TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1659 ND_PRINT((ndo, "RD: %s, %s",
1660 bgp_vpn_rd_print(ndo, tptr),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001661 ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001662 tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1663 tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1664 }
1665 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001666 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1667 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1668 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1669 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1670 if (tlen < (int)sizeof(struct in_addr)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001671 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001672 tlen = 0;
1673 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001674 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001675 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001676 tlen -= (sizeof(struct in_addr));
1677 tptr += (sizeof(struct in_addr));
1678 }
1679 break;
1680 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1681 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1682 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001683 ND_TCHECK2(tptr[0], tlen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001684 ND_PRINT((ndo, "%s", isonsap_string(ndo, tptr, tlen)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001685 tptr += tlen;
1686 tlen = 0;
1687 break;
1688
1689 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1690 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1691 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1692 if (tlen < BGP_VPN_RD_LEN+1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001693 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001694 tlen = 0;
1695 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001696 ND_TCHECK2(tptr[0], tlen);
1697 ND_PRINT((ndo, "RD: %s, %s",
1698 bgp_vpn_rd_print(ndo, tptr),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001699 isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001700 /* rfc986 mapped IPv4 address ? */
1701 if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601)
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001702 ND_PRINT((ndo, " = %s", ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN+4)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001703 /* rfc1888 mapped IPv6 address ? */
1704 else if (EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000)
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001705 ND_PRINT((ndo, " = %s", ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN+3)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001706 tptr += tlen;
1707 tlen = 0;
1708 }
1709 break;
1710 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001711 ND_TCHECK2(tptr[0], tlen);
1712 ND_PRINT((ndo, "no AFI %u/SAFI %u decoder", af, safi));
1713 if (ndo->ndo_vflag <= 1)
1714 print_unknown_data(ndo, tptr, "\n\t ", tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001715 tptr += tlen;
1716 tlen = 0;
1717 goto done;
1718 break;
1719 }
1720 }
1721 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001722 ND_PRINT((ndo, ", nh-length: %u", nhlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001723 tptr += tlen;
1724
Elliott Hughes892a68b2015-10-19 14:43:53 -07001725 ND_TCHECK(tptr[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001726 snpa = tptr[0];
1727 tptr++;
1728
1729 if (snpa) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001730 ND_PRINT((ndo, "\n\t %u SNPA", snpa));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001731 for (/*nothing*/; snpa > 0; snpa--) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001732 ND_TCHECK(tptr[0]);
1733 ND_PRINT((ndo, "\n\t %d bytes", tptr[0]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001734 tptr += tptr[0] + 1;
1735 }
1736 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001737 ND_PRINT((ndo, ", no SNPA"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001738 }
1739
Elliott Hughescec480a2017-12-19 16:54:57 -08001740 while (tptr < pptr + len) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001741 switch (af<<8 | safi) {
1742 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1743 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1744 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001745 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001746 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001747 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001748 else if (advance == -2)
1749 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001750 else if (advance == -3)
1751 break; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001752 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001753 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001754 break;
1755 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001756 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001757 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001758 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001759 else if (advance == -2)
1760 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001761 else if (advance == -3)
1762 break; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001763 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001764 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001765 break;
1766 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1767 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1768 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001769 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001770 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001771 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001772 else if (advance == -2)
1773 goto trunc;
1774 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001775 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001776 break;
1777 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001778 advance = decode_rt_routing_info(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001779 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001780 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001781 else if (advance == -2)
1782 goto trunc;
1783 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001784 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001785 break;
JP Abgrall53f17a92014-02-12 14:02:41 -08001786 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
1787 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001788 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001789 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001790 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001791 else if (advance == -2)
1792 goto trunc;
1793 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001794 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001795 break;
JP Abgrall53f17a92014-02-12 14:02:41 -08001796
1797 case (AFNUM_INET<<8 | SAFNUM_MDT):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001798 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08001799 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001800 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
JP Abgrall53f17a92014-02-12 14:02:41 -08001801 else if (advance == -2)
1802 goto trunc;
1803 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001804 ND_PRINT((ndo, "\n\t %s", buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08001805 break;
JP Abgrall53f17a92014-02-12 14:02:41 -08001806 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1807 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1808 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001809 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001810 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001811 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001812 else if (advance == -2)
1813 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001814 else if (advance == -3)
1815 break; /* bytes left, but not enough */
1816 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001817 ND_PRINT((ndo, "\n\t %s", buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08001818 break;
1819 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001820 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08001821 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001822 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
JP Abgrall53f17a92014-02-12 14:02:41 -08001823 else if (advance == -2)
1824 goto trunc;
1825 else if (advance == -3)
1826 break; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001827 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001828 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001829 break;
1830 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1831 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1832 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001833 advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001834 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001835 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001836 else if (advance == -2)
1837 goto trunc;
1838 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001839 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001840 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001841 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1842 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1843 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1844 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001845 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001846 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001847 ND_PRINT((ndo, "\n\t (illegal length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001848 else if (advance == -2)
1849 goto trunc;
1850 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001851 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001852 break;
1853 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1854 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1855 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001856 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001857 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001858 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001859 else if (advance == -2)
1860 goto trunc;
1861 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001862 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001863 break;
1864 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1865 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1866 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001867 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001868 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001869 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001870 else if (advance == -2)
1871 goto trunc;
1872 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001873 ND_PRINT((ndo, "\n\t %s", buf));
1874 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001875 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001876 ND_TCHECK2(*tptr,tlen);
1877 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1878 if (ndo->ndo_vflag <= 1)
1879 print_unknown_data(ndo, tptr, "\n\t ", tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001880 advance = 0;
1881 tptr = pptr + len;
1882 break;
1883 }
1884 if (advance < 0)
1885 break;
1886 tptr += advance;
1887 }
1888 done:
1889 break;
1890
1891 case BGPTYPE_MP_UNREACH_NLRI:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001892 ND_TCHECK2(tptr[0], BGP_MP_NLRI_MINSIZE);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001893 af = EXTRACT_16BITS(tptr);
1894 safi = tptr[2];
1895
Elliott Hughes892a68b2015-10-19 14:43:53 -07001896 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001897 tok2str(af_values, "Unknown AFI", af),
The Android Open Source Project2949f582009-03-03 19:30:46 -08001898 af,
1899 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001900 tok2str(bgp_safi_values, "Unknown SAFI", safi),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001901 safi));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001902
1903 if (len == BGP_MP_NLRI_MINSIZE)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001904 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001905
1906 tptr += 3;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001907
Elliott Hughescec480a2017-12-19 16:54:57 -08001908 while (tptr < pptr + len) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001909 switch (af<<8 | safi) {
1910 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1911 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1912 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001913 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001914 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001915 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001916 else if (advance == -2)
1917 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001918 else if (advance == -3)
1919 break; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001920 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001921 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001922 break;
1923 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001924 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001925 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001926 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001927 else if (advance == -2)
1928 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001929 else if (advance == -3)
1930 break; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001931 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001932 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001933 break;
1934 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1935 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1936 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001937 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001938 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001939 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001940 else if (advance == -2)
1941 goto trunc;
1942 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001943 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001944 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001945 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1946 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1947 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001948 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001949 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001950 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001951 else if (advance == -2)
1952 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001953 else if (advance == -3)
1954 break; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001955 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001956 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001957 break;
1958 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001959 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001960 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001961 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001962 else if (advance == -2)
1963 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001964 else if (advance == -3)
1965 break; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001966 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001967 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001968 break;
1969 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1970 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1971 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001972 advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001973 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001974 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001975 else if (advance == -2)
1976 goto trunc;
1977 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001978 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001979 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001980 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1981 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1982 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1983 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001984 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001985 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001986 ND_PRINT((ndo, "\n\t (illegal length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001987 else if (advance == -2)
1988 goto trunc;
1989 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001990 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001991 break;
1992 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1993 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1994 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001995 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001996 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001997 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001998 else if (advance == -2)
1999 goto trunc;
2000 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07002001 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002002 break;
2003 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
2004 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
2005 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
Elliott Hughes892a68b2015-10-19 14:43:53 -07002006 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002007 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07002008 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002009 else if (advance == -2)
2010 goto trunc;
2011 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07002012 ND_PRINT((ndo, "\n\t %s", buf));
2013 break;
JP Abgrall53f17a92014-02-12 14:02:41 -08002014 case (AFNUM_INET<<8 | SAFNUM_MDT):
Elliott Hughes892a68b2015-10-19 14:43:53 -07002015 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08002016 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07002017 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
JP Abgrall53f17a92014-02-12 14:02:41 -08002018 else if (advance == -2)
2019 goto trunc;
2020 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07002021 ND_PRINT((ndo, "\n\t %s", buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08002022 break;
2023 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
2024 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
Elliott Hughes892a68b2015-10-19 14:43:53 -07002025 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08002026 if (advance == -1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07002027 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
JP Abgrall53f17a92014-02-12 14:02:41 -08002028 else if (advance == -2)
2029 goto trunc;
2030 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07002031 ND_PRINT((ndo, "\n\t %s", buf));
JP Abgrall53f17a92014-02-12 14:02:41 -08002032 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002033 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002034 ND_TCHECK2(*(tptr-3),tlen);
2035 ND_PRINT((ndo, "no AFI %u / SAFI %u decoder", af, safi));
2036 if (ndo->ndo_vflag <= 1)
2037 print_unknown_data(ndo, tptr-3, "\n\t ", tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002038 advance = 0;
2039 tptr = pptr + len;
2040 break;
2041 }
2042 if (advance < 0)
2043 break;
2044 tptr += advance;
2045 }
2046 break;
2047 case BGPTYPE_EXTD_COMMUNITIES:
2048 if (len % 8) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002049 ND_PRINT((ndo, "invalid len"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002050 break;
2051 }
2052 while (tlen>0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002053 uint16_t extd_comm;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002054
Elliott Hughes892a68b2015-10-19 14:43:53 -07002055 ND_TCHECK2(tptr[0], 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002056 extd_comm=EXTRACT_16BITS(tptr);
2057
Elliott Hughes892a68b2015-10-19 14:43:53 -07002058 ND_PRINT((ndo, "\n\t %s (0x%04x), Flags [%s]",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002059 tok2str(bgp_extd_comm_subtype_values,
The Android Open Source Project2949f582009-03-03 19:30:46 -08002060 "unknown extd community typecode",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002061 extd_comm),
The Android Open Source Project2949f582009-03-03 19:30:46 -08002062 extd_comm,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002063 bittok2str(bgp_extd_comm_flag_values, "none", extd_comm)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002064
Elliott Hughes892a68b2015-10-19 14:43:53 -07002065 ND_TCHECK2(*(tptr+2), 6);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002066 switch(extd_comm) {
2067 case BGP_EXT_COM_RT_0:
2068 case BGP_EXT_COM_RO_0:
JP Abgrall53f17a92014-02-12 14:02:41 -08002069 case BGP_EXT_COM_L2VPN_RT_0:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002070 ND_PRINT((ndo, ": %u:%u (= %s)",
The Android Open Source Project2949f582009-03-03 19:30:46 -08002071 EXTRACT_16BITS(tptr+2),
JP Abgrall53f17a92014-02-12 14:02:41 -08002072 EXTRACT_32BITS(tptr+4),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002073 ipaddr_string(ndo, tptr+4)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002074 break;
2075 case BGP_EXT_COM_RT_1:
2076 case BGP_EXT_COM_RO_1:
JP Abgrall53f17a92014-02-12 14:02:41 -08002077 case BGP_EXT_COM_L2VPN_RT_1:
2078 case BGP_EXT_COM_VRF_RT_IMP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002079 ND_PRINT((ndo, ": %s:%u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002080 ipaddr_string(ndo, tptr+2),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002081 EXTRACT_16BITS(tptr+6)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002082 break;
2083 case BGP_EXT_COM_RT_2:
2084 case BGP_EXT_COM_RO_2:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002085 ND_PRINT((ndo, ": %s:%u",
2086 as_printf(ndo, astostr, sizeof(astostr),
2087 EXTRACT_32BITS(tptr+2)), EXTRACT_16BITS(tptr+6)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002088 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002089 case BGP_EXT_COM_LINKBAND:
2090 bw.i = EXTRACT_32BITS(tptr+2);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002091 ND_PRINT((ndo, ": bandwidth: %.3f Mbps",
2092 bw.f*8/1000000));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002093 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002094 case BGP_EXT_COM_VPN_ORIGIN:
2095 case BGP_EXT_COM_VPN_ORIGIN2:
2096 case BGP_EXT_COM_VPN_ORIGIN3:
2097 case BGP_EXT_COM_VPN_ORIGIN4:
2098 case BGP_EXT_COM_OSPF_RID:
2099 case BGP_EXT_COM_OSPF_RID2:
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002100 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr+2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002101 break;
2102 case BGP_EXT_COM_OSPF_RTYPE:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002103 case BGP_EXT_COM_OSPF_RTYPE2:
2104 ND_PRINT((ndo, ": area:%s, router-type:%s, metric-type:%s%s",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002105 ipaddr_string(ndo, tptr+2),
2106 tok2str(bgp_extd_comm_ospf_rtype_values,
The Android Open Source Project2949f582009-03-03 19:30:46 -08002107 "unknown (0x%02x)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002108 *(tptr+6)),
The Android Open Source Project2949f582009-03-03 19:30:46 -08002109 (*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
Elliott Hughes892a68b2015-10-19 14:43:53 -07002110 ((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002111 break;
2112 case BGP_EXT_COM_L2INFO:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002113 ND_PRINT((ndo, ": %s Control Flags [0x%02x]:MTU %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002114 tok2str(l2vpn_encaps_values,
The Android Open Source Project2949f582009-03-03 19:30:46 -08002115 "unknown encaps",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002116 *(tptr+2)),
The Android Open Source Project2949f582009-03-03 19:30:46 -08002117 *(tptr+3),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002118 EXTRACT_16BITS(tptr+4)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002119 break;
JP Abgrall53f17a92014-02-12 14:02:41 -08002120 case BGP_EXT_COM_SOURCE_AS:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002121 ND_PRINT((ndo, ": AS %u", EXTRACT_16BITS(tptr+2)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002122 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002123 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002124 ND_TCHECK2(*tptr,8);
2125 print_unknown_data(ndo, tptr, "\n\t ", 8);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002126 break;
2127 }
2128 tlen -=8;
2129 tptr +=8;
2130 }
2131 break;
2132
JP Abgrall53f17a92014-02-12 14:02:41 -08002133 case BGPTYPE_PMSI_TUNNEL:
2134 {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002135 uint8_t tunnel_type, flags;
2136
Elliott Hughescec480a2017-12-19 16:54:57 -08002137 ND_TCHECK2(tptr[0], 5);
JP Abgrall53f17a92014-02-12 14:02:41 -08002138 tunnel_type = *(tptr+1);
2139 flags = *tptr;
2140 tlen = len;
2141
Elliott Hughes892a68b2015-10-19 14:43:53 -07002142 ND_PRINT((ndo, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
JP Abgrall53f17a92014-02-12 14:02:41 -08002143 tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type),
2144 tunnel_type,
2145 bittok2str(bgp_pmsi_flag_values, "none", flags),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002146 EXTRACT_24BITS(tptr+2)>>4));
JP Abgrall53f17a92014-02-12 14:02:41 -08002147
2148 tptr +=5;
2149 tlen -= 5;
2150
2151 switch (tunnel_type) {
2152 case BGP_PMSI_TUNNEL_PIM_SM: /* fall through */
2153 case BGP_PMSI_TUNNEL_PIM_BIDIR:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002154 ND_TCHECK2(tptr[0], 8);
2155 ND_PRINT((ndo, "\n\t Sender %s, P-Group %s",
2156 ipaddr_string(ndo, tptr),
2157 ipaddr_string(ndo, tptr+4)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002158 break;
2159
2160 case BGP_PMSI_TUNNEL_PIM_SSM:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002161 ND_TCHECK2(tptr[0], 8);
2162 ND_PRINT((ndo, "\n\t Root-Node %s, P-Group %s",
2163 ipaddr_string(ndo, tptr),
2164 ipaddr_string(ndo, tptr+4)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002165 break;
2166 case BGP_PMSI_TUNNEL_INGRESS:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002167 ND_TCHECK2(tptr[0], 4);
2168 ND_PRINT((ndo, "\n\t Tunnel-Endpoint %s",
2169 ipaddr_string(ndo, tptr)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002170 break;
2171 case BGP_PMSI_TUNNEL_LDP_P2MP: /* fall through */
2172 case BGP_PMSI_TUNNEL_LDP_MP2MP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002173 ND_TCHECK2(tptr[0], 8);
2174 ND_PRINT((ndo, "\n\t Root-Node %s, LSP-ID 0x%08x",
2175 ipaddr_string(ndo, tptr),
2176 EXTRACT_32BITS(tptr+4)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002177 break;
2178 case BGP_PMSI_TUNNEL_RSVP_P2MP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002179 ND_TCHECK2(tptr[0], 8);
2180 ND_PRINT((ndo, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2181 ipaddr_string(ndo, tptr),
2182 EXTRACT_32BITS(tptr+4)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002183 break;
2184 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002185 if (ndo->ndo_vflag <= 1) {
2186 print_unknown_data(ndo, tptr, "\n\t ", tlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08002187 }
2188 }
2189 break;
2190 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002191 case BGPTYPE_AIGP:
2192 {
2193 uint8_t type;
2194 uint16_t length;
2195
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002196 tlen = len;
2197
2198 while (tlen >= 3) {
2199
Elliott Hughescec480a2017-12-19 16:54:57 -08002200 ND_TCHECK2(tptr[0], 3);
2201
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002202 type = *tptr;
2203 length = EXTRACT_16BITS(tptr+1);
Elliott Hughescec480a2017-12-19 16:54:57 -08002204 tptr += 3;
2205 tlen -= 3;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002206
2207 ND_PRINT((ndo, "\n\t %s TLV (%u), length %u",
2208 tok2str(bgp_aigp_values, "Unknown", type),
2209 type, length));
2210
Elliott Hughescec480a2017-12-19 16:54:57 -08002211 if (length < 3)
2212 goto trunc;
2213 length -= 3;
2214
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002215 /*
2216 * Check if we can read the TLV data.
2217 */
Elliott Hughescec480a2017-12-19 16:54:57 -08002218 ND_TCHECK2(tptr[3], length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002219
2220 switch (type) {
2221
2222 case BGP_AIGP_TLV:
Elliott Hughescec480a2017-12-19 16:54:57 -08002223 if (length < 8)
2224 goto trunc;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002225 ND_PRINT((ndo, ", metric %" PRIu64,
Elliott Hughescec480a2017-12-19 16:54:57 -08002226 EXTRACT_64BITS(tptr)));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002227 break;
2228
2229 default:
2230 if (ndo->ndo_vflag <= 1) {
Elliott Hughescec480a2017-12-19 16:54:57 -08002231 print_unknown_data(ndo, tptr,"\n\t ", length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002232 }
2233 }
2234
2235 tptr += length;
2236 tlen -= length;
2237 }
2238 break;
2239 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08002240 case BGPTYPE_ATTR_SET:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002241 ND_TCHECK2(tptr[0], 4);
JP Abgrall53f17a92014-02-12 14:02:41 -08002242 if (len < 4)
2243 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002244 ND_PRINT((ndo, "\n\t Origin AS: %s",
2245 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr))));
JP Abgrall53f17a92014-02-12 14:02:41 -08002246 tptr+=4;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002247 len -=4;
2248
JP Abgrall53f17a92014-02-12 14:02:41 -08002249 while (len) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002250 u_int aflags, alenlen, alen;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002251
2252 ND_TCHECK2(tptr[0], 2);
JP Abgrall53f17a92014-02-12 14:02:41 -08002253 if (len < 2)
2254 goto trunc;
2255 aflags = *tptr;
2256 atype = *(tptr + 1);
2257 tptr += 2;
2258 len -= 2;
2259 alenlen = bgp_attr_lenlen(aflags, tptr);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002260 ND_TCHECK2(tptr[0], alenlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08002261 if (len < alenlen)
2262 goto trunc;
2263 alen = bgp_attr_len(aflags, tptr);
2264 tptr += alenlen;
2265 len -= alenlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002266
2267 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002268 tok2str(bgp_attr_values,
2269 "Unknown Attribute", atype),
JP Abgrall53f17a92014-02-12 14:02:41 -08002270 atype,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002271 alen));
2272
JP Abgrall53f17a92014-02-12 14:02:41 -08002273 if (aflags) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002274 ND_PRINT((ndo, ", Flags [%s%s%s%s",
JP Abgrall53f17a92014-02-12 14:02:41 -08002275 aflags & 0x80 ? "O" : "",
2276 aflags & 0x40 ? "T" : "",
2277 aflags & 0x20 ? "P" : "",
Elliott Hughes892a68b2015-10-19 14:43:53 -07002278 aflags & 0x10 ? "E" : ""));
JP Abgrall53f17a92014-02-12 14:02:41 -08002279 if (aflags & 0xf)
Elliott Hughes892a68b2015-10-19 14:43:53 -07002280 ND_PRINT((ndo, "+%x", aflags & 0xf));
2281 ND_PRINT((ndo, "]: "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002282 }
2283 /* FIXME check for recursion */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002284 if (!bgp_attr_print(ndo, atype, tptr, alen))
The Android Open Source Project2949f582009-03-03 19:30:46 -08002285 return 0;
2286 tptr += alen;
2287 len -= alen;
2288 }
2289 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002290
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002291 case BGPTYPE_LARGE_COMMUNITY:
2292 if (len == 0 || len % 12) {
2293 ND_PRINT((ndo, "invalid len"));
2294 break;
2295 }
2296 ND_PRINT((ndo, "\n\t "));
2297 while (len > 0) {
2298 ND_TCHECK2(*tptr, 12);
2299 ND_PRINT((ndo, "%u:%u:%u%s",
2300 EXTRACT_32BITS(tptr),
2301 EXTRACT_32BITS(tptr + 4),
2302 EXTRACT_32BITS(tptr + 8),
2303 (len > 12) ? ", " : ""));
2304 tptr += 12;
2305 len -= 12;
2306 }
2307 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002308 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002309 ND_TCHECK2(*pptr,len);
2310 ND_PRINT((ndo, "\n\t no Attribute %u decoder", atype)); /* we have no decoder for the attribute */
2311 if (ndo->ndo_vflag <= 1)
2312 print_unknown_data(ndo, pptr, "\n\t ", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002313 break;
2314 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002315 if (ndo->ndo_vflag > 1 && len) { /* omit zero length attributes*/
2316 ND_TCHECK2(*pptr,len);
2317 print_unknown_data(ndo, pptr, "\n\t ", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002318 }
2319 return 1;
2320
2321trunc:
2322 return 0;
2323}
2324
2325static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07002326bgp_capabilities_print(netdissect_options *ndo,
2327 const u_char *opt, int caps_len)
JP Abgrall53f17a92014-02-12 14:02:41 -08002328{
JP Abgrall53f17a92014-02-12 14:02:41 -08002329 int cap_type, cap_len, tcap_len, cap_offset;
2330 int i = 0;
2331
2332 while (i < caps_len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002333 ND_TCHECK2(opt[i], BGP_CAP_HEADER_SIZE);
JP Abgrall53f17a92014-02-12 14:02:41 -08002334 cap_type=opt[i];
2335 cap_len=opt[i+1];
2336 tcap_len=cap_len;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002337 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002338 tok2str(bgp_capcode_values, "Unknown",
2339 cap_type),
JP Abgrall53f17a92014-02-12 14:02:41 -08002340 cap_type,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002341 cap_len));
2342 ND_TCHECK2(opt[i+2], cap_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002343 switch (cap_type) {
2344 case BGP_CAPCODE_MP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002345 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002346 tok2str(af_values, "Unknown",
2347 EXTRACT_16BITS(opt+i+2)),
JP Abgrall53f17a92014-02-12 14:02:41 -08002348 EXTRACT_16BITS(opt+i+2),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002349 tok2str(bgp_safi_values, "Unknown",
2350 opt[i+5]),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002351 opt[i+5]));
JP Abgrall53f17a92014-02-12 14:02:41 -08002352 break;
2353 case BGP_CAPCODE_RESTART:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002354 ND_PRINT((ndo, "\n\t\tRestart Flags: [%s], Restart Time %us",
JP Abgrall53f17a92014-02-12 14:02:41 -08002355 ((opt[i+2])&0x80) ? "R" : "none",
Elliott Hughes892a68b2015-10-19 14:43:53 -07002356 EXTRACT_16BITS(opt+i+2)&0xfff));
JP Abgrall53f17a92014-02-12 14:02:41 -08002357 tcap_len-=2;
2358 cap_offset=4;
2359 while(tcap_len>=4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002360 ND_PRINT((ndo, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002361 tok2str(af_values,"Unknown",
2362 EXTRACT_16BITS(opt+i+cap_offset)),
JP Abgrall53f17a92014-02-12 14:02:41 -08002363 EXTRACT_16BITS(opt+i+cap_offset),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002364 tok2str(bgp_safi_values,"Unknown",
2365 opt[i+cap_offset+2]),
JP Abgrall53f17a92014-02-12 14:02:41 -08002366 opt[i+cap_offset+2],
Elliott Hughes892a68b2015-10-19 14:43:53 -07002367 ((opt[i+cap_offset+3])&0x80) ? "yes" : "no" ));
JP Abgrall53f17a92014-02-12 14:02:41 -08002368 tcap_len-=4;
2369 cap_offset+=4;
2370 }
2371 break;
2372 case BGP_CAPCODE_RR:
2373 case BGP_CAPCODE_RR_CISCO:
2374 break;
2375 case BGP_CAPCODE_AS_NEW:
2376
2377 /*
2378 * Extract the 4 byte AS number encoded.
2379 */
2380 if (cap_len == 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002381 ND_PRINT((ndo, "\n\t\t 4 Byte AS %s",
2382 as_printf(ndo, astostr, sizeof(astostr),
2383 EXTRACT_32BITS(opt + i + 2))));
JP Abgrall53f17a92014-02-12 14:02:41 -08002384 }
2385 break;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002386 case BGP_CAPCODE_ADD_PATH:
2387 cap_offset=2;
2388 if (tcap_len == 0) {
2389 ND_PRINT((ndo, " (bogus)")); /* length */
2390 break;
2391 }
2392 while (tcap_len > 0) {
2393 if (tcap_len < 4) {
2394 ND_PRINT((ndo, "\n\t\t(invalid)"));
2395 break;
2396 }
2397 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2398 tok2str(af_values,"Unknown",EXTRACT_16BITS(opt+i+cap_offset)),
2399 EXTRACT_16BITS(opt+i+cap_offset),
2400 tok2str(bgp_safi_values,"Unknown",opt[i+cap_offset+2]),
2401 opt[i+cap_offset+2],
2402 tok2str(bgp_add_path_recvsend,"Bogus (0x%02x)",opt[i+cap_offset+3])
2403 ));
2404 tcap_len-=4;
2405 cap_offset+=4;
2406 }
2407 break;
JP Abgrall53f17a92014-02-12 14:02:41 -08002408 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002409 ND_PRINT((ndo, "\n\t\tno decoder for Capability %u",
2410 cap_type));
2411 if (ndo->ndo_vflag <= 1)
2412 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002413 break;
2414 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002415 if (ndo->ndo_vflag > 1 && cap_len > 0) {
2416 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002417 }
2418 i += BGP_CAP_HEADER_SIZE + cap_len;
2419 }
2420 return;
2421
2422trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002423 ND_PRINT((ndo, "[|BGP]"));
JP Abgrall53f17a92014-02-12 14:02:41 -08002424}
2425
2426static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07002427bgp_open_print(netdissect_options *ndo,
2428 const u_char *dat, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002429{
2430 struct bgp_open bgpo;
2431 struct bgp_opt bgpopt;
2432 const u_char *opt;
JP Abgrall53f17a92014-02-12 14:02:41 -08002433 int i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002434
Elliott Hughes892a68b2015-10-19 14:43:53 -07002435 ND_TCHECK2(dat[0], BGP_OPEN_SIZE);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002436 memcpy(&bgpo, dat, BGP_OPEN_SIZE);
2437
Elliott Hughes892a68b2015-10-19 14:43:53 -07002438 ND_PRINT((ndo, "\n\t Version %d, ", bgpo.bgpo_version));
2439 ND_PRINT((ndo, "my AS %s, ",
2440 as_printf(ndo, astostr, sizeof(astostr), ntohs(bgpo.bgpo_myas))));
2441 ND_PRINT((ndo, "Holdtime %us, ", ntohs(bgpo.bgpo_holdtime)));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002442 ND_PRINT((ndo, "ID %s", ipaddr_string(ndo, &bgpo.bgpo_id)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002443 ND_PRINT((ndo, "\n\t Optional parameters, length: %u", bgpo.bgpo_optlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002444
2445 /* some little sanity checking */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002446 if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002447 return;
2448
2449 /* ugly! */
2450 opt = &((const struct bgp_open *)dat)->bgpo_optlen;
2451 opt++;
2452
2453 i = 0;
2454 while (i < bgpo.bgpo_optlen) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002455 ND_TCHECK2(opt[i], BGP_OPT_SIZE);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002456 memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE);
2457 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002458 ND_PRINT((ndo, "\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002459 break;
2460 }
2461
Elliott Hughes892a68b2015-10-19 14:43:53 -07002462 ND_PRINT((ndo, "\n\t Option %s (%u), length: %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002463 tok2str(bgp_opt_values,"Unknown",
2464 bgpopt.bgpopt_type),
JP Abgrall53f17a92014-02-12 14:02:41 -08002465 bgpopt.bgpopt_type,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002466 bgpopt.bgpopt_len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002467
JP Abgrall53f17a92014-02-12 14:02:41 -08002468 /* now let's decode the options we know*/
2469 switch(bgpopt.bgpopt_type) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08002470
JP Abgrall53f17a92014-02-12 14:02:41 -08002471 case BGP_OPT_CAP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002472 bgp_capabilities_print(ndo, &opt[i+BGP_OPT_SIZE],
JP Abgrall53f17a92014-02-12 14:02:41 -08002473 bgpopt.bgpopt_len);
2474 break;
2475
2476 case BGP_OPT_AUTH:
2477 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002478 ND_PRINT((ndo, "\n\t no decoder for option %u",
2479 bgpopt.bgpopt_type));
JP Abgrall53f17a92014-02-12 14:02:41 -08002480 break;
2481 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08002482 i += BGP_OPT_SIZE + bgpopt.bgpopt_len;
2483 }
2484 return;
2485trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002486 ND_PRINT((ndo, "[|BGP]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002487}
2488
2489static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07002490bgp_update_print(netdissect_options *ndo,
2491 const u_char *dat, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002492{
2493 struct bgp bgp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002494 const u_char *p;
JP Abgrall53f17a92014-02-12 14:02:41 -08002495 int withdrawn_routes_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002496 int len;
2497 int i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002498
Elliott Hughes892a68b2015-10-19 14:43:53 -07002499 ND_TCHECK2(dat[0], BGP_SIZE);
JP Abgrall53f17a92014-02-12 14:02:41 -08002500 if (length < BGP_SIZE)
2501 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002502 memcpy(&bgp, dat, BGP_SIZE);
2503 p = dat + BGP_SIZE; /*XXX*/
JP Abgrall53f17a92014-02-12 14:02:41 -08002504 length -= BGP_SIZE;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002505
2506 /* Unfeasible routes */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002507 ND_TCHECK2(p[0], 2);
JP Abgrall53f17a92014-02-12 14:02:41 -08002508 if (length < 2)
2509 goto trunc;
2510 withdrawn_routes_len = EXTRACT_16BITS(p);
2511 p += 2;
2512 length -= 2;
2513 if (withdrawn_routes_len) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08002514 /*
2515 * Without keeping state from the original NLRI message,
2516 * it's not possible to tell if this a v4 or v6 route,
2517 * so only try to decode it if we're not v6 enabled.
2518 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002519 ND_TCHECK2(p[0], withdrawn_routes_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002520 if (length < withdrawn_routes_len)
2521 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002522 ND_PRINT((ndo, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len));
JP Abgrall53f17a92014-02-12 14:02:41 -08002523 p += withdrawn_routes_len;
2524 length -= withdrawn_routes_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002525 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08002526
Elliott Hughes892a68b2015-10-19 14:43:53 -07002527 ND_TCHECK2(p[0], 2);
JP Abgrall53f17a92014-02-12 14:02:41 -08002528 if (length < 2)
2529 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002530 len = EXTRACT_16BITS(p);
JP Abgrall53f17a92014-02-12 14:02:41 -08002531 p += 2;
2532 length -= 2;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002533
JP Abgrall53f17a92014-02-12 14:02:41 -08002534 if (withdrawn_routes_len == 0 && len == 0 && length == 0) {
2535 /* No withdrawn routes, no path attributes, no NLRI */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002536 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002537 return;
2538 }
2539
2540 if (len) {
2541 /* do something more useful!*/
JP Abgrall53f17a92014-02-12 14:02:41 -08002542 while (len) {
2543 int aflags, atype, alenlen, alen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002544
Elliott Hughes892a68b2015-10-19 14:43:53 -07002545 ND_TCHECK2(p[0], 2);
JP Abgrall53f17a92014-02-12 14:02:41 -08002546 if (len < 2)
2547 goto trunc;
2548 if (length < 2)
2549 goto trunc;
2550 aflags = *p;
2551 atype = *(p + 1);
2552 p += 2;
2553 len -= 2;
2554 length -= 2;
2555 alenlen = bgp_attr_lenlen(aflags, p);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002556 ND_TCHECK2(p[0], alenlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08002557 if (len < alenlen)
2558 goto trunc;
2559 if (length < alenlen)
2560 goto trunc;
2561 alen = bgp_attr_len(aflags, p);
2562 p += alenlen;
2563 len -= alenlen;
2564 length -= alenlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002565
Elliott Hughes892a68b2015-10-19 14:43:53 -07002566 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002567 tok2str(bgp_attr_values, "Unknown Attribute",
2568 atype),
JP Abgrall53f17a92014-02-12 14:02:41 -08002569 atype,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002570 alen));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002571
JP Abgrall53f17a92014-02-12 14:02:41 -08002572 if (aflags) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002573 ND_PRINT((ndo, ", Flags [%s%s%s%s",
JP Abgrall53f17a92014-02-12 14:02:41 -08002574 aflags & 0x80 ? "O" : "",
2575 aflags & 0x40 ? "T" : "",
2576 aflags & 0x20 ? "P" : "",
Elliott Hughes892a68b2015-10-19 14:43:53 -07002577 aflags & 0x10 ? "E" : ""));
JP Abgrall53f17a92014-02-12 14:02:41 -08002578 if (aflags & 0xf)
Elliott Hughes892a68b2015-10-19 14:43:53 -07002579 ND_PRINT((ndo, "+%x", aflags & 0xf));
2580 ND_PRINT((ndo, "]: "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002581 }
JP Abgrall53f17a92014-02-12 14:02:41 -08002582 if (len < alen)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002583 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08002584 if (length < alen)
2585 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002586 if (!bgp_attr_print(ndo, atype, p, alen))
JP Abgrall53f17a92014-02-12 14:02:41 -08002587 goto trunc;
2588 p += alen;
2589 len -= alen;
2590 length -= alen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002591 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002592 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08002593
JP Abgrall53f17a92014-02-12 14:02:41 -08002594 if (length) {
2595 /*
2596 * XXX - what if they're using the "Advertisement of
2597 * Multiple Paths in BGP" feature:
2598 *
2599 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2600 *
2601 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2602 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002603 ND_PRINT((ndo, "\n\t Updated routes:"));
JP Abgrall53f17a92014-02-12 14:02:41 -08002604 while (length) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08002605 char buf[MAXHOSTNAMELEN + 100];
Elliott Hughes892a68b2015-10-19 14:43:53 -07002606 i = decode_prefix4(ndo, p, length, buf, sizeof(buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002607 if (i == -1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002608 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002609 break;
2610 } else if (i == -2)
2611 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08002612 else if (i == -3)
2613 goto trunc; /* bytes left, but not enough */
The Android Open Source Project2949f582009-03-03 19:30:46 -08002614 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002615 ND_PRINT((ndo, "\n\t %s", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002616 p += i;
JP Abgrall53f17a92014-02-12 14:02:41 -08002617 length -= i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002618 }
2619 }
2620 }
2621 return;
2622trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002623 ND_PRINT((ndo, "[|BGP]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002624}
2625
2626static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07002627bgp_notification_print(netdissect_options *ndo,
2628 const u_char *dat, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002629{
2630 struct bgp_notification bgpn;
2631 const u_char *tptr;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002632
Elliott Hughes892a68b2015-10-19 14:43:53 -07002633 ND_TCHECK2(dat[0], BGP_NOTIFICATION_SIZE);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002634 memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE);
2635
2636 /* some little sanity checking */
2637 if (length<BGP_NOTIFICATION_SIZE)
2638 return;
2639
Elliott Hughes892a68b2015-10-19 14:43:53 -07002640 ND_PRINT((ndo, ", %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002641 tok2str(bgp_notify_major_values, "Unknown Error",
2642 bgpn.bgpn_major),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002643 bgpn.bgpn_major));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002644
2645 switch (bgpn.bgpn_major) {
2646
2647 case BGP_NOTIFY_MAJOR_MSG:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002648 ND_PRINT((ndo, ", subcode %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002649 tok2str(bgp_notify_minor_msg_values, "Unknown",
2650 bgpn.bgpn_minor),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002651 bgpn.bgpn_minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002652 break;
2653 case BGP_NOTIFY_MAJOR_OPEN:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002654 ND_PRINT((ndo, ", subcode %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002655 tok2str(bgp_notify_minor_open_values, "Unknown",
2656 bgpn.bgpn_minor),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002657 bgpn.bgpn_minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002658 break;
2659 case BGP_NOTIFY_MAJOR_UPDATE:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002660 ND_PRINT((ndo, ", subcode %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002661 tok2str(bgp_notify_minor_update_values, "Unknown",
2662 bgpn.bgpn_minor),
2663 bgpn.bgpn_minor));
2664 break;
2665 case BGP_NOTIFY_MAJOR_FSM:
2666 ND_PRINT((ndo, " subcode %s (%u)",
2667 tok2str(bgp_notify_minor_fsm_values, "Unknown",
2668 bgpn.bgpn_minor),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002669 bgpn.bgpn_minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002670 break;
2671 case BGP_NOTIFY_MAJOR_CAP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002672 ND_PRINT((ndo, " subcode %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002673 tok2str(bgp_notify_minor_cap_values, "Unknown",
2674 bgpn.bgpn_minor),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002675 bgpn.bgpn_minor));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002676 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002677 case BGP_NOTIFY_MAJOR_CEASE:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002678 ND_PRINT((ndo, ", subcode %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002679 tok2str(bgp_notify_minor_cease_values, "Unknown",
2680 bgpn.bgpn_minor),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002681 bgpn.bgpn_minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002682
2683 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2684 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2685 */
2686 if(bgpn.bgpn_minor == BGP_NOTIFY_MINOR_CEASE_MAXPRFX && length >= BGP_NOTIFICATION_SIZE + 7) {
2687 tptr = dat + BGP_NOTIFICATION_SIZE;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002688 ND_TCHECK2(*tptr, 7);
2689 ND_PRINT((ndo, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002690 tok2str(af_values, "Unknown",
2691 EXTRACT_16BITS(tptr)),
The Android Open Source Project2949f582009-03-03 19:30:46 -08002692 EXTRACT_16BITS(tptr),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002693 tok2str(bgp_safi_values, "Unknown", *(tptr+2)),
The Android Open Source Project2949f582009-03-03 19:30:46 -08002694 *(tptr+2),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002695 EXTRACT_32BITS(tptr+3)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002696 }
2697 break;
2698 default:
2699 break;
2700 }
2701
2702 return;
2703trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002704 ND_PRINT((ndo, "[|BGP]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002705}
2706
2707static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07002708bgp_route_refresh_print(netdissect_options *ndo,
2709 const u_char *pptr, int len)
2710{
The Android Open Source Project2949f582009-03-03 19:30:46 -08002711 const struct bgp_route_refresh *bgp_route_refresh_header;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002712
Elliott Hughes892a68b2015-10-19 14:43:53 -07002713 ND_TCHECK2(pptr[0], BGP_ROUTE_REFRESH_SIZE);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002714
2715 /* some little sanity checking */
2716 if (len<BGP_ROUTE_REFRESH_SIZE)
2717 return;
2718
2719 bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
2720
Elliott Hughes892a68b2015-10-19 14:43:53 -07002721 ND_PRINT((ndo, "\n\t AFI %s (%u), SAFI %s (%u)",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002722 tok2str(af_values,"Unknown",
The Android Open Source Project2949f582009-03-03 19:30:46 -08002723 /* this stinks but the compiler pads the structure
2724 * weird */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002725 EXTRACT_16BITS(&bgp_route_refresh_header->afi)),
The Android Open Source Project2949f582009-03-03 19:30:46 -08002726 EXTRACT_16BITS(&bgp_route_refresh_header->afi),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002727 tok2str(bgp_safi_values,"Unknown",
2728 bgp_route_refresh_header->safi),
Elliott Hughes892a68b2015-10-19 14:43:53 -07002729 bgp_route_refresh_header->safi));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002730
Elliott Hughes892a68b2015-10-19 14:43:53 -07002731 if (ndo->ndo_vflag > 1) {
2732 ND_TCHECK2(*pptr, len);
2733 print_unknown_data(ndo, pptr, "\n\t ", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002734 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002735
The Android Open Source Project2949f582009-03-03 19:30:46 -08002736 return;
2737trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002738 ND_PRINT((ndo, "[|BGP]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002739}
2740
2741static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07002742bgp_header_print(netdissect_options *ndo,
2743 const u_char *dat, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002744{
2745 struct bgp bgp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002746
Elliott Hughes892a68b2015-10-19 14:43:53 -07002747 ND_TCHECK2(dat[0], BGP_SIZE);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002748 memcpy(&bgp, dat, BGP_SIZE);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002749 ND_PRINT((ndo, "\n\t%s Message (%u), length: %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002750 tok2str(bgp_msg_values, "Unknown", bgp.bgp_type),
The Android Open Source Project2949f582009-03-03 19:30:46 -08002751 bgp.bgp_type,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002752 length));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002753
2754 switch (bgp.bgp_type) {
2755 case BGP_OPEN:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002756 bgp_open_print(ndo, dat, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002757 break;
2758 case BGP_UPDATE:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002759 bgp_update_print(ndo, dat, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002760 break;
2761 case BGP_NOTIFICATION:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002762 bgp_notification_print(ndo, dat, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002763 break;
2764 case BGP_KEEPALIVE:
2765 break;
2766 case BGP_ROUTE_REFRESH:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002767 bgp_route_refresh_print(ndo, dat, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002768 break;
2769 default:
2770 /* we have no decoder for the BGP message */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002771 ND_TCHECK2(*dat, length);
2772 ND_PRINT((ndo, "\n\t no Message %u decoder", bgp.bgp_type));
2773 print_unknown_data(ndo, dat, "\n\t ", length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002774 break;
2775 }
2776 return 1;
2777trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002778 ND_PRINT((ndo, "[|BGP]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002779 return 0;
2780}
2781
2782void
Elliott Hughes892a68b2015-10-19 14:43:53 -07002783bgp_print(netdissect_options *ndo,
2784 const u_char *dat, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002785{
2786 const u_char *p;
2787 const u_char *ep;
2788 const u_char *start;
2789 const u_char marker[] = {
2790 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2791 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2792 };
2793 struct bgp bgp;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002794 uint16_t hlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002795
2796 ep = dat + length;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002797 if (ndo->ndo_snapend < dat + length)
2798 ep = ndo->ndo_snapend;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002799
Elliott Hughes892a68b2015-10-19 14:43:53 -07002800 ND_PRINT((ndo, ": BGP"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002801
Elliott Hughes892a68b2015-10-19 14:43:53 -07002802 if (ndo->ndo_vflag < 1) /* lets be less chatty */
The Android Open Source Project2949f582009-03-03 19:30:46 -08002803 return;
2804
2805 p = dat;
2806 start = p;
2807 while (p < ep) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002808 if (!ND_TTEST2(p[0], 1))
The Android Open Source Project2949f582009-03-03 19:30:46 -08002809 break;
2810 if (p[0] != 0xff) {
2811 p++;
2812 continue;
2813 }
2814
Elliott Hughes892a68b2015-10-19 14:43:53 -07002815 if (!ND_TTEST2(p[0], sizeof(marker)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08002816 break;
2817 if (memcmp(p, marker, sizeof(marker)) != 0) {
2818 p++;
2819 continue;
2820 }
2821
2822 /* found BGP header */
Elliott Hughes892a68b2015-10-19 14:43:53 -07002823 ND_TCHECK2(p[0], BGP_SIZE); /*XXX*/
The Android Open Source Project2949f582009-03-03 19:30:46 -08002824 memcpy(&bgp, p, BGP_SIZE);
2825
2826 if (start != p)
Elliott Hughes892a68b2015-10-19 14:43:53 -07002827 ND_PRINT((ndo, " [|BGP]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002828
2829 hlen = ntohs(bgp.bgp_len);
2830 if (hlen < BGP_SIZE) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002831 ND_PRINT((ndo, "\n[|BGP Bogus header length %u < %u]", hlen,
2832 BGP_SIZE));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002833 break;
2834 }
2835
Elliott Hughes892a68b2015-10-19 14:43:53 -07002836 if (ND_TTEST2(p[0], hlen)) {
2837 if (!bgp_header_print(ndo, p, hlen))
The Android Open Source Project2949f582009-03-03 19:30:46 -08002838 return;
2839 p += hlen;
2840 start = p;
2841 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002842 ND_PRINT((ndo, "\n[|BGP %s]",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002843 tok2str(bgp_msg_values,
The Android Open Source Project2949f582009-03-03 19:30:46 -08002844 "Unknown Message Type",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002845 bgp.bgp_type)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002846 break;
2847 }
2848 }
2849
2850 return;
2851
2852trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07002853 ND_PRINT((ndo, " [|BGP]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002854}
JP Abgrall53f17a92014-02-12 14:02:41 -08002855
2856/*
2857 * Local Variables:
2858 * c-style: whitesmith
2859 * c-basic-offset: 4
2860 * End:
2861 */