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"
32 #define ND_LONGJMP_FROM_TCHECK
33 #include "netdissect.h"
34 #include "addrtoname.h"
41 * RFC 1058 and RFC 2453 header of packet.
44 * 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
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Command (1) | Version (1) | unused |
47 * +---------------+---------------+-------------------------------+
50 nd_uint8_t rip_cmd
; /* request/response */
51 nd_uint8_t rip_vers
; /* protocol version # */
52 nd_byte unused
[2]; /* unused */
55 #define RIPCMD_REQUEST 1 /* want info */
56 #define RIPCMD_RESPONSE 2 /* responding to request */
57 #define RIPCMD_TRACEON 3 /* turn tracing on */
58 #define RIPCMD_TRACEOFF 4 /* turn it off */
60 #define RIPCMD_TRIGREQ 6
61 #define RIPCMD_TRIGRESP 7
62 #define RIPCMD_TRIGACK 8
63 #define RIPCMD_UPDREQ 9
64 #define RIPCMD_UPDRESP 10
65 #define RIPCMD_UPDACK 11
67 static const struct tok rip_cmd_values
[] = {
68 { RIPCMD_REQUEST
, "Request" },
69 { RIPCMD_RESPONSE
, "Response" },
70 { RIPCMD_TRACEON
, "Trace on" },
71 { RIPCMD_TRACEOFF
, "Trace off" },
72 { RIPCMD_TRIGREQ
, "Triggered Request" },
73 { RIPCMD_TRIGRESP
, "Triggered Response" },
74 { RIPCMD_TRIGACK
, "Triggered Acknowledgement" },
75 { RIPCMD_UPDREQ
, "Update Request" },
76 { RIPCMD_UPDRESP
, "Update Response" },
77 { RIPCMD_UPDACK
, "Update Acknowledge" },
81 #define RIP_AUTHLEN 16
82 #define RIP_ROUTELEN 20
85 * First 4 bytes of all RIPv1/RIPv2 entries.
87 struct rip_entry_header
{
88 nd_uint16_t rip_family
;
96 * 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
97 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98 * | Address Family Identifier (2) | must be zero (2) |
99 * +-------------------------------+-------------------------------+
101 * +---------------------------------------------------------------+
102 * | must be zero (4) |
103 * +---------------------------------------------------------------+
104 * | must be zero (4) |
105 * +---------------------------------------------------------------+
107 * +---------------------------------------------------------------+
109 struct rip_netinfo_v1
{
110 nd_uint16_t rip_family
;
115 nd_uint32_t rip_metric
; /* cost of route */
120 * RFC 2453 route entry
123 * 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
124 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
125 * | Address Family Identifier (2) | Route Tag (2) |
126 * +-------------------------------+-------------------------------+
128 * +---------------------------------------------------------------+
129 * | Subnet Mask (4) |
130 * +---------------------------------------------------------------+
132 * +---------------------------------------------------------------+
134 * +---------------------------------------------------------------+
138 struct rip_netinfo_v2
{
139 nd_uint16_t rip_family
;
142 nd_uint32_t rip_dest_mask
;
144 nd_uint32_t rip_metric
; /* cost of route */
148 * RFC 2453 authentication entry
151 * 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
152 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 * | 0xFFFF | Authentication Type (2) |
154 * +-------------------------------+-------------------------------+
155 * - Authentication (16) -
156 * +---------------------------------------------------------------+
160 nd_uint16_t rip_family
;
162 nd_byte rip_auth
[16];
166 * RFC 4822 Cryptographic Authentication entry.
169 * 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
170 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171 * | RIPv2 Packet Length | Key ID | Auth Data Len |
172 * +---------------+---------------+---------------+---------------+
173 * | Sequence Number (non-decreasing) |
174 * +---------------+---------------+---------------+---------------+
175 * | reserved must be zero |
176 * +---------------+---------------+---------------+---------------+
177 * | reserved must be zero |
178 * +---------------+---------------+---------------+---------------+
180 struct rip_auth_crypto_v2
{
181 nd_uint16_t rip_packet_len
;
182 nd_uint8_t rip_key_id
;
183 nd_uint8_t rip_auth_data_len
;
184 nd_uint32_t rip_seq_num
;
190 rip_entry_print_v1(netdissect_options
*ndo
, const u_char
*p
,
193 const struct rip_entry_header
*eh
= (const struct rip_entry_header
*)p
;
195 const struct rip_netinfo_v1
*ni
= (const struct rip_netinfo_v1
*)p
;
198 ND_LCHECKMSG_U(remaining
, RIP_ROUTELEN
, "remaining data length");
200 family
= GET_BE_U_2(ni
->rip_family
);
201 if (family
!= BSD_AFNUM_INET
&& family
!= 0) {
202 ND_PRINT("\n\t AFI %s, ", tok2str(bsd_af_values
, "Unknown (%u)", family
));
203 print_unknown_data(ndo
, p
+ sizeof(*eh
), "\n\t ", RIP_ROUTELEN
- sizeof(*eh
));
204 return (RIP_ROUTELEN
);
206 if (GET_BE_U_2(ni
->rip_mbz1
) ||
207 GET_BE_U_4(ni
->rip_mbz2
) ||
208 GET_BE_U_4(ni
->rip_mbz3
)) {
209 /* MBZ fields not zero */
210 print_unknown_data(ndo
, p
, "\n\t ", RIP_ROUTELEN
);
211 return (RIP_ROUTELEN
);
214 ND_PRINT("\n\t AFI 0, %s, metric: %u",
215 GET_IPADDR_STRING(ni
->rip_dest
),
216 GET_BE_U_4(ni
->rip_metric
));
217 return (RIP_ROUTELEN
);
218 } /* BSD_AFNUM_INET */
219 ND_PRINT("\n\t %s, metric: %u",
220 GET_IPADDR_STRING(ni
->rip_dest
),
221 GET_BE_U_4(ni
->rip_metric
));
222 return (RIP_ROUTELEN
);
228 rip_entry_print_v2(netdissect_options
*ndo
, const u_char
*p
,
231 const struct rip_entry_header
*eh
= (const struct rip_entry_header
*)p
;
233 const struct rip_netinfo_v2
*ni
;
235 ND_LCHECKMSG_ZU(remaining
, sizeof(*eh
), "remaining data length");
237 family
= GET_BE_U_2(eh
->rip_family
);
238 if (family
== 0xFFFF) { /* variable-sized authentication structures */
239 uint16_t auth_type
= GET_BE_U_2(eh
->rip_tag
);
242 remaining
-= sizeof(*eh
);
243 if (auth_type
== 2) {
244 ND_PRINT("\n\t Simple Text Authentication data: ");
245 nd_printjnp(ndo
, p
, RIP_AUTHLEN
);
246 } else if (auth_type
== 3) {
247 const struct rip_auth_crypto_v2
*ch
;
249 ch
= (const struct rip_auth_crypto_v2
*)p
;
250 ND_LCHECKMSG_ZU(remaining
, sizeof(*ch
), "remaining data length");
251 ND_PRINT("\n\t Auth header:");
252 ND_PRINT(" Packet Len %u,",
253 GET_BE_U_2(ch
->rip_packet_len
));
254 ND_PRINT(" Key-ID %u,", GET_U_1(ch
->rip_key_id
));
255 ND_PRINT(" Auth Data Len %u,",
256 GET_U_1(ch
->rip_auth_data_len
));
257 ND_PRINT(" SeqNo %u,", GET_BE_U_4(ch
->rip_seq_num
));
258 ND_PRINT(" MBZ %u,", GET_BE_U_4(ch
->rip_mbz1
));
259 ND_PRINT(" MBZ %u", GET_BE_U_4(ch
->rip_mbz2
));
260 } else if (auth_type
== 1) {
261 ND_PRINT("\n\t Auth trailer:");
262 print_unknown_data(ndo
, p
, "\n\t ", remaining
);
263 return (sizeof(*eh
) + remaining
); /* AT spans till the packet end */
265 ND_PRINT("\n\t Unknown (%u) Authentication data:",
267 print_unknown_data(ndo
, p
, "\n\t ", remaining
);
268 return (sizeof(*eh
) + remaining
); /* we don't know how long this is, so we go to the packet end */
270 } else if (family
!= BSD_AFNUM_INET
&& family
!= 0) {
271 ND_PRINT("\n\t AFI %s", tok2str(bsd_af_values
, "Unknown (%u)", family
));
272 print_unknown_data(ndo
, p
+ sizeof(*eh
), "\n\t ", RIP_ROUTELEN
- sizeof(*eh
));
273 } else { /* BSD_AFNUM_INET or AFI 0 */
274 ni
= (const struct rip_netinfo_v2
*)p
;
275 ND_LCHECKMSG_ZU(remaining
, sizeof(*ni
), "remaining data length");
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_LCHECKMSG_ZU(len
, sizeof(*rp
), "packet length");
303 rp
= (const struct rip
*)p
;
305 vers
= GET_U_1(rp
->rip_vers
);
307 (ndo
->ndo_vflag
>= 1) ? "\n\t" : "",
310 /* dump version and lets see if we know the commands name*/
311 cmd
= GET_U_1(rp
->rip_cmd
);
312 ND_PRINT(", %s, length: %u",
313 tok2str(rip_cmd_values
, "unknown command (%u)", cmd
),
317 if (ndo
->ndo_vflag
< 1)
325 case RIPCMD_RESPONSE
:
329 ND_PRINT(", routes: %u", len
/ RIP_ROUTELEN
);
331 entry_size
= rip_entry_print_v1(ndo
, p
, len
);
332 if (entry_size
== 0) {
336 ND_LCHECKMSG_U(len
, entry_size
, "remaining entries length");
343 ND_PRINT(", routes: %u or less", len
/ RIP_ROUTELEN
);
345 entry_size
= rip_entry_print_v2(ndo
, p
, len
);
346 if (entry_size
== 0) {
350 ND_LCHECKMSG_U(len
, entry_size
, "remaining entries length");
357 ND_PRINT(", unknown version");
363 case RIPCMD_TRACEOFF
:
365 case RIPCMD_TRIGRESP
:
373 if (ndo
->ndo_vflag
<= 1) {
374 if (!print_unknown_data(ndo
, p
, "\n\t", len
))
379 /* do we want to see an additionally hexdump ? */
380 if (ndo
->ndo_vflag
> 1) {
381 if (!print_unknown_data(ndo
, p
, "\n\t", len
))
386 nd_print_invalid(ndo
);
387 ND_TCHECK_LEN(p
, len
);