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 */
28 #include "netdissect-stdinc.h"
30 #define ND_LONGJMP_FROM_TCHECK
31 #include "netdissect.h"
32 #include "addrtoname.h"
39 * RFC 1058 and RFC 2453 header of packet.
42 * 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
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | Command (1) | Version (1) | unused |
45 * +---------------+---------------+-------------------------------+
48 nd_uint8_t rip_cmd
; /* request/response */
49 nd_uint8_t rip_vers
; /* protocol version # */
50 nd_byte unused
[2]; /* unused */
53 #define RIPCMD_REQUEST 1 /* want info */
54 #define RIPCMD_RESPONSE 2 /* responding to request */
55 #define RIPCMD_TRACEON 3 /* turn tracing on */
56 #define RIPCMD_TRACEOFF 4 /* turn it off */
58 #define RIPCMD_TRIGREQ 6
59 #define RIPCMD_TRIGRESP 7
60 #define RIPCMD_TRIGACK 8
61 #define RIPCMD_UPDREQ 9
62 #define RIPCMD_UPDRESP 10
63 #define RIPCMD_UPDACK 11
65 static const struct tok rip_cmd_values
[] = {
66 { RIPCMD_REQUEST
, "Request" },
67 { RIPCMD_RESPONSE
, "Response" },
68 { RIPCMD_TRACEON
, "Trace on" },
69 { RIPCMD_TRACEOFF
, "Trace off" },
70 { RIPCMD_TRIGREQ
, "Triggered Request" },
71 { RIPCMD_TRIGRESP
, "Triggered Response" },
72 { RIPCMD_TRIGACK
, "Triggered Acknowledgement" },
73 { RIPCMD_UPDREQ
, "Update Request" },
74 { RIPCMD_UPDRESP
, "Update Response" },
75 { RIPCMD_UPDACK
, "Update Acknowledge" },
79 #define RIP_AUTHLEN 16
80 #define RIP_ROUTELEN 20
83 * First 4 bytes of all RIPv1/RIPv2 entries.
85 struct rip_entry_header
{
86 nd_uint16_t rip_family
;
94 * 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
95 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96 * | Address Family Identifier (2) | must be zero (2) |
97 * +-------------------------------+-------------------------------+
99 * +---------------------------------------------------------------+
100 * | must be zero (4) |
101 * +---------------------------------------------------------------+
102 * | must be zero (4) |
103 * +---------------------------------------------------------------+
105 * +---------------------------------------------------------------+
107 struct rip_netinfo_v1
{
108 nd_uint16_t rip_family
;
113 nd_uint32_t rip_metric
; /* cost of route */
118 * RFC 2453 route entry
121 * 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
122 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123 * | Address Family Identifier (2) | Route Tag (2) |
124 * +-------------------------------+-------------------------------+
126 * +---------------------------------------------------------------+
127 * | Subnet Mask (4) |
128 * +---------------------------------------------------------------+
130 * +---------------------------------------------------------------+
132 * +---------------------------------------------------------------+
136 struct rip_netinfo_v2
{
137 nd_uint16_t rip_family
;
140 nd_uint32_t rip_dest_mask
;
142 nd_uint32_t rip_metric
; /* cost of route */
146 * RFC 2453 authentication entry
149 * 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
150 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151 * | 0xFFFF | Authentication Type (2) |
152 * +-------------------------------+-------------------------------+
153 * - Authentication (16) -
154 * +---------------------------------------------------------------+
158 nd_uint16_t rip_family
;
160 nd_byte rip_auth
[16];
164 * RFC 4822 Cryptographic Authentication entry.
167 * 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
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169 * | RIPv2 Packet Length | Key ID | Auth Data Len |
170 * +---------------+---------------+---------------+---------------+
171 * | Sequence Number (non-decreasing) |
172 * +---------------+---------------+---------------+---------------+
173 * | reserved must be zero |
174 * +---------------+---------------+---------------+---------------+
175 * | reserved must be zero |
176 * +---------------+---------------+---------------+---------------+
178 struct rip_auth_crypto_v2
{
179 nd_uint16_t rip_packet_len
;
180 nd_uint8_t rip_key_id
;
181 nd_uint8_t rip_auth_data_len
;
182 nd_uint32_t rip_seq_num
;
188 rip_entry_print_v1(netdissect_options
*ndo
, const u_char
*p
,
191 const struct rip_entry_header
*eh
= (const struct rip_entry_header
*)p
;
193 const struct rip_netinfo_v1
*ni
= (const struct rip_netinfo_v1
*)p
;
196 ND_ICHECKMSG_U("remaining data length", remaining
, <, RIP_ROUTELEN
);
198 family
= GET_BE_U_2(ni
->rip_family
);
199 if (family
!= BSD_AF_INET
&& family
!= 0) {
200 ND_PRINT("\n\t AFI %s, ", tok2str(bsd_af_values
, "Unknown (%u)", family
));
201 print_unknown_data(ndo
, p
+ sizeof(*eh
), "\n\t ", RIP_ROUTELEN
- sizeof(*eh
));
202 return (RIP_ROUTELEN
);
204 if (GET_BE_U_2(ni
->rip_mbz1
) ||
205 GET_BE_U_4(ni
->rip_mbz2
) ||
206 GET_BE_U_4(ni
->rip_mbz3
)) {
207 /* MBZ fields not zero */
208 print_unknown_data(ndo
, p
, "\n\t ", RIP_ROUTELEN
);
209 return (RIP_ROUTELEN
);
212 ND_PRINT("\n\t AFI 0, %s, metric: %u",
213 GET_IPADDR_STRING(ni
->rip_dest
),
214 GET_BE_U_4(ni
->rip_metric
));
215 return (RIP_ROUTELEN
);
217 ND_PRINT("\n\t %s, metric: %u",
218 GET_IPADDR_STRING(ni
->rip_dest
),
219 GET_BE_U_4(ni
->rip_metric
));
220 return (RIP_ROUTELEN
);
226 rip_entry_print_v2(netdissect_options
*ndo
, const u_char
*p
,
229 const struct rip_entry_header
*eh
= (const struct rip_entry_header
*)p
;
231 const struct rip_netinfo_v2
*ni
;
233 ND_ICHECKMSG_ZU("remaining data length", remaining
, <, sizeof(*eh
));
235 family
= GET_BE_U_2(eh
->rip_family
);
236 if (family
== 0xFFFF) { /* variable-sized authentication structures */
237 uint16_t auth_type
= GET_BE_U_2(eh
->rip_tag
);
240 remaining
-= sizeof(*eh
);
241 if (auth_type
== 2) {
242 ND_PRINT("\n\t Simple Text Authentication data: ");
243 nd_printjnp(ndo
, p
, RIP_AUTHLEN
);
244 } else if (auth_type
== 3) {
245 const struct rip_auth_crypto_v2
*ch
;
247 ch
= (const struct rip_auth_crypto_v2
*)p
;
248 ND_ICHECKMSG_ZU("remaining data length", remaining
,
250 ND_PRINT("\n\t Auth header:");
251 ND_PRINT(" Packet Len %u,",
252 GET_BE_U_2(ch
->rip_packet_len
));
253 ND_PRINT(" Key-ID %u,", GET_U_1(ch
->rip_key_id
));
254 ND_PRINT(" Auth Data Len %u,",
255 GET_U_1(ch
->rip_auth_data_len
));
256 ND_PRINT(" SeqNo %u,", GET_BE_U_4(ch
->rip_seq_num
));
257 ND_PRINT(" MBZ %u,", GET_BE_U_4(ch
->rip_mbz1
));
258 ND_PRINT(" MBZ %u", GET_BE_U_4(ch
->rip_mbz2
));
259 } else if (auth_type
== 1) {
260 ND_PRINT("\n\t Auth trailer:");
261 print_unknown_data(ndo
, p
, "\n\t ", remaining
);
262 return (sizeof(*eh
) + remaining
); /* AT spans till the packet end */
264 ND_PRINT("\n\t Unknown (%u) Authentication data:",
266 print_unknown_data(ndo
, p
, "\n\t ", remaining
);
267 return (sizeof(*eh
) + remaining
); /* we don't know how long this is, so we go to the packet end */
269 } else if (family
!= BSD_AF_INET
&& family
!= 0) {
270 ND_PRINT("\n\t AFI %s", tok2str(bsd_af_values
, "Unknown (%u)", family
));
271 print_unknown_data(ndo
, p
+ sizeof(*eh
), "\n\t ", RIP_ROUTELEN
- sizeof(*eh
));
272 } else { /* BSD_AF_INET or AFI 0 */
273 ni
= (const struct rip_netinfo_v2
*)p
;
274 ND_ICHECKMSG_ZU("remaining data length", remaining
, <,
276 ND_PRINT("\n\t AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
277 tok2str(bsd_af_values
, "%u", family
),
278 GET_IPADDR_STRING(ni
->rip_dest
),
279 mask2plen(GET_BE_U_4(ni
->rip_dest_mask
)),
280 GET_BE_U_2(ni
->rip_tag
),
281 GET_BE_U_4(ni
->rip_metric
));
282 if (GET_BE_U_4(ni
->rip_router
))
283 ND_PRINT("%s", GET_IPADDR_STRING(ni
->rip_router
));
287 return (RIP_ROUTELEN
);
293 rip_print(netdissect_options
*ndo
,
294 const u_char
*p
, u_int len
)
296 const struct rip
*rp
;
300 ndo
->ndo_protocol
= "rip";
301 ND_PRINT("%s", (ndo
->ndo_vflag
>= 1) ? "\n\t" : "");
302 nd_print_protocol_caps(ndo
);
303 ND_ICHECKMSG_ZU("packet length", len
, <, sizeof(*rp
));
305 rp
= (const struct rip
*)p
;
307 vers
= GET_U_1(rp
->rip_vers
);
308 ND_PRINT("v%u", vers
);
309 if (vers
!= 1 && vers
!= 2) {
310 ND_PRINT(" [version != 1 && version != 2]");
314 /* dump version and lets see if we know the commands name*/
315 cmd
= GET_U_1(rp
->rip_cmd
);
316 ND_PRINT(", %s, length: %u",
317 tok2str(rip_cmd_values
, "unknown command (%u)", cmd
),
321 if (ndo
->ndo_vflag
< 1)
329 case RIPCMD_RESPONSE
:
333 ND_PRINT(", routes: %u", len
/ RIP_ROUTELEN
);
335 entry_size
= rip_entry_print_v1(ndo
, p
, len
);
336 if (entry_size
== 0) {
340 ND_ICHECKMSG_U("remaining entries length",
348 ND_PRINT(", routes: %u or less", len
/ RIP_ROUTELEN
);
350 entry_size
= rip_entry_print_v2(ndo
, p
, len
);
351 if (entry_size
== 0) {
355 ND_ICHECKMSG_U("remaining entries length",
363 ND_PRINT(", unknown version");
369 case RIPCMD_TRACEOFF
:
371 case RIPCMD_TRIGRESP
:
379 if (ndo
->ndo_vflag
<= 1) {
380 if (!print_unknown_data(ndo
, p
, "\n\t", len
))
385 /* do we want to see an additionally hexdump ? */
386 if (ndo
->ndo_vflag
> 1 && ND_TTEST_LEN(p
, len
)) {
387 if (!print_unknown_data(ndo
, p
, "\n\t", len
))
392 nd_print_invalid(ndo
);
393 ND_TCHECK_LEN(p
, len
);