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