2 * Copyright (c) 1998-2006 The TCPDUMP project
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.
15 * support for the Cisco prop. VQP Protocol
17 * Original code by Carles Kishimoto <Carles.Kishimoto@bsc.es>
20 #include <sys/cdefs.h>
22 __RCSID("$NetBSD: print-vqp.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
25 #define NETDISSECT_REWORKED
30 #include <tcpdump-stdinc.h>
32 #include "interface.h"
34 #include "addrtoname.h"
37 #define VQP_EXTRACT_VERSION(x) ((x)&0xFF)
43 * 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
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * | Constant | Packet type | Error Code | nitems |
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * | Packet Sequence Number (4 bytes) |
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 struct vqp_common_header_t
{
59 struct vqp_obj_tlv_t
{
61 uint8_t obj_length
[2];
64 #define VQP_OBJ_REQ_JOIN_PORT 0x01
65 #define VQP_OBJ_RESP_VLAN 0x02
66 #define VQP_OBJ_REQ_RECONFIRM 0x03
67 #define VQP_OBJ_RESP_RECONFIRM 0x04
69 static const struct tok vqp_msg_type_values
[] = {
70 { VQP_OBJ_REQ_JOIN_PORT
, "Request, Join Port"},
71 { VQP_OBJ_RESP_VLAN
, "Response, VLAN"},
72 { VQP_OBJ_REQ_RECONFIRM
, "Request, Reconfirm"},
73 { VQP_OBJ_RESP_RECONFIRM
, "Response, Reconfirm"},
77 static const struct tok vqp_error_code_values
[] = {
79 { 0x03, "Access denied"},
80 { 0x04, "Shutdown port"},
81 { 0x05, "Wrong VTP domain"},
85 /* FIXME the heading 0x0c looks ugly - those must be flags etc. */
86 #define VQP_OBJ_IP_ADDRESS 0x0c01
87 #define VQP_OBJ_PORT_NAME 0x0c02
88 #define VQP_OBJ_VLAN_NAME 0x0c03
89 #define VQP_OBJ_VTP_DOMAIN 0x0c04
90 #define VQP_OBJ_ETHERNET_PKT 0x0c05
91 #define VQP_OBJ_MAC_NULL 0x0c06
92 #define VQP_OBJ_MAC_ADDRESS 0x0c08
94 static const struct tok vqp_obj_values
[] = {
95 { VQP_OBJ_IP_ADDRESS
, "Client IP Address" },
96 { VQP_OBJ_PORT_NAME
, "Port Name" },
97 { VQP_OBJ_VLAN_NAME
, "VLAN Name" },
98 { VQP_OBJ_VTP_DOMAIN
, "VTP Domain" },
99 { VQP_OBJ_ETHERNET_PKT
, "Ethernet Packet" },
100 { VQP_OBJ_MAC_NULL
, "MAC Null" },
101 { VQP_OBJ_MAC_ADDRESS
, "MAC Address" },
106 vqp_print(netdissect_options
*ndo
, register const u_char
*pptr
, register u_int len
)
108 const struct vqp_common_header_t
*vqp_common_header
;
109 const struct vqp_obj_tlv_t
*vqp_obj_tlv
;
112 uint16_t vqp_obj_len
;
113 uint32_t vqp_obj_type
;
119 vqp_common_header
= (const struct vqp_common_header_t
*)pptr
;
120 ND_TCHECK(*vqp_common_header
);
123 * Sanity checking of the header.
125 if (VQP_EXTRACT_VERSION(vqp_common_header
->version
) != VQP_VERSION
) {
126 ND_PRINT((ndo
, "VQP version %u packet not supported",
127 VQP_EXTRACT_VERSION(vqp_common_header
->version
)));
131 /* in non-verbose mode just lets print the basic Message Type */
132 if (ndo
->ndo_vflag
< 1) {
133 ND_PRINT((ndo
, "VQPv%u %s Message, error-code %s (%u), length %u",
134 VQP_EXTRACT_VERSION(vqp_common_header
->version
),
135 tok2str(vqp_msg_type_values
, "unknown (%u)",vqp_common_header
->msg_type
),
136 tok2str(vqp_error_code_values
, "unknown (%u)",vqp_common_header
->error_code
),
137 vqp_common_header
->error_code
,
142 /* ok they seem to want to know everything - lets fully decode it */
143 nitems
= vqp_common_header
->nitems
;
144 ND_PRINT((ndo
, "\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u",
145 VQP_EXTRACT_VERSION(vqp_common_header
->version
),
146 tok2str(vqp_msg_type_values
, "unknown (%u)",vqp_common_header
->msg_type
),
147 tok2str(vqp_error_code_values
, "unknown (%u)",vqp_common_header
->error_code
),
148 vqp_common_header
->error_code
,
149 EXTRACT_32BITS(&vqp_common_header
->sequence
),
153 /* skip VQP Common header */
154 tptr
+=sizeof(const struct vqp_common_header_t
);
155 tlen
-=sizeof(const struct vqp_common_header_t
);
157 while (nitems
> 0 && tlen
> 0) {
159 vqp_obj_tlv
= (const struct vqp_obj_tlv_t
*)tptr
;
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
);
165 ND_PRINT((ndo
, "\n\t %s Object (0x%08x), length %u, value: ",
166 tok2str(vqp_obj_values
, "Unknown", vqp_obj_type
),
167 vqp_obj_type
, vqp_obj_len
));
169 /* basic sanity check */
170 if (vqp_obj_type
== 0 || vqp_obj_len
==0) {
174 /* did we capture enough for fully decoding the object ? */
175 ND_TCHECK2(*tptr
, vqp_obj_len
);
177 switch(vqp_obj_type
) {
178 case VQP_OBJ_IP_ADDRESS
:
179 ND_PRINT((ndo
, "%s (0x%08x)", ipaddr_string(ndo
, tptr
), EXTRACT_32BITS(tptr
)));
181 /* those objects have similar semantics - fall through */
182 case VQP_OBJ_PORT_NAME
:
183 case VQP_OBJ_VLAN_NAME
:
184 case VQP_OBJ_VTP_DOMAIN
:
185 case VQP_OBJ_ETHERNET_PKT
:
186 safeputs(ndo
, tptr
, vqp_obj_len
);
188 /* those objects have similar semantics - fall through */
189 case VQP_OBJ_MAC_ADDRESS
:
190 case VQP_OBJ_MAC_NULL
:
191 ND_PRINT((ndo
, "%s", etheraddr_string(ndo
, tptr
)));
194 if (ndo
->ndo_vflag
<= 1)
195 print_unknown_data(ndo
,tptr
, "\n\t ", vqp_obj_len
);
204 ND_PRINT((ndo
, "\n\t[|VQP]"));