Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / tcpdump / print-bfd.c
blob9dc3fde7b547abec1d55f0bdcef4ecd2b9de5ff1
1 /* $NetBSD$ */
3 /*
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 * Original code by Hannes Gredler (hannes@juniper.net)
18 #include <sys/cdefs.h>
19 #ifndef lint
20 #if 0
21 static const char rcsid[] _U_ =
22 "@(#) Header: /tcpdump/master/tcpdump/print-bfd.c,v 1.5.2.5 2006/02/02 06:36:37 hannes Exp";
23 #else
24 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
25 #endif
26 #endif
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
32 #include <tcpdump-stdinc.h>
34 #include <stdio.h>
35 #include <stdlib.h>
37 #include "interface.h"
38 #include "extract.h"
39 #include "addrtoname.h"
41 #include "udp.h"
44 * Control packet, BFDv0, draft-katz-ward-bfd-01.txt
46 * 0 1 2 3
47 * 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
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * |Vers | Diag |H|D|P|F| Rsvd | Detect Mult | Length |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | My Discriminator |
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * | Your Discriminator |
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 * | Desired Min TX Interval |
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * | Required Min RX Interval |
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 * | Required Min Echo RX Interval |
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63 /*
64 * Control packet, BFDv1, draft-ietf-bfd-base-02.txt
66 * 0 1 2 3
67 * 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
68 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 * |Vers | Diag |Sta|P|F|C|A|D|R| Detect Mult | Length |
70 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 * | My Discriminator |
72 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 * | Your Discriminator |
74 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 * | Desired Min TX Interval |
76 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 * | Required Min RX Interval |
78 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 * | Required Min Echo RX Interval |
80 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 struct bfd_header_t {
84 u_int8_t version_diag;
85 u_int8_t flags;
86 u_int8_t detect_time_multiplier;
87 u_int8_t length;
88 u_int8_t my_discriminator[4];
89 u_int8_t your_discriminator[4];
90 u_int8_t desired_min_tx_interval[4];
91 u_int8_t required_min_rx_interval[4];
92 u_int8_t required_min_echo_interval[4];
96 * An optional Authentication Header may be present
98 * 0 1 2 3
99 * 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
100 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
101 * | Auth Type | Auth Len | Authentication Data... |
102 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
105 struct bfd_auth_header_t {
106 u_int8_t auth_type;
107 u_int8_t auth_len;
108 u_int8_t auth_data;
111 static const struct tok bfd_v1_authentication_values[] = {
112 { 0, "Reserved" },
113 { 1, "Simple Password" },
114 { 2, "Keyed MD5" },
115 { 3, "Meticulous Keyed MD5" },
116 { 4, "Keyed SHA1" },
117 { 5, "Meticulous Keyed SHA1" },
118 { 0, NULL }
121 #define BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
122 #define BFD_EXTRACT_DIAG(x) ((x)&0x1f)
124 static const struct tok bfd_port_values[] = {
125 { BFD_CONTROL_PORT, "Control" },
126 { BFD_ECHO_PORT, "Echo" },
127 { 0, NULL }
131 static const struct tok bfd_diag_values[] = {
132 { 0, "No Diagnostic" },
133 { 1, "Control Detection Time Expired" },
134 { 2, "Echo Function Failed" },
135 { 3, "Neighbor Signaled Session Down" },
136 { 4, "Forwarding Plane Reset" },
137 { 5, "Path Down" },
138 { 6, "Concatenated Path Down" },
139 { 7, "Administratively Down" },
140 { 8, "Reverse Concatenated Path Down" },
141 { 0, NULL }
144 static const struct tok bfd_v0_flag_values[] = {
145 { 0x80, "I Hear You" },
146 { 0x40, "Demand" },
147 { 0x20, "Poll" },
148 { 0x10, "Final" },
149 { 0x08, "Reserved" },
150 { 0x04, "Reserved" },
151 { 0x02, "Reserved" },
152 { 0x01, "Reserved" },
153 { 0, NULL }
156 #define BFD_FLAG_AUTH 0x04
158 static const struct tok bfd_v1_flag_values[] = {
159 { 0x20, "Poll" },
160 { 0x10, "Final" },
161 { 0x08, "Control Plane Independent" },
162 { BFD_FLAG_AUTH, "Authentication Present" },
163 { 0x02, "Demand" },
164 { 0x01, "Reserved" },
165 { 0, NULL }
168 static const struct tok bfd_v1_state_values[] = {
169 { 0, "AdminDown" },
170 { 1, "Down" },
171 { 2, "Init" },
172 { 3, "Up" },
173 { 0, NULL }
176 void
177 bfd_print(register const u_char *pptr, register u_int len, register u_int port)
179 const struct bfd_header_t *bfd_header;
180 const struct bfd_auth_header_t *bfd_auth_header;
181 u_int8_t version;
183 bfd_header = (const struct bfd_header_t *)pptr;
184 TCHECK(*bfd_header);
185 version = BFD_EXTRACT_VERSION(bfd_header->version_diag);
187 switch (port << 8 | version) {
189 /* BFDv0 */
190 case (BFD_CONTROL_PORT << 8):
191 if (vflag < 1 )
193 printf("BFDv%u, %s, Flags: [%s], length: %u",
194 version,
195 tok2str(bfd_port_values, "unknown (%u)", port),
196 bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
197 len);
198 return;
201 printf("BFDv%u, length: %u\n\t%s, Flags: [%s], Diagnostic: %s (0x%02x)",
202 version,
203 len,
204 tok2str(bfd_port_values, "unknown (%u)", port),
205 bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
206 tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
207 BFD_EXTRACT_DIAG(bfd_header->version_diag));
209 printf("\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
210 bfd_header->detect_time_multiplier,
211 bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
212 bfd_header->length);
215 printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator));
216 printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator));
217 printf("\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000);
218 printf("\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000);
219 printf("\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000);
220 break;
222 /* BFDv1 */
223 case (BFD_CONTROL_PORT << 8 | 1):
224 if (vflag < 1 )
226 printf("BFDv%u, %s, State %s, Flags: [%s], length: %u",
227 version,
228 tok2str(bfd_port_values, "unknown (%u)", port),
229 tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
230 bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
231 len);
232 return;
235 printf("BFDv%u, length: %u\n\t%s, State %s, Flags: [%s], Diagnostic: %s (0x%02x)",
236 version,
237 len,
238 tok2str(bfd_port_values, "unknown (%u)", port),
239 tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
240 bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
241 tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
242 BFD_EXTRACT_DIAG(bfd_header->version_diag));
244 printf("\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
245 bfd_header->detect_time_multiplier,
246 bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
247 bfd_header->length);
250 printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator));
251 printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator));
252 printf("\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000);
253 printf("\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000);
254 printf("\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000);
256 if (bfd_header->flags & BFD_FLAG_AUTH) {
257 pptr += sizeof (const struct bfd_header_t);
258 bfd_auth_header = (const struct bfd_auth_header_t *)pptr;
259 TCHECK2(*bfd_auth_header, sizeof(const struct bfd_auth_header_t));
260 printf("\n\t%s (%u) Authentication, length %u present",
261 tok2str(bfd_v1_authentication_values,"Unknown",bfd_auth_header->auth_type),
262 bfd_auth_header->auth_type,
263 bfd_auth_header->auth_len);
265 break;
267 /* BFDv0 */
268 case (BFD_ECHO_PORT << 8): /* not yet supported - fall through */
269 /* BFDv1 */
270 case (BFD_ECHO_PORT << 8 | 1):
272 default:
273 printf("BFD, %s, length: %u",
274 tok2str(bfd_port_values, "unknown (%u)", port),
275 len);
276 if (vflag >= 1) {
277 if(!print_unknown_data(pptr,"\n\t",len))
278 return;
280 break;
282 return;
284 trunc:
285 printf("[|BFD]");