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