1c398230bSWarner Losh /*- 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 * 4. Neither the name of the University nor the names of its contributors 14df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 15df8bae1dSRodney W. Grimes * without specific prior written permission. 16df8bae1dSRodney W. Grimes * 17df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27df8bae1dSRodney W. Grimes * SUCH DAMAGE. 28df8bae1dSRodney W. Grimes * 29fe6db7c7SRuslan Ermilov * @(#)if_loop.c 8.2 (Berkeley) 1/9/95 30c3aac50fSPeter Wemm * $FreeBSD$ 31df8bae1dSRodney W. Grimes */ 32df8bae1dSRodney W. Grimes 33df8bae1dSRodney W. Grimes /* 34df8bae1dSRodney W. Grimes * Loopback interface driver for protocol testing and timing. 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 377262d3e4SEivind Eklund #include "opt_atalk.h" 381d5e9e22SEivind Eklund #include "opt_inet.h" 39cfa1ca9dSYoshinobu Inoue #include "opt_inet6.h" 40430df5f4SEivind Eklund #include "opt_ipx.h" 41430df5f4SEivind Eklund 42df8bae1dSRodney W. Grimes #include <sys/param.h> 43df8bae1dSRodney W. Grimes #include <sys/systm.h> 44df8bae1dSRodney W. Grimes #include <sys/kernel.h> 4590d9802fSPeter Wemm #include <sys/malloc.h> 46df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 472b120974SPeter Wemm #include <sys/module.h> 483d4ce33dSBrooks Davis #include <machine/bus.h> 493d4ce33dSBrooks Davis #include <sys/rman.h> 50df8bae1dSRodney W. Grimes #include <sys/socket.h> 5151a53488SBruce Evans #include <sys/sockio.h> 5290d9802fSPeter Wemm #include <sys/sysctl.h> 53df8bae1dSRodney W. Grimes 54df8bae1dSRodney W. Grimes #include <net/if.h> 55f889d2efSBrooks Davis #include <net/if_clone.h> 56df8bae1dSRodney W. Grimes #include <net/if_types.h> 57df8bae1dSRodney W. Grimes #include <net/netisr.h> 58df8bae1dSRodney W. Grimes #include <net/route.h> 59df8bae1dSRodney W. Grimes #include <net/bpf.h> 6033841545SHajimu UMEMOTO #include <net/bpfdesc.h> 61df8bae1dSRodney W. Grimes 62df8bae1dSRodney W. Grimes #ifdef INET 63df8bae1dSRodney W. Grimes #include <netinet/in.h> 64df8bae1dSRodney W. Grimes #include <netinet/in_var.h> 65df8bae1dSRodney W. Grimes #endif 66df8bae1dSRodney W. Grimes 67cc6a66f2SJulian Elischer #ifdef IPX 68cc6a66f2SJulian Elischer #include <netipx/ipx.h> 69cc6a66f2SJulian Elischer #include <netipx/ipx_if.h> 70cc6a66f2SJulian Elischer #endif 71cc6a66f2SJulian Elischer 7282cd038dSYoshinobu Inoue #ifdef INET6 7382cd038dSYoshinobu Inoue #ifndef INET 7482cd038dSYoshinobu Inoue #include <netinet/in.h> 7582cd038dSYoshinobu Inoue #endif 7682cd038dSYoshinobu Inoue #include <netinet6/in6_var.h> 77686cdd19SJun-ichiro itojun Hagino #include <netinet/ip6.h> 7882cd038dSYoshinobu Inoue #endif 7982cd038dSYoshinobu Inoue 80655929bfSJulian Elischer #ifdef NETATALK 81655929bfSJulian Elischer #include <netatalk/at.h> 82655929bfSJulian Elischer #include <netatalk/at_var.h> 838cdfefbdSPeter Wemm #endif 84655929bfSJulian Elischer 85db8889c6SDavid Greenman #ifdef TINY_LOMTU 86df8bae1dSRodney W. Grimes #define LOMTU (1024+512) 8782cd038dSYoshinobu Inoue #elif defined(LARGE_LOMTU) 8882cd038dSYoshinobu Inoue #define LOMTU 131072 89db8889c6SDavid Greenman #else 90af78195eSDavid Greenman #define LOMTU 16384 91db8889c6SDavid Greenman #endif 92df8bae1dSRodney W. Grimes 933d4ce33dSBrooks Davis #define LONAME "lo" 9490d9802fSPeter Wemm 9590d9802fSPeter Wemm struct lo_softc { 96fc74a9f9SBrooks Davis struct ifnet *sc_ifp; 9790d9802fSPeter Wemm LIST_ENTRY(lo_softc) sc_next; 9890d9802fSPeter Wemm }; 993d4ce33dSBrooks Davis 1003d4ce33dSBrooks Davis int loioctl(struct ifnet *, u_long, caddr_t); 1013d4ce33dSBrooks Davis static void lortrequest(int, struct rtentry *, struct rt_addrinfo *); 1023d4ce33dSBrooks Davis int looutput(struct ifnet *ifp, struct mbuf *m, 1033d4ce33dSBrooks Davis struct sockaddr *dst, struct rtentry *rt); 1046b7330e2SSam Leffler static int lo_clone_create(struct if_clone *, int, caddr_t); 105bb2bfb4fSBrooks Davis static void lo_clone_destroy(struct ifnet *); 1063d4ce33dSBrooks Davis 1073d4ce33dSBrooks Davis struct ifnet *loif = NULL; /* Used externally */ 1083d4ce33dSBrooks Davis 1093d4ce33dSBrooks Davis static MALLOC_DEFINE(M_LO, LONAME, "Loopback Interface"); 1103d4ce33dSBrooks Davis 111f25ee086SRobert Watson static struct mtx lo_mtx; 11290d9802fSPeter Wemm static LIST_HEAD(lo_list, lo_softc) lo_list; 11390d9802fSPeter Wemm 114f889d2efSBrooks Davis IFC_SIMPLE_DECLARE(lo, 1); 1153d4ce33dSBrooks Davis 116bb2bfb4fSBrooks Davis static void 1173d4ce33dSBrooks Davis lo_clone_destroy(ifp) 1183d4ce33dSBrooks Davis struct ifnet *ifp; 1193d4ce33dSBrooks Davis { 1203d4ce33dSBrooks Davis struct lo_softc *sc; 1213d4ce33dSBrooks Davis 1223d4ce33dSBrooks Davis sc = ifp->if_softc; 1233d4ce33dSBrooks Davis 124ae5a19beSBrooks Davis /* XXX: destroying lo0 will lead to panics. */ 125ae5a19beSBrooks Davis KASSERT(loif != ifp, ("%s: destroying lo0", __func__)); 1263d4ce33dSBrooks Davis 127f25ee086SRobert Watson mtx_lock(&lo_mtx); 128f25ee086SRobert Watson LIST_REMOVE(sc, sc_next); 129f25ee086SRobert Watson mtx_unlock(&lo_mtx); 1303d4ce33dSBrooks Davis bpfdetach(ifp); 1313d4ce33dSBrooks Davis if_detach(ifp); 132fc74a9f9SBrooks Davis if_free(ifp); 133d722be54SLuigi Rizzo free(sc, M_LO); 1343d4ce33dSBrooks Davis } 1353d4ce33dSBrooks Davis 136bb2bfb4fSBrooks Davis static int 1376b7330e2SSam Leffler lo_clone_create(ifc, unit, params) 1383b16e7b2SMaxime Henrion struct if_clone *ifc; 1393b16e7b2SMaxime Henrion int unit; 1406b7330e2SSam Leffler caddr_t params; 14190d9802fSPeter Wemm { 142fc74a9f9SBrooks Davis struct ifnet *ifp; 14390d9802fSPeter Wemm struct lo_softc *sc; 14490d9802fSPeter Wemm 145a163d034SWarner Losh MALLOC(sc, struct lo_softc *, sizeof(*sc), M_LO, M_WAITOK | M_ZERO); 146fc74a9f9SBrooks Davis ifp = sc->sc_ifp = if_alloc(IFT_LOOP); 147fc74a9f9SBrooks Davis if (ifp == NULL) { 148fc74a9f9SBrooks Davis free(sc, M_LO); 149fc74a9f9SBrooks Davis return (ENOSPC); 150fc74a9f9SBrooks Davis } 15190d9802fSPeter Wemm 152fc74a9f9SBrooks Davis if_initname(ifp, ifc->ifc_name, unit); 153fc74a9f9SBrooks Davis ifp->if_mtu = LOMTU; 154fc74a9f9SBrooks Davis ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; 155fc74a9f9SBrooks Davis ifp->if_ioctl = loioctl; 156fc74a9f9SBrooks Davis ifp->if_output = looutput; 157fc74a9f9SBrooks Davis ifp->if_snd.ifq_maxlen = ifqmaxlen; 158fc74a9f9SBrooks Davis ifp->if_softc = sc; 159fc74a9f9SBrooks Davis if_attach(ifp); 16001399f34SDavid Malone bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); 161f25ee086SRobert Watson mtx_lock(&lo_mtx); 16290d9802fSPeter Wemm LIST_INSERT_HEAD(&lo_list, sc, sc_next); 163f25ee086SRobert Watson mtx_unlock(&lo_mtx); 16490d9802fSPeter Wemm if (loif == NULL) 165fc74a9f9SBrooks Davis loif = ifp; 1663b16e7b2SMaxime Henrion 1673b16e7b2SMaxime Henrion return (0); 16890d9802fSPeter Wemm } 16990d9802fSPeter Wemm 1702b120974SPeter Wemm static int 1712b120974SPeter Wemm loop_modevent(module_t mod, int type, void *data) 172df8bae1dSRodney W. Grimes { 1732b120974SPeter Wemm switch (type) { 1742b120974SPeter Wemm case MOD_LOAD: 175f25ee086SRobert Watson mtx_init(&lo_mtx, "lo_mtx", NULL, MTX_DEF); 1763d4ce33dSBrooks Davis LIST_INIT(&lo_list); 1773d4ce33dSBrooks Davis if_clone_attach(&lo_cloner); 1782b120974SPeter Wemm break; 1792b120974SPeter Wemm case MOD_UNLOAD: 1802b120974SPeter Wemm printf("loop module unload - not possible for this module type\n"); 1812b120974SPeter Wemm return EINVAL; 1823e019deaSPoul-Henning Kamp default: 1833e019deaSPoul-Henning Kamp return EOPNOTSUPP; 184f5fea3ddSPaul Traina } 1852b120974SPeter Wemm return 0; 1862b120974SPeter Wemm } 1872b120974SPeter Wemm 1882b120974SPeter Wemm static moduledata_t loop_mod = { 1892b120974SPeter Wemm "loop", 1902b120974SPeter Wemm loop_modevent, 1912b120974SPeter Wemm 0 1922b120974SPeter Wemm }; 1932b120974SPeter Wemm 19478ece553SAlexander Kabaev DECLARE_MODULE(loop, loop_mod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY); 195df8bae1dSRodney W. Grimes 196cfa1ca9dSYoshinobu Inoue int 197df8bae1dSRodney W. Grimes looutput(ifp, m, dst, rt) 198df8bae1dSRodney W. Grimes struct ifnet *ifp; 199df8bae1dSRodney W. Grimes register struct mbuf *m; 200df8bae1dSRodney W. Grimes struct sockaddr *dst; 201df8bae1dSRodney W. Grimes register struct rtentry *rt; 202df8bae1dSRodney W. Grimes { 20301399f34SDavid Malone u_int32_t af; 20401399f34SDavid Malone 205fe584538SDag-Erling Smørgrav M_ASSERTPKTHDR(m); /* check if we have the packet header */ 206ed7509acSJulian Elischer 207ed7509acSJulian Elischer if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) { 208ed7509acSJulian Elischer m_freem(m); 209ed7509acSJulian Elischer return (rt->rt_flags & RTF_BLACKHOLE ? 0 : 210ed7509acSJulian Elischer rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); 211ed7509acSJulian Elischer } 21282cd038dSYoshinobu Inoue 213ed7509acSJulian Elischer ifp->if_opackets++; 214ed7509acSJulian Elischer ifp->if_obytes += m->m_pkthdr.len; 21501399f34SDavid Malone 21601399f34SDavid Malone /* BPF writes need to be handled specially. */ 21701399f34SDavid Malone if (dst->sa_family == AF_UNSPEC) { 21801399f34SDavid Malone bcopy(dst->sa_data, &af, sizeof(af)); 21901399f34SDavid Malone dst->sa_family = af; 22001399f34SDavid Malone } 22101399f34SDavid Malone 222201c2527SJulian Elischer #if 1 /* XXX */ 223201c2527SJulian Elischer switch (dst->sa_family) { 224201c2527SJulian Elischer case AF_INET: 22582cd038dSYoshinobu Inoue case AF_INET6: 226201c2527SJulian Elischer case AF_IPX: 227201c2527SJulian Elischer case AF_APPLETALK: 22805b3ccefSJulian Elischer break; 229201c2527SJulian Elischer default: 23071582bf5SRobert Watson printf("looutput: af=%d unexpected\n", dst->sa_family); 231201c2527SJulian Elischer m_freem(m); 232201c2527SJulian Elischer return (EAFNOSUPPORT); 233201c2527SJulian Elischer } 234201c2527SJulian Elischer #endif 23506a429a3SArchie Cobbs return(if_simloop(ifp, m, dst->sa_family, 0)); 236ed7509acSJulian Elischer } 237ed7509acSJulian Elischer 238ed7509acSJulian Elischer /* 239ed7509acSJulian Elischer * if_simloop() 240ed7509acSJulian Elischer * 241ed7509acSJulian Elischer * This function is to support software emulation of hardware loopback, 242ed7509acSJulian Elischer * i.e., for interfaces with the IFF_SIMPLEX attribute. Since they can't 243ed7509acSJulian Elischer * hear their own broadcasts, we create a copy of the packet that we 244ed7509acSJulian Elischer * would normally receive via a hardware loopback. 245ed7509acSJulian Elischer * 246ed7509acSJulian Elischer * This function expects the packet to include the media header of length hlen. 247ed7509acSJulian Elischer */ 248ed7509acSJulian Elischer 249ed7509acSJulian Elischer int 25006a429a3SArchie Cobbs if_simloop(ifp, m, af, hlen) 251ed7509acSJulian Elischer struct ifnet *ifp; 25233841545SHajimu UMEMOTO struct mbuf *m; 25306a429a3SArchie Cobbs int af; 254ed7509acSJulian Elischer int hlen; 255ed7509acSJulian Elischer { 256df5e1987SJonathan Lemon int isr; 257df8bae1dSRodney W. Grimes 258fe584538SDag-Erling Smørgrav M_ASSERTPKTHDR(m); 2599c855a36SSam Leffler m_tag_delete_nonpersistent(m); 260ed7509acSJulian Elischer m->m_pkthdr.rcvif = ifp; 26106a429a3SArchie Cobbs 2628343821bSSUZUKI Shinsuke /* 2638343821bSSUZUKI Shinsuke * Let BPF see incoming packet in the following manner: 2648343821bSSUZUKI Shinsuke * - Emulated packet loopback for a simplex interface 2658343821bSSUZUKI Shinsuke * (net/if_ethersubr.c) 2668343821bSSUZUKI Shinsuke * -> passes it to ifp's BPF 2678343821bSSUZUKI Shinsuke * - IPv4/v6 multicast packet loopback (netinet(6)/ip(6)_output.c) 2688343821bSSUZUKI Shinsuke * -> not passes it to any BPF 2698343821bSSUZUKI Shinsuke * - Normal packet loopback from myself to myself (net/if_loop.c) 2708343821bSSUZUKI Shinsuke * -> passes to lo0's BPF (even in case of IPv6, where ifp!=lo0) 2718343821bSSUZUKI Shinsuke */ 2728343821bSSUZUKI Shinsuke if (hlen > 0) { 27316d878ccSChristian S.J. Peron if (bpf_peers_present(ifp->if_bpf)) { 2748343821bSSUZUKI Shinsuke bpf_mtap(ifp->if_bpf, m); 2758343821bSSUZUKI Shinsuke } 2768343821bSSUZUKI Shinsuke } else { 2778343821bSSUZUKI Shinsuke if (bpf_peers_present(loif->if_bpf)) { 2788343821bSSUZUKI Shinsuke if ((m->m_flags & M_MCAST) == 0 || loif == ifp) { 2798343821bSSUZUKI Shinsuke /* XXX beware sizeof(af) != 4 */ 2808343821bSSUZUKI Shinsuke u_int32_t af1 = af; 2818343821bSSUZUKI Shinsuke 282df8bae1dSRodney W. Grimes /* 283437ffe18SSam Leffler * We need to prepend the address family. 284df8bae1dSRodney W. Grimes */ 2858343821bSSUZUKI Shinsuke bpf_mtap2(loif->if_bpf, &af1, sizeof(af1), m); 2868343821bSSUZUKI Shinsuke } 2878343821bSSUZUKI Shinsuke } 288df8bae1dSRodney W. Grimes } 289df8bae1dSRodney W. Grimes 290ed7509acSJulian Elischer /* Strip away media header */ 2913a43ad8fSDoug Rabson if (hlen > 0) { 292fe81f64fSAndrew Gallatin m_adj(m, hlen); 293f6966ecdSOlivier Houchard #ifndef __NO_STRICT_ALIGNMENT 29473dbd3daSJohn Baldwin /* 29573dbd3daSJohn Baldwin * Some archs do not like unaligned data, so 29673dbd3daSJohn Baldwin * we move data down in the first mbuf. 29773dbd3daSJohn Baldwin */ 298fe81f64fSAndrew Gallatin if (mtod(m, vm_offset_t) & 3) { 29960ed92ddSMatt Jacob KASSERT(hlen >= 3, ("if_simloop: hlen too small")); 300fe81f64fSAndrew Gallatin bcopy(m->m_data, 301fe81f64fSAndrew Gallatin (char *)(mtod(m, vm_offset_t) 302fe81f64fSAndrew Gallatin - (mtod(m, vm_offset_t) & 3)), 303fe81f64fSAndrew Gallatin m->m_len); 304445e045bSAlexander Kabaev m->m_data -= (mtod(m,vm_offset_t) & 3); 305fe81f64fSAndrew Gallatin } 3063a43ad8fSDoug Rabson #endif 3073a43ad8fSDoug Rabson } 308ed7509acSJulian Elischer 30906a429a3SArchie Cobbs /* Deliver to upper layer protocol */ 31006a429a3SArchie Cobbs switch (af) { 311df8bae1dSRodney W. Grimes #ifdef INET 312df8bae1dSRodney W. Grimes case AF_INET: 313df8bae1dSRodney W. Grimes isr = NETISR_IP; 314df8bae1dSRodney W. Grimes break; 315df8bae1dSRodney W. Grimes #endif 31682cd038dSYoshinobu Inoue #ifdef INET6 31782cd038dSYoshinobu Inoue case AF_INET6: 31882cd038dSYoshinobu Inoue m->m_flags |= M_LOOP; 31982cd038dSYoshinobu Inoue isr = NETISR_IPV6; 32082cd038dSYoshinobu Inoue break; 32182cd038dSYoshinobu Inoue #endif 322cc6a66f2SJulian Elischer #ifdef IPX 323cc6a66f2SJulian Elischer case AF_IPX: 324cc6a66f2SJulian Elischer isr = NETISR_IPX; 325cc6a66f2SJulian Elischer break; 326cc6a66f2SJulian Elischer #endif 327655929bfSJulian Elischer #ifdef NETATALK 328655929bfSJulian Elischer case AF_APPLETALK: 3291cafed39SJonathan Lemon isr = NETISR_ATALK2; 330655929bfSJulian Elischer break; 3318cdfefbdSPeter Wemm #endif 332df8bae1dSRodney W. Grimes default: 33306a429a3SArchie Cobbs printf("if_simloop: can't handle af=%d\n", af); 334df8bae1dSRodney W. Grimes m_freem(m); 335df8bae1dSRodney W. Grimes return (EAFNOSUPPORT); 336df8bae1dSRodney W. Grimes } 337df8bae1dSRodney W. Grimes ifp->if_ipackets++; 338df8bae1dSRodney W. Grimes ifp->if_ibytes += m->m_pkthdr.len; 3393161f583SAndre Oppermann netisr_queue(isr, m); /* mbuf is free'd on failure. */ 340df8bae1dSRodney W. Grimes return (0); 341df8bae1dSRodney W. Grimes } 342df8bae1dSRodney W. Grimes 343df8bae1dSRodney W. Grimes /* ARGSUSED */ 3443bda9f9bSPoul-Henning Kamp static void 3458071913dSRuslan Ermilov lortrequest(cmd, rt, info) 346df8bae1dSRodney W. Grimes int cmd; 347df8bae1dSRodney W. Grimes struct rtentry *rt; 3488071913dSRuslan Ermilov struct rt_addrinfo *info; 349df8bae1dSRodney W. Grimes { 350d1dd20beSSam Leffler RT_LOCK_ASSERT(rt); 35197d8d152SAndre Oppermann rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; 352df8bae1dSRodney W. Grimes } 353df8bae1dSRodney W. Grimes 354df8bae1dSRodney W. Grimes /* 355df8bae1dSRodney W. Grimes * Process an ioctl request. 356df8bae1dSRodney W. Grimes */ 357df8bae1dSRodney W. Grimes /* ARGSUSED */ 358cfa1ca9dSYoshinobu Inoue int 359df8bae1dSRodney W. Grimes loioctl(ifp, cmd, data) 360df8bae1dSRodney W. Grimes register struct ifnet *ifp; 361ecbb00a2SDoug Rabson u_long cmd; 362df8bae1dSRodney W. Grimes caddr_t data; 363df8bae1dSRodney W. Grimes { 364df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 36590fd8c38SDavid Greenman register struct ifreq *ifr = (struct ifreq *)data; 366df8bae1dSRodney W. Grimes register int error = 0; 367df8bae1dSRodney W. Grimes 368df8bae1dSRodney W. Grimes switch (cmd) { 369df8bae1dSRodney W. Grimes 370df8bae1dSRodney W. Grimes case SIOCSIFADDR: 37113f4c340SRobert Watson ifp->if_flags |= IFF_UP; 37213f4c340SRobert Watson ifp->if_drv_flags |= IFF_DRV_RUNNING; 373df8bae1dSRodney W. Grimes ifa = (struct ifaddr *)data; 374df8bae1dSRodney W. Grimes ifa->ifa_rtrequest = lortrequest; 375df8bae1dSRodney W. Grimes /* 376df8bae1dSRodney W. Grimes * Everything else is done at a higher level. 377df8bae1dSRodney W. Grimes */ 378df8bae1dSRodney W. Grimes break; 379df8bae1dSRodney W. Grimes 380df8bae1dSRodney W. Grimes case SIOCADDMULTI: 381df8bae1dSRodney W. Grimes case SIOCDELMULTI: 382df8bae1dSRodney W. Grimes if (ifr == 0) { 383df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; /* XXX */ 384df8bae1dSRodney W. Grimes break; 385df8bae1dSRodney W. Grimes } 386df8bae1dSRodney W. Grimes switch (ifr->ifr_addr.sa_family) { 387df8bae1dSRodney W. Grimes 388df8bae1dSRodney W. Grimes #ifdef INET 389df8bae1dSRodney W. Grimes case AF_INET: 390df8bae1dSRodney W. Grimes break; 391df8bae1dSRodney W. Grimes #endif 39282cd038dSYoshinobu Inoue #ifdef INET6 39382cd038dSYoshinobu Inoue case AF_INET6: 39482cd038dSYoshinobu Inoue break; 39582cd038dSYoshinobu Inoue #endif 396df8bae1dSRodney W. Grimes 397df8bae1dSRodney W. Grimes default: 398df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; 399df8bae1dSRodney W. Grimes break; 400df8bae1dSRodney W. Grimes } 401df8bae1dSRodney W. Grimes break; 402df8bae1dSRodney W. Grimes 40390fd8c38SDavid Greenman case SIOCSIFMTU: 40490fd8c38SDavid Greenman ifp->if_mtu = ifr->ifr_mtu; 40590fd8c38SDavid Greenman break; 40690fd8c38SDavid Greenman 407ce42f1fbSPoul-Henning Kamp case SIOCSIFFLAGS: 408ce42f1fbSPoul-Henning Kamp break; 409ce42f1fbSPoul-Henning Kamp 410df8bae1dSRodney W. Grimes default: 411df8bae1dSRodney W. Grimes error = EINVAL; 412df8bae1dSRodney W. Grimes } 413df8bae1dSRodney W. Grimes return (error); 414df8bae1dSRodney W. Grimes } 415