2 * Routines for Bi-directional Fault Detection (BFD) message dissection
4 * Copyright 2003, Hannes Gredler <hannes@juniper.net>
5 * Copyright 2006, Balint Reczey <Balint.Reczey@ericsson.com>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 #include <epan/packet.h>
40 #define UDP_PORT_BFD_CONTROL 3784 /* draft-katz-ward-bfd-v4v6-1hop-00.txt */
42 static const value_string bfd_control_v0_diag_values[] = {
43 { 0, "No Diagnostic" },
44 { 1, "Control Detection Time Expired" },
45 { 2, "Echo Function Failed" },
46 { 3, "Neighbor Signaled Session Down" },
47 { 4, "Forwarding Plane Reset" },
49 { 6, "Concatenated Path Down" },
50 { 7, "Administratively Down" },
54 static const value_string bfd_control_v1_diag_values[] = {
55 { 0, "No Diagnostic" },
56 { 1, "Control Detection Time Expired" },
57 { 2, "Echo Function Failed" },
58 { 3, "Neighbor Signaled Session Down" },
59 { 4, "Forwarding Plane Reset" },
61 { 6, "Concatenated Path Down" },
62 { 7, "Administratively Down" },
63 { 8, "Reverse Concatenated Path Down" },
67 static const value_string bfd_control_sta_values[] = {
75 static gint proto_bfd = -1;
77 static gint hf_bfd_version = -1;
78 static gint hf_bfd_diag = -1;
79 static gint hf_bfd_sta = -1;
80 static gint hf_bfd_flags = -1;
81 static gint hf_bfd_flags_h = -1;
82 static gint hf_bfd_flags_p = -1;
83 static gint hf_bfd_flags_f = -1;
84 static gint hf_bfd_flags_c = -1;
85 static gint hf_bfd_flags_a = -1;
86 static gint hf_bfd_flags_d = -1;
87 static gint hf_bfd_flags_d_v0 = -1;
88 static gint hf_bfd_detect_time_multiplier = -1;
89 static gint hf_bfd_my_discriminator = -1;
90 static gint hf_bfd_your_discriminator = -1;
91 static gint hf_bfd_desired_min_tx_interval = -1;
92 static gint hf_bfd_required_min_rx_interval = -1;
93 static gint hf_bfd_required_min_echo_interval = -1;
95 static gint ett_bfd = -1;
96 static gint ett_bfd_flags = -1;
99 * Control packet version 0, draft-katz-ward-bfd-01.txt
102 * 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
103 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
104 * |Vers | Diag |H|D|P|F| Rsvd | Detect Mult | Length |
105 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106 * | My Discriminator |
107 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108 * | Your Discriminator |
109 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110 * | Desired Min TX Interval |
111 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112 * | Required Min RX Interval |
113 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114 * | Required Min Echo RX Interval |
115 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 * Control packet version 1, draft-ietf-bfd-base-04.txt
122 * 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
123 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
124 * |Vers | Diag |Sta|P|F|C|A|D|R| Detect Mult | Length |
125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126 * | My Discriminator |
127 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 * | Your Discriminator |
129 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130 * | Desired Min TX Interval |
131 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132 * | Required Min RX Interval |
133 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
134 * | Required Min Echo RX Interval |
135 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
137 * An optional Authentication Section may be present:
138 * Dissection is not implemented yet.
140 * 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
141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 * | Auth Type | Auth Len | Authentication Data... |
143 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
149 static void dissect_bfd_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
151 gint bfd_version = -1;
155 gint bfd_flags_h = -1;
156 gint bfd_flags_p = -1;
157 gint bfd_flags_f = -1;
158 gint bfd_flags_c = -1;
159 gint bfd_flags_a = -1;
160 gint bfd_flags_d = -1;
161 gint bfd_flags_d_v0 = -1;
162 gint bfd_detect_time_multiplier = -1;
163 gint bfd_length = -1;
164 gint bfd_my_discriminator = -1;
165 gint bfd_your_discriminator = -1;
166 gint bfd_desired_min_tx_interval = -1;
167 gint bfd_required_min_rx_interval = -1;
168 gint bfd_required_min_echo_interval = -1;
171 proto_tree *bfd_tree;
172 proto_tree *bfd_flags_tree;
174 if (check_col(pinfo->cinfo, COL_PROTOCOL))
175 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BFD Control");
176 if (check_col(pinfo->cinfo, COL_INFO))
177 col_clear(pinfo->cinfo, COL_INFO);
179 bfd_version = ((tvb_get_guint8(tvb, 0) & 0xe0) >> 5);
180 bfd_diag = (tvb_get_guint8(tvb, 0) & 0x1f);
181 switch (bfd_version) {
183 bfd_flags = tvb_get_guint8(tvb, 1 );
184 bfd_flags_h = (tvb_get_guint8(tvb, 1) & 0x80);
185 bfd_flags_d_v0 = (tvb_get_guint8(tvb, 1) & 0x40);
189 bfd_sta = (tvb_get_guint8(tvb, 1) & 0xc0);
190 bfd_flags = (tvb_get_guint8(tvb, 1) & 0x3e);
191 bfd_flags_p = (tvb_get_guint8(tvb, 1) & 0x20);
192 bfd_flags_f = (tvb_get_guint8(tvb, 1) & 0x10);
193 bfd_flags_c = (tvb_get_guint8(tvb, 1) & 0x08);
194 bfd_flags_a = (tvb_get_guint8(tvb, 1) & 0x04);
195 bfd_flags_d = (tvb_get_guint8(tvb, 1) & 0x02);
198 bfd_detect_time_multiplier = tvb_get_guint8(tvb, 2);
199 bfd_length = tvb_get_guint8(tvb, 3);
201 bfd_my_discriminator = tvb_get_ntohl(tvb, 4);
202 bfd_your_discriminator = tvb_get_ntohl(tvb, 8);
203 bfd_desired_min_tx_interval = tvb_get_ntohl(tvb, 12);
204 bfd_required_min_rx_interval = tvb_get_ntohl(tvb, 16);
205 bfd_required_min_echo_interval = tvb_get_ntohl(tvb, 20);
207 if (check_col(pinfo->cinfo, COL_INFO)) {
208 switch (bfd_version) {
210 col_add_fstr(pinfo->cinfo, COL_INFO, "Diag: %s, Flags: 0x%02x",
211 val_to_str(bfd_diag, bfd_control_v0_diag_values, "UNKNOWN"),
216 col_add_fstr(pinfo->cinfo, COL_INFO, "Diag: %s, State: %s, Flags: 0x%02x",
217 val_to_str(bfd_diag, bfd_control_v1_diag_values, "UNKNOWN"),
218 val_to_str(bfd_sta >> 6 , bfd_control_sta_values, "UNKNOWN"),
225 ti = proto_tree_add_protocol_format(tree, proto_bfd, tvb, 0, -1,
226 "BFD Control message");
228 bfd_tree = proto_item_add_subtree(ti, ett_bfd);
230 ti = proto_tree_add_uint(bfd_tree, hf_bfd_version, tvb, 0,
231 1, bfd_version << 5);
233 ti = proto_tree_add_uint(bfd_tree, hf_bfd_diag, tvb, 0,
236 switch (bfd_version) {
241 ti = proto_tree_add_uint(bfd_tree, hf_bfd_sta, tvb, 1,
246 switch (bfd_version) {
248 ti = proto_tree_add_text ( bfd_tree, tvb, 1, 1, "Message Flags: 0x%02x",
250 bfd_flags_tree = proto_item_add_subtree(bfd_tree, ett_bfd_flags);
251 ti = proto_tree_add_boolean(bfd_flags_tree, hf_bfd_flags_h, tvb, 8, 1, bfd_flags_h);
252 ti = proto_tree_add_boolean(bfd_flags_tree, hf_bfd_flags_d_v0, tvb, 8, 1, bfd_flags_d_v0);
256 ti = proto_tree_add_text ( bfd_tree, tvb, 1, 1, "Message Flags: 0x%02x",
258 bfd_flags_tree = proto_item_add_subtree(bfd_tree, ett_bfd_flags);
259 ti = proto_tree_add_boolean(bfd_flags_tree, hf_bfd_flags_p, tvb, 6, 1, bfd_flags_p);
260 ti = proto_tree_add_boolean(bfd_flags_tree, hf_bfd_flags_f, tvb, 6, 1, bfd_flags_f);
261 ti = proto_tree_add_boolean(bfd_flags_tree, hf_bfd_flags_c, tvb, 6, 1, bfd_flags_c);
262 ti = proto_tree_add_boolean(bfd_flags_tree, hf_bfd_flags_a, tvb, 6, 1, bfd_flags_a);
263 ti = proto_tree_add_boolean(bfd_flags_tree, hf_bfd_flags_d, tvb, 6, 1, bfd_flags_d);
267 ti = proto_tree_add_uint_format_value(bfd_tree, hf_bfd_detect_time_multiplier, tvb, 2,
268 1, bfd_detect_time_multiplier,
269 "%u (= %u ms Detection time)",
270 bfd_detect_time_multiplier,
271 bfd_detect_time_multiplier * bfd_desired_min_tx_interval/1000);
273 ti = proto_tree_add_text ( bfd_tree, tvb, 3, 1, "Message Length: %u Bytes", bfd_length );
275 ti = proto_tree_add_uint(bfd_tree, hf_bfd_my_discriminator, tvb, 4,
276 4, bfd_my_discriminator);
278 ti = proto_tree_add_uint(bfd_tree, hf_bfd_your_discriminator, tvb, 8,
279 4, bfd_your_discriminator);
281 ti = proto_tree_add_uint_format_value(bfd_tree, hf_bfd_desired_min_tx_interval, tvb, 12,
282 4, bfd_desired_min_tx_interval,
284 bfd_desired_min_tx_interval/1000);
286 ti = proto_tree_add_uint_format_value(bfd_tree, hf_bfd_required_min_rx_interval, tvb, 16,
287 4, bfd_required_min_rx_interval,
289 bfd_required_min_rx_interval/1000);
291 ti = proto_tree_add_uint_format_value(bfd_tree, hf_bfd_required_min_echo_interval, tvb, 20,
292 4, bfd_required_min_echo_interval,
294 bfd_required_min_echo_interval/1000);
300 /* Register the protocol with Ethereal */
301 void proto_register_bfd(void)
304 /* Setup list of header fields */
305 static hf_register_info hf[] = {
307 { "Protocol Version", "bfd.version",
308 FT_UINT8, BASE_DEC, NULL , 0xe0,
312 { "Diagnostic Code", "bfd.diag",
313 FT_UINT8, BASE_HEX, VALS(bfd_control_v1_diag_values), 0x1f,
317 { "Session State", "bfd.sta",
318 FT_UINT8, BASE_HEX, VALS(bfd_control_sta_values), 0xc0,
322 { "Message Flags", "bfd.flags",
323 FT_UINT8, BASE_HEX, NULL, 0xf0,
327 { "I hear you", "bfd.flags.h",
328 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x80,
331 { &hf_bfd_flags_d_v0,
332 { "Demand", "bfd.flags.d",
333 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x40,
337 { "Poll", "bfd.flags.p",
338 FT_BOOLEAN, 6, TFS(&flags_set_truth), 0x20,
342 { "Final", "bfd.flags.f",
343 FT_BOOLEAN, 6, TFS(&flags_set_truth), 0x10,
347 { "Control Plane Independent", "bfd.flags.c",
348 FT_BOOLEAN, 6, TFS(&flags_set_truth), 0x08,
352 { "Authentication Present", "bfd.flags.a",
353 FT_BOOLEAN, 6, TFS(&flags_set_truth), 0x04,
357 { "Demand", "bfd.flags.d",
358 FT_BOOLEAN, 6, TFS(&flags_set_truth), 0x02,
361 { &hf_bfd_detect_time_multiplier,
362 { "Detect Time Multiplier", "bfd.detect_time_multiplier",
363 FT_UINT8, BASE_DEC, NULL, 0x0,
366 { &hf_bfd_my_discriminator,
367 { "My Discriminator", "bfd.my_discriminator",
368 FT_UINT32, BASE_HEX, NULL, 0x0,
371 { &hf_bfd_your_discriminator,
372 { "Your Discriminator", "bfd.your_discriminator",
373 FT_UINT32, BASE_HEX, NULL, 0x0,
376 { &hf_bfd_desired_min_tx_interval,
377 { "Desired Min TX Interval", "bfd.desired_min_tx_interval",
378 FT_UINT32, BASE_DEC, NULL, 0x0,
381 { &hf_bfd_required_min_rx_interval,
382 { "Required Min RX Interval", "bfd.required_min_rx_interval",
383 FT_UINT32, BASE_DEC, NULL, 0x0,
386 { &hf_bfd_required_min_echo_interval,
387 { "Required Min Echo Interval", "bfd.required_min_echo_interval",
388 FT_UINT32, BASE_DEC, NULL, 0x0,
393 /* Setup protocol subtree array */
394 static gint *ett[] = {
399 /* Register the protocol name and description */
400 proto_bfd = proto_register_protocol("Bi-directional Fault Detection Control Message",
404 /* Required function calls to register the header fields and subtrees used */
405 proto_register_field_array(proto_bfd, hf, array_length(hf));
406 proto_register_subtree_array(ett, array_length(ett));
410 proto_reg_handoff_bfd(void)
412 dissector_handle_t bfd_control_handle;
414 bfd_control_handle = create_dissector_handle(dissect_bfd_control, proto_bfd);
415 dissector_add("udp.port", UDP_PORT_BFD_CONTROL, bfd_control_handle);