source: rtems-libbsd/freebsd/contrib/tcpdump/print-dvmrp.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: 8.1 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 1995, 1996
5 *      The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24#ifndef lint
25static const char rcsid[] _U_ =
26    "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.27 2003-11-19 09:42:04 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <tcpdump-stdinc.h>
34
35#include <stdio.h>
36#include <string.h>
37#include <stdlib.h>
38
39#include "interface.h"
40#include "extract.h"
41#include "addrtoname.h"
42
43/*
44 * DVMRP message types and flag values shamelessly stolen from
45 * mrouted/dvmrp.h.
46 */
47#define DVMRP_PROBE             1       /* for finding neighbors */
48#define DVMRP_REPORT            2       /* for reporting some or all routes */
49#define DVMRP_ASK_NEIGHBORS     3       /* sent by mapper, asking for a list */
50                                        /* of this router's neighbors */
51#define DVMRP_NEIGHBORS         4       /* response to such a request */
52#define DVMRP_ASK_NEIGHBORS2    5       /* as above, want new format reply */
53#define DVMRP_NEIGHBORS2        6
54#define DVMRP_PRUNE             7       /* prune message */
55#define DVMRP_GRAFT             8       /* graft message */
56#define DVMRP_GRAFT_ACK         9       /* graft acknowledgement */
57
58/*
59 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
60 */
61#define DVMRP_NF_TUNNEL         0x01    /* neighbors reached via tunnel */
62#define DVMRP_NF_SRCRT          0x02    /* tunnel uses IP source routing */
63#define DVMRP_NF_DOWN           0x10    /* kernel state of interface */
64#define DVMRP_NF_DISABLED       0x20    /* administratively disabled */
65#define DVMRP_NF_QUERIER        0x40    /* I am the subnet's querier */
66
67static int print_probe(const u_char *, const u_char *, u_int);
68static int print_report(const u_char *, const u_char *, u_int);
69static int print_neighbors(const u_char *, const u_char *, u_int);
70static int print_neighbors2(const u_char *, const u_char *, u_int);
71static int print_prune(const u_char *);
72static int print_graft(const u_char *);
73static int print_graft_ack(const u_char *);
74
75static u_int32_t target_level;
76
77void
78dvmrp_print(register const u_char *bp, register u_int len)
79{
80        register const u_char *ep;
81        register u_char type;
82
83        ep = (const u_char *)snapend;
84        if (bp >= ep)
85                return;
86
87        TCHECK(bp[1]);
88        type = bp[1];
89
90        /* Skip IGMP header */
91        bp += 8;
92        len -= 8;
93
94        switch (type) {
95
96        case DVMRP_PROBE:
97                printf(" Probe");
98                if (vflag) {
99                        if (print_probe(bp, ep, len) < 0)
100                                goto trunc;
101                }
102                break;
103
104        case DVMRP_REPORT:
105                printf(" Report");
106                if (vflag > 1) {
107                        if (print_report(bp, ep, len) < 0)
108                                goto trunc;
109                }
110                break;
111
112        case DVMRP_ASK_NEIGHBORS:
113                printf(" Ask-neighbors(old)");
114                break;
115
116        case DVMRP_NEIGHBORS:
117                printf(" Neighbors(old)");
118                if (print_neighbors(bp, ep, len) < 0)
119                        goto trunc;
120                break;
121
122        case DVMRP_ASK_NEIGHBORS2:
123                printf(" Ask-neighbors2");
124                break;
125
126        case DVMRP_NEIGHBORS2:
127                printf(" Neighbors2");
128                /*
129                 * extract version and capabilities from IGMP group
130                 * address field
131                 */
132                bp -= 4;
133                TCHECK2(bp[0], 4);
134                target_level = (bp[0] << 24) | (bp[1] << 16) |
135                    (bp[2] << 8) | bp[3];
136                bp += 4;
137                if (print_neighbors2(bp, ep, len) < 0)
138                        goto trunc;
139                break;
140
141        case DVMRP_PRUNE:
142                printf(" Prune");
143                if (print_prune(bp) < 0)
144                        goto trunc;
145                break;
146
147        case DVMRP_GRAFT:
148                printf(" Graft");
149                if (print_graft(bp) < 0)
150                        goto trunc;
151                break;
152
153        case DVMRP_GRAFT_ACK:
154                printf(" Graft-ACK");
155                if (print_graft_ack(bp) < 0)
156                        goto trunc;
157                break;
158
159        default:
160                printf(" [type %d]", type);
161                break;
162        }
163        return;
164
165trunc:
166        printf("[|dvmrp]");
167        return;
168}
169
170static int
171print_report(register const u_char *bp, register const u_char *ep,
172    register u_int len)
173{
174        register u_int32_t mask, origin;
175        register int metric, done;
176        register u_int i, width;
177
178        while (len > 0) {
179                if (len < 3) {
180                        printf(" [|]");
181                        return (0);
182                }
183                TCHECK2(bp[0], 3);
184                mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2];
185                width = 1;
186                if (bp[0])
187                        width = 2;
188                if (bp[1])
189                        width = 3;
190                if (bp[2])
191                        width = 4;
192
193                printf("\n\tMask %s", intoa(htonl(mask)));
194                bp += 3;
195                len -= 3;
196                do {
197                        if (bp + width + 1 > ep) {
198                                printf(" [|]");
199                                return (0);
200                        }
201                        if (len < width + 1) {
202                                printf("\n\t  [Truncated Report]");
203                                return (0);
204                        }
205                        origin = 0;
206                        for (i = 0; i < width; ++i) {
207                                TCHECK(*bp);
208                                origin = origin << 8 | *bp++;
209                        }
210                        for ( ; i < 4; ++i)
211                                origin <<= 8;
212
213                        TCHECK(*bp);
214                        metric = *bp++;
215                        done = metric & 0x80;
216                        metric &= 0x7f;
217                        printf("\n\t  %s metric %d", intoa(htonl(origin)),
218                                metric);
219                        len -= width + 1;
220                } while (!done);
221        }
222        return (0);
223trunc:
224        return (-1);
225}
226
227static int
228print_probe(register const u_char *bp, register const u_char *ep,
229    register u_int len)
230{
231        register u_int32_t genid;
232
233        TCHECK2(bp[0], 4);
234        if ((len < 4) || ((bp + 4) > ep)) {
235                /* { (ctags) */
236                printf(" [|}");
237                return (0);
238        }
239        genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3];
240        bp += 4;
241        len -= 4;
242        if (vflag > 1)
243                printf("\n\t");
244        else
245                printf(" ");
246        printf("genid %u", genid);
247        if (vflag < 2)
248                return (0);
249
250        while ((len > 0) && (bp < ep)) {
251                TCHECK2(bp[0], 4);
252                printf("\n\tneighbor %s", ipaddr_string(bp));
253                bp += 4; len -= 4;
254        }
255        return (0);
256trunc:
257        return (-1);
258}
259
260static int
261print_neighbors(register const u_char *bp, register const u_char *ep,
262    register u_int len)
263{
264        const u_char *laddr;
265        register u_char metric;
266        register u_char thresh;
267        register int ncount;
268
269        while (len > 0 && bp < ep) {
270                TCHECK2(bp[0], 7);
271                laddr = bp;
272                bp += 4;
273                metric = *bp++;
274                thresh = *bp++;
275                ncount = *bp++;
276                len -= 7;
277                while (--ncount >= 0) {
278                        TCHECK2(bp[0], 4);
279                        printf(" [%s ->", ipaddr_string(laddr));
280                        printf(" %s, (%d/%d)]",
281                                   ipaddr_string(bp), metric, thresh);
282                        bp += 4;
283                        len -= 4;
284                }
285        }
286        return (0);
287trunc:
288        return (-1);
289}
290
291static int
292print_neighbors2(register const u_char *bp, register const u_char *ep,
293    register u_int len)
294{
295        const u_char *laddr;
296        register u_char metric, thresh, flags;
297        register int ncount;
298
299        printf(" (v %d.%d):",
300               (int)target_level & 0xff,
301               (int)(target_level >> 8) & 0xff);
302
303        while (len > 0 && bp < ep) {
304                TCHECK2(bp[0], 8);
305                laddr = bp;
306                bp += 4;
307                metric = *bp++;
308                thresh = *bp++;
309                flags = *bp++;
310                ncount = *bp++;
311                len -= 8;
312                while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) {
313                        printf(" [%s -> ", ipaddr_string(laddr));
314                        printf("%s (%d/%d", ipaddr_string(bp),
315                                     metric, thresh);
316                        if (flags & DVMRP_NF_TUNNEL)
317                                printf("/tunnel");
318                        if (flags & DVMRP_NF_SRCRT)
319                                printf("/srcrt");
320                        if (flags & DVMRP_NF_QUERIER)
321                                printf("/querier");
322                        if (flags & DVMRP_NF_DISABLED)
323                                printf("/disabled");
324                        if (flags & DVMRP_NF_DOWN)
325                                printf("/down");
326                        printf(")]");
327                        bp += 4;
328                        len -= 4;
329                }
330                if (ncount != -1) {
331                        printf(" [|]");
332                        return (0);
333                }
334        }
335        return (0);
336trunc:
337        return (-1);
338}
339
340static int
341print_prune(register const u_char *bp)
342{
343        TCHECK2(bp[0], 12);
344        printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
345        bp += 8;
346        (void)printf(" timer ");
347        relts_print(EXTRACT_32BITS(bp));
348        return (0);
349trunc:
350        return (-1);
351}
352
353static int
354print_graft(register const u_char *bp)
355{
356        TCHECK2(bp[0], 8);
357        printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
358        return (0);
359trunc:
360        return (-1);
361}
362
363static int
364print_graft_ack(register const u_char *bp)
365{
366        TCHECK2(bp[0], 8);
367        printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
368        return (0);
369trunc:
370        return (-1);
371}
Note: See TracBrowser for help on using the repository browser.