The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 |
| 3 | * The Regents of the University of California. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that: (1) source code distributions |
| 7 | * retain the above copyright notice and this paragraph in its entirety, (2) |
| 8 | * distributions including binary code include the above copyright notice and |
| 9 | * this paragraph in its entirety in the documentation or other materials |
| 10 | * provided with the distribution, and (3) all advertising materials mentioning |
| 11 | * features or use of this software display the following acknowledgement: |
| 12 | * ``This product includes software developed by the University of California, |
| 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
| 14 | * the University nor the names of its contributors may be used to endorse |
| 15 | * or promote products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 20 | */ |
| 21 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: Address Resolution Protocol (ARP) printer */ |
| 23 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 25 | #include <config.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #endif |
| 27 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 28 | #include "netdissect-stdinc.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 29 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 30 | #define ND_LONGJMP_FROM_TCHECK |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 31 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 32 | #include "addrtoname.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 33 | #include "ethertype.h" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 34 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 35 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 36 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 37 | /* |
| 38 | * Address Resolution Protocol. |
| 39 | * |
| 40 | * See RFC 826 for protocol description. ARP packets are variable |
| 41 | * in size; the arphdr structure defines the fixed-length portion. |
| 42 | * Protocol type values are the same as those for 10 Mb/s Ethernet. |
| 43 | * It is followed by the variable-sized fields ar_sha, arp_spa, |
| 44 | * arp_tha and arp_tpa in that order, according to the lengths |
| 45 | * specified. Field names used correspond to RFC 826. |
| 46 | */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 47 | struct arp_pkthdr { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 48 | nd_uint16_t ar_hrd; /* format of hardware address */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 49 | #define ARPHRD_ETHER 1 /* ethernet hardware format */ |
| 50 | #define ARPHRD_IEEE802 6 /* token-ring hardware format */ |
| 51 | #define ARPHRD_ARCNET 7 /* arcnet hardware format */ |
| 52 | #define ARPHRD_FRELAY 15 /* frame relay hardware format */ |
| 53 | #define ARPHRD_ATM2225 19 /* ATM (RFC 2225) */ |
| 54 | #define ARPHRD_STRIP 23 /* Ricochet Starmode Radio hardware format */ |
| 55 | #define ARPHRD_IEEE1394 24 /* IEEE 1394 (FireWire) hardware format */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 56 | #define ARPHRD_INFINIBAND 32 /* InfiniBand RFC 4391 */ |
| 57 | nd_uint16_t ar_pro; /* format of protocol address */ |
| 58 | nd_uint8_t ar_hln; /* length of hardware address */ |
| 59 | nd_uint8_t ar_pln; /* length of protocol address */ |
| 60 | nd_uint16_t ar_op; /* one of: */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 61 | #define ARPOP_REQUEST 1 /* request to resolve address */ |
| 62 | #define ARPOP_REPLY 2 /* response to previous request */ |
| 63 | #define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ |
| 64 | #define ARPOP_REVREPLY 4 /* response giving protocol address */ |
| 65 | #define ARPOP_INVREQUEST 8 /* request to identify peer */ |
| 66 | #define ARPOP_INVREPLY 9 /* response identifying peer */ |
| 67 | #define ARPOP_NAK 10 /* NAK - only valif for ATM ARP */ |
| 68 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 69 | /* |
| 70 | * The remaining fields are variable in size, |
| 71 | * according to the sizes above. |
| 72 | */ |
| 73 | #ifdef COMMENT_ONLY |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 74 | nd_byte ar_sha[]; /* sender hardware address */ |
| 75 | nd_byte ar_spa[]; /* sender protocol address */ |
| 76 | nd_byte ar_tha[]; /* target hardware address */ |
| 77 | nd_byte ar_tpa[]; /* target protocol address */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 78 | #endif |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 79 | #define ar_sha(ap) (((const u_char *)((ap)+1))+ 0) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 80 | #define ar_spa(ap) (((const u_char *)((ap)+1))+ GET_U_1((ap)->ar_hln)) |
| 81 | #define ar_tha(ap) (((const u_char *)((ap)+1))+ GET_U_1((ap)->ar_hln)+GET_U_1((ap)->ar_pln)) |
| 82 | #define ar_tpa(ap) (((const u_char *)((ap)+1))+2*GET_U_1((ap)->ar_hln)+GET_U_1((ap)->ar_pln)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #define ARP_HDRLEN 8 |
| 86 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 87 | #define HRD(ap) GET_BE_U_2((ap)->ar_hrd) |
| 88 | #define HRD_LEN(ap) GET_U_1((ap)->ar_hln) |
| 89 | #define PROTO_LEN(ap) GET_U_1((ap)->ar_pln) |
| 90 | #define OP(ap) GET_BE_U_2((ap)->ar_op) |
| 91 | #define PRO(ap) GET_BE_U_2((ap)->ar_pro) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 92 | #define SHA(ap) (ar_sha(ap)) |
| 93 | #define SPA(ap) (ar_spa(ap)) |
| 94 | #define THA(ap) (ar_tha(ap)) |
| 95 | #define TPA(ap) (ar_tpa(ap)) |
| 96 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 97 | |
| 98 | static const struct tok arpop_values[] = { |
| 99 | { ARPOP_REQUEST, "Request" }, |
| 100 | { ARPOP_REPLY, "Reply" }, |
| 101 | { ARPOP_REVREQUEST, "Reverse Request" }, |
| 102 | { ARPOP_REVREPLY, "Reverse Reply" }, |
| 103 | { ARPOP_INVREQUEST, "Inverse Request" }, |
| 104 | { ARPOP_INVREPLY, "Inverse Reply" }, |
| 105 | { ARPOP_NAK, "NACK Reply" }, |
| 106 | { 0, NULL } |
| 107 | }; |
| 108 | |
| 109 | static const struct tok arphrd_values[] = { |
| 110 | { ARPHRD_ETHER, "Ethernet" }, |
| 111 | { ARPHRD_IEEE802, "TokenRing" }, |
| 112 | { ARPHRD_ARCNET, "ArcNet" }, |
| 113 | { ARPHRD_FRELAY, "FrameRelay" }, |
| 114 | { ARPHRD_STRIP, "Strip" }, |
| 115 | { ARPHRD_IEEE1394, "IEEE 1394" }, |
| 116 | { ARPHRD_ATM2225, "ATM" }, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 117 | { ARPHRD_INFINIBAND, "InfiniBand" }, |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 118 | { 0, NULL } |
| 119 | }; |
| 120 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 121 | /* |
| 122 | * ATM Address Resolution Protocol. |
| 123 | * |
| 124 | * See RFC 2225 for protocol description. ATMARP packets are similar |
| 125 | * to ARP packets, except that there are no length fields for the |
| 126 | * protocol address - instead, there are type/length fields for |
| 127 | * the ATM number and subaddress - and the hardware addresses consist |
| 128 | * of an ATM number and an ATM subaddress. |
| 129 | */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 130 | struct atmarp_pkthdr { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 131 | nd_uint16_t aar_hrd; /* format of hardware address */ |
| 132 | nd_uint16_t aar_pro; /* format of protocol address */ |
| 133 | nd_uint8_t aar_shtl; /* length of source ATM number */ |
| 134 | nd_uint8_t aar_sstl; /* length of source ATM subaddress */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 135 | #define ATMARP_IS_E164 0x40 /* bit in type/length for E.164 format */ |
| 136 | #define ATMARP_LEN_MASK 0x3F /* length of {sub}address in type/length */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 137 | nd_uint16_t aar_op; /* same as regular ARP */ |
| 138 | nd_uint8_t aar_spln; /* length of source protocol address */ |
| 139 | nd_uint8_t aar_thtl; /* length of target ATM number */ |
| 140 | nd_uint8_t aar_tstl; /* length of target ATM subaddress */ |
| 141 | nd_uint8_t aar_tpln; /* length of target protocol address */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 142 | /* |
| 143 | * The remaining fields are variable in size, |
| 144 | * according to the sizes above. |
| 145 | */ |
| 146 | #ifdef COMMENT_ONLY |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 147 | nd_byte aar_sha[]; /* source ATM number */ |
| 148 | nd_byte aar_ssa[]; /* source ATM subaddress */ |
| 149 | nd_byte aar_spa[]; /* sender protocol address */ |
| 150 | nd_byte aar_tha[]; /* target ATM number */ |
| 151 | nd_byte aar_tsa[]; /* target ATM subaddress */ |
| 152 | nd_byte aar_tpa[]; /* target protocol address */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 153 | #endif |
| 154 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 155 | #define ATMHRD(ap) GET_BE_U_2((ap)->aar_hrd) |
| 156 | #define ATMSHRD_LEN(ap) (GET_U_1((ap)->aar_shtl) & ATMARP_LEN_MASK) |
| 157 | #define ATMSSLN(ap) (GET_U_1((ap)->aar_sstl) & ATMARP_LEN_MASK) |
| 158 | #define ATMSPROTO_LEN(ap) GET_U_1((ap)->aar_spln) |
| 159 | #define ATMOP(ap) GET_BE_U_2((ap)->aar_op) |
| 160 | #define ATMPRO(ap) GET_BE_U_2((ap)->aar_pro) |
| 161 | #define ATMTHRD_LEN(ap) (GET_U_1((ap)->aar_thtl) & ATMARP_LEN_MASK) |
| 162 | #define ATMTSLN(ap) (GET_U_1((ap)->aar_tstl) & ATMARP_LEN_MASK) |
| 163 | #define ATMTPROTO_LEN(ap) GET_U_1((ap)->aar_tpln) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 164 | #define aar_sha(ap) ((const u_char *)((ap)+1)) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 165 | #define aar_ssa(ap) (aar_sha(ap) + ATMSHRD_LEN(ap)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 166 | #define aar_spa(ap) (aar_ssa(ap) + ATMSSLN(ap)) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 167 | #define aar_tha(ap) (aar_spa(ap) + ATMSPROTO_LEN(ap)) |
| 168 | #define aar_tsa(ap) (aar_tha(ap) + ATMTHRD_LEN(ap)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 169 | #define aar_tpa(ap) (aar_tsa(ap) + ATMTSLN(ap)) |
| 170 | }; |
| 171 | |
| 172 | #define ATMSHA(ap) (aar_sha(ap)) |
| 173 | #define ATMSSA(ap) (aar_ssa(ap)) |
| 174 | #define ATMSPA(ap) (aar_spa(ap)) |
| 175 | #define ATMTHA(ap) (aar_tha(ap)) |
| 176 | #define ATMTSA(ap) (aar_tsa(ap)) |
| 177 | #define ATMTPA(ap) (aar_tpa(ap)) |
| 178 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 179 | static int |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 180 | isnonzero(netdissect_options *ndo, const u_char *a, size_t len) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 181 | { |
| 182 | while (len > 0) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 183 | if (GET_U_1(a) != 0) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 184 | return (1); |
| 185 | a++; |
| 186 | len--; |
| 187 | } |
| 188 | return (0); |
| 189 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 190 | |
| 191 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 192 | tpaddr_print_ip(netdissect_options *ndo, |
| 193 | const struct arp_pkthdr *ap, u_short pro) |
| 194 | { |
| 195 | if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 196 | ND_PRINT("<wrong proto type>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 197 | else if (PROTO_LEN(ap) != 4) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 198 | ND_PRINT("<wrong len>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 199 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 200 | ND_PRINT("%s", GET_IPADDR_STRING(TPA(ap))); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static void |
| 204 | spaddr_print_ip(netdissect_options *ndo, |
| 205 | const struct arp_pkthdr *ap, u_short pro) |
| 206 | { |
| 207 | if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 208 | ND_PRINT("<wrong proto type>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 209 | else if (PROTO_LEN(ap) != 4) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 210 | ND_PRINT("<wrong len>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 211 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 212 | ND_PRINT("%s", GET_IPADDR_STRING(SPA(ap))); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static void |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 216 | atmarp_addr_print(netdissect_options *ndo, |
| 217 | const u_char *ha, u_int ha_len, const u_char *srca, |
| 218 | u_int srca_len) |
| 219 | { |
| 220 | if (ha_len == 0) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 221 | ND_PRINT("<No address>"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 222 | else { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 223 | ND_PRINT("%s", GET_LINKADDR_STRING(ha, LINKADDR_ATM, ha_len)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 224 | if (srca_len != 0) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 225 | ND_PRINT(",%s", |
| 226 | GET_LINKADDR_STRING(srca, LINKADDR_ATM, srca_len)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 231 | atmarp_tpaddr_print(netdissect_options *ndo, |
| 232 | const struct atmarp_pkthdr *ap, u_short pro) |
| 233 | { |
| 234 | if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 235 | ND_PRINT("<wrong proto type>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 236 | else if (ATMTPROTO_LEN(ap) != 4) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 237 | ND_PRINT("<wrong tplen>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 238 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 239 | ND_PRINT("%s", GET_IPADDR_STRING(ATMTPA(ap))); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static void |
| 243 | atmarp_spaddr_print(netdissect_options *ndo, |
| 244 | const struct atmarp_pkthdr *ap, u_short pro) |
| 245 | { |
| 246 | if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 247 | ND_PRINT("<wrong proto type>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 248 | else if (ATMSPROTO_LEN(ap) != 4) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 249 | ND_PRINT("<wrong splen>"); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 250 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 251 | ND_PRINT("%s", GET_IPADDR_STRING(ATMSPA(ap))); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 255 | atmarp_print(netdissect_options *ndo, |
| 256 | const u_char *bp, u_int length, u_int caplen) |
| 257 | { |
| 258 | const struct atmarp_pkthdr *ap; |
| 259 | u_short pro, hrd, op; |
| 260 | |
| 261 | ap = (const struct atmarp_pkthdr *)bp; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 262 | ND_TCHECK_SIZE(ap); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 263 | |
| 264 | hrd = ATMHRD(ap); |
| 265 | pro = ATMPRO(ap); |
| 266 | op = ATMOP(ap); |
| 267 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 268 | ND_TCHECK_LEN(ATMTPA(ap), ATMTPROTO_LEN(ap)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 269 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 270 | if (!ndo->ndo_eflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 271 | ND_PRINT("ARP, "); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 272 | } |
| 273 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 274 | if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) || |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 275 | ATMSPROTO_LEN(ap) != 4 || |
| 276 | ATMTPROTO_LEN(ap) != 4 || |
| 277 | ndo->ndo_vflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 278 | ND_PRINT("%s, %s (len %u/%u)", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 279 | tok2str(arphrd_values, "Unknown Hardware (%u)", hrd), |
| 280 | tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro), |
| 281 | ATMSPROTO_LEN(ap), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 282 | ATMTPROTO_LEN(ap)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 283 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 284 | /* don't know about the address formats */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 285 | if (!ndo->ndo_vflag) { |
| 286 | goto out; |
| 287 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 288 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 289 | |
| 290 | /* print operation */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 291 | ND_PRINT("%s%s ", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 292 | ndo->ndo_vflag ? ", " : "", |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 293 | tok2str(arpop_values, "Unknown (%u)", op)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 294 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 295 | switch (op) { |
| 296 | |
| 297 | case ARPOP_REQUEST: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 298 | ND_PRINT("who-has "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 299 | atmarp_tpaddr_print(ndo, ap, pro); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 300 | if (ATMTHRD_LEN(ap) != 0) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 301 | ND_PRINT(" ("); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 302 | atmarp_addr_print(ndo, ATMTHA(ap), ATMTHRD_LEN(ap), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 303 | ATMTSA(ap), ATMTSLN(ap)); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 304 | ND_PRINT(")"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 305 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 306 | ND_PRINT(" tell "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 307 | atmarp_spaddr_print(ndo, ap, pro); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 308 | break; |
| 309 | |
| 310 | case ARPOP_REPLY: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 311 | atmarp_spaddr_print(ndo, ap, pro); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 312 | ND_PRINT(" is-at "); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 313 | atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap), |
| 314 | ATMSSLN(ap)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 315 | break; |
| 316 | |
| 317 | case ARPOP_INVREQUEST: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 318 | ND_PRINT("who-is "); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 319 | atmarp_addr_print(ndo, ATMTHA(ap), ATMTHRD_LEN(ap), ATMTSA(ap), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 320 | ATMTSLN(ap)); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 321 | ND_PRINT(" tell "); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 322 | atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 323 | ATMSSLN(ap)); |
| 324 | break; |
| 325 | |
| 326 | case ARPOP_INVREPLY: |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 327 | atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 328 | ATMSSLN(ap)); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 329 | ND_PRINT("at "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 330 | atmarp_spaddr_print(ndo, ap, pro); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 331 | break; |
| 332 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 333 | case ARPOP_NAK: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 334 | ND_PRINT("for "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 335 | atmarp_spaddr_print(ndo, ap, pro); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 336 | break; |
| 337 | |
| 338 | default: |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 339 | ND_DEFAULTPRINT((const u_char *)ap, caplen); |
| 340 | return; |
| 341 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 342 | |
| 343 | out: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 344 | ND_PRINT(", length %u", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void |
| 348 | arp_print(netdissect_options *ndo, |
| 349 | const u_char *bp, u_int length, u_int caplen) |
| 350 | { |
| 351 | const struct arp_pkthdr *ap; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 352 | u_short pro, hrd, op, linkaddr; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 353 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 354 | ndo->ndo_protocol = "arp"; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 355 | ap = (const struct arp_pkthdr *)bp; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 356 | ND_TCHECK_SIZE(ap); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 357 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 358 | hrd = HRD(ap); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 359 | pro = PRO(ap); |
| 360 | op = OP(ap); |
| 361 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 362 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 363 | /* if its ATM then call the ATM ARP printer |
| 364 | for Frame-relay ARP most of the fields |
| 365 | are similar to Ethernet so overload the Ethernet Printer |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 366 | and set the linkaddr type for GET_LINKADDR_STRING() accordingly */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 367 | |
| 368 | switch(hrd) { |
| 369 | case ARPHRD_ATM2225: |
| 370 | atmarp_print(ndo, bp, length, caplen); |
| 371 | return; |
| 372 | case ARPHRD_FRELAY: |
| 373 | linkaddr = LINKADDR_FRELAY; |
| 374 | break; |
| 375 | default: |
| 376 | linkaddr = LINKADDR_ETHER; |
| 377 | break; |
| 378 | } |
| 379 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 380 | ND_TCHECK_LEN(TPA(ap), PROTO_LEN(ap)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 381 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 382 | if (!ndo->ndo_eflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 383 | ND_PRINT("ARP, "); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* print hardware type/len and proto type/len */ |
| 387 | if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) || |
| 388 | PROTO_LEN(ap) != 4 || |
| 389 | HRD_LEN(ap) == 0 || |
| 390 | ndo->ndo_vflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 391 | ND_PRINT("%s (len %u), %s (len %u)", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 392 | tok2str(arphrd_values, "Unknown Hardware (%u)", hrd), |
| 393 | HRD_LEN(ap), |
| 394 | tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 395 | PROTO_LEN(ap)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 396 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 397 | /* don't know about the address formats */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 398 | if (!ndo->ndo_vflag) { |
| 399 | goto out; |
| 400 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 401 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 402 | |
| 403 | /* print operation */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 404 | ND_PRINT("%s%s ", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 405 | ndo->ndo_vflag ? ", " : "", |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 406 | tok2str(arpop_values, "Unknown (%u)", op)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 407 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 408 | switch (op) { |
| 409 | |
| 410 | case ARPOP_REQUEST: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 411 | ND_PRINT("who-has "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 412 | tpaddr_print_ip(ndo, ap, pro); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 413 | if (isnonzero(ndo, (const u_char *)THA(ap), HRD_LEN(ap))) |
| 414 | ND_PRINT(" (%s)", |
| 415 | GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap))); |
| 416 | ND_PRINT(" tell "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 417 | spaddr_print_ip(ndo, ap, pro); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 418 | break; |
| 419 | |
| 420 | case ARPOP_REPLY: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 421 | spaddr_print_ip(ndo, ap, pro); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 422 | ND_PRINT(" is-at %s", |
| 423 | GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 424 | break; |
| 425 | |
| 426 | case ARPOP_REVREQUEST: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 427 | /* |
| 428 | * XXX - GET_LINKADDR_STRING() may return a pointer to |
| 429 | * a static buffer, so we only have one call to it per |
| 430 | * ND_PRINT() call. |
| 431 | * |
| 432 | * This should be done in a cleaner fashion. |
| 433 | */ |
| 434 | ND_PRINT("who-is %s", |
| 435 | GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap))); |
| 436 | ND_PRINT(" tell %s", |
| 437 | GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 438 | break; |
| 439 | |
| 440 | case ARPOP_REVREPLY: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 441 | ND_PRINT("%s at ", |
| 442 | GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap))); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 443 | tpaddr_print_ip(ndo, ap, pro); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 444 | break; |
| 445 | |
| 446 | case ARPOP_INVREQUEST: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 447 | /* |
| 448 | * XXX - GET_LINKADDR_STRING() may return a pointer to |
| 449 | * a static buffer, so we only have one call to it per |
| 450 | * ND_PRINT() call. |
| 451 | * |
| 452 | * This should be done in a cleaner fashion. |
| 453 | */ |
| 454 | ND_PRINT("who-is %s", |
| 455 | GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap))); |
| 456 | ND_PRINT(" tell %s", |
| 457 | GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 458 | break; |
| 459 | |
| 460 | case ARPOP_INVREPLY: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 461 | ND_PRINT("%s at ", |
| 462 | GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap))); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 463 | spaddr_print_ip(ndo, ap, pro); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 464 | break; |
| 465 | |
| 466 | default: |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 467 | ND_DEFAULTPRINT((const u_char *)ap, caplen); |
| 468 | return; |
| 469 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 470 | |
| 471 | out: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 472 | ND_PRINT(", length %u", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 473 | } |