source: rtems-libbsd/freebsd/contrib/tcpdump/print-eigrp.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: 16.9 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 1998-2004  Hannes Gredler <hannes@tcpdump.org>
5 *      The TCPDUMP project
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code
9 * distributions retain the above copyright notice and this paragraph
10 * in its entirety, and (2) distributions including binary code include
11 * the above copyright notice and this paragraph in its entirety in
12 * the documentation or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16 * FOR A PARTICULAR PURPOSE.
17 */
18
19#ifndef lint
20static const char rcsid[] _U_ =
21    "@(#) $Header: /tcpdump/master/tcpdump/print-eigrp.c,v 1.7 2005-05-06 02:53:26 guy Exp $";
22#endif
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include <tcpdump-stdinc.h>
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33
34#include "interface.h"
35#include "extract.h"
36#include "addrtoname.h"
37
38/*
39 * packet format documented at
40 * http://www.rhyshaden.com/eigrp.htm
41 */
42
43struct eigrp_common_header {
44    u_int8_t version;
45    u_int8_t opcode;
46    u_int8_t checksum[2];
47    u_int8_t flags[4];
48    u_int8_t seq[4];
49    u_int8_t ack[4];
50    u_int8_t asn[4];
51};
52
53#define EIGRP_VERSION                        2
54
55#define EIGRP_OPCODE_UPDATE                  1
56#define EIGRP_OPCODE_QUERY                   3
57#define EIGRP_OPCODE_REPLY                   4
58#define EIGRP_OPCODE_HELLO                   5
59#define EIGRP_OPCODE_IPXSAP                  6
60#define EIGRP_OPCODE_PROBE                   7
61
62static const struct tok eigrp_opcode_values[] = {
63    { EIGRP_OPCODE_UPDATE, "Update" },
64    { EIGRP_OPCODE_QUERY, "Query" },
65    { EIGRP_OPCODE_REPLY, "Reply" },
66    { EIGRP_OPCODE_HELLO, "Hello" },
67    { EIGRP_OPCODE_IPXSAP, "IPX SAP" },
68    { EIGRP_OPCODE_PROBE, "Probe" },
69    { 0, NULL}
70};
71
72static const struct tok eigrp_common_header_flag_values[] = {
73    { 0x01, "Init" },
74    { 0x02, "Conditionally Received" },
75    { 0, NULL}
76};
77
78struct eigrp_tlv_header {
79    u_int8_t type[2];
80    u_int8_t length[2];
81};
82
83#define EIGRP_TLV_GENERAL_PARM   0x0001
84#define EIGRP_TLV_AUTH           0x0002
85#define EIGRP_TLV_SEQ            0x0003
86#define EIGRP_TLV_SW_VERSION     0x0004
87#define EIGRP_TLV_MCAST_SEQ      0x0005
88#define EIGRP_TLV_IP_INT         0x0102
89#define EIGRP_TLV_IP_EXT         0x0103
90#define EIGRP_TLV_AT_INT         0x0202
91#define EIGRP_TLV_AT_EXT         0x0203
92#define EIGRP_TLV_AT_CABLE_SETUP 0x0204
93#define EIGRP_TLV_IPX_INT        0x0302
94#define EIGRP_TLV_IPX_EXT        0x0303
95
96static const struct tok eigrp_tlv_values[] = {
97    { EIGRP_TLV_GENERAL_PARM, "General Parameters"},
98    { EIGRP_TLV_AUTH, "Authentication"},
99    { EIGRP_TLV_SEQ, "Sequence"},
100    { EIGRP_TLV_SW_VERSION, "Software Version"},
101    { EIGRP_TLV_MCAST_SEQ, "Next Multicast Sequence"},
102    { EIGRP_TLV_IP_INT, "IP Internal routes"},
103    { EIGRP_TLV_IP_EXT, "IP External routes"},
104    { EIGRP_TLV_AT_INT, "AppleTalk Internal routes"},
105    { EIGRP_TLV_AT_EXT, "AppleTalk External routes"},
106    { EIGRP_TLV_AT_CABLE_SETUP, "AppleTalk Cable setup"},
107    { EIGRP_TLV_IPX_INT, "IPX Internal routes"},
108    { EIGRP_TLV_IPX_EXT, "IPX External routes"},
109    { 0, NULL}
110};
111
112struct eigrp_tlv_general_parm_t {
113    u_int8_t k1;
114    u_int8_t k2;
115    u_int8_t k3;
116    u_int8_t k4;
117    u_int8_t k5;
118    u_int8_t res;
119    u_int8_t holdtime[2];
120};         
121
122struct eigrp_tlv_sw_version_t {
123    u_int8_t ios_major;
124    u_int8_t ios_minor;
125    u_int8_t eigrp_major;
126    u_int8_t eigrp_minor;
127};
128
129struct eigrp_tlv_ip_int_t {
130    u_int8_t nexthop[4];
131    u_int8_t delay[4];
132    u_int8_t bandwidth[4];
133    u_int8_t mtu[3];
134    u_int8_t hopcount;
135    u_int8_t reliability;
136    u_int8_t load;
137    u_int8_t reserved[2];
138    u_int8_t plen;
139    u_int8_t destination; /* variable length [1-4] bytes encoding */
140};
141
142struct eigrp_tlv_ip_ext_t {
143    u_int8_t nexthop[4];
144    u_int8_t origin_router[4];
145    u_int8_t origin_as[4];
146    u_int8_t tag[4];
147    u_int8_t metric[4];
148    u_int8_t reserved[2];
149    u_int8_t proto_id;
150    u_int8_t flags;
151    u_int8_t delay[4];
152    u_int8_t bandwidth[4];
153    u_int8_t mtu[3];
154    u_int8_t hopcount;
155    u_int8_t reliability;
156    u_int8_t load;
157    u_int8_t reserved2[2];
158    u_int8_t plen;
159    u_int8_t destination; /* variable length [1-4] bytes encoding */
160};
161
162struct eigrp_tlv_at_cable_setup_t {
163    u_int8_t cable_start[2];
164    u_int8_t cable_end[2];
165    u_int8_t router_id[4];
166};
167
168struct eigrp_tlv_at_int_t {
169    u_int8_t nexthop[4];
170    u_int8_t delay[4];
171    u_int8_t bandwidth[4];
172    u_int8_t mtu[3];
173    u_int8_t hopcount;
174    u_int8_t reliability;
175    u_int8_t load;
176    u_int8_t reserved[2];
177    u_int8_t cable_start[2];
178    u_int8_t cable_end[2];
179};
180
181struct eigrp_tlv_at_ext_t {
182    u_int8_t nexthop[4];
183    u_int8_t origin_router[4];
184    u_int8_t origin_as[4];
185    u_int8_t tag[4];
186    u_int8_t proto_id;
187    u_int8_t flags;
188    u_int8_t metric[2];
189    u_int8_t delay[4];
190    u_int8_t bandwidth[4];
191    u_int8_t mtu[3];
192    u_int8_t hopcount;
193    u_int8_t reliability;
194    u_int8_t load;
195    u_int8_t reserved2[2];
196    u_int8_t cable_start[2];
197    u_int8_t cable_end[2];
198};
199
200static const struct tok eigrp_ext_proto_id_values[] = {
201    { 0x01, "IGRP" },
202    { 0x02, "EIGRP" },
203    { 0x03, "Static" },
204    { 0x04, "RIP" },
205    { 0x05, "Hello" },
206    { 0x06, "OSPF" },
207    { 0x07, "IS-IS" },
208    { 0x08, "EGP" },
209    { 0x09, "BGP" },
210    { 0x0a, "IDRP" },
211    { 0x0b, "Connected" },
212    { 0, NULL}
213};
214
215void
216eigrp_print(register const u_char *pptr, register u_int len) {
217
218    const struct eigrp_common_header *eigrp_com_header;
219    const struct eigrp_tlv_header *eigrp_tlv_header;
220    const u_char *tptr,*tlv_tptr;
221    u_int tlen,eigrp_tlv_len,eigrp_tlv_type,tlv_tlen, byte_length, bit_length;
222    u_int8_t prefix[4];
223
224    union {
225        const struct eigrp_tlv_general_parm_t *eigrp_tlv_general_parm;
226        const struct eigrp_tlv_sw_version_t *eigrp_tlv_sw_version;
227        const struct eigrp_tlv_ip_int_t *eigrp_tlv_ip_int;
228        const struct eigrp_tlv_ip_ext_t *eigrp_tlv_ip_ext;
229        const struct eigrp_tlv_at_cable_setup_t *eigrp_tlv_at_cable_setup;
230        const struct eigrp_tlv_at_int_t *eigrp_tlv_at_int;
231        const struct eigrp_tlv_at_ext_t *eigrp_tlv_at_ext;
232    } tlv_ptr;
233
234    tptr=pptr;
235    eigrp_com_header = (const struct eigrp_common_header *)pptr;
236    TCHECK(*eigrp_com_header);
237
238    /*
239     * Sanity checking of the header.
240     */
241    if (eigrp_com_header->version != EIGRP_VERSION) {
242        printf("EIGRP version %u packet not supported",eigrp_com_header->version);
243        return;
244    }
245
246    /* in non-verbose mode just lets print the basic Message Type*/
247    if (vflag < 1) {
248        printf("EIGRP %s, length: %u",
249               tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode),
250               len);
251        return;
252    }
253
254    /* ok they seem to want to know everything - lets fully decode it */
255
256    tlen=len-sizeof(struct eigrp_common_header);
257
258    /* FIXME print other header info */
259    printf("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
260           eigrp_com_header->version,
261           tok2str(eigrp_opcode_values, "unknown, type: %u",eigrp_com_header->opcode),
262           eigrp_com_header->opcode,
263           EXTRACT_16BITS(&eigrp_com_header->checksum),
264           tok2str(eigrp_common_header_flag_values,
265                   "none",
266                   EXTRACT_32BITS(&eigrp_com_header->flags)),
267           EXTRACT_32BITS(&eigrp_com_header->seq),
268           EXTRACT_32BITS(&eigrp_com_header->ack),
269           EXTRACT_32BITS(&eigrp_com_header->asn),
270           tlen);
271
272    tptr+=sizeof(const struct eigrp_common_header);
273
274    while(tlen>0) {
275        /* did we capture enough for fully decoding the object header ? */
276        TCHECK2(*tptr, sizeof(struct eigrp_tlv_header));
277
278        eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr;
279        eigrp_tlv_len=EXTRACT_16BITS(&eigrp_tlv_header->length);
280        eigrp_tlv_type=EXTRACT_16BITS(&eigrp_tlv_header->type);
281
282
283        if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header) ||
284            eigrp_tlv_len > tlen) {
285            print_unknown_data(tptr+sizeof(struct eigrp_tlv_header),"\n\t    ",tlen);
286            return;
287        }
288
289        printf("\n\t  %s TLV (0x%04x), length: %u",
290               tok2str(eigrp_tlv_values,
291                       "Unknown",
292                       eigrp_tlv_type),
293               eigrp_tlv_type,
294               eigrp_tlv_len);
295
296        tlv_tptr=tptr+sizeof(struct eigrp_tlv_header);
297        tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header);
298
299        /* did we capture enough for fully decoding the object ? */
300        TCHECK2(*tptr, eigrp_tlv_len);
301
302        switch(eigrp_tlv_type) {
303
304        case EIGRP_TLV_GENERAL_PARM:
305            tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm_t *)tlv_tptr;
306
307            printf("\n\t    holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
308                   EXTRACT_16BITS(tlv_ptr.eigrp_tlv_general_parm->holdtime),
309                   tlv_ptr.eigrp_tlv_general_parm->k1,
310                   tlv_ptr.eigrp_tlv_general_parm->k2,
311                   tlv_ptr.eigrp_tlv_general_parm->k3,
312                   tlv_ptr.eigrp_tlv_general_parm->k4,
313                   tlv_ptr.eigrp_tlv_general_parm->k5);
314            break;
315
316        case EIGRP_TLV_SW_VERSION:
317            tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version_t *)tlv_tptr;
318
319            printf("\n\t    IOS version: %u.%u, EIGRP version %u.%u",
320                   tlv_ptr.eigrp_tlv_sw_version->ios_major,
321                   tlv_ptr.eigrp_tlv_sw_version->ios_minor,
322                   tlv_ptr.eigrp_tlv_sw_version->eigrp_major,
323                   tlv_ptr.eigrp_tlv_sw_version->eigrp_minor);
324            break;
325
326        case EIGRP_TLV_IP_INT:
327            tlv_ptr.eigrp_tlv_ip_int = (const struct eigrp_tlv_ip_int_t *)tlv_tptr;
328
329            bit_length = tlv_ptr.eigrp_tlv_ip_int->plen;
330            if (bit_length > 32) {
331                printf("\n\t    illegal prefix length %u",bit_length);
332                break;
333            }
334            byte_length = (bit_length + 7) / 8; /* variable length encoding */
335            memset(prefix, 0, 4);
336            memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_int->destination,byte_length);
337
338            printf("\n\t    IPv4 prefix: %15s/%u, nexthop: ",
339                   ipaddr_string(prefix),
340                   bit_length);
341            if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->nexthop) == 0)
342                printf("self");
343            else
344                printf("%s",ipaddr_string(&tlv_ptr.eigrp_tlv_ip_int->nexthop));
345
346            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
347                   (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->delay)/100),
348                   EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->bandwidth),
349                   EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_int->mtu),
350                   tlv_ptr.eigrp_tlv_ip_int->hopcount,
351                   tlv_ptr.eigrp_tlv_ip_int->reliability,
352                   tlv_ptr.eigrp_tlv_ip_int->load);
353            break;
354
355        case EIGRP_TLV_IP_EXT:
356            tlv_ptr.eigrp_tlv_ip_ext = (const struct eigrp_tlv_ip_ext_t *)tlv_tptr;
357
358            bit_length = tlv_ptr.eigrp_tlv_ip_ext->plen;
359            if (bit_length > 32) {
360                printf("\n\t    illegal prefix length %u",bit_length);
361                break;
362            }
363            byte_length = (bit_length + 7) / 8; /* variable length encoding */
364            memset(prefix, 0, 4);
365            memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_ext->destination,byte_length);
366
367            printf("\n\t    IPv4 prefix: %15s/%u, nexthop: ",
368                   ipaddr_string(prefix),
369                   bit_length);
370            if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->nexthop) == 0)
371                printf("self");
372            else
373                printf("%s",ipaddr_string(&tlv_ptr.eigrp_tlv_ip_ext->nexthop));
374
375            printf("\n\t      origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
376                   ipaddr_string(tlv_ptr.eigrp_tlv_ip_ext->origin_router),
377                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->origin_as),
378                   tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_ip_ext->proto_id),
379                   tlv_ptr.eigrp_tlv_ip_ext->flags,
380                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->tag),
381                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->metric));
382
383            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
384                   (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->delay)/100),
385                   EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->bandwidth),
386                   EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_ext->mtu),
387                   tlv_ptr.eigrp_tlv_ip_ext->hopcount,
388                   tlv_ptr.eigrp_tlv_ip_ext->reliability,
389                   tlv_ptr.eigrp_tlv_ip_ext->load);
390            break;
391
392        case EIGRP_TLV_AT_CABLE_SETUP:
393            tlv_ptr.eigrp_tlv_at_cable_setup = (const struct eigrp_tlv_at_cable_setup_t *)tlv_tptr;
394
395            printf("\n\t    Cable-range: %u-%u, Router-ID %u",
396                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_start),
397                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_end),
398                   EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->router_id));
399            break;
400
401        case EIGRP_TLV_AT_INT:
402            tlv_ptr.eigrp_tlv_at_int = (const struct eigrp_tlv_at_int_t *)tlv_tptr;
403
404            printf("\n\t     Cable-Range: %u-%u, nexthop: ",
405                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_start),
406                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_end));
407
408            if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop) == 0)
409                printf("self");
410            else
411                printf("%u.%u",
412                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop),
413                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop[2]));
414
415            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
416                   (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->delay)/100),
417                   EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->bandwidth),
418                   EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_int->mtu),
419                   tlv_ptr.eigrp_tlv_at_int->hopcount,
420                   tlv_ptr.eigrp_tlv_at_int->reliability,
421                   tlv_ptr.eigrp_tlv_at_int->load);
422            break;
423
424        case EIGRP_TLV_AT_EXT:
425            tlv_ptr.eigrp_tlv_at_ext = (const struct eigrp_tlv_at_ext_t *)tlv_tptr;
426
427            printf("\n\t     Cable-Range: %u-%u, nexthop: ",
428                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_start),
429                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_end));
430
431            if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop) == 0)
432                printf("self");
433            else
434                printf("%u.%u",
435                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop),
436                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop[2]));
437
438            printf("\n\t      origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
439                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_router),
440                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_as),
441                   tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_at_ext->proto_id),
442                   tlv_ptr.eigrp_tlv_at_ext->flags,
443                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->tag),
444                   EXTRACT_16BITS(tlv_ptr.eigrp_tlv_at_ext->metric));
445
446            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
447                   (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->delay)/100),
448                   EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->bandwidth),
449                   EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_ext->mtu),
450                   tlv_ptr.eigrp_tlv_at_ext->hopcount,
451                   tlv_ptr.eigrp_tlv_at_ext->reliability,
452                   tlv_ptr.eigrp_tlv_at_ext->load);
453            break;
454
455            /*
456             * FIXME those are the defined TLVs that lack a decoder
457             * you are welcome to contribute code ;-)
458             */
459
460        case EIGRP_TLV_AUTH:
461        case EIGRP_TLV_SEQ:
462        case EIGRP_TLV_MCAST_SEQ:
463        case EIGRP_TLV_IPX_INT:
464        case EIGRP_TLV_IPX_EXT:
465
466        default:
467            if (vflag <= 1)
468                print_unknown_data(tlv_tptr,"\n\t    ",tlv_tlen);
469            break;
470        }
471        /* do we want to see an additionally hexdump ? */
472        if (vflag > 1)
473            print_unknown_data(tptr+sizeof(struct eigrp_tlv_header),"\n\t    ",
474                               eigrp_tlv_len-sizeof(struct eigrp_tlv_header));
475
476        tptr+=eigrp_tlv_len;
477        tlen-=eigrp_tlv_len;
478    }
479    return;
480trunc:
481    printf("\n\t\t packet exceeded snapshot");
482}
Note: See TracBrowser for help on using the repository browser.