Merge from vendor branch LIBPCAP:
[dragonfly.git] / contrib / tcpdump-3.8.3 / print-bfd.c
blob2c6aec40290c6e233f8c1ae0dd8544ee61506d74
1 /*
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that: (1) source code
4 * distributions retain the above copyright notice and this paragraph
5 * in its entirety, and (2) distributions including binary code include
6 * the above copyright notice and this paragraph in its entirety in
7 * the documentation or other materials provided with the distribution.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11 * FOR A PARTICULAR PURPOSE.
13 * Original code by Hannes Gredler (hannes@juniper.net)
16 #ifndef lint
17 static const char rcsid[] _U_ =
18 "@(#) $Header: /tcpdump/master/tcpdump/print-bfd.c,v 1.3.2.2 2003/11/16 08:51:12 guy Exp $";
19 #endif
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include <tcpdump-stdinc.h>
27 #include <stdio.h>
28 #include <stdlib.h>
30 #include "interface.h"
31 #include "extract.h"
32 #include "addrtoname.h"
34 #include "udp.h"
37 * Control packet, draft-katz-ward-bfd-01.txt
39 * 0 1 2 3
40 * 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
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * |Vers | Diag |H|D|P|F| Rsvd | Detect Mult | Length |
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | My Discriminator |
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Your Discriminator |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Desired Min TX Interval |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * | Required Min RX Interval |
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * | Required Min Echo RX Interval |
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 struct bfd_header_t {
57 u_int8_t version_diag;
58 u_int8_t flags;
59 u_int8_t detect_time_multiplier;
60 u_int8_t length;
61 u_int8_t my_discriminator[4];
62 u_int8_t your_discriminator[4];
63 u_int8_t desired_min_tx_interval[4];
64 u_int8_t required_min_rx_interval[4];
65 u_int8_t required_min_echo_interval[4];
68 #define BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
69 #define BFD_EXTRACT_DIAG(x) ((x)&0x1f)
71 static const struct tok bfd_port_values[] = {
72 { BFD_CONTROL_PORT, "Control" },
73 { BFD_ECHO_PORT, "Echo" },
74 { 0, NULL }
78 static const struct tok bfd_diag_values[] = {
79 { 0, "No Diagnostic" },
80 { 1, "Control Detection Time Expired" },
81 { 2, "Echo Function Failed" },
82 { 3, "Neighbor Signaled Session Down" },
83 { 4, "Forwarding Plane Reset" },
84 { 5, "Path Down" },
85 { 6, "Concatenated Path Down" },
86 { 7, "Administratively Down" },
87 { 0, NULL }
90 static const struct tok bfd_flag_values[] = {
91 { 0x80, "I Hear You" },
92 { 0x40, "Demand" },
93 { 0x20, "Poll" },
94 { 0x10, "Final" },
95 { 0x08, "Reserved" },
96 { 0x04, "Reserved" },
97 { 0x02, "Reserved" },
98 { 0x01, "Reserved" },
99 { 0, NULL }
102 void
103 bfd_print(register const u_char *pptr, register u_int len, register u_int port)
105 const struct bfd_header_t *bfd_header;
107 bfd_header = (const struct bfd_header_t *)pptr;
108 TCHECK(*bfd_header);
110 switch (port) {
112 case BFD_CONTROL_PORT:
113 if (vflag < 1 )
115 printf("BFDv%u, %s, Flags: [%s], length: %u",
116 BFD_EXTRACT_VERSION(bfd_header->version_diag),
117 tok2str(bfd_port_values, "unknown (%u)", port),
118 bittok2str(bfd_flag_values, "none", bfd_header->flags),
119 len);
120 return;
123 printf("BFDv%u, length: %u\n\t%s, Flags: [%s], Diagnostic: %s (0x%02x)",
124 BFD_EXTRACT_VERSION(bfd_header->version_diag),
125 len,
126 tok2str(bfd_port_values, "unknown (%u)", port),
127 bittok2str(bfd_flag_values, "none", bfd_header->flags),
128 tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
129 BFD_EXTRACT_DIAG(bfd_header->version_diag));
131 printf("\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
132 bfd_header->detect_time_multiplier,
133 bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
134 bfd_header->length);
137 printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator));
138 printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator));
139 printf("\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000);
140 printf("\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000);
141 printf("\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000);
142 break;
144 case BFD_ECHO_PORT: /* not yet supported - fall through */
146 default:
147 printf("BFD, %s, length: %u",
148 tok2str(bfd_port_values, "unknown (%u)", port),
149 len);
150 if (vflag >= 1) {
151 if(!print_unknown_data(pptr,"\n\t",len))
152 return;
154 break;
156 return;
158 trunc:
159 printf("[|BFD]");