2 * Routines for the Common Address Redundancy Protocol (CARP)
3 * Copyright 2013, Uli Heilmeier <uh@heilmeier.eu>
4 * Based on packet-vrrp.c by Heikki Vatiainen <hessu@cs.tut.fi>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/ipproto.h>
17 #include <epan/expert.h>
18 #include <epan/in_cksum.h>
20 void proto_register_carp(void);
21 void proto_reg_handoff_carp(void);
23 static dissector_handle_t carp_handle
;
25 static int proto_carp
;
27 static int ett_carp_ver_type
;
29 static int hf_carp_ver_type
;
30 static int hf_carp_version
;
31 static int hf_carp_type
;
32 static int hf_carp_vhid
;
33 static int hf_carp_advskew
;
34 static int hf_carp_authlen
;
35 static int hf_carp_demotion
;
36 static int hf_carp_advbase
;
37 static int hf_carp_counter
;
38 static int hf_carp_hmac
;
39 static int hf_carp_checksum
;
40 static int hf_carp_checksum_status
;
42 static expert_field ei_carp_checksum
;
44 #define CARP_VERSION_MASK 0xf0
45 #define CARP_TYPE_MASK 0x0f
47 #define CARP_TYPE_ADVERTISEMENT 1
48 static const value_string carp_type_vals
[] = {
49 {CARP_TYPE_ADVERTISEMENT
, "Advertisement"},
54 test_carp_packet(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree _U_
, void *data _U_
)
56 uint8_t ver_type
, version
, auth_length
;
58 /* First some simple check if the data is
60 if (tvb_captured_length(tvb
) < 36)
63 /* Version must be 1 or 2, type must be in carp_type_vals */
64 ver_type
= tvb_get_uint8(tvb
, 0);
65 version
= hi_nibble(ver_type
);
66 if ((version
== 0) || (version
> 2) ||
67 (try_val_to_str(lo_nibble(ver_type
), carp_type_vals
) == NULL
))
70 auth_length
= tvb_get_uint8(tvb
, 3);
71 if ( auth_length
!= 7 )
78 dissect_carp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
85 proto_tree
*carp_tree
, *ver_type_tree
;
88 /* Make sure it's a CARP packet */
89 if (!test_carp_packet(tvb
, pinfo
, tree
, data
))
92 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "CARP");
93 col_clear(pinfo
->cinfo
, COL_INFO
);
95 vhid
= tvb_get_uint8(tvb
, 1);
96 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s (Virtual Host ID: %u)",
97 "Announcement", vhid
);
99 ti
= proto_tree_add_item(tree
, proto_carp
, tvb
, 0, -1, ENC_NA
);
100 carp_tree
= proto_item_add_subtree(ti
, ett_carp
);
102 ver_type
= tvb_get_uint8(tvb
, 0);
103 tv
= proto_tree_add_uint_format(carp_tree
, hf_carp_ver_type
,
104 tvb
, offset
, 1, ver_type
,
105 "Version %u, Packet type %u (%s)",
106 hi_nibble(ver_type
), lo_nibble(ver_type
),
107 val_to_str_const(lo_nibble(ver_type
), carp_type_vals
, "Unknown"));
108 ver_type_tree
= proto_item_add_subtree(tv
, ett_carp_ver_type
);
109 proto_tree_add_uint(ver_type_tree
, hf_carp_version
, tvb
, offset
, 1, ver_type
);
110 proto_tree_add_uint(ver_type_tree
, hf_carp_type
, tvb
, offset
, 1, ver_type
);
113 proto_tree_add_item(carp_tree
, hf_carp_vhid
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
116 proto_tree_add_item(carp_tree
, hf_carp_advskew
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
119 proto_tree_add_item(carp_tree
, hf_carp_authlen
, tvb
,
120 offset
, 1, ENC_BIG_ENDIAN
);
123 proto_tree_add_item(carp_tree
, hf_carp_demotion
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
126 proto_tree_add_item(carp_tree
, hf_carp_advbase
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
129 carp_len
= tvb_reported_length(tvb
);
130 if (!pinfo
->fragmented
&& tvb_captured_length(tvb
) >= carp_len
) {
131 /* The packet isn't part of a fragmented datagram
132 and isn't truncated, so we can checksum it. */
133 SET_CKSUM_VEC_TVB(cksum_vec
[0], tvb
, 0, carp_len
);
134 proto_tree_add_checksum(carp_tree
, tvb
, offset
, hf_carp_checksum
, hf_carp_checksum_status
, &ei_carp_checksum
, pinfo
, in_cksum(&cksum_vec
[0], 1),
135 ENC_BIG_ENDIAN
, PROTO_CHECKSUM_VERIFY
|PROTO_CHECKSUM_IN_CKSUM
);
137 proto_tree_add_checksum(carp_tree
, tvb
, offset
, hf_carp_checksum
, hf_carp_checksum_status
, &ei_carp_checksum
, pinfo
, 0, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
143 proto_tree_add_item(carp_tree
, hf_carp_counter
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
146 proto_tree_add_item(carp_tree
, hf_carp_hmac
, tvb
, offset
, 20, ENC_NA
);
152 /* heuristic dissector */
154 dissect_carp_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
156 if (!test_carp_packet(tvb
, pinfo
, tree
, data
))
159 dissect_carp(tvb
, pinfo
, tree
, data
);
163 void proto_register_carp(void)
165 static hf_register_info hf
[] = {
167 {"CARP message version and type", "carp.typever",
168 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
172 {"CARP protocol version", "carp.version",
173 FT_UINT8
, BASE_DEC
, NULL
, CARP_VERSION_MASK
,
177 {"CARP packet type", "carp.type",
178 FT_UINT8
, BASE_DEC
, VALS(carp_type_vals
), CARP_TYPE_MASK
,
182 {"Virtual Host ID", "carp.vhid",
183 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
187 {"Advertisement Skew", "carp.advskew",
188 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
192 {"Auth Len", "carp.authlen",
193 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
194 "Size of counter+hash in 32bit chunks", HFILL
}},
197 {"Demotion indicator", "carp.demotion",
198 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
202 {"Adver Int", "carp.adver_int",
203 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
204 "Time interval (in seconds) between ADVERTISEMENTS", HFILL
}},
206 { &hf_carp_counter
, {"Counter", "carp.counter",
207 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
211 {"HMAC", "carp.hmac",
212 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
213 "SHA-1 HMAC", HFILL
}},
216 {"Checksum", "carp.checksum",
217 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
220 { &hf_carp_checksum_status
,
221 {"Checksum Status", "carp.checksum.status",
222 FT_UINT8
, BASE_NONE
, VALS(proto_checksum_vals
), 0x0,
226 static int *ett
[] = {
231 static ei_register_info ei
[] = {
232 { &ei_carp_checksum
, { "carp.bad_checksum", PI_CHECKSUM
, PI_ERROR
, "Bad checksum", EXPFILL
}},
235 expert_module_t
* expert_carp
;
237 proto_carp
= proto_register_protocol("Common Address Redundancy Protocol", "CARP", "carp");
238 carp_handle
= register_dissector("carp", dissect_carp
, proto_carp
);
239 proto_register_field_array(proto_carp
, hf
, array_length(hf
));
240 proto_register_subtree_array(ett
, array_length(ett
));
241 expert_carp
= expert_register_protocol(proto_carp
);
242 expert_register_field_array(expert_carp
, ei
, array_length(ei
));
246 proto_reg_handoff_carp(void)
248 dissector_add_uint("ip.proto", IP_PROTO_VRRP
, carp_handle
);
249 heur_dissector_add( "ip", dissect_carp_heur
, "CARP over IP", "carp_ip", proto_carp
, HEURISTIC_ENABLE
);
253 * Editor modelines - https://www.wireshark.org/tools/modelines.html
258 * indent-tabs-mode: nil
261 * vi: set shiftwidth=4 tabstop=8 expandtab:
262 * :indentSize=4:tabSize=8:noTabs=true: