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