Home | History | Annotate | Line # | Download | only in netinet6
mld6.c revision 1.61.2.6
      1  1.61.2.6     skrll /*	$NetBSD: mld6.c,v 1.61.2.6 2016/12/05 10:55:28 skrll Exp $	*/
      2      1.13    itojun /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
      3       1.3   thorpej 
      4       1.2    itojun /*
      5       1.2    itojun  * Copyright (C) 1998 WIDE Project.
      6       1.2    itojun  * All rights reserved.
      7      1.13    itojun  *
      8       1.2    itojun  * Redistribution and use in source and binary forms, with or without
      9       1.2    itojun  * modification, are permitted provided that the following conditions
     10       1.2    itojun  * are met:
     11       1.2    itojun  * 1. Redistributions of source code must retain the above copyright
     12       1.2    itojun  *    notice, this list of conditions and the following disclaimer.
     13       1.2    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.2    itojun  *    notice, this list of conditions and the following disclaimer in the
     15       1.2    itojun  *    documentation and/or other materials provided with the distribution.
     16       1.2    itojun  * 3. Neither the name of the project nor the names of its contributors
     17       1.2    itojun  *    may be used to endorse or promote products derived from this software
     18       1.2    itojun  *    without specific prior written permission.
     19      1.13    itojun  *
     20       1.2    itojun  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     21       1.2    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22       1.2    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23       1.2    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     24       1.2    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25       1.2    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26       1.2    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27       1.2    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28       1.2    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29       1.2    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30       1.2    itojun  * SUCH DAMAGE.
     31       1.2    itojun  */
     32       1.2    itojun 
     33       1.2    itojun /*
     34       1.2    itojun  * Copyright (c) 1992, 1993
     35       1.2    itojun  *	The Regents of the University of California.  All rights reserved.
     36       1.2    itojun  *
     37       1.2    itojun  * This code is derived from software contributed to Berkeley by
     38       1.2    itojun  * Stephen Deering of Stanford University.
     39       1.2    itojun  *
     40       1.2    itojun  * Redistribution and use in source and binary forms, with or without
     41       1.2    itojun  * modification, are permitted provided that the following conditions
     42       1.2    itojun  * are met:
     43       1.2    itojun  * 1. Redistributions of source code must retain the above copyright
     44       1.2    itojun  *    notice, this list of conditions and the following disclaimer.
     45       1.2    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     46       1.2    itojun  *    notice, this list of conditions and the following disclaimer in the
     47       1.2    itojun  *    documentation and/or other materials provided with the distribution.
     48      1.23       agc  * 3. Neither the name of the University nor the names of its contributors
     49      1.23       agc  *    may be used to endorse or promote products derived from this software
     50      1.23       agc  *    without specific prior written permission.
     51      1.23       agc  *
     52      1.23       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53      1.23       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54      1.23       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55      1.23       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56      1.23       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57      1.23       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58      1.23       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59      1.23       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60      1.23       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61      1.23       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62      1.23       agc  * SUCH DAMAGE.
     63      1.23       agc  *
     64      1.23       agc  *	@(#)igmp.c	8.1 (Berkeley) 7/19/93
     65      1.23       agc  */
     66      1.23       agc 
     67      1.23       agc /*
     68      1.23       agc  * Copyright (c) 1988 Stephen Deering.
     69      1.23       agc  *
     70      1.23       agc  * This code is derived from software contributed to Berkeley by
     71      1.23       agc  * Stephen Deering of Stanford University.
     72      1.23       agc  *
     73      1.23       agc  * Redistribution and use in source and binary forms, with or without
     74      1.23       agc  * modification, are permitted provided that the following conditions
     75      1.23       agc  * are met:
     76      1.23       agc  * 1. Redistributions of source code must retain the above copyright
     77      1.23       agc  *    notice, this list of conditions and the following disclaimer.
     78      1.23       agc  * 2. Redistributions in binary form must reproduce the above copyright
     79      1.23       agc  *    notice, this list of conditions and the following disclaimer in the
     80      1.23       agc  *    documentation and/or other materials provided with the distribution.
     81       1.2    itojun  * 3. All advertising materials mentioning features or use of this software
     82       1.2    itojun  *    must display the following acknowledgement:
     83       1.2    itojun  *	This product includes software developed by the University of
     84       1.2    itojun  *	California, Berkeley and its contributors.
     85       1.2    itojun  * 4. Neither the name of the University nor the names of its contributors
     86       1.2    itojun  *    may be used to endorse or promote products derived from this software
     87       1.2    itojun  *    without specific prior written permission.
     88       1.2    itojun  *
     89       1.2    itojun  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     90       1.2    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     91       1.2    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     92       1.2    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     93       1.2    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     94       1.2    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     95       1.2    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     96       1.2    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     97       1.2    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     98       1.2    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     99       1.2    itojun  * SUCH DAMAGE.
    100       1.2    itojun  *
    101       1.2    itojun  *	@(#)igmp.c	8.1 (Berkeley) 7/19/93
    102       1.2    itojun  */
    103      1.16     lukem 
    104      1.16     lukem #include <sys/cdefs.h>
    105  1.61.2.6     skrll __KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.61.2.6 2016/12/05 10:55:28 skrll Exp $");
    106       1.2    itojun 
    107  1.61.2.2     skrll #ifdef _KERNEL_OPT
    108       1.2    itojun #include "opt_inet.h"
    109  1.61.2.6     skrll #include "opt_net_mpsafe.h"
    110  1.61.2.2     skrll #endif
    111       1.2    itojun 
    112       1.2    itojun #include <sys/param.h>
    113       1.2    itojun #include <sys/systm.h>
    114       1.2    itojun #include <sys/mbuf.h>
    115       1.2    itojun #include <sys/socket.h>
    116      1.45        ad #include <sys/socketvar.h>
    117       1.2    itojun #include <sys/protosw.h>
    118       1.2    itojun #include <sys/syslog.h>
    119      1.31    rpaulo #include <sys/sysctl.h>
    120      1.31    rpaulo #include <sys/kernel.h>
    121      1.31    rpaulo #include <sys/callout.h>
    122      1.55       tls #include <sys/cprng.h>
    123       1.2    itojun 
    124       1.2    itojun #include <net/if.h>
    125       1.2    itojun 
    126       1.2    itojun #include <netinet/in.h>
    127       1.2    itojun #include <netinet/in_var.h>
    128      1.31    rpaulo #include <netinet6/in6_var.h>
    129      1.10    itojun #include <netinet/ip6.h>
    130       1.2    itojun #include <netinet6/ip6_var.h>
    131      1.29    rpaulo #include <netinet6/scope6_var.h>
    132      1.10    itojun #include <netinet/icmp6.h>
    133      1.44   thorpej #include <netinet6/icmp6_private.h>
    134       1.2    itojun #include <netinet6/mld6_var.h>
    135       1.2    itojun 
    136       1.7    itojun #include <net/net_osdep.h>
    137       1.7    itojun 
    138      1.31    rpaulo 
    139      1.31    rpaulo /*
    140      1.31    rpaulo  * This structure is used to keep track of in6_multi chains which belong to
    141      1.31    rpaulo  * deleted interface addresses.
    142      1.31    rpaulo  */
    143      1.56     joerg static LIST_HEAD(, multi6_kludge) in6_mk = LIST_HEAD_INITIALIZER(in6_mk);
    144      1.31    rpaulo 
    145      1.31    rpaulo struct multi6_kludge {
    146      1.31    rpaulo 	LIST_ENTRY(multi6_kludge) mk_entry;
    147      1.31    rpaulo 	struct ifnet *mk_ifp;
    148      1.31    rpaulo 	struct in6_multihead mk_head;
    149      1.31    rpaulo };
    150      1.31    rpaulo 
    151      1.31    rpaulo 
    152       1.2    itojun /*
    153       1.2    itojun  * Protocol constants
    154       1.2    itojun  */
    155       1.2    itojun 
    156       1.2    itojun /*
    157       1.2    itojun  * time between repetitions of a node's initial report of interest in a
    158       1.2    itojun  * multicast address(in seconds)
    159       1.2    itojun  */
    160      1.22    itojun #define MLD_UNSOLICITED_REPORT_INTERVAL	10
    161       1.2    itojun 
    162       1.2    itojun static struct ip6_pktopts ip6_opts;
    163       1.2    itojun 
    164      1.31    rpaulo static void mld_start_listening(struct in6_multi *);
    165      1.31    rpaulo static void mld_stop_listening(struct in6_multi *);
    166      1.31    rpaulo 
    167      1.31    rpaulo static struct mld_hdr * mld_allocbuf(struct mbuf **, int, struct in6_multi *,
    168      1.31    rpaulo 	int);
    169      1.31    rpaulo static void mld_sendpkt(struct in6_multi *, int, const struct in6_addr *);
    170      1.31    rpaulo static void mld_starttimer(struct in6_multi *);
    171      1.31    rpaulo static void mld_stoptimer(struct in6_multi *);
    172      1.31    rpaulo static u_long mld_timerresid(struct in6_multi *);
    173       1.2    itojun 
    174       1.2    itojun void
    175      1.42      matt mld_init(void)
    176       1.2    itojun {
    177       1.2    itojun 	static u_int8_t hbh_buf[8];
    178       1.2    itojun 	struct ip6_hbh *hbh = (struct ip6_hbh *)hbh_buf;
    179       1.2    itojun 	u_int16_t rtalert_code = htons((u_int16_t)IP6OPT_RTALERT_MLD);
    180       1.2    itojun 
    181       1.2    itojun 	/* ip6h_nxt will be fill in later */
    182      1.11    itojun 	hbh->ip6h_len = 0;	/* (8 >> 3) - 1 */
    183       1.2    itojun 
    184       1.2    itojun 	/* XXX: grotty hard coding... */
    185       1.2    itojun 	hbh_buf[2] = IP6OPT_PADN;	/* 2 byte padding */
    186       1.2    itojun 	hbh_buf[3] = 0;
    187       1.2    itojun 	hbh_buf[4] = IP6OPT_RTALERT;
    188       1.2    itojun 	hbh_buf[5] = IP6OPT_RTALERT_LEN - 2;
    189      1.50   tsutsui 	memcpy(&hbh_buf[6], (void *)&rtalert_code, sizeof(u_int16_t));
    190       1.2    itojun 
    191       1.2    itojun 	ip6_opts.ip6po_hbh = hbh;
    192       1.2    itojun 	/* We will specify the hoplimit by a multicast option. */
    193       1.2    itojun 	ip6_opts.ip6po_hlim = -1;
    194  1.61.2.1     skrll 	ip6_opts.ip6po_prefer_tempaddr = IP6PO_TEMPADDR_NOTPREFER;
    195       1.2    itojun }
    196       1.2    itojun 
    197      1.31    rpaulo static void
    198      1.38  christos mld_starttimer(struct in6_multi *in6m)
    199      1.31    rpaulo {
    200      1.31    rpaulo 	struct timeval now;
    201      1.31    rpaulo 
    202      1.61     ozaki 	KASSERT(in6m->in6m_timer != IN6M_TIMER_UNDEF);
    203      1.61     ozaki 
    204      1.31    rpaulo 	microtime(&now);
    205      1.31    rpaulo 	in6m->in6m_timer_expire.tv_sec = now.tv_sec + in6m->in6m_timer / hz;
    206      1.31    rpaulo 	in6m->in6m_timer_expire.tv_usec = now.tv_usec +
    207      1.31    rpaulo 	    (in6m->in6m_timer % hz) * (1000000 / hz);
    208      1.31    rpaulo 	if (in6m->in6m_timer_expire.tv_usec > 1000000) {
    209      1.31    rpaulo 		in6m->in6m_timer_expire.tv_sec++;
    210      1.31    rpaulo 		in6m->in6m_timer_expire.tv_usec -= 1000000;
    211      1.31    rpaulo 	}
    212      1.31    rpaulo 
    213      1.31    rpaulo 	/* start or restart the timer */
    214      1.41     joerg 	callout_schedule(&in6m->in6m_timer_ch, in6m->in6m_timer);
    215      1.31    rpaulo }
    216      1.31    rpaulo 
    217      1.31    rpaulo static void
    218      1.38  christos mld_stoptimer(struct in6_multi *in6m)
    219      1.31    rpaulo {
    220      1.31    rpaulo 	if (in6m->in6m_timer == IN6M_TIMER_UNDEF)
    221      1.31    rpaulo 		return;
    222      1.31    rpaulo 
    223      1.41     joerg 	callout_stop(&in6m->in6m_timer_ch);
    224      1.31    rpaulo 
    225      1.31    rpaulo 	in6m->in6m_timer = IN6M_TIMER_UNDEF;
    226      1.31    rpaulo }
    227      1.31    rpaulo 
    228      1.31    rpaulo static void
    229      1.41     joerg mld_timeo(void *arg)
    230      1.31    rpaulo {
    231      1.41     joerg 	struct in6_multi *in6m = arg;
    232      1.45        ad 
    233      1.45        ad 	mutex_enter(softnet_lock);
    234      1.45        ad 	KERNEL_LOCK(1, NULL);
    235      1.31    rpaulo 
    236      1.61     ozaki 	if (in6m->in6m_timer == IN6M_TIMER_UNDEF)
    237      1.61     ozaki 		goto out;
    238      1.61     ozaki 
    239      1.31    rpaulo 	in6m->in6m_timer = IN6M_TIMER_UNDEF;
    240      1.31    rpaulo 
    241      1.31    rpaulo 	switch (in6m->in6m_state) {
    242      1.31    rpaulo 	case MLD_REPORTPENDING:
    243      1.31    rpaulo 		mld_start_listening(in6m);
    244      1.31    rpaulo 		break;
    245      1.31    rpaulo 	default:
    246      1.31    rpaulo 		mld_sendpkt(in6m, MLD_LISTENER_REPORT, NULL);
    247      1.31    rpaulo 		break;
    248      1.31    rpaulo 	}
    249      1.31    rpaulo 
    250      1.61     ozaki out:
    251      1.45        ad 	KERNEL_UNLOCK_ONE(NULL);
    252      1.45        ad 	mutex_exit(softnet_lock);
    253      1.31    rpaulo }
    254      1.31    rpaulo 
    255      1.31    rpaulo static u_long
    256      1.38  christos mld_timerresid(struct in6_multi *in6m)
    257      1.31    rpaulo {
    258      1.31    rpaulo 	struct timeval now, diff;
    259      1.31    rpaulo 
    260      1.31    rpaulo 	microtime(&now);
    261      1.31    rpaulo 
    262      1.31    rpaulo 	if (now.tv_sec > in6m->in6m_timer_expire.tv_sec ||
    263      1.31    rpaulo 	    (now.tv_sec == in6m->in6m_timer_expire.tv_sec &&
    264      1.31    rpaulo 	    now.tv_usec > in6m->in6m_timer_expire.tv_usec)) {
    265      1.31    rpaulo 		return (0);
    266      1.31    rpaulo 	}
    267      1.31    rpaulo 	diff = in6m->in6m_timer_expire;
    268      1.31    rpaulo 	diff.tv_sec -= now.tv_sec;
    269      1.31    rpaulo 	diff.tv_usec -= now.tv_usec;
    270      1.31    rpaulo 	if (diff.tv_usec < 0) {
    271      1.31    rpaulo 		diff.tv_sec--;
    272      1.31    rpaulo 		diff.tv_usec += 1000000;
    273      1.31    rpaulo 	}
    274      1.31    rpaulo 
    275      1.31    rpaulo 	/* return the remaining time in milliseconds */
    276      1.47   adrianp 	return diff.tv_sec * 1000 + diff.tv_usec / 1000;
    277      1.31    rpaulo }
    278      1.31    rpaulo 
    279      1.31    rpaulo static void
    280      1.38  christos mld_start_listening(struct in6_multi *in6m)
    281       1.2    itojun {
    282      1.29    rpaulo 	struct in6_addr all_in6;
    283      1.29    rpaulo 
    284       1.2    itojun 	/*
    285      1.11    itojun 	 * RFC2710 page 10:
    286       1.2    itojun 	 * The node never sends a Report or Done for the link-scope all-nodes
    287       1.2    itojun 	 * address.
    288       1.2    itojun 	 * MLD messages are never sent for multicast addresses whose scope is 0
    289       1.2    itojun 	 * (reserved) or 1 (node-local).
    290       1.2    itojun 	 */
    291      1.29    rpaulo 	all_in6 = in6addr_linklocal_allnodes;
    292      1.29    rpaulo 	if (in6_setscope(&all_in6, in6m->in6m_ifp, NULL)) {
    293      1.29    rpaulo 		/* XXX: this should not happen! */
    294      1.29    rpaulo 		in6m->in6m_timer = 0;
    295      1.29    rpaulo 		in6m->in6m_state = MLD_OTHERLISTENER;
    296      1.29    rpaulo 	}
    297      1.29    rpaulo 	if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr, &all_in6) ||
    298       1.2    itojun 	    IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) {
    299      1.31    rpaulo 		in6m->in6m_timer = IN6M_TIMER_UNDEF;
    300      1.22    itojun 		in6m->in6m_state = MLD_OTHERLISTENER;
    301       1.2    itojun 	} else {
    302      1.31    rpaulo 		mld_sendpkt(in6m, MLD_LISTENER_REPORT, NULL);
    303      1.55       tls 		in6m->in6m_timer = cprng_fast32() %
    304      1.31    rpaulo 		    (MLD_UNSOLICITED_REPORT_INTERVAL * hz);
    305      1.22    itojun 		in6m->in6m_state = MLD_IREPORTEDLAST;
    306      1.31    rpaulo 
    307      1.31    rpaulo 		mld_starttimer(in6m);
    308       1.2    itojun 	}
    309       1.2    itojun }
    310       1.2    itojun 
    311      1.31    rpaulo static void
    312      1.38  christos mld_stop_listening(struct in6_multi *in6m)
    313       1.2    itojun {
    314      1.29    rpaulo 	struct in6_addr allnode, allrouter;
    315      1.29    rpaulo 
    316      1.29    rpaulo 	allnode = in6addr_linklocal_allnodes;
    317      1.29    rpaulo 	if (in6_setscope(&allnode, in6m->in6m_ifp, NULL)) {
    318      1.29    rpaulo 		/* XXX: this should not happen! */
    319      1.29    rpaulo 		return;
    320      1.29    rpaulo 	}
    321      1.29    rpaulo 	allrouter = in6addr_linklocal_allrouters;
    322      1.29    rpaulo 	if (in6_setscope(&allrouter, in6m->in6m_ifp, NULL)) {
    323      1.29    rpaulo 		/* XXX impossible */
    324      1.29    rpaulo 		return;
    325      1.29    rpaulo 	}
    326       1.2    itojun 
    327      1.22    itojun 	if (in6m->in6m_state == MLD_IREPORTEDLAST &&
    328      1.29    rpaulo 	    (!IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr, &allnode)) &&
    329      1.29    rpaulo 	    IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) >
    330      1.29    rpaulo 	    IPV6_ADDR_SCOPE_INTFACELOCAL) {
    331      1.31    rpaulo 		mld_sendpkt(in6m, MLD_LISTENER_DONE, &allrouter);
    332      1.29    rpaulo 	}
    333       1.2    itojun }
    334       1.2    itojun 
    335       1.2    itojun void
    336      1.38  christos mld_input(struct mbuf *m, int off)
    337       1.2    itojun {
    338      1.52  dholland 	struct ip6_hdr *ip6;
    339      1.22    itojun 	struct mld_hdr *mldh;
    340  1.61.2.4     skrll 	struct ifnet *ifp;
    341      1.31    rpaulo 	struct in6_multi *in6m = NULL;
    342      1.29    rpaulo 	struct in6_addr mld_addr, all_in6;
    343       1.2    itojun 	struct in6_ifaddr *ia;
    344      1.47   adrianp 	u_long timer = 0;	/* timer value in the MLD query header */
    345  1.61.2.4     skrll 	int s;
    346       1.2    itojun 
    347  1.61.2.4     skrll 	ifp = m_get_rcvif(m, &s);
    348      1.22    itojun 	IP6_EXTHDR_GET(mldh, struct mld_hdr *, m, off, sizeof(*mldh));
    349      1.13    itojun 	if (mldh == NULL) {
    350      1.44   thorpej 		ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
    351  1.61.2.4     skrll 		goto out_nodrop;
    352      1.13    itojun 	}
    353      1.13    itojun 
    354       1.2    itojun 	/* source address validation */
    355      1.13    itojun 	ip6 = mtod(m, struct ip6_hdr *);/* in case mpullup */
    356       1.2    itojun 	if (!IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src)) {
    357      1.31    rpaulo 		/*
    358      1.31    rpaulo 		 * RFC3590 allows the IPv6 unspecified address as the source
    359      1.31    rpaulo 		 * address of MLD report and done messages.  However, as this
    360      1.31    rpaulo 		 * same document says, this special rule is for snooping
    361      1.31    rpaulo 		 * switches and the RFC requires routers to discard MLD packets
    362      1.31    rpaulo 		 * with the unspecified source address.  The RFC only talks
    363      1.31    rpaulo 		 * about hosts receiving an MLD query or report in Security
    364      1.31    rpaulo 		 * Considerations, but this is probably the correct intention.
    365      1.31    rpaulo 		 * RFC3590 does not talk about other cases than link-local and
    366      1.31    rpaulo 		 * the unspecified source addresses, but we believe the same
    367      1.31    rpaulo 		 * rule should be applied.
    368      1.31    rpaulo 		 * As a result, we only allow link-local addresses as the
    369      1.31    rpaulo 		 * source address; otherwise, simply discard the packet.
    370      1.31    rpaulo 		 */
    371      1.18    itojun #if 0
    372      1.31    rpaulo 		/*
    373      1.31    rpaulo 		 * XXX: do not log in an input path to avoid log flooding,
    374      1.31    rpaulo 		 * though RFC3590 says "SHOULD log" if the source of a query
    375      1.31    rpaulo 		 * is the unspecified address.
    376      1.31    rpaulo 		 */
    377      1.31    rpaulo 		log(LOG_INFO,
    378      1.22    itojun 		    "mld_input: src %s is not link-local (grp=%s)\n",
    379      1.31    rpaulo 		    ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&mldh->mld_addr));
    380      1.18    itojun #endif
    381  1.61.2.4     skrll 		goto out;
    382       1.2    itojun 	}
    383       1.2    itojun 
    384       1.2    itojun 	/*
    385      1.29    rpaulo 	 * make a copy for local work (in6_setscope() may modify the 1st arg)
    386      1.29    rpaulo 	 */
    387      1.29    rpaulo 	mld_addr = mldh->mld_addr;
    388      1.29    rpaulo 	if (in6_setscope(&mld_addr, ifp, NULL)) {
    389      1.29    rpaulo 		/* XXX: this should not happen! */
    390  1.61.2.4     skrll 		goto out;
    391      1.29    rpaulo 	}
    392      1.29    rpaulo 
    393      1.29    rpaulo 	/*
    394      1.31    rpaulo 	 * In the MLD specification, there are 3 states and a flag.
    395       1.2    itojun 	 *
    396       1.2    itojun 	 * In Non-Listener state, we simply don't have a membership record.
    397       1.2    itojun 	 * In Delaying Listener state, our timer is running (in6m->in6m_timer)
    398  1.61.2.2     skrll 	 * In Idle Listener state, our timer is not running
    399      1.31    rpaulo 	 * (in6m->in6m_timer==IN6M_TIMER_UNDEF)
    400       1.2    itojun 	 *
    401      1.22    itojun 	 * The flag is in6m->in6m_state, it is set to MLD_OTHERLISTENER if
    402      1.22    itojun 	 * we have heard a report from another member, or MLD_IREPORTEDLAST
    403       1.2    itojun 	 * if we sent the last report.
    404       1.2    itojun 	 */
    405      1.22    itojun 	switch (mldh->mld_type) {
    406  1.61.2.5     skrll 	case MLD_LISTENER_QUERY: {
    407  1.61.2.5     skrll 		struct psref psref;
    408  1.61.2.5     skrll 
    409       1.7    itojun 		if (ifp->if_flags & IFF_LOOPBACK)
    410       1.7    itojun 			break;
    411       1.7    itojun 
    412      1.29    rpaulo 		if (!IN6_IS_ADDR_UNSPECIFIED(&mld_addr) &&
    413      1.29    rpaulo 		    !IN6_IS_ADDR_MULTICAST(&mld_addr))
    414       1.7    itojun 			break;	/* print error or log stat? */
    415      1.29    rpaulo 
    416      1.29    rpaulo 		all_in6 = in6addr_linklocal_allnodes;
    417      1.29    rpaulo 		if (in6_setscope(&all_in6, ifp, NULL)) {
    418      1.29    rpaulo 			/* XXX: this should not happen! */
    419      1.29    rpaulo 			break;
    420      1.29    rpaulo 		}
    421       1.2    itojun 
    422       1.7    itojun 		/*
    423      1.11    itojun 		 * - Start the timers in all of our membership records
    424      1.11    itojun 		 *   that the query applies to for the interface on
    425      1.11    itojun 		 *   which the query arrived excl. those that belong
    426      1.11    itojun 		 *   to the "all-nodes" group (ff02::1).
    427      1.11    itojun 		 * - Restart any timer that is already running but has
    428      1.30    rpaulo 		 *   a value longer than the requested timeout.
    429      1.11    itojun 		 * - Use the value specified in the query message as
    430      1.11    itojun 		 *   the maximum timeout.
    431      1.11    itojun 		 */
    432      1.31    rpaulo 		timer = ntohs(mldh->mld_maxdelay);
    433      1.31    rpaulo 
    434  1.61.2.5     skrll 		ia = in6_get_ia_from_ifp_psref(ifp, &psref);
    435       1.7    itojun 		if (ia == NULL)
    436       1.7    itojun 			break;
    437       1.2    itojun 
    438  1.61.2.5     skrll 		/* The following operations may sleep */
    439  1.61.2.5     skrll 		m_put_rcvif(ifp, &s);
    440  1.61.2.5     skrll 		ifp = NULL;
    441  1.61.2.5     skrll 
    442      1.35    dyoung 		LIST_FOREACH(in6m, &ia->ia6_multiaddrs, in6m_entry) {
    443      1.29    rpaulo 			if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr, &all_in6) ||
    444       1.7    itojun 			    IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) <
    445       1.7    itojun 			    IPV6_ADDR_SCOPE_LINKLOCAL)
    446       1.7    itojun 				continue;
    447       1.2    itojun 
    448      1.31    rpaulo 			if (in6m->in6m_state == MLD_REPORTPENDING)
    449      1.31    rpaulo 				continue; /* we are not yet ready */
    450      1.31    rpaulo 
    451      1.31    rpaulo 			if (!IN6_IS_ADDR_UNSPECIFIED(&mld_addr) &&
    452      1.31    rpaulo 			    !IN6_ARE_ADDR_EQUAL(&mld_addr, &in6m->in6m_addr))
    453      1.31    rpaulo 				continue;
    454      1.31    rpaulo 
    455      1.31    rpaulo 			if (timer == 0) {
    456      1.31    rpaulo 				/* send a report immediately */
    457      1.31    rpaulo 				mld_stoptimer(in6m);
    458      1.31    rpaulo 				mld_sendpkt(in6m, MLD_LISTENER_REPORT, NULL);
    459      1.31    rpaulo 				in6m->in6m_state = MLD_IREPORTEDLAST;
    460      1.31    rpaulo 			} else if (in6m->in6m_timer == IN6M_TIMER_UNDEF ||
    461      1.47   adrianp 			    mld_timerresid(in6m) > timer) {
    462      1.47   adrianp 				in6m->in6m_timer =
    463      1.55       tls 				   1 + (cprng_fast32() % timer) * hz / 1000;
    464      1.31    rpaulo 				mld_starttimer(in6m);
    465       1.7    itojun 			}
    466       1.7    itojun 		}
    467  1.61.2.5     skrll 		ia6_release(ia, &psref);
    468      1.29    rpaulo 		break;
    469  1.61.2.5     skrll 	    }
    470       1.2    itojun 
    471      1.22    itojun 	case MLD_LISTENER_REPORT:
    472       1.2    itojun 		/*
    473      1.11    itojun 		 * For fast leave to work, we have to know that we are the
    474      1.11    itojun 		 * last person to send a report for this group.  Reports
    475      1.11    itojun 		 * can potentially get looped back if we are a multicast
    476      1.11    itojun 		 * router, so discard reports sourced by me.
    477      1.11    itojun 		 * Note that it is impossible to check IFF_LOOPBACK flag of
    478      1.11    itojun 		 * ifp for this purpose, since ip6_mloopback pass the physical
    479      1.11    itojun 		 * interface to looutput.
    480      1.11    itojun 		 */
    481       1.7    itojun 		if (m->m_flags & M_LOOP) /* XXX: grotty flag, but efficient */
    482       1.7    itojun 			break;
    483       1.7    itojun 
    484      1.22    itojun 		if (!IN6_IS_ADDR_MULTICAST(&mldh->mld_addr))
    485       1.7    itojun 			break;
    486       1.7    itojun 
    487       1.7    itojun 		/*
    488      1.11    itojun 		 * If we belong to the group being reported, stop
    489      1.11    itojun 		 * our timer for that group.
    490      1.11    itojun 		 */
    491      1.29    rpaulo 		IN6_LOOKUP_MULTI(mld_addr, ifp, in6m);
    492       1.7    itojun 		if (in6m) {
    493      1.31    rpaulo 			mld_stoptimer(in6m); /* transit to idle state */
    494      1.22    itojun 			in6m->in6m_state = MLD_OTHERLISTENER; /* clear flag */
    495       1.7    itojun 		}
    496       1.7    itojun 		break;
    497       1.7    itojun 	default:		/* this is impossible */
    498      1.18    itojun #if 0
    499      1.19    itojun 		/*
    500      1.19    itojun 		 * this case should be impossible because of filtering in
    501      1.19    itojun 		 * icmp6_input().  But we explicitly disabled this part
    502      1.19    itojun 		 * just in case.
    503      1.19    itojun 		 */
    504      1.31    rpaulo 		log(LOG_ERR, "mld_input: illegal type(%d)", mldh->mld_type);
    505      1.18    itojun #endif
    506       1.7    itojun 		break;
    507       1.2    itojun 	}
    508      1.11    itojun 
    509  1.61.2.4     skrll out:
    510      1.11    itojun 	m_freem(m);
    511  1.61.2.4     skrll out_nodrop:
    512  1.61.2.4     skrll 	m_put_rcvif(ifp, &s);
    513       1.2    itojun }
    514       1.2    itojun 
    515       1.2    itojun static void
    516  1.61.2.2     skrll mld_sendpkt(struct in6_multi *in6m, int type,
    517      1.38  christos 	const struct in6_addr *dst)
    518       1.2    itojun {
    519      1.31    rpaulo 	struct mbuf *mh;
    520      1.22    itojun 	struct mld_hdr *mldh;
    521      1.31    rpaulo 	struct ip6_hdr *ip6 = NULL;
    522       1.2    itojun 	struct ip6_moptions im6o;
    523      1.31    rpaulo 	struct in6_ifaddr *ia = NULL;
    524       1.2    itojun 	struct ifnet *ifp = in6m->in6m_ifp;
    525      1.19    itojun 	int ignflags;
    526  1.61.2.5     skrll 	struct psref psref;
    527  1.61.2.5     skrll 	int bound;
    528       1.2    itojun 
    529       1.2    itojun 	/*
    530       1.2    itojun 	 * At first, find a link local address on the outgoing interface
    531       1.2    itojun 	 * to use as the source address of the MLD packet.
    532      1.19    itojun 	 * We do not reject tentative addresses for MLD report to deal with
    533      1.19    itojun 	 * the case where we first join a link-local address.
    534       1.2    itojun 	 */
    535      1.19    itojun 	ignflags = (IN6_IFF_NOTREADY|IN6_IFF_ANYCAST) & ~IN6_IFF_TENTATIVE;
    536  1.61.2.5     skrll 	bound = curlwp_bind();
    537  1.61.2.5     skrll 	ia = in6ifa_ifpforlinklocal_psref(ifp, ignflags, &psref);
    538  1.61.2.5     skrll 	if (ia == NULL) {
    539  1.61.2.5     skrll 		curlwp_bindx(bound);
    540       1.2    itojun 		return;
    541  1.61.2.5     skrll 	}
    542  1.61.2.5     skrll 	if ((ia->ia6_flags & IN6_IFF_TENTATIVE)) {
    543  1.61.2.5     skrll 		ia6_release(ia, &psref);
    544      1.19    itojun 		ia = NULL;
    545  1.61.2.5     skrll 	}
    546       1.2    itojun 
    547      1.31    rpaulo 	/* Allocate two mbufs to store IPv6 header and MLD header */
    548      1.31    rpaulo 	mldh = mld_allocbuf(&mh, sizeof(struct mld_hdr), in6m, type);
    549  1.61.2.5     skrll 	if (mldh == NULL) {
    550  1.61.2.5     skrll 		ia6_release(ia, &psref);
    551  1.61.2.5     skrll 		curlwp_bindx(bound);
    552       1.2    itojun 		return;
    553  1.61.2.5     skrll 	}
    554       1.2    itojun 
    555      1.31    rpaulo 	/* fill src/dst here */
    556      1.31    rpaulo  	ip6 = mtod(mh, struct ip6_hdr *);
    557      1.31    rpaulo  	ip6->ip6_src = ia ? ia->ia_addr.sin6_addr : in6addr_any;
    558      1.31    rpaulo  	ip6->ip6_dst = dst ? *dst : in6m->in6m_addr;
    559  1.61.2.5     skrll 	ia6_release(ia, &psref);
    560  1.61.2.5     skrll 	curlwp_bindx(bound);
    561       1.2    itojun 
    562      1.22    itojun 	mldh->mld_addr = in6m->in6m_addr;
    563      1.29    rpaulo 	in6_clearscope(&mldh->mld_addr); /* XXX */
    564      1.22    itojun 	mldh->mld_cksum = in6_cksum(mh, IPPROTO_ICMPV6, sizeof(struct ip6_hdr),
    565      1.22    itojun 	    sizeof(struct mld_hdr));
    566       1.2    itojun 
    567       1.2    itojun 	/* construct multicast option */
    568      1.31    rpaulo 	memset(&im6o, 0, sizeof(im6o));
    569  1.61.2.4     skrll 	im6o.im6o_multicast_if_index = if_get_index(ifp);
    570       1.2    itojun 	im6o.im6o_multicast_hlim = 1;
    571       1.2    itojun 
    572       1.2    itojun 	/*
    573       1.2    itojun 	 * Request loopback of the report if we are acting as a multicast
    574       1.2    itojun 	 * router, so that the process-level routing daemon can hear it.
    575       1.2    itojun 	 */
    576       1.2    itojun 	im6o.im6o_multicast_loop = (ip6_mrouter != NULL);
    577       1.2    itojun 
    578       1.2    itojun 	/* increment output statictics */
    579      1.44   thorpej 	ICMP6_STATINC(ICMP6_STAT_OUTHIST + type);
    580      1.15    itojun 	icmp6_ifstat_inc(ifp, ifs6_out_msg);
    581      1.17    itojun 	switch (type) {
    582      1.22    itojun 	case MLD_LISTENER_QUERY:
    583      1.15    itojun 		icmp6_ifstat_inc(ifp, ifs6_out_mldquery);
    584      1.15    itojun 		break;
    585      1.22    itojun 	case MLD_LISTENER_REPORT:
    586      1.15    itojun 		icmp6_ifstat_inc(ifp, ifs6_out_mldreport);
    587      1.15    itojun 		break;
    588      1.22    itojun 	case MLD_LISTENER_DONE:
    589      1.15    itojun 		icmp6_ifstat_inc(ifp, ifs6_out_mlddone);
    590      1.15    itojun 		break;
    591       1.7    itojun 	}
    592      1.19    itojun 
    593      1.27     perry 	ip6_output(mh, &ip6_opts, NULL, ia ? 0 : IPV6_UNSPECSRC,
    594      1.53    plunky 	    &im6o, NULL, NULL);
    595       1.2    itojun }
    596      1.31    rpaulo 
    597      1.31    rpaulo static struct mld_hdr *
    598      1.34  christos mld_allocbuf(struct mbuf **mh, int len, struct in6_multi *in6m,
    599      1.33  christos     int type)
    600      1.31    rpaulo {
    601      1.31    rpaulo 	struct mbuf *md;
    602      1.31    rpaulo 	struct mld_hdr *mldh;
    603      1.31    rpaulo 	struct ip6_hdr *ip6;
    604      1.31    rpaulo 
    605      1.31    rpaulo 	/*
    606      1.31    rpaulo 	 * Allocate mbufs to store ip6 header and MLD header.
    607      1.31    rpaulo 	 * We allocate 2 mbufs and make chain in advance because
    608      1.31    rpaulo 	 * it is more convenient when inserting the hop-by-hop option later.
    609      1.31    rpaulo 	 */
    610      1.31    rpaulo 	MGETHDR(*mh, M_DONTWAIT, MT_HEADER);
    611      1.31    rpaulo 	if (*mh == NULL)
    612      1.31    rpaulo 		return NULL;
    613      1.31    rpaulo 	MGET(md, M_DONTWAIT, MT_DATA);
    614      1.31    rpaulo 	if (md == NULL) {
    615      1.31    rpaulo 		m_free(*mh);
    616      1.31    rpaulo 		*mh = NULL;
    617      1.31    rpaulo 		return NULL;
    618      1.31    rpaulo 	}
    619      1.31    rpaulo 	(*mh)->m_next = md;
    620      1.31    rpaulo 	md->m_next = NULL;
    621      1.31    rpaulo 
    622  1.61.2.4     skrll 	m_reset_rcvif((*mh));
    623      1.31    rpaulo 	(*mh)->m_pkthdr.len = sizeof(struct ip6_hdr) + len;
    624      1.31    rpaulo 	(*mh)->m_len = sizeof(struct ip6_hdr);
    625      1.31    rpaulo 	MH_ALIGN(*mh, sizeof(struct ip6_hdr));
    626      1.31    rpaulo 
    627      1.31    rpaulo 	/* fill in the ip6 header */
    628      1.31    rpaulo 	ip6 = mtod(*mh, struct ip6_hdr *);
    629      1.31    rpaulo 	memset(ip6, 0, sizeof(*ip6));
    630      1.31    rpaulo 	ip6->ip6_flow = 0;
    631      1.31    rpaulo 	ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
    632      1.31    rpaulo 	ip6->ip6_vfc |= IPV6_VERSION;
    633      1.31    rpaulo 	/* ip6_plen will be set later */
    634      1.31    rpaulo 	ip6->ip6_nxt = IPPROTO_ICMPV6;
    635      1.31    rpaulo 	/* ip6_hlim will be set by im6o.im6o_multicast_hlim */
    636      1.31    rpaulo 	/* ip6_src/dst will be set by mld_sendpkt() or mld_sendbuf() */
    637      1.31    rpaulo 
    638      1.31    rpaulo 	/* fill in the MLD header as much as possible */
    639      1.31    rpaulo 	md->m_len = len;
    640      1.31    rpaulo 	mldh = mtod(md, struct mld_hdr *);
    641      1.31    rpaulo 	memset(mldh, 0, len);
    642      1.31    rpaulo 	mldh->mld_type = type;
    643      1.31    rpaulo 	return mldh;
    644      1.31    rpaulo }
    645      1.31    rpaulo 
    646      1.31    rpaulo /*
    647      1.31    rpaulo  * Add an address to the list of IP6 multicast addresses for a given interface.
    648      1.31    rpaulo  */
    649      1.31    rpaulo struct	in6_multi *
    650  1.61.2.2     skrll in6_addmulti(struct in6_addr *maddr6, struct ifnet *ifp,
    651      1.38  christos 	int *errorp, int timer)
    652      1.31    rpaulo {
    653      1.31    rpaulo 	struct	in6_ifaddr *ia;
    654      1.54    dyoung 	struct	sockaddr_in6 sin6;
    655      1.31    rpaulo 	struct	in6_multi *in6m;
    656      1.31    rpaulo 	int	s = splsoftnet();
    657      1.31    rpaulo 
    658      1.31    rpaulo 	*errorp = 0;
    659      1.31    rpaulo 
    660      1.31    rpaulo 	/*
    661      1.31    rpaulo 	 * See if address already in list.
    662      1.31    rpaulo 	 */
    663      1.31    rpaulo 	IN6_LOOKUP_MULTI(*maddr6, ifp, in6m);
    664      1.31    rpaulo 	if (in6m != NULL) {
    665      1.31    rpaulo 		/*
    666      1.31    rpaulo 		 * Found it; just increment the refrence count.
    667      1.31    rpaulo 		 */
    668      1.31    rpaulo 		in6m->in6m_refcount++;
    669      1.31    rpaulo 	} else {
    670  1.61.2.5     skrll 		int _s;
    671      1.31    rpaulo 		/*
    672      1.31    rpaulo 		 * New address; allocate a new multicast record
    673      1.31    rpaulo 		 * and link it into the interface's multicast list.
    674      1.31    rpaulo 		 */
    675      1.31    rpaulo 		in6m = (struct in6_multi *)
    676      1.51    dyoung 			malloc(sizeof(*in6m), M_IPMADDR, M_NOWAIT|M_ZERO);
    677      1.31    rpaulo 		if (in6m == NULL) {
    678      1.31    rpaulo 			splx(s);
    679      1.31    rpaulo 			*errorp = ENOBUFS;
    680      1.31    rpaulo 			return (NULL);
    681      1.31    rpaulo 		}
    682      1.31    rpaulo 
    683      1.31    rpaulo 		in6m->in6m_addr = *maddr6;
    684      1.31    rpaulo 		in6m->in6m_ifp = ifp;
    685      1.31    rpaulo 		in6m->in6m_refcount = 1;
    686      1.31    rpaulo 		in6m->in6m_timer = IN6M_TIMER_UNDEF;
    687  1.61.2.3     skrll 		callout_init(&in6m->in6m_timer_ch, CALLOUT_MPSAFE);
    688  1.61.2.3     skrll 		callout_setfunc(&in6m->in6m_timer_ch, mld_timeo, in6m);
    689  1.61.2.3     skrll 
    690  1.61.2.5     skrll 		_s = pserialize_read_enter();
    691  1.61.2.4     skrll 		ia = in6_get_ia_from_ifp(ifp);
    692      1.31    rpaulo 		if (ia == NULL) {
    693  1.61.2.5     skrll 			pserialize_read_exit(_s);
    694  1.61.2.3     skrll 			callout_destroy(&in6m->in6m_timer_ch);
    695      1.31    rpaulo 			free(in6m, M_IPMADDR);
    696      1.31    rpaulo 			splx(s);
    697      1.31    rpaulo 			*errorp = EADDRNOTAVAIL; /* appropriate? */
    698      1.31    rpaulo 			return (NULL);
    699      1.31    rpaulo 		}
    700      1.31    rpaulo 		in6m->in6m_ia = ia;
    701      1.60     rmind 		ifaref(&ia->ia_ifa); /* gain a reference */
    702  1.61.2.5     skrll 		/* FIXME NOMPSAFE: need to lock */
    703      1.31    rpaulo 		LIST_INSERT_HEAD(&ia->ia6_multiaddrs, in6m, in6m_entry);
    704  1.61.2.5     skrll 		pserialize_read_exit(_s);
    705      1.31    rpaulo 
    706      1.31    rpaulo 		/*
    707      1.31    rpaulo 		 * Ask the network driver to update its multicast reception
    708      1.31    rpaulo 		 * filter appropriately for the new address.
    709      1.31    rpaulo 		 */
    710      1.54    dyoung 		sockaddr_in6_init(&sin6, maddr6, 0, 0, 0);
    711      1.54    dyoung 		*errorp = if_mcast_op(ifp, SIOCADDMULTI, sin6tosa(&sin6));
    712      1.31    rpaulo 		if (*errorp) {
    713  1.61.2.3     skrll 			callout_destroy(&in6m->in6m_timer_ch);
    714      1.31    rpaulo 			LIST_REMOVE(in6m, in6m_entry);
    715      1.31    rpaulo 			free(in6m, M_IPMADDR);
    716      1.60     rmind 			ifafree(&ia->ia_ifa);
    717      1.31    rpaulo 			splx(s);
    718      1.31    rpaulo 			return (NULL);
    719      1.31    rpaulo 		}
    720      1.31    rpaulo 
    721      1.32    rpaulo 		in6m->in6m_timer = timer;
    722      1.31    rpaulo 		if (in6m->in6m_timer > 0) {
    723      1.31    rpaulo 			in6m->in6m_state = MLD_REPORTPENDING;
    724      1.31    rpaulo 			mld_starttimer(in6m);
    725      1.31    rpaulo 
    726      1.31    rpaulo 			splx(s);
    727      1.31    rpaulo 			return (in6m);
    728      1.31    rpaulo 		}
    729      1.31    rpaulo 
    730      1.31    rpaulo 		/*
    731      1.31    rpaulo 		 * Let MLD6 know that we have joined a new IP6 multicast
    732      1.31    rpaulo 		 * group.
    733      1.31    rpaulo 		 */
    734      1.31    rpaulo 		mld_start_listening(in6m);
    735      1.31    rpaulo 	}
    736      1.31    rpaulo 	splx(s);
    737      1.31    rpaulo 	return (in6m);
    738      1.31    rpaulo }
    739      1.31    rpaulo 
    740      1.31    rpaulo /*
    741      1.31    rpaulo  * Delete a multicast address record.
    742      1.31    rpaulo  */
    743      1.31    rpaulo void
    744      1.38  christos in6_delmulti(struct in6_multi *in6m)
    745      1.31    rpaulo {
    746      1.54    dyoung 	struct	sockaddr_in6 sin6;
    747      1.31    rpaulo 	struct	in6_ifaddr *ia;
    748      1.31    rpaulo 	int	s = splsoftnet();
    749      1.31    rpaulo 
    750      1.31    rpaulo 	mld_stoptimer(in6m);
    751      1.31    rpaulo 
    752      1.31    rpaulo 	if (--in6m->in6m_refcount == 0) {
    753  1.61.2.5     skrll 		int _s;
    754  1.61.2.5     skrll 
    755      1.31    rpaulo 		/*
    756      1.31    rpaulo 		 * No remaining claims to this record; let MLD6 know
    757      1.31    rpaulo 		 * that we are leaving the multicast group.
    758      1.31    rpaulo 		 */
    759      1.31    rpaulo 		mld_stop_listening(in6m);
    760      1.31    rpaulo 
    761      1.31    rpaulo 		/*
    762      1.31    rpaulo 		 * Unlink from list.
    763      1.31    rpaulo 		 */
    764      1.31    rpaulo 		LIST_REMOVE(in6m, in6m_entry);
    765      1.35    dyoung 		if (in6m->in6m_ia != NULL) {
    766      1.60     rmind 			ifafree(&in6m->in6m_ia->ia_ifa); /* release reference */
    767      1.35    dyoung 			in6m->in6m_ia = NULL;
    768      1.31    rpaulo 		}
    769      1.31    rpaulo 
    770      1.31    rpaulo 		/*
    771      1.31    rpaulo 		 * Delete all references of this multicasting group from
    772      1.31    rpaulo 		 * the membership arrays
    773      1.31    rpaulo 		 */
    774  1.61.2.5     skrll 		_s = pserialize_read_enter();
    775  1.61.2.4     skrll 		IN6_ADDRLIST_READER_FOREACH(ia) {
    776      1.31    rpaulo 			struct in6_multi_mship *imm;
    777      1.35    dyoung 			LIST_FOREACH(imm, &ia->ia6_memberships, i6mm_chain) {
    778      1.31    rpaulo 				if (imm->i6mm_maddr == in6m)
    779      1.31    rpaulo 					imm->i6mm_maddr = NULL;
    780      1.31    rpaulo 			}
    781      1.31    rpaulo 		}
    782  1.61.2.5     skrll 		pserialize_read_exit(_s);
    783      1.31    rpaulo 
    784      1.31    rpaulo 		/*
    785      1.31    rpaulo 		 * Notify the network driver to update its multicast
    786      1.31    rpaulo 		 * reception filter.
    787      1.31    rpaulo 		 */
    788      1.54    dyoung 		sockaddr_in6_init(&sin6, &in6m->in6m_addr, 0, 0, 0);
    789      1.54    dyoung 		if_mcast_op(in6m->in6m_ifp, SIOCDELMULTI, sin6tosa(&sin6));
    790      1.61     ozaki 
    791      1.61     ozaki 		/* Tell mld_timeo we're halting the timer */
    792      1.61     ozaki 		in6m->in6m_timer = IN6M_TIMER_UNDEF;
    793  1.61.2.6     skrll #ifdef NET_MPSAFE
    794  1.61.2.6     skrll 		callout_halt(&in6m->in6m_timer_ch, NULL);
    795  1.61.2.6     skrll #else
    796      1.61     ozaki 		callout_halt(&in6m->in6m_timer_ch, softnet_lock);
    797  1.61.2.6     skrll #endif
    798      1.41     joerg 		callout_destroy(&in6m->in6m_timer_ch);
    799      1.61     ozaki 
    800      1.31    rpaulo 		free(in6m, M_IPMADDR);
    801      1.31    rpaulo 	}
    802      1.31    rpaulo 	splx(s);
    803      1.31    rpaulo }
    804      1.31    rpaulo 
    805      1.31    rpaulo 
    806      1.31    rpaulo struct in6_multi_mship *
    807  1.61.2.2     skrll in6_joingroup(struct ifnet *ifp, struct in6_addr *addr,
    808      1.38  christos 	int *errorp, int timer)
    809      1.31    rpaulo {
    810      1.31    rpaulo 	struct in6_multi_mship *imm;
    811      1.31    rpaulo 
    812      1.51    dyoung 	imm = malloc(sizeof(*imm), M_IPMADDR, M_NOWAIT|M_ZERO);
    813      1.51    dyoung 	if (imm == NULL) {
    814      1.31    rpaulo 		*errorp = ENOBUFS;
    815      1.31    rpaulo 		return NULL;
    816      1.31    rpaulo 	}
    817      1.31    rpaulo 
    818      1.32    rpaulo 	imm->i6mm_maddr = in6_addmulti(addr, ifp, errorp, timer);
    819      1.31    rpaulo 	if (!imm->i6mm_maddr) {
    820      1.36    dyoung 		/* *errorp is already set */
    821      1.31    rpaulo 		free(imm, M_IPMADDR);
    822      1.31    rpaulo 		return NULL;
    823      1.31    rpaulo 	}
    824      1.31    rpaulo 	return imm;
    825      1.31    rpaulo }
    826      1.31    rpaulo 
    827      1.31    rpaulo int
    828      1.38  christos in6_leavegroup(struct in6_multi_mship *imm)
    829      1.31    rpaulo {
    830      1.31    rpaulo 
    831      1.31    rpaulo 	if (imm->i6mm_maddr) {
    832      1.31    rpaulo 		in6_delmulti(imm->i6mm_maddr);
    833      1.31    rpaulo 	}
    834      1.31    rpaulo 	free(imm, M_IPMADDR);
    835      1.31    rpaulo 	return 0;
    836      1.31    rpaulo }
    837      1.31    rpaulo 
    838      1.31    rpaulo 
    839      1.31    rpaulo /*
    840      1.31    rpaulo  * Multicast address kludge:
    841      1.31    rpaulo  * If there were any multicast addresses attached to this interface address,
    842      1.31    rpaulo  * either move them to another address on this interface, or save them until
    843      1.31    rpaulo  * such time as this interface is reconfigured for IPv6.
    844      1.31    rpaulo  */
    845      1.31    rpaulo void
    846      1.38  christos in6_savemkludge(struct in6_ifaddr *oia)
    847      1.31    rpaulo {
    848      1.31    rpaulo 	struct in6_ifaddr *ia;
    849      1.36    dyoung 	struct in6_multi *in6m;
    850  1.61.2.5     skrll 	int s;
    851      1.31    rpaulo 
    852  1.61.2.5     skrll 	s = pserialize_read_enter();
    853  1.61.2.4     skrll 	ia = in6_get_ia_from_ifp(oia->ia_ifp);
    854      1.31    rpaulo 	if (ia) {	/* there is another address */
    855      1.36    dyoung 		KASSERT(ia != oia);
    856      1.36    dyoung 		while ((in6m = LIST_FIRST(&oia->ia6_multiaddrs)) != NULL) {
    857      1.36    dyoung 			LIST_REMOVE(in6m, in6m_entry);
    858      1.60     rmind 			ifaref(&ia->ia_ifa);
    859      1.60     rmind 			ifafree(&in6m->in6m_ia->ia_ifa);
    860      1.31    rpaulo 			in6m->in6m_ia = ia;
    861  1.61.2.5     skrll 			/* FIXME NOMPSAFE: need to lock */
    862      1.31    rpaulo 			LIST_INSERT_HEAD(&ia->ia6_multiaddrs, in6m, in6m_entry);
    863      1.31    rpaulo 		}
    864      1.31    rpaulo 	} else {	/* last address on this if deleted, save */
    865      1.31    rpaulo 		struct multi6_kludge *mk;
    866      1.31    rpaulo 
    867      1.35    dyoung 		LIST_FOREACH(mk, &in6_mk, mk_entry) {
    868      1.31    rpaulo 			if (mk->mk_ifp == oia->ia_ifp)
    869      1.31    rpaulo 				break;
    870      1.31    rpaulo 		}
    871      1.31    rpaulo 		if (mk == NULL) /* this should not happen! */
    872      1.31    rpaulo 			panic("in6_savemkludge: no kludge space");
    873      1.31    rpaulo 
    874      1.36    dyoung 		while ((in6m = LIST_FIRST(&oia->ia6_multiaddrs)) != NULL) {
    875      1.36    dyoung 			LIST_REMOVE(in6m, in6m_entry);
    876      1.60     rmind 			ifafree(&in6m->in6m_ia->ia_ifa); /* release reference */
    877      1.31    rpaulo 			in6m->in6m_ia = NULL;
    878      1.31    rpaulo 			LIST_INSERT_HEAD(&mk->mk_head, in6m, in6m_entry);
    879      1.31    rpaulo 		}
    880      1.31    rpaulo 	}
    881  1.61.2.5     skrll 	pserialize_read_exit(s);
    882      1.31    rpaulo }
    883      1.31    rpaulo 
    884      1.31    rpaulo /*
    885      1.31    rpaulo  * Continuation of multicast address hack:
    886      1.31    rpaulo  * If there was a multicast group list previously saved for this interface,
    887      1.31    rpaulo  * then we re-attach it to the first address configured on the i/f.
    888      1.31    rpaulo  */
    889      1.31    rpaulo void
    890      1.38  christos in6_restoremkludge(struct in6_ifaddr *ia, struct ifnet *ifp)
    891      1.31    rpaulo {
    892      1.31    rpaulo 	struct multi6_kludge *mk;
    893      1.36    dyoung 	struct in6_multi *in6m;
    894      1.31    rpaulo 
    895      1.35    dyoung 	LIST_FOREACH(mk, &in6_mk, mk_entry) {
    896      1.35    dyoung 		if (mk->mk_ifp == ifp)
    897      1.31    rpaulo 			break;
    898      1.31    rpaulo 	}
    899      1.35    dyoung 	if (mk == NULL)
    900      1.35    dyoung 		return;
    901      1.36    dyoung 	while ((in6m = LIST_FIRST(&mk->mk_head)) != NULL) {
    902      1.36    dyoung 		LIST_REMOVE(in6m, in6m_entry);
    903      1.35    dyoung 		in6m->in6m_ia = ia;
    904      1.60     rmind 		ifaref(&ia->ia_ifa);
    905      1.35    dyoung 		LIST_INSERT_HEAD(&ia->ia6_multiaddrs, in6m, in6m_entry);
    906      1.35    dyoung 	}
    907      1.31    rpaulo }
    908      1.31    rpaulo 
    909      1.31    rpaulo /*
    910      1.31    rpaulo  * Allocate space for the kludge at interface initialization time.
    911      1.31    rpaulo  * Formerly, we dynamically allocated the space in in6_savemkludge() with
    912      1.31    rpaulo  * malloc(M_WAITOK).  However, it was wrong since the function could be called
    913      1.31    rpaulo  * under an interrupt context (software timer on address lifetime expiration).
    914      1.31    rpaulo  * Also, we cannot just give up allocating the strucutre, since the group
    915      1.31    rpaulo  * membership structure is very complex and we need to keep it anyway.
    916      1.31    rpaulo  * Of course, this function MUST NOT be called under an interrupt context.
    917      1.31    rpaulo  * Specifically, it is expected to be called only from in6_ifattach(), though
    918      1.31    rpaulo  * it is a global function.
    919      1.31    rpaulo  */
    920      1.31    rpaulo void
    921      1.38  christos in6_createmkludge(struct ifnet *ifp)
    922      1.31    rpaulo {
    923      1.31    rpaulo 	struct multi6_kludge *mk;
    924      1.31    rpaulo 
    925      1.35    dyoung 	LIST_FOREACH(mk, &in6_mk, mk_entry) {
    926      1.31    rpaulo 		/* If we've already had one, do not allocate. */
    927      1.31    rpaulo 		if (mk->mk_ifp == ifp)
    928      1.31    rpaulo 			return;
    929      1.31    rpaulo 	}
    930      1.31    rpaulo 
    931      1.51    dyoung 	mk = malloc(sizeof(*mk), M_IPMADDR, M_ZERO|M_WAITOK);
    932      1.31    rpaulo 
    933      1.31    rpaulo 	LIST_INIT(&mk->mk_head);
    934      1.31    rpaulo 	mk->mk_ifp = ifp;
    935      1.31    rpaulo 	LIST_INSERT_HEAD(&in6_mk, mk, mk_entry);
    936      1.31    rpaulo }
    937      1.31    rpaulo 
    938      1.31    rpaulo void
    939      1.38  christos in6_purgemkludge(struct ifnet *ifp)
    940      1.31    rpaulo {
    941      1.31    rpaulo 	struct multi6_kludge *mk;
    942      1.36    dyoung 	struct in6_multi *in6m, *next;
    943      1.31    rpaulo 
    944      1.35    dyoung 	LIST_FOREACH(mk, &in6_mk, mk_entry) {
    945      1.35    dyoung 		if (mk->mk_ifp == ifp)
    946      1.35    dyoung 			break;
    947      1.35    dyoung 	}
    948      1.35    dyoung 	if (mk == NULL)
    949      1.35    dyoung 		return;
    950      1.35    dyoung 
    951      1.35    dyoung 	/* leave from all multicast groups joined */
    952      1.36    dyoung 	for (in6m = LIST_FIRST(&mk->mk_head); in6m != NULL; in6m = next) {
    953      1.36    dyoung 		next = LIST_NEXT(in6m, in6m_entry);
    954      1.35    dyoung 		in6_delmulti(in6m);
    955      1.31    rpaulo 	}
    956      1.35    dyoung 	LIST_REMOVE(mk, mk_entry);
    957      1.35    dyoung 	free(mk, M_IPMADDR);
    958      1.31    rpaulo }
    959      1.57     joerg 
    960      1.57     joerg static int
    961      1.57     joerg in6_mkludge_sysctl(SYSCTLFN_ARGS)
    962      1.57     joerg {
    963      1.57     joerg 	struct multi6_kludge *mk;
    964      1.57     joerg 	struct in6_multi *in6m;
    965      1.57     joerg 	int error;
    966      1.57     joerg 	uint32_t tmp;
    967      1.57     joerg 	size_t written;
    968      1.57     joerg 
    969      1.57     joerg 	if (namelen != 1)
    970      1.57     joerg 		return EINVAL;
    971      1.57     joerg 
    972      1.57     joerg 	if (oldp == NULL) {
    973      1.57     joerg 		*oldlenp = 0;
    974      1.57     joerg 		LIST_FOREACH(mk, &in6_mk, mk_entry) {
    975      1.57     joerg 			if (mk->mk_ifp->if_index == name[0])
    976      1.57     joerg 				continue;
    977      1.57     joerg 			LIST_FOREACH(in6m, &mk->mk_head, in6m_entry) {
    978      1.57     joerg 				*oldlenp += sizeof(struct in6_addr) +
    979      1.57     joerg 				    sizeof(uint32_t);
    980      1.57     joerg 			}
    981      1.57     joerg 		}
    982      1.57     joerg 		return 0;
    983      1.57     joerg 	}
    984      1.57     joerg 
    985      1.57     joerg 	error = 0;
    986      1.57     joerg 	written = 0;
    987      1.57     joerg 	LIST_FOREACH(mk, &in6_mk, mk_entry) {
    988      1.57     joerg 		if (mk->mk_ifp->if_index == name[0])
    989      1.57     joerg 			continue;
    990      1.57     joerg 		LIST_FOREACH(in6m, &mk->mk_head, in6m_entry) {
    991      1.57     joerg 			if (written + sizeof(struct in6_addr) +
    992      1.57     joerg 			    sizeof(uint32_t) > *oldlenp)
    993      1.57     joerg 				goto done;
    994      1.57     joerg 			error = sysctl_copyout(l, &in6m->in6m_addr,
    995      1.57     joerg 			    oldp, sizeof(struct in6_addr));
    996      1.57     joerg 			if (error)
    997      1.57     joerg 				goto done;
    998      1.57     joerg 			oldp = (char *)oldp + sizeof(struct in6_addr);
    999      1.57     joerg 			written += sizeof(struct in6_addr);
   1000      1.57     joerg 			tmp = in6m->in6m_refcount;
   1001      1.57     joerg 			error = sysctl_copyout(l, &tmp, oldp, sizeof(tmp));
   1002      1.57     joerg 			if (error)
   1003      1.57     joerg 				goto done;
   1004      1.57     joerg 			oldp = (char *)oldp + sizeof(tmp);
   1005      1.57     joerg 			written += sizeof(tmp);
   1006      1.57     joerg 		}
   1007      1.57     joerg 	}
   1008      1.57     joerg 
   1009      1.57     joerg done:
   1010      1.57     joerg 	*oldlenp = written;
   1011      1.57     joerg 	return error;
   1012      1.57     joerg }
   1013      1.57     joerg 
   1014      1.57     joerg static int
   1015      1.57     joerg in6_multicast_sysctl(SYSCTLFN_ARGS)
   1016      1.57     joerg {
   1017      1.57     joerg 	struct ifnet *ifp;
   1018      1.57     joerg 	struct ifaddr *ifa;
   1019      1.57     joerg 	struct in6_ifaddr *ifa6;
   1020      1.57     joerg 	struct in6_multi *in6m;
   1021      1.57     joerg 	uint32_t tmp;
   1022      1.57     joerg 	int error;
   1023      1.57     joerg 	size_t written;
   1024  1.61.2.5     skrll 	struct psref psref, psref_ia;
   1025  1.61.2.5     skrll 	int bound, s;
   1026      1.57     joerg 
   1027      1.57     joerg 	if (namelen != 1)
   1028      1.57     joerg 		return EINVAL;
   1029      1.57     joerg 
   1030  1.61.2.4     skrll 	bound = curlwp_bind();
   1031  1.61.2.4     skrll 	ifp = if_get_byindex(name[0], &psref);
   1032  1.61.2.4     skrll 	if (ifp == NULL) {
   1033  1.61.2.4     skrll 		curlwp_bindx(bound);
   1034      1.57     joerg 		return ENODEV;
   1035  1.61.2.4     skrll 	}
   1036      1.57     joerg 
   1037      1.57     joerg 	if (oldp == NULL) {
   1038      1.57     joerg 		*oldlenp = 0;
   1039  1.61.2.5     skrll 		s = pserialize_read_enter();
   1040  1.61.2.4     skrll 		IFADDR_READER_FOREACH(ifa, ifp) {
   1041      1.57     joerg 			if (ifa->ifa_addr->sa_family != AF_INET6)
   1042      1.57     joerg 				continue;
   1043      1.57     joerg 			ifa6 = (struct in6_ifaddr *)ifa;
   1044      1.57     joerg 			LIST_FOREACH(in6m, &ifa6->ia6_multiaddrs, in6m_entry) {
   1045      1.57     joerg 				*oldlenp += 2 * sizeof(struct in6_addr) +
   1046      1.57     joerg 				    sizeof(uint32_t);
   1047      1.57     joerg 			}
   1048      1.57     joerg 		}
   1049  1.61.2.5     skrll 		pserialize_read_exit(s);
   1050  1.61.2.4     skrll 		if_put(ifp, &psref);
   1051  1.61.2.4     skrll 		curlwp_bindx(bound);
   1052      1.57     joerg 		return 0;
   1053      1.57     joerg 	}
   1054      1.57     joerg 
   1055      1.57     joerg 	error = 0;
   1056      1.57     joerg 	written = 0;
   1057  1.61.2.5     skrll 	s = pserialize_read_enter();
   1058  1.61.2.4     skrll 	IFADDR_READER_FOREACH(ifa, ifp) {
   1059      1.57     joerg 		if (ifa->ifa_addr->sa_family != AF_INET6)
   1060      1.57     joerg 			continue;
   1061  1.61.2.5     skrll 
   1062  1.61.2.5     skrll 		ifa_acquire(ifa, &psref_ia);
   1063  1.61.2.5     skrll 		pserialize_read_exit(s);
   1064  1.61.2.5     skrll 
   1065      1.57     joerg 		ifa6 = (struct in6_ifaddr *)ifa;
   1066      1.57     joerg 		LIST_FOREACH(in6m, &ifa6->ia6_multiaddrs, in6m_entry) {
   1067      1.57     joerg 			if (written + 2 * sizeof(struct in6_addr) +
   1068      1.57     joerg 			    sizeof(uint32_t) > *oldlenp)
   1069      1.57     joerg 				goto done;
   1070      1.57     joerg 			error = sysctl_copyout(l, &ifa6->ia_addr.sin6_addr,
   1071      1.57     joerg 			    oldp, sizeof(struct in6_addr));
   1072      1.57     joerg 			if (error)
   1073      1.57     joerg 				goto done;
   1074      1.57     joerg 			oldp = (char *)oldp + sizeof(struct in6_addr);
   1075      1.57     joerg 			written += sizeof(struct in6_addr);
   1076      1.57     joerg 			error = sysctl_copyout(l, &in6m->in6m_addr,
   1077      1.57     joerg 			    oldp, sizeof(struct in6_addr));
   1078      1.57     joerg 			if (error)
   1079      1.57     joerg 				goto done;
   1080      1.57     joerg 			oldp = (char *)oldp + sizeof(struct in6_addr);
   1081      1.57     joerg 			written += sizeof(struct in6_addr);
   1082      1.57     joerg 			tmp = in6m->in6m_refcount;
   1083      1.57     joerg 			error = sysctl_copyout(l, &tmp, oldp, sizeof(tmp));
   1084      1.57     joerg 			if (error)
   1085      1.57     joerg 				goto done;
   1086      1.57     joerg 			oldp = (char *)oldp + sizeof(tmp);
   1087      1.57     joerg 			written += sizeof(tmp);
   1088      1.57     joerg 		}
   1089  1.61.2.5     skrll 
   1090  1.61.2.5     skrll 		s = pserialize_read_enter();
   1091  1.61.2.5     skrll 		ifa_release(ifa, &psref_ia);
   1092      1.57     joerg 	}
   1093  1.61.2.5     skrll 	pserialize_read_exit(s);
   1094      1.57     joerg done:
   1095  1.61.2.5     skrll 	ifa_release(ifa, &psref_ia);
   1096  1.61.2.4     skrll 	if_put(ifp, &psref);
   1097  1.61.2.4     skrll 	curlwp_bindx(bound);
   1098      1.57     joerg 	*oldlenp = written;
   1099      1.57     joerg 	return error;
   1100      1.57     joerg }
   1101      1.57     joerg 
   1102      1.57     joerg SYSCTL_SETUP(sysctl_in6_mklude_setup, "sysctl net.inet6.multicast_kludge subtree setup")
   1103      1.57     joerg {
   1104      1.57     joerg 
   1105      1.57     joerg 	sysctl_createv(clog, 0, NULL, NULL,
   1106      1.57     joerg 		       CTLFLAG_PERMANENT,
   1107      1.59     joerg 		       CTLTYPE_NODE, "inet6", NULL,
   1108      1.59     joerg 		       NULL, 0, NULL, 0,
   1109      1.59     joerg 		       CTL_NET, PF_INET6, CTL_EOL);
   1110      1.59     joerg 
   1111      1.59     joerg 	sysctl_createv(clog, 0, NULL, NULL,
   1112      1.59     joerg 		       CTLFLAG_PERMANENT,
   1113      1.57     joerg 		       CTLTYPE_NODE, "multicast",
   1114      1.57     joerg 		       SYSCTL_DESCR("Multicast information"),
   1115      1.57     joerg 		       in6_multicast_sysctl, 0, NULL, 0,
   1116      1.57     joerg 		       CTL_NET, PF_INET6, CTL_CREATE, CTL_EOL);
   1117      1.57     joerg 
   1118      1.57     joerg 	sysctl_createv(clog, 0, NULL, NULL,
   1119      1.57     joerg 		       CTLFLAG_PERMANENT,
   1120      1.57     joerg 		       CTLTYPE_NODE, "multicast_kludge",
   1121      1.57     joerg 		       SYSCTL_DESCR("multicast kludge information"),
   1122      1.57     joerg 		       in6_mkludge_sysctl, 0, NULL, 0,
   1123      1.57     joerg 		       CTL_NET, PF_INET6, CTL_CREATE, CTL_EOL);
   1124      1.57     joerg }
   1125