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