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 |
| 21 | #include "config.h" |
| 22 | #endif |
| 23 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 24 | #include <netdissect-stdinc.h> |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 25 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 26 | #include "netdissect.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 27 | #include "extract.h" |
| 28 | #include "addrtoname.h" |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 29 | #include "ether.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 30 | |
| 31 | #define VQP_VERSION 1 |
| 32 | #define VQP_EXTRACT_VERSION(x) ((x)&0xFF) |
| 33 | |
| 34 | /* |
| 35 | * VQP common header |
| 36 | * |
| 37 | * 0 1 2 3 |
| 38 | * 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 |
| 39 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 40 | * | Constant | Packet type | Error Code | nitems | |
| 41 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 42 | * | Packet Sequence Number (4 bytes) | |
| 43 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 44 | */ |
| 45 | |
| 46 | struct vqp_common_header_t { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 47 | uint8_t version; |
| 48 | uint8_t msg_type; |
| 49 | uint8_t error_code; |
| 50 | uint8_t nitems; |
| 51 | uint8_t sequence[4]; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct vqp_obj_tlv_t { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 55 | uint8_t obj_type[4]; |
| 56 | uint8_t obj_length[2]; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | #define VQP_OBJ_REQ_JOIN_PORT 0x01 |
| 60 | #define VQP_OBJ_RESP_VLAN 0x02 |
| 61 | #define VQP_OBJ_REQ_RECONFIRM 0x03 |
| 62 | #define VQP_OBJ_RESP_RECONFIRM 0x04 |
| 63 | |
| 64 | static const struct tok vqp_msg_type_values[] = { |
| 65 | { VQP_OBJ_REQ_JOIN_PORT, "Request, Join Port"}, |
| 66 | { VQP_OBJ_RESP_VLAN, "Response, VLAN"}, |
| 67 | { VQP_OBJ_REQ_RECONFIRM, "Request, Reconfirm"}, |
| 68 | { VQP_OBJ_RESP_RECONFIRM, "Response, Reconfirm"}, |
| 69 | { 0, NULL} |
| 70 | }; |
| 71 | |
| 72 | static const struct tok vqp_error_code_values[] = { |
| 73 | { 0x00, "No error"}, |
| 74 | { 0x03, "Access denied"}, |
| 75 | { 0x04, "Shutdown port"}, |
| 76 | { 0x05, "Wrong VTP domain"}, |
| 77 | { 0, NULL} |
| 78 | }; |
| 79 | |
| 80 | /* FIXME the heading 0x0c looks ugly - those must be flags etc. */ |
| 81 | #define VQP_OBJ_IP_ADDRESS 0x0c01 |
| 82 | #define VQP_OBJ_PORT_NAME 0x0c02 |
| 83 | #define VQP_OBJ_VLAN_NAME 0x0c03 |
| 84 | #define VQP_OBJ_VTP_DOMAIN 0x0c04 |
| 85 | #define VQP_OBJ_ETHERNET_PKT 0x0c05 |
| 86 | #define VQP_OBJ_MAC_NULL 0x0c06 |
| 87 | #define VQP_OBJ_MAC_ADDRESS 0x0c08 |
| 88 | |
| 89 | static const struct tok vqp_obj_values[] = { |
| 90 | { VQP_OBJ_IP_ADDRESS, "Client IP Address" }, |
| 91 | { VQP_OBJ_PORT_NAME, "Port Name" }, |
| 92 | { VQP_OBJ_VLAN_NAME, "VLAN Name" }, |
| 93 | { VQP_OBJ_VTP_DOMAIN, "VTP Domain" }, |
| 94 | { VQP_OBJ_ETHERNET_PKT, "Ethernet Packet" }, |
| 95 | { VQP_OBJ_MAC_NULL, "MAC Null" }, |
| 96 | { VQP_OBJ_MAC_ADDRESS, "MAC Address" }, |
| 97 | { 0, NULL} |
| 98 | }; |
| 99 | |
| 100 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 101 | vqp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 102 | { |
| 103 | const struct vqp_common_header_t *vqp_common_header; |
| 104 | const struct vqp_obj_tlv_t *vqp_obj_tlv; |
| 105 | |
| 106 | const u_char *tptr; |
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 | |
| 112 | tptr=pptr; |
| 113 | tlen = len; |
| 114 | vqp_common_header = (const struct vqp_common_header_t *)pptr; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 115 | ND_TCHECK(*vqp_common_header); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 116 | if (sizeof(struct vqp_common_header_t) > tlen) |
| 117 | goto trunc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * Sanity checking of the header. |
| 121 | */ |
| 122 | if (VQP_EXTRACT_VERSION(vqp_common_header->version) != VQP_VERSION) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 123 | ND_PRINT((ndo, "VQP version %u packet not supported", |
| 124 | VQP_EXTRACT_VERSION(vqp_common_header->version))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 125 | return; |
| 126 | } |
| 127 | |
| 128 | /* in non-verbose mode just lets print the basic Message Type */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 129 | if (ndo->ndo_vflag < 1) { |
| 130 | ND_PRINT((ndo, "VQPv%u %s Message, error-code %s (%u), length %u", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 131 | VQP_EXTRACT_VERSION(vqp_common_header->version), |
| 132 | tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), |
| 133 | tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), |
| 134 | vqp_common_header->error_code, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 135 | len)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 136 | return; |
| 137 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 138 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 139 | /* ok they seem to want to know everything - lets fully decode it */ |
| 140 | nitems = vqp_common_header->nitems; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 141 | ND_PRINT((ndo, "\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 142 | VQP_EXTRACT_VERSION(vqp_common_header->version), |
| 143 | tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), |
| 144 | tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), |
| 145 | vqp_common_header->error_code, |
| 146 | EXTRACT_32BITS(&vqp_common_header->sequence), |
| 147 | nitems, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 148 | len)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 149 | |
| 150 | /* skip VQP Common header */ |
| 151 | tptr+=sizeof(const struct vqp_common_header_t); |
| 152 | tlen-=sizeof(const struct vqp_common_header_t); |
| 153 | |
| 154 | while (nitems > 0 && tlen > 0) { |
| 155 | |
| 156 | vqp_obj_tlv = (const struct vqp_obj_tlv_t *)tptr; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 157 | ND_TCHECK(*vqp_obj_tlv); |
| 158 | if (sizeof(struct vqp_obj_tlv_t) > tlen) |
| 159 | goto trunc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 160 | vqp_obj_type = EXTRACT_32BITS(vqp_obj_tlv->obj_type); |
| 161 | vqp_obj_len = EXTRACT_16BITS(vqp_obj_tlv->obj_length); |
| 162 | tptr+=sizeof(struct vqp_obj_tlv_t); |
| 163 | tlen-=sizeof(struct vqp_obj_tlv_t); |
| 164 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 165 | ND_PRINT((ndo, "\n\t %s Object (0x%08x), length %u, value: ", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 166 | tok2str(vqp_obj_values, "Unknown", vqp_obj_type), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 167 | vqp_obj_type, vqp_obj_len)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 168 | |
| 169 | /* basic sanity check */ |
| 170 | if (vqp_obj_type == 0 || vqp_obj_len ==0) { |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | /* did we capture enough for fully decoding the object ? */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 175 | ND_TCHECK2(*tptr, vqp_obj_len); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 176 | if (vqp_obj_len > tlen) |
| 177 | goto trunc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 178 | |
| 179 | switch(vqp_obj_type) { |
| 180 | case VQP_OBJ_IP_ADDRESS: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 181 | if (vqp_obj_len != 4) |
| 182 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 183 | ND_PRINT((ndo, "%s (0x%08x)", ipaddr_string(ndo, tptr), EXTRACT_32BITS(tptr))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 184 | break; |
| 185 | /* those objects have similar semantics - fall through */ |
| 186 | case VQP_OBJ_PORT_NAME: |
| 187 | case VQP_OBJ_VLAN_NAME: |
| 188 | case VQP_OBJ_VTP_DOMAIN: |
| 189 | case VQP_OBJ_ETHERNET_PKT: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 190 | safeputs(ndo, tptr, vqp_obj_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 191 | break; |
| 192 | /* those objects have similar semantics - fall through */ |
| 193 | case VQP_OBJ_MAC_ADDRESS: |
| 194 | case VQP_OBJ_MAC_NULL: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 195 | if (vqp_obj_len != ETHER_ADDR_LEN) |
| 196 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 197 | ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 198 | break; |
| 199 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 200 | if (ndo->ndo_vflag <= 1) |
| 201 | print_unknown_data(ndo,tptr, "\n\t ", vqp_obj_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 202 | break; |
| 203 | } |
| 204 | tptr += vqp_obj_len; |
| 205 | tlen -= vqp_obj_len; |
| 206 | nitems--; |
| 207 | } |
| 208 | return; |
| 209 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 210 | ND_PRINT((ndo, "\n\t[|VQP]")); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 211 | } |