2 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Lawrence Berkeley Laboratory,
11 * Berkeley, CA. The name of the University may not be used to
12 * endorse or promote products derived from this software without
13 * specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
21 /* \summary: Exterior Gateway Protocol (EGP) printer */
23 /* specification: RFC 827 */
27 #include "netdissect-stdinc.h"
29 #define ND_LONGJMP_FROM_TCHECK
30 #include "netdissect.h"
31 #include "addrtoname.h"
35 nd_uint8_t egp_version
;
38 #define EGPT_ACQUIRE 3
44 #define EGPC_REQUEST 0
45 #define EGPC_CONFIRM 1
48 #define EGPC_CEASEACK 4
51 nd_uint8_t egp_status
;
54 #define EGPS_PASSIVE 2
63 #define EGPS_UNSOL 0x80
64 nd_uint16_t egp_checksum
;
66 nd_uint16_t egp_sequence
;
68 nd_uint16_t egpu_hello
;
69 nd_uint8_t egpu_gws
[2];
70 nd_uint16_t egpu_reason
;
72 #define EGPR_BADHEAD 1
73 #define EGPR_BADDATA 2
74 #define EGPR_NOREACH 3
77 #define EGPR_UVERSION 6
79 #define egp_hello egp_handg.egpu_hello
80 #define egp_intgw egp_handg.egpu_gws[0]
81 #define egp_extgw egp_handg.egpu_gws[1]
82 #define egp_reason egp_handg.egpu_reason
84 nd_uint16_t egpu_poll
;
85 nd_ipv4 egpu_sourcenet
;
87 #define egp_poll egp_pands.egpu_poll
88 #define egp_sourcenet egp_pands.egpu_sourcenet
91 static const struct tok egp_type_str
[] = {
92 { EGPT_ACQUIRE
, "acquire" },
93 { EGPT_REACH
, "reach" },
94 { EGPT_POLL
, "poll" },
95 { EGPT_UPDATE
, "update" },
96 { EGPT_ERROR
, "error" },
100 static const struct tok egp_acquire_codes_str
[] = {
101 { EGPC_REQUEST
, "request" },
102 { EGPC_CONFIRM
, "confirm" },
103 { EGPC_REFUSE
, "refuse" },
104 { EGPC_CEASE
, "cease" },
105 { EGPC_CEASEACK
, "cease_ack" },
109 static const struct tok egp_acquire_status_str
[] = {
110 { EGPS_UNSPEC
, "unspecified" },
111 { EGPS_ACTIVE
, "active_mode" },
112 { EGPS_PASSIVE
, "passive_mode" },
113 { EGPS_NORES
, "insufficient_resources" },
114 { EGPS_ADMIN
, "administratively_prohibited" },
115 { EGPS_GODOWN
, "going_down" },
116 { EGPS_PARAM
, "parameter_violation" },
117 { EGPS_PROTO
, "protocol_violation" },
121 static const struct tok egp_reach_codes_str
[] = {
122 { EGPC_HELLO
, "hello" },
123 { EGPC_HEARDU
, "i-h-u" },
127 static const struct tok egp_status_updown_str
[] = {
128 { EGPS_INDET
, "indeterminate" },
130 { EGPS_DOWN
, "down" },
134 static const struct tok egp_reasons_str
[] = {
135 { EGPR_UNSPEC
, "unspecified" },
136 { EGPR_BADHEAD
, "bad_EGP_header_format" },
137 { EGPR_BADDATA
, "bad_EGP_data_field_format" },
138 { EGPR_NOREACH
, "reachability_info_unavailable" },
139 { EGPR_XSPOLL
, "excessive_polling_rate" },
140 { EGPR_NORESP
, "no_response" },
141 { EGPR_UVERSION
, "unsupported_version" },
146 egpnr_print(netdissect_options
*ndo
,
147 const struct egp_packet
*egp
, u_int length
)
153 u_int gateways
, distances
, networks
;
154 u_int intgw
, extgw
, t_gateways
;
157 addr
= GET_IPV4_TO_NETWORK_ORDER(egp
->egp_sourcenet
);
158 if (IN_CLASSA(addr
)) {
159 net
= addr
& IN_CLASSA_NET
;
161 } else if (IN_CLASSB(addr
)) {
162 net
= addr
& IN_CLASSB_NET
;
164 } else if (IN_CLASSC(addr
)) {
165 net
= addr
& IN_CLASSC_NET
;
171 cp
= (const uint8_t *)(egp
+ 1);
172 length
-= sizeof(*egp
);
174 intgw
= GET_U_1(egp
->egp_intgw
);
175 extgw
= GET_U_1(egp
->egp_extgw
);
176 t_gateways
= intgw
+ extgw
;
177 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
178 /* Pickup host part of gateway address */
180 if (length
< 4 - netlen
)
182 ND_TCHECK_LEN(cp
, 4 - netlen
);
190 addr
= (addr
<< 8) | GET_U_1(cp
);
194 addr
= (addr
<< 8) | GET_U_1(cp
);
199 length
-= 4 - netlen
;
202 distances
= GET_U_1(cp
);
206 gateways
< intgw
? "int" : "ext",
207 ipaddr_string(ndo
, (const u_char
*)&addr
)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
211 while (distances
!= 0) {
214 ND_PRINT("%sd%u:", comma
, GET_U_1(cp
));
217 networks
= GET_U_1(cp
);
220 while (networks
!= 0) {
221 /* Pickup network number */
224 addr
= ((uint32_t) GET_U_1(cp
)) << 24;
227 if (IN_CLASSB(addr
)) {
230 addr
|= ((uint32_t) GET_U_1(cp
)) << 16;
233 } else if (!IN_CLASSA(addr
)) {
236 addr
|= ((uint32_t) GET_U_1(cp
)) << 16;
238 addr
|= ((uint32_t) GET_U_1(cp
)) << 8;
242 ND_PRINT(" %s", ipaddr_string(ndo
, (const u_char
*)&addr
)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
251 nd_print_invalid(ndo
);
255 egp_print(netdissect_options
*ndo
,
256 const uint8_t *bp
, u_int length
)
258 const struct egp_packet
*egp
;
264 ndo
->ndo_protocol
= "egp";
265 egp
= (const struct egp_packet
*)bp
;
266 ND_ICHECKMSG_ZU("packet length", length
, <, sizeof(*egp
));
269 version
= GET_U_1(egp
->egp_version
);
270 if (!ndo
->ndo_vflag
) {
271 ND_PRINT("EGPv%u, AS %u, seq %u, length %u",
273 GET_BE_U_2(egp
->egp_as
),
274 GET_BE_U_2(egp
->egp_sequence
),
278 ND_PRINT("EGPv%u, length %u",
282 if (version
!= EGP_VERSION
) {
283 ND_PRINT("[version %u]", version
);
287 type
= GET_U_1(egp
->egp_type
);
288 ND_PRINT(" %s", tok2str(egp_type_str
, "[type %u]", type
));
289 code
= GET_U_1(egp
->egp_code
);
290 status
= GET_U_1(egp
->egp_status
);
294 ND_PRINT(" %s", tok2str(egp_acquire_codes_str
, "[code %u]", code
));
302 ND_PRINT(" %s", tok2str(egp_acquire_status_str
, "%u", status
));
306 ND_PRINT(" [status %u]", status
);
309 ND_PRINT(" hello:%u poll:%u",
310 GET_BE_U_2(egp
->egp_hello
),
311 GET_BE_U_2(egp
->egp_poll
));
324 ND_PRINT(" %s", tok2str(egp_acquire_status_str
, "%u", status
));
328 ND_PRINT("[status %u]", status
);
336 ND_PRINT(" %s", tok2str(egp_reach_codes_str
, "[reach code %u]", code
));
340 ND_PRINT(" state:%s", tok2str(egp_status_updown_str
, "%u", status
));
346 ND_PRINT(" state:%s", tok2str(egp_status_updown_str
, "%u", status
));
347 ND_PRINT(" net:%s", GET_IPADDR_STRING(egp
->egp_sourcenet
));
351 if (status
& EGPS_UNSOL
) {
352 status
&= ~EGPS_UNSOL
;
353 ND_PRINT(" unsolicited");
355 ND_PRINT(" state:%s", tok2str(egp_status_updown_str
, "%u", status
));
356 ND_PRINT(" %s int %u ext %u",
357 GET_IPADDR_STRING(egp
->egp_sourcenet
),
358 GET_U_1(egp
->egp_intgw
),
359 GET_U_1(egp
->egp_extgw
));
361 egpnr_print(ndo
, egp
, length
);
365 ND_PRINT(" state:%s", tok2str(egp_status_updown_str
, "%u", status
));
366 ND_PRINT(" %s", tok2str(egp_reasons_str
, "[reason %u]", GET_BE_U_2(egp
->egp_reason
)));
371 nd_print_invalid(ndo
);