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