TODO drsuapi compressed
[wireshark-sm.git] / epan / dissectors / packet-bfd.c
blob7e8e59e4e2d023bb61484c7439e5405ad4fd9d17
1 /* packet-bfd.c
2 * Routines for Bidirectional Forwarding Detection (BFD) message dissection
3 * RFCs
4 * 5880: Bidirectional Forwarding Detection (BFD)
5 * 5881: Bidirectional Forwarding Detection (BFD) for IPv4 and IPv6 (Single Hop)
6 * 5882: Generic Application of Bidirectional Forwarding Detection (BFD)
7 * 5883: Bidirectional Forwarding Detection (BFD) for Multihop Paths
8 * 5884: Bidirectional Forwarding Detection (BFD) for MPLS Label Switched Paths (LSPs)
9 * 5885: Bidirectional Forwarding Detection (BFD) for the Pseudowire Virtual Circuit Connectivity Verification (VCCV)
10 * 7130: Bidirectional Forwarding Detection (BFD) on Link Aggregation Group (LAG) Interfaces
11 * 7881: Seamless Bidirectional Forwarding Detection (S-BFD) for IPv4, IPv6, and MPLS
12 * (and https://tools.ietf.org/html/draft-ietf-bfd-base-01 for version 0)
14 * Copyright 2003, Hannes Gredler <hannes@juniper.net>
15 * Copyright 2006, Balint Reczey <Balint.Reczey@ericsson.com>
16 * Copyright 2007, Todd J Martin <todd.martin@acm.org>
18 * Copyright 2011, Jaihari Kalijanakiraman <jaiharik@ipinfusion.com>
19 * Krishnamurthy Mayya <krishnamurthy.mayya@ipinfusion.com>
20 * Nikitha Malgi <malgi.nikitha@ipinfusion.com>
21 * - support for MPLS-TP BFD Proactive CV Message Format as per RFC 6428
22 * - includes decoding support for Section MEP-ID, LSP MEP-ID, PW MEP-ID
24 * Wireshark - Network traffic analyzer
25 * By Gerald Combs <gerald@wireshark.org>
26 * Copyright 1998 Gerald Combs
28 * SPDX-License-Identifier: GPL-2.0-or-later
31 #include "config.h"
33 #include <epan/packet.h>
34 #include <epan/expert.h>
35 #include <epan/tfs.h>
36 #include <epan/unit_strings.h>
38 #include "packet-bfd.h"
39 #include "packet-mpls.h"
41 void proto_register_bfd(void);
42 void proto_reg_handoff_bfd(void);
44 static dissector_handle_t bfd_control_handle;
45 static dissector_handle_t bfd_echo_handle;
47 /* 3784: BFD control, 3785: BFD echo, 4784: BFD multi hop control */
48 /* 6784: BFD on LAG, 7784: seamless BFD */
49 /* https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=bfd */
50 #define UDP_PORT_RANGE_BFD_CTRL "3784,4784,6784,7784"
51 #define UDP_PORT_BFD_ECHO 3785
53 /* As per RFC 6428 : https://tools.ietf.org/html/rfc6428
54 Section: 3.5 */
55 #define TLV_TYPE_MPLSTP_SECTION_MEP 0
56 #define TLV_TYPE_MPLSTP_LSP_MEP 1
57 #define TLV_TYPE_MPLSTP_PW_MEP 2
59 static const value_string mplstp_mep_tlv_type_values [] = {
60 { TLV_TYPE_MPLSTP_SECTION_MEP, "Section MEP-ID" },
61 { TLV_TYPE_MPLSTP_LSP_MEP, "LSP MEP-ID" },
62 { TLV_TYPE_MPLSTP_PW_MEP, "PW MEP-ID" },
63 { 0, NULL}
65 static const value_string bfd_control_v0_diag_values[] = {
66 { 0, "No Diagnostic" },
67 { 1, "Control Detection Time Expired" },
68 { 2, "Echo Function Failed" },
69 { 3, "Neighbor Signaled Session Down" },
70 { 4, "Forwarding Plane Reset" },
71 { 5, "Path Down" },
72 { 6, "Concatenated Path Down" },
73 { 7, "Administratively Down" },
74 { 0, NULL }
77 static const value_string bfd_control_v1_diag_values[] = {
78 { 0, "No Diagnostic" },
79 { 1, "Control Detection Time Expired" },
80 { 2, "Echo Function Failed" },
81 { 3, "Neighbor Signaled Session Down" },
82 { 4, "Forwarding Plane Reset" },
83 { 5, "Path Down" },
84 { 6, "Concatenated Path Down" },
85 { 7, "Administratively Down" },
86 { 8, "Reverse Concatenated Path Down" },
87 { 9, "Mis-Connectivity Defect" },
88 { 0, NULL }
91 static const value_string bfd_control_sta_values[] = {
92 { 0, "AdminDown" },
93 { 1, "Down" },
94 { 2, "Init" },
95 { 3, "Up" },
96 { 0, NULL }
99 #define BFD_AUTH_SIMPLE 1
100 #define BFD_AUTH_MD5 2
101 #define BFD_AUTH_MET_MD5 3
102 #define BFD_AUTH_SHA1 4
103 #define BFD_AUTH_MET_SHA1 5
104 static const value_string bfd_control_auth_type_values[] = {
105 { BFD_AUTH_SIMPLE , "Simple Password" },
106 { BFD_AUTH_MD5 , "Keyed MD5" },
107 { BFD_AUTH_MET_MD5 , "Meticulous Keyed MD5" },
108 { BFD_AUTH_SHA1 , "Keyed SHA1" },
109 { BFD_AUTH_MET_SHA1 , "Meticulous Keyed SHA1" },
110 { 0, NULL }
112 /* Per the standard, the simple password must by 1-16 bytes in length */
113 #define MAX_PASSWORD_LEN 16
114 /* Per the standard, the length of the MD5 authentication packets must be 24
115 * bytes and the checksum is 16 bytes */
116 #define MD5_AUTH_LEN 24
117 #define MD5_CHECKSUM_LEN 16
118 /* Per the standard, the length of the SHA1 authentication packets must be 28
119 * bytes and the checksum is 20 bytes */
120 #define SHA1_AUTH_LEN 28
121 #define SHA1_CHECKSUM_LEN 20
123 static int proto_bfd;
124 static int proto_bfd_echo;
126 static int hf_bfd_version;
127 static int hf_bfd_diag;
128 static int hf_bfd_sta;
129 static int hf_bfd_flags;
130 static int hf_bfd_flags_h;
131 static int hf_bfd_flags_p;
132 static int hf_bfd_flags_f;
133 static int hf_bfd_flags_c;
134 static int hf_bfd_flags_a;
135 static int hf_bfd_flags_d;
136 static int hf_bfd_flags_m;
137 static int hf_bfd_flags_d_v0;
138 static int hf_bfd_flags_p_v0;
139 static int hf_bfd_flags_f_v0;
140 static int hf_bfd_detect_time_multiplier;
141 static int hf_bfd_message_length;
142 static int hf_bfd_my_discriminator;
143 static int hf_bfd_your_discriminator;
144 static int hf_bfd_desired_min_tx_interval;
145 static int hf_bfd_required_min_rx_interval;
146 static int hf_bfd_required_min_echo_interval;
147 static int hf_bfd_checksum;
149 static int hf_bfd_auth_type;
150 static int hf_bfd_auth_len;
151 static int hf_bfd_auth_key;
152 static int hf_bfd_auth_password;
153 static int hf_bfd_auth_seq_num;
155 static int hf_bfd_echo;
157 static int ett_bfd;
158 static int ett_bfd_flags;
159 static int ett_bfd_auth;
161 static int ett_bfd_echo;
163 static expert_field ei_bfd_auth_len_invalid;
164 static expert_field ei_bfd_auth_no_data;
166 static int hf_mep_type;
167 static int hf_mep_len;
168 static int hf_mep_global_id;
169 static int hf_mep_node_id;
170 /* static int hf_mep_interface_no; */
171 static int hf_mep_tunnel_no;
172 static int hf_mep_lsp_no;
173 static int hf_mep_ac_id;
174 static int hf_mep_agi_type;
175 static int hf_mep_agi_len;
176 static int hf_mep_agi_val;
177 static int hf_section_interface_no;
179 * Control packet version 0, draft-katz-ward-bfd-01.txt
181 * 0 1 2 3
182 * 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
183 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
184 * |Vers | Diag |H|D|P|F| Rsvd | Detect Mult | Length |
185 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
186 * | My Discriminator |
187 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
188 * | Your Discriminator |
189 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
190 * | Desired Min TX Interval |
191 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
192 * | Required Min RX Interval |
193 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
194 * | Required Min Echo RX Interval |
195 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
199 * Control packet version 1, RFC 5880
201 * 0 1 2 3
202 * 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
203 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204 * |Vers | Diag |Sta|P|F|C|A|D|M| Detect Mult | Length |
205 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
206 * | My Discriminator |
207 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
208 * | Your Discriminator |
209 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
210 * | Desired Min TX Interval |
211 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
212 * | Required Min RX Interval |
213 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
214 * | Required Min Echo RX Interval |
215 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217 * An optional Authentication Section may be present:
218 * 0 1 2 3
219 * 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
220 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221 * | Auth Type | Auth Len | Authentication Data... |
222 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
224 * There are 5 types of authentication defined:
225 * 1 - Simple Password
226 * 2 - Keyed MD5
227 * 3 - Meticulous Keyed MD5
228 * 4 - Keyed SHA1
229 * 5 - Meticulous Keyed SHA1
231 * The format for Simple Password authentication is:
232 * 0 1 2 3
233 * 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
234 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
235 * | Auth Type | Auth Len | Auth Key ID | Password... |
236 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237 * | ... |
238 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240 * The format for Keyed MD5 and Meticulous Keyed MD5 authentication is:
241 * 0 1 2 3
242 * 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
243 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244 * | Auth Type | Auth Len | Auth Key ID | Reserved |
245 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
246 * | Sequence Number |
247 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 * | Auth Key/Checksum... |
249 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
250 * | ... |
251 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
253 * The format for Keyed SHA1 and Meticulous Keyed SHA1 authentication is:
254 * 0 1 2 3
255 * 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
256 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
257 * | Auth Type | Auth Len | Auth Key ID | Reserved |
258 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
259 * | Sequence Number |
260 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
261 * | Auth Key/Checksum... |
262 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
263 * | ... |
264 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
270 /* Given the type of authentication being used, return the required length of
271 * the authentication header
273 static uint8_t
274 get_bfd_required_auth_len(uint8_t auth_type)
276 uint8_t auth_len = 0;
278 switch (auth_type) {
279 case BFD_AUTH_MD5:
280 case BFD_AUTH_MET_MD5:
281 auth_len = MD5_AUTH_LEN;
282 break;
283 case BFD_AUTH_SHA1:
284 case BFD_AUTH_MET_SHA1:
285 auth_len = SHA1_AUTH_LEN;
286 break;
287 default:
288 break;
290 return auth_len;
293 /* Given the type of authentication being used, return the length of
294 * checksum field
296 static uint8_t
297 get_bfd_checksum_len(uint8_t auth_type)
299 uint8_t checksum_len = 0;
300 switch (auth_type) {
301 case BFD_AUTH_MD5:
302 case BFD_AUTH_MET_MD5:
303 checksum_len = MD5_CHECKSUM_LEN;
304 break;
305 case BFD_AUTH_SHA1:
306 case BFD_AUTH_MET_SHA1:
307 checksum_len = SHA1_CHECKSUM_LEN;
308 break;
309 default:
310 break;
312 return checksum_len;
315 static void
316 dissect_bfd_authentication(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
318 int offset = 24;
319 uint8_t auth_type;
320 uint8_t auth_len;
321 proto_item *auth_item = NULL;
322 proto_tree *auth_tree = NULL;
323 const uint8_t *password;
325 auth_type = tvb_get_uint8(tvb, offset);
326 auth_len = tvb_get_uint8(tvb, offset + 1);
328 if (tree) {
329 auth_tree = proto_tree_add_subtree_format(tree, tvb, offset, auth_len,
330 ett_bfd_auth, NULL, "Authentication: %s",
331 val_to_str(auth_type,
332 bfd_control_auth_type_values,
333 "Unknown Authentication Type (%d)") );
335 proto_tree_add_item(auth_tree, hf_bfd_auth_type, tvb, offset, 1, ENC_BIG_ENDIAN);
337 proto_tree_add_item(auth_tree, hf_bfd_auth_len, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
339 proto_tree_add_item(auth_tree, hf_bfd_auth_key, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
342 switch (auth_type) {
343 case BFD_AUTH_SIMPLE:
344 proto_tree_add_item_ret_string(auth_tree, hf_bfd_auth_password, tvb, offset+3,
345 auth_len-3, ENC_ASCII|ENC_NA, pinfo->pool, &password);
346 proto_item_append_text(auth_item, ": %s", password);
347 break;
348 case BFD_AUTH_MD5:
349 case BFD_AUTH_MET_MD5:
350 case BFD_AUTH_SHA1:
351 case BFD_AUTH_MET_SHA1:
352 if (auth_len != get_bfd_required_auth_len(auth_type)) {
353 proto_tree_add_expert_format(auth_tree, pinfo, &ei_bfd_auth_len_invalid, tvb, offset, auth_len,
354 "Length of authentication section (%d) is invalid for Authentication Type: %s",
355 auth_len, val_to_str(auth_type, bfd_control_auth_type_values, "Unknown Authentication Type (%d)") );
357 proto_item_append_text(auth_item, ": Invalid Authentication Section");
360 if (tree) {
361 proto_tree_add_item(auth_tree, hf_bfd_auth_seq_num, tvb, offset+4, 4, ENC_BIG_ENDIAN);
363 proto_tree_add_item(auth_tree, hf_bfd_checksum, tvb, offset+8, get_bfd_checksum_len(auth_type), ENC_NA);
365 break;
366 default:
367 break;
371 static int
372 dissect_bfd_echo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
374 proto_tree *bfd_tree = NULL;
375 unsigned bfd_length = tvb_reported_length_remaining(tvb, 0);
377 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BFD Echo");
378 /* XXX Add direction */
379 col_set_str(pinfo->cinfo, COL_INFO, "Originator specific content");
381 if (tree) {
382 proto_item *ti;
384 ti = proto_tree_add_protocol_format(tree, proto_bfd_echo, tvb, 0, bfd_length,
385 "BFD Echo message");
387 bfd_tree = proto_item_add_subtree(ti, ett_bfd_echo);
389 proto_tree_add_item(bfd_tree, hf_bfd_echo, tvb, 0, bfd_length, ENC_NA);
392 return bfd_length;
395 static int
396 dissect_bfd_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
398 unsigned flags;
399 unsigned bfd_version;
400 unsigned bfd_diag;
401 unsigned bfd_sta = 0;
402 unsigned bfd_flags;
403 unsigned bfd_flags_a = 0;
404 unsigned bfd_detect_time_multiplier;
405 unsigned bfd_length;
406 unsigned bfd_my_discriminator;
407 unsigned bfd_your_discriminator;
408 unsigned bfd_desired_min_tx_interval;
409 unsigned bfd_required_min_rx_interval;
410 unsigned bfd_required_min_echo_interval;
411 proto_tree *bfd_tree = NULL;
413 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BFD Control");
414 col_clear(pinfo->cinfo, COL_INFO);
416 bfd_version = (tvb_get_uint8(tvb, 0) & 0xe0) >> 5;
417 bfd_diag = (tvb_get_uint8(tvb, 0) & 0x1f);
418 flags = tvb_get_uint8(tvb, 1);
419 switch (bfd_version) {
420 case 0:
421 bfd_flags = flags;
422 break;
423 case 1:
424 default:
425 bfd_sta = flags & 0xc0;
426 bfd_flags = flags & 0x3e;
427 bfd_flags_a = flags & 0x04;
428 break;
431 bfd_detect_time_multiplier = tvb_get_uint8(tvb, 2);
432 bfd_length = tvb_get_uint8(tvb, 3);
433 bfd_my_discriminator = tvb_get_ntohl(tvb, 4);
434 bfd_your_discriminator = tvb_get_ntohl(tvb, 8);
435 bfd_desired_min_tx_interval = tvb_get_ntohl(tvb, 12);
436 bfd_required_min_rx_interval = tvb_get_ntohl(tvb, 16);
437 bfd_required_min_echo_interval = tvb_get_ntohl(tvb, 20);
439 switch (bfd_version) {
440 case 0:
441 col_add_fstr(pinfo->cinfo, COL_INFO, "Diag: %s, Flags: 0x%02x",
442 val_to_str_const(bfd_diag, bfd_control_v0_diag_values, "Unknown"),
443 bfd_flags);
444 break;
445 case 1:
446 default:
447 col_add_fstr(pinfo->cinfo, COL_INFO, "Diag: %s, State: %s, Flags: 0x%02x",
448 val_to_str_const(bfd_diag, bfd_control_v1_diag_values, "Unknown"),
449 val_to_str_const(bfd_sta >> 6 , bfd_control_sta_values, "Unknown"),
450 bfd_flags);
451 break;
454 if (tree) {
455 proto_item *ti;
457 ti = proto_tree_add_protocol_format(tree, proto_bfd, tvb, 0, bfd_length,
458 "BFD Control message");
460 bfd_tree = proto_item_add_subtree(ti, ett_bfd);
462 proto_tree_add_uint(bfd_tree, hf_bfd_version, tvb, 0,
463 1, bfd_version << 5);
465 proto_tree_add_uint(bfd_tree, hf_bfd_diag, tvb, 0,
466 1, bfd_diag);
468 switch (bfd_version) {
469 case 0:
470 break;
471 case 1:
472 default:
473 proto_tree_add_uint(bfd_tree, hf_bfd_sta, tvb, 1,
474 1, bfd_sta);
476 break;
478 switch (bfd_version) {
479 case 0:
481 static int * const bfd_message_flags[] = {
482 &hf_bfd_flags_h,
483 &hf_bfd_flags_d_v0,
484 &hf_bfd_flags_p_v0,
485 &hf_bfd_flags_f_v0,
486 NULL
488 proto_tree_add_bitmask_with_flags(bfd_tree, tvb, 1, hf_bfd_flags, ett_bfd_flags, bfd_message_flags, ENC_NA, BMT_NO_FALSE);
490 break;
491 case 1:
492 default:
494 static int * const bfd_message_flags[] = {
495 &hf_bfd_flags_p,
496 &hf_bfd_flags_f,
497 &hf_bfd_flags_c,
498 &hf_bfd_flags_a,
499 &hf_bfd_flags_d,
500 &hf_bfd_flags_m,
501 NULL
503 proto_tree_add_bitmask_with_flags(bfd_tree, tvb, 1, hf_bfd_flags, ett_bfd_flags, bfd_message_flags, ENC_NA, BMT_NO_FALSE);
505 break;
508 proto_tree_add_uint_format_value(bfd_tree, hf_bfd_detect_time_multiplier, tvb, 2,
509 1, bfd_detect_time_multiplier,
510 "%u (= %u ms Detection time)",
511 bfd_detect_time_multiplier,
512 bfd_detect_time_multiplier * (bfd_desired_min_tx_interval/1000));
514 proto_tree_add_uint(bfd_tree, hf_bfd_message_length, tvb, 3, 1, bfd_length);
516 proto_tree_add_uint(bfd_tree, hf_bfd_my_discriminator, tvb, 4,
517 4, bfd_my_discriminator);
519 proto_tree_add_uint(bfd_tree, hf_bfd_your_discriminator, tvb, 8,
520 4, bfd_your_discriminator);
522 proto_tree_add_uint_format_value(bfd_tree, hf_bfd_desired_min_tx_interval, tvb, 12,
523 4, bfd_desired_min_tx_interval,
524 "%4u ms (%u us)",
525 bfd_desired_min_tx_interval/1000,
526 bfd_desired_min_tx_interval);
528 proto_tree_add_uint_format_value(bfd_tree, hf_bfd_required_min_rx_interval, tvb, 16,
529 4, bfd_required_min_rx_interval,
530 "%4u ms (%u us)",
531 bfd_required_min_rx_interval/1000,
532 bfd_required_min_rx_interval);
534 proto_tree_add_uint_format_value(bfd_tree, hf_bfd_required_min_echo_interval, tvb, 20,
535 4, bfd_required_min_echo_interval,
536 "%4u ms (%u us)",
537 bfd_required_min_echo_interval/1000,
538 bfd_required_min_echo_interval);
539 } /* if (tree) */
541 /* Dissect the authentication fields if the Authentication flag has
542 * been set
544 if (bfd_version && bfd_flags_a) {
545 if (bfd_length >= 28) {
546 dissect_bfd_authentication(tvb, pinfo, bfd_tree);
547 } else {
548 proto_tree_add_expert_format(bfd_tree, pinfo, &ei_bfd_auth_no_data, tvb, 24, bfd_length-24,
549 "Authentication: Length of the BFD frame is invalid (%d)", bfd_length);
553 return tvb_captured_length(tvb);
556 /* BFD CV Source MEP-ID TLV Decoder,
557 As per RFC 6428 : https://tools.ietf.org/html/rfc6428
558 sections - 3.5.1, 3.5.2, 3.5.3 */
559 void
560 dissect_bfd_mep (tvbuff_t *tvb, proto_tree *tree, const int hfindex)
562 proto_item *ti;
563 proto_tree *bfd_tree;
564 int offset = 0;
565 int mep_type;
566 int mep_len;
567 int mep_agi_len;
569 if (!tree)
570 return;
572 /* Fetch the BFD control message length and move the offset
573 to point to the data portion after the control message */
575 /* The parameter hfindex is used for determining the tree under which MEP-ID TLV
576 has to be determined. Since according to RFC 6428, MEP-ID TLV can be used by any
577 OAM function, if hfindex is 0, as per this function the MEP-TLV is a part of
578 BFD-CV payload. If a non-zero hfindex comes, then tht TLV info will be displayed
579 under a particular protocol-tree. */
580 if (!hfindex)
582 offset = tvb_get_uint8(tvb, 3);
583 mep_type = tvb_get_ntohs (tvb, offset);
584 mep_len = tvb_get_ntohs (tvb, (offset + 2));
585 ti = proto_tree_add_protocol_format (tree, proto_bfd, tvb, offset, (mep_len + 4),
586 "MPLS-TP SOURCE MEP-ID TLV");
588 else
590 mep_type = tvb_get_ntohs (tvb, offset);
591 mep_len = tvb_get_ntohs (tvb, (offset + 2));
592 ti = proto_tree_add_protocol_format (tree, hfindex, tvb, offset, (mep_len + 4),
593 "MPLS-TP SOURCE MEP-ID TLV");
596 switch (mep_type) {
597 case TLV_TYPE_MPLSTP_SECTION_MEP:
599 bfd_tree = proto_item_add_subtree (ti, ett_bfd);
600 proto_tree_add_uint (bfd_tree, hf_mep_type , tvb, offset,
601 2, mep_type);
602 proto_tree_add_uint (bfd_tree, hf_mep_len, tvb, (offset + 2),
603 2, mep_len);
604 proto_tree_add_item (bfd_tree, hf_mep_global_id, tvb, (offset + 4),
605 4, ENC_BIG_ENDIAN);
606 proto_tree_add_item (bfd_tree, hf_mep_node_id, tvb, (offset + 8),
607 4, ENC_BIG_ENDIAN);
608 proto_tree_add_item (bfd_tree, hf_section_interface_no, tvb, (offset + 12),
609 4, ENC_BIG_ENDIAN);
611 break;
613 case TLV_TYPE_MPLSTP_LSP_MEP:
615 bfd_tree = proto_item_add_subtree (ti, ett_bfd);
616 proto_tree_add_uint (bfd_tree, hf_mep_type , tvb, offset,
617 2, mep_type);
618 proto_tree_add_uint (bfd_tree, hf_mep_len, tvb, (offset + 2),
619 2, mep_len);
620 proto_tree_add_item (bfd_tree, hf_mep_global_id, tvb, (offset + 4),
621 4, ENC_BIG_ENDIAN);
622 proto_tree_add_item (bfd_tree, hf_mep_node_id, tvb, (offset + 8),
623 4, ENC_BIG_ENDIAN);
624 proto_tree_add_item (bfd_tree, hf_mep_tunnel_no, tvb, (offset + 12),
625 2, ENC_BIG_ENDIAN);
626 proto_tree_add_item (bfd_tree, hf_mep_lsp_no, tvb, (offset + 14),
627 2, ENC_BIG_ENDIAN);
629 break;
631 case TLV_TYPE_MPLSTP_PW_MEP:
633 mep_agi_len = tvb_get_uint8 (tvb, (offset + 17));
634 bfd_tree = proto_item_add_subtree (ti, ett_bfd);
635 proto_tree_add_uint (bfd_tree, hf_mep_type, tvb, offset,
636 2, (mep_type));
637 proto_tree_add_uint (bfd_tree, hf_mep_len, tvb, (offset + 2),
638 2, mep_len);
639 proto_tree_add_item (bfd_tree, hf_mep_global_id, tvb, (offset + 4),
640 4, ENC_BIG_ENDIAN);
641 proto_tree_add_item (bfd_tree, hf_mep_node_id, tvb, (offset + 8),
642 4, ENC_BIG_ENDIAN);
643 proto_tree_add_item (bfd_tree, hf_mep_ac_id, tvb, (offset + 12),
644 4, ENC_BIG_ENDIAN);
645 proto_tree_add_item (bfd_tree, hf_mep_agi_type, tvb, (offset + 16),
646 1, ENC_BIG_ENDIAN);
647 proto_tree_add_uint (bfd_tree, hf_mep_agi_len, tvb, (offset + 17),
648 1, mep_agi_len);
649 proto_tree_add_item (bfd_tree, hf_mep_agi_val, tvb, (offset + 18),
650 mep_agi_len, ENC_ASCII);
652 break;
654 default:
655 break;
657 return;
660 /* Register the protocol with Wireshark */
661 void
662 proto_register_bfd(void)
665 /* Setup list of header fields */
666 static hf_register_info hf[] = {
667 { &hf_bfd_version,
668 { "Protocol Version", "bfd.version",
669 FT_UINT8, BASE_DEC, NULL , 0xe0,
670 "The version number of the BFD protocol", HFILL }
672 { &hf_bfd_diag,
673 { "Diagnostic Code", "bfd.diag",
674 FT_UINT8, BASE_HEX, VALS(bfd_control_v1_diag_values), 0x1f,
675 "This field give the reason for a BFD session failure", HFILL }
677 { &hf_bfd_sta,
678 { "Session State", "bfd.sta",
679 FT_UINT8, BASE_HEX, VALS(bfd_control_sta_values), 0xc0,
680 "The BFD state as seen by the transmitting system", HFILL }
682 { &hf_bfd_flags,
683 { "Message Flags", "bfd.flags",
684 FT_UINT8, BASE_HEX, NULL, 0x00,
685 NULL, HFILL }
687 { &hf_bfd_flags_h,
688 { "I hear you", "bfd.flags.h",
689 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x80,
690 NULL, HFILL }
692 { &hf_bfd_flags_d_v0,
693 { "Demand", "bfd.flags.d",
694 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x40,
695 NULL, HFILL }
697 { &hf_bfd_flags_p_v0,
698 { "Poll", "bfd.flags.p",
699 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x20,
700 NULL, HFILL }
702 { &hf_bfd_flags_f_v0,
703 { "Final", "bfd.flags.f",
704 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x10,
705 NULL, HFILL }
707 { &hf_bfd_flags_p,
708 { "Poll", "bfd.flags.p",
709 FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x20, /* 6 flag bits; Sta is shown separately */
710 "If set, the transmitting system is expecting a packet with the Final (F) bit in reply",
711 HFILL }
713 { &hf_bfd_flags_f,
714 { "Final", "bfd.flags.f",
715 FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x10, /* 6 flag bits; Sta is shown separately */
716 "If set, the transmitting system is replying to a packet with the Poll (P) bit set",
717 HFILL }
719 { &hf_bfd_flags_c,
720 { "Control Plane Independent", "bfd.flags.c",
721 FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x08, /* 6 flag bits; Sta is shown separately */
722 "If set, the BFD implementation is implemented in the forwarding plane", HFILL }
724 { &hf_bfd_flags_a,
725 { "Authentication Present", "bfd.flags.a",
726 FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x04, /* 6 flag bits; Sta is shown separately */
727 "The Authentication Section is present", HFILL }
729 { &hf_bfd_flags_d,
730 { "Demand", "bfd.flags.d",
731 FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x02, /* 6 flag bits; Sta is shown separately */
732 "If set, Demand mode is active in the transmitting system", HFILL }
734 { &hf_bfd_flags_m,
735 { "Multipoint", "bfd.flags.m",
736 FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x01, /* 6 flag bits; Sta is shown separately */
737 "Reserved for future point-to-multipoint extensions", HFILL }
739 { &hf_bfd_detect_time_multiplier,
740 { "Detect Time Multiplier", "bfd.detect_time_multiplier",
741 FT_UINT8, BASE_DEC, NULL, 0x0,
742 "The transmit interval multiplied by this value is the failure detection time", HFILL }
744 { &hf_bfd_message_length,
745 { "Message Length", "bfd.message_length",
746 FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_byte_bytes), 0x0,
747 "Length of the BFD Control packet, in bytes", HFILL }
749 { &hf_bfd_my_discriminator,
750 { "My Discriminator", "bfd.my_discriminator",
751 FT_UINT32, BASE_HEX, NULL, 0x0,
752 NULL, HFILL }
754 { &hf_bfd_your_discriminator,
755 { "Your Discriminator", "bfd.your_discriminator",
756 FT_UINT32, BASE_HEX, NULL, 0x0,
757 NULL, HFILL }
759 { &hf_bfd_desired_min_tx_interval,
760 { "Desired Min TX Interval", "bfd.desired_min_tx_interval",
761 FT_UINT32, BASE_DEC, NULL, 0x0,
762 "The minimum interval to use when transmitting BFD Control packets", HFILL }
764 { &hf_bfd_required_min_rx_interval,
765 { "Required Min RX Interval", "bfd.required_min_rx_interval",
766 FT_UINT32, BASE_DEC, NULL, 0x0,
767 "The minimum interval between received BFD Control packets that this system can support", HFILL }
769 { &hf_bfd_required_min_echo_interval,
770 { "Required Min Echo Interval", "bfd.required_min_echo_interval",
771 FT_UINT32, BASE_DEC, NULL, 0x0,
772 "The minimum interval between received BFD Echo packets that this system can support", HFILL }
774 { &hf_bfd_checksum,
775 { "Checksum", "bfd.checksum",
776 FT_BYTES, BASE_NONE, NULL, 0x0,
777 NULL, HFILL }
779 { &hf_bfd_auth_type,
780 { "Authentication Type", "bfd.auth.type",
781 FT_UINT8, BASE_DEC, VALS(bfd_control_auth_type_values), 0x0,
782 "The type of authentication in use on this session", HFILL }
784 { &hf_bfd_auth_len,
785 { "Authentication Length", "bfd.auth.len",
786 FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_byte_bytes), 0x0,
787 "The length, in bytes, of the authentication section", HFILL }
789 { &hf_bfd_auth_key,
790 { "Authentication Key ID", "bfd.auth.key",
791 FT_UINT8, BASE_DEC, NULL, 0x0,
792 "The Authentication Key ID, identifies which password is in use for this packet", HFILL }
794 { &hf_bfd_auth_password,
795 { "Password", "bfd.auth.password",
796 FT_STRING, BASE_NONE, NULL, 0x0,
797 "The simple password in use on this session", HFILL }
799 { &hf_bfd_auth_seq_num,
800 { "Sequence Number", "bfd.auth.seq_num",
801 FT_UINT32, BASE_HEX, NULL, 0x0,
802 "The Sequence Number is periodically incremented to prevent replay attacks", HFILL }
804 { &hf_mep_type,
805 { "Type", "bfd.mep.type",
806 FT_UINT16, BASE_DEC, VALS(mplstp_mep_tlv_type_values), 0x0,
807 "The type of the MEP Id", HFILL }
809 { &hf_mep_len,
810 { "Length", "bfd.mep.len",
811 FT_UINT16, BASE_DEC, NULL , 0x0,
812 "The length of the MEP Id", HFILL }
814 { &hf_mep_global_id,
815 { "Global Id", "bfd.mep.global.id",
816 FT_UINT32, BASE_DEC, NULL , 0x0,
817 "MPLS-TP Global MEP Id", HFILL }
819 { &hf_mep_node_id,
820 { "Node Id", "bfd.mep.node.id",
821 FT_IPv4, BASE_NONE, NULL , 0x0,
822 "MPLS-TP Node Identifier", HFILL }
824 #if 0
825 { &hf_mep_interface_no,
826 { "Interface Number", "bfd.mep.interface.no",
827 FT_UINT32, BASE_DEC, NULL , 0x0,
828 "MPLS-TP Interface Number", HFILL }
830 #endif
831 { &hf_mep_tunnel_no,
832 { "Tunnel Number", "bfd.mep.tunnel.no",
833 FT_UINT16, BASE_DEC, NULL , 0x0,
834 NULL, HFILL }
836 { &hf_mep_lsp_no,
837 { "LSP Number", "bfd.mep.lsp.no",
838 FT_UINT16, BASE_DEC, NULL , 0x0,
839 NULL, HFILL }
841 { &hf_mep_ac_id,
842 { "AC Id", "bfd.mep.ac.id",
843 FT_UINT32, BASE_DEC, NULL , 0x0,
844 NULL, HFILL }
846 { &hf_mep_agi_type,
847 { "AGI TYPE", "bfd.mep.agi.type",
848 FT_UINT8, BASE_DEC, NULL , 0x0,
849 NULL, HFILL }
851 { &hf_mep_agi_len,
852 { "AGI Length", "bfd.mep.agi.len",
853 FT_UINT8, BASE_DEC, NULL , 0x0,
854 NULL, HFILL }
856 { &hf_mep_agi_val,
857 { "AGI value", "bfd.mep.agi.val",
858 FT_STRING, BASE_NONE, NULL , 0x0,
859 NULL, HFILL }
861 { &hf_section_interface_no,
862 { "Interface Number", "bfd.mep.interface.no",
863 FT_UINT32, BASE_DEC, NULL , 0x0,
864 "MPLS-TP Interface Number", HFILL }
867 /* BFD Echo */
868 static hf_register_info hf_echo[] = {
869 { &hf_bfd_echo,
870 { "Echo", "bfd_echo.packet",
871 FT_BYTES, BASE_NONE, NULL, 0x0,
872 "Originator specific echo packet", HFILL }
876 /* Setup protocol subtree array */
877 static int *ett[] = {
878 &ett_bfd,
879 &ett_bfd_flags,
880 &ett_bfd_auth,
881 &ett_bfd_echo
884 static ei_register_info ei[] = {
885 { &ei_bfd_auth_len_invalid, { "bfd.auth.len.invalid", PI_MALFORMED, PI_WARN, "Length of authentication section is invalid", EXPFILL }},
886 { &ei_bfd_auth_no_data, { "bfd.auth.no_data", PI_MALFORMED, PI_WARN, "Authentication flag is set in a BFD packet, but no authentication data is present", EXPFILL }},
889 expert_module_t* expert_bfd;
891 /* Register the protocol name and description */
892 proto_bfd = proto_register_protocol("Bidirectional Forwarding Detection Control Message",
893 "BFD Control",
894 "bfd");
895 proto_bfd_echo = proto_register_protocol("Bidirectional Forwarding Detection Echo Packet",
896 "BFD Echo",
897 "bfd_echo");
899 /* Required function calls to register the header fields and subtrees used */
900 proto_register_field_array(proto_bfd, hf, array_length(hf));
901 proto_register_field_array(proto_bfd_echo, hf_echo, array_length(hf_echo));
902 proto_register_subtree_array(ett, array_length(ett));
903 expert_bfd = expert_register_protocol(proto_bfd);
904 expert_register_field_array(expert_bfd, ei, array_length(ei));
906 /* Register dissectors */
907 bfd_control_handle = register_dissector("bfd", dissect_bfd_control, proto_bfd);
908 bfd_echo_handle = register_dissector("bfd_echo", dissect_bfd_echo, proto_bfd_echo);
911 void
912 proto_reg_handoff_bfd(void)
914 dissector_add_uint_range_with_preference("udp.port", UDP_PORT_RANGE_BFD_CTRL, bfd_control_handle);
915 dissector_add_uint("udp.port", UDP_PORT_BFD_ECHO, bfd_echo_handle);
917 dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_BFD_CC, bfd_control_handle);
918 dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_BFD_CV, bfd_control_handle);
919 dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_BFD, bfd_control_handle);
923 * Editor modelines - https://www.wireshark.org/tools/modelines.html
925 * Local variables:
926 * c-basic-offset: 4
927 * tab-width: 8
928 * indent-tabs-mode: nil
929 * End:
931 * vi: set shiftwidth=4 tabstop=8 expandtab:
932 * :indentSize=4:tabSize=8:noTabs=true: