ip6_mroute.c revision 1.8 1 1.8 itojun /* $NetBSD: ip6_mroute.c,v 1.8 1999/12/13 15:17:22 itojun Exp $ */
2 1.3 thorpej
3 1.2 itojun /*
4 1.2 itojun * Copyright (C) 1998 WIDE Project.
5 1.2 itojun * All rights reserved.
6 1.2 itojun *
7 1.2 itojun * Redistribution and use in source and binary forms, with or without
8 1.2 itojun * modification, are permitted provided that the following conditions
9 1.2 itojun * are met:
10 1.2 itojun * 1. Redistributions of source code must retain the above copyright
11 1.2 itojun * notice, this list of conditions and the following disclaimer.
12 1.2 itojun * 2. Redistributions in binary form must reproduce the above copyright
13 1.2 itojun * notice, this list of conditions and the following disclaimer in the
14 1.2 itojun * documentation and/or other materials provided with the distribution.
15 1.2 itojun * 3. Neither the name of the project nor the names of its contributors
16 1.2 itojun * may be used to endorse or promote products derived from this software
17 1.2 itojun * without specific prior written permission.
18 1.2 itojun *
19 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2 itojun * SUCH DAMAGE.
30 1.2 itojun */
31 1.2 itojun
32 1.2 itojun /* BSDI ip_mroute.c,v 2.10 1996/11/14 00:29:52 jch Exp */
33 1.2 itojun
34 1.2 itojun /*
35 1.2 itojun * IP multicast forwarding procedures
36 1.2 itojun *
37 1.2 itojun * Written by David Waitzman, BBN Labs, August 1988.
38 1.2 itojun * Modified by Steve Deering, Stanford, February 1989.
39 1.2 itojun * Modified by Mark J. Steiglitz, Stanford, May, 1991
40 1.2 itojun * Modified by Van Jacobson, LBL, January 1993
41 1.2 itojun * Modified by Ajit Thyagarajan, PARC, August 1993
42 1.2 itojun * Modified by Bill Fenenr, PARC, April 1994
43 1.2 itojun *
44 1.2 itojun * MROUTING Revision: 3.5.1.2 + PIM-SMv2 (pimd) Support
45 1.2 itojun */
46 1.2 itojun
47 1.2 itojun #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
48 1.2 itojun #include "opt_inet.h"
49 1.2 itojun #endif
50 1.2 itojun
51 1.8 itojun #ifndef _KERNEL
52 1.8 itojun # ifdef KERNEL
53 1.8 itojun # define _KERNEL
54 1.8 itojun # endif
55 1.8 itojun #endif
56 1.8 itojun
57 1.2 itojun #include <sys/param.h>
58 1.2 itojun #include <sys/systm.h>
59 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
60 1.8 itojun #include <sys/malloc.h>
61 1.8 itojun #endif
62 1.2 itojun #include <sys/mbuf.h>
63 1.2 itojun #include <sys/socket.h>
64 1.2 itojun #include <sys/socketvar.h>
65 1.2 itojun #include <sys/sockio.h>
66 1.2 itojun #include <sys/protosw.h>
67 1.2 itojun #include <sys/errno.h>
68 1.2 itojun #include <sys/time.h>
69 1.2 itojun #include <sys/kernel.h>
70 1.8 itojun #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
71 1.2 itojun #include <sys/ioctl.h>
72 1.2 itojun #endif
73 1.2 itojun #include <sys/syslog.h>
74 1.2 itojun
75 1.2 itojun #include <net/if.h>
76 1.2 itojun #include <net/route.h>
77 1.2 itojun #include <net/raw_cb.h>
78 1.2 itojun
79 1.2 itojun #include <netinet/in.h>
80 1.2 itojun #include <netinet/in_var.h>
81 1.2 itojun
82 1.2 itojun #include <netinet6/ip6.h>
83 1.2 itojun #include <netinet6/ip6_var.h>
84 1.2 itojun #include <netinet6/ip6_mroute.h>
85 1.2 itojun #include <netinet6/pim6.h>
86 1.2 itojun #include <netinet6/pim6_var.h>
87 1.2 itojun
88 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
89 1.8 itojun static MALLOC_DEFINE(M_MRTABLE, "mf6c", "multicast forwarding cache entry");
90 1.8 itojun #endif
91 1.8 itojun
92 1.2 itojun #define M_HASCL(m) ((m)->m_flags & M_EXT)
93 1.2 itojun
94 1.2 itojun static int ip6_mdq __P((struct mbuf *, struct ifnet *, struct mf6c *));
95 1.2 itojun static void phyint_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *));
96 1.2 itojun
97 1.2 itojun static int set_pim6 __P((int *));
98 1.8 itojun #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
99 1.2 itojun static int get_pim6 __P((struct mbuf *));
100 1.8 itojun #endif
101 1.2 itojun static int socket_send __P((struct socket *, struct mbuf *,
102 1.2 itojun struct sockaddr_in6 *));
103 1.2 itojun static int register_send __P((struct ip6_hdr *, struct mif6 *,
104 1.2 itojun struct mbuf *));
105 1.2 itojun
106 1.2 itojun /*
107 1.2 itojun * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
108 1.2 itojun * except for netstat or debugging purposes.
109 1.2 itojun */
110 1.2 itojun struct socket *ip6_mrouter = NULL;
111 1.2 itojun int ip6_mrtproto = IPPROTO_PIM; /* for netstat only */
112 1.2 itojun struct mrt6stat mrt6stat;
113 1.2 itojun
114 1.2 itojun #define NO_RTE_FOUND 0x1
115 1.2 itojun #define RTE_FOUND 0x2
116 1.2 itojun
117 1.2 itojun struct mf6c *mf6ctable[MF6CTBLSIZ];
118 1.2 itojun u_char nexpire[MF6CTBLSIZ];
119 1.2 itojun static struct mif6 mif6table[MAXMIFS];
120 1.2 itojun #ifdef MRT6DEBUG
121 1.2 itojun u_int mrt6debug = 0; /* debug level */
122 1.2 itojun #define DEBUG_MFC 0x02
123 1.2 itojun #define DEBUG_FORWARD 0x04
124 1.2 itojun #define DEBUG_EXPIRE 0x08
125 1.2 itojun #define DEBUG_XMIT 0x10
126 1.2 itojun #define DEBUG_REG 0x20
127 1.2 itojun #define DEBUG_PIM 0x40
128 1.2 itojun #endif
129 1.2 itojun
130 1.2 itojun static void expire_upcalls __P((void *));
131 1.2 itojun #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
132 1.2 itojun #define UPCALL_EXPIRE 6 /* number of timeouts */
133 1.2 itojun
134 1.2 itojun #ifdef INET
135 1.2 itojun #ifdef MROUTING
136 1.2 itojun extern struct socket *ip_mrouter;
137 1.2 itojun #endif
138 1.2 itojun #endif
139 1.2 itojun
140 1.2 itojun /*
141 1.2 itojun * 'Interfaces' associated with decapsulator (so we can tell
142 1.2 itojun * packets that went through it from ones that get reflected
143 1.2 itojun * by a broken gateway). These interfaces are never linked into
144 1.2 itojun * the system ifnet list & no routes point to them. I.e., packets
145 1.2 itojun * can't be sent this way. They only exist as a placeholder for
146 1.2 itojun * multicast source verification.
147 1.2 itojun */
148 1.2 itojun struct ifnet multicast_register_if;
149 1.2 itojun
150 1.2 itojun #define ENCAP_HOPS 64
151 1.2 itojun
152 1.2 itojun /*
153 1.2 itojun * Private variables.
154 1.2 itojun */
155 1.2 itojun static mifi_t nummifs = 0;
156 1.2 itojun static mifi_t reg_mif_num = (mifi_t)-1;
157 1.2 itojun
158 1.2 itojun static struct pim6stat pim6stat;
159 1.2 itojun
160 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
161 1.8 itojun static struct callout_handle expire_upcalls_ch;
162 1.8 itojun #endif
163 1.8 itojun
164 1.2 itojun /*
165 1.2 itojun * one-back cache used by ipip_input to locate a tunnel's mif
166 1.2 itojun * given a datagram's src ip address.
167 1.2 itojun */
168 1.2 itojun static int pim6;
169 1.2 itojun
170 1.2 itojun /*
171 1.2 itojun * Hash function for a source, group entry
172 1.2 itojun */
173 1.2 itojun #define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
174 1.2 itojun (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
175 1.2 itojun (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \
176 1.2 itojun (g).s6_addr32[2] ^ (g).s6_addr32[3])
177 1.2 itojun
178 1.2 itojun /*
179 1.2 itojun * Find a route for a given origin IPv6 address and Multicast group address.
180 1.2 itojun * Quality of service parameter to be added in the future!!!
181 1.2 itojun */
182 1.2 itojun
183 1.2 itojun #define MF6CFIND(o, g, rt) { \
184 1.2 itojun register struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
185 1.2 itojun rt = NULL; \
186 1.2 itojun mrt6stat.mrt6s_mfc_lookups++; \
187 1.2 itojun while (_rt) { \
188 1.2 itojun if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
189 1.2 itojun IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
190 1.2 itojun (_rt->mf6c_stall == NULL)) { \
191 1.2 itojun rt = _rt; \
192 1.2 itojun break; \
193 1.2 itojun } \
194 1.2 itojun _rt = _rt->mf6c_next; \
195 1.2 itojun } \
196 1.2 itojun if (rt == NULL) { \
197 1.2 itojun mrt6stat.mrt6s_mfc_misses++; \
198 1.2 itojun } \
199 1.2 itojun }
200 1.2 itojun
201 1.2 itojun /*
202 1.2 itojun * Macros to compute elapsed time efficiently
203 1.2 itojun * Borrowed from Van Jacobson's scheduling code
204 1.2 itojun */
205 1.2 itojun #define TV_DELTA(a, b, delta) { \
206 1.2 itojun register int xxs; \
207 1.2 itojun \
208 1.2 itojun delta = (a).tv_usec - (b).tv_usec; \
209 1.2 itojun if ((xxs = (a).tv_sec - (b).tv_sec)) { \
210 1.2 itojun switch (xxs) { \
211 1.2 itojun case 2: \
212 1.2 itojun delta += 1000000; \
213 1.2 itojun /* fall through */ \
214 1.2 itojun case 1: \
215 1.2 itojun delta += 1000000; \
216 1.2 itojun break; \
217 1.2 itojun default: \
218 1.2 itojun delta += (1000000 * xxs); \
219 1.2 itojun } \
220 1.2 itojun } \
221 1.2 itojun }
222 1.2 itojun
223 1.2 itojun #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
224 1.2 itojun (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
225 1.2 itojun
226 1.2 itojun #ifdef UPCALL_TIMING
227 1.7 itojun #define UPCALL_MAX 50
228 1.7 itojun u_long upcall_data[UPCALL_MAX + 1];
229 1.2 itojun static void collate();
230 1.2 itojun #endif /* UPCALL_TIMING */
231 1.2 itojun
232 1.2 itojun static int get_sg_cnt __P((struct sioc_sg_req6 *));
233 1.2 itojun static int get_mif6_cnt __P((struct sioc_mif_req6 *));
234 1.2 itojun static int ip6_mrouter_init __P((struct socket *, struct mbuf *));
235 1.2 itojun static int add_m6if __P((struct mif6ctl *));
236 1.2 itojun static int del_m6if __P((mifi_t *));
237 1.2 itojun static int add_m6fc __P((struct mf6cctl *));
238 1.2 itojun static int del_m6fc __P((struct mf6cctl *));
239 1.2 itojun
240 1.2 itojun /*
241 1.2 itojun * Handle MRT setsockopt commands to modify the multicast routing tables.
242 1.2 itojun */
243 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
244 1.8 itojun int
245 1.8 itojun ip6_mrouter_set(so, sopt)
246 1.8 itojun struct socket *so;
247 1.8 itojun struct sockopt *sopt;
248 1.8 itojun {
249 1.8 itojun int error = 0;
250 1.8 itojun struct mbuf *m;
251 1.8 itojun
252 1.8 itojun if (so != ip6_mrouter && sopt->sopt_name != MRT6_INIT)
253 1.8 itojun return (EACCES);
254 1.8 itojun
255 1.8 itojun if (error = soopt_getm(sopt, &m)) /* XXX */
256 1.8 itojun return (error);
257 1.8 itojun if (error = soopt_mcopyin(sopt, m)) /* XXX */
258 1.8 itojun return (error);
259 1.8 itojun
260 1.8 itojun switch (sopt->sopt_name) {
261 1.8 itojun case MRT6_INIT:
262 1.8 itojun error = ip6_mrouter_init(so, m);
263 1.8 itojun break;
264 1.8 itojun case MRT6_DONE:
265 1.8 itojun error = ip6_mrouter_done();
266 1.8 itojun break;
267 1.8 itojun case MRT6_ADD_MIF:
268 1.8 itojun error = add_m6if(mtod(m, struct mif6ctl *));
269 1.8 itojun break;
270 1.8 itojun case MRT6_DEL_MIF:
271 1.8 itojun error = del_m6if(mtod(m, mifi_t *));
272 1.8 itojun break;
273 1.8 itojun case MRT6_ADD_MFC:
274 1.8 itojun error = add_m6fc(mtod(m, struct mf6cctl *));
275 1.8 itojun break;
276 1.8 itojun case MRT6_DEL_MFC:
277 1.8 itojun error = del_m6fc(mtod(m, struct mf6cctl *));
278 1.8 itojun break;
279 1.8 itojun case MRT6_PIM:
280 1.8 itojun error = set_pim6(mtod(m, int *));
281 1.8 itojun break;
282 1.8 itojun default:
283 1.8 itojun error = EOPNOTSUPP;
284 1.8 itojun break;
285 1.8 itojun }
286 1.8 itojun
287 1.8 itojun (void)m_freem(m);
288 1.8 itojun return(error);
289 1.8 itojun }
290 1.8 itojun #else
291 1.2 itojun int
292 1.2 itojun ip6_mrouter_set(cmd, so, m)
293 1.2 itojun int cmd;
294 1.2 itojun struct socket *so;
295 1.2 itojun struct mbuf *m;
296 1.2 itojun {
297 1.2 itojun if (cmd != MRT6_INIT && so != ip6_mrouter)
298 1.2 itojun return EACCES;
299 1.2 itojun
300 1.2 itojun switch (cmd) {
301 1.2 itojun case MRT6_INIT: return ip6_mrouter_init(so, m);
302 1.2 itojun case MRT6_DONE: return ip6_mrouter_done();
303 1.2 itojun case MRT6_ADD_MIF: return add_m6if(mtod(m, struct mif6ctl *));
304 1.2 itojun case MRT6_DEL_MIF: return del_m6if(mtod(m, mifi_t *));
305 1.2 itojun case MRT6_ADD_MFC: return add_m6fc(mtod(m, struct mf6cctl *));
306 1.2 itojun case MRT6_DEL_MFC: return del_m6fc(mtod(m, struct mf6cctl *));
307 1.2 itojun case MRT6_PIM: return set_pim6(mtod(m, int *));
308 1.2 itojun default: return EOPNOTSUPP;
309 1.2 itojun }
310 1.2 itojun }
311 1.8 itojun #endif
312 1.2 itojun
313 1.2 itojun /*
314 1.2 itojun * Handle MRT getsockopt commands
315 1.2 itojun */
316 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
317 1.8 itojun int
318 1.8 itojun ip6_mrouter_get(so, sopt)
319 1.8 itojun struct socket *so;
320 1.8 itojun struct sockopt *sopt;
321 1.8 itojun {
322 1.8 itojun int error = 0;
323 1.8 itojun
324 1.8 itojun if (so != ip6_mrouter) return EACCES;
325 1.8 itojun
326 1.8 itojun switch (sopt->sopt_name) {
327 1.8 itojun case MRT6_PIM:
328 1.8 itojun error = sooptcopyout(sopt, &pim6, sizeof(pim6));
329 1.8 itojun break;
330 1.8 itojun }
331 1.8 itojun return (error);
332 1.8 itojun }
333 1.8 itojun #else
334 1.2 itojun int
335 1.2 itojun ip6_mrouter_get(cmd, so, m)
336 1.2 itojun int cmd;
337 1.2 itojun struct socket *so;
338 1.2 itojun struct mbuf **m;
339 1.2 itojun {
340 1.2 itojun struct mbuf *mb;
341 1.2 itojun
342 1.2 itojun if (so != ip6_mrouter) return EACCES;
343 1.2 itojun
344 1.2 itojun *m = mb = m_get(M_WAIT, MT_SOOPTS);
345 1.2 itojun
346 1.2 itojun switch (cmd) {
347 1.2 itojun case MRT6_PIM: return get_pim6(mb);
348 1.2 itojun default:
349 1.2 itojun m_free(mb);
350 1.2 itojun return EOPNOTSUPP;
351 1.2 itojun }
352 1.2 itojun }
353 1.8 itojun #endif
354 1.2 itojun
355 1.2 itojun /*
356 1.2 itojun * Handle ioctl commands to obtain information from the cache
357 1.2 itojun */
358 1.2 itojun int
359 1.2 itojun mrt6_ioctl(cmd, data)
360 1.2 itojun int cmd;
361 1.2 itojun caddr_t data;
362 1.2 itojun {
363 1.2 itojun int error = 0;
364 1.2 itojun
365 1.2 itojun switch (cmd) {
366 1.2 itojun case SIOCGETSGCNT_IN6:
367 1.2 itojun return(get_sg_cnt((struct sioc_sg_req6 *)data));
368 1.2 itojun break; /* for safety */
369 1.2 itojun case SIOCGETMIFCNT_IN6:
370 1.2 itojun return(get_mif6_cnt((struct sioc_mif_req6 *)data));
371 1.2 itojun break; /* for safety */
372 1.2 itojun default:
373 1.2 itojun return (EINVAL);
374 1.2 itojun break;
375 1.2 itojun }
376 1.2 itojun return error;
377 1.2 itojun }
378 1.2 itojun
379 1.2 itojun /*
380 1.2 itojun * returns the packet, byte, rpf-failure count for the source group provided
381 1.2 itojun */
382 1.2 itojun static int
383 1.2 itojun get_sg_cnt(req)
384 1.2 itojun register struct sioc_sg_req6 *req;
385 1.2 itojun {
386 1.2 itojun register struct mf6c *rt;
387 1.2 itojun int s;
388 1.2 itojun
389 1.8 itojun #ifdef __NetBSD__
390 1.4 itojun s = splsoftnet();
391 1.8 itojun #else
392 1.8 itojun s = splnet();
393 1.8 itojun #endif
394 1.2 itojun MF6CFIND(req->src.sin6_addr, req->grp.sin6_addr, rt);
395 1.2 itojun splx(s);
396 1.2 itojun if (rt != NULL) {
397 1.2 itojun req->pktcnt = rt->mf6c_pkt_cnt;
398 1.2 itojun req->bytecnt = rt->mf6c_byte_cnt;
399 1.2 itojun req->wrong_if = rt->mf6c_wrong_if;
400 1.2 itojun } else
401 1.2 itojun return(ESRCH);
402 1.2 itojun #if 0
403 1.2 itojun req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
404 1.2 itojun #endif
405 1.2 itojun
406 1.2 itojun return 0;
407 1.2 itojun }
408 1.2 itojun
409 1.2 itojun /*
410 1.2 itojun * returns the input and output packet and byte counts on the mif provided
411 1.2 itojun */
412 1.2 itojun static int
413 1.2 itojun get_mif6_cnt(req)
414 1.2 itojun register struct sioc_mif_req6 *req;
415 1.2 itojun {
416 1.2 itojun register mifi_t mifi = req->mifi;
417 1.2 itojun
418 1.2 itojun if (mifi >= nummifs)
419 1.2 itojun return EINVAL;
420 1.2 itojun
421 1.2 itojun req->icount = mif6table[mifi].m6_pkt_in;
422 1.2 itojun req->ocount = mif6table[mifi].m6_pkt_out;
423 1.2 itojun req->ibytes = mif6table[mifi].m6_bytes_in;
424 1.2 itojun req->obytes = mif6table[mifi].m6_bytes_out;
425 1.2 itojun
426 1.2 itojun return 0;
427 1.2 itojun }
428 1.2 itojun
429 1.8 itojun #if !(defined(__FreeBSD__) && __FreeBSD__ >=3)
430 1.2 itojun /*
431 1.2 itojun * Get PIM processiong global
432 1.2 itojun */
433 1.2 itojun static int
434 1.2 itojun get_pim6(m)
435 1.2 itojun struct mbuf *m;
436 1.2 itojun {
437 1.2 itojun int *i;
438 1.2 itojun
439 1.2 itojun i = mtod(m, int *);
440 1.2 itojun
441 1.2 itojun *i = pim6;
442 1.2 itojun
443 1.2 itojun return 0;
444 1.2 itojun }
445 1.8 itojun #endif
446 1.2 itojun
447 1.2 itojun static int
448 1.2 itojun set_pim6(i)
449 1.2 itojun int *i;
450 1.2 itojun {
451 1.2 itojun if ((*i != 1) && (*i != 0))
452 1.2 itojun return EINVAL;
453 1.2 itojun
454 1.2 itojun pim6 = *i;
455 1.2 itojun
456 1.2 itojun return 0;
457 1.2 itojun }
458 1.2 itojun
459 1.2 itojun /*
460 1.2 itojun * Enable multicast routing
461 1.2 itojun */
462 1.2 itojun static int
463 1.2 itojun ip6_mrouter_init(so, m)
464 1.2 itojun struct socket *so;
465 1.2 itojun struct mbuf *m;
466 1.2 itojun {
467 1.2 itojun int *v;
468 1.2 itojun
469 1.2 itojun #ifdef MRT6DEBUG
470 1.2 itojun if (mrt6debug)
471 1.2 itojun log(LOG_DEBUG,
472 1.2 itojun "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n",
473 1.2 itojun so->so_type, so->so_proto->pr_protocol);
474 1.2 itojun #endif
475 1.2 itojun
476 1.2 itojun if (so->so_type != SOCK_RAW ||
477 1.2 itojun so->so_proto->pr_protocol != IPPROTO_ICMPV6)
478 1.2 itojun return EOPNOTSUPP;
479 1.2 itojun
480 1.2 itojun if (!m || (m->m_len != sizeof(int *)))
481 1.2 itojun return ENOPROTOOPT;
482 1.2 itojun
483 1.2 itojun v = mtod(m, int *);
484 1.2 itojun if (*v != 1)
485 1.2 itojun return ENOPROTOOPT;
486 1.2 itojun
487 1.2 itojun if (ip6_mrouter != NULL) return EADDRINUSE;
488 1.2 itojun
489 1.2 itojun ip6_mrouter = so;
490 1.2 itojun
491 1.2 itojun bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
492 1.2 itojun bzero((caddr_t)nexpire, sizeof(nexpire));
493 1.2 itojun
494 1.2 itojun pim6 = 0;/* used for stubbing out/in pim stuff */
495 1.2 itojun
496 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
497 1.8 itojun expire_upcalls_ch =
498 1.8 itojun #endif
499 1.2 itojun timeout(expire_upcalls, (caddr_t)NULL, EXPIRE_TIMEOUT);
500 1.2 itojun
501 1.2 itojun #ifdef MRT6DEBUG
502 1.2 itojun if (mrt6debug)
503 1.2 itojun log(LOG_DEBUG, "ip6_mrouter_init\n");
504 1.2 itojun #endif
505 1.2 itojun
506 1.2 itojun return 0;
507 1.2 itojun }
508 1.2 itojun
509 1.2 itojun /*
510 1.2 itojun * Disable multicast routing
511 1.2 itojun */
512 1.2 itojun int
513 1.2 itojun ip6_mrouter_done()
514 1.2 itojun {
515 1.2 itojun mifi_t mifi;
516 1.2 itojun int i;
517 1.2 itojun struct ifnet *ifp;
518 1.2 itojun struct in6_ifreq ifr;
519 1.2 itojun struct mf6c *rt;
520 1.2 itojun struct rtdetq *rte;
521 1.2 itojun int s;
522 1.2 itojun
523 1.8 itojun #ifdef __NetBSD__
524 1.4 itojun s = splsoftnet();
525 1.8 itojun #else
526 1.8 itojun s = splnet();
527 1.8 itojun #endif
528 1.2 itojun
529 1.2 itojun /*
530 1.2 itojun * For each phyint in use, disable promiscuous reception of all IPv6
531 1.2 itojun * multicasts.
532 1.2 itojun */
533 1.2 itojun #ifdef INET
534 1.2 itojun #ifdef MROUTING
535 1.2 itojun /*
536 1.2 itojun * If there is still IPv4 multicast routing daemon,
537 1.2 itojun * we remain interfaces to receive all muliticasted packets.
538 1.2 itojun * XXX: there may be an interface in which the IPv4 multicast
539 1.2 itojun * daemon is not interested...
540 1.2 itojun */
541 1.2 itojun if (!ip_mrouter)
542 1.2 itojun #endif
543 1.2 itojun #endif
544 1.2 itojun {
545 1.2 itojun for (mifi = 0; mifi < nummifs; mifi++) {
546 1.2 itojun if (mif6table[mifi].m6_ifp &&
547 1.2 itojun !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
548 1.2 itojun ifr.ifr_addr.sin6_family = AF_INET6;
549 1.2 itojun ifr.ifr_addr.sin6_addr= in6addr_any;
550 1.2 itojun ifp = mif6table[mifi].m6_ifp;
551 1.2 itojun (*ifp->if_ioctl)(ifp, SIOCDELMULTI,
552 1.2 itojun (caddr_t)&ifr);
553 1.2 itojun }
554 1.2 itojun }
555 1.2 itojun }
556 1.2 itojun #ifdef notyet
557 1.2 itojun bzero((caddr_t)qtable, sizeof(qtable));
558 1.2 itojun bzero((caddr_t)tbftable, sizeof(tbftable));
559 1.2 itojun #endif
560 1.2 itojun bzero((caddr_t)mif6table, sizeof(mif6table));
561 1.2 itojun nummifs = 0;
562 1.2 itojun
563 1.2 itojun pim6 = 0; /* used to stub out/in pim specific code */
564 1.2 itojun
565 1.8 itojun untimeout(expire_upcalls, (caddr_t)NULL
566 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
567 1.8 itojun , expire_upcalls_ch
568 1.8 itojun #endif
569 1.8 itojun );
570 1.2 itojun
571 1.2 itojun /*
572 1.2 itojun * Free all multicast forwarding cache entries.
573 1.2 itojun */
574 1.2 itojun for (i = 0; i < MF6CTBLSIZ; i++) {
575 1.2 itojun rt = mf6ctable[i];
576 1.2 itojun while (rt) {
577 1.2 itojun struct mf6c *frt;
578 1.2 itojun
579 1.2 itojun for (rte = rt->mf6c_stall; rte != NULL; ) {
580 1.2 itojun struct rtdetq *n = rte->next;
581 1.2 itojun
582 1.2 itojun m_free(rte->m);
583 1.2 itojun free(rte, M_MRTABLE);
584 1.2 itojun rte = n;
585 1.2 itojun }
586 1.2 itojun frt = rt;
587 1.2 itojun rt = rt->mf6c_next;
588 1.2 itojun free(frt, M_MRTABLE);
589 1.2 itojun }
590 1.2 itojun }
591 1.2 itojun
592 1.2 itojun bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
593 1.2 itojun
594 1.2 itojun /*
595 1.2 itojun * Reset de-encapsulation cache
596 1.2 itojun */
597 1.2 itojun reg_mif_num = -1;
598 1.2 itojun
599 1.2 itojun ip6_mrouter = NULL;
600 1.2 itojun
601 1.2 itojun splx(s);
602 1.2 itojun
603 1.2 itojun #ifdef MRT6DEBUG
604 1.2 itojun if (mrt6debug)
605 1.2 itojun log(LOG_DEBUG, "ip6_mrouter_done\n");
606 1.2 itojun #endif
607 1.2 itojun
608 1.2 itojun return 0;
609 1.2 itojun }
610 1.2 itojun
611 1.2 itojun static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
612 1.2 itojun
613 1.2 itojun /*
614 1.2 itojun * Add a mif to the mif table
615 1.2 itojun */
616 1.2 itojun static int
617 1.2 itojun add_m6if(mifcp)
618 1.2 itojun register struct mif6ctl *mifcp;
619 1.2 itojun {
620 1.2 itojun register struct mif6 *mifp;
621 1.2 itojun struct ifnet *ifp;
622 1.8 itojun #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
623 1.2 itojun struct in6_ifreq ifr;
624 1.8 itojun #endif
625 1.2 itojun int error, s;
626 1.2 itojun #ifdef notyet
627 1.2 itojun struct tbf *m_tbf = tbftable + mifcp->mif6c_mifi;
628 1.2 itojun #endif
629 1.2 itojun
630 1.2 itojun if (mifcp->mif6c_mifi >= MAXMIFS)
631 1.2 itojun return EINVAL;
632 1.2 itojun mifp = mif6table + mifcp->mif6c_mifi;
633 1.2 itojun if (mifp->m6_ifp)
634 1.2 itojun return EADDRINUSE; /* XXX: is it appropriate? */
635 1.2 itojun if (mifcp->mif6c_pifi == 0 || mifcp->mif6c_pifi > if_index)
636 1.2 itojun return ENXIO;
637 1.2 itojun ifp = ifindex2ifnet[mifcp->mif6c_pifi];
638 1.2 itojun
639 1.2 itojun if (mifcp->mif6c_flags & MIFF_REGISTER) {
640 1.2 itojun if (reg_mif_num == (mifi_t)-1) {
641 1.8 itojun #if defined(__NetBSD__) || defined(__OpenBSD__)
642 1.2 itojun strcpy(multicast_register_if.if_xname,
643 1.2 itojun "register_mif"); /* XXX */
644 1.2 itojun #else
645 1.2 itojun multicast_register_if.if_name = "register_mif";
646 1.2 itojun #endif
647 1.2 itojun multicast_register_if.if_flags |= IFF_LOOPBACK;
648 1.2 itojun multicast_register_if.if_index = mifcp->mif6c_mifi;
649 1.2 itojun reg_mif_num = mifcp->mif6c_mifi;
650 1.2 itojun }
651 1.2 itojun
652 1.2 itojun ifp = &multicast_register_if;
653 1.2 itojun
654 1.2 itojun } /* if REGISTER */
655 1.2 itojun else {
656 1.2 itojun /* Make sure the interface supports multicast */
657 1.2 itojun if ((ifp->if_flags & IFF_MULTICAST) == 0)
658 1.2 itojun return EOPNOTSUPP;
659 1.2 itojun
660 1.8 itojun #ifdef __NetBSD__
661 1.8 itojun s = splsoftnet();
662 1.8 itojun #else
663 1.8 itojun s = splnet();
664 1.8 itojun #endif
665 1.8 itojun #if (defined(__FreeBSD__) && __FreeBSD__ >= 3)
666 1.8 itojun error = if_allmulti(ifp, 1);
667 1.8 itojun #else
668 1.2 itojun /*
669 1.2 itojun * Enable promiscuous reception of all IPv6 multicasts
670 1.8 itojun * from the interface.
671 1.2 itojun */
672 1.2 itojun ifr.ifr_addr.sin6_family = AF_INET6;
673 1.2 itojun ifr.ifr_addr.sin6_addr = in6addr_any;
674 1.2 itojun error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, (caddr_t)&ifr);
675 1.8 itojun #endif
676 1.2 itojun splx(s);
677 1.2 itojun if (error)
678 1.2 itojun return error;
679 1.2 itojun }
680 1.2 itojun
681 1.8 itojun #ifdef __NetBSD__
682 1.4 itojun s = splsoftnet();
683 1.8 itojun #else
684 1.8 itojun s = splnet();
685 1.8 itojun #endif
686 1.2 itojun mifp->m6_flags = mifcp->mif6c_flags;
687 1.2 itojun mifp->m6_ifp = ifp;
688 1.2 itojun #ifdef notyet
689 1.2 itojun /* scaling up here allows division by 1024 in critical code */
690 1.2 itojun mifp->m6_rate_limit = mifcp->mif6c_rate_limit * 1024 / 1000;
691 1.2 itojun #endif
692 1.2 itojun /* initialize per mif pkt counters */
693 1.2 itojun mifp->m6_pkt_in = 0;
694 1.2 itojun mifp->m6_pkt_out = 0;
695 1.2 itojun mifp->m6_bytes_in = 0;
696 1.2 itojun mifp->m6_bytes_out = 0;
697 1.2 itojun splx(s);
698 1.2 itojun
699 1.2 itojun /* Adjust nummifs up if the mifi is higher than nummifs */
700 1.2 itojun if (nummifs <= mifcp->mif6c_mifi)
701 1.2 itojun nummifs = mifcp->mif6c_mifi + 1;
702 1.2 itojun
703 1.2 itojun #ifdef MRT6DEBUG
704 1.2 itojun if (mrt6debug)
705 1.2 itojun log(LOG_DEBUG,
706 1.2 itojun "add_mif #%d, phyint %s%d\n",
707 1.2 itojun mifcp->mif6c_mifi,
708 1.2 itojun ifp->if_name, ifp->if_unit);
709 1.2 itojun #endif
710 1.2 itojun
711 1.2 itojun return 0;
712 1.2 itojun }
713 1.2 itojun
714 1.2 itojun /*
715 1.2 itojun * Delete a mif from the mif table
716 1.2 itojun */
717 1.2 itojun static int
718 1.2 itojun del_m6if(mifip)
719 1.2 itojun mifi_t *mifip;
720 1.2 itojun {
721 1.2 itojun register struct mif6 *mifp = mif6table + *mifip;
722 1.2 itojun register mifi_t mifi;
723 1.2 itojun struct ifnet *ifp;
724 1.8 itojun #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
725 1.2 itojun struct in6_ifreq ifr;
726 1.8 itojun #endif
727 1.2 itojun int s;
728 1.2 itojun
729 1.2 itojun if (*mifip >= nummifs)
730 1.2 itojun return EINVAL;
731 1.2 itojun if (mifp->m6_ifp == NULL)
732 1.2 itojun return EINVAL;
733 1.2 itojun
734 1.8 itojun #ifdef __NetBSD__
735 1.4 itojun s = splsoftnet();
736 1.8 itojun #else
737 1.8 itojun s = splnet();
738 1.8 itojun #endif
739 1.2 itojun
740 1.2 itojun if (!(mifp->m6_flags & MIFF_REGISTER)) {
741 1.2 itojun /*
742 1.2 itojun * XXX: what if there is yet IPv4 multicast daemon
743 1.2 itojun * using the interface?
744 1.2 itojun */
745 1.8 itojun ifp = mifp->m6_ifp;
746 1.8 itojun
747 1.8 itojun #if (defined(__FreeBSD__) && __FreeBSD__ >= 3)
748 1.8 itojun if_allmulti(ifp, 0);
749 1.8 itojun #else
750 1.2 itojun ifr.ifr_addr.sin6_family = AF_INET6;
751 1.2 itojun ifr.ifr_addr.sin6_addr = in6addr_any;
752 1.2 itojun (*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)&ifr);
753 1.8 itojun #endif
754 1.2 itojun }
755 1.2 itojun
756 1.2 itojun #ifdef notyet
757 1.2 itojun bzero((caddr_t)qtable[*mifip], sizeof(qtable[*mifip]));
758 1.2 itojun bzero((caddr_t)mifp->m6_tbf, sizeof(*(mifp->m6_tbf)));
759 1.2 itojun #endif
760 1.2 itojun bzero((caddr_t)mifp, sizeof (*mifp));
761 1.2 itojun
762 1.2 itojun /* Adjust nummifs down */
763 1.2 itojun for (mifi = nummifs; mifi > 0; mifi--)
764 1.2 itojun if (mif6table[mifi - 1].m6_ifp)
765 1.2 itojun break;
766 1.2 itojun nummifs = mifi;
767 1.2 itojun
768 1.2 itojun splx(s);
769 1.2 itojun
770 1.2 itojun #ifdef MRT6DEBUG
771 1.2 itojun if (mrt6debug)
772 1.2 itojun log(LOG_DEBUG, "del_m6if %d, nummifs %d\n", *mifip, nummifs);
773 1.2 itojun #endif
774 1.2 itojun
775 1.2 itojun return 0;
776 1.2 itojun }
777 1.2 itojun
778 1.2 itojun /*
779 1.2 itojun * Add an mfc entry
780 1.2 itojun */
781 1.2 itojun static int
782 1.2 itojun add_m6fc(mfccp)
783 1.2 itojun struct mf6cctl *mfccp;
784 1.2 itojun {
785 1.2 itojun struct mf6c *rt;
786 1.2 itojun u_long hash;
787 1.2 itojun struct rtdetq *rte;
788 1.2 itojun register u_short nstl;
789 1.2 itojun int s;
790 1.2 itojun
791 1.2 itojun MF6CFIND(mfccp->mf6cc_origin.sin6_addr,
792 1.2 itojun mfccp->mf6cc_mcastgrp.sin6_addr, rt);
793 1.2 itojun
794 1.2 itojun /* If an entry already exists, just update the fields */
795 1.2 itojun if (rt) {
796 1.2 itojun #ifdef MRT6DEBUG
797 1.2 itojun if (mrt6debug & DEBUG_MFC)
798 1.2 itojun log(LOG_DEBUG,"add_m6fc update o %s g %s p %x\n",
799 1.2 itojun ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
800 1.2 itojun ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
801 1.2 itojun mfccp->mf6cc_parent);
802 1.2 itojun #endif
803 1.2 itojun
804 1.8 itojun #ifdef __NetBSD__
805 1.4 itojun s = splsoftnet();
806 1.8 itojun #else
807 1.8 itojun s = splnet();
808 1.8 itojun #endif
809 1.2 itojun rt->mf6c_parent = mfccp->mf6cc_parent;
810 1.2 itojun rt->mf6c_ifset = mfccp->mf6cc_ifset;
811 1.2 itojun splx(s);
812 1.2 itojun return 0;
813 1.2 itojun }
814 1.2 itojun
815 1.2 itojun /*
816 1.2 itojun * Find the entry for which the upcall was made and update
817 1.2 itojun */
818 1.8 itojun #ifdef __NetBSD__
819 1.4 itojun s = splsoftnet();
820 1.8 itojun #else
821 1.8 itojun s = splnet();
822 1.8 itojun #endif
823 1.2 itojun hash = MF6CHASH(mfccp->mf6cc_origin.sin6_addr,
824 1.2 itojun mfccp->mf6cc_mcastgrp.sin6_addr);
825 1.2 itojun for (rt = mf6ctable[hash], nstl = 0; rt; rt = rt->mf6c_next) {
826 1.2 itojun if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
827 1.2 itojun &mfccp->mf6cc_origin.sin6_addr) &&
828 1.2 itojun IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
829 1.2 itojun &mfccp->mf6cc_mcastgrp.sin6_addr) &&
830 1.2 itojun (rt->mf6c_stall != NULL)) {
831 1.2 itojun
832 1.2 itojun if (nstl++)
833 1.2 itojun log(LOG_ERR,
834 1.5 itojun "add_m6fc: %s o %s g %s p %x dbx %p\n",
835 1.2 itojun "multiple kernel entries",
836 1.2 itojun ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
837 1.2 itojun ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
838 1.5 itojun mfccp->mf6cc_parent, rt->mf6c_stall);
839 1.2 itojun
840 1.2 itojun #ifdef MRT6DEBUG
841 1.2 itojun if (mrt6debug & DEBUG_MFC)
842 1.2 itojun log(LOG_DEBUG,
843 1.2 itojun "add_m6fc o %s g %s p %x dbg %x\n",
844 1.2 itojun ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
845 1.2 itojun ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
846 1.2 itojun mfccp->mf6cc_parent, rt->mf6c_stall);
847 1.2 itojun #endif
848 1.2 itojun
849 1.2 itojun rt->mf6c_origin = mfccp->mf6cc_origin;
850 1.2 itojun rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
851 1.2 itojun rt->mf6c_parent = mfccp->mf6cc_parent;
852 1.2 itojun rt->mf6c_ifset = mfccp->mf6cc_ifset;
853 1.2 itojun /* initialize pkt counters per src-grp */
854 1.2 itojun rt->mf6c_pkt_cnt = 0;
855 1.2 itojun rt->mf6c_byte_cnt = 0;
856 1.2 itojun rt->mf6c_wrong_if = 0;
857 1.2 itojun
858 1.2 itojun rt->mf6c_expire = 0; /* Don't clean this guy up */
859 1.2 itojun nexpire[hash]--;
860 1.2 itojun
861 1.2 itojun /* free packets Qed at the end of this entry */
862 1.2 itojun for (rte = rt->mf6c_stall; rte != NULL; ) {
863 1.2 itojun struct rtdetq *n = rte->next;
864 1.2 itojun ip6_mdq(rte->m, rte->ifp, rt);
865 1.2 itojun m_freem(rte->m);
866 1.2 itojun #ifdef UPCALL_TIMING
867 1.2 itojun collate(&(rte->t));
868 1.2 itojun #endif /* UPCALL_TIMING */
869 1.2 itojun free(rte, M_MRTABLE);
870 1.2 itojun rte = n;
871 1.2 itojun }
872 1.2 itojun rt->mf6c_stall = NULL;
873 1.2 itojun }
874 1.2 itojun }
875 1.2 itojun
876 1.2 itojun /*
877 1.2 itojun * It is possible that an entry is being inserted without an upcall
878 1.2 itojun */
879 1.2 itojun if (nstl == 0) {
880 1.2 itojun #ifdef MRT6DEBUG
881 1.2 itojun if (mrt6debug & DEBUG_MFC)
882 1.2 itojun log(LOG_DEBUG,"add_mfc no upcall h %d o %s g %s p %x\n",
883 1.2 itojun hash,
884 1.2 itojun ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
885 1.2 itojun ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
886 1.2 itojun mfccp->mf6cc_parent);
887 1.2 itojun #endif
888 1.2 itojun
889 1.2 itojun for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
890 1.2 itojun
891 1.2 itojun if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
892 1.2 itojun &mfccp->mf6cc_origin.sin6_addr)&&
893 1.2 itojun IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
894 1.2 itojun &mfccp->mf6cc_mcastgrp.sin6_addr)) {
895 1.2 itojun
896 1.2 itojun rt->mf6c_origin = mfccp->mf6cc_origin;
897 1.2 itojun rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
898 1.2 itojun rt->mf6c_parent = mfccp->mf6cc_parent;
899 1.2 itojun /* initialize pkt counters per src-grp */
900 1.2 itojun rt->mf6c_pkt_cnt = 0;
901 1.2 itojun rt->mf6c_byte_cnt = 0;
902 1.2 itojun rt->mf6c_wrong_if = 0;
903 1.2 itojun
904 1.2 itojun if (rt->mf6c_expire)
905 1.2 itojun nexpire[hash]--;
906 1.2 itojun rt->mf6c_expire = 0;
907 1.2 itojun }
908 1.2 itojun }
909 1.2 itojun if (rt == NULL) {
910 1.2 itojun /* no upcall, so make a new entry */
911 1.2 itojun rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE,
912 1.2 itojun M_NOWAIT);
913 1.2 itojun if (rt == NULL) {
914 1.2 itojun splx(s);
915 1.2 itojun return ENOBUFS;
916 1.2 itojun }
917 1.2 itojun
918 1.2 itojun /* insert new entry at head of hash chain */
919 1.2 itojun rt->mf6c_origin = mfccp->mf6cc_origin;
920 1.2 itojun rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
921 1.2 itojun rt->mf6c_parent = mfccp->mf6cc_parent;
922 1.2 itojun /* initialize pkt counters per src-grp */
923 1.2 itojun rt->mf6c_pkt_cnt = 0;
924 1.2 itojun rt->mf6c_byte_cnt = 0;
925 1.2 itojun rt->mf6c_wrong_if = 0;
926 1.2 itojun rt->mf6c_expire = 0;
927 1.2 itojun rt->mf6c_stall = NULL;
928 1.2 itojun
929 1.2 itojun /* link into table */
930 1.2 itojun rt->mf6c_next = mf6ctable[hash];
931 1.2 itojun mf6ctable[hash] = rt;
932 1.2 itojun }
933 1.2 itojun }
934 1.2 itojun splx(s);
935 1.2 itojun return 0;
936 1.2 itojun }
937 1.2 itojun
938 1.2 itojun #ifdef UPCALL_TIMING
939 1.2 itojun /*
940 1.2 itojun * collect delay statistics on the upcalls
941 1.2 itojun */
942 1.2 itojun static void
943 1.2 itojun collate(t)
944 1.2 itojun register struct timeval *t;
945 1.2 itojun {
946 1.2 itojun register u_long d;
947 1.2 itojun register struct timeval tp;
948 1.2 itojun register u_long delta;
949 1.2 itojun
950 1.2 itojun GET_TIME(tp);
951 1.2 itojun
952 1.2 itojun if (TV_LT(*t, tp))
953 1.2 itojun {
954 1.2 itojun TV_DELTA(tp, *t, delta);
955 1.2 itojun
956 1.2 itojun d = delta >> 10;
957 1.7 itojun if (d > UPCALL_MAX)
958 1.7 itojun d = UPCALL_MAX;
959 1.2 itojun
960 1.2 itojun ++upcall_data[d];
961 1.2 itojun }
962 1.2 itojun }
963 1.2 itojun #endif /* UPCALL_TIMING */
964 1.2 itojun
965 1.2 itojun /*
966 1.2 itojun * Delete an mfc entry
967 1.2 itojun */
968 1.2 itojun static int
969 1.2 itojun del_m6fc(mfccp)
970 1.2 itojun struct mf6cctl *mfccp;
971 1.2 itojun {
972 1.2 itojun struct sockaddr_in6 origin;
973 1.2 itojun struct sockaddr_in6 mcastgrp;
974 1.2 itojun struct mf6c *rt;
975 1.2 itojun struct mf6c **nptr;
976 1.2 itojun u_long hash;
977 1.2 itojun int s;
978 1.2 itojun
979 1.2 itojun origin = mfccp->mf6cc_origin;
980 1.2 itojun mcastgrp = mfccp->mf6cc_mcastgrp;
981 1.2 itojun hash = MF6CHASH(origin.sin6_addr, mcastgrp.sin6_addr);
982 1.2 itojun
983 1.2 itojun #ifdef MRT6DEBUG
984 1.2 itojun if (mrt6debug & DEBUG_MFC)
985 1.2 itojun log(LOG_DEBUG,"del_m6fc orig %s mcastgrp %s\n",
986 1.2 itojun ip6_sprintf(&origin.sin6_addr),
987 1.2 itojun ip6_sprintf(&mcastgrp.sin6_addr));
988 1.2 itojun #endif
989 1.2 itojun
990 1.8 itojun #ifdef __NetBSD__
991 1.4 itojun s = splsoftnet();
992 1.8 itojun #else
993 1.8 itojun s = splnet();
994 1.8 itojun #endif
995 1.2 itojun
996 1.2 itojun nptr = &mf6ctable[hash];
997 1.2 itojun while ((rt = *nptr) != NULL) {
998 1.2 itojun if (IN6_ARE_ADDR_EQUAL(&origin.sin6_addr,
999 1.2 itojun &rt->mf6c_origin.sin6_addr) &&
1000 1.2 itojun IN6_ARE_ADDR_EQUAL(&mcastgrp.sin6_addr,
1001 1.2 itojun &rt->mf6c_mcastgrp.sin6_addr) &&
1002 1.2 itojun rt->mf6c_stall == NULL)
1003 1.2 itojun break;
1004 1.2 itojun
1005 1.2 itojun nptr = &rt->mf6c_next;
1006 1.2 itojun }
1007 1.2 itojun if (rt == NULL) {
1008 1.2 itojun splx(s);
1009 1.2 itojun return EADDRNOTAVAIL;
1010 1.2 itojun }
1011 1.2 itojun
1012 1.2 itojun *nptr = rt->mf6c_next;
1013 1.2 itojun free(rt, M_MRTABLE);
1014 1.2 itojun
1015 1.2 itojun splx(s);
1016 1.2 itojun
1017 1.2 itojun return 0;
1018 1.2 itojun }
1019 1.2 itojun
1020 1.2 itojun static int
1021 1.2 itojun socket_send(s, mm, src)
1022 1.2 itojun struct socket *s;
1023 1.2 itojun struct mbuf *mm;
1024 1.2 itojun struct sockaddr_in6 *src;
1025 1.2 itojun {
1026 1.2 itojun if (s) {
1027 1.2 itojun if (sbappendaddr(&s->so_rcv,
1028 1.2 itojun (struct sockaddr *)src,
1029 1.2 itojun mm, (struct mbuf *)0) != 0) {
1030 1.2 itojun sorwakeup(s);
1031 1.2 itojun return 0;
1032 1.2 itojun }
1033 1.2 itojun }
1034 1.2 itojun m_freem(mm);
1035 1.2 itojun return -1;
1036 1.2 itojun }
1037 1.2 itojun
1038 1.2 itojun /*
1039 1.2 itojun * IPv6 multicast forwarding function. This function assumes that the packet
1040 1.2 itojun * pointed to by "ip6" has arrived on (or is about to be sent to) the interface
1041 1.2 itojun * pointed to by "ifp", and the packet is to be relayed to other networks
1042 1.2 itojun * that have members of the packet's destination IPv6 multicast group.
1043 1.2 itojun *
1044 1.2 itojun * The packet is returned unscathed to the caller, unless it is
1045 1.2 itojun * erroneous, in which case a non-zero return value tells the caller to
1046 1.2 itojun * discard it.
1047 1.2 itojun */
1048 1.2 itojun
1049 1.2 itojun int
1050 1.2 itojun ip6_mforward(ip6, ifp, m)
1051 1.2 itojun register struct ip6_hdr *ip6;
1052 1.2 itojun struct ifnet *ifp;
1053 1.2 itojun struct mbuf *m;
1054 1.2 itojun {
1055 1.2 itojun register struct mf6c *rt;
1056 1.2 itojun register struct mif6 *mifp;
1057 1.2 itojun register struct mbuf *mm;
1058 1.2 itojun int s;
1059 1.2 itojun mifi_t mifi;
1060 1.2 itojun
1061 1.2 itojun #ifdef MRT6DEBUG
1062 1.2 itojun if (mrt6debug & DEBUG_FORWARD)
1063 1.2 itojun log(LOG_DEBUG, "ip6_mforward: src %s, dst %s, ifindex %d\n",
1064 1.2 itojun ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst),
1065 1.2 itojun ifp->if_index);
1066 1.2 itojun #endif
1067 1.2 itojun
1068 1.2 itojun /*
1069 1.2 itojun * Don't forward a packet with Hop limit of zero or one,
1070 1.2 itojun * or a packet destined to a local-only group.
1071 1.2 itojun */
1072 1.2 itojun if (ip6->ip6_hlim <= 1 || IN6_IS_ADDR_MC_NODELOCAL(&ip6->ip6_dst) ||
1073 1.2 itojun IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst))
1074 1.2 itojun return 0;
1075 1.2 itojun ip6->ip6_hlim--;
1076 1.2 itojun
1077 1.2 itojun /*
1078 1.2 itojun * Determine forwarding mifs from the forwarding cache table
1079 1.2 itojun */
1080 1.8 itojun #ifdef __NetBSD__
1081 1.4 itojun s = splsoftnet();
1082 1.8 itojun #else
1083 1.8 itojun s = splnet();
1084 1.8 itojun #endif
1085 1.2 itojun MF6CFIND(ip6->ip6_src, ip6->ip6_dst, rt);
1086 1.2 itojun
1087 1.2 itojun /* Entry exists, so forward if necessary */
1088 1.2 itojun if (rt) {
1089 1.2 itojun splx(s);
1090 1.2 itojun return (ip6_mdq(m, ifp, rt));
1091 1.2 itojun } else {
1092 1.2 itojun /*
1093 1.2 itojun * If we don't have a route for packet's origin,
1094 1.2 itojun * Make a copy of the packet &
1095 1.2 itojun * send message to routing daemon
1096 1.2 itojun */
1097 1.2 itojun
1098 1.2 itojun register struct mbuf *mb0;
1099 1.2 itojun register struct rtdetq *rte;
1100 1.2 itojun register u_long hash;
1101 1.2 itojun /* register int i, npkts;*/
1102 1.2 itojun #ifdef UPCALL_TIMING
1103 1.2 itojun struct timeval tp;
1104 1.2 itojun
1105 1.2 itojun GET_TIME(tp);
1106 1.2 itojun #endif /* UPCALL_TIMING */
1107 1.2 itojun
1108 1.2 itojun mrt6stat.mrt6s_no_route++;
1109 1.2 itojun #ifdef MRT6DEBUG
1110 1.2 itojun if (mrt6debug & (DEBUG_FORWARD | DEBUG_MFC))
1111 1.2 itojun log(LOG_DEBUG, "ip6_mforward: no rte s %s g %s\n",
1112 1.2 itojun ip6_sprintf(&ip6->ip6_src),
1113 1.2 itojun ip6_sprintf(&ip6->ip6_dst));
1114 1.2 itojun #endif
1115 1.2 itojun
1116 1.2 itojun /*
1117 1.2 itojun * Allocate mbufs early so that we don't do extra work if we
1118 1.2 itojun * are just going to fail anyway.
1119 1.2 itojun */
1120 1.2 itojun rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE,
1121 1.2 itojun M_NOWAIT);
1122 1.2 itojun if (rte == NULL) {
1123 1.2 itojun splx(s);
1124 1.2 itojun return ENOBUFS;
1125 1.2 itojun }
1126 1.2 itojun mb0 = m_copy(m, 0, M_COPYALL);
1127 1.2 itojun /*
1128 1.2 itojun * Pullup packet header if needed before storing it,
1129 1.2 itojun * as other references may modify it in the meantime.
1130 1.2 itojun */
1131 1.2 itojun if (mb0 &&
1132 1.2 itojun (M_HASCL(mb0) || mb0->m_len < sizeof(struct ip6_hdr)))
1133 1.2 itojun mb0 = m_pullup(mb0, sizeof(struct ip6_hdr));
1134 1.2 itojun if (mb0 == NULL) {
1135 1.2 itojun free(rte, M_MRTABLE);
1136 1.2 itojun splx(s);
1137 1.2 itojun return ENOBUFS;
1138 1.2 itojun }
1139 1.2 itojun
1140 1.2 itojun /* is there an upcall waiting for this packet? */
1141 1.2 itojun hash = MF6CHASH(ip6->ip6_src, ip6->ip6_dst);
1142 1.2 itojun for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
1143 1.2 itojun if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_src,
1144 1.2 itojun &rt->mf6c_origin.sin6_addr) &&
1145 1.2 itojun IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
1146 1.2 itojun &rt->mf6c_mcastgrp.sin6_addr) &&
1147 1.2 itojun (rt->mf6c_stall != NULL))
1148 1.2 itojun break;
1149 1.2 itojun }
1150 1.2 itojun
1151 1.2 itojun if (rt == NULL) {
1152 1.2 itojun struct mrt6msg *im;
1153 1.2 itojun
1154 1.2 itojun /* no upcall, so make a new entry */
1155 1.2 itojun rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE,
1156 1.2 itojun M_NOWAIT);
1157 1.2 itojun if (rt == NULL) {
1158 1.2 itojun free(rte, M_MRTABLE);
1159 1.2 itojun m_freem(mb0);
1160 1.2 itojun splx(s);
1161 1.2 itojun return ENOBUFS;
1162 1.2 itojun }
1163 1.2 itojun /*
1164 1.2 itojun * Make a copy of the header to send to the user
1165 1.2 itojun * level process
1166 1.2 itojun */
1167 1.2 itojun mm = m_copy(mb0, 0, sizeof(struct ip6_hdr));
1168 1.2 itojun
1169 1.2 itojun if (mm == NULL) {
1170 1.2 itojun free(rte, M_MRTABLE);
1171 1.2 itojun m_freem(mb0);
1172 1.2 itojun free(rt, M_MRTABLE);
1173 1.2 itojun splx(s);
1174 1.2 itojun return ENOBUFS;
1175 1.2 itojun }
1176 1.2 itojun
1177 1.2 itojun /*
1178 1.2 itojun * Send message to routing daemon
1179 1.2 itojun */
1180 1.2 itojun sin6.sin6_addr = ip6->ip6_src;
1181 1.2 itojun
1182 1.2 itojun im = mtod(mm, struct mrt6msg *);
1183 1.2 itojun im->im6_msgtype = MRT6MSG_NOCACHE;
1184 1.2 itojun im->im6_mbz = 0;
1185 1.2 itojun
1186 1.2 itojun #ifdef MRT6DEBUG
1187 1.2 itojun if (mrt6debug & DEBUG_FORWARD)
1188 1.2 itojun log(LOG_DEBUG,
1189 1.2 itojun "getting the iif info in the kernel\n");
1190 1.2 itojun #endif
1191 1.2 itojun
1192 1.2 itojun for (mifp = mif6table, mifi = 0;
1193 1.2 itojun mifi < nummifs && mifp->m6_ifp != ifp;
1194 1.2 itojun mifp++, mifi++)
1195 1.2 itojun ;
1196 1.2 itojun
1197 1.2 itojun im->im6_mif = mifi;
1198 1.2 itojun
1199 1.2 itojun if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1200 1.2 itojun log(LOG_WARNING, "ip6_mforward: ip6_mrouter "
1201 1.2 itojun "socket queue full\n");
1202 1.2 itojun mrt6stat.mrt6s_upq_sockfull++;
1203 1.2 itojun free(rte, M_MRTABLE);
1204 1.2 itojun m_freem(mb0);
1205 1.2 itojun free(rt, M_MRTABLE);
1206 1.2 itojun splx(s);
1207 1.2 itojun return ENOBUFS;
1208 1.2 itojun }
1209 1.2 itojun
1210 1.2 itojun mrt6stat.mrt6s_upcalls++;
1211 1.2 itojun
1212 1.2 itojun /* insert new entry at head of hash chain */
1213 1.2 itojun bzero(rt, sizeof(*rt));
1214 1.8 itojun rt->mf6c_origin.sin6_family = AF_INET6;
1215 1.8 itojun rt->mf6c_origin.sin6_len = sizeof(struct sockaddr_in6);
1216 1.2 itojun rt->mf6c_origin.sin6_addr = ip6->ip6_src;
1217 1.8 itojun rt->mf6c_mcastgrp.sin6_family = AF_INET6;
1218 1.8 itojun rt->mf6c_mcastgrp.sin6_len = sizeof(struct sockaddr_in6);
1219 1.2 itojun rt->mf6c_mcastgrp.sin6_addr = ip6->ip6_dst;
1220 1.2 itojun rt->mf6c_expire = UPCALL_EXPIRE;
1221 1.2 itojun nexpire[hash]++;
1222 1.2 itojun rt->mf6c_parent = MF6C_INCOMPLETE_PARENT;
1223 1.2 itojun
1224 1.2 itojun /* link into table */
1225 1.2 itojun rt->mf6c_next = mf6ctable[hash];
1226 1.2 itojun mf6ctable[hash] = rt;
1227 1.2 itojun /* Add this entry to the end of the queue */
1228 1.2 itojun rt->mf6c_stall = rte;
1229 1.2 itojun } else {
1230 1.2 itojun /* determine if q has overflowed */
1231 1.2 itojun struct rtdetq **p;
1232 1.2 itojun register int npkts = 0;
1233 1.2 itojun
1234 1.2 itojun for (p = &rt->mf6c_stall; *p != NULL; p = &(*p)->next)
1235 1.2 itojun if (++npkts > MAX_UPQ6) {
1236 1.2 itojun mrt6stat.mrt6s_upq_ovflw++;
1237 1.2 itojun free(rte, M_MRTABLE);
1238 1.2 itojun m_freem(mb0);
1239 1.2 itojun splx(s);
1240 1.2 itojun return 0;
1241 1.2 itojun }
1242 1.2 itojun
1243 1.2 itojun /* Add this entry to the end of the queue */
1244 1.2 itojun *p = rte;
1245 1.2 itojun }
1246 1.2 itojun
1247 1.2 itojun rte->next = NULL;
1248 1.2 itojun rte->m = mb0;
1249 1.2 itojun rte->ifp = ifp;
1250 1.2 itojun #ifdef UPCALL_TIMING
1251 1.2 itojun rte->t = tp;
1252 1.2 itojun #endif /* UPCALL_TIMING */
1253 1.2 itojun
1254 1.2 itojun splx(s);
1255 1.2 itojun
1256 1.2 itojun return 0;
1257 1.2 itojun }
1258 1.2 itojun }
1259 1.2 itojun
1260 1.2 itojun /*
1261 1.2 itojun * Clean up cache entries if upcalls are not serviced
1262 1.2 itojun * Call from the Slow Timeout mechanism, every half second.
1263 1.2 itojun */
1264 1.2 itojun static void
1265 1.2 itojun expire_upcalls(unused)
1266 1.2 itojun void *unused;
1267 1.2 itojun {
1268 1.2 itojun struct rtdetq *rte;
1269 1.2 itojun struct mf6c *mfc, **nptr;
1270 1.2 itojun int i;
1271 1.2 itojun int s;
1272 1.2 itojun
1273 1.8 itojun #ifdef __NetBSD__
1274 1.4 itojun s = splsoftnet();
1275 1.8 itojun #else
1276 1.8 itojun s = splnet();
1277 1.8 itojun #endif
1278 1.2 itojun for (i = 0; i < MF6CTBLSIZ; i++) {
1279 1.2 itojun if (nexpire[i] == 0)
1280 1.2 itojun continue;
1281 1.2 itojun nptr = &mf6ctable[i];
1282 1.2 itojun while ((mfc = *nptr) != NULL) {
1283 1.2 itojun rte = mfc->mf6c_stall;
1284 1.2 itojun /*
1285 1.2 itojun * Skip real cache entries
1286 1.2 itojun * Make sure it wasn't marked to not expire (shouldn't happen)
1287 1.2 itojun * If it expires now
1288 1.2 itojun */
1289 1.2 itojun if (rte != NULL &&
1290 1.2 itojun mfc->mf6c_expire != 0 &&
1291 1.2 itojun --mfc->mf6c_expire == 0) {
1292 1.2 itojun #ifdef MRT6DEBUG
1293 1.2 itojun if (mrt6debug & DEBUG_EXPIRE)
1294 1.2 itojun log(LOG_DEBUG, "expire_upcalls: expiring (%s %s)\n",
1295 1.2 itojun ip6_sprintf(&mfc->mf6c_origin.sin6_addr),
1296 1.2 itojun ip6_sprintf(&mfc->mf6c_mcastgrp.sin6_addr));
1297 1.2 itojun #endif
1298 1.2 itojun /*
1299 1.2 itojun * drop all the packets
1300 1.2 itojun * free the mbuf with the pkt, if, timing info
1301 1.2 itojun */
1302 1.2 itojun do {
1303 1.2 itojun struct rtdetq *n = rte->next;
1304 1.2 itojun m_freem(rte->m);
1305 1.2 itojun free(rte, M_MRTABLE);
1306 1.2 itojun rte = n;
1307 1.2 itojun } while (rte != NULL);
1308 1.2 itojun mrt6stat.mrt6s_cache_cleanups++;
1309 1.2 itojun nexpire[i]--;
1310 1.2 itojun
1311 1.2 itojun *nptr = mfc->mf6c_next;
1312 1.2 itojun free(mfc, M_MRTABLE);
1313 1.2 itojun } else {
1314 1.2 itojun nptr = &mfc->mf6c_next;
1315 1.2 itojun }
1316 1.2 itojun }
1317 1.2 itojun }
1318 1.2 itojun splx(s);
1319 1.8 itojun #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1320 1.8 itojun expire_upcalls_ch =
1321 1.8 itojun #endif
1322 1.2 itojun timeout(expire_upcalls, (caddr_t)NULL, EXPIRE_TIMEOUT);
1323 1.2 itojun }
1324 1.2 itojun
1325 1.2 itojun /*
1326 1.2 itojun * Packet forwarding routine once entry in the cache is made
1327 1.2 itojun */
1328 1.2 itojun static int
1329 1.2 itojun ip6_mdq(m, ifp, rt)
1330 1.2 itojun register struct mbuf *m;
1331 1.2 itojun register struct ifnet *ifp;
1332 1.2 itojun register struct mf6c *rt;
1333 1.2 itojun {
1334 1.2 itojun register struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1335 1.2 itojun register mifi_t mifi, iif;
1336 1.2 itojun register struct mif6 *mifp;
1337 1.7 itojun register int plen = m->m_pkthdr.len;
1338 1.2 itojun
1339 1.2 itojun /*
1340 1.2 itojun * Macro to send packet on mif. Since RSVP packets don't get counted on
1341 1.2 itojun * input, they shouldn't get counted on output, so statistics keeping is
1342 1.2 itojun * seperate.
1343 1.2 itojun */
1344 1.2 itojun
1345 1.2 itojun #define MC6_SEND(ip6,mifp,m) { \
1346 1.2 itojun if ((mifp)->m6_flags & MIFF_REGISTER) \
1347 1.2 itojun register_send((ip6), (mifp), (m)); \
1348 1.2 itojun else \
1349 1.2 itojun phyint_send((ip6), (mifp), (m)); \
1350 1.2 itojun }
1351 1.2 itojun
1352 1.2 itojun /*
1353 1.2 itojun * Don't forward if it didn't arrive from the parent mif
1354 1.2 itojun * for its origin.
1355 1.2 itojun */
1356 1.2 itojun mifi = rt->mf6c_parent;
1357 1.2 itojun if ((mifi >= nummifs) || (mif6table[mifi].m6_ifp != ifp)) {
1358 1.2 itojun /* came in the wrong interface */
1359 1.2 itojun #ifdef MRT6DEBUG
1360 1.2 itojun if (mrt6debug & DEBUG_FORWARD)
1361 1.2 itojun log(LOG_DEBUG,
1362 1.2 itojun "wrong if: ifid %d mifi %d mififid %x\n",
1363 1.2 itojun ifp->if_index, mifi,
1364 1.2 itojun mif6table[mifi].m6_ifp->if_index);
1365 1.2 itojun #endif
1366 1.2 itojun mrt6stat.mrt6s_wrong_if++;
1367 1.2 itojun rt->mf6c_wrong_if++;
1368 1.2 itojun /*
1369 1.2 itojun * If we are doing PIM processing, and we are forwarding
1370 1.2 itojun * packets on this interface, send a message to the
1371 1.2 itojun * routing daemon.
1372 1.2 itojun */
1373 1.2 itojun if(mifi < nummifs) /* have to make sure this is a valid mif */
1374 1.2 itojun if(mif6table[mifi].m6_ifp)
1375 1.2 itojun
1376 1.6 itojun if (pim6 && (m->m_flags & M_LOOP) == 0) {
1377 1.6 itojun /*
1378 1.6 itojun * Check the M_LOOP flag to avoid an
1379 1.6 itojun * unnecessary PIM assert.
1380 1.6 itojun * XXX: M_LOOP is an ad-hoc hack...
1381 1.6 itojun */
1382 1.2 itojun static struct sockaddr_in6 sin6 =
1383 1.2 itojun { sizeof(sin6), AF_INET6 };
1384 1.2 itojun
1385 1.2 itojun register struct mbuf *mm;
1386 1.2 itojun struct mrt6msg *im;
1387 1.2 itojun
1388 1.2 itojun mm = m_copy(m, 0,
1389 1.2 itojun sizeof(struct ip6_hdr));
1390 1.2 itojun if (mm &&
1391 1.2 itojun (M_HASCL(mm) ||
1392 1.2 itojun mm->m_len < sizeof(struct ip6_hdr)))
1393 1.2 itojun mm = m_pullup(mm, sizeof(struct ip6_hdr));
1394 1.2 itojun if (mm == NULL)
1395 1.2 itojun return ENOBUFS;
1396 1.2 itojun
1397 1.2 itojun im = mtod(mm, struct mrt6msg *);
1398 1.2 itojun im->im6_msgtype = MRT6MSG_WRONGMIF;
1399 1.2 itojun im->im6_mbz = 0;
1400 1.2 itojun
1401 1.2 itojun for (mifp = mif6table, iif = 0;
1402 1.2 itojun iif < nummifs && mifp &&
1403 1.2 itojun mifp->m6_ifp != ifp;
1404 1.2 itojun mifp++, iif++);
1405 1.2 itojun
1406 1.2 itojun im->im6_mif = iif;
1407 1.2 itojun
1408 1.2 itojun sin6.sin6_addr = im->im6_src;
1409 1.2 itojun
1410 1.2 itojun mrt6stat.mrt6s_upcalls++;
1411 1.2 itojun
1412 1.2 itojun if (socket_send(ip6_mrouter, mm,
1413 1.2 itojun &sin6) < 0) {
1414 1.2 itojun #ifdef MRT6DEBUG
1415 1.2 itojun if (mrt6debug)
1416 1.2 itojun log(LOG_WARNING, "mdq, ip6_mrouter socket queue full\n");
1417 1.2 itojun #endif
1418 1.2 itojun ++mrt6stat.mrt6s_upq_sockfull;
1419 1.2 itojun return ENOBUFS;
1420 1.2 itojun } /* if socket Q full */
1421 1.2 itojun } /* if PIM */
1422 1.2 itojun return 0;
1423 1.2 itojun } /* if wrong iif */
1424 1.2 itojun
1425 1.2 itojun /* If I sourced this packet, it counts as output, else it was input. */
1426 1.2 itojun if (m->m_pkthdr.rcvif == NULL) {
1427 1.2 itojun /* XXX: is rcvif really NULL when output?? */
1428 1.2 itojun mif6table[mifi].m6_pkt_out++;
1429 1.2 itojun mif6table[mifi].m6_bytes_out += plen;
1430 1.2 itojun } else {
1431 1.2 itojun mif6table[mifi].m6_pkt_in++;
1432 1.2 itojun mif6table[mifi].m6_bytes_in += plen;
1433 1.2 itojun }
1434 1.2 itojun rt->mf6c_pkt_cnt++;
1435 1.2 itojun rt->mf6c_byte_cnt += plen;
1436 1.2 itojun
1437 1.2 itojun /*
1438 1.2 itojun * For each mif, forward a copy of the packet if there are group
1439 1.2 itojun * members downstream on the interface.
1440 1.2 itojun */
1441 1.2 itojun for (mifp = mif6table, mifi = 0; mifi < nummifs; mifp++, mifi++)
1442 1.2 itojun if (IF_ISSET(mifi, &rt->mf6c_ifset)) {
1443 1.2 itojun mifp->m6_pkt_out++;
1444 1.2 itojun mifp->m6_bytes_out += plen;
1445 1.2 itojun MC6_SEND(ip6, mifp, m);
1446 1.2 itojun }
1447 1.2 itojun return 0;
1448 1.2 itojun }
1449 1.2 itojun
1450 1.2 itojun static void
1451 1.2 itojun phyint_send(ip6, mifp, m)
1452 1.2 itojun struct ip6_hdr *ip6;
1453 1.2 itojun struct mif6 *mifp;
1454 1.2 itojun struct mbuf *m;
1455 1.2 itojun {
1456 1.2 itojun register struct mbuf *mb_copy;
1457 1.2 itojun struct ifnet *ifp = mifp->m6_ifp;
1458 1.2 itojun int error = 0;
1459 1.8 itojun #ifdef __NetBSD__
1460 1.4 itojun int s = splsoftnet();
1461 1.8 itojun #else
1462 1.8 itojun int s = splnet();
1463 1.8 itojun #endif
1464 1.2 itojun static struct route_in6 ro6;
1465 1.2 itojun struct in6_multi *in6m;
1466 1.2 itojun
1467 1.2 itojun /*
1468 1.2 itojun * Make a new reference to the packet; make sure that
1469 1.2 itojun * the IPv6 header is actually copied, not just referenced,
1470 1.2 itojun * so that ip6_output() only scribbles on the copy.
1471 1.2 itojun */
1472 1.2 itojun mb_copy = m_copy(m, 0, M_COPYALL);
1473 1.2 itojun if (mb_copy &&
1474 1.2 itojun (M_HASCL(mb_copy) || mb_copy->m_len < sizeof(struct ip6_hdr)))
1475 1.2 itojun mb_copy = m_pullup(mb_copy, sizeof(struct ip6_hdr));
1476 1.2 itojun if (mb_copy == NULL)
1477 1.2 itojun return;
1478 1.2 itojun /* set MCAST flag to the outgoing packet */
1479 1.2 itojun mb_copy->m_flags |= M_MCAST;
1480 1.2 itojun
1481 1.2 itojun /*
1482 1.2 itojun * If we sourced the packet, call ip6_output since we may devide
1483 1.2 itojun * the packet into fragments when the packet is too big for the
1484 1.2 itojun * outgoing interface.
1485 1.2 itojun * Otherwise, we can simply send the packet to the interface
1486 1.2 itojun * sending queue.
1487 1.2 itojun */
1488 1.2 itojun if (m->m_pkthdr.rcvif == NULL) {
1489 1.2 itojun struct ip6_moptions im6o;
1490 1.2 itojun
1491 1.2 itojun im6o.im6o_multicast_ifp = ifp;
1492 1.2 itojun /* XXX: ip6_output will override ip6->ip6_hlim */
1493 1.2 itojun im6o.im6o_multicast_hlim = ip6->ip6_hlim;
1494 1.2 itojun im6o.im6o_multicast_loop = 1;
1495 1.2 itojun error = ip6_output(mb_copy, NULL, &ro6,
1496 1.8 itojun IPV6_FORWARDING, &im6o, NULL);
1497 1.2 itojun
1498 1.2 itojun #ifdef MRT6DEBUG
1499 1.2 itojun if (mrt6debug & DEBUG_XMIT)
1500 1.2 itojun log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1501 1.2 itojun mifp - mif6table, error);
1502 1.2 itojun #endif
1503 1.2 itojun splx(s);
1504 1.2 itojun return;
1505 1.2 itojun }
1506 1.2 itojun
1507 1.2 itojun /*
1508 1.2 itojun * If we belong to the destination multicast group
1509 1.2 itojun * on the outgoing interface, loop back a copy.
1510 1.2 itojun */
1511 1.2 itojun IN6_LOOKUP_MULTI(ip6->ip6_dst, ifp, in6m);
1512 1.2 itojun if (in6m != NULL) {
1513 1.2 itojun ro6.ro_dst.sin6_len = sizeof(struct sockaddr_in6);
1514 1.2 itojun ro6.ro_dst.sin6_family = AF_INET6;
1515 1.2 itojun ro6.ro_dst.sin6_addr = ip6->ip6_dst;
1516 1.2 itojun ip6_mloopback(ifp, m, &ro6.ro_dst);
1517 1.2 itojun }
1518 1.2 itojun /*
1519 1.2 itojun * Put the packet into the sending queue of the outgoing interface
1520 1.2 itojun * if it would fit in the MTU of the interface.
1521 1.2 itojun */
1522 1.2 itojun if (mb_copy->m_pkthdr.len < ifp->if_mtu || ifp->if_mtu < IPV6_MMTU) {
1523 1.2 itojun ro6.ro_dst.sin6_len = sizeof(struct sockaddr_in6);
1524 1.2 itojun ro6.ro_dst.sin6_family = AF_INET6;
1525 1.2 itojun ro6.ro_dst.sin6_addr = ip6->ip6_dst;
1526 1.8 itojun /*
1527 1.8 itojun * We just call if_output instead of nd6_output here, since
1528 1.8 itojun * we need no ND for a multicast forwarded packet...right?
1529 1.8 itojun */
1530 1.2 itojun error = (*ifp->if_output)(ifp, mb_copy,
1531 1.2 itojun (struct sockaddr *)&ro6.ro_dst,
1532 1.2 itojun NULL);
1533 1.2 itojun #ifdef MRT6DEBUG
1534 1.2 itojun if (mrt6debug & DEBUG_XMIT)
1535 1.2 itojun log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1536 1.2 itojun mifp - mif6table, error);
1537 1.2 itojun #endif
1538 1.2 itojun }
1539 1.2 itojun else {
1540 1.2 itojun #ifdef MULTICAST_PMTUD
1541 1.2 itojun icmp6_error(mb_copy, ICMP6_PACKET_TOO_BIG, 0, ifp->if_mtu);
1542 1.2 itojun return;
1543 1.2 itojun #else
1544 1.2 itojun #ifdef MRT6DEBUG
1545 1.2 itojun #ifdef __NetBSD__
1546 1.2 itojun if (mrt6debug & DEBUG_DEBUG_XMIT)
1547 1.2 itojun log(LOG_DEBUG,
1548 1.2 itojun "phyint_send: packet too big on %s o %s g %s"
1549 1.2 itojun " size %d(discarded)\n",
1550 1.2 itojun ifp->if_xname,
1551 1.2 itojun ip6_sprintf(&ip6->ip6_src),
1552 1.2 itojun ip6_sprintf(&ip6->ip6_dst),
1553 1.2 itojun mb_copy->m_pkthdr.len);
1554 1.2 itojun #else
1555 1.2 itojun if (mrt6debug & DEBUG_XMIT)
1556 1.2 itojun log(LOG_DEBUG,
1557 1.2 itojun "phyint_send: packet too big on %s%u o %s g %s"
1558 1.2 itojun " size %d(discarded)\n",
1559 1.2 itojun ifp->if_name, ifp->if_unit,
1560 1.2 itojun ip6_sprintf(&ip6->ip6_src),
1561 1.2 itojun ip6_sprintf(&ip6->ip6_dst),
1562 1.2 itojun mb_copy->m_pkthdr.len);
1563 1.2 itojun #endif /* __NetBSD__ */
1564 1.2 itojun #endif /* MRT6DEBUG */
1565 1.2 itojun m_freem(mb_copy); /* simply discard the packet */
1566 1.2 itojun return;
1567 1.2 itojun #endif
1568 1.2 itojun }
1569 1.2 itojun }
1570 1.2 itojun
1571 1.2 itojun static int
1572 1.2 itojun register_send(ip6, mif, m)
1573 1.2 itojun register struct ip6_hdr *ip6;
1574 1.2 itojun struct mif6 *mif;
1575 1.2 itojun register struct mbuf *m;
1576 1.2 itojun {
1577 1.2 itojun register struct mbuf *mm;
1578 1.2 itojun register int i, len = m->m_pkthdr.len;
1579 1.2 itojun static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
1580 1.2 itojun struct mrt6msg *im6;
1581 1.2 itojun
1582 1.2 itojun #ifdef MRT6DEBUG
1583 1.2 itojun if (mrt6debug)
1584 1.2 itojun log(LOG_DEBUG, "** IPv6 register_send **\n src %s dst %s\n",
1585 1.2 itojun ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst));
1586 1.2 itojun #endif
1587 1.2 itojun ++pim6stat.pim6s_snd_registers;
1588 1.2 itojun
1589 1.2 itojun /* Make a copy of the packet to send to the user level process */
1590 1.2 itojun MGETHDR(mm, M_DONTWAIT, MT_HEADER);
1591 1.2 itojun if (mm == NULL)
1592 1.2 itojun return ENOBUFS;
1593 1.2 itojun mm->m_data += max_linkhdr;
1594 1.2 itojun mm->m_len = sizeof(struct ip6_hdr);
1595 1.2 itojun
1596 1.2 itojun if ((mm->m_next = m_copy(m, 0, M_COPYALL)) == NULL) {
1597 1.2 itojun m_freem(mm);
1598 1.2 itojun return ENOBUFS;
1599 1.2 itojun }
1600 1.2 itojun i = MHLEN - M_LEADINGSPACE(mm);
1601 1.2 itojun if (i > len)
1602 1.2 itojun i = len;
1603 1.2 itojun mm = m_pullup(mm, i);
1604 1.2 itojun if (mm == NULL){
1605 1.2 itojun m_freem(mm);
1606 1.2 itojun return ENOBUFS;
1607 1.2 itojun }
1608 1.2 itojun /* TODO: check it! */
1609 1.2 itojun mm->m_pkthdr.len = len + sizeof(struct ip6_hdr);
1610 1.2 itojun
1611 1.2 itojun /*
1612 1.2 itojun * Send message to routing daemon
1613 1.2 itojun */
1614 1.2 itojun sin6.sin6_addr = ip6->ip6_src;
1615 1.2 itojun
1616 1.2 itojun im6 = mtod(mm, struct mrt6msg *);
1617 1.2 itojun im6->im6_msgtype = MRT6MSG_WHOLEPKT;
1618 1.2 itojun im6->im6_mbz = 0;
1619 1.2 itojun
1620 1.2 itojun im6->im6_mif = mif - mif6table;
1621 1.2 itojun
1622 1.2 itojun /* iif info is not given for reg. encap.n */
1623 1.2 itojun mrt6stat.mrt6s_upcalls++;
1624 1.2 itojun
1625 1.2 itojun if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1626 1.2 itojun #ifdef MRT6DEBUG
1627 1.2 itojun if (mrt6debug)
1628 1.2 itojun log(LOG_WARNING,
1629 1.2 itojun "register_send: ip_mrouter socket queue full\n");
1630 1.2 itojun #endif
1631 1.2 itojun ++mrt6stat.mrt6s_upq_sockfull;
1632 1.2 itojun return ENOBUFS;
1633 1.2 itojun }
1634 1.2 itojun return 0;
1635 1.2 itojun }
1636 1.2 itojun
1637 1.2 itojun /*
1638 1.2 itojun * PIM sparse mode hook
1639 1.2 itojun * Receives the pim control messages, and passes them up to the listening
1640 1.2 itojun * socket, using rip6_input.
1641 1.2 itojun * The only message processed is the REGISTER pim message; the pim header
1642 1.2 itojun * is stripped off, and the inner packet is passed to register_mforward.
1643 1.2 itojun */
1644 1.2 itojun int
1645 1.2 itojun pim6_input(mp, offp, proto)
1646 1.2 itojun struct mbuf **mp;
1647 1.2 itojun int *offp, proto;
1648 1.2 itojun {
1649 1.2 itojun register struct pim *pim; /* pointer to a pim struct */
1650 1.2 itojun register struct ip6_hdr *ip6;
1651 1.2 itojun register int pimlen;
1652 1.2 itojun struct mbuf *m = *mp;
1653 1.2 itojun int minlen;
1654 1.2 itojun int off = *offp;
1655 1.2 itojun
1656 1.2 itojun ++pim6stat.pim6s_rcv_total;
1657 1.2 itojun
1658 1.2 itojun ip6 = mtod(m, struct ip6_hdr *);
1659 1.2 itojun pimlen = m->m_pkthdr.len - *offp;
1660 1.2 itojun
1661 1.2 itojun /*
1662 1.2 itojun * Validate lengths
1663 1.2 itojun */
1664 1.2 itojun if (pimlen < PIM_MINLEN) {
1665 1.2 itojun ++pim6stat.pim6s_rcv_tooshort;
1666 1.2 itojun #ifdef MRT6DEBUG
1667 1.2 itojun if (mrt6debug & DEBUG_PIM)
1668 1.2 itojun log(LOG_DEBUG,"pim6_input: PIM packet too short\n");
1669 1.2 itojun #endif
1670 1.2 itojun m_freem(m);
1671 1.2 itojun return(IPPROTO_DONE);
1672 1.2 itojun }
1673 1.2 itojun
1674 1.2 itojun /*
1675 1.2 itojun * if the packet is at least as big as a REGISTER, go ahead
1676 1.2 itojun * and grab the PIM REGISTER header size, to avoid another
1677 1.2 itojun * possible m_pullup() later.
1678 1.2 itojun *
1679 1.2 itojun * PIM_MINLEN == pimhdr + u_int32 == 8
1680 1.2 itojun * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1681 1.2 itojun */
1682 1.2 itojun minlen = (pimlen >= PIM6_REG_MINLEN) ? PIM6_REG_MINLEN : PIM_MINLEN;
1683 1.2 itojun
1684 1.2 itojun /*
1685 1.2 itojun * Make sure that the IP6 and PIM headers in contiguous memory, and
1686 1.2 itojun * possibly the PIM REGISTER header
1687 1.2 itojun */
1688 1.8 itojun #ifndef PULLDOWN_TEST
1689 1.2 itojun IP6_EXTHDR_CHECK(m, off, minlen, IPPROTO_DONE);
1690 1.8 itojun /* adjust pointer */
1691 1.2 itojun ip6 = mtod(m, struct ip6_hdr *);
1692 1.2 itojun
1693 1.2 itojun /* adjust mbuf to point to the PIM header */
1694 1.2 itojun pim = (struct pim *)((caddr_t)ip6 + off);
1695 1.8 itojun #else
1696 1.8 itojun IP6_EXTHDR_GET(pim, struct pim *, m, off, minlen);
1697 1.8 itojun if (pim == NULL) {
1698 1.8 itojun pim6stat.pim6s_rcv_tooshort++;
1699 1.8 itojun return IPPROTO_DONE;
1700 1.8 itojun }
1701 1.8 itojun #endif
1702 1.2 itojun
1703 1.2 itojun #define PIM6_CHECKSUM
1704 1.2 itojun #ifdef PIM6_CHECKSUM
1705 1.2 itojun {
1706 1.2 itojun int cksumlen;
1707 1.2 itojun
1708 1.2 itojun /*
1709 1.2 itojun * Validate checksum.
1710 1.2 itojun * If PIM REGISTER, exclude the data packet
1711 1.2 itojun */
1712 1.2 itojun if (pim->pim_type == PIM_REGISTER)
1713 1.2 itojun cksumlen = PIM_MINLEN;
1714 1.2 itojun else
1715 1.2 itojun cksumlen = pimlen;
1716 1.2 itojun
1717 1.2 itojun if (in6_cksum(m, IPPROTO_PIM, off, cksumlen)) {
1718 1.2 itojun ++pim6stat.pim6s_rcv_badsum;
1719 1.2 itojun #ifdef MRT6DEBUG
1720 1.2 itojun if (mrt6debug & DEBUG_PIM)
1721 1.2 itojun log(LOG_DEBUG,
1722 1.2 itojun "pim6_input: invalid checksum\n");
1723 1.2 itojun #endif
1724 1.2 itojun m_freem(m);
1725 1.2 itojun return(IPPROTO_DONE);
1726 1.2 itojun }
1727 1.2 itojun }
1728 1.2 itojun #endif /* PIM_CHECKSUM */
1729 1.2 itojun
1730 1.2 itojun /* PIM version check */
1731 1.2 itojun if (pim->pim_ver != PIM_VERSION) {
1732 1.2 itojun ++pim6stat.pim6s_rcv_badversion;
1733 1.2 itojun #ifdef MRT6DEBUG
1734 1.2 itojun log(LOG_ERR,
1735 1.2 itojun "pim6_input: incorrect version %d, expecting %d\n",
1736 1.2 itojun pim->pim_ver, PIM_VERSION);
1737 1.2 itojun #endif
1738 1.2 itojun m_freem(m);
1739 1.2 itojun return(IPPROTO_DONE);
1740 1.2 itojun }
1741 1.2 itojun
1742 1.2 itojun if (pim->pim_type == PIM_REGISTER) {
1743 1.2 itojun /*
1744 1.2 itojun * since this is a REGISTER, we'll make a copy of the register
1745 1.7 itojun * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1746 1.2 itojun * routing daemon.
1747 1.2 itojun */
1748 1.2 itojun static struct sockaddr_in6 dst = { sizeof(dst), AF_INET6 };
1749 1.2 itojun
1750 1.2 itojun struct mbuf *mcp;
1751 1.2 itojun struct ip6_hdr *eip6;
1752 1.7 itojun u_int32_t *reghdr;
1753 1.2 itojun int rc;
1754 1.2 itojun
1755 1.2 itojun ++pim6stat.pim6s_rcv_registers;
1756 1.2 itojun
1757 1.2 itojun if ((reg_mif_num >= nummifs) || (reg_mif_num == (mifi_t) -1)) {
1758 1.2 itojun #ifdef MRT6DEBUG
1759 1.2 itojun if (mrt6debug & DEBUG_PIM)
1760 1.2 itojun log(LOG_DEBUG,
1761 1.2 itojun "pim6_input: register mif not set: %d\n",
1762 1.2 itojun reg_mif_num);
1763 1.2 itojun #endif
1764 1.2 itojun m_freem(m);
1765 1.2 itojun return(IPPROTO_DONE);
1766 1.2 itojun }
1767 1.2 itojun
1768 1.7 itojun reghdr = (u_int32_t *)(pim + 1);
1769 1.2 itojun
1770 1.2 itojun if ((ntohl(*reghdr) & PIM_NULL_REGISTER))
1771 1.2 itojun goto pim6_input_to_daemon;
1772 1.2 itojun
1773 1.2 itojun /*
1774 1.2 itojun * Validate length
1775 1.2 itojun */
1776 1.2 itojun if (pimlen < PIM6_REG_MINLEN) {
1777 1.2 itojun ++pim6stat.pim6s_rcv_tooshort;
1778 1.2 itojun ++pim6stat.pim6s_rcv_badregisters;
1779 1.2 itojun #ifdef MRT6DEBUG
1780 1.2 itojun log(LOG_ERR,
1781 1.2 itojun "pim6_input: register packet size too "
1782 1.2 itojun "small %d from %s\n",
1783 1.2 itojun pimlen, ip6_sprintf(&ip6->ip6_src));
1784 1.2 itojun #endif
1785 1.2 itojun m_freem(m);
1786 1.2 itojun return(IPPROTO_DONE);
1787 1.2 itojun }
1788 1.2 itojun
1789 1.2 itojun eip6 = (struct ip6_hdr *) (reghdr + 1);
1790 1.2 itojun #ifdef MRT6DEBUG
1791 1.2 itojun if (mrt6debug & DEBUG_PIM)
1792 1.2 itojun log(LOG_DEBUG,
1793 1.2 itojun "pim6_input[register], eip6: %s -> %s, "
1794 1.2 itojun "eip6 plen %d\n",
1795 1.2 itojun ip6_sprintf(&eip6->ip6_src),
1796 1.2 itojun ip6_sprintf(&eip6->ip6_dst),
1797 1.2 itojun ntohs(eip6->ip6_plen));
1798 1.2 itojun #endif
1799 1.2 itojun
1800 1.2 itojun /* verify the inner packet is destined to a mcast group */
1801 1.2 itojun if (!IN6_IS_ADDR_MULTICAST(&eip6->ip6_dst)) {
1802 1.2 itojun ++pim6stat.pim6s_rcv_badregisters;
1803 1.2 itojun #ifdef MRT6DEBUG
1804 1.2 itojun if (mrt6debug & DEBUG_PIM)
1805 1.2 itojun log(LOG_DEBUG,
1806 1.2 itojun "pim6_input: inner packet of register "
1807 1.2 itojun "is not multicast %s\n",
1808 1.2 itojun ip6_sprintf(&eip6->ip6_dst));
1809 1.2 itojun #endif
1810 1.2 itojun m_freem(m);
1811 1.2 itojun return(IPPROTO_DONE);
1812 1.2 itojun }
1813 1.2 itojun
1814 1.2 itojun /*
1815 1.2 itojun * make a copy of the whole header to pass to the daemon later.
1816 1.2 itojun */
1817 1.2 itojun mcp = m_copy(m, 0, off + PIM6_REG_MINLEN);
1818 1.2 itojun if (mcp == NULL) {
1819 1.2 itojun #ifdef MRT6DEBUG
1820 1.2 itojun log(LOG_ERR,
1821 1.2 itojun "pim6_input: pim register: "
1822 1.2 itojun "could not copy register head\n");
1823 1.2 itojun #endif
1824 1.2 itojun m_freem(m);
1825 1.2 itojun return(IPPROTO_DONE);
1826 1.2 itojun }
1827 1.2 itojun
1828 1.2 itojun /*
1829 1.2 itojun * forward the inner ip6 packet; point m_data at the inner ip6.
1830 1.2 itojun */
1831 1.2 itojun m_adj(m, off + PIM_MINLEN);
1832 1.2 itojun #ifdef MRT6DEBUG
1833 1.2 itojun if (mrt6debug & DEBUG_PIM) {
1834 1.2 itojun log(LOG_DEBUG,
1835 1.2 itojun "pim6_input: forwarding decapsulated register: "
1836 1.2 itojun "src %s, dst %s, mif %d\n",
1837 1.2 itojun ip6_sprintf(&eip6->ip6_src),
1838 1.2 itojun ip6_sprintf(&eip6->ip6_dst),
1839 1.2 itojun reg_mif_num);
1840 1.2 itojun }
1841 1.2 itojun #endif
1842 1.2 itojun
1843 1.2 itojun rc = looutput(mif6table[reg_mif_num].m6_ifp, m,
1844 1.2 itojun (struct sockaddr *) &dst,
1845 1.2 itojun (struct rtentry *) NULL);
1846 1.2 itojun
1847 1.2 itojun /* prepare the register head to send to the mrouting daemon */
1848 1.2 itojun m = mcp;
1849 1.2 itojun }
1850 1.2 itojun
1851 1.2 itojun /*
1852 1.2 itojun * Pass the PIM message up to the daemon; if it is a register message
1853 1.2 itojun * pass the 'head' only up to the daemon. This includes the
1854 1.2 itojun * encapsulator ip6 header, pim header, register header and the
1855 1.2 itojun * encapsulated ip6 header.
1856 1.2 itojun */
1857 1.2 itojun pim6_input_to_daemon:
1858 1.2 itojun rip6_input(&m, offp, proto);
1859 1.2 itojun return(IPPROTO_DONE);
1860 1.2 itojun }
1861