JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1998-2006 The TCPDUMP project |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that: (1) source code |
| 6 | * distributions retain the above copyright notice and this paragraph |
| 7 | * in its entirety, and (2) distributions including binary code include |
| 8 | * the above copyright notice and this paragraph in its entirety in |
| 9 | * the documentation or other materials provided with the distribution. |
| 10 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND |
| 11 | * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT |
| 12 | * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 13 | * FOR A PARTICULAR PURPOSE. |
| 14 | * |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 15 | * Original code by Carles Kishimoto <Carles.Kishimoto@bsc.es> |
| 16 | */ |
| 17 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 18 | /* \summary: Cisco VLAN Query Protocol (VQP) printer */ |
| 19 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 20 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 21 | #include <config.h> |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 22 | #endif |
| 23 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 24 | #include "netdissect-stdinc.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 25 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 26 | #define ND_LONGJMP_FROM_TCHECK |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 27 | #include "netdissect.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 28 | #include "extract.h" |
| 29 | #include "addrtoname.h" |
| 30 | |
| 31 | #define VQP_VERSION 1 |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * VQP common header |
| 35 | * |
| 36 | * 0 1 2 3 |
| 37 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 38 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 39 | * | Constant | Packet type | Error Code | nitems | |
| 40 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 41 | * | Packet Sequence Number (4 bytes) | |
| 42 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 43 | */ |
| 44 | |
| 45 | struct vqp_common_header_t { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 46 | nd_uint8_t version; |
| 47 | nd_uint8_t msg_type; |
| 48 | nd_uint8_t error_code; |
| 49 | nd_uint8_t nitems; |
| 50 | nd_uint32_t sequence; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct vqp_obj_tlv_t { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 54 | nd_uint32_t obj_type; |
| 55 | nd_uint16_t obj_length; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | #define VQP_OBJ_REQ_JOIN_PORT 0x01 |
| 59 | #define VQP_OBJ_RESP_VLAN 0x02 |
| 60 | #define VQP_OBJ_REQ_RECONFIRM 0x03 |
| 61 | #define VQP_OBJ_RESP_RECONFIRM 0x04 |
| 62 | |
| 63 | static const struct tok vqp_msg_type_values[] = { |
| 64 | { VQP_OBJ_REQ_JOIN_PORT, "Request, Join Port"}, |
| 65 | { VQP_OBJ_RESP_VLAN, "Response, VLAN"}, |
| 66 | { VQP_OBJ_REQ_RECONFIRM, "Request, Reconfirm"}, |
| 67 | { VQP_OBJ_RESP_RECONFIRM, "Response, Reconfirm"}, |
| 68 | { 0, NULL} |
| 69 | }; |
| 70 | |
| 71 | static const struct tok vqp_error_code_values[] = { |
| 72 | { 0x00, "No error"}, |
| 73 | { 0x03, "Access denied"}, |
| 74 | { 0x04, "Shutdown port"}, |
| 75 | { 0x05, "Wrong VTP domain"}, |
| 76 | { 0, NULL} |
| 77 | }; |
| 78 | |
| 79 | /* FIXME the heading 0x0c looks ugly - those must be flags etc. */ |
| 80 | #define VQP_OBJ_IP_ADDRESS 0x0c01 |
| 81 | #define VQP_OBJ_PORT_NAME 0x0c02 |
| 82 | #define VQP_OBJ_VLAN_NAME 0x0c03 |
| 83 | #define VQP_OBJ_VTP_DOMAIN 0x0c04 |
| 84 | #define VQP_OBJ_ETHERNET_PKT 0x0c05 |
| 85 | #define VQP_OBJ_MAC_NULL 0x0c06 |
| 86 | #define VQP_OBJ_MAC_ADDRESS 0x0c08 |
| 87 | |
| 88 | static const struct tok vqp_obj_values[] = { |
| 89 | { VQP_OBJ_IP_ADDRESS, "Client IP Address" }, |
| 90 | { VQP_OBJ_PORT_NAME, "Port Name" }, |
| 91 | { VQP_OBJ_VLAN_NAME, "VLAN Name" }, |
| 92 | { VQP_OBJ_VTP_DOMAIN, "VTP Domain" }, |
| 93 | { VQP_OBJ_ETHERNET_PKT, "Ethernet Packet" }, |
| 94 | { VQP_OBJ_MAC_NULL, "MAC Null" }, |
| 95 | { VQP_OBJ_MAC_ADDRESS, "MAC Address" }, |
| 96 | { 0, NULL} |
| 97 | }; |
| 98 | |
| 99 | void |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 100 | vqp_print(netdissect_options *ndo, const u_char *pptr, u_int len) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 101 | { |
| 102 | const struct vqp_common_header_t *vqp_common_header; |
| 103 | const struct vqp_obj_tlv_t *vqp_obj_tlv; |
| 104 | |
| 105 | const u_char *tptr; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 106 | uint8_t version; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 107 | uint16_t vqp_obj_len; |
| 108 | uint32_t vqp_obj_type; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 109 | u_int tlen; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 110 | uint8_t nitems; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 111 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 112 | ndo->ndo_protocol = "vqp"; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 113 | tptr=pptr; |
| 114 | tlen = len; |
| 115 | vqp_common_header = (const struct vqp_common_header_t *)pptr; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 116 | ND_TCHECK_SIZE(vqp_common_header); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 117 | if (sizeof(struct vqp_common_header_t) > tlen) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 118 | goto invalid; |
| 119 | version = GET_U_1(vqp_common_header->version); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Sanity checking of the header. |
| 123 | */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 124 | if (version != VQP_VERSION) { |
| 125 | ND_PRINT("VQP version %u packet not supported", |
| 126 | version); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 127 | return; |
| 128 | } |
| 129 | |
| 130 | /* in non-verbose mode just lets print the basic Message Type */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 131 | if (ndo->ndo_vflag < 1) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 132 | ND_PRINT("VQPv%u %s Message, error-code %s (%u), length %u", |
| 133 | version, |
| 134 | tok2str(vqp_msg_type_values, "unknown (%u)",GET_U_1(vqp_common_header->msg_type)), |
| 135 | tok2str(vqp_error_code_values, "unknown (%u)",GET_U_1(vqp_common_header->error_code)), |
| 136 | GET_U_1(vqp_common_header->error_code), |
| 137 | len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 138 | return; |
| 139 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 140 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 141 | /* ok they seem to want to know everything - lets fully decode it */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 142 | nitems = GET_U_1(vqp_common_header->nitems); |
| 143 | ND_PRINT("\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", |
| 144 | version, |
| 145 | tok2str(vqp_msg_type_values, "unknown (%u)",GET_U_1(vqp_common_header->msg_type)), |
| 146 | tok2str(vqp_error_code_values, "unknown (%u)",GET_U_1(vqp_common_header->error_code)), |
| 147 | GET_U_1(vqp_common_header->error_code), |
| 148 | GET_BE_U_4(vqp_common_header->sequence), |
| 149 | nitems, |
| 150 | len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 151 | |
| 152 | /* skip VQP Common header */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 153 | tptr+=sizeof(struct vqp_common_header_t); |
| 154 | tlen-=sizeof(struct vqp_common_header_t); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 155 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 156 | while (nitems != 0 && tlen != 0) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 157 | |
| 158 | vqp_obj_tlv = (const struct vqp_obj_tlv_t *)tptr; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 159 | ND_TCHECK_SIZE(vqp_obj_tlv); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 160 | if (sizeof(struct vqp_obj_tlv_t) > tlen) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 161 | goto invalid; |
| 162 | vqp_obj_type = GET_BE_U_4(vqp_obj_tlv->obj_type); |
| 163 | vqp_obj_len = GET_BE_U_2(vqp_obj_tlv->obj_length); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 164 | tptr+=sizeof(struct vqp_obj_tlv_t); |
| 165 | tlen-=sizeof(struct vqp_obj_tlv_t); |
| 166 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 167 | ND_PRINT("\n\t %s Object (0x%08x), length %u, value: ", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 168 | tok2str(vqp_obj_values, "Unknown", vqp_obj_type), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 169 | vqp_obj_type, vqp_obj_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 170 | |
| 171 | /* basic sanity check */ |
| 172 | if (vqp_obj_type == 0 || vqp_obj_len ==0) { |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | /* did we capture enough for fully decoding the object ? */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 177 | ND_TCHECK_LEN(tptr, vqp_obj_len); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 178 | if (vqp_obj_len > tlen) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 179 | goto invalid; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 180 | |
| 181 | switch(vqp_obj_type) { |
| 182 | case VQP_OBJ_IP_ADDRESS: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 183 | if (vqp_obj_len != 4) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 184 | goto invalid; |
| 185 | ND_PRINT("%s (0x%08x)", GET_IPADDR_STRING(tptr), |
| 186 | GET_BE_U_4(tptr)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 187 | break; |
| 188 | /* those objects have similar semantics - fall through */ |
| 189 | case VQP_OBJ_PORT_NAME: |
| 190 | case VQP_OBJ_VLAN_NAME: |
| 191 | case VQP_OBJ_VTP_DOMAIN: |
| 192 | case VQP_OBJ_ETHERNET_PKT: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 193 | nd_printjnp(ndo, tptr, vqp_obj_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 194 | break; |
| 195 | /* those objects have similar semantics - fall through */ |
| 196 | case VQP_OBJ_MAC_ADDRESS: |
| 197 | case VQP_OBJ_MAC_NULL: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 198 | if (vqp_obj_len != MAC_ADDR_LEN) |
| 199 | goto invalid; |
| 200 | ND_PRINT("%s", GET_ETHERADDR_STRING(tptr)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 201 | break; |
| 202 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 203 | if (ndo->ndo_vflag <= 1) |
| 204 | print_unknown_data(ndo,tptr, "\n\t ", vqp_obj_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 205 | break; |
| 206 | } |
| 207 | tptr += vqp_obj_len; |
| 208 | tlen -= vqp_obj_len; |
| 209 | nitems--; |
| 210 | } |
| 211 | return; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 212 | invalid: |
| 213 | nd_print_invalid(ndo); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 214 | } |