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" 45fe6fb873SRobert Watson #include "opt_mac.h" 46430df5f4SEivind Eklund 47df8bae1dSRodney W. Grimes #include <sys/param.h> 48df8bae1dSRodney W. Grimes #include <sys/systm.h> 49df8bae1dSRodney W. Grimes #include <sys/kernel.h> 50fe6fb873SRobert Watson #include <sys/mac.h> 5190d9802fSPeter Wemm #include <sys/malloc.h> 52df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 532b120974SPeter Wemm #include <sys/module.h> 543d4ce33dSBrooks Davis #include <machine/bus.h> 553d4ce33dSBrooks Davis #include <sys/rman.h> 56df8bae1dSRodney W. Grimes #include <sys/socket.h> 5751a53488SBruce Evans #include <sys/sockio.h> 5890d9802fSPeter Wemm #include <sys/sysctl.h> 59df8bae1dSRodney W. Grimes 60df8bae1dSRodney W. Grimes #include <net/if.h> 61df8bae1dSRodney W. Grimes #include <net/if_types.h> 62df8bae1dSRodney W. Grimes #include <net/netisr.h> 63df8bae1dSRodney W. Grimes #include <net/route.h> 64df8bae1dSRodney W. Grimes #include <net/bpf.h> 6533841545SHajimu UMEMOTO #include <net/bpfdesc.h> 66df8bae1dSRodney W. Grimes 67df8bae1dSRodney W. Grimes #ifdef INET 68df8bae1dSRodney W. Grimes #include <netinet/in.h> 69df8bae1dSRodney W. Grimes #include <netinet/in_var.h> 70df8bae1dSRodney W. Grimes #endif 71df8bae1dSRodney W. Grimes 72cc6a66f2SJulian Elischer #ifdef IPX 73cc6a66f2SJulian Elischer #include <netipx/ipx.h> 74cc6a66f2SJulian Elischer #include <netipx/ipx_if.h> 75cc6a66f2SJulian Elischer #endif 76cc6a66f2SJulian Elischer 7782cd038dSYoshinobu Inoue #ifdef INET6 7882cd038dSYoshinobu Inoue #ifndef INET 7982cd038dSYoshinobu Inoue #include <netinet/in.h> 8082cd038dSYoshinobu Inoue #endif 8182cd038dSYoshinobu Inoue #include <netinet6/in6_var.h> 82686cdd19SJun-ichiro itojun Hagino #include <netinet/ip6.h> 8382cd038dSYoshinobu Inoue #endif 8482cd038dSYoshinobu Inoue 85655929bfSJulian Elischer #ifdef NETATALK 86655929bfSJulian Elischer #include <netatalk/at.h> 87655929bfSJulian Elischer #include <netatalk/at_var.h> 888cdfefbdSPeter Wemm #endif 89655929bfSJulian Elischer 90db8889c6SDavid Greenman #ifdef TINY_LOMTU 91df8bae1dSRodney W. Grimes #define LOMTU (1024+512) 9282cd038dSYoshinobu Inoue #elif defined(LARGE_LOMTU) 9382cd038dSYoshinobu Inoue #define LOMTU 131072 94db8889c6SDavid Greenman #else 95af78195eSDavid Greenman #define LOMTU 16384 96db8889c6SDavid Greenman #endif 97df8bae1dSRodney W. Grimes 983d4ce33dSBrooks Davis #define LONAME "lo" 9990d9802fSPeter Wemm 10090d9802fSPeter Wemm struct lo_softc { 10190d9802fSPeter Wemm struct ifnet sc_if; /* network-visible interface */ 10290d9802fSPeter Wemm LIST_ENTRY(lo_softc) sc_next; 10390d9802fSPeter Wemm }; 1043d4ce33dSBrooks Davis 1053d4ce33dSBrooks Davis int loioctl(struct ifnet *, u_long, caddr_t); 1063d4ce33dSBrooks Davis static void lortrequest(int, struct rtentry *, struct rt_addrinfo *); 1073d4ce33dSBrooks Davis int looutput(struct ifnet *ifp, struct mbuf *m, 1083d4ce33dSBrooks Davis struct sockaddr *dst, struct rtentry *rt); 1093b16e7b2SMaxime Henrion int lo_clone_create(struct if_clone *, int); 110ae5a19beSBrooks Davis void lo_clone_destroy(struct ifnet *); 1113d4ce33dSBrooks Davis 1123d4ce33dSBrooks Davis struct ifnet *loif = NULL; /* Used externally */ 1133d4ce33dSBrooks Davis 1143d4ce33dSBrooks Davis static MALLOC_DEFINE(M_LO, LONAME, "Loopback Interface"); 1153d4ce33dSBrooks Davis 11690d9802fSPeter Wemm static LIST_HEAD(lo_list, lo_softc) lo_list; 11790d9802fSPeter Wemm 118ae5a19beSBrooks Davis struct if_clone lo_cloner = IF_CLONE_INITIALIZER(LONAME, 119ae5a19beSBrooks Davis lo_clone_create, lo_clone_destroy, 1, IF_MAXUNIT); 1203d4ce33dSBrooks Davis 121ae5a19beSBrooks Davis void 1223d4ce33dSBrooks Davis lo_clone_destroy(ifp) 1233d4ce33dSBrooks Davis struct ifnet *ifp; 1243d4ce33dSBrooks Davis { 1253d4ce33dSBrooks Davis struct lo_softc *sc; 1263d4ce33dSBrooks Davis 1273d4ce33dSBrooks Davis sc = ifp->if_softc; 1283d4ce33dSBrooks Davis 129ae5a19beSBrooks Davis /* XXX: destroying lo0 will lead to panics. */ 130ae5a19beSBrooks Davis KASSERT(loif != ifp, ("%s: destroying lo0", __func__)); 1313d4ce33dSBrooks Davis 1323d4ce33dSBrooks Davis bpfdetach(ifp); 1333d4ce33dSBrooks Davis if_detach(ifp); 1343d4ce33dSBrooks Davis LIST_REMOVE(sc, sc_next); 135d722be54SLuigi Rizzo free(sc, M_LO); 1363d4ce33dSBrooks Davis } 1373d4ce33dSBrooks Davis 1383b16e7b2SMaxime Henrion int 1393b16e7b2SMaxime Henrion lo_clone_create(ifc, unit) 1403b16e7b2SMaxime Henrion struct if_clone *ifc; 1413b16e7b2SMaxime Henrion int unit; 14290d9802fSPeter Wemm { 14390d9802fSPeter Wemm struct lo_softc *sc; 14490d9802fSPeter Wemm 145a163d034SWarner Losh MALLOC(sc, struct lo_softc *, sizeof(*sc), M_LO, M_WAITOK | M_ZERO); 14690d9802fSPeter Wemm 1479bf40edeSBrooks Davis if_initname(&sc->sc_if, ifc->ifc_name, unit); 14890d9802fSPeter Wemm sc->sc_if.if_mtu = LOMTU; 14990d9802fSPeter Wemm sc->sc_if.if_flags = IFF_LOOPBACK | IFF_MULTICAST; 15090d9802fSPeter Wemm sc->sc_if.if_ioctl = loioctl; 15190d9802fSPeter Wemm sc->sc_if.if_output = looutput; 15290d9802fSPeter Wemm sc->sc_if.if_type = IFT_LOOP; 15390d9802fSPeter Wemm sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen; 1543d4ce33dSBrooks Davis sc->sc_if.if_softc = sc; 15590d9802fSPeter Wemm if_attach(&sc->sc_if); 15690d9802fSPeter Wemm bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int)); 15790d9802fSPeter Wemm LIST_INSERT_HEAD(&lo_list, sc, sc_next); 15890d9802fSPeter Wemm if (loif == NULL) 15990d9802fSPeter Wemm loif = &sc->sc_if; 1603b16e7b2SMaxime Henrion 1613b16e7b2SMaxime Henrion return (0); 16290d9802fSPeter Wemm } 16390d9802fSPeter Wemm 1642b120974SPeter Wemm static int 1652b120974SPeter Wemm loop_modevent(module_t mod, int type, void *data) 166df8bae1dSRodney W. Grimes { 1672b120974SPeter Wemm switch (type) { 1682b120974SPeter Wemm case MOD_LOAD: 1693d4ce33dSBrooks Davis LIST_INIT(&lo_list); 1703d4ce33dSBrooks Davis if_clone_attach(&lo_cloner); 1712b120974SPeter Wemm break; 1722b120974SPeter Wemm case MOD_UNLOAD: 1732b120974SPeter Wemm printf("loop module unload - not possible for this module type\n"); 1742b120974SPeter Wemm return EINVAL; 175f5fea3ddSPaul Traina } 1762b120974SPeter Wemm return 0; 1772b120974SPeter Wemm } 1782b120974SPeter Wemm 1792b120974SPeter Wemm static moduledata_t loop_mod = { 1802b120974SPeter Wemm "loop", 1812b120974SPeter Wemm loop_modevent, 1822b120974SPeter Wemm 0 1832b120974SPeter Wemm }; 1842b120974SPeter Wemm 18578ece553SAlexander Kabaev DECLARE_MODULE(loop, loop_mod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY); 186df8bae1dSRodney W. Grimes 187cfa1ca9dSYoshinobu Inoue int 188df8bae1dSRodney W. Grimes looutput(ifp, m, dst, rt) 189df8bae1dSRodney W. Grimes struct ifnet *ifp; 190df8bae1dSRodney W. Grimes register struct mbuf *m; 191df8bae1dSRodney W. Grimes struct sockaddr *dst; 192df8bae1dSRodney W. Grimes register struct rtentry *rt; 193df8bae1dSRodney W. Grimes { 1947ab9842aSMike Silbersack #ifdef INET6 19517d65319SMike Silbersack struct mbuf *n; 1967ab9842aSMike Silbersack #endif 197fe584538SDag-Erling Smørgrav 198fe584538SDag-Erling Smørgrav M_ASSERTPKTHDR(m); /* check if we have the packet header */ 199ed7509acSJulian Elischer 200ed7509acSJulian Elischer if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) { 201ed7509acSJulian Elischer m_freem(m); 202ed7509acSJulian Elischer return (rt->rt_flags & RTF_BLACKHOLE ? 0 : 203ed7509acSJulian Elischer rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); 204ed7509acSJulian Elischer } 205fe3e8c51SMike Silbersack #ifdef INET6 20682cd038dSYoshinobu Inoue /* 20782cd038dSYoshinobu Inoue * KAME requires that the packet to be contiguous on the 20882cd038dSYoshinobu Inoue * mbuf. We need to make that sure. 20982cd038dSYoshinobu Inoue * this kind of code should be avoided. 21017d65319SMike Silbersack * 21117d65319SMike Silbersack * XXX: KAME may no longer need contiguous packets. Once 21217d65319SMike Silbersack * that has been verified, the following code _should_ be 21317d65319SMike Silbersack * removed. 21482cd038dSYoshinobu Inoue */ 21582cd038dSYoshinobu Inoue 21617d65319SMike Silbersack if (m && m->m_next != NULL) { 2179967cafcSSam Leffler 21817d65319SMike Silbersack n = m_defrag(m, M_DONTWAIT); 21917d65319SMike Silbersack 22017d65319SMike Silbersack if (n == NULL) { 22182cd038dSYoshinobu Inoue m_freem(m); 22217d65319SMike Silbersack return (ENOBUFS); 22317d65319SMike Silbersack } else { 22482cd038dSYoshinobu Inoue m = n; 22582cd038dSYoshinobu Inoue } 22682cd038dSYoshinobu Inoue } 227fe3e8c51SMike Silbersack #endif 22882cd038dSYoshinobu Inoue 229ed7509acSJulian Elischer ifp->if_opackets++; 230ed7509acSJulian Elischer ifp->if_obytes += m->m_pkthdr.len; 231201c2527SJulian Elischer #if 1 /* XXX */ 232201c2527SJulian Elischer switch (dst->sa_family) { 233201c2527SJulian Elischer case AF_INET: 23482cd038dSYoshinobu Inoue case AF_INET6: 235201c2527SJulian Elischer case AF_IPX: 236201c2527SJulian Elischer case AF_APPLETALK: 23705b3ccefSJulian Elischer break; 238201c2527SJulian Elischer default: 23971582bf5SRobert Watson printf("looutput: af=%d unexpected\n", dst->sa_family); 240201c2527SJulian Elischer m_freem(m); 241201c2527SJulian Elischer return (EAFNOSUPPORT); 242201c2527SJulian Elischer } 243201c2527SJulian Elischer #endif 24406a429a3SArchie Cobbs return(if_simloop(ifp, m, dst->sa_family, 0)); 245ed7509acSJulian Elischer } 246ed7509acSJulian Elischer 247ed7509acSJulian Elischer /* 248ed7509acSJulian Elischer * if_simloop() 249ed7509acSJulian Elischer * 250ed7509acSJulian Elischer * This function is to support software emulation of hardware loopback, 251ed7509acSJulian Elischer * i.e., for interfaces with the IFF_SIMPLEX attribute. Since they can't 252ed7509acSJulian Elischer * hear their own broadcasts, we create a copy of the packet that we 253ed7509acSJulian Elischer * would normally receive via a hardware loopback. 254ed7509acSJulian Elischer * 255ed7509acSJulian Elischer * This function expects the packet to include the media header of length hlen. 256ed7509acSJulian Elischer */ 257ed7509acSJulian Elischer 258ed7509acSJulian Elischer int 25906a429a3SArchie Cobbs if_simloop(ifp, m, af, hlen) 260ed7509acSJulian Elischer struct ifnet *ifp; 26133841545SHajimu UMEMOTO struct mbuf *m; 26206a429a3SArchie Cobbs int af; 263ed7509acSJulian Elischer int hlen; 264ed7509acSJulian Elischer { 265df5e1987SJonathan Lemon int isr; 266df8bae1dSRodney W. Grimes 267fe584538SDag-Erling Smørgrav M_ASSERTPKTHDR(m); 2689c855a36SSam Leffler m_tag_delete_nonpersistent(m); 269ed7509acSJulian Elischer m->m_pkthdr.rcvif = ifp; 27006a429a3SArchie Cobbs 271963e4c2aSGarrett Wollman /* BPF write needs to be handled specially */ 27206a429a3SArchie Cobbs if (af == AF_UNSPEC) { 27306a429a3SArchie Cobbs KASSERT(m->m_len >= sizeof(int), ("if_simloop: m_len")); 27406a429a3SArchie Cobbs af = *(mtod(m, int *)); 275963e4c2aSGarrett Wollman m->m_len -= sizeof(int); 276963e4c2aSGarrett Wollman m->m_pkthdr.len -= sizeof(int); 277963e4c2aSGarrett Wollman m->m_data += sizeof(int); 278963e4c2aSGarrett Wollman } 279963e4c2aSGarrett Wollman 28006a429a3SArchie Cobbs /* Let BPF see incoming packet */ 281f5fea3ddSPaul Traina if (ifp->if_bpf) { 282ed7509acSJulian Elischer struct mbuf m0, *n = m; 283ed7509acSJulian Elischer 28433841545SHajimu UMEMOTO if (ifp->if_bpf->bif_dlt == DLT_NULL) { 285df8bae1dSRodney W. Grimes /* 286df8bae1dSRodney W. Grimes * We need to prepend the address family as 287df8bae1dSRodney W. Grimes * a four byte field. Cons up a dummy header 288df8bae1dSRodney W. Grimes * to pacify bpf. This is safe because bpf 289df8bae1dSRodney W. Grimes * will only read from the mbuf (i.e., it won't 290df8bae1dSRodney W. Grimes * try to free it or keep a pointer a to it). 291df8bae1dSRodney W. Grimes */ 292df8bae1dSRodney W. Grimes m0.m_next = m; 293df8bae1dSRodney W. Grimes m0.m_len = 4; 294df8bae1dSRodney W. Grimes m0.m_data = (char *)⁡ 295ed7509acSJulian Elischer n = &m0; 29633841545SHajimu UMEMOTO } 2976fc32a24SSam Leffler BPF_MTAP(ifp, n); 298df8bae1dSRodney W. Grimes } 299df8bae1dSRodney W. Grimes 300ed7509acSJulian Elischer /* Strip away media header */ 3013a43ad8fSDoug Rabson if (hlen > 0) { 302fe81f64fSAndrew Gallatin m_adj(m, hlen); 303ebffbf8cSJake Burkholder #if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) 3043a43ad8fSDoug Rabson /* The alpha doesn't like unaligned data. 3053a43ad8fSDoug Rabson * We move data down in the first mbuf */ 306fe81f64fSAndrew Gallatin if (mtod(m, vm_offset_t) & 3) { 30760ed92ddSMatt Jacob KASSERT(hlen >= 3, ("if_simloop: hlen too small")); 308fe81f64fSAndrew Gallatin bcopy(m->m_data, 309fe81f64fSAndrew Gallatin (char *)(mtod(m, vm_offset_t) 310fe81f64fSAndrew Gallatin - (mtod(m, vm_offset_t) & 3)), 311fe81f64fSAndrew Gallatin m->m_len); 312fe81f64fSAndrew Gallatin mtod(m,vm_offset_t) -= (mtod(m, vm_offset_t) & 3); 313fe81f64fSAndrew Gallatin } 3143a43ad8fSDoug Rabson #endif 3153a43ad8fSDoug Rabson } 316ed7509acSJulian Elischer 31706a429a3SArchie Cobbs /* Deliver to upper layer protocol */ 31806a429a3SArchie Cobbs switch (af) { 319df8bae1dSRodney W. Grimes #ifdef INET 320df8bae1dSRodney W. Grimes case AF_INET: 321df8bae1dSRodney W. Grimes isr = NETISR_IP; 322df8bae1dSRodney W. Grimes break; 323df8bae1dSRodney W. Grimes #endif 32482cd038dSYoshinobu Inoue #ifdef INET6 32582cd038dSYoshinobu Inoue case AF_INET6: 32682cd038dSYoshinobu Inoue m->m_flags |= M_LOOP; 32782cd038dSYoshinobu Inoue isr = NETISR_IPV6; 32882cd038dSYoshinobu Inoue break; 32982cd038dSYoshinobu Inoue #endif 330cc6a66f2SJulian Elischer #ifdef IPX 331cc6a66f2SJulian Elischer case AF_IPX: 332cc6a66f2SJulian Elischer isr = NETISR_IPX; 333cc6a66f2SJulian Elischer break; 334cc6a66f2SJulian Elischer #endif 335655929bfSJulian Elischer #ifdef NETATALK 336655929bfSJulian Elischer case AF_APPLETALK: 3371cafed39SJonathan Lemon isr = NETISR_ATALK2; 338655929bfSJulian Elischer break; 3398cdfefbdSPeter Wemm #endif 340df8bae1dSRodney W. Grimes default: 34106a429a3SArchie Cobbs printf("if_simloop: can't handle af=%d\n", af); 342df8bae1dSRodney W. Grimes m_freem(m); 343df8bae1dSRodney W. Grimes return (EAFNOSUPPORT); 344df8bae1dSRodney W. Grimes } 345df8bae1dSRodney W. Grimes ifp->if_ipackets++; 346df8bae1dSRodney W. Grimes ifp->if_ibytes += m->m_pkthdr.len; 3478dbc9c8bSSam Leffler netisr_queue(isr, m); 348df8bae1dSRodney W. Grimes return (0); 349df8bae1dSRodney W. Grimes } 350df8bae1dSRodney W. Grimes 351df8bae1dSRodney W. Grimes /* ARGSUSED */ 3523bda9f9bSPoul-Henning Kamp static void 3538071913dSRuslan Ermilov lortrequest(cmd, rt, info) 354df8bae1dSRodney W. Grimes int cmd; 355df8bae1dSRodney W. Grimes struct rtentry *rt; 3568071913dSRuslan Ermilov struct rt_addrinfo *info; 357df8bae1dSRodney W. Grimes { 358d1dd20beSSam Leffler RT_LOCK_ASSERT(rt); 359d1dd20beSSam Leffler 3605eb1d25aSGarrett Wollman if (rt) { 3615eb1d25aSGarrett Wollman rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; /* for ISO */ 3625eb1d25aSGarrett Wollman /* 3635eb1d25aSGarrett Wollman * For optimal performance, the send and receive buffers 3645eb1d25aSGarrett Wollman * should be at least twice the MTU plus a little more for 3655eb1d25aSGarrett Wollman * overhead. 3665eb1d25aSGarrett Wollman */ 3675eb1d25aSGarrett Wollman rt->rt_rmx.rmx_recvpipe = 3685eb1d25aSGarrett Wollman rt->rt_rmx.rmx_sendpipe = 3 * LOMTU; 3695eb1d25aSGarrett Wollman } 370df8bae1dSRodney W. Grimes } 371df8bae1dSRodney W. Grimes 372df8bae1dSRodney W. Grimes /* 373df8bae1dSRodney W. Grimes * Process an ioctl request. 374df8bae1dSRodney W. Grimes */ 375df8bae1dSRodney W. Grimes /* ARGSUSED */ 376cfa1ca9dSYoshinobu Inoue int 377df8bae1dSRodney W. Grimes loioctl(ifp, cmd, data) 378df8bae1dSRodney W. Grimes register struct ifnet *ifp; 379ecbb00a2SDoug Rabson u_long cmd; 380df8bae1dSRodney W. Grimes caddr_t data; 381df8bae1dSRodney W. Grimes { 382df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 38390fd8c38SDavid Greenman register struct ifreq *ifr = (struct ifreq *)data; 384df8bae1dSRodney W. Grimes register int error = 0; 385df8bae1dSRodney W. Grimes 386df8bae1dSRodney W. Grimes switch (cmd) { 387df8bae1dSRodney W. Grimes 388df8bae1dSRodney W. Grimes case SIOCSIFADDR: 389b8dc74a3SGarrett Wollman ifp->if_flags |= IFF_UP | IFF_RUNNING; 390df8bae1dSRodney W. Grimes ifa = (struct ifaddr *)data; 391df8bae1dSRodney W. Grimes ifa->ifa_rtrequest = lortrequest; 392df8bae1dSRodney W. Grimes /* 393df8bae1dSRodney W. Grimes * Everything else is done at a higher level. 394df8bae1dSRodney W. Grimes */ 395df8bae1dSRodney W. Grimes break; 396df8bae1dSRodney W. Grimes 397df8bae1dSRodney W. Grimes case SIOCADDMULTI: 398df8bae1dSRodney W. Grimes case SIOCDELMULTI: 399df8bae1dSRodney W. Grimes if (ifr == 0) { 400df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; /* XXX */ 401df8bae1dSRodney W. Grimes break; 402df8bae1dSRodney W. Grimes } 403df8bae1dSRodney W. Grimes switch (ifr->ifr_addr.sa_family) { 404df8bae1dSRodney W. Grimes 405df8bae1dSRodney W. Grimes #ifdef INET 406df8bae1dSRodney W. Grimes case AF_INET: 407df8bae1dSRodney W. Grimes break; 408df8bae1dSRodney W. Grimes #endif 40982cd038dSYoshinobu Inoue #ifdef INET6 41082cd038dSYoshinobu Inoue case AF_INET6: 41182cd038dSYoshinobu Inoue break; 41282cd038dSYoshinobu Inoue #endif 413df8bae1dSRodney W. Grimes 414df8bae1dSRodney W. Grimes default: 415df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; 416df8bae1dSRodney W. Grimes break; 417df8bae1dSRodney W. Grimes } 418df8bae1dSRodney W. Grimes break; 419df8bae1dSRodney W. Grimes 42090fd8c38SDavid Greenman case SIOCSIFMTU: 42190fd8c38SDavid Greenman ifp->if_mtu = ifr->ifr_mtu; 42290fd8c38SDavid Greenman break; 42390fd8c38SDavid Greenman 424ce42f1fbSPoul-Henning Kamp case SIOCSIFFLAGS: 425ce42f1fbSPoul-Henning Kamp break; 426ce42f1fbSPoul-Henning Kamp 427df8bae1dSRodney W. Grimes default: 428df8bae1dSRodney W. Grimes error = EINVAL; 429df8bae1dSRodney W. Grimes } 430df8bae1dSRodney W. Grimes return (error); 431df8bae1dSRodney W. Grimes } 432