2 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 /* \summary: Routing Information Protocol (RIP) printer */
24 /* specification: RFC 1058, RFC 2453, RFC 4822 */
30 #include "netdissect-stdinc.h"
34 #include "netdissect.h"
35 #include "addrtoname.h"
42 * RFC 1058 and RFC 2453 header of packet.
45 * 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
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * | Command (1) | Version (1) | unused |
48 * +---------------+---------------+-------------------------------+
51 nd_uint8_t rip_cmd
; /* request/response */
52 nd_uint8_t rip_vers
; /* protocol version # */
53 nd_byte unused
[2]; /* unused */
56 #define RIPCMD_REQUEST 1 /* want info */
57 #define RIPCMD_RESPONSE 2 /* responding to request */
58 #define RIPCMD_TRACEON 3 /* turn tracing on */
59 #define RIPCMD_TRACEOFF 4 /* turn it off */
60 #define RIPCMD_POLL 5 /* want info from everybody */
61 #define RIPCMD_POLLENTRY 6 /* poll for entry */
63 static const struct tok rip_cmd_values
[] = {
64 { RIPCMD_REQUEST
, "Request" },
65 { RIPCMD_RESPONSE
, "Response" },
66 { RIPCMD_TRACEON
, "Trace on" },
67 { RIPCMD_TRACEOFF
, "Trace off" },
68 { RIPCMD_POLL
, "Poll" },
69 { RIPCMD_POLLENTRY
, "Poll Entry" },
73 #define RIP_AUTHLEN 16
74 #define RIP_ROUTELEN 20
77 * First 4 bytes of all RIPv1/RIPv2 entries.
79 struct rip_entry_header
{
80 nd_uint16_t rip_family
;
88 * 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
89 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 * | Address Family Identifier (2) | must be zero (2) |
91 * +-------------------------------+-------------------------------+
93 * +---------------------------------------------------------------+
94 * | must be zero (4) |
95 * +---------------------------------------------------------------+
96 * | must be zero (4) |
97 * +---------------------------------------------------------------+
99 * +---------------------------------------------------------------+
101 struct rip_netinfo_v1
{
102 nd_uint16_t rip_family
;
107 nd_uint32_t rip_metric
; /* cost of route */
112 * RFC 2453 route entry
115 * 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
116 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117 * | Address Family Identifier (2) | Route Tag (2) |
118 * +-------------------------------+-------------------------------+
120 * +---------------------------------------------------------------+
121 * | Subnet Mask (4) |
122 * +---------------------------------------------------------------+
124 * +---------------------------------------------------------------+
126 * +---------------------------------------------------------------+
130 struct rip_netinfo_v2
{
131 nd_uint16_t rip_family
;
134 nd_uint32_t rip_dest_mask
;
136 nd_uint32_t rip_metric
; /* cost of route */
140 * RFC 2453 authentication entry
143 * 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
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 * | 0xFFFF | Authentication Type (2) |
146 * +-------------------------------+-------------------------------+
147 * - Authentication (16) -
148 * +---------------------------------------------------------------+
152 nd_uint16_t rip_family
;
154 nd_byte rip_auth
[16];
158 * RFC 4822 Cryptographic Authentication entry.
161 * 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
162 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
163 * | RIPv2 Packet Length | Key ID | Auth Data Len |
164 * +---------------+---------------+---------------+---------------+
165 * | Sequence Number (non-decreasing) |
166 * +---------------+---------------+---------------+---------------+
167 * | reserved must be zero |
168 * +---------------+---------------+---------------+---------------+
169 * | reserved must be zero |
170 * +---------------+---------------+---------------+---------------+
172 struct rip_auth_crypto_v2
{
173 nd_uint16_t rip_packet_len
;
174 nd_uint8_t rip_key_id
;
175 nd_uint8_t rip_auth_data_len
;
176 nd_uint32_t rip_seq_num
;
182 rip_entry_print_v1(netdissect_options
*ndo
, const u_char
*p
,
185 const struct rip_entry_header
*eh
= (const struct rip_entry_header
*)p
;
187 const struct rip_netinfo_v1
*ni
= (const struct rip_netinfo_v1
*)p
;
190 if (remaining
< RIP_ROUTELEN
)
192 family
= EXTRACT_BE_U_2(ni
->rip_family
);
193 if (family
!= BSD_AFNUM_INET
&& family
!= 0) {
194 ND_PRINT("\n\t AFI %s, ", tok2str(bsd_af_values
, "Unknown (%u)", family
));
195 print_unknown_data(ndo
, p
+ sizeof(*eh
), "\n\t ", RIP_ROUTELEN
- sizeof(*eh
));
196 return (RIP_ROUTELEN
);
198 if (EXTRACT_BE_U_2(ni
->rip_mbz1
) ||
199 EXTRACT_BE_U_4(ni
->rip_mbz2
) ||
200 EXTRACT_BE_U_4(ni
->rip_mbz3
)) {
201 /* MBZ fields not zero */
202 print_unknown_data(ndo
, p
, "\n\t ", RIP_ROUTELEN
);
203 return (RIP_ROUTELEN
);
206 ND_PRINT("\n\t AFI 0, %s, metric: %u",
207 ipaddr_string(ndo
, ni
->rip_dest
),
208 EXTRACT_BE_U_4(ni
->rip_metric
));
209 return (RIP_ROUTELEN
);
210 } /* BSD_AFNUM_INET */
211 ND_PRINT("\n\t %s, metric: %u",
212 ipaddr_string(ndo
, ni
->rip_dest
),
213 EXTRACT_BE_U_4(ni
->rip_metric
));
214 return (RIP_ROUTELEN
);
218 rip_entry_print_v2(netdissect_options
*ndo
, const u_char
*p
,
221 const struct rip_entry_header
*eh
= (const struct rip_entry_header
*)p
;
223 const struct rip_netinfo_v2
*ni
;
225 if (remaining
< sizeof(*eh
))
227 family
= EXTRACT_BE_U_2(eh
->rip_family
);
228 if (family
== 0xFFFF) { /* variable-sized authentication structures */
229 uint16_t auth_type
= EXTRACT_BE_U_2(eh
->rip_tag
);
232 remaining
-= sizeof(*eh
);
233 if (auth_type
== 2) {
234 ND_PRINT("\n\t Simple Text Authentication data: ");
235 if (nd_printzp(ndo
, p
, RIP_AUTHLEN
, p
+ remaining
))
237 } else if (auth_type
== 3) {
238 const struct rip_auth_crypto_v2
*ch
;
240 ch
= (const struct rip_auth_crypto_v2
*)p
;
241 if (remaining
< sizeof(*ch
))
243 ND_PRINT("\n\t Auth header:");
244 ND_PRINT(" Packet Len %u,", EXTRACT_BE_U_2(ch
->rip_packet_len
));
245 ND_PRINT(" Key-ID %u,", EXTRACT_U_1(ch
->rip_key_id
));
246 ND_PRINT(" Auth Data Len %u,", EXTRACT_U_1(ch
->rip_auth_data_len
));
247 ND_PRINT(" SeqNo %u,", EXTRACT_BE_U_4(ch
->rip_seq_num
));
248 ND_PRINT(" MBZ %u,", EXTRACT_BE_U_4(ch
->rip_mbz1
));
249 ND_PRINT(" MBZ %u", EXTRACT_BE_U_4(ch
->rip_mbz2
));
250 } else if (auth_type
== 1) {
251 ND_PRINT("\n\t Auth trailer:");
252 print_unknown_data(ndo
, p
, "\n\t ", remaining
);
253 return (sizeof(*eh
) + remaining
); /* AT spans till the packet end */
255 ND_PRINT("\n\t Unknown (%u) Authentication data:",
257 print_unknown_data(ndo
, p
, "\n\t ", remaining
);
258 return (sizeof(*eh
) + remaining
); /* we don't know how long this is, so we go to the packet end */
260 } else if (family
!= BSD_AFNUM_INET
&& family
!= 0) {
261 ND_PRINT("\n\t AFI %s", tok2str(bsd_af_values
, "Unknown (%u)", family
));
262 print_unknown_data(ndo
, p
+ sizeof(*eh
), "\n\t ", RIP_ROUTELEN
- sizeof(*eh
));
263 } else { /* BSD_AFNUM_INET or AFI 0 */
264 ni
= (const struct rip_netinfo_v2
*)p
;
265 if (remaining
< sizeof(*ni
))
267 ND_PRINT("\n\t AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
268 tok2str(bsd_af_values
, "%u", family
),
269 ipaddr_string(ndo
, ni
->rip_dest
),
270 mask2plen(EXTRACT_BE_U_4(ni
->rip_dest_mask
)),
271 EXTRACT_BE_U_2(ni
->rip_tag
),
272 EXTRACT_BE_U_4(ni
->rip_metric
));
273 if (EXTRACT_BE_U_4(ni
->rip_router
))
274 ND_PRINT("%s", ipaddr_string(ndo
, ni
->rip_router
));
278 return (RIP_ROUTELEN
);
282 rip_print(netdissect_options
*ndo
,
283 const u_char
*dat
, u_int length
)
285 const struct rip
*rp
;
291 ndo
->ndo_protocol
= "rip";
292 if (ndo
->ndo_snapend
< dat
) {
296 i
= ndo
->ndo_snapend
- dat
;
299 if (i
< sizeof(*rp
)) {
305 rp
= (const struct rip
*)dat
;
307 vers
= EXTRACT_U_1(rp
->rip_vers
);
309 (ndo
->ndo_vflag
>= 1) ? "\n\t" : "",
316 * XXX - RFC 1058 says
318 * 0 Datagrams whose version number is zero are to be ignored.
319 * These are from a previous version of the protocol, whose
320 * packet format was machine-specific.
322 * so perhaps we should just dump the packet, in hex.
324 print_unknown_data(ndo
, (const uint8_t *)&rp
->rip_cmd
, "\n\t", length
);
328 /* dump version and lets see if we know the commands name*/
329 cmd
= EXTRACT_U_1(rp
->rip_cmd
);
330 ND_PRINT(", %s, length: %u",
331 tok2str(rip_cmd_values
, "unknown command (%u)", cmd
),
334 if (ndo
->ndo_vflag
< 1)
340 case RIPCMD_RESPONSE
:
344 j
= length
/ RIP_ROUTELEN
;
345 ND_PRINT(", routes: %u", j
);
346 p
= (const u_char
*)(rp
+ 1);
348 entry_size
= rip_entry_print_v1(ndo
, p
, i
);
349 if (entry_size
== 0) {
360 j
= length
/ RIP_ROUTELEN
;
361 ND_PRINT(", routes: %u or less", j
);
362 p
= (const u_char
*)(rp
+ 1);
364 entry_size
= rip_entry_print_v2(ndo
, p
, i
);
365 if (entry_size
== 0) {
371 if (i
< entry_size
) {
382 ND_PRINT(", unknown version");
387 case RIPCMD_TRACEOFF
:
389 case RIPCMD_POLLENTRY
:
395 if (ndo
->ndo_vflag
<= 1) {
396 if (!print_unknown_data(ndo
, (const uint8_t *)rp
, "\n\t", length
))
401 /* do we want to see an additionally hexdump ? */
402 if (ndo
->ndo_vflag
> 1) {
403 if (!print_unknown_data(ndo
, (const uint8_t *)rp
, "\n\t", length
))