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 #include <sys/cdefs.h>
24 __RCSID("$NetBSD: print-rip.c,v 1.5 2014/11/20 03:05:03 christos Exp $");
27 #define NETDISSECT_REWORKED
32 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h" /* must come after interface.h */
42 static const char tstr
[] = "[|rip]";
45 uint8_t rip_cmd
; /* request/response */
46 uint8_t rip_vers
; /* protocol version # */
47 uint8_t unused
[2]; /* unused */
50 #define RIPCMD_REQUEST 1 /* want info */
51 #define RIPCMD_RESPONSE 2 /* responding to request */
52 #define RIPCMD_TRACEON 3 /* turn tracing on */
53 #define RIPCMD_TRACEOFF 4 /* turn it off */
54 #define RIPCMD_POLL 5 /* want info from everybody */
55 #define RIPCMD_POLLENTRY 6 /* poll for entry */
57 static const struct tok rip_cmd_values
[] = {
58 { RIPCMD_REQUEST
, "Request" },
59 { RIPCMD_RESPONSE
, "Response" },
60 { RIPCMD_TRACEON
, "Trace on" },
61 { RIPCMD_TRACEOFF
, "Trace off" },
62 { RIPCMD_POLL
, "Poll" },
63 { RIPCMD_POLLENTRY
, "Poll Entry" },
67 #define RIP_AUTHLEN 16
68 #define RIP_ROUTELEN 20
74 * 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
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 * | Command (1) | Version (1) | unused |
77 * +---------------+---------------+-------------------------------+
78 * | Address Family Identifier (2) | Route Tag (2) |
79 * +-------------------------------+-------------------------------+
81 * +---------------------------------------------------------------+
83 * +---------------------------------------------------------------+
85 * +---------------------------------------------------------------+
87 * +---------------------------------------------------------------+
95 uint32_t rip_dest_mask
;
97 uint32_t rip_metric
; /* cost of route */
101 rip_entry_print_v1(netdissect_options
*ndo
,
102 register const struct rip_netinfo
*ni
)
104 register u_short family
;
107 family
= EXTRACT_16BITS(&ni
->rip_family
);
108 if (family
!= BSD_AFNUM_INET
&& family
!= 0) {
109 ND_PRINT((ndo
, "\n\t AFI %s, ", tok2str(bsd_af_values
, "Unknown (%u)", family
)));
110 print_unknown_data(ndo
, (uint8_t *)&ni
->rip_family
, "\n\t ", RIP_ROUTELEN
);
113 if (EXTRACT_16BITS(&ni
->rip_tag
) ||
114 EXTRACT_32BITS(&ni
->rip_dest_mask
) ||
115 EXTRACT_32BITS(&ni
->rip_router
)) {
116 /* MBZ fields not zero */
117 print_unknown_data(ndo
, (uint8_t *)&ni
->rip_family
, "\n\t ", RIP_ROUTELEN
);
121 ND_PRINT((ndo
, "\n\t AFI 0, %s, metric: %u",
122 ipaddr_string(ndo
, &ni
->rip_dest
),
123 EXTRACT_32BITS(&ni
->rip_metric
)));
125 } /* BSD_AFNUM_INET */
126 ND_PRINT((ndo
, "\n\t %s, metric: %u",
127 ipaddr_string(ndo
, &ni
->rip_dest
),
128 EXTRACT_32BITS(&ni
->rip_metric
)));
132 rip_entry_print_v2(netdissect_options
*ndo
,
133 register const struct rip_netinfo
*ni
, const unsigned remaining
)
135 register u_short family
;
137 family
= EXTRACT_16BITS(&ni
->rip_family
);
138 if (family
== 0xFFFF) { /* variable-sized authentication structures */
139 uint16_t auth_type
= EXTRACT_16BITS(&ni
->rip_tag
);
140 if (auth_type
== 2) {
141 register u_char
*p
= (u_char
*)&ni
->rip_dest
;
143 ND_PRINT((ndo
, "\n\t Simple Text Authentication data: "));
144 for (; i
< RIP_AUTHLEN
; p
++, i
++)
145 ND_PRINT((ndo
, "%c", ND_ISPRINT(*p
) ? *p
: '.'));
146 } else if (auth_type
== 3) {
147 ND_PRINT((ndo
, "\n\t Auth header:"));
148 ND_PRINT((ndo
, " Packet Len %u,", EXTRACT_16BITS((uint8_t *)ni
+ 4)));
149 ND_PRINT((ndo
, " Key-ID %u,", *((uint8_t *)ni
+ 6)));
150 ND_PRINT((ndo
, " Auth Data Len %u,", *((uint8_t *)ni
+ 7)));
151 ND_PRINT((ndo
, " SeqNo %u,", EXTRACT_32BITS(&ni
->rip_dest_mask
)));
152 ND_PRINT((ndo
, " MBZ %u,", EXTRACT_32BITS(&ni
->rip_router
)));
153 ND_PRINT((ndo
, " MBZ %u", EXTRACT_32BITS(&ni
->rip_metric
)));
154 } else if (auth_type
== 1) {
155 ND_PRINT((ndo
, "\n\t Auth trailer:"));
156 print_unknown_data(ndo
, (uint8_t *)&ni
->rip_dest
, "\n\t ", remaining
);
157 return remaining
; /* AT spans till the packet end */
159 ND_PRINT((ndo
, "\n\t Unknown (%u) Authentication data:",
160 EXTRACT_16BITS(&ni
->rip_tag
)));
161 print_unknown_data(ndo
, (uint8_t *)&ni
->rip_dest
, "\n\t ", remaining
);
163 } else if (family
!= BSD_AFNUM_INET
&& family
!= 0) {
164 ND_PRINT((ndo
, "\n\t AFI %s", tok2str(bsd_af_values
, "Unknown (%u)", family
)));
165 print_unknown_data(ndo
, (uint8_t *)&ni
->rip_tag
, "\n\t ", RIP_ROUTELEN
-2);
166 } else { /* BSD_AFNUM_INET or AFI 0 */
167 ND_PRINT((ndo
, "\n\t AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
168 tok2str(bsd_af_values
, "%u", family
),
169 ipaddr_string(ndo
, &ni
->rip_dest
),
170 mask2plen(EXTRACT_32BITS(&ni
->rip_dest_mask
)),
171 EXTRACT_16BITS(&ni
->rip_tag
),
172 EXTRACT_32BITS(&ni
->rip_metric
)));
173 if (EXTRACT_32BITS(&ni
->rip_router
))
174 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, &ni
->rip_router
)));
176 ND_PRINT((ndo
, "self"));
182 rip_print(netdissect_options
*ndo
,
183 const u_char
*dat
, u_int length
)
185 register const struct rip
*rp
;
186 register const struct rip_netinfo
*ni
;
189 if (ndo
->ndo_snapend
< dat
) {
190 ND_PRINT((ndo
, " %s", tstr
));
193 i
= ndo
->ndo_snapend
- dat
;
196 if (i
< sizeof(*rp
)) {
197 ND_PRINT((ndo
, " %s", tstr
));
202 rp
= (struct rip
*)dat
;
204 ND_PRINT((ndo
, "%sRIPv%u",
205 (ndo
->ndo_vflag
>= 1) ? "\n\t" : "",
208 switch (rp
->rip_vers
) {
213 * XXX - RFC 1058 says
215 * 0 Datagrams whose version number is zero are to be ignored.
216 * These are from a previous version of the protocol, whose
217 * packet format was machine-specific.
219 * so perhaps we should just dump the packet, in hex.
221 print_unknown_data(ndo
, (uint8_t *)&rp
->rip_cmd
, "\n\t", length
);
224 /* dump version and lets see if we know the commands name*/
225 ND_PRINT((ndo
, ", %s, length: %u",
226 tok2str(rip_cmd_values
,
227 "unknown command (%u)",
231 if (ndo
->ndo_vflag
< 1)
234 switch (rp
->rip_cmd
) {
236 case RIPCMD_RESPONSE
:
237 j
= length
/ sizeof(*ni
);
238 ND_PRINT((ndo
, ", routes: %u%s", j
, rp
->rip_vers
== 2 ? " or less" : ""));
239 ni
= (struct rip_netinfo
*)(rp
+ 1);
240 for (; i
>= sizeof(*ni
); ++ni
) {
241 if (rp
->rip_vers
== 1)
243 rip_entry_print_v1(ndo
, ni
);
246 else if (rp
->rip_vers
== 2)
247 i
-= rip_entry_print_v2(ndo
, ni
, i
);
252 ND_PRINT((ndo
, "%s", tstr
));
255 case RIPCMD_TRACEOFF
:
257 case RIPCMD_POLLENTRY
:
263 if (ndo
->ndo_vflag
<= 1) {
264 if(!print_unknown_data(ndo
, (uint8_t *)rp
, "\n\t", length
))
269 /* do we want to see an additionally hexdump ? */
270 if (ndo
->ndo_vflag
> 1) {
271 if(!print_unknown_data(ndo
, (uint8_t *)rp
, "\n\t", length
))