Home | History | Annotate | Line # | Download | only in net
if_loop.c revision 1.57
      1  1.57   thorpej /*	$NetBSD: if_loop.c,v 1.57 2005/12/11 23:05:25 thorpej Exp $	*/
      2  1.26    itojun 
      3  1.26    itojun /*
      4  1.26    itojun  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5  1.26    itojun  * All rights reserved.
      6  1.55     perry  *
      7  1.26    itojun  * Redistribution and use in source and binary forms, with or without
      8  1.26    itojun  * modification, are permitted provided that the following conditions
      9  1.26    itojun  * are met:
     10  1.26    itojun  * 1. Redistributions of source code must retain the above copyright
     11  1.26    itojun  *    notice, this list of conditions and the following disclaimer.
     12  1.26    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.26    itojun  *    notice, this list of conditions and the following disclaimer in the
     14  1.26    itojun  *    documentation and/or other materials provided with the distribution.
     15  1.26    itojun  * 3. Neither the name of the project nor the names of its contributors
     16  1.26    itojun  *    may be used to endorse or promote products derived from this software
     17  1.26    itojun  *    without specific prior written permission.
     18  1.55     perry  *
     19  1.26    itojun  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20  1.26    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.26    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.26    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23  1.26    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.26    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.26    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.26    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.26    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.26    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.26    itojun  * SUCH DAMAGE.
     30  1.26    itojun  */
     31  1.12       cgd 
     32   1.1       cgd /*
     33  1.11   mycroft  * Copyright (c) 1982, 1986, 1993
     34  1.11   mycroft  *	The Regents of the University of California.  All rights reserved.
     35   1.1       cgd  *
     36   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     37   1.1       cgd  * modification, are permitted provided that the following conditions
     38   1.1       cgd  * are met:
     39   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     40   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     41   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     42   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     43   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     44  1.47       agc  * 3. Neither the name of the University nor the names of its contributors
     45   1.1       cgd  *    may be used to endorse or promote products derived from this software
     46   1.1       cgd  *    without specific prior written permission.
     47   1.1       cgd  *
     48   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58   1.1       cgd  * SUCH DAMAGE.
     59   1.1       cgd  *
     60  1.21      fvdl  *	@(#)if_loop.c	8.2 (Berkeley) 1/9/95
     61   1.1       cgd  */
     62   1.1       cgd 
     63   1.1       cgd /*
     64   1.1       cgd  * Loopback interface driver for protocol testing and timing.
     65   1.1       cgd  */
     66  1.40     lukem 
     67  1.40     lukem #include <sys/cdefs.h>
     68  1.57   thorpej __KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.57 2005/12/11 23:05:25 thorpej Exp $");
     69  1.23  jonathan 
     70  1.23  jonathan #include "opt_inet.h"
     71  1.23  jonathan #include "opt_atalk.h"
     72  1.24  jonathan #include "opt_iso.h"
     73  1.25  jonathan #include "opt_ns.h"
     74  1.46    martin #include "opt_ipx.h"
     75  1.46    martin #include "opt_mbuftrace.h"
     76   1.1       cgd 
     77   1.9   mycroft #include "bpfilter.h"
     78   1.4       cgd 
     79   1.9   mycroft #include <sys/param.h>
     80   1.9   mycroft #include <sys/systm.h>
     81  1.11   mycroft #include <sys/kernel.h>
     82   1.9   mycroft #include <sys/mbuf.h>
     83   1.9   mycroft #include <sys/socket.h>
     84   1.9   mycroft #include <sys/errno.h>
     85   1.9   mycroft #include <sys/ioctl.h>
     86  1.11   mycroft #include <sys/time.h>
     87  1.11   mycroft 
     88  1.11   mycroft #include <machine/cpu.h>
     89   1.9   mycroft 
     90   1.9   mycroft #include <net/if.h>
     91   1.9   mycroft #include <net/if_types.h>
     92   1.9   mycroft #include <net/netisr.h>
     93   1.9   mycroft #include <net/route.h>
     94   1.1       cgd 
     95   1.1       cgd #ifdef	INET
     96   1.9   mycroft #include <netinet/in.h>
     97   1.9   mycroft #include <netinet/in_systm.h>
     98   1.9   mycroft #include <netinet/in_var.h>
     99   1.9   mycroft #include <netinet/ip.h>
    100   1.1       cgd #endif
    101   1.1       cgd 
    102  1.26    itojun #ifdef INET6
    103  1.26    itojun #ifndef INET
    104  1.26    itojun #include <netinet/in.h>
    105  1.26    itojun #endif
    106  1.26    itojun #include <netinet6/in6_var.h>
    107  1.29    itojun #include <netinet/ip6.h>
    108  1.26    itojun #endif
    109  1.26    itojun 
    110   1.1       cgd #ifdef NS
    111   1.9   mycroft #include <netns/ns.h>
    112   1.9   mycroft #include <netns/ns_if.h>
    113   1.1       cgd #endif
    114   1.1       cgd 
    115  1.22  christos #ifdef IPX
    116  1.22  christos #include <netipx/ipx.h>
    117  1.22  christos #include <netipx/ipx_if.h>
    118  1.22  christos #endif
    119  1.22  christos 
    120   1.1       cgd #ifdef ISO
    121   1.9   mycroft #include <netiso/iso.h>
    122   1.9   mycroft #include <netiso/iso_var.h>
    123   1.1       cgd #endif
    124   1.1       cgd 
    125  1.19  christos #ifdef NETATALK
    126  1.19  christos #include <netatalk/at.h>
    127  1.19  christos #include <netatalk/at_var.h>
    128  1.19  christos #endif
    129  1.19  christos 
    130   1.2       cgd #if NBPFILTER > 0
    131   1.2       cgd #include <net/bpf.h>
    132   1.2       cgd #endif
    133   1.9   mycroft 
    134  1.26    itojun #if defined(LARGE_LOMTU)
    135  1.26    itojun #define LOMTU	(131072 +  MHLEN + MLEN)
    136  1.48  jonathan #define LOMTU_MAX LOMTU
    137  1.26    itojun #else
    138  1.20  jonathan #define	LOMTU	(32768 +  MHLEN + MLEN)
    139  1.48  jonathan #define	LOMTU_MAX	(65536 +  MHLEN + MLEN)
    140  1.26    itojun #endif
    141   1.1       cgd 
    142  1.34   thorpej #ifdef ALTQ
    143  1.57   thorpej static void	lostart(struct ifnet *);
    144  1.34   thorpej #endif
    145  1.32   thorpej 
    146  1.52     peter struct loop_softc {
    147  1.52     peter 	LIST_ENTRY(loop_softc) sc_list;
    148  1.52     peter 	struct ifnet sc_if;
    149  1.52     peter };
    150  1.52     peter 
    151  1.57   thorpej static LIST_HEAD(, loop_softc) loop_softc_list;
    152  1.52     peter 
    153  1.57   thorpej static int	loop_clone_create(struct if_clone *, int);
    154  1.57   thorpej static int	loop_clone_destroy(struct ifnet *);
    155  1.52     peter 
    156  1.57   thorpej static struct if_clone loop_cloner =
    157  1.52     peter     IF_CLONE_INITIALIZER("lo", loop_clone_create, loop_clone_destroy);
    158  1.52     peter 
    159   1.6    andrew void
    160  1.52     peter loopattach(int n)
    161   1.1       cgd {
    162  1.52     peter 	LIST_INIT(&loop_softc_list);
    163  1.52     peter 
    164  1.52     peter 	(void)loop_clone_create(&loop_cloner, 0);	/* lo0 always exists */
    165  1.52     peter 	if_clone_attach(&loop_cloner);
    166  1.52     peter }
    167  1.52     peter 
    168  1.57   thorpej static int
    169  1.52     peter loop_clone_create(struct if_clone *ifc, int unit)
    170  1.52     peter {
    171  1.52     peter 	struct loop_softc *sc;
    172  1.52     peter 
    173  1.52     peter 	sc = malloc(sizeof(struct loop_softc), M_DEVBUF, M_WAITOK | M_ZERO);
    174  1.52     peter 
    175  1.52     peter 	snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname), "%s%d",
    176  1.52     peter 	    ifc->ifc_name, unit);
    177   1.1       cgd 
    178  1.52     peter 	sc->sc_if.if_softc = sc;
    179  1.52     peter 	sc->sc_if.if_mtu = LOMTU;
    180  1.52     peter 	sc->sc_if.if_flags = IFF_LOOPBACK | IFF_MULTICAST;
    181  1.52     peter 	sc->sc_if.if_ioctl = loioctl;
    182  1.52     peter 	sc->sc_if.if_output = looutput;
    183  1.34   thorpej #ifdef ALTQ
    184  1.52     peter 	sc->sc_if.if_start = lostart;
    185  1.34   thorpej #endif
    186  1.52     peter 	sc->sc_if.if_type = IFT_LOOP;
    187  1.52     peter 	sc->sc_if.if_hdrlen = 0;
    188  1.52     peter 	sc->sc_if.if_addrlen = 0;
    189  1.52     peter 	sc->sc_if.if_dlt = DLT_NULL;
    190  1.52     peter 	IFQ_SET_READY(&sc->sc_if.if_snd);
    191  1.52     peter 	if (unit == 0)
    192  1.52     peter 		lo0ifp = &sc->sc_if;
    193  1.52     peter 	if_attach(&sc->sc_if);
    194  1.52     peter 	if_alloc_sadl(&sc->sc_if);
    195   1.2       cgd #if NBPFILTER > 0
    196  1.52     peter 	bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int));
    197   1.2       cgd #endif
    198  1.42      matt #ifdef MBUFTRACE
    199  1.52     peter 	sc->sc_if.if_mowner = malloc(sizeof(struct mowner), M_DEVBUF,
    200  1.52     peter 	    M_WAITOK | M_ZERO);
    201  1.52     peter 	strlcpy(sc->sc_if.if_mowner->mo_name, sc->sc_if.if_xname,
    202  1.52     peter 	    sizeof(sc->sc_if.if_mowner->mo_name));
    203  1.52     peter 	MOWNER_ATTACH(sc->sc_if.if_mowner);
    204  1.42      matt #endif
    205  1.52     peter 	LIST_INSERT_HEAD(&loop_softc_list, sc, sc_list);
    206  1.52     peter 
    207  1.52     peter 	return (0);
    208  1.52     peter }
    209  1.52     peter 
    210  1.57   thorpej static int
    211  1.52     peter loop_clone_destroy(struct ifnet *ifp)
    212  1.52     peter {
    213  1.52     peter 	struct loop_softc *sc = ifp->if_softc;
    214  1.52     peter 
    215  1.53     peter 	if (ifp == lo0ifp)
    216  1.53     peter 		return (EPERM);
    217  1.52     peter 
    218  1.52     peter #ifdef MBUFTRACE
    219  1.52     peter 	MOWNER_DETACH(ifp->if_mowner);
    220  1.52     peter 	free(ifp->if_mowner, M_DEVBUF);
    221  1.52     peter #endif
    222  1.52     peter 
    223  1.52     peter #if NBPFILTER > 0
    224  1.52     peter 	bpfdetach(ifp);
    225  1.52     peter #endif
    226  1.52     peter 	if_detach(ifp);
    227  1.52     peter 
    228  1.52     peter 	LIST_REMOVE(sc, sc_list);
    229  1.52     peter 	free(sc, M_DEVBUF);
    230  1.53     peter 
    231  1.53     peter 	return (0);
    232   1.1       cgd }
    233   1.1       cgd 
    234  1.11   mycroft int
    235  1.54     peter looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
    236  1.54     peter     struct rtentry *rt)
    237   1.1       cgd {
    238   1.1       cgd 	int s, isr;
    239  1.54     peter 	struct ifqueue *ifq = NULL;
    240   1.1       cgd 
    241  1.42      matt 	MCLAIM(m, ifp->if_mowner);
    242   1.1       cgd 	if ((m->m_flags & M_PKTHDR) == 0)
    243  1.14   mycroft 		panic("looutput: no header mbuf");
    244   1.2       cgd #if NBPFILTER > 0
    245  1.51  christos 	if (ifp->if_bpf && (ifp->if_flags & IFF_LOOPBACK))
    246  1.51  christos 		bpf_mtap_af(ifp->if_bpf, dst->sa_family, m);
    247   1.2       cgd #endif
    248   1.1       cgd 	m->m_pkthdr.rcvif = ifp;
    249   1.1       cgd 
    250  1.11   mycroft 	if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
    251   1.1       cgd 		m_freem(m);
    252  1.11   mycroft 		return (rt->rt_flags & RTF_BLACKHOLE ? 0 :
    253  1.11   mycroft 			rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH);
    254   1.1       cgd 	}
    255  1.26    itojun 
    256   1.1       cgd 	ifp->if_opackets++;
    257   1.1       cgd 	ifp->if_obytes += m->m_pkthdr.len;
    258  1.32   thorpej 
    259  1.32   thorpej #ifdef ALTQ
    260  1.32   thorpej 	/*
    261  1.32   thorpej 	 * ALTQ on the loopback interface is just for debugging.  It's
    262  1.32   thorpej 	 * used only for loopback interfaces, not for a simplex interface.
    263  1.32   thorpej 	 */
    264  1.32   thorpej 	if ((ALTQ_IS_ENABLED(&ifp->if_snd) || TBR_IS_ENABLED(&ifp->if_snd)) &&
    265  1.32   thorpej 	    ifp->if_start == lostart) {
    266  1.32   thorpej 		struct altq_pktattr pktattr;
    267  1.32   thorpej 		int error;
    268  1.32   thorpej 
    269  1.32   thorpej 		/*
    270  1.32   thorpej 		 * If the queueing discipline needs packet classification,
    271  1.32   thorpej 		 * do it before prepending the link headers.
    272  1.32   thorpej 		 */
    273  1.32   thorpej 		IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family, &pktattr);
    274  1.32   thorpej 
    275  1.32   thorpej 		M_PREPEND(m, sizeof(uint32_t), M_DONTWAIT);
    276  1.32   thorpej 		if (m == NULL)
    277  1.32   thorpej 			return (ENOBUFS);
    278  1.32   thorpej 		*(mtod(m, uint32_t *)) = dst->sa_family;
    279  1.32   thorpej 
    280  1.38   thorpej 		s = splnet();
    281  1.32   thorpej 		IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
    282  1.32   thorpej 		(*ifp->if_start)(ifp);
    283  1.32   thorpej 		splx(s);
    284  1.32   thorpej 		return (error);
    285  1.32   thorpej 	}
    286  1.32   thorpej #endif /* ALTQ */
    287  1.49  jonathan 
    288  1.49  jonathan 	m_tag_delete_nonpersistent(m);
    289  1.32   thorpej 
    290   1.1       cgd 	switch (dst->sa_family) {
    291   1.1       cgd 
    292   1.1       cgd #ifdef INET
    293   1.1       cgd 	case AF_INET:
    294   1.1       cgd 		ifq = &ipintrq;
    295   1.1       cgd 		isr = NETISR_IP;
    296   1.1       cgd 		break;
    297   1.1       cgd #endif
    298  1.26    itojun #ifdef INET6
    299  1.26    itojun 	case AF_INET6:
    300  1.26    itojun 		m->m_flags |= M_LOOP;
    301  1.26    itojun 		ifq = &ip6intrq;
    302  1.26    itojun 		isr = NETISR_IPV6;
    303  1.26    itojun 		break;
    304  1.26    itojun #endif
    305   1.1       cgd #ifdef NS
    306   1.1       cgd 	case AF_NS:
    307   1.1       cgd 		ifq = &nsintrq;
    308   1.1       cgd 		isr = NETISR_NS;
    309   1.1       cgd 		break;
    310   1.1       cgd #endif
    311   1.1       cgd #ifdef ISO
    312   1.1       cgd 	case AF_ISO:
    313   1.1       cgd 		ifq = &clnlintrq;
    314   1.1       cgd 		isr = NETISR_ISO;
    315  1.22  christos 		break;
    316  1.22  christos #endif
    317  1.22  christos #ifdef IPX
    318  1.22  christos 	case AF_IPX:
    319  1.22  christos 		ifq = &ipxintrq;
    320  1.22  christos 		isr = NETISR_IPX;
    321  1.19  christos 		break;
    322  1.19  christos #endif
    323  1.19  christos #ifdef NETATALK
    324  1.19  christos 	case AF_APPLETALK:
    325  1.19  christos 	        ifq = &atintrq2;
    326  1.19  christos 		isr = NETISR_ATALK;
    327   1.1       cgd 		break;
    328   1.1       cgd #endif
    329   1.1       cgd 	default:
    330  1.17  christos 		printf("%s: can't handle af%d\n", ifp->if_xname,
    331  1.16  christos 		    dst->sa_family);
    332   1.1       cgd 		m_freem(m);
    333   1.1       cgd 		return (EAFNOSUPPORT);
    334   1.1       cgd 	}
    335  1.38   thorpej 	s = splnet();
    336   1.1       cgd 	if (IF_QFULL(ifq)) {
    337   1.1       cgd 		IF_DROP(ifq);
    338   1.1       cgd 		m_freem(m);
    339   1.1       cgd 		splx(s);
    340   1.1       cgd 		return (ENOBUFS);
    341   1.1       cgd 	}
    342   1.1       cgd 	IF_ENQUEUE(ifq, m);
    343   1.1       cgd 	schednetisr(isr);
    344   1.1       cgd 	ifp->if_ipackets++;
    345   1.1       cgd 	ifp->if_ibytes += m->m_pkthdr.len;
    346   1.1       cgd 	splx(s);
    347   1.1       cgd 	return (0);
    348   1.1       cgd }
    349  1.32   thorpej 
    350  1.32   thorpej #ifdef ALTQ
    351  1.57   thorpej static void
    352  1.32   thorpej lostart(struct ifnet *ifp)
    353  1.32   thorpej {
    354  1.32   thorpej 	struct ifqueue *ifq;
    355  1.32   thorpej 	struct mbuf *m;
    356  1.32   thorpej 	uint32_t af;
    357  1.32   thorpej 	int s, isr;
    358  1.32   thorpej 
    359  1.32   thorpej 	for (;;) {
    360  1.32   thorpej 		IFQ_DEQUEUE(&ifp->if_snd, m);
    361  1.32   thorpej 		if (m == NULL)
    362  1.32   thorpej 			return;
    363  1.32   thorpej 
    364  1.32   thorpej 		af = *(mtod(m, uint32_t *));
    365  1.32   thorpej 		m_adj(m, sizeof(uint32_t));
    366  1.32   thorpej 
    367  1.32   thorpej 		switch (af) {
    368  1.32   thorpej #ifdef INET
    369  1.32   thorpej 		case AF_INET:
    370  1.32   thorpej 			ifq = &ipintrq;
    371  1.32   thorpej 			isr = NETISR_IP;
    372  1.32   thorpej 			break;
    373  1.32   thorpej #endif
    374  1.32   thorpej #ifdef INET6
    375  1.32   thorpej 		case AF_INET6:
    376  1.32   thorpej 			m->m_flags |= M_LOOP;
    377  1.32   thorpej 			ifq = &ip6intrq;
    378  1.32   thorpej 			isr = NETISR_IPV6;
    379  1.32   thorpej 			break;
    380  1.32   thorpej #endif
    381  1.32   thorpej #ifdef IPX
    382  1.32   thorpej 		case AF_IPX:
    383  1.32   thorpej 			ifq = &ipxintrq;
    384  1.32   thorpej 			isr = NETISR_IPX;
    385  1.32   thorpej 			break;
    386  1.32   thorpej #endif
    387  1.32   thorpej #ifdef NS
    388  1.32   thorpej 		case AF_NS:
    389  1.32   thorpej 			ifq = &nsintrq;
    390  1.32   thorpej 			isr = NETISR_NS;
    391  1.32   thorpej 			break;
    392  1.32   thorpej #endif
    393  1.32   thorpej #ifdef ISO
    394  1.32   thorpej 		case AF_ISO:
    395  1.32   thorpej 			ifq = &clnlintrq;
    396  1.32   thorpej 			isr = NETISR_ISO;
    397  1.32   thorpej 			break;
    398  1.32   thorpej #endif
    399  1.32   thorpej #ifdef NETATALK
    400  1.32   thorpej 		case AF_APPLETALK:
    401  1.32   thorpej 			ifq = &atintrq2;
    402  1.32   thorpej 			isr = NETISR_ATALK;
    403  1.32   thorpej 			break;
    404  1.32   thorpej #endif
    405  1.32   thorpej 		default:
    406  1.32   thorpej 			printf("%s: can't handle af%d\n", ifp->if_xname, af);
    407  1.32   thorpej 			m_freem(m);
    408  1.32   thorpej 			return;
    409  1.32   thorpej 		}
    410  1.32   thorpej 
    411  1.38   thorpej 		s = splnet();
    412  1.32   thorpej 		if (IF_QFULL(ifq)) {
    413  1.32   thorpej 			IF_DROP(ifq);
    414  1.32   thorpej 			splx(s);
    415  1.32   thorpej 			m_freem(m);
    416  1.32   thorpej 			return;
    417  1.32   thorpej 		}
    418  1.32   thorpej 		IF_ENQUEUE(ifq, m);
    419  1.32   thorpej 		schednetisr(isr);
    420  1.32   thorpej 		ifp->if_ipackets++;
    421  1.32   thorpej 		ifp->if_ibytes += m->m_pkthdr.len;
    422  1.32   thorpej 		splx(s);
    423  1.32   thorpej 	}
    424  1.32   thorpej }
    425  1.32   thorpej #endif /* ALTQ */
    426   1.1       cgd 
    427   1.1       cgd /* ARGSUSED */
    428  1.11   mycroft void
    429  1.54     peter lortrequest(int cmd, struct rtentry *rt, struct rt_addrinfo *info)
    430   1.1       cgd {
    431  1.11   mycroft 
    432   1.1       cgd 	if (rt)
    433  1.52     peter 		rt->rt_rmx.rmx_mtu = lo0ifp->if_mtu;
    434   1.1       cgd }
    435   1.1       cgd 
    436   1.1       cgd /*
    437   1.1       cgd  * Process an ioctl request.
    438   1.1       cgd  */
    439   1.1       cgd /* ARGSUSED */
    440  1.11   mycroft int
    441  1.54     peter loioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
    442   1.1       cgd {
    443  1.30  augustss 	struct ifaddr *ifa;
    444  1.30  augustss 	struct ifreq *ifr;
    445  1.30  augustss 	int error = 0;
    446   1.1       cgd 
    447   1.1       cgd 	switch (cmd) {
    448   1.1       cgd 
    449   1.1       cgd 	case SIOCSIFADDR:
    450   1.1       cgd 		ifp->if_flags |= IFF_UP;
    451   1.1       cgd 		ifa = (struct ifaddr *)data;
    452  1.54     peter 		if (ifa != NULL /*&& ifa->ifa_addr->sa_family == AF_ISO*/)
    453   1.1       cgd 			ifa->ifa_rtrequest = lortrequest;
    454   1.1       cgd 		/*
    455   1.1       cgd 		 * Everything else is done at a higher level.
    456   1.1       cgd 		 */
    457  1.48  jonathan 		break;
    458  1.48  jonathan 
    459  1.48  jonathan 	case SIOCSIFMTU:
    460  1.48  jonathan 		ifr = (struct ifreq *)data;
    461  1.48  jonathan 		if ((unsigned)ifr->ifr_mtu > LOMTU_MAX)
    462  1.48  jonathan 			error = EINVAL;
    463  1.48  jonathan 		else {
    464  1.48  jonathan 			/* XXX update rt mtu for AF_ISO? */
    465  1.48  jonathan 			ifp->if_mtu = ifr->ifr_mtu;
    466  1.48  jonathan 		}
    467   1.1       cgd 		break;
    468   1.1       cgd 
    469   1.8   hpeyerl 	case SIOCADDMULTI:
    470   1.8   hpeyerl 	case SIOCDELMULTI:
    471   1.8   hpeyerl 		ifr = (struct ifreq *)data;
    472  1.54     peter 		if (ifr == NULL) {
    473   1.8   hpeyerl 			error = EAFNOSUPPORT;		/* XXX */
    474   1.8   hpeyerl 			break;
    475   1.8   hpeyerl 		}
    476   1.8   hpeyerl 		switch (ifr->ifr_addr.sa_family) {
    477   1.8   hpeyerl 
    478   1.8   hpeyerl #ifdef INET
    479   1.8   hpeyerl 		case AF_INET:
    480  1.26    itojun 			break;
    481  1.26    itojun #endif
    482  1.26    itojun #ifdef INET6
    483  1.26    itojun 		case AF_INET6:
    484   1.8   hpeyerl 			break;
    485   1.8   hpeyerl #endif
    486  1.11   mycroft 
    487   1.8   hpeyerl 		default:
    488   1.8   hpeyerl 			error = EAFNOSUPPORT;
    489   1.8   hpeyerl 			break;
    490   1.8   hpeyerl 		}
    491   1.8   hpeyerl 		break;
    492  1.11   mycroft 
    493   1.1       cgd 	default:
    494   1.1       cgd 		error = EINVAL;
    495   1.1       cgd 	}
    496   1.1       cgd 	return (error);
    497   1.1       cgd }
    498