]> The Tcpdump Group git mirrors - tcpdump/blob - print-bgp.c
add support for the source-as and vrf-import extended communities as per draft-ietf...
[tcpdump] / print-bgp.c
1 /*
2 * Copyright (C) 1999 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * Extensively modified by Hannes Gredler (hannes@juniper.net) for more
30 * complete BGP support.
31 */
32
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
36
37 #ifndef lint
38 static const char rcsid[] _U_ =
39 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.105 2007-05-16 14:02:51 hannes Exp $";
40 #endif
41
42 #include <tcpdump-stdinc.h>
43
44 #include <stdio.h>
45 #include <string.h>
46
47 #include "interface.h"
48 #include "decode_prefix.h"
49 #include "addrtoname.h"
50 #include "extract.h"
51 #include "bgp.h"
52 #include "af.h"
53 #include "l2vpn.h"
54
55 struct bgp {
56 u_int8_t bgp_marker[16];
57 u_int16_t bgp_len;
58 u_int8_t bgp_type;
59 };
60 #define BGP_SIZE 19 /* unaligned */
61
62 #define BGP_OPEN 1
63 #define BGP_UPDATE 2
64 #define BGP_NOTIFICATION 3
65 #define BGP_KEEPALIVE 4
66 #define BGP_ROUTE_REFRESH 5
67
68 static struct tok bgp_msg_values[] = {
69 { BGP_OPEN, "Open"},
70 { BGP_UPDATE, "Update"},
71 { BGP_NOTIFICATION, "Notification"},
72 { BGP_KEEPALIVE, "Keepalive"},
73 { BGP_ROUTE_REFRESH, "Route Refresh"},
74 { 0, NULL}
75 };
76
77 struct bgp_open {
78 u_int8_t bgpo_marker[16];
79 u_int16_t bgpo_len;
80 u_int8_t bgpo_type;
81 u_int8_t bgpo_version;
82 u_int16_t bgpo_myas;
83 u_int16_t bgpo_holdtime;
84 u_int32_t bgpo_id;
85 u_int8_t bgpo_optlen;
86 /* options should follow */
87 };
88 #define BGP_OPEN_SIZE 29 /* unaligned */
89
90 struct bgp_opt {
91 u_int8_t bgpopt_type;
92 u_int8_t bgpopt_len;
93 /* variable length */
94 };
95 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
96
97 #define BGP_UPDATE_MINSIZE 23
98
99 struct bgp_notification {
100 u_int8_t bgpn_marker[16];
101 u_int16_t bgpn_len;
102 u_int8_t bgpn_type;
103 u_int8_t bgpn_major;
104 u_int8_t bgpn_minor;
105 };
106 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
107
108 struct bgp_route_refresh {
109 u_int8_t bgp_marker[16];
110 u_int16_t len;
111 u_int8_t type;
112 u_int8_t afi[2]; /* the compiler messes this structure up */
113 u_int8_t res; /* when doing misaligned sequences of int8 and int16 */
114 u_int8_t safi; /* afi should be int16 - so we have to access it using */
115 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
116 #define BGP_ROUTE_REFRESH_SIZE 23
117
118 struct bgp_attr {
119 u_int8_t bgpa_flags;
120 u_int8_t bgpa_type;
121 union {
122 u_int8_t len;
123 u_int16_t elen;
124 } bgpa_len;
125 #define bgp_attr_len(p) \
126 (((p)->bgpa_flags & 0x10) ? \
127 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
128 #define bgp_attr_off(p) \
129 (((p)->bgpa_flags & 0x10) ? 4 : 3)
130 };
131
132 #define BGPTYPE_ORIGIN 1
133 #define BGPTYPE_AS_PATH 2
134 #define BGPTYPE_NEXT_HOP 3
135 #define BGPTYPE_MULTI_EXIT_DISC 4
136 #define BGPTYPE_LOCAL_PREF 5
137 #define BGPTYPE_ATOMIC_AGGREGATE 6
138 #define BGPTYPE_AGGREGATOR 7
139 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
140 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
141 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
142 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
143 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
144 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
145 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
146 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
147 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
148 #define BGPTYPE_PMSI_TUNNEL 17 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
149 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
150
151 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
152
153 static struct tok bgp_attr_values[] = {
154 { BGPTYPE_ORIGIN, "Origin"},
155 { BGPTYPE_AS_PATH, "AS Path"},
156 { BGPTYPE_NEXT_HOP, "Next Hop"},
157 { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"},
158 { BGPTYPE_LOCAL_PREF, "Local Preference"},
159 { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"},
160 { BGPTYPE_AGGREGATOR, "Aggregator"},
161 { BGPTYPE_COMMUNITIES, "Community"},
162 { BGPTYPE_ORIGINATOR_ID, "Originator ID"},
163 { BGPTYPE_CLUSTER_LIST, "Cluster List"},
164 { BGPTYPE_DPA, "DPA"},
165 { BGPTYPE_ADVERTISERS, "Advertisers"},
166 { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"},
167 { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"},
168 { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"},
169 { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"},
170 { BGPTYPE_PMSI_TUNNEL, "PMSI Tunnel"},
171 { BGPTYPE_ATTR_SET, "Attribute Set"},
172 { 255, "Reserved for development"},
173 { 0, NULL}
174 };
175
176 #define BGP_AS_SET 1
177 #define BGP_AS_SEQUENCE 2
178 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
179 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
180
181 static struct tok bgp_as_path_segment_open_values[] = {
182 { BGP_AS_SEQUENCE, ""},
183 { BGP_AS_SET, "{ "},
184 { BGP_CONFED_AS_SEQUENCE, "( "},
185 { BGP_CONFED_AS_SET, "({ "},
186 { 0, NULL}
187 };
188
189 static struct tok bgp_as_path_segment_close_values[] = {
190 { BGP_AS_SEQUENCE, ""},
191 { BGP_AS_SET, "}"},
192 { BGP_CONFED_AS_SEQUENCE, ")"},
193 { BGP_CONFED_AS_SET, "})"},
194 { 0, NULL}
195 };
196
197 #define BGP_OPT_AUTH 1
198 #define BGP_OPT_CAP 2
199
200
201 static struct tok bgp_opt_values[] = {
202 { BGP_OPT_AUTH, "Authentication Information"},
203 { BGP_OPT_CAP, "Capabilities Advertisement"},
204 { 0, NULL}
205 };
206
207 #define BGP_CAPCODE_MP 1
208 #define BGP_CAPCODE_RR 2
209 #define BGP_CAPCODE_ORF 3 /* XXX */
210 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
211 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
212 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
213 #define BGP_CAPCODE_RR_CISCO 128
214
215 static struct tok bgp_capcode_values[] = {
216 { BGP_CAPCODE_MP, "Multiprotocol Extensions"},
217 { BGP_CAPCODE_RR, "Route Refresh"},
218 { BGP_CAPCODE_ORF, "Cooperative Route Filtering"},
219 { BGP_CAPCODE_RESTART, "Graceful Restart"},
220 { BGP_CAPCODE_AS_NEW, "32-Bit AS Number"},
221 { BGP_CAPCODE_DYN_CAP, "Dynamic Capability"},
222 { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"},
223 { 0, NULL}
224 };
225
226 #define BGP_NOTIFY_MAJOR_MSG 1
227 #define BGP_NOTIFY_MAJOR_OPEN 2
228 #define BGP_NOTIFY_MAJOR_UPDATE 3
229 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
230 #define BGP_NOTIFY_MAJOR_FSM 5
231 #define BGP_NOTIFY_MAJOR_CEASE 6
232 #define BGP_NOTIFY_MAJOR_CAP 7
233
234 static struct tok bgp_notify_major_values[] = {
235 { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"},
236 { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"},
237 { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"},
238 { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"},
239 { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"},
240 { BGP_NOTIFY_MAJOR_CEASE, "Cease"},
241 { BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"},
242 { 0, NULL}
243 };
244
245 /* draft-ietf-idr-cease-subcode-02 */
246 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
247 static struct tok bgp_notify_minor_cease_values[] = {
248 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"},
249 { 2, "Administratively Shutdown"},
250 { 3, "Peer Unconfigured"},
251 { 4, "Administratively Reset"},
252 { 5, "Connection Rejected"},
253 { 6, "Other Configuration Change"},
254 { 7, "Connection Collision Resolution"},
255 { 0, NULL}
256 };
257
258 static struct tok bgp_notify_minor_msg_values[] = {
259 { 1, "Connection Not Synchronized"},
260 { 2, "Bad Message Length"},
261 { 3, "Bad Message Type"},
262 { 0, NULL}
263 };
264
265 static struct tok bgp_notify_minor_open_values[] = {
266 { 1, "Unsupported Version Number"},
267 { 2, "Bad Peer AS"},
268 { 3, "Bad BGP Identifier"},
269 { 4, "Unsupported Optional Parameter"},
270 { 5, "Authentication Failure"},
271 { 6, "Unacceptable Hold Time"},
272 { 7, "Capability Message Error"},
273 { 0, NULL}
274 };
275
276 static struct tok bgp_notify_minor_update_values[] = {
277 { 1, "Malformed Attribute List"},
278 { 2, "Unrecognized Well-known Attribute"},
279 { 3, "Missing Well-known Attribute"},
280 { 4, "Attribute Flags Error"},
281 { 5, "Attribute Length Error"},
282 { 6, "Invalid ORIGIN Attribute"},
283 { 7, "AS Routing Loop"},
284 { 8, "Invalid NEXT_HOP Attribute"},
285 { 9, "Optional Attribute Error"},
286 { 10, "Invalid Network Field"},
287 { 11, "Malformed AS_PATH"},
288 { 0, NULL}
289 };
290
291 static struct tok bgp_notify_minor_cap_values[] = {
292 { 1, "Invalid Action Value" },
293 { 2, "Invalid Capability Length" },
294 { 3, "Malformed Capability Value" },
295 { 4, "Unsupported Capability Code" },
296 { 0, NULL }
297 };
298
299 static struct tok bgp_origin_values[] = {
300 { 0, "IGP"},
301 { 1, "EGP"},
302 { 2, "Incomplete"},
303 { 0, NULL}
304 };
305
306 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
307 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
308 #define BGP_PMSI_TUNNEL_PIM_SSM 3
309 #define BGP_PMSI_TUNNEL_PIM_SM 4
310 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
311 #define BGP_PMSI_TUNNEL_INGRESS 6
312 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
313
314 static struct tok bgp_pmsi_tunnel_values[] = {
315 { BGP_PMSI_TUNNEL_RSVP_P2MP, "RSVP-TE P2MP LSP"},
316 { BGP_PMSI_TUNNEL_LDP_P2MP, "LDP P2MP LSP"},
317 { BGP_PMSI_TUNNEL_PIM_SSM, "PIM-SSM Tree"},
318 { BGP_PMSI_TUNNEL_PIM_SM, "PIM-SM Tree"},
319 { BGP_PMSI_TUNNEL_PIM_BIDIR, "PIM-Bidir Tree"},
320 { BGP_PMSI_TUNNEL_INGRESS, "Ingress Replication"},
321 { BGP_PMSI_TUNNEL_LDP_MP2MP, "LDP MP2MP LSP"},
322 { 0, NULL}
323 };
324
325 static struct tok bgp_pmsi_flag_values[] = {
326 { 0x01, "Leaf Information required"},
327 { 0, NULL}
328 };
329
330
331 /* Subsequent address family identifier, RFC2283 section 7 */
332 #define SAFNUM_RES 0
333 #define SAFNUM_UNICAST 1
334 #define SAFNUM_MULTICAST 2
335 #define SAFNUM_UNIMULTICAST 3
336 /* labeled BGP RFC3107 */
337 #define SAFNUM_LABUNICAST 4
338 #define SAFNUM_TUNNEL 64 /* XXX */
339 #define SAFNUM_VPLS 65 /* XXX */
340 #define SAFNUM_MDT 66 /* XXX */
341 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
342 #define SAFNUM_VPNUNICAST 128
343 #define SAFNUM_VPNMULTICAST 129
344 #define SAFNUM_VPNUNIMULTICAST 130
345 /* draft-marques-ppvpn-rt-constrain-01.txt */
346 #define SAFNUM_RT_ROUTING_INFO 132
347 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
348 #define SAFNUM_MULTICAST_VPN 139
349
350 #define BGP_VPN_RD_LEN 8
351
352 static struct tok bgp_safi_values[] = {
353 { SAFNUM_RES, "Reserved"},
354 { SAFNUM_UNICAST, "Unicast"},
355 { SAFNUM_MULTICAST, "Multicast"},
356 { SAFNUM_UNIMULTICAST, "Unicast+Multicast"},
357 { SAFNUM_LABUNICAST, "labeled Unicast"},
358 { SAFNUM_TUNNEL, "Tunnel"},
359 { SAFNUM_VPLS, "VPLS"},
360 { SAFNUM_MDT, "MDT"},
361 { SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
362 { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
363 { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
364 { SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"},
365 { SAFNUM_MULTICAST_VPN, "Multicast VPN"},
366 { 0, NULL }
367 };
368
369 /* well-known community */
370 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
371 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
372 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
373
374 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
375 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
376 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
377 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
378 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
379 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
380 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
381 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
382 /* rfc2547 bgp-mpls-vpns */
383 #define BGP_EXT_COM_CISCO_MCAST 0x0009 /* cisco proprietary */
384
385 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
386 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
387 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
388 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
389
390 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
391 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
392
393 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
394 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
395
396 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
397
398 #define BGP_EXT_COM_SOURCE_AS 0x0010 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
399 #define BGP_EXT_COM_VRF_RT_IMP 0x0108 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
400
401 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
402 #define BGP_EXT_COM_EIGRP_GEN 0x8800
403 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
404 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
405 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
406 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
407 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
408
409 static struct tok bgp_extd_comm_flag_values[] = {
410 { 0x8000, "vendor-specific"},
411 { 0x4000, "non-transitive"},
412 { 0, NULL},
413 };
414
415 static struct tok bgp_extd_comm_subtype_values[] = {
416 { BGP_EXT_COM_RT_0, "target"},
417 { BGP_EXT_COM_RT_1, "target"},
418 { BGP_EXT_COM_RT_2, "target"},
419 { BGP_EXT_COM_RO_0, "origin"},
420 { BGP_EXT_COM_RO_1, "origin"},
421 { BGP_EXT_COM_RO_2, "origin"},
422 { BGP_EXT_COM_LINKBAND, "link-BW"},
423 { BGP_EXT_COM_CISCO_MCAST, "mdt-group"},
424 { BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"},
425 { BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"},
426 { BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"},
427 { BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"},
428 { BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"},
429 { BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"},
430 { BGP_EXT_COM_OSPF_RID, "ospf-router-id"},
431 { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"},
432 { BGP_EXT_COM_L2INFO, "layer2-info"},
433 { BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" },
434 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" },
435 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" },
436 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" },
437 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" },
438 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" },
439 { BGP_EXT_COM_SOURCE_AS, "source-AS" },
440 { BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"},
441 { 0, NULL},
442 };
443
444 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
445 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
446 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
447 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
448 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
449 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
450 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
451 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
452
453 static struct tok bgp_extd_comm_ospf_rtype_values[] = {
454 { BGP_OSPF_RTYPE_RTR, "Router" },
455 { BGP_OSPF_RTYPE_NET, "Network" },
456 { BGP_OSPF_RTYPE_SUM, "Summary" },
457 { BGP_OSPF_RTYPE_EXT, "External" },
458 { BGP_OSPF_RTYPE_NSSA,"NSSA External" },
459 { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
460 { 0, NULL },
461 };
462
463 int
464 decode_prefix4(const u_char *pptr, char *buf, u_int buflen)
465 {
466 struct in_addr addr;
467 u_int plen;
468
469 TCHECK(pptr[0]);
470 plen = pptr[0];
471 if (32 < plen)
472 return -1;
473
474 memset(&addr, 0, sizeof(addr));
475 TCHECK2(pptr[1], (plen + 7) / 8);
476 memcpy(&addr, &pptr[1], (plen + 7) / 8);
477 if (plen % 8) {
478 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
479 ((0xff00 >> (plen % 8)) & 0xff);
480 }
481 snprintf(buf, buflen, "%s/%d", getname((u_char *)&addr), plen);
482 return 1 + (plen + 7) / 8;
483
484 trunc:
485 return -2;
486 }
487
488 static int
489 decode_labeled_prefix4(const u_char *pptr, char *buf, u_int buflen)
490 {
491 struct in_addr addr;
492 u_int plen;
493
494 TCHECK(pptr[0]);
495 plen = pptr[0]; /* get prefix length */
496
497 /* this is one of the weirdnesses of rfc3107
498 the label length (actually the label + COS bits)
499 is added to the prefix length;
500 we also do only read out just one label -
501 there is no real application for advertisement of
502 stacked labels in a a single BGP message
503 */
504
505 if (24 > plen)
506 return -1;
507
508 plen-=24; /* adjust prefixlen - labellength */
509
510 if (32 < plen)
511 return -1;
512
513 memset(&addr, 0, sizeof(addr));
514 TCHECK2(pptr[4], (plen + 7) / 8);
515 memcpy(&addr, &pptr[4], (plen + 7) / 8);
516 if (plen % 8) {
517 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
518 ((0xff00 >> (plen % 8)) & 0xff);
519 }
520 /* the label may get offsetted by 4 bits so lets shift it right */
521 snprintf(buf, buflen, "%s/%d, label:%u %s",
522 getname((u_char *)&addr),
523 plen,
524 EXTRACT_24BITS(pptr+1)>>4,
525 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
526
527 return 4 + (plen + 7) / 8;
528
529 trunc:
530 return -2;
531 }
532
533 /* RDs and RTs share the same semantics
534 * we use bgp_vpn_rd_print for
535 * printing route targets inside a NLRI */
536 char *
537 bgp_vpn_rd_print (const u_char *pptr) {
538
539 /* allocate space for the largest possible string */
540 static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
541 char *pos = rd;
542
543 /* ok lets load the RD format */
544 switch (EXTRACT_16BITS(pptr)) {
545
546 /* AS:IP-address fmt*/
547 case 0:
548 snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u.%u.%u.%u",
549 EXTRACT_16BITS(pptr+2), *(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7));
550 break;
551 /* IP-address:AS fmt*/
552
553 case 1:
554 snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u",
555 *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6));
556 break;
557
558 /* 4-byte-AS:number fmt*/
559 case 2:
560 snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (%u.%u.%u.%u:%u)",
561 EXTRACT_32BITS(pptr+2), EXTRACT_16BITS(pptr+6),
562 *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6));
563 break;
564 default:
565 snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format");
566 break;
567 }
568 pos += strlen(pos);
569 *(pos) = '\0';
570 return (rd);
571 }
572
573 static int
574 decode_rt_routing_info(const u_char *pptr, char *buf, u_int buflen)
575 {
576 u_int8_t route_target[8];
577 u_int plen;
578
579 TCHECK(pptr[0]);
580 plen = pptr[0]; /* get prefix length */
581
582 if (0 == plen)
583 return 1; /* default route target */
584
585 if (32 > plen)
586 return -1;
587
588 plen-=32; /* adjust prefix length */
589
590 if (64 < plen)
591 return -1;
592
593 memset(&route_target, 0, sizeof(route_target));
594 TCHECK2(pptr[1], (plen + 7) / 8);
595 memcpy(&route_target, &pptr[1], (plen + 7) / 8);
596 if (plen % 8) {
597 ((u_char *)&route_target)[(plen + 7) / 8 - 1] &=
598 ((0xff00 >> (plen % 8)) & 0xff);
599 }
600 snprintf(buf, buflen, "origin AS: %u, route target %s",
601 EXTRACT_32BITS(pptr+1),
602 bgp_vpn_rd_print((u_char *)&route_target));
603
604 return 5 + (plen + 7) / 8;
605
606 trunc:
607 return -2;
608 }
609
610 static int
611 decode_labeled_vpn_prefix4(const u_char *pptr, char *buf, u_int buflen)
612 {
613 struct in_addr addr;
614 u_int plen;
615
616 TCHECK(pptr[0]);
617 plen = pptr[0]; /* get prefix length */
618
619 if ((24+64) > plen)
620 return -1;
621
622 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
623
624 if (32 < plen)
625 return -1;
626
627 memset(&addr, 0, sizeof(addr));
628 TCHECK2(pptr[12], (plen + 7) / 8);
629 memcpy(&addr, &pptr[12], (plen + 7) / 8);
630 if (plen % 8) {
631 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
632 ((0xff00 >> (plen % 8)) & 0xff);
633 }
634 /* the label may get offsetted by 4 bits so lets shift it right */
635 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
636 bgp_vpn_rd_print(pptr+4),
637 getname((u_char *)&addr),
638 plen,
639 EXTRACT_24BITS(pptr+1)>>4,
640 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
641
642 return 12 + (plen + 7) / 8;
643
644 trunc:
645 return -2;
646 }
647
648 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
649 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
650 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
651 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
652 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
653 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
654 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
655
656 static struct tok bgp_multicast_vpn_route_type_values[] = {
657 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"},
658 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"},
659 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"},
660 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"},
661 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
662 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
663 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
664 };
665
666 static int
667 decode_multicast_vpn(const u_char *pptr, char *buf, u_int buflen)
668 {
669 u_int8_t route_type, route_length;
670
671 TCHECK2(pptr[0], 2);
672 route_type = *pptr++;
673 route_length = *pptr++;
674
675 snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
676 tok2str(bgp_multicast_vpn_route_type_values, "Unknown", route_type),
677 route_type, route_length);
678
679 switch(route_type) {
680
681 /*
682 * no per route-type printing yet.
683 */
684 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
685 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
686 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
687 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF:
688 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
689 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN:
690 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
691 default:
692 break;
693 }
694
695 return route_length + 2;
696
697 trunc:
698 return -2;
699 }
700
701 static int
702 decode_labeled_vpn_l2(const u_char *pptr, char *buf, u_int buflen)
703 {
704 int plen,tlen,strlen,tlv_type,tlv_len,ttlv_len;
705
706 TCHECK2(pptr[0], 2);
707 plen=EXTRACT_16BITS(pptr);
708 tlen=plen;
709 pptr+=2;
710 TCHECK2(pptr[0],15);
711 strlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
712 bgp_vpn_rd_print(pptr),
713 EXTRACT_16BITS(pptr+8),
714 EXTRACT_16BITS(pptr+10),
715 EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
716 pptr+=15;
717 tlen-=15;
718
719 /* ok now the variable part - lets read out TLVs*/
720 while (tlen>0) {
721 if (tlen < 3)
722 return -1;
723 TCHECK2(pptr[0], 3);
724 tlv_type=*pptr++;
725 tlv_len=EXTRACT_16BITS(pptr);
726 ttlv_len=tlv_len;
727 pptr+=2;
728
729 switch(tlv_type) {
730 case 1:
731 strlen+=snprintf(buf+strlen,buflen-strlen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
732 tlv_type,
733 tlv_len);
734 ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
735 while (ttlv_len>0) {
736 TCHECK(pptr[0]);
737 strlen+=snprintf(buf+strlen,buflen-strlen, "%02x",*pptr++);
738 ttlv_len--;
739 }
740 break;
741 default:
742 snprintf(buf+strlen,buflen-strlen, "\n\t\tunknown TLV #%u, length: %u",
743 tlv_type,
744 tlv_len);
745 break;
746 }
747 tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it tright */
748 }
749 return plen+2;
750
751 trunc:
752 return -2;
753 }
754
755 #ifdef INET6
756 int
757 decode_prefix6(const u_char *pd, char *buf, u_int buflen)
758 {
759 struct in6_addr addr;
760 u_int plen;
761
762 TCHECK(pd[0]);
763 plen = pd[0];
764 if (128 < plen)
765 return -1;
766
767 memset(&addr, 0, sizeof(addr));
768 TCHECK2(pd[1], (plen + 7) / 8);
769 memcpy(&addr, &pd[1], (plen + 7) / 8);
770 if (plen % 8) {
771 addr.s6_addr[(plen + 7) / 8 - 1] &=
772 ((0xff00 >> (plen % 8)) & 0xff);
773 }
774 snprintf(buf, buflen, "%s/%d", getname6((u_char *)&addr), plen);
775 return 1 + (plen + 7) / 8;
776
777 trunc:
778 return -2;
779 }
780
781 static int
782 decode_labeled_prefix6(const u_char *pptr, char *buf, u_int buflen)
783 {
784 struct in6_addr addr;
785 u_int plen;
786
787 TCHECK(pptr[0]);
788 plen = pptr[0]; /* get prefix length */
789
790 if (24 > plen)
791 return -1;
792
793 plen-=24; /* adjust prefixlen - labellength */
794
795 if (128 < plen)
796 return -1;
797
798 memset(&addr, 0, sizeof(addr));
799 TCHECK2(pptr[4], (plen + 7) / 8);
800 memcpy(&addr, &pptr[4], (plen + 7) / 8);
801 if (plen % 8) {
802 addr.s6_addr[(plen + 7) / 8 - 1] &=
803 ((0xff00 >> (plen % 8)) & 0xff);
804 }
805 /* the label may get offsetted by 4 bits so lets shift it right */
806 snprintf(buf, buflen, "%s/%d, label:%u %s",
807 getname6((u_char *)&addr),
808 plen,
809 EXTRACT_24BITS(pptr+1)>>4,
810 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
811
812 return 4 + (plen + 7) / 8;
813
814 trunc:
815 return -2;
816 }
817
818 static int
819 decode_labeled_vpn_prefix6(const u_char *pptr, char *buf, u_int buflen)
820 {
821 struct in6_addr addr;
822 u_int plen;
823
824 TCHECK(pptr[0]);
825 plen = pptr[0]; /* get prefix length */
826
827 if ((24+64) > plen)
828 return -1;
829
830 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
831
832 if (128 < plen)
833 return -1;
834
835 memset(&addr, 0, sizeof(addr));
836 TCHECK2(pptr[12], (plen + 7) / 8);
837 memcpy(&addr, &pptr[12], (plen + 7) / 8);
838 if (plen % 8) {
839 addr.s6_addr[(plen + 7) / 8 - 1] &=
840 ((0xff00 >> (plen % 8)) & 0xff);
841 }
842 /* the label may get offsetted by 4 bits so lets shift it right */
843 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
844 bgp_vpn_rd_print(pptr+4),
845 getname6((u_char *)&addr),
846 plen,
847 EXTRACT_24BITS(pptr+1)>>4,
848 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
849
850 return 12 + (plen + 7) / 8;
851
852 trunc:
853 return -2;
854 }
855 #endif
856
857 static int
858 decode_clnp_prefix(const u_char *pptr, char *buf, u_int buflen)
859 {
860 u_int8_t addr[19];
861 u_int plen;
862
863 TCHECK(pptr[0]);
864 plen = pptr[0]; /* get prefix length */
865
866 if (152 < plen)
867 return -1;
868
869 memset(&addr, 0, sizeof(addr));
870 TCHECK2(pptr[4], (plen + 7) / 8);
871 memcpy(&addr, &pptr[4], (plen + 7) / 8);
872 if (plen % 8) {
873 addr[(plen + 7) / 8 - 1] &=
874 ((0xff00 >> (plen % 8)) & 0xff);
875 }
876 snprintf(buf, buflen, "%s/%d",
877 isonsap_string(addr,(plen + 7) / 8),
878 plen);
879
880 return 1 + (plen + 7) / 8;
881
882 trunc:
883 return -2;
884 }
885
886 static int
887 decode_labeled_vpn_clnp_prefix(const u_char *pptr, char *buf, u_int buflen)
888 {
889 u_int8_t addr[19];
890 u_int plen;
891
892 TCHECK(pptr[0]);
893 plen = pptr[0]; /* get prefix length */
894
895 if ((24+64) > plen)
896 return -1;
897
898 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
899
900 if (152 < plen)
901 return -1;
902
903 memset(&addr, 0, sizeof(addr));
904 TCHECK2(pptr[12], (plen + 7) / 8);
905 memcpy(&addr, &pptr[12], (plen + 7) / 8);
906 if (plen % 8) {
907 addr[(plen + 7) / 8 - 1] &=
908 ((0xff00 >> (plen % 8)) & 0xff);
909 }
910 /* the label may get offsetted by 4 bits so lets shift it right */
911 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
912 bgp_vpn_rd_print(pptr+4),
913 isonsap_string(addr,(plen + 7) / 8),
914 plen,
915 EXTRACT_24BITS(pptr+1)>>4,
916 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
917
918 return 12 + (plen + 7) / 8;
919
920 trunc:
921 return -2;
922 }
923
924 static int
925 bgp_attr_print(const struct bgp_attr *attr, const u_char *pptr, int len)
926 {
927 int i;
928 u_int16_t af;
929 u_int8_t safi, snpa, nhlen;
930 union { /* copy buffer for bandwidth values */
931 float f;
932 u_int32_t i;
933 } bw;
934 int advance;
935 int tlen;
936 const u_char *tptr;
937 char buf[MAXHOSTNAMELEN + 100];
938 char tokbuf[TOKBUFSIZE];
939
940 tptr = pptr;
941 tlen=len;
942
943 switch (attr->bgpa_type) {
944 case BGPTYPE_ORIGIN:
945 if (len != 1)
946 printf("invalid len");
947 else {
948 TCHECK(*tptr);
949 printf("%s", tok2strbuf(bgp_origin_values,
950 "Unknown Origin Typecode",
951 tptr[0],
952 tokbuf, sizeof(tokbuf)));
953 }
954 break;
955
956 case BGPTYPE_AS_PATH:
957 if (len % 2) {
958 printf("invalid len");
959 break;
960 }
961 if (!len) {
962 printf("empty");
963 break;
964 }
965
966 while (tptr < pptr + len) {
967 TCHECK(tptr[0]);
968 printf("%s", tok2strbuf(bgp_as_path_segment_open_values,
969 "?", tptr[0],
970 tokbuf, sizeof(tokbuf)));
971 for (i = 0; i < tptr[1] * 2; i += 2) {
972 TCHECK2(tptr[2 + i], 2);
973 printf("%u ", EXTRACT_16BITS(&tptr[2 + i]));
974 }
975 TCHECK(tptr[0]);
976 printf("%s", tok2strbuf(bgp_as_path_segment_close_values,
977 "?", tptr[0],
978 tokbuf, sizeof(tokbuf)));
979 TCHECK(tptr[1]);
980 tptr += 2 + tptr[1] * 2;
981 }
982 break;
983 case BGPTYPE_NEXT_HOP:
984 if (len != 4)
985 printf("invalid len");
986 else {
987 TCHECK2(tptr[0], 4);
988 printf("%s", getname(tptr));
989 }
990 break;
991 case BGPTYPE_MULTI_EXIT_DISC:
992 case BGPTYPE_LOCAL_PREF:
993 if (len != 4)
994 printf("invalid len");
995 else {
996 TCHECK2(tptr[0], 4);
997 printf("%u", EXTRACT_32BITS(tptr));
998 }
999 break;
1000 case BGPTYPE_ATOMIC_AGGREGATE:
1001 if (len != 0)
1002 printf("invalid len");
1003 break;
1004 case BGPTYPE_AGGREGATOR:
1005 if (len != 6) {
1006 printf("invalid len");
1007 break;
1008 }
1009 TCHECK2(tptr[0], 6);
1010 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr),
1011 getname(tptr + 2));
1012 break;
1013 case BGPTYPE_COMMUNITIES:
1014 if (len % 4) {
1015 printf("invalid len");
1016 break;
1017 }
1018 while (tlen>0) {
1019 u_int32_t comm;
1020 TCHECK2(tptr[0], 4);
1021 comm = EXTRACT_32BITS(tptr);
1022 switch (comm) {
1023 case BGP_COMMUNITY_NO_EXPORT:
1024 printf(" NO_EXPORT");
1025 break;
1026 case BGP_COMMUNITY_NO_ADVERT:
1027 printf(" NO_ADVERTISE");
1028 break;
1029 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
1030 printf(" NO_EXPORT_SUBCONFED");
1031 break;
1032 default:
1033 printf("%u:%u%s",
1034 (comm >> 16) & 0xffff,
1035 comm & 0xffff,
1036 (tlen>4) ? ", " : "");
1037 break;
1038 }
1039 tlen -=4;
1040 tptr +=4;
1041 }
1042 break;
1043 case BGPTYPE_ORIGINATOR_ID:
1044 if (len != 4) {
1045 printf("invalid len");
1046 break;
1047 }
1048 TCHECK2(tptr[0], 4);
1049 printf("%s",getname(tptr));
1050 break;
1051 case BGPTYPE_CLUSTER_LIST:
1052 if (len % 4) {
1053 printf("invalid len");
1054 break;
1055 }
1056 while (tlen>0) {
1057 TCHECK2(tptr[0], 4);
1058 printf("%s%s",
1059 getname(tptr),
1060 (tlen>4) ? ", " : "");
1061 tlen -=4;
1062 tptr +=4;
1063 }
1064 break;
1065 case BGPTYPE_MP_REACH_NLRI:
1066 TCHECK2(tptr[0], 3);
1067 af = EXTRACT_16BITS(tptr);
1068 safi = tptr[2];
1069
1070 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1071 tok2strbuf(af_values, "Unknown AFI", af,
1072 tokbuf, sizeof(tokbuf)),
1073 af,
1074 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1075 tok2strbuf(bgp_safi_values, "Unknown SAFI", safi,
1076 tokbuf, sizeof(tokbuf)),
1077 safi);
1078
1079 switch(af<<8 | safi) {
1080 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1081 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1082 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1083 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1084 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1085 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1086 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1087 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1088 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1089 #ifdef INET6
1090 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1091 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1092 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1093 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1094 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1095 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1096 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1097 #endif
1098 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1099 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1100 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1101 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1102 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1103 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1104 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1105 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1106 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1107 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1108 break;
1109 default:
1110 TCHECK2(tptr[0], tlen);
1111 printf("\n\t no AFI %u / SAFI %u decoder",af,safi);
1112 if (vflag <= 1)
1113 print_unknown_data(tptr,"\n\t ",tlen);
1114 goto done;
1115 break;
1116 }
1117
1118 tptr +=3;
1119
1120 TCHECK(tptr[0]);
1121 nhlen = tptr[0];
1122 tlen = nhlen;
1123 tptr++;
1124
1125 if (tlen) {
1126 printf("\n\t nexthop: ");
1127 while (tlen > 0) {
1128 switch(af<<8 | safi) {
1129 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1130 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1131 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1132 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1133 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1134 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1135 if (tlen < (int)sizeof(struct in_addr)) {
1136 printf("invalid len");
1137 tlen = 0;
1138 } else {
1139 TCHECK2(tptr[0], sizeof(struct in_addr));
1140 printf("%s",getname(tptr));
1141 tlen -= sizeof(struct in_addr);
1142 tptr += sizeof(struct in_addr);
1143 }
1144 break;
1145 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1146 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1147 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1148 if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) {
1149 printf("invalid len");
1150 tlen = 0;
1151 } else {
1152 TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1153 printf("RD: %s, %s",
1154 bgp_vpn_rd_print(tptr),
1155 getname(tptr+BGP_VPN_RD_LEN));
1156 tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1157 tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1158 }
1159 break;
1160 #ifdef INET6
1161 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1162 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1163 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1164 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1165 if (tlen < (int)sizeof(struct in6_addr)) {
1166 printf("invalid len");
1167 tlen = 0;
1168 } else {
1169 TCHECK2(tptr[0], sizeof(struct in6_addr));
1170 printf("%s", getname6(tptr));
1171 tlen -= sizeof(struct in6_addr);
1172 tptr += sizeof(struct in6_addr);
1173 }
1174 break;
1175 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1176 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1177 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1178 if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) {
1179 printf("invalid len");
1180 tlen = 0;
1181 } else {
1182 TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1183 printf("RD: %s, %s",
1184 bgp_vpn_rd_print(tptr),
1185 getname6(tptr+BGP_VPN_RD_LEN));
1186 tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1187 tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1188 }
1189 break;
1190 #endif
1191 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1192 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1193 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1194 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1195 if (tlen < (int)sizeof(struct in_addr)) {
1196 printf("invalid len");
1197 tlen = 0;
1198 } else {
1199 TCHECK2(tptr[0], sizeof(struct in_addr));
1200 printf("%s", getname(tptr));
1201 tlen -= (sizeof(struct in_addr));
1202 tptr += (sizeof(struct in_addr));
1203 }
1204 break;
1205 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1206 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1207 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1208 TCHECK2(tptr[0], tlen);
1209 printf("%s",isonsap_string(tptr,tlen));
1210 tptr += tlen;
1211 tlen = 0;
1212 break;
1213
1214 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1215 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1216 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1217 if (tlen < BGP_VPN_RD_LEN+1) {
1218 printf("invalid len");
1219 tlen = 0;
1220 } else {
1221 TCHECK2(tptr[0], tlen);
1222 printf("RD: %s, %s",
1223 bgp_vpn_rd_print(tptr),
1224 isonsap_string(tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN));
1225 /* rfc986 mapped IPv4 address ? */
1226 if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601)
1227 printf(" = %s", getname(tptr+BGP_VPN_RD_LEN+4));
1228 #ifdef INET6
1229 /* rfc1888 mapped IPv6 address ? */
1230 else if (EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000)
1231 printf(" = %s", getname6(tptr+BGP_VPN_RD_LEN+3));
1232 #endif
1233 tptr += tlen;
1234 tlen = 0;
1235 }
1236 break;
1237 default:
1238 TCHECK2(tptr[0], tlen);
1239 printf("no AFI %u/SAFI %u decoder",af,safi);
1240 if (vflag <= 1)
1241 print_unknown_data(tptr,"\n\t ",tlen);
1242 tptr += tlen;
1243 tlen = 0;
1244 goto done;
1245 break;
1246 }
1247 }
1248 }
1249 printf(", nh-length: %u", nhlen);
1250 tptr += tlen;
1251
1252 TCHECK(tptr[0]);
1253 snpa = tptr[0];
1254 tptr++;
1255
1256 if (snpa) {
1257 printf("\n\t %u SNPA", snpa);
1258 for (/*nothing*/; snpa > 0; snpa--) {
1259 TCHECK(tptr[0]);
1260 printf("\n\t %d bytes", tptr[0]);
1261 tptr += tptr[0] + 1;
1262 }
1263 } else {
1264 printf(", no SNPA");
1265 }
1266
1267 while (len - (tptr - pptr) > 0) {
1268 switch (af<<8 | safi) {
1269 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1270 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1271 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1272 advance = decode_prefix4(tptr, buf, sizeof(buf));
1273 if (advance == -1)
1274 printf("\n\t (illegal prefix length)");
1275 else if (advance == -2)
1276 goto trunc;
1277 else
1278 printf("\n\t %s", buf);
1279 break;
1280 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1281 advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
1282 if (advance == -1)
1283 printf("\n\t (illegal prefix length)");
1284 else if (advance == -2)
1285 goto trunc;
1286 else
1287 printf("\n\t %s", buf);
1288 break;
1289 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1290 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1291 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1292 advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
1293 if (advance == -1)
1294 printf("\n\t (illegal prefix length)");
1295 else if (advance == -2)
1296 goto trunc;
1297 else
1298 printf("\n\t %s", buf);
1299 break;
1300 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1301 advance = decode_rt_routing_info(tptr, buf, sizeof(buf));
1302 if (advance == -1)
1303 printf("\n\t (illegal prefix length)");
1304 else if (advance == -2)
1305 goto trunc;
1306 else
1307 printf("\n\t %s", buf);
1308 break;
1309 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1310 advance = decode_multicast_vpn(tptr, buf, sizeof(buf));
1311 if (advance == -1)
1312 printf("\n\t (illegal prefix length)");
1313 else if (advance == -2)
1314 goto trunc;
1315 else
1316 printf("\n\t %s", buf);
1317 break;
1318 #ifdef INET6
1319 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1320 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1321 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1322 advance = decode_prefix6(tptr, buf, sizeof(buf));
1323 if (advance == -1)
1324 printf("\n\t (illegal prefix length)");
1325 else if (advance == -2)
1326 goto trunc;
1327 else
1328 printf("\n\t %s", buf);
1329 break;
1330 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1331 advance = decode_labeled_prefix6(tptr, buf, sizeof(buf));
1332 if (advance == -1)
1333 printf("\n\t (illegal prefix length)");
1334 else if (advance == -2)
1335 goto trunc;
1336 else
1337 printf("\n\t %s", buf);
1338 break;
1339 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1340 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1341 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1342 advance = decode_labeled_vpn_prefix6(tptr, buf, sizeof(buf));
1343 if (advance == -1)
1344 printf("\n\t (illegal prefix length)");
1345 else if (advance == -2)
1346 goto trunc;
1347 else
1348 printf("\n\t %s", buf);
1349 break;
1350 #endif
1351 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1352 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1353 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1354 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1355 advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
1356 if (advance == -1)
1357 printf("\n\t (illegal length)");
1358 else if (advance == -2)
1359 goto trunc;
1360 else
1361 printf("\n\t %s", buf);
1362 break;
1363 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1364 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1365 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1366 advance = decode_clnp_prefix(tptr, buf, sizeof(buf));
1367 if (advance == -1)
1368 printf("\n\t (illegal prefix length)");
1369 else if (advance == -2)
1370 goto trunc;
1371 else
1372 printf("\n\t %s", buf);
1373 break;
1374 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1375 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1376 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1377 advance = decode_labeled_vpn_clnp_prefix(tptr, buf, sizeof(buf));
1378 if (advance == -1)
1379 printf("\n\t (illegal prefix length)");
1380 else if (advance == -2)
1381 goto trunc;
1382 else
1383 printf("\n\t %s", buf);
1384 break;
1385 default:
1386 TCHECK2(*tptr,tlen);
1387 printf("\n\t no AFI %u / SAFI %u decoder",af,safi);
1388 if (vflag <= 1)
1389 print_unknown_data(tptr,"\n\t ",tlen);
1390 advance = 0;
1391 tptr = pptr + len;
1392 break;
1393 }
1394 if (advance < 0)
1395 break;
1396 tptr += advance;
1397 }
1398 done:
1399 break;
1400
1401 case BGPTYPE_MP_UNREACH_NLRI:
1402 TCHECK2(tptr[0], BGP_MP_NLRI_MINSIZE);
1403 af = EXTRACT_16BITS(tptr);
1404 safi = tptr[2];
1405
1406 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1407 tok2strbuf(af_values, "Unknown AFI", af,
1408 tokbuf, sizeof(tokbuf)),
1409 af,
1410 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1411 tok2strbuf(bgp_safi_values, "Unknown SAFI", safi,
1412 tokbuf, sizeof(tokbuf)),
1413 safi);
1414
1415 if (len == BGP_MP_NLRI_MINSIZE)
1416 printf("\n\t End-of-Rib Marker (empty NLRI)");
1417
1418 tptr += 3;
1419
1420 while (len - (tptr - pptr) > 0) {
1421 switch (af<<8 | safi) {
1422 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1423 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1424 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1425 advance = decode_prefix4(tptr, buf, sizeof(buf));
1426 if (advance == -1)
1427 printf("\n\t (illegal prefix length)");
1428 else if (advance == -2)
1429 goto trunc;
1430 else
1431 printf("\n\t %s", buf);
1432 break;
1433 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1434 advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
1435 if (advance == -1)
1436 printf("\n\t (illegal prefix length)");
1437 else if (advance == -2)
1438 goto trunc;
1439 else
1440 printf("\n\t %s", buf);
1441 break;
1442 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1443 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1444 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1445 advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
1446 if (advance == -1)
1447 printf("\n\t (illegal prefix length)");
1448 else if (advance == -2)
1449 goto trunc;
1450 else
1451 printf("\n\t %s", buf);
1452 break;
1453 #ifdef INET6
1454 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1455 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1456 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1457 advance = decode_prefix6(tptr, buf, sizeof(buf));
1458 if (advance == -1)
1459 printf("\n\t (illegal prefix length)");
1460 else if (advance == -2)
1461 goto trunc;
1462 else
1463 printf("\n\t %s", buf);
1464 break;
1465 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1466 advance = decode_labeled_prefix6(tptr, buf, sizeof(buf));
1467 if (advance == -1)
1468 printf("\n\t (illegal prefix length)");
1469 else if (advance == -2)
1470 goto trunc;
1471 else
1472 printf("\n\t %s", buf);
1473 break;
1474 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1475 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1476 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1477 advance = decode_labeled_vpn_prefix6(tptr, buf, sizeof(buf));
1478 if (advance == -1)
1479 printf("\n\t (illegal prefix length)");
1480 else if (advance == -2)
1481 goto trunc;
1482 else
1483 printf("\n\t %s", buf);
1484 break;
1485 #endif
1486 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1487 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1488 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1489 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1490 advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
1491 if (advance == -1)
1492 printf("\n\t (illegal length)");
1493 else if (advance == -2)
1494 goto trunc;
1495 else
1496 printf("\n\t %s", buf);
1497 break;
1498 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1499 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1500 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1501 advance = decode_clnp_prefix(tptr, buf, sizeof(buf));
1502 if (advance == -1)
1503 printf("\n\t (illegal prefix length)");
1504 else if (advance == -2)
1505 goto trunc;
1506 else
1507 printf("\n\t %s", buf);
1508 break;
1509 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1510 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1511 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1512 advance = decode_labeled_vpn_clnp_prefix(tptr, buf, sizeof(buf));
1513 if (advance == -1)
1514 printf("\n\t (illegal prefix length)");
1515 else if (advance == -2)
1516 goto trunc;
1517 else
1518 printf("\n\t %s", buf);
1519 break;
1520 default:
1521 TCHECK2(*(tptr-3),tlen);
1522 printf("no AFI %u / SAFI %u decoder",af,safi);
1523 if (vflag <= 1)
1524 print_unknown_data(tptr-3,"\n\t ",tlen);
1525 advance = 0;
1526 tptr = pptr + len;
1527 break;
1528 }
1529 if (advance < 0)
1530 break;
1531 tptr += advance;
1532 }
1533 break;
1534 case BGPTYPE_EXTD_COMMUNITIES:
1535 if (len % 8) {
1536 printf("invalid len");
1537 break;
1538 }
1539 while (tlen>0) {
1540 u_int16_t extd_comm;
1541
1542 TCHECK2(tptr[0], 2);
1543 extd_comm=EXTRACT_16BITS(tptr);
1544
1545 printf("\n\t %s (0x%04x), Flags [%s]",
1546 tok2strbuf(bgp_extd_comm_subtype_values,
1547 "unknown extd community typecode",
1548 extd_comm, tokbuf, sizeof(tokbuf)),
1549 extd_comm,
1550 bittok2str(bgp_extd_comm_flag_values, "none", extd_comm));
1551
1552 TCHECK2(*(tptr+2), 6);
1553 switch(extd_comm) {
1554 case BGP_EXT_COM_RT_0:
1555 case BGP_EXT_COM_RO_0:
1556 printf(": %u:%s",
1557 EXTRACT_16BITS(tptr+2),
1558 getname(tptr+4));
1559 break;
1560 case BGP_EXT_COM_RT_1:
1561 case BGP_EXT_COM_RO_1:
1562 case BGP_EXT_COM_VRF_RT_IMP:
1563 printf(": %s:%u",
1564 getname(tptr+2),
1565 EXTRACT_16BITS(tptr+6));
1566 break;
1567 case BGP_EXT_COM_RT_2:
1568 case BGP_EXT_COM_RO_2:
1569 printf(": %u:%u",
1570 EXTRACT_32BITS(tptr+2),
1571 EXTRACT_16BITS(tptr+6));
1572 break;
1573 case BGP_EXT_COM_LINKBAND:
1574 bw.i = EXTRACT_32BITS(tptr+2);
1575 printf(": bandwidth: %.3f Mbps",
1576 bw.f*8/1000000);
1577 break;
1578 case BGP_EXT_COM_CISCO_MCAST:
1579 printf(": AS %u, group %s",
1580 EXTRACT_16BITS(tptr+2),
1581 getname(tptr+4));
1582 break;
1583 case BGP_EXT_COM_VPN_ORIGIN:
1584 case BGP_EXT_COM_VPN_ORIGIN2:
1585 case BGP_EXT_COM_VPN_ORIGIN3:
1586 case BGP_EXT_COM_VPN_ORIGIN4:
1587 case BGP_EXT_COM_OSPF_RID:
1588 case BGP_EXT_COM_OSPF_RID2:
1589 printf("%s", getname(tptr+2));
1590 break;
1591 case BGP_EXT_COM_OSPF_RTYPE:
1592 case BGP_EXT_COM_OSPF_RTYPE2:
1593 printf(": area:%s, router-type:%s, metric-type:%s%s",
1594 getname(tptr+2),
1595 tok2strbuf(bgp_extd_comm_ospf_rtype_values,
1596 "unknown (0x%02x)",
1597 *(tptr+6),
1598 tokbuf, sizeof(tokbuf)),
1599 (*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
1600 ((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : "");
1601 break;
1602 case BGP_EXT_COM_L2INFO:
1603 printf(": %s Control Flags [0x%02x]:MTU %u",
1604 tok2strbuf(l2vpn_encaps_values,
1605 "unknown encaps",
1606 *(tptr+2),
1607 tokbuf, sizeof(tokbuf)),
1608 *(tptr+3),
1609 EXTRACT_16BITS(tptr+4));
1610 break;
1611 case BGP_EXT_COM_SOURCE_AS:
1612 printf(": AS %u", EXTRACT_16BITS(tptr+2));
1613 break;
1614 default:
1615 TCHECK2(*tptr,8);
1616 print_unknown_data(tptr,"\n\t ",8);
1617 break;
1618 }
1619 tlen -=8;
1620 tptr +=8;
1621 }
1622 break;
1623
1624 case BGPTYPE_PMSI_TUNNEL:
1625 {
1626 u_int8_t tunnel_type, flags;
1627
1628 tunnel_type = *(tptr+1);
1629 flags = *tptr;
1630 tlen = len;
1631
1632 TCHECK2(tptr[0], 5);
1633 printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
1634 tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type),
1635 tunnel_type,
1636 bittok2str(bgp_pmsi_flag_values, "none", flags),
1637 EXTRACT_24BITS(tptr+2)>>4);
1638
1639 tptr +=5;
1640 tlen -= 5;
1641
1642 switch (tunnel_type) {
1643 case BGP_PMSI_TUNNEL_PIM_SSM:
1644 TCHECK2(tptr[0], 8);
1645 printf("\n\t P-Root-Node %s, P-Group %s",
1646 ipaddr_string(tptr),
1647 ipaddr_string(tptr+4));
1648 break;
1649
1650 /*
1651 * no Tunnel-ID printing, just hexdumping for now
1652 * you are welcome to contribute code ;-)
1653 */
1654 case BGP_PMSI_TUNNEL_RSVP_P2MP:
1655 case BGP_PMSI_TUNNEL_LDP_P2MP:
1656 case BGP_PMSI_TUNNEL_PIM_SM:
1657 case BGP_PMSI_TUNNEL_PIM_BIDIR:
1658 case BGP_PMSI_TUNNEL_INGRESS:
1659 case BGP_PMSI_TUNNEL_LDP_MP2MP:
1660 default:
1661 if (vflag <= 1) {
1662 print_unknown_data(tptr,"\n\t ",tlen);
1663 }
1664 }
1665 break;
1666 }
1667 case BGPTYPE_ATTR_SET:
1668 TCHECK2(tptr[0], 4);
1669 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr));
1670 tptr+=4;
1671 len -=4;
1672
1673 while (len >= 2 ) {
1674 int alen;
1675 struct bgp_attr bgpa;
1676
1677 TCHECK2(tptr[0], sizeof(bgpa));
1678 memcpy(&bgpa, tptr, sizeof(bgpa));
1679 alen = bgp_attr_len(&bgpa);
1680 tptr += bgp_attr_off(&bgpa);
1681 len -= bgp_attr_off(&bgpa);
1682
1683 printf("\n\t %s (%u), length: %u",
1684 tok2strbuf(bgp_attr_values,
1685 "Unknown Attribute", bgpa.bgpa_type,
1686 tokbuf, sizeof(tokbuf)),
1687 bgpa.bgpa_type,
1688 alen);
1689
1690 if (bgpa.bgpa_flags) {
1691 printf(", Flags [%s%s%s%s",
1692 bgpa.bgpa_flags & 0x80 ? "O" : "",
1693 bgpa.bgpa_flags & 0x40 ? "T" : "",
1694 bgpa.bgpa_flags & 0x20 ? "P" : "",
1695 bgpa.bgpa_flags & 0x10 ? "E" : "");
1696 if (bgpa.bgpa_flags & 0xf)
1697 printf("+%x", bgpa.bgpa_flags & 0xf);
1698 printf("]: ");
1699 }
1700 /* FIXME check for recursion */
1701 if (!bgp_attr_print(&bgpa, tptr, alen))
1702 return 0;
1703 tptr += alen;
1704 len -= alen;
1705 }
1706 break;
1707
1708
1709 default:
1710 TCHECK2(*pptr,len);
1711 printf("\n\t no Attribute %u decoder",attr->bgpa_type); /* we have no decoder for the attribute */
1712 if (vflag <= 1)
1713 print_unknown_data(pptr,"\n\t ",len);
1714 break;
1715 }
1716 if (vflag > 1 && len) { /* omit zero length attributes*/
1717 TCHECK2(*pptr,len);
1718 print_unknown_data(pptr,"\n\t ",len);
1719 }
1720 return 1;
1721
1722 trunc:
1723 return 0;
1724 }
1725
1726 static void
1727 bgp_open_print(const u_char *dat, int length)
1728 {
1729 struct bgp_open bgpo;
1730 struct bgp_opt bgpopt;
1731 const u_char *opt;
1732 int i,cap_type,cap_len,tcap_len,cap_offset;
1733 char tokbuf[TOKBUFSIZE];
1734 char tokbuf2[TOKBUFSIZE];
1735
1736 TCHECK2(dat[0], BGP_OPEN_SIZE);
1737 memcpy(&bgpo, dat, BGP_OPEN_SIZE);
1738
1739 printf("\n\t Version %d, ", bgpo.bgpo_version);
1740 printf("my AS %u, ", ntohs(bgpo.bgpo_myas));
1741 printf("Holdtime %us, ", ntohs(bgpo.bgpo_holdtime));
1742 printf("ID %s", getname((u_char *)&bgpo.bgpo_id));
1743 printf("\n\t Optional parameters, length: %u", bgpo.bgpo_optlen);
1744
1745 /* some little sanity checking */
1746 if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE)
1747 return;
1748
1749 /* ugly! */
1750 opt = &((const struct bgp_open *)dat)->bgpo_optlen;
1751 opt++;
1752
1753 i = 0;
1754 while (i < bgpo.bgpo_optlen) {
1755 TCHECK2(opt[i], BGP_OPT_SIZE);
1756 memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE);
1757 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
1758 printf("\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len);
1759 break;
1760 }
1761
1762 printf("\n\t Option %s (%u), length: %u",
1763 tok2strbuf(bgp_opt_values,"Unknown",
1764 bgpopt.bgpopt_type,
1765 tokbuf, sizeof(tokbuf)),
1766 bgpopt.bgpopt_type,
1767 bgpopt.bgpopt_len);
1768
1769 /* now lets decode the options we know*/
1770 switch(bgpopt.bgpopt_type) {
1771 case BGP_OPT_CAP:
1772 cap_type=opt[i+BGP_OPT_SIZE];
1773 cap_len=opt[i+BGP_OPT_SIZE+1];
1774 tcap_len=cap_len;
1775 printf("\n\t %s (%u), length: %u",
1776 tok2strbuf(bgp_capcode_values, "Unknown",
1777 cap_type, tokbuf, sizeof(tokbuf)),
1778 cap_type,
1779 cap_len);
1780 switch(cap_type) {
1781 case BGP_CAPCODE_MP:
1782 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1783 tok2strbuf(af_values, "Unknown",
1784 EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2),
1785 tokbuf, sizeof(tokbuf)),
1786 EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2),
1787 tok2strbuf(bgp_safi_values, "Unknown",
1788 opt[i+BGP_OPT_SIZE+5],
1789 tokbuf, sizeof(tokbuf)),
1790 opt[i+BGP_OPT_SIZE+5]);
1791 break;
1792 case BGP_CAPCODE_RESTART:
1793 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1794 ((opt[i+BGP_OPT_SIZE+2])&0x80) ? "R" : "none",
1795 EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2)&0xfff);
1796 tcap_len-=2;
1797 cap_offset=4;
1798 while(tcap_len>=4) {
1799 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1800 tok2strbuf(af_values,"Unknown",
1801 EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+cap_offset),
1802 tokbuf, sizeof(tokbuf)),
1803 EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+cap_offset),
1804 tok2strbuf(bgp_safi_values,"Unknown",
1805 opt[i+BGP_OPT_SIZE+cap_offset+2],
1806 tokbuf2, sizeof(tokbuf2)),
1807 opt[i+BGP_OPT_SIZE+cap_offset+2],
1808 ((opt[i+BGP_OPT_SIZE+cap_offset+3])&0x80) ? "yes" : "no" );
1809 tcap_len-=4;
1810 cap_offset+=4;
1811 }
1812 break;
1813 case BGP_CAPCODE_RR:
1814 case BGP_CAPCODE_RR_CISCO:
1815 break;
1816 default:
1817 TCHECK2(opt[i+BGP_OPT_SIZE+2],cap_len);
1818 printf("\n\t\tno decoder for Capability %u",
1819 cap_type);
1820 if (vflag <= 1)
1821 print_unknown_data(&opt[i+BGP_OPT_SIZE+2],"\n\t\t",cap_len);
1822 break;
1823 }
1824 if (vflag > 1) {
1825 TCHECK2(opt[i+BGP_OPT_SIZE+2],cap_len);
1826 print_unknown_data(&opt[i+BGP_OPT_SIZE+2],"\n\t\t",cap_len);
1827 }
1828 break;
1829 case BGP_OPT_AUTH:
1830 default:
1831 printf("\n\t no decoder for option %u",
1832 bgpopt.bgpopt_type);
1833 break;
1834 }
1835
1836 i += BGP_OPT_SIZE + bgpopt.bgpopt_len;
1837 }
1838 return;
1839 trunc:
1840 printf("[|BGP]");
1841 }
1842
1843 static void
1844 bgp_update_print(const u_char *dat, int length)
1845 {
1846 struct bgp bgp;
1847 struct bgp_attr bgpa;
1848 const u_char *p;
1849 int len;
1850 int i;
1851 char tokbuf[TOKBUFSIZE];
1852
1853 TCHECK2(dat[0], BGP_SIZE);
1854 memcpy(&bgp, dat, BGP_SIZE);
1855 p = dat + BGP_SIZE; /*XXX*/
1856
1857 /* Unfeasible routes */
1858 len = EXTRACT_16BITS(p);
1859 if (len) {
1860 /*
1861 * Without keeping state from the original NLRI message,
1862 * it's not possible to tell if this a v4 or v6 route,
1863 * so only try to decode it if we're not v6 enabled.
1864 */
1865 #ifdef INET6
1866 printf("\n\t Withdrawn routes: %d bytes", len);
1867 #else
1868 char buf[MAXHOSTNAMELEN + 100];
1869 int wpfx;
1870
1871 TCHECK2(p[2], len);
1872 i = 2;
1873
1874 printf("\n\t Withdrawn routes:");
1875
1876 while(i < 2 + len) {
1877 wpfx = decode_prefix4(&p[i], buf, sizeof(buf));
1878 if (wpfx == -1) {
1879 printf("\n\t (illegal prefix length)");
1880 break;
1881 } else if (wpfx == -2)
1882 goto trunc;
1883 else {
1884 i += wpfx;
1885 printf("\n\t %s", buf);
1886 }
1887 }
1888 #endif
1889 }
1890 p += 2 + len;
1891
1892 TCHECK2(p[0], 2);
1893 len = EXTRACT_16BITS(p);
1894
1895 if (len == 0 && length == BGP_UPDATE_MINSIZE) {
1896 printf("\n\t End-of-Rib Marker (empty NLRI)");
1897 return;
1898 }
1899
1900 if (len) {
1901 /* do something more useful!*/
1902 i = 2;
1903 while (i < 2 + len) {
1904 int alen, aoff;
1905
1906 TCHECK2(p[i], sizeof(bgpa));
1907 memcpy(&bgpa, &p[i], sizeof(bgpa));
1908 alen = bgp_attr_len(&bgpa);
1909 aoff = bgp_attr_off(&bgpa);
1910
1911 printf("\n\t %s (%u), length: %u",
1912 tok2strbuf(bgp_attr_values, "Unknown Attribute",
1913 bgpa.bgpa_type,
1914 tokbuf, sizeof(tokbuf)),
1915 bgpa.bgpa_type,
1916 alen);
1917
1918 if (bgpa.bgpa_flags) {
1919 printf(", Flags [%s%s%s%s",
1920 bgpa.bgpa_flags & 0x80 ? "O" : "",
1921 bgpa.bgpa_flags & 0x40 ? "T" : "",
1922 bgpa.bgpa_flags & 0x20 ? "P" : "",
1923 bgpa.bgpa_flags & 0x10 ? "E" : "");
1924 if (bgpa.bgpa_flags & 0xf)
1925 printf("+%x", bgpa.bgpa_flags & 0xf);
1926 printf("]: ");
1927 }
1928 if (!bgp_attr_print(&bgpa, &p[i + aoff], alen))
1929 goto trunc;
1930 i += aoff + alen;
1931 }
1932 }
1933 p += 2 + len;
1934
1935 if (dat + length > p) {
1936 printf("\n\t Updated routes:");
1937 while (dat + length > p) {
1938 char buf[MAXHOSTNAMELEN + 100];
1939 i = decode_prefix4(p, buf, sizeof(buf));
1940 if (i == -1) {
1941 printf("\n\t (illegal prefix length)");
1942 break;
1943 } else if (i == -2)
1944 goto trunc;
1945 else {
1946 printf("\n\t %s", buf);
1947 p += i;
1948 }
1949 }
1950 }
1951 return;
1952 trunc:
1953 printf("[|BGP]");
1954 }
1955
1956 static void
1957 bgp_notification_print(const u_char *dat, int length)
1958 {
1959 struct bgp_notification bgpn;
1960 const u_char *tptr;
1961 char tokbuf[TOKBUFSIZE];
1962 char tokbuf2[TOKBUFSIZE];
1963
1964 TCHECK2(dat[0], BGP_NOTIFICATION_SIZE);
1965 memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE);
1966
1967 /* some little sanity checking */
1968 if (length<BGP_NOTIFICATION_SIZE)
1969 return;
1970
1971 printf(", %s (%u)",
1972 tok2strbuf(bgp_notify_major_values, "Unknown Error",
1973 bgpn.bgpn_major, tokbuf, sizeof(tokbuf)),
1974 bgpn.bgpn_major);
1975
1976 switch (bgpn.bgpn_major) {
1977
1978 case BGP_NOTIFY_MAJOR_MSG:
1979 printf(", subcode %s (%u)",
1980 tok2strbuf(bgp_notify_minor_msg_values, "Unknown",
1981 bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
1982 bgpn.bgpn_minor);
1983 break;
1984 case BGP_NOTIFY_MAJOR_OPEN:
1985 printf(", subcode %s (%u)",
1986 tok2strbuf(bgp_notify_minor_open_values, "Unknown",
1987 bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
1988 bgpn.bgpn_minor);
1989 break;
1990 case BGP_NOTIFY_MAJOR_UPDATE:
1991 printf(", subcode %s (%u)",
1992 tok2strbuf(bgp_notify_minor_update_values, "Unknown",
1993 bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
1994 bgpn.bgpn_minor);
1995 break;
1996 case BGP_NOTIFY_MAJOR_CAP:
1997 printf(" subcode %s (%u)",
1998 tok2strbuf(bgp_notify_minor_cap_values, "Unknown",
1999 bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
2000 bgpn.bgpn_minor);
2001 case BGP_NOTIFY_MAJOR_CEASE:
2002 printf(", subcode %s (%u)",
2003 tok2strbuf(bgp_notify_minor_cease_values, "Unknown",
2004 bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
2005 bgpn.bgpn_minor);
2006
2007 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2008 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2009 */
2010 if(bgpn.bgpn_minor == BGP_NOTIFY_MINOR_CEASE_MAXPRFX && length >= BGP_NOTIFICATION_SIZE + 7) {
2011 tptr = dat + BGP_NOTIFICATION_SIZE;
2012 TCHECK2(*tptr, 7);
2013 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2014 tok2strbuf(af_values, "Unknown",
2015 EXTRACT_16BITS(tptr), tokbuf, sizeof(tokbuf)),
2016 EXTRACT_16BITS(tptr),
2017 tok2strbuf(bgp_safi_values, "Unknown", *(tptr+2),
2018 tokbuf2, sizeof(tokbuf)),
2019 *(tptr+2),
2020 EXTRACT_32BITS(tptr+3));
2021 }
2022 break;
2023 default:
2024 break;
2025 }
2026
2027 return;
2028 trunc:
2029 printf("[|BGP]");
2030 }
2031
2032 static void
2033 bgp_route_refresh_print(const u_char *pptr, int len) {
2034
2035 const struct bgp_route_refresh *bgp_route_refresh_header;
2036 char tokbuf[TOKBUFSIZE];
2037 char tokbuf2[TOKBUFSIZE];
2038
2039 TCHECK2(pptr[0], BGP_ROUTE_REFRESH_SIZE);
2040
2041 /* some little sanity checking */
2042 if (len<BGP_ROUTE_REFRESH_SIZE)
2043 return;
2044
2045 bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
2046
2047 printf("\n\t AFI %s (%u), SAFI %s (%u)",
2048 tok2strbuf(af_values,"Unknown",
2049 /* this stinks but the compiler pads the structure
2050 * weird */
2051 EXTRACT_16BITS(&bgp_route_refresh_header->afi),
2052 tokbuf, sizeof(tokbuf)),
2053 EXTRACT_16BITS(&bgp_route_refresh_header->afi),
2054 tok2strbuf(bgp_safi_values,"Unknown",
2055 bgp_route_refresh_header->safi,
2056 tokbuf2, sizeof(tokbuf2)),
2057 bgp_route_refresh_header->safi);
2058
2059 if (vflag > 1) {
2060 TCHECK2(*pptr, len);
2061 print_unknown_data(pptr,"\n\t ", len);
2062 }
2063
2064 return;
2065 trunc:
2066 printf("[|BGP]");
2067 }
2068
2069 static int
2070 bgp_header_print(const u_char *dat, int length)
2071 {
2072 struct bgp bgp;
2073 char tokbuf[TOKBUFSIZE];
2074
2075 TCHECK2(dat[0], BGP_SIZE);
2076 memcpy(&bgp, dat, BGP_SIZE);
2077 printf("\n\t%s Message (%u), length: %u",
2078 tok2strbuf(bgp_msg_values, "Unknown", bgp.bgp_type,
2079 tokbuf, sizeof(tokbuf)),
2080 bgp.bgp_type,
2081 length);
2082
2083 switch (bgp.bgp_type) {
2084 case BGP_OPEN:
2085 bgp_open_print(dat, length);
2086 break;
2087 case BGP_UPDATE:
2088 bgp_update_print(dat, length);
2089 break;
2090 case BGP_NOTIFICATION:
2091 bgp_notification_print(dat, length);
2092 break;
2093 case BGP_KEEPALIVE:
2094 break;
2095 case BGP_ROUTE_REFRESH:
2096 bgp_route_refresh_print(dat, length);
2097 break;
2098 default:
2099 /* we have no decoder for the BGP message */
2100 TCHECK2(*dat, length);
2101 printf("\n\t no Message %u decoder",bgp.bgp_type);
2102 print_unknown_data(dat,"\n\t ",length);
2103 break;
2104 }
2105 return 1;
2106 trunc:
2107 printf("[|BGP]");
2108 return 0;
2109 }
2110
2111 void
2112 bgp_print(const u_char *dat, int length)
2113 {
2114 const u_char *p;
2115 const u_char *ep;
2116 const u_char *start;
2117 const u_char marker[] = {
2118 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2119 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2120 };
2121 struct bgp bgp;
2122 u_int16_t hlen;
2123 char tokbuf[TOKBUFSIZE];
2124
2125 ep = dat + length;
2126 if (snapend < dat + length)
2127 ep = snapend;
2128
2129 printf(": BGP, length: %u",length);
2130
2131 if (vflag < 1) /* lets be less chatty */
2132 return;
2133
2134 p = dat;
2135 start = p;
2136 while (p < ep) {
2137 if (!TTEST2(p[0], 1))
2138 break;
2139 if (p[0] != 0xff) {
2140 p++;
2141 continue;
2142 }
2143
2144 if (!TTEST2(p[0], sizeof(marker)))
2145 break;
2146 if (memcmp(p, marker, sizeof(marker)) != 0) {
2147 p++;
2148 continue;
2149 }
2150
2151 /* found BGP header */
2152 TCHECK2(p[0], BGP_SIZE); /*XXX*/
2153 memcpy(&bgp, p, BGP_SIZE);
2154
2155 if (start != p)
2156 printf(" [|BGP]");
2157
2158 hlen = ntohs(bgp.bgp_len);
2159 if (hlen < BGP_SIZE) {
2160 printf("\n[|BGP Bogus header length %u < %u]", hlen,
2161 BGP_SIZE);
2162 break;
2163 }
2164
2165 if (TTEST2(p[0], hlen)) {
2166 if (!bgp_header_print(p, hlen))
2167 return;
2168 p += hlen;
2169 start = p;
2170 } else {
2171 printf("\n[|BGP %s]",
2172 tok2strbuf(bgp_msg_values,
2173 "Unknown Message Type",
2174 bgp.bgp_type,
2175 tokbuf, sizeof(tokbuf)));
2176 break;
2177 }
2178 }
2179
2180 return;
2181
2182 trunc:
2183 printf(" [|BGP]");
2184 }