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