source: rtems-libbsd/freebsd/contrib/tcpdump/print-bfd.c @ 084d4db

4.11
Last change on this file since 084d4db was 8440506, checked in by Chris Johns <chrisj@…>, on 06/15/15 at 07:42:23

Add tcpdump and libpcap.

  • Update the file builder generator to handle generator specific cflags and includes. The tcpdump and libpcap have localised headers and need specific headers paths to see them. There are also module specific flags and these need to be passed to the lex and yacc generators.
  • Add the tcpdump support.
  • Property mode set to 100644
File size: 11.0 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
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.
14 *
15 * Original code by Hannes Gredler (hannes@juniper.net)
16 */
17
18#ifndef lint
19static const char rcsid[] _U_ =
20    "@(#) $Header: /tcpdump/master/tcpdump/print-bfd.c,v 1.10 2006-02-02 06:35:52 hannes Exp $";
21#endif
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <tcpdump-stdinc.h>
28
29#include <stdio.h>
30#include <stdlib.h>
31
32#include "interface.h"
33#include "extract.h"
34#include "addrtoname.h"
35
36#include "udp.h"
37
38/*
39 * Control packet, BFDv0, draft-katz-ward-bfd-01.txt
40 *
41 *     0                   1                   2                   3
42 *     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
43 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 *    |Vers |  Diag   |H|D|P|F| Rsvd  |  Detect Mult  |    Length     |
45 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 *    |                       My Discriminator                        |
47 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 *    |                      Your Discriminator                       |
49 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 *    |                    Desired Min TX Interval                    |
51 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 *    |                   Required Min RX Interval                    |
53 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 *    |                 Required Min Echo RX Interval                 |
55 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 */
57
58/*
59 *  Control packet, BFDv1, draft-ietf-bfd-base-02.txt
60 *
61 *     0                   1                   2                   3
62 *     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
63 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 *    |Vers |  Diag   |Sta|P|F|C|A|D|R|  Detect Mult  |    Length     |
65 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 *    |                       My Discriminator                        |
67 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 *    |                      Your Discriminator                       |
69 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 *    |                    Desired Min TX Interval                    |
71 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 *    |                   Required Min RX Interval                    |
73 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 *    |                 Required Min Echo RX Interval                 |
75 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 */
77
78struct bfd_header_t {
79    u_int8_t version_diag;
80    u_int8_t flags;
81    u_int8_t detect_time_multiplier;
82    u_int8_t length;
83    u_int8_t my_discriminator[4];
84    u_int8_t your_discriminator[4];
85    u_int8_t desired_min_tx_interval[4];
86    u_int8_t required_min_rx_interval[4];
87    u_int8_t required_min_echo_interval[4];
88};
89
90/*
91 *    An optional Authentication Header may be present
92 *
93 *     0                   1                   2                   3
94 *     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
95 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96 *    |   Auth Type   |   Auth Len    |    Authentication Data...     |
97 *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98 */
99
100struct bfd_auth_header_t {
101    u_int8_t auth_type;
102    u_int8_t auth_len;
103    u_int8_t auth_data;
104};
105
106static const struct tok bfd_v1_authentication_values[] = {
107    { 0,        "Reserved" },
108    { 1,        "Simple Password" },
109    { 2,        "Keyed MD5" },
110    { 3,        "Meticulous Keyed MD5" },
111    { 4,        "Keyed SHA1" },
112    { 5,        "Meticulous Keyed SHA1" },
113    { 0, NULL }
114};
115
116#define BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
117#define BFD_EXTRACT_DIAG(x)     ((x)&0x1f)
118
119static const struct tok bfd_port_values[] = {
120    { BFD_CONTROL_PORT, "Control" },
121    { BFD_ECHO_PORT,    "Echo" },
122    { 0, NULL }
123};
124
125
126static const struct tok bfd_diag_values[] = {
127    { 0, "No Diagnostic" },
128    { 1, "Control Detection Time Expired" },
129    { 2, "Echo Function Failed" },
130    { 3, "Neighbor Signaled Session Down" },
131    { 4, "Forwarding Plane Reset" },
132    { 5, "Path Down" },
133    { 6, "Concatenated Path Down" },
134    { 7, "Administratively Down" },
135    { 8, "Reverse Concatenated Path Down" },
136    { 0, NULL }
137};
138
139static const struct tok bfd_v0_flag_values[] = {
140    { 0x80,     "I Hear You" },
141    { 0x40,     "Demand" },
142    { 0x20,     "Poll" },
143    { 0x10,     "Final" },
144    { 0x08,     "Reserved" },
145    { 0x04,     "Reserved" },
146    { 0x02,     "Reserved" },
147    { 0x01,     "Reserved" },
148    { 0, NULL }
149};
150
151#define BFD_FLAG_AUTH 0x04
152
153static const struct tok bfd_v1_flag_values[] = {
154    { 0x20, "Poll" },
155    { 0x10, "Final" },
156    { 0x08, "Control Plane Independent" },
157    { BFD_FLAG_AUTH, "Authentication Present" },
158    { 0x02, "Demand" },
159    { 0x01, "Reserved" },
160    { 0, NULL }
161};
162
163static const struct tok bfd_v1_state_values[] = {
164    { 0, "AdminDown" },
165    { 1, "Down" },
166    { 2, "Init" },
167    { 3, "Up" },
168    { 0, NULL }
169};
170
171void
172bfd_print(register const u_char *pptr, register u_int len, register u_int port)
173{
174        const struct bfd_header_t *bfd_header;
175        const struct bfd_auth_header_t *bfd_auth_header;
176        u_int8_t version = 0;
177
178        bfd_header = (const struct bfd_header_t *)pptr;
179        if (port == BFD_CONTROL_PORT) {
180            TCHECK(*bfd_header);
181            version = BFD_EXTRACT_VERSION(bfd_header->version_diag);
182        } else if (port == BFD_ECHO_PORT) {
183            /* Echo is BFD v1 only */
184            version = 1;
185        }
186        switch ((port << 8) | version) {
187
188            /* BFDv0 */
189        case (BFD_CONTROL_PORT << 8):
190            if (vflag < 1 )
191            {
192                printf("BFDv%u, %s, Flags: [%s], length: %u",
193                       version,
194                       tok2str(bfd_port_values, "unknown (%u)", port),
195                       bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
196                       len);
197                return;
198            }
199           
200            printf("BFDv%u, length: %u\n\t%s, Flags: [%s], Diagnostic: %s (0x%02x)",
201                   version,
202                   len,
203                   tok2str(bfd_port_values, "unknown (%u)", port),
204                   bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
205                   tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
206                   BFD_EXTRACT_DIAG(bfd_header->version_diag));
207           
208            printf("\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
209                   bfd_header->detect_time_multiplier,
210                   bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
211                   bfd_header->length);
212
213
214            printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator));
215            printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator));
216            printf("\n\t  Desired min Tx Interval:    %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000);
217            printf("\n\t  Required min Rx Interval:   %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000);
218            printf("\n\t  Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000);
219            break;
220
221            /* BFDv1 */
222        case (BFD_CONTROL_PORT << 8 | 1):
223            if (vflag < 1 )
224            {
225                printf("BFDv%u, %s, State %s, Flags: [%s], length: %u",
226                       version,
227                       tok2str(bfd_port_values, "unknown (%u)", port),
228                       tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
229                       bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
230                       len);
231                return;
232            }
233           
234            printf("BFDv%u, length: %u\n\t%s, State %s, Flags: [%s], Diagnostic: %s (0x%02x)",
235                   version,
236                   len,
237                   tok2str(bfd_port_values, "unknown (%u)", port),
238                   tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
239                   bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
240                   tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
241                   BFD_EXTRACT_DIAG(bfd_header->version_diag));
242           
243            printf("\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
244                   bfd_header->detect_time_multiplier,
245                   bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
246                   bfd_header->length);
247
248
249            printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator));
250            printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator));
251            printf("\n\t  Desired min Tx Interval:    %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000);
252            printf("\n\t  Required min Rx Interval:   %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000);
253            printf("\n\t  Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000);
254
255            if (bfd_header->flags & BFD_FLAG_AUTH) {
256                pptr += sizeof (const struct bfd_header_t);
257                bfd_auth_header = (const struct bfd_auth_header_t *)pptr;
258                TCHECK2(*bfd_auth_header, sizeof(const struct bfd_auth_header_t));
259                printf("\n\t%s (%u) Authentication, length %u present",
260                       tok2str(bfd_v1_authentication_values,"Unknown",bfd_auth_header->auth_type),
261                       bfd_auth_header->auth_type,
262                       bfd_auth_header->auth_len);
263            }
264            break;
265
266            /* BFDv0 */
267        case (BFD_ECHO_PORT << 8): /* not yet supported - fall through */
268            /* BFDv1 */
269        case (BFD_ECHO_PORT << 8 | 1):
270
271        default:
272            printf("BFD, %s, length: %u",
273                   tok2str(bfd_port_values, "unknown (%u)", port),
274                   len);
275            if (vflag >= 1) {
276                if(!print_unknown_data(pptr,"\n\t",len))
277                    return;
278            }
279            break;
280        }
281        return;
282
283trunc:
284        printf("[|BFD]");
285}
Note: See TracBrowser for help on using the repository browser.