141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (c) 1989, 1990, 1991, 1993, 1994
341c99275SPeter Avalos * The Regents of the University of California. All rights reserved.
441c99275SPeter Avalos *
541c99275SPeter Avalos * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos * or promote products derived from this software without specific prior
1641c99275SPeter Avalos * written permission.
1741c99275SPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos */
2141c99275SPeter Avalos
22411677aeSAaron LI /* \summary: IPv6 Routing Information Protocol (RIPng) printer */
2341c99275SPeter Avalos
24*ed775ee7SAntonio Huete Jimenez /* specification: RFC 2080 */
25*ed775ee7SAntonio Huete Jimenez
2641c99275SPeter Avalos #ifdef HAVE_CONFIG_H
27*ed775ee7SAntonio Huete Jimenez #include <config.h>
2841c99275SPeter Avalos #endif
2941c99275SPeter Avalos
30*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3141c99275SPeter Avalos
32411677aeSAaron LI #include "netdissect.h"
3341c99275SPeter Avalos #include "addrtoname.h"
3441c99275SPeter Avalos #include "extract.h"
3541c99275SPeter Avalos
36411677aeSAaron LI /*
37411677aeSAaron LI * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project.
38411677aeSAaron LI * All rights reserved.
39411677aeSAaron LI *
40411677aeSAaron LI * Redistribution and use in source and binary forms, with or without
41411677aeSAaron LI * modification, are permitted provided that the following conditions
42411677aeSAaron LI * are met:
43411677aeSAaron LI * 1. Redistributions of source code must retain the above copyright
44411677aeSAaron LI * notice, this list of conditions and the following disclaimer.
45411677aeSAaron LI * 2. Redistributions in binary form must reproduce the above copyright
46411677aeSAaron LI * notice, this list of conditions and the following disclaimer in the
47411677aeSAaron LI * documentation and/or other materials provided with the distribution.
48411677aeSAaron LI * 3. Neither the name of the project nor the names of its contributors
49411677aeSAaron LI * may be used to endorse or promote products derived from this software
50411677aeSAaron LI * without specific prior written permission.
51411677aeSAaron LI *
52411677aeSAaron LI * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
53411677aeSAaron LI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54411677aeSAaron LI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55411677aeSAaron LI * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
56411677aeSAaron LI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57411677aeSAaron LI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58411677aeSAaron LI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59411677aeSAaron LI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60411677aeSAaron LI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61411677aeSAaron LI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62411677aeSAaron LI * SUCH DAMAGE.
63411677aeSAaron LI */
64411677aeSAaron LI #define RIP6_VERSION 1
65411677aeSAaron LI
66411677aeSAaron LI #define RIP6_REQUEST 1
67411677aeSAaron LI #define RIP6_RESPONSE 2
68411677aeSAaron LI
69411677aeSAaron LI struct netinfo6 {
70*ed775ee7SAntonio Huete Jimenez nd_ipv6 rip6_dest;
71*ed775ee7SAntonio Huete Jimenez nd_uint16_t rip6_tag;
72*ed775ee7SAntonio Huete Jimenez nd_uint8_t rip6_plen;
73*ed775ee7SAntonio Huete Jimenez nd_uint8_t rip6_metric;
74411677aeSAaron LI };
75411677aeSAaron LI
76411677aeSAaron LI struct rip6 {
77*ed775ee7SAntonio Huete Jimenez nd_uint8_t rip6_cmd;
78*ed775ee7SAntonio Huete Jimenez nd_uint8_t rip6_vers;
79*ed775ee7SAntonio Huete Jimenez nd_byte rip6_res1[2];
80*ed775ee7SAntonio Huete Jimenez struct netinfo6 rip6_nets[1];
81411677aeSAaron LI };
82411677aeSAaron LI
83411677aeSAaron LI #define HOPCNT_INFINITY6 16
84411677aeSAaron LI
ND_IN6_IS_ADDR_UNSPECIFIED(const nd_ipv6 * addr)85*ed775ee7SAntonio Huete Jimenez static int ND_IN6_IS_ADDR_UNSPECIFIED(const nd_ipv6 *addr)
8641c99275SPeter Avalos {
87*ed775ee7SAntonio Huete Jimenez static const nd_ipv6 in6addr_any_val = { 0 }; /* :: */
88*ed775ee7SAntonio Huete Jimenez return (memcmp(addr, &in6addr_any_val, sizeof(*addr)) == 0);
8941c99275SPeter Avalos }
9041c99275SPeter Avalos
91*ed775ee7SAntonio Huete Jimenez static void
rip6_entry_print(netdissect_options * ndo,const struct netinfo6 * ni,const u_int print_metric)92*ed775ee7SAntonio Huete Jimenez rip6_entry_print(netdissect_options *ndo,
93*ed775ee7SAntonio Huete Jimenez const struct netinfo6 *ni, const u_int print_metric)
9441c99275SPeter Avalos {
95*ed775ee7SAntonio Huete Jimenez uint16_t tag;
96*ed775ee7SAntonio Huete Jimenez uint8_t metric;
97*ed775ee7SAntonio Huete Jimenez
98*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s/%u", GET_IP6ADDR_STRING(ni->rip6_dest),
99*ed775ee7SAntonio Huete Jimenez GET_U_1(ni->rip6_plen));
100*ed775ee7SAntonio Huete Jimenez tag = GET_BE_U_2(ni->rip6_tag);
101*ed775ee7SAntonio Huete Jimenez if (tag)
102*ed775ee7SAntonio Huete Jimenez ND_PRINT(" [%u]", tag);
103*ed775ee7SAntonio Huete Jimenez metric = GET_U_1(ni->rip6_metric);
104*ed775ee7SAntonio Huete Jimenez if (metric && print_metric)
105*ed775ee7SAntonio Huete Jimenez ND_PRINT(" (%u)", metric);
10641c99275SPeter Avalos }
10741c99275SPeter Avalos
10841c99275SPeter Avalos void
ripng_print(netdissect_options * ndo,const u_char * dat,unsigned int length)109411677aeSAaron LI ripng_print(netdissect_options *ndo, const u_char *dat, unsigned int length)
11041c99275SPeter Avalos {
111*ed775ee7SAntonio Huete Jimenez const struct rip6 *rp = (const struct rip6 *)dat;
112*ed775ee7SAntonio Huete Jimenez uint8_t cmd, vers;
113*ed775ee7SAntonio Huete Jimenez const struct netinfo6 *ni;
114411677aeSAaron LI unsigned int length_left;
115411677aeSAaron LI u_int j;
11641c99275SPeter Avalos
117*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "ripng";
118*ed775ee7SAntonio Huete Jimenez vers = GET_U_1(rp->rip6_vers);
119*ed775ee7SAntonio Huete Jimenez if (vers != RIP6_VERSION) {
120*ed775ee7SAntonio Huete Jimenez ND_PRINT(" [vers %u]", vers);
121*ed775ee7SAntonio Huete Jimenez goto invalid;
122*ed775ee7SAntonio Huete Jimenez }
123*ed775ee7SAntonio Huete Jimenez cmd = GET_U_1(rp->rip6_cmd);
124*ed775ee7SAntonio Huete Jimenez switch (cmd) {
12541c99275SPeter Avalos
12641c99275SPeter Avalos case RIP6_REQUEST:
127411677aeSAaron LI length_left = length;
128411677aeSAaron LI if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
129*ed775ee7SAntonio Huete Jimenez goto invalid;
130411677aeSAaron LI length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
131411677aeSAaron LI j = length_left / sizeof(*ni);
132411677aeSAaron LI if (j == 1) {
133*ed775ee7SAntonio Huete Jimenez if (GET_U_1(rp->rip6_nets->rip6_metric) == HOPCNT_INFINITY6
134*ed775ee7SAntonio Huete Jimenez && ND_IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
135*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ripng-req dump");
13641c99275SPeter Avalos break;
13741c99275SPeter Avalos }
13841c99275SPeter Avalos }
139411677aeSAaron LI if (j * sizeof(*ni) != length_left)
140*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ripng-req %u[%u]:", j, length);
141411677aeSAaron LI else
142*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ripng-req %u:", j);
143411677aeSAaron LI for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
144411677aeSAaron LI length_left -= sizeof(*ni), ++ni) {
145411677aeSAaron LI if (ndo->ndo_vflag > 1)
146*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\t");
147411677aeSAaron LI else
148*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ");
149*ed775ee7SAntonio Huete Jimenez rip6_entry_print(ndo, ni, FALSE);
150411677aeSAaron LI }
151411677aeSAaron LI if (length_left != 0)
152*ed775ee7SAntonio Huete Jimenez goto invalid;
15341c99275SPeter Avalos break;
15441c99275SPeter Avalos case RIP6_RESPONSE:
155411677aeSAaron LI length_left = length;
156411677aeSAaron LI if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
157*ed775ee7SAntonio Huete Jimenez goto invalid;
158411677aeSAaron LI length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
159411677aeSAaron LI j = length_left / sizeof(*ni);
160411677aeSAaron LI if (j * sizeof(*ni) != length_left)
161*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ripng-resp %u[%u]:", j, length);
16241c99275SPeter Avalos else
163*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ripng-resp %u:", j);
164411677aeSAaron LI for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
165411677aeSAaron LI length_left -= sizeof(*ni), ++ni) {
166411677aeSAaron LI if (ndo->ndo_vflag > 1)
167*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\t");
16841c99275SPeter Avalos else
169*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ");
170*ed775ee7SAntonio Huete Jimenez rip6_entry_print(ndo, ni, TRUE);
17141c99275SPeter Avalos }
172411677aeSAaron LI if (length_left != 0)
173*ed775ee7SAntonio Huete Jimenez goto invalid;
17441c99275SPeter Avalos break;
17541c99275SPeter Avalos default:
176*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ripng-%u ?? %u", cmd, length);
177*ed775ee7SAntonio Huete Jimenez goto invalid;
17841c99275SPeter Avalos }
179411677aeSAaron LI return;
180411677aeSAaron LI
181*ed775ee7SAntonio Huete Jimenez invalid:
182*ed775ee7SAntonio Huete Jimenez nd_print_invalid(ndo);
18341c99275SPeter Avalos }
184