1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33fe6db7c7SRuslan Ermilov * @(#)if_loop.c 8.2 (Berkeley) 1/9/95 34c3aac50fSPeter Wemm * $FreeBSD$ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37df8bae1dSRodney W. Grimes /* 38df8bae1dSRodney W. Grimes * Loopback interface driver for protocol testing and timing. 39df8bae1dSRodney W. Grimes */ 40df8bae1dSRodney W. Grimes 417262d3e4SEivind Eklund #include "opt_atalk.h" 421d5e9e22SEivind Eklund #include "opt_inet.h" 43cfa1ca9dSYoshinobu Inoue #include "opt_inet6.h" 44430df5f4SEivind Eklund #include "opt_ipx.h" 45430df5f4SEivind Eklund 46df8bae1dSRodney W. Grimes #include <sys/param.h> 47df8bae1dSRodney W. Grimes #include <sys/systm.h> 48df8bae1dSRodney W. Grimes #include <sys/kernel.h> 4990d9802fSPeter Wemm #include <sys/malloc.h> 50df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 512b120974SPeter Wemm #include <sys/module.h> 523d4ce33dSBrooks Davis #include <machine/bus.h> 533d4ce33dSBrooks Davis #include <sys/rman.h> 54df8bae1dSRodney W. Grimes #include <sys/socket.h> 5551a53488SBruce Evans #include <sys/sockio.h> 5690d9802fSPeter Wemm #include <sys/sysctl.h> 57df8bae1dSRodney W. Grimes 58df8bae1dSRodney W. Grimes #include <net/if.h> 59df8bae1dSRodney W. Grimes #include <net/if_types.h> 60df8bae1dSRodney W. Grimes #include <net/netisr.h> 61df8bae1dSRodney W. Grimes #include <net/route.h> 62df8bae1dSRodney W. Grimes #include <net/bpf.h> 6333841545SHajimu UMEMOTO #include <net/bpfdesc.h> 64df8bae1dSRodney W. Grimes 65df8bae1dSRodney W. Grimes #ifdef INET 66df8bae1dSRodney W. Grimes #include <netinet/in.h> 67df8bae1dSRodney W. Grimes #include <netinet/in_var.h> 68df8bae1dSRodney W. Grimes #endif 69df8bae1dSRodney W. Grimes 70cc6a66f2SJulian Elischer #ifdef IPX 71cc6a66f2SJulian Elischer #include <netipx/ipx.h> 72cc6a66f2SJulian Elischer #include <netipx/ipx_if.h> 73cc6a66f2SJulian Elischer #endif 74cc6a66f2SJulian Elischer 7582cd038dSYoshinobu Inoue #ifdef INET6 7682cd038dSYoshinobu Inoue #ifndef INET 7782cd038dSYoshinobu Inoue #include <netinet/in.h> 7882cd038dSYoshinobu Inoue #endif 7982cd038dSYoshinobu Inoue #include <netinet6/in6_var.h> 80686cdd19SJun-ichiro itojun Hagino #include <netinet/ip6.h> 8182cd038dSYoshinobu Inoue #endif 8282cd038dSYoshinobu Inoue 83df8bae1dSRodney W. Grimes #ifdef NS 84df8bae1dSRodney W. Grimes #include <netns/ns.h> 85df8bae1dSRodney W. Grimes #include <netns/ns_if.h> 86df8bae1dSRodney W. Grimes #endif 87df8bae1dSRodney W. Grimes 88655929bfSJulian Elischer #ifdef NETATALK 89655929bfSJulian Elischer #include <netatalk/at.h> 90655929bfSJulian Elischer #include <netatalk/at_var.h> 918cdfefbdSPeter Wemm #endif 92655929bfSJulian Elischer 93db8889c6SDavid Greenman #ifdef TINY_LOMTU 94df8bae1dSRodney W. Grimes #define LOMTU (1024+512) 9582cd038dSYoshinobu Inoue #elif defined(LARGE_LOMTU) 9682cd038dSYoshinobu Inoue #define LOMTU 131072 97db8889c6SDavid Greenman #else 98af78195eSDavid Greenman #define LOMTU 16384 99db8889c6SDavid Greenman #endif 100df8bae1dSRodney W. Grimes 1013d4ce33dSBrooks Davis #define LONAME "lo" 10290d9802fSPeter Wemm 10390d9802fSPeter Wemm struct lo_softc { 10490d9802fSPeter Wemm struct ifnet sc_if; /* network-visible interface */ 10590d9802fSPeter Wemm LIST_ENTRY(lo_softc) sc_next; 10690d9802fSPeter Wemm }; 1073d4ce33dSBrooks Davis 1083d4ce33dSBrooks Davis int loioctl(struct ifnet *, u_long, caddr_t); 1093d4ce33dSBrooks Davis static void lortrequest(int, struct rtentry *, struct rt_addrinfo *); 1103d4ce33dSBrooks Davis int looutput(struct ifnet *ifp, struct mbuf *m, 1113d4ce33dSBrooks Davis struct sockaddr *dst, struct rtentry *rt); 1123b16e7b2SMaxime Henrion int lo_clone_create(struct if_clone *, int); 1133d4ce33dSBrooks Davis int lo_clone_destroy(struct ifnet *); 1143d4ce33dSBrooks Davis 1153d4ce33dSBrooks Davis struct ifnet *loif = NULL; /* Used externally */ 1163d4ce33dSBrooks Davis 1173d4ce33dSBrooks Davis static MALLOC_DEFINE(M_LO, LONAME, "Loopback Interface"); 1183d4ce33dSBrooks Davis 11990d9802fSPeter Wemm static LIST_HEAD(lo_list, lo_softc) lo_list; 12090d9802fSPeter Wemm 1213d4ce33dSBrooks Davis struct if_clone lo_cloner = 1223b16e7b2SMaxime Henrion IF_CLONE_INITIALIZER(LONAME, lo_clone_create, lo_clone_destroy, IF_MAXUNIT); 1233d4ce33dSBrooks Davis 1243d4ce33dSBrooks Davis int 1253d4ce33dSBrooks Davis lo_clone_destroy(ifp) 1263d4ce33dSBrooks Davis struct ifnet *ifp; 1273d4ce33dSBrooks Davis { 1283d4ce33dSBrooks Davis struct lo_softc *sc; 1293d4ce33dSBrooks Davis 1303d4ce33dSBrooks Davis sc = ifp->if_softc; 1313d4ce33dSBrooks Davis 1323d4ce33dSBrooks Davis /* 1333d4ce33dSBrooks Davis * Prevent lo0 from being destroyed. 1343d4ce33dSBrooks Davis */ 1353d4ce33dSBrooks Davis if (loif == ifp) 1363d4ce33dSBrooks Davis return (EINVAL); 1373d4ce33dSBrooks Davis 1383d4ce33dSBrooks Davis bpfdetach(ifp); 1393d4ce33dSBrooks Davis if_detach(ifp); 1403d4ce33dSBrooks Davis LIST_REMOVE(sc, sc_next); 141d722be54SLuigi Rizzo free(sc, M_LO); 1423d4ce33dSBrooks Davis return (0); 1433d4ce33dSBrooks Davis } 1443d4ce33dSBrooks Davis 1453b16e7b2SMaxime Henrion int 1463b16e7b2SMaxime Henrion lo_clone_create(ifc, unit) 1473b16e7b2SMaxime Henrion struct if_clone *ifc; 1483b16e7b2SMaxime Henrion int unit; 14990d9802fSPeter Wemm { 15090d9802fSPeter Wemm struct lo_softc *sc; 15190d9802fSPeter Wemm 1521707240dSBoris Popov MALLOC(sc, struct lo_softc *, sizeof(*sc), M_LO, M_WAITOK | M_ZERO); 15390d9802fSPeter Wemm 1543d4ce33dSBrooks Davis sc->sc_if.if_name = LONAME; 15590d9802fSPeter Wemm sc->sc_if.if_unit = unit; 15690d9802fSPeter Wemm sc->sc_if.if_mtu = LOMTU; 15790d9802fSPeter Wemm sc->sc_if.if_flags = IFF_LOOPBACK | IFF_MULTICAST; 15890d9802fSPeter Wemm sc->sc_if.if_ioctl = loioctl; 15990d9802fSPeter Wemm sc->sc_if.if_output = looutput; 16090d9802fSPeter Wemm sc->sc_if.if_type = IFT_LOOP; 16190d9802fSPeter Wemm sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen; 1623d4ce33dSBrooks Davis sc->sc_if.if_softc = sc; 16390d9802fSPeter Wemm if_attach(&sc->sc_if); 16490d9802fSPeter Wemm bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int)); 16590d9802fSPeter Wemm LIST_INSERT_HEAD(&lo_list, sc, sc_next); 16690d9802fSPeter Wemm if (loif == NULL) 16790d9802fSPeter Wemm loif = &sc->sc_if; 1683b16e7b2SMaxime Henrion 1693b16e7b2SMaxime Henrion return (0); 17090d9802fSPeter Wemm } 17190d9802fSPeter Wemm 1722b120974SPeter Wemm static int 1732b120974SPeter Wemm loop_modevent(module_t mod, int type, void *data) 174df8bae1dSRodney W. Grimes { 1753d4ce33dSBrooks Davis int err; 176df8bae1dSRodney W. Grimes 1772b120974SPeter Wemm switch (type) { 1782b120974SPeter Wemm case MOD_LOAD: 1793d4ce33dSBrooks Davis LIST_INIT(&lo_list); 1803d4ce33dSBrooks Davis if_clone_attach(&lo_cloner); 1813d4ce33dSBrooks Davis 1823d4ce33dSBrooks Davis /* Create lo0 */ 1833b16e7b2SMaxime Henrion err = if_clone_create("lo0", sizeof ("lo0")); 1843d4ce33dSBrooks Davis KASSERT(err == 0, ("%s: can't create lo0", __func__)); 1852b120974SPeter Wemm break; 1862b120974SPeter Wemm case MOD_UNLOAD: 1872b120974SPeter Wemm printf("loop module unload - not possible for this module type\n"); 1882b120974SPeter Wemm return EINVAL; 189f5fea3ddSPaul Traina } 1902b120974SPeter Wemm return 0; 1912b120974SPeter Wemm } 1922b120974SPeter Wemm 1932b120974SPeter Wemm static moduledata_t loop_mod = { 1942b120974SPeter Wemm "loop", 1952b120974SPeter Wemm loop_modevent, 1962b120974SPeter Wemm 0 1972b120974SPeter Wemm }; 1982b120974SPeter Wemm 1992b120974SPeter Wemm DECLARE_MODULE(loop, loop_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 200df8bae1dSRodney W. Grimes 201cfa1ca9dSYoshinobu Inoue int 202df8bae1dSRodney W. Grimes looutput(ifp, m, dst, rt) 203df8bae1dSRodney W. Grimes struct ifnet *ifp; 204df8bae1dSRodney W. Grimes register struct mbuf *m; 205df8bae1dSRodney W. Grimes struct sockaddr *dst; 206df8bae1dSRodney W. Grimes register struct rtentry *rt; 207df8bae1dSRodney W. Grimes { 208ed7509acSJulian Elischer if ((m->m_flags & M_PKTHDR) == 0) 209ed7509acSJulian Elischer panic("looutput no HDR"); 210ed7509acSJulian Elischer 211ed7509acSJulian Elischer if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) { 212ed7509acSJulian Elischer m_freem(m); 213ed7509acSJulian Elischer return (rt->rt_flags & RTF_BLACKHOLE ? 0 : 214ed7509acSJulian Elischer rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); 215ed7509acSJulian Elischer } 21682cd038dSYoshinobu Inoue /* 21782cd038dSYoshinobu Inoue * KAME requires that the packet to be contiguous on the 21882cd038dSYoshinobu Inoue * mbuf. We need to make that sure. 21982cd038dSYoshinobu Inoue * this kind of code should be avoided. 22082cd038dSYoshinobu Inoue * XXX: fails to join if interface MTU > MCLBYTES. jumbogram? 22182cd038dSYoshinobu Inoue */ 22282cd038dSYoshinobu Inoue if (m && m->m_next != NULL && m->m_pkthdr.len < MCLBYTES) { 22382cd038dSYoshinobu Inoue struct mbuf *n; 22482cd038dSYoshinobu Inoue 22582cd038dSYoshinobu Inoue MGETHDR(n, M_DONTWAIT, MT_HEADER); 22682cd038dSYoshinobu Inoue if (!n) 22782cd038dSYoshinobu Inoue goto contiguousfail; 22882cd038dSYoshinobu Inoue MCLGET(n, M_DONTWAIT); 22982cd038dSYoshinobu Inoue if (! (n->m_flags & M_EXT)) { 23082cd038dSYoshinobu Inoue m_freem(n); 23182cd038dSYoshinobu Inoue goto contiguousfail; 23282cd038dSYoshinobu Inoue } 23382cd038dSYoshinobu Inoue 23482cd038dSYoshinobu Inoue m_copydata(m, 0, m->m_pkthdr.len, mtod(n, caddr_t)); 23582cd038dSYoshinobu Inoue n->m_pkthdr = m->m_pkthdr; 23682cd038dSYoshinobu Inoue n->m_len = m->m_pkthdr.len; 23733841545SHajimu UMEMOTO n->m_pkthdr.aux = m->m_pkthdr.aux; 23833841545SHajimu UMEMOTO m->m_pkthdr.aux = (struct mbuf *)NULL; 23982cd038dSYoshinobu Inoue m_freem(m); 24082cd038dSYoshinobu Inoue m = n; 24182cd038dSYoshinobu Inoue } 24282cd038dSYoshinobu Inoue if (0) { 24382cd038dSYoshinobu Inoue contiguousfail: 24482cd038dSYoshinobu Inoue printf("looutput: mbuf allocation failed\n"); 24582cd038dSYoshinobu Inoue } 24682cd038dSYoshinobu Inoue 247ed7509acSJulian Elischer ifp->if_opackets++; 248ed7509acSJulian Elischer ifp->if_obytes += m->m_pkthdr.len; 249201c2527SJulian Elischer #if 1 /* XXX */ 250201c2527SJulian Elischer switch (dst->sa_family) { 251201c2527SJulian Elischer case AF_INET: 25282cd038dSYoshinobu Inoue case AF_INET6: 253201c2527SJulian Elischer case AF_IPX: 254201c2527SJulian Elischer case AF_NS: 255201c2527SJulian Elischer case AF_APPLETALK: 25605b3ccefSJulian Elischer break; 257201c2527SJulian Elischer default: 25871582bf5SRobert Watson printf("looutput: af=%d unexpected\n", dst->sa_family); 259201c2527SJulian Elischer m_freem(m); 260201c2527SJulian Elischer return (EAFNOSUPPORT); 261201c2527SJulian Elischer } 262201c2527SJulian Elischer #endif 26306a429a3SArchie Cobbs return(if_simloop(ifp, m, dst->sa_family, 0)); 264ed7509acSJulian Elischer } 265ed7509acSJulian Elischer 266ed7509acSJulian Elischer /* 267ed7509acSJulian Elischer * if_simloop() 268ed7509acSJulian Elischer * 269ed7509acSJulian Elischer * This function is to support software emulation of hardware loopback, 270ed7509acSJulian Elischer * i.e., for interfaces with the IFF_SIMPLEX attribute. Since they can't 271ed7509acSJulian Elischer * hear their own broadcasts, we create a copy of the packet that we 272ed7509acSJulian Elischer * would normally receive via a hardware loopback. 273ed7509acSJulian Elischer * 274ed7509acSJulian Elischer * This function expects the packet to include the media header of length hlen. 275ed7509acSJulian Elischer */ 276ed7509acSJulian Elischer 277ed7509acSJulian Elischer int 27806a429a3SArchie Cobbs if_simloop(ifp, m, af, hlen) 279ed7509acSJulian Elischer struct ifnet *ifp; 28033841545SHajimu UMEMOTO struct mbuf *m; 28106a429a3SArchie Cobbs int af; 282ed7509acSJulian Elischer int hlen; 283ed7509acSJulian Elischer { 284df5e1987SJonathan Lemon int isr; 285df5e1987SJonathan Lemon struct ifqueue *inq = 0; 286df8bae1dSRodney W. Grimes 28706a429a3SArchie Cobbs KASSERT((m->m_flags & M_PKTHDR) != 0, ("if_simloop: no HDR")); 288ed7509acSJulian Elischer m->m_pkthdr.rcvif = ifp; 28906a429a3SArchie Cobbs 290963e4c2aSGarrett Wollman /* BPF write needs to be handled specially */ 29106a429a3SArchie Cobbs if (af == AF_UNSPEC) { 29206a429a3SArchie Cobbs KASSERT(m->m_len >= sizeof(int), ("if_simloop: m_len")); 29306a429a3SArchie Cobbs af = *(mtod(m, int *)); 294963e4c2aSGarrett Wollman m->m_len -= sizeof(int); 295963e4c2aSGarrett Wollman m->m_pkthdr.len -= sizeof(int); 296963e4c2aSGarrett Wollman m->m_data += sizeof(int); 297963e4c2aSGarrett Wollman } 298963e4c2aSGarrett Wollman 29906a429a3SArchie Cobbs /* Let BPF see incoming packet */ 300f5fea3ddSPaul Traina if (ifp->if_bpf) { 301ed7509acSJulian Elischer struct mbuf m0, *n = m; 302ed7509acSJulian Elischer 30333841545SHajimu UMEMOTO if (ifp->if_bpf->bif_dlt == DLT_NULL) { 304df8bae1dSRodney W. Grimes /* 305df8bae1dSRodney W. Grimes * We need to prepend the address family as 306df8bae1dSRodney W. Grimes * a four byte field. Cons up a dummy header 307df8bae1dSRodney W. Grimes * to pacify bpf. This is safe because bpf 308df8bae1dSRodney W. Grimes * will only read from the mbuf (i.e., it won't 309df8bae1dSRodney W. Grimes * try to free it or keep a pointer a to it). 310df8bae1dSRodney W. Grimes */ 311df8bae1dSRodney W. Grimes m0.m_next = m; 312df8bae1dSRodney W. Grimes m0.m_len = 4; 313df8bae1dSRodney W. Grimes m0.m_data = (char *)⁡ 314ed7509acSJulian Elischer n = &m0; 31533841545SHajimu UMEMOTO } 316ed7509acSJulian Elischer bpf_mtap(ifp, n); 317df8bae1dSRodney W. Grimes } 318df8bae1dSRodney W. Grimes 319ed7509acSJulian Elischer /* Strip away media header */ 3203a43ad8fSDoug Rabson if (hlen > 0) { 321fe81f64fSAndrew Gallatin m_adj(m, hlen); 322ebffbf8cSJake Burkholder #if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) 3233a43ad8fSDoug Rabson /* The alpha doesn't like unaligned data. 3243a43ad8fSDoug Rabson * We move data down in the first mbuf */ 325fe81f64fSAndrew Gallatin if (mtod(m, vm_offset_t) & 3) { 32660ed92ddSMatt Jacob KASSERT(hlen >= 3, ("if_simloop: hlen too small")); 327fe81f64fSAndrew Gallatin bcopy(m->m_data, 328fe81f64fSAndrew Gallatin (char *)(mtod(m, vm_offset_t) 329fe81f64fSAndrew Gallatin - (mtod(m, vm_offset_t) & 3)), 330fe81f64fSAndrew Gallatin m->m_len); 331fe81f64fSAndrew Gallatin mtod(m,vm_offset_t) -= (mtod(m, vm_offset_t) & 3); 332fe81f64fSAndrew Gallatin } 3333a43ad8fSDoug Rabson #endif 3343a43ad8fSDoug Rabson } 335ed7509acSJulian Elischer 33606a429a3SArchie Cobbs /* Deliver to upper layer protocol */ 33706a429a3SArchie Cobbs switch (af) { 338df8bae1dSRodney W. Grimes #ifdef INET 339df8bae1dSRodney W. Grimes case AF_INET: 340df5e1987SJonathan Lemon inq = &ipintrq; 341df8bae1dSRodney W. Grimes isr = NETISR_IP; 342df8bae1dSRodney W. Grimes break; 343df8bae1dSRodney W. Grimes #endif 34482cd038dSYoshinobu Inoue #ifdef INET6 34582cd038dSYoshinobu Inoue case AF_INET6: 34682cd038dSYoshinobu Inoue m->m_flags |= M_LOOP; 347df5e1987SJonathan Lemon inq = &ip6intrq; 34882cd038dSYoshinobu Inoue isr = NETISR_IPV6; 34982cd038dSYoshinobu Inoue break; 35082cd038dSYoshinobu Inoue #endif 351cc6a66f2SJulian Elischer #ifdef IPX 352cc6a66f2SJulian Elischer case AF_IPX: 353df5e1987SJonathan Lemon inq = &ipxintrq; 354cc6a66f2SJulian Elischer isr = NETISR_IPX; 355cc6a66f2SJulian Elischer break; 356cc6a66f2SJulian Elischer #endif 357df8bae1dSRodney W. Grimes #ifdef NS 358df8bae1dSRodney W. Grimes case AF_NS: 359df5e1987SJonathan Lemon inq = &nsintrq; 360df8bae1dSRodney W. Grimes isr = NETISR_NS; 361df8bae1dSRodney W. Grimes break; 362df8bae1dSRodney W. Grimes #endif 363655929bfSJulian Elischer #ifdef NETATALK 364655929bfSJulian Elischer case AF_APPLETALK: 365df5e1987SJonathan Lemon inq = &atintrq2; 366655929bfSJulian Elischer isr = NETISR_ATALK; 367655929bfSJulian Elischer break; 3688cdfefbdSPeter Wemm #endif 369df8bae1dSRodney W. Grimes default: 37006a429a3SArchie Cobbs printf("if_simloop: can't handle af=%d\n", af); 371df8bae1dSRodney W. Grimes m_freem(m); 372df8bae1dSRodney W. Grimes return (EAFNOSUPPORT); 373df8bae1dSRodney W. Grimes } 374df8bae1dSRodney W. Grimes ifp->if_ipackets++; 375df8bae1dSRodney W. Grimes ifp->if_ibytes += m->m_pkthdr.len; 376df5e1987SJonathan Lemon (void) IF_HANDOFF(inq, m, NULL); 377df5e1987SJonathan Lemon schednetisr(isr); 378df8bae1dSRodney W. Grimes return (0); 379df8bae1dSRodney W. Grimes } 380df8bae1dSRodney W. Grimes 381df8bae1dSRodney W. Grimes /* ARGSUSED */ 3823bda9f9bSPoul-Henning Kamp static void 3838071913dSRuslan Ermilov lortrequest(cmd, rt, info) 384df8bae1dSRodney W. Grimes int cmd; 385df8bae1dSRodney W. Grimes struct rtentry *rt; 3868071913dSRuslan Ermilov struct rt_addrinfo *info; 387df8bae1dSRodney W. Grimes { 3885eb1d25aSGarrett Wollman if (rt) { 3895eb1d25aSGarrett Wollman rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; /* for ISO */ 3905eb1d25aSGarrett Wollman /* 3915eb1d25aSGarrett Wollman * For optimal performance, the send and receive buffers 3925eb1d25aSGarrett Wollman * should be at least twice the MTU plus a little more for 3935eb1d25aSGarrett Wollman * overhead. 3945eb1d25aSGarrett Wollman */ 3955eb1d25aSGarrett Wollman rt->rt_rmx.rmx_recvpipe = 3965eb1d25aSGarrett Wollman rt->rt_rmx.rmx_sendpipe = 3 * LOMTU; 3975eb1d25aSGarrett Wollman } 398df8bae1dSRodney W. Grimes } 399df8bae1dSRodney W. Grimes 400df8bae1dSRodney W. Grimes /* 401df8bae1dSRodney W. Grimes * Process an ioctl request. 402df8bae1dSRodney W. Grimes */ 403df8bae1dSRodney W. Grimes /* ARGSUSED */ 404cfa1ca9dSYoshinobu Inoue int 405df8bae1dSRodney W. Grimes loioctl(ifp, cmd, data) 406df8bae1dSRodney W. Grimes register struct ifnet *ifp; 407ecbb00a2SDoug Rabson u_long cmd; 408df8bae1dSRodney W. Grimes caddr_t data; 409df8bae1dSRodney W. Grimes { 410df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 41190fd8c38SDavid Greenman register struct ifreq *ifr = (struct ifreq *)data; 412df8bae1dSRodney W. Grimes register int error = 0; 413df8bae1dSRodney W. Grimes 414df8bae1dSRodney W. Grimes switch (cmd) { 415df8bae1dSRodney W. Grimes 416df8bae1dSRodney W. Grimes case SIOCSIFADDR: 417b8dc74a3SGarrett Wollman ifp->if_flags |= IFF_UP | IFF_RUNNING; 418df8bae1dSRodney W. Grimes ifa = (struct ifaddr *)data; 419df8bae1dSRodney W. Grimes ifa->ifa_rtrequest = lortrequest; 420df8bae1dSRodney W. Grimes /* 421df8bae1dSRodney W. Grimes * Everything else is done at a higher level. 422df8bae1dSRodney W. Grimes */ 423df8bae1dSRodney W. Grimes break; 424df8bae1dSRodney W. Grimes 425df8bae1dSRodney W. Grimes case SIOCADDMULTI: 426df8bae1dSRodney W. Grimes case SIOCDELMULTI: 427df8bae1dSRodney W. Grimes if (ifr == 0) { 428df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; /* XXX */ 429df8bae1dSRodney W. Grimes break; 430df8bae1dSRodney W. Grimes } 431df8bae1dSRodney W. Grimes switch (ifr->ifr_addr.sa_family) { 432df8bae1dSRodney W. Grimes 433df8bae1dSRodney W. Grimes #ifdef INET 434df8bae1dSRodney W. Grimes case AF_INET: 435df8bae1dSRodney W. Grimes break; 436df8bae1dSRodney W. Grimes #endif 43782cd038dSYoshinobu Inoue #ifdef INET6 43882cd038dSYoshinobu Inoue case AF_INET6: 43982cd038dSYoshinobu Inoue break; 44082cd038dSYoshinobu Inoue #endif 441df8bae1dSRodney W. Grimes 442df8bae1dSRodney W. Grimes default: 443df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; 444df8bae1dSRodney W. Grimes break; 445df8bae1dSRodney W. Grimes } 446df8bae1dSRodney W. Grimes break; 447df8bae1dSRodney W. Grimes 44890fd8c38SDavid Greenman case SIOCSIFMTU: 44990fd8c38SDavid Greenman ifp->if_mtu = ifr->ifr_mtu; 45090fd8c38SDavid Greenman break; 45190fd8c38SDavid Greenman 452ce42f1fbSPoul-Henning Kamp case SIOCSIFFLAGS: 453ce42f1fbSPoul-Henning Kamp break; 454ce42f1fbSPoul-Henning Kamp 455df8bae1dSRodney W. Grimes default: 456df8bae1dSRodney W. Grimes error = EINVAL; 457df8bae1dSRodney W. Grimes } 458df8bae1dSRodney W. Grimes return (error); 459df8bae1dSRodney W. Grimes } 460