source: rtems-libbsd/freebsd/contrib/tcpdump/print-egp.c @ 8440506

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 8440506 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.0 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
5 *      The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by the University of California, Lawrence Berkeley Laboratory,
13 * Berkeley, CA.  The name of the University may not be used to
14 * endorse or promote products derived from this software without
15 * specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
21 */
22
23#ifndef lint
24static const char rcsid[] _U_ =
25    "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.38 2006-02-11 22:13:24 hannes Exp $ (LBL)";
26#endif
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <tcpdump-stdinc.h>
33
34#include <stdio.h>
35
36#include "interface.h"
37#include "addrtoname.h"
38#include "extract.h"
39
40#include "ip.h"
41
42struct egp_packet {
43        u_int8_t  egp_version;
44#define EGP_VERSION     2
45        u_int8_t  egp_type;
46#define  EGPT_ACQUIRE   3
47#define  EGPT_REACH     5
48#define  EGPT_POLL      2
49#define  EGPT_UPDATE    1
50#define  EGPT_ERROR     8
51        u_int8_t  egp_code;
52#define  EGPC_REQUEST   0
53#define  EGPC_CONFIRM   1
54#define  EGPC_REFUSE    2
55#define  EGPC_CEASE     3
56#define  EGPC_CEASEACK  4
57#define  EGPC_HELLO     0
58#define  EGPC_HEARDU    1
59        u_int8_t  egp_status;
60#define  EGPS_UNSPEC    0
61#define  EGPS_ACTIVE    1
62#define  EGPS_PASSIVE   2
63#define  EGPS_NORES     3
64#define  EGPS_ADMIN     4
65#define  EGPS_GODOWN    5
66#define  EGPS_PARAM     6
67#define  EGPS_PROTO     7
68#define  EGPS_INDET     0
69#define  EGPS_UP        1
70#define  EGPS_DOWN      2
71#define  EGPS_UNSOL     0x80
72        u_int16_t  egp_checksum;
73        u_int16_t  egp_as;
74        u_int16_t  egp_sequence;
75        union {
76                u_int16_t  egpu_hello;
77                u_int8_t egpu_gws[2];
78                u_int16_t  egpu_reason;
79#define  EGPR_UNSPEC    0
80#define  EGPR_BADHEAD   1
81#define  EGPR_BADDATA   2
82#define  EGPR_NOREACH   3
83#define  EGPR_XSPOLL    4
84#define  EGPR_NORESP    5
85#define  EGPR_UVERSION  6
86        } egp_handg;
87#define  egp_hello  egp_handg.egpu_hello
88#define  egp_intgw  egp_handg.egpu_gws[0]
89#define  egp_extgw  egp_handg.egpu_gws[1]
90#define  egp_reason  egp_handg.egpu_reason
91        union {
92                u_int16_t  egpu_poll;
93                u_int32_t egpu_sourcenet;
94        } egp_pands;
95#define  egp_poll  egp_pands.egpu_poll
96#define  egp_sourcenet  egp_pands.egpu_sourcenet
97};
98
99const char *egp_acquire_codes[] = {
100        "request",
101        "confirm",
102        "refuse",
103        "cease",
104        "cease_ack"
105};
106
107const char *egp_acquire_status[] = {
108        "unspecified",
109        "active_mode",
110        "passive_mode",
111        "insufficient_resources",
112        "administratively_prohibited",
113        "going_down",
114        "parameter_violation",
115        "protocol_violation"
116};
117
118const char *egp_reach_codes[] = {
119        "hello",
120        "i-h-u"
121};
122
123const char *egp_status_updown[] = {
124        "indeterminate",
125        "up",
126        "down"
127};
128
129const char *egp_reasons[] = {
130        "unspecified",
131        "bad_EGP_header_format",
132        "bad_EGP_data_field_format",
133        "reachability_info_unavailable",
134        "excessive_polling_rate",
135        "no_response",
136        "unsupported_version"
137};
138
139static void
140egpnrprint(register const struct egp_packet *egp)
141{
142        register const u_int8_t *cp;
143        u_int32_t addr;
144        register u_int32_t net;
145        register u_int netlen;
146        int gateways, distances, networks;
147        int t_gateways;
148        const char *comma;
149
150        addr = egp->egp_sourcenet;
151        if (IN_CLASSA(addr)) {
152                net = addr & IN_CLASSA_NET;
153                netlen = 1;
154        } else if (IN_CLASSB(addr)) {
155                net = addr & IN_CLASSB_NET;
156                netlen = 2;
157        } else if (IN_CLASSC(addr)) {
158                net = addr & IN_CLASSC_NET;
159                netlen = 3;
160        } else {
161                net = 0;
162                netlen = 0;
163        }
164        cp = (u_int8_t *)(egp + 1);
165
166        t_gateways = egp->egp_intgw + egp->egp_extgw;
167        for (gateways = 0; gateways < t_gateways; ++gateways) {
168                /* Pickup host part of gateway address */
169                addr = 0;
170                TCHECK2(cp[0], 4 - netlen);
171                switch (netlen) {
172
173                case 1:
174                        addr = *cp++;
175                        /* fall through */
176                case 2:
177                        addr = (addr << 8) | *cp++;
178                        /* fall through */
179                case 3:
180                        addr = (addr << 8) | *cp++;
181                }
182                addr |= net;
183                TCHECK2(cp[0], 1);
184                distances = *cp++;
185                printf(" %s %s ",
186                       gateways < (int)egp->egp_intgw ? "int" : "ext",
187                       ipaddr_string(&addr));
188
189                comma = "";
190                putchar('(');
191                while (--distances >= 0) {
192                        TCHECK2(cp[0], 2);
193                        printf("%sd%d:", comma, (int)*cp++);
194                        comma = ", ";
195                        networks = *cp++;
196                        while (--networks >= 0) {
197                                /* Pickup network number */
198                                TCHECK2(cp[0], 1);
199                                addr = (u_int32_t)*cp++ << 24;
200                                if (IN_CLASSB(addr)) {
201                                        TCHECK2(cp[0], 1);
202                                        addr |= (u_int32_t)*cp++ << 16;
203                                } else if (!IN_CLASSA(addr)) {
204                                        TCHECK2(cp[0], 2);
205                                        addr |= (u_int32_t)*cp++ << 16;
206                                        addr |= (u_int32_t)*cp++ << 8;
207                                }
208                                printf(" %s", ipaddr_string(&addr));
209                        }
210                }
211                putchar(')');
212        }
213        return;
214trunc:
215        fputs("[|]", stdout);
216}
217
218void
219egp_print(register const u_int8_t *bp, register u_int length)
220{
221        register const struct egp_packet *egp;
222        register int status;
223        register int code;
224        register int type;
225
226        egp = (struct egp_packet *)bp;
227        if (!TTEST2(*egp, length)) {
228                printf("[|egp]");
229                return;
230        }
231
232        if (!vflag) {
233            printf("EGPv%u, AS %u, seq %u, length %u",
234                   egp->egp_version,
235                   EXTRACT_16BITS(&egp->egp_as),
236                   EXTRACT_16BITS(&egp->egp_sequence),
237                   length);
238            return;
239        } else
240            printf("EGPv%u, length %u",
241                   egp->egp_version,
242                   length);           
243
244        if (egp->egp_version != EGP_VERSION) {
245                printf("[version %d]", egp->egp_version);
246                return;
247        }
248
249        type = egp->egp_type;
250        code = egp->egp_code;
251        status = egp->egp_status;
252
253        switch (type) {
254        case EGPT_ACQUIRE:
255                printf(" acquire");
256                switch (code) {
257                case EGPC_REQUEST:
258                case EGPC_CONFIRM:
259                        printf(" %s", egp_acquire_codes[code]);
260                        switch (status) {
261                        case EGPS_UNSPEC:
262                        case EGPS_ACTIVE:
263                        case EGPS_PASSIVE:
264                                printf(" %s", egp_acquire_status[status]);
265                                break;
266
267                        default:
268                                printf(" [status %d]", status);
269                                break;
270                        }
271                        printf(" hello:%d poll:%d",
272                               EXTRACT_16BITS(&egp->egp_hello),
273                               EXTRACT_16BITS(&egp->egp_poll));
274                        break;
275
276                case EGPC_REFUSE:
277                case EGPC_CEASE:
278                case EGPC_CEASEACK:
279                        printf(" %s", egp_acquire_codes[code]);
280                        switch (status ) {
281                        case EGPS_UNSPEC:
282                        case EGPS_NORES:
283                        case EGPS_ADMIN:
284                        case EGPS_GODOWN:
285                        case EGPS_PARAM:
286                        case EGPS_PROTO:
287                                printf(" %s", egp_acquire_status[status]);
288                                break;
289
290                        default:
291                                printf("[status %d]", status);
292                                break;
293                        }
294                        break;
295
296                default:
297                        printf("[code %d]", code);
298                        break;
299                }
300                break;
301
302        case EGPT_REACH:
303                switch (code) {
304
305                case EGPC_HELLO:
306                case EGPC_HEARDU:
307                        printf(" %s", egp_reach_codes[code]);
308                        if (status <= EGPS_DOWN)
309                                printf(" state:%s", egp_status_updown[status]);
310                        else
311                                printf(" [status %d]", status);
312                        break;
313
314                default:
315                        printf("[reach code %d]", code);
316                        break;
317                }
318                break;
319
320        case EGPT_POLL:
321                printf(" poll");
322                if (egp->egp_status <= EGPS_DOWN)
323                        printf(" state:%s", egp_status_updown[status]);
324                else
325                        printf(" [status %d]", status);
326                printf(" net:%s", ipaddr_string(&egp->egp_sourcenet));
327                break;
328
329        case EGPT_UPDATE:
330                printf(" update");
331                if (status & EGPS_UNSOL) {
332                        status &= ~EGPS_UNSOL;
333                        printf(" unsolicited");
334                }
335                if (status <= EGPS_DOWN)
336                        printf(" state:%s", egp_status_updown[status]);
337                else
338                        printf(" [status %d]", status);
339                printf(" %s int %d ext %d",
340                       ipaddr_string(&egp->egp_sourcenet),
341                       egp->egp_intgw,
342                       egp->egp_extgw);
343                if (vflag)
344                        egpnrprint(egp);
345                break;
346
347        case EGPT_ERROR:
348                printf(" error");
349                if (status <= EGPS_DOWN)
350                        printf(" state:%s", egp_status_updown[status]);
351                else
352                        printf(" [status %d]", status);
353
354                if (EXTRACT_16BITS(&egp->egp_reason) <= EGPR_UVERSION)
355                        printf(" %s", egp_reasons[EXTRACT_16BITS(&egp->egp_reason)]);
356                else
357                        printf(" [reason %d]", EXTRACT_16BITS(&egp->egp_reason));
358                break;
359
360        default:
361                printf("[type %d]", type);
362                break;
363        }
364}
Note: See TracBrowser for help on using the repository browser.