1b0453382SBill Fenner /*
2b0453382SBill Fenner * Copyright (c) 1989, 1990, 1991, 1993, 1994
3b0453382SBill Fenner * The Regents of the University of California. All rights reserved.
4b0453382SBill Fenner *
5b0453382SBill Fenner * Redistribution and use in source and binary forms, with or without
6b0453382SBill Fenner * modification, are permitted provided that: (1) source code distributions
7b0453382SBill Fenner * retain the above copyright notice and this paragraph in its entirety, (2)
8b0453382SBill Fenner * distributions including binary code include the above copyright notice and
9b0453382SBill Fenner * this paragraph in its entirety in the documentation or other materials
10b0453382SBill Fenner * provided with the distribution, and (3) all advertising materials mentioning
11b0453382SBill Fenner * features or use of this software display the following acknowledgement:
12b0453382SBill Fenner * ``This product includes software developed by the University of California,
13b0453382SBill Fenner * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14b0453382SBill Fenner * the University nor the names of its contributors may be used to endorse
15b0453382SBill Fenner * or promote products derived from this software without specific prior
16b0453382SBill Fenner * written permission.
17b0453382SBill Fenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18b0453382SBill Fenner * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19b0453382SBill Fenner * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20b0453382SBill Fenner */
21b0453382SBill Fenner
223340d773SGleb Smirnoff /* \summary: IPv6 Routing Information Protocol (RIPng) printer */
233340d773SGleb Smirnoff
24*ee67461eSJoseph Mingrone /* specification: RFC 2080 */
25*ee67461eSJoseph Mingrone
26*ee67461eSJoseph Mingrone #include <config.h>
27b0453382SBill Fenner
28*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
29b0453382SBill Fenner
303340d773SGleb Smirnoff #include "netdissect.h"
31b0453382SBill Fenner #include "addrtoname.h"
325b0fe478SBruce M Simpson #include "extract.h"
33b0453382SBill Fenner
343c602fabSXin LI /*
353c602fabSXin LI * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project.
363c602fabSXin LI * All rights reserved.
373c602fabSXin LI *
383c602fabSXin LI * Redistribution and use in source and binary forms, with or without
393c602fabSXin LI * modification, are permitted provided that the following conditions
403c602fabSXin LI * are met:
413c602fabSXin LI * 1. Redistributions of source code must retain the above copyright
423c602fabSXin LI * notice, this list of conditions and the following disclaimer.
433c602fabSXin LI * 2. Redistributions in binary form must reproduce the above copyright
443c602fabSXin LI * notice, this list of conditions and the following disclaimer in the
453c602fabSXin LI * documentation and/or other materials provided with the distribution.
463c602fabSXin LI * 3. Neither the name of the project nor the names of its contributors
473c602fabSXin LI * may be used to endorse or promote products derived from this software
483c602fabSXin LI * without specific prior written permission.
493c602fabSXin LI *
503c602fabSXin LI * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
513c602fabSXin LI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
523c602fabSXin LI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
533c602fabSXin LI * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
543c602fabSXin LI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
553c602fabSXin LI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
563c602fabSXin LI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
573c602fabSXin LI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
583c602fabSXin LI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
593c602fabSXin LI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
603c602fabSXin LI * SUCH DAMAGE.
613c602fabSXin LI */
623c602fabSXin LI #define RIP6_VERSION 1
633c602fabSXin LI
643c602fabSXin LI #define RIP6_REQUEST 1
653c602fabSXin LI #define RIP6_RESPONSE 2
663c602fabSXin LI
673c602fabSXin LI struct netinfo6 {
68*ee67461eSJoseph Mingrone nd_ipv6 rip6_dest;
69*ee67461eSJoseph Mingrone nd_uint16_t rip6_tag;
70*ee67461eSJoseph Mingrone nd_uint8_t rip6_plen;
71*ee67461eSJoseph Mingrone nd_uint8_t rip6_metric;
723c602fabSXin LI };
733c602fabSXin LI
743c602fabSXin LI struct rip6 {
75*ee67461eSJoseph Mingrone nd_uint8_t rip6_cmd;
76*ee67461eSJoseph Mingrone nd_uint8_t rip6_vers;
77*ee67461eSJoseph Mingrone nd_byte rip6_res1[2];
78*ee67461eSJoseph Mingrone struct netinfo6 rip6_nets[1];
793c602fabSXin LI };
803c602fabSXin LI
813c602fabSXin LI #define HOPCNT_INFINITY6 16
823c602fabSXin LI
ND_IN6_IS_ADDR_UNSPECIFIED(const nd_ipv6 * addr)83*ee67461eSJoseph Mingrone static int ND_IN6_IS_ADDR_UNSPECIFIED(const nd_ipv6 *addr)
841de50e9fSSam Leffler {
85*ee67461eSJoseph Mingrone static const nd_ipv6 in6addr_any_val = { 0 }; /* :: */
86*ee67461eSJoseph Mingrone return (memcmp(addr, &in6addr_any_val, sizeof(*addr)) == 0);
871de50e9fSSam Leffler }
881de50e9fSSam Leffler
89*ee67461eSJoseph Mingrone static void
rip6_entry_print(netdissect_options * ndo,const struct netinfo6 * ni,const u_int print_metric)90*ee67461eSJoseph Mingrone rip6_entry_print(netdissect_options *ndo,
91*ee67461eSJoseph Mingrone const struct netinfo6 *ni, const u_int print_metric)
92b0453382SBill Fenner {
93*ee67461eSJoseph Mingrone uint16_t tag;
94*ee67461eSJoseph Mingrone uint8_t metric;
95*ee67461eSJoseph Mingrone
96*ee67461eSJoseph Mingrone ND_PRINT("%s/%u", GET_IP6ADDR_STRING(ni->rip6_dest),
97*ee67461eSJoseph Mingrone GET_U_1(ni->rip6_plen));
98*ee67461eSJoseph Mingrone tag = GET_BE_U_2(ni->rip6_tag);
99*ee67461eSJoseph Mingrone if (tag)
100*ee67461eSJoseph Mingrone ND_PRINT(" [%u]", tag);
101*ee67461eSJoseph Mingrone metric = GET_U_1(ni->rip6_metric);
102*ee67461eSJoseph Mingrone if (metric && print_metric)
103*ee67461eSJoseph Mingrone ND_PRINT(" (%u)", metric);
104b0453382SBill Fenner }
105b0453382SBill Fenner
106b0453382SBill Fenner void
ripng_print(netdissect_options * ndo,const u_char * dat,unsigned int length)1073c602fabSXin LI ripng_print(netdissect_options *ndo, const u_char *dat, unsigned int length)
108b0453382SBill Fenner {
109*ee67461eSJoseph Mingrone const struct rip6 *rp = (const struct rip6 *)dat;
110*ee67461eSJoseph Mingrone uint8_t cmd, vers;
111*ee67461eSJoseph Mingrone const struct netinfo6 *ni;
1120bff6a5aSEd Maste unsigned int length_left;
1130bff6a5aSEd Maste u_int j;
114b0453382SBill Fenner
115*ee67461eSJoseph Mingrone ndo->ndo_protocol = "ripng";
116*ee67461eSJoseph Mingrone vers = GET_U_1(rp->rip6_vers);
117*ee67461eSJoseph Mingrone if (vers != RIP6_VERSION) {
118*ee67461eSJoseph Mingrone nd_print_protocol(ndo);
119*ee67461eSJoseph Mingrone ND_PRINT(" [version %u, must be %u]", vers, RIP6_VERSION);
120*ee67461eSJoseph Mingrone goto invalid;
121*ee67461eSJoseph Mingrone }
122*ee67461eSJoseph Mingrone cmd = GET_U_1(rp->rip6_cmd);
123*ee67461eSJoseph Mingrone switch (cmd) {
124b0453382SBill Fenner
125b0453382SBill Fenner case RIP6_REQUEST:
1260bff6a5aSEd Maste length_left = length;
1270bff6a5aSEd Maste if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
128*ee67461eSJoseph Mingrone goto invalid;
1290bff6a5aSEd Maste length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
1300bff6a5aSEd Maste j = length_left / sizeof(*ni);
1310bff6a5aSEd Maste if (j == 1) {
132*ee67461eSJoseph Mingrone if (GET_U_1(rp->rip6_nets->rip6_metric) == HOPCNT_INFINITY6
133*ee67461eSJoseph Mingrone && ND_IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
134*ee67461eSJoseph Mingrone ND_PRINT(" ripng-req dump");
135b0453382SBill Fenner break;
136b0453382SBill Fenner }
1370bff6a5aSEd Maste }
1380bff6a5aSEd Maste if (j * sizeof(*ni) != length_left)
139*ee67461eSJoseph Mingrone ND_PRINT(" ripng-req %u[%u]:", j, length);
140b0453382SBill Fenner else
141*ee67461eSJoseph Mingrone ND_PRINT(" ripng-req %u:", j);
1420bff6a5aSEd Maste for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
1430bff6a5aSEd Maste length_left -= sizeof(*ni), ++ni) {
1443c602fabSXin LI if (ndo->ndo_vflag > 1)
145*ee67461eSJoseph Mingrone ND_PRINT("\n\t");
146b0453382SBill Fenner else
147*ee67461eSJoseph Mingrone ND_PRINT(" ");
148*ee67461eSJoseph Mingrone rip6_entry_print(ndo, ni, FALSE);
149b0453382SBill Fenner }
1500bff6a5aSEd Maste if (length_left != 0)
151*ee67461eSJoseph Mingrone goto invalid;
152b0453382SBill Fenner break;
153b0453382SBill Fenner case RIP6_RESPONSE:
1540bff6a5aSEd Maste length_left = length;
1550bff6a5aSEd Maste if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
156*ee67461eSJoseph Mingrone goto invalid;
1570bff6a5aSEd Maste length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
1580bff6a5aSEd Maste j = length_left / sizeof(*ni);
1590bff6a5aSEd Maste if (j * sizeof(*ni) != length_left)
160*ee67461eSJoseph Mingrone ND_PRINT(" ripng-resp %u[%u]:", j, length);
161b0453382SBill Fenner else
162*ee67461eSJoseph Mingrone ND_PRINT(" ripng-resp %u:", j);
1630bff6a5aSEd Maste for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
1640bff6a5aSEd Maste length_left -= sizeof(*ni), ++ni) {
1653c602fabSXin LI if (ndo->ndo_vflag > 1)
166*ee67461eSJoseph Mingrone ND_PRINT("\n\t");
167b0453382SBill Fenner else
168*ee67461eSJoseph Mingrone ND_PRINT(" ");
169*ee67461eSJoseph Mingrone rip6_entry_print(ndo, ni, TRUE);
170b0453382SBill Fenner }
1710bff6a5aSEd Maste if (length_left != 0)
172*ee67461eSJoseph Mingrone goto invalid;
173b0453382SBill Fenner break;
174b0453382SBill Fenner default:
175*ee67461eSJoseph Mingrone ND_PRINT(" ripng-%u ?? %u", cmd, length);
176*ee67461eSJoseph Mingrone goto invalid;
177b0453382SBill Fenner }
1780bff6a5aSEd Maste return;
1790bff6a5aSEd Maste
180*ee67461eSJoseph Mingrone invalid:
181*ee67461eSJoseph Mingrone nd_print_invalid(ndo);
182b0453382SBill Fenner }
183