blob: 4bc900d105ac6a8a58c6a5eb383d94ebd9ee2135 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (c) 1989, 1990, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
Elliott Hughes892a68b2015-10-19 14:43:53 -070022#define NETDISSECT_REWORKED
The Android Open Source Project2949f582009-03-03 19:30:46 -080023#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#ifdef INET6
28
29#include <tcpdump-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080030
The Android Open Source Project2949f582009-03-03 19:30:46 -080031#include "interface.h"
32#include "addrtoname.h"
33#include "extract.h"
34
Elliott Hughes892a68b2015-10-19 14:43:53 -070035/*
36 * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project.
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. Neither the name of the project nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 */
63#define RIP6_VERSION 1
64
65#define RIP6_REQUEST 1
66#define RIP6_RESPONSE 2
67
68struct netinfo6 {
69 struct in6_addr rip6_dest;
70 uint16_t rip6_tag;
71 uint8_t rip6_plen;
72 uint8_t rip6_metric;
73};
74
75struct rip6 {
76 uint8_t rip6_cmd;
77 uint8_t rip6_vers;
78 uint8_t rip6_res1[2];
79 union {
80 struct netinfo6 ru6_nets[1];
81 char ru6_tracefile[1];
82 } rip6un;
83#define rip6_nets rip6un.ru6_nets
84#define rip6_tracefile rip6un.ru6_tracefile
85};
86
87#define HOPCNT_INFINITY6 16
88
The Android Open Source Project2949f582009-03-03 19:30:46 -080089#if !defined(IN6_IS_ADDR_UNSPECIFIED) && !defined(_MSC_VER) /* MSVC inline */
90static int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *addr)
91{
92 static const struct in6_addr in6addr_any; /* :: */
93 return (memcmp(addr, &in6addr_any, sizeof(*addr)) == 0);
94}
95#endif
96
97static int
Elliott Hughes892a68b2015-10-19 14:43:53 -070098rip6_entry_print(netdissect_options *ndo, register const struct netinfo6 *ni, int metric)
The Android Open Source Project2949f582009-03-03 19:30:46 -080099{
100 int l;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700101 l = ND_PRINT((ndo, "%s/%d", ip6addr_string(ndo, &ni->rip6_dest), ni->rip6_plen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800102 if (ni->rip6_tag)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700103 l += ND_PRINT((ndo, " [%d]", EXTRACT_16BITS(&ni->rip6_tag)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800104 if (metric)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700105 l += ND_PRINT((ndo, " (%d)", ni->rip6_metric));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800106 return l;
107}
108
109void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700110ripng_print(netdissect_options *ndo, const u_char *dat, unsigned int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800111{
112 register const struct rip6 *rp = (struct rip6 *)dat;
113 register const struct netinfo6 *ni;
114 register u_int amt;
115 register u_int i;
116 int j;
117 int trunc;
118
Elliott Hughes892a68b2015-10-19 14:43:53 -0700119 if (ndo->ndo_snapend < dat)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800120 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700121 amt = ndo->ndo_snapend - dat;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800122 i = min(length, amt);
123 if (i < (sizeof(struct rip6) - sizeof(struct netinfo6)))
124 return;
125 i -= (sizeof(struct rip6) - sizeof(struct netinfo6));
126
127 switch (rp->rip6_cmd) {
128
129 case RIP6_REQUEST:
130 j = length / sizeof(*ni);
131 if (j == 1
132 && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6
133 && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700134 ND_PRINT((ndo, " ripng-req dump"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800135 break;
136 }
137 if (j * sizeof(*ni) != length - 4)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700138 ND_PRINT((ndo, " ripng-req %d[%u]:", j, length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800139 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700140 ND_PRINT((ndo, " ripng-req %d:", j));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800141 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
142 for (ni = rp->rip6_nets; i >= sizeof(*ni);
143 i -= sizeof(*ni), ++ni) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700144 if (ndo->ndo_vflag > 1)
145 ND_PRINT((ndo, "\n\t"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800146 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700147 ND_PRINT((ndo, " "));
148 rip6_entry_print(ndo, ni, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800149 }
150 break;
151 case RIP6_RESPONSE:
152 j = length / sizeof(*ni);
153 if (j * sizeof(*ni) != length - 4)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700154 ND_PRINT((ndo, " ripng-resp %d[%u]:", j, length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800155 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700156 ND_PRINT((ndo, " ripng-resp %d:", j));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800157 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
158 for (ni = rp->rip6_nets; i >= sizeof(*ni);
159 i -= sizeof(*ni), ++ni) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700160 if (ndo->ndo_vflag > 1)
161 ND_PRINT((ndo, "\n\t"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800162 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700163 ND_PRINT((ndo, " "));
164 rip6_entry_print(ndo, ni, ni->rip6_metric);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800165 }
166 if (trunc)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700167 ND_PRINT((ndo, "[|ripng]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800168 break;
169 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700170 ND_PRINT((ndo, " ripng-%d ?? %u", rp->rip6_cmd, length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800171 break;
172 }
173 if (rp->rip6_vers != RIP6_VERSION)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700174 ND_PRINT((ndo, " [vers %d]", rp->rip6_vers));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800175}
176#endif /* INET6 */