1*05b00f60SXin Li /*
2*05b00f60SXin Li * Copyright (c) 1989, 1990, 1991, 1993, 1994
3*05b00f60SXin Li * The Regents of the University of California. All rights reserved.
4*05b00f60SXin Li *
5*05b00f60SXin Li * Redistribution and use in source and binary forms, with or without
6*05b00f60SXin Li * modification, are permitted provided that: (1) source code distributions
7*05b00f60SXin Li * retain the above copyright notice and this paragraph in its entirety, (2)
8*05b00f60SXin Li * distributions including binary code include the above copyright notice and
9*05b00f60SXin Li * this paragraph in its entirety in the documentation or other materials
10*05b00f60SXin Li * provided with the distribution, and (3) all advertising materials mentioning
11*05b00f60SXin Li * features or use of this software display the following acknowledgement:
12*05b00f60SXin Li * ``This product includes software developed by the University of California,
13*05b00f60SXin Li * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*05b00f60SXin Li * the University nor the names of its contributors may be used to endorse
15*05b00f60SXin Li * or promote products derived from this software without specific prior
16*05b00f60SXin Li * written permission.
17*05b00f60SXin Li * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*05b00f60SXin Li * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*05b00f60SXin Li * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*05b00f60SXin Li */
21*05b00f60SXin Li
22*05b00f60SXin Li /* \summary: IPv6 Routing Information Protocol (RIPng) printer */
23*05b00f60SXin Li
24*05b00f60SXin Li /* specification: RFC 2080 */
25*05b00f60SXin Li
26*05b00f60SXin Li #ifdef HAVE_CONFIG_H
27*05b00f60SXin Li #include <config.h>
28*05b00f60SXin Li #endif
29*05b00f60SXin Li
30*05b00f60SXin Li #include "netdissect-stdinc.h"
31*05b00f60SXin Li
32*05b00f60SXin Li #include "netdissect.h"
33*05b00f60SXin Li #include "addrtoname.h"
34*05b00f60SXin Li #include "extract.h"
35*05b00f60SXin Li
36*05b00f60SXin Li /*
37*05b00f60SXin Li * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project.
38*05b00f60SXin Li * All rights reserved.
39*05b00f60SXin Li *
40*05b00f60SXin Li * Redistribution and use in source and binary forms, with or without
41*05b00f60SXin Li * modification, are permitted provided that the following conditions
42*05b00f60SXin Li * are met:
43*05b00f60SXin Li * 1. Redistributions of source code must retain the above copyright
44*05b00f60SXin Li * notice, this list of conditions and the following disclaimer.
45*05b00f60SXin Li * 2. Redistributions in binary form must reproduce the above copyright
46*05b00f60SXin Li * notice, this list of conditions and the following disclaimer in the
47*05b00f60SXin Li * documentation and/or other materials provided with the distribution.
48*05b00f60SXin Li * 3. Neither the name of the project nor the names of its contributors
49*05b00f60SXin Li * may be used to endorse or promote products derived from this software
50*05b00f60SXin Li * without specific prior written permission.
51*05b00f60SXin Li *
52*05b00f60SXin Li * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
53*05b00f60SXin Li * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54*05b00f60SXin Li * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55*05b00f60SXin Li * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
56*05b00f60SXin Li * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57*05b00f60SXin Li * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58*05b00f60SXin Li * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59*05b00f60SXin Li * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60*05b00f60SXin Li * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61*05b00f60SXin Li * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62*05b00f60SXin Li * SUCH DAMAGE.
63*05b00f60SXin Li */
64*05b00f60SXin Li #define RIP6_VERSION 1
65*05b00f60SXin Li
66*05b00f60SXin Li #define RIP6_REQUEST 1
67*05b00f60SXin Li #define RIP6_RESPONSE 2
68*05b00f60SXin Li
69*05b00f60SXin Li struct netinfo6 {
70*05b00f60SXin Li nd_ipv6 rip6_dest;
71*05b00f60SXin Li nd_uint16_t rip6_tag;
72*05b00f60SXin Li nd_uint8_t rip6_plen;
73*05b00f60SXin Li nd_uint8_t rip6_metric;
74*05b00f60SXin Li };
75*05b00f60SXin Li
76*05b00f60SXin Li struct rip6 {
77*05b00f60SXin Li nd_uint8_t rip6_cmd;
78*05b00f60SXin Li nd_uint8_t rip6_vers;
79*05b00f60SXin Li nd_byte rip6_res1[2];
80*05b00f60SXin Li struct netinfo6 rip6_nets[1];
81*05b00f60SXin Li };
82*05b00f60SXin Li
83*05b00f60SXin Li #define HOPCNT_INFINITY6 16
84*05b00f60SXin Li
ND_IN6_IS_ADDR_UNSPECIFIED(const nd_ipv6 * addr)85*05b00f60SXin Li static int ND_IN6_IS_ADDR_UNSPECIFIED(const nd_ipv6 *addr)
86*05b00f60SXin Li {
87*05b00f60SXin Li static const nd_ipv6 in6addr_any_val = { 0 }; /* :: */
88*05b00f60SXin Li return (memcmp(addr, &in6addr_any_val, sizeof(*addr)) == 0);
89*05b00f60SXin Li }
90*05b00f60SXin Li
91*05b00f60SXin Li static void
rip6_entry_print(netdissect_options * ndo,const struct netinfo6 * ni,const u_int print_metric)92*05b00f60SXin Li rip6_entry_print(netdissect_options *ndo,
93*05b00f60SXin Li const struct netinfo6 *ni, const u_int print_metric)
94*05b00f60SXin Li {
95*05b00f60SXin Li uint16_t tag;
96*05b00f60SXin Li uint8_t metric;
97*05b00f60SXin Li
98*05b00f60SXin Li ND_PRINT("%s/%u", GET_IP6ADDR_STRING(ni->rip6_dest),
99*05b00f60SXin Li GET_U_1(ni->rip6_plen));
100*05b00f60SXin Li tag = GET_BE_U_2(ni->rip6_tag);
101*05b00f60SXin Li if (tag)
102*05b00f60SXin Li ND_PRINT(" [%u]", tag);
103*05b00f60SXin Li metric = GET_U_1(ni->rip6_metric);
104*05b00f60SXin Li if (metric && print_metric)
105*05b00f60SXin Li ND_PRINT(" (%u)", metric);
106*05b00f60SXin Li }
107*05b00f60SXin Li
108*05b00f60SXin Li void
ripng_print(netdissect_options * ndo,const u_char * dat,unsigned int length)109*05b00f60SXin Li ripng_print(netdissect_options *ndo, const u_char *dat, unsigned int length)
110*05b00f60SXin Li {
111*05b00f60SXin Li const struct rip6 *rp = (const struct rip6 *)dat;
112*05b00f60SXin Li uint8_t cmd, vers;
113*05b00f60SXin Li const struct netinfo6 *ni;
114*05b00f60SXin Li unsigned int length_left;
115*05b00f60SXin Li u_int j;
116*05b00f60SXin Li
117*05b00f60SXin Li ndo->ndo_protocol = "ripng";
118*05b00f60SXin Li vers = GET_U_1(rp->rip6_vers);
119*05b00f60SXin Li if (vers != RIP6_VERSION) {
120*05b00f60SXin Li nd_print_protocol(ndo);
121*05b00f60SXin Li ND_PRINT(" [version %u, must be %u]", vers, RIP6_VERSION);
122*05b00f60SXin Li goto invalid;
123*05b00f60SXin Li }
124*05b00f60SXin Li cmd = GET_U_1(rp->rip6_cmd);
125*05b00f60SXin Li switch (cmd) {
126*05b00f60SXin Li
127*05b00f60SXin Li case RIP6_REQUEST:
128*05b00f60SXin Li length_left = length;
129*05b00f60SXin Li if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
130*05b00f60SXin Li goto invalid;
131*05b00f60SXin Li length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
132*05b00f60SXin Li j = length_left / sizeof(*ni);
133*05b00f60SXin Li if (j == 1) {
134*05b00f60SXin Li if (GET_U_1(rp->rip6_nets->rip6_metric) == HOPCNT_INFINITY6
135*05b00f60SXin Li && ND_IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
136*05b00f60SXin Li ND_PRINT(" ripng-req dump");
137*05b00f60SXin Li break;
138*05b00f60SXin Li }
139*05b00f60SXin Li }
140*05b00f60SXin Li if (j * sizeof(*ni) != length_left)
141*05b00f60SXin Li ND_PRINT(" ripng-req %u[%u]:", j, length);
142*05b00f60SXin Li else
143*05b00f60SXin Li ND_PRINT(" ripng-req %u:", j);
144*05b00f60SXin Li for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
145*05b00f60SXin Li length_left -= sizeof(*ni), ++ni) {
146*05b00f60SXin Li if (ndo->ndo_vflag > 1)
147*05b00f60SXin Li ND_PRINT("\n\t");
148*05b00f60SXin Li else
149*05b00f60SXin Li ND_PRINT(" ");
150*05b00f60SXin Li rip6_entry_print(ndo, ni, FALSE);
151*05b00f60SXin Li }
152*05b00f60SXin Li if (length_left != 0)
153*05b00f60SXin Li goto invalid;
154*05b00f60SXin Li break;
155*05b00f60SXin Li case RIP6_RESPONSE:
156*05b00f60SXin Li length_left = length;
157*05b00f60SXin Li if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
158*05b00f60SXin Li goto invalid;
159*05b00f60SXin Li length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
160*05b00f60SXin Li j = length_left / sizeof(*ni);
161*05b00f60SXin Li if (j * sizeof(*ni) != length_left)
162*05b00f60SXin Li ND_PRINT(" ripng-resp %u[%u]:", j, length);
163*05b00f60SXin Li else
164*05b00f60SXin Li ND_PRINT(" ripng-resp %u:", j);
165*05b00f60SXin Li for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
166*05b00f60SXin Li length_left -= sizeof(*ni), ++ni) {
167*05b00f60SXin Li if (ndo->ndo_vflag > 1)
168*05b00f60SXin Li ND_PRINT("\n\t");
169*05b00f60SXin Li else
170*05b00f60SXin Li ND_PRINT(" ");
171*05b00f60SXin Li rip6_entry_print(ndo, ni, TRUE);
172*05b00f60SXin Li }
173*05b00f60SXin Li if (length_left != 0)
174*05b00f60SXin Li goto invalid;
175*05b00f60SXin Li break;
176*05b00f60SXin Li default:
177*05b00f60SXin Li ND_PRINT(" ripng-%u ?? %u", cmd, length);
178*05b00f60SXin Li goto invalid;
179*05b00f60SXin Li }
180*05b00f60SXin Li return;
181*05b00f60SXin Li
182*05b00f60SXin Li invalid:
183*05b00f60SXin Li nd_print_invalid(ndo);
184*05b00f60SXin Li }
185