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 26206a429a3SArchie Cobbs /* Let BPF see incoming packet */ 26316d878ccSChristian S.J. Peron if (bpf_peers_present(ifp->if_bpf)) { 26433841545SHajimu UMEMOTO if (ifp->if_bpf->bif_dlt == DLT_NULL) { 265437ffe18SSam Leffler u_int32_t af1 = af; /* XXX beware sizeof(af) != 4 */ 266df8bae1dSRodney W. Grimes /* 267437ffe18SSam Leffler * We need to prepend the address family. 268df8bae1dSRodney W. Grimes */ 269437ffe18SSam Leffler bpf_mtap2(ifp->if_bpf, &af1, sizeof(af1), m); 270437ffe18SSam Leffler } else 271437ffe18SSam Leffler bpf_mtap(ifp->if_bpf, m); 272df8bae1dSRodney W. Grimes } 273df8bae1dSRodney W. Grimes 274ed7509acSJulian Elischer /* Strip away media header */ 2753a43ad8fSDoug Rabson if (hlen > 0) { 276fe81f64fSAndrew Gallatin m_adj(m, hlen); 27773dbd3daSJohn Baldwin #if defined(__ia64__) || defined(__sparc64__) 27873dbd3daSJohn Baldwin /* 27973dbd3daSJohn Baldwin * Some archs do not like unaligned data, so 28073dbd3daSJohn Baldwin * we move data down in the first mbuf. 28173dbd3daSJohn Baldwin */ 282fe81f64fSAndrew Gallatin if (mtod(m, vm_offset_t) & 3) { 28360ed92ddSMatt Jacob KASSERT(hlen >= 3, ("if_simloop: hlen too small")); 284fe81f64fSAndrew Gallatin bcopy(m->m_data, 285fe81f64fSAndrew Gallatin (char *)(mtod(m, vm_offset_t) 286fe81f64fSAndrew Gallatin - (mtod(m, vm_offset_t) & 3)), 287fe81f64fSAndrew Gallatin m->m_len); 288445e045bSAlexander Kabaev m->m_data -= (mtod(m,vm_offset_t) & 3); 289fe81f64fSAndrew Gallatin } 2903a43ad8fSDoug Rabson #endif 2913a43ad8fSDoug Rabson } 292ed7509acSJulian Elischer 29306a429a3SArchie Cobbs /* Deliver to upper layer protocol */ 29406a429a3SArchie Cobbs switch (af) { 295df8bae1dSRodney W. Grimes #ifdef INET 296df8bae1dSRodney W. Grimes case AF_INET: 297df8bae1dSRodney W. Grimes isr = NETISR_IP; 298df8bae1dSRodney W. Grimes break; 299df8bae1dSRodney W. Grimes #endif 30082cd038dSYoshinobu Inoue #ifdef INET6 30182cd038dSYoshinobu Inoue case AF_INET6: 30282cd038dSYoshinobu Inoue m->m_flags |= M_LOOP; 30382cd038dSYoshinobu Inoue isr = NETISR_IPV6; 30482cd038dSYoshinobu Inoue break; 30582cd038dSYoshinobu Inoue #endif 306cc6a66f2SJulian Elischer #ifdef IPX 307cc6a66f2SJulian Elischer case AF_IPX: 308cc6a66f2SJulian Elischer isr = NETISR_IPX; 309cc6a66f2SJulian Elischer break; 310cc6a66f2SJulian Elischer #endif 311655929bfSJulian Elischer #ifdef NETATALK 312655929bfSJulian Elischer case AF_APPLETALK: 3131cafed39SJonathan Lemon isr = NETISR_ATALK2; 314655929bfSJulian Elischer break; 3158cdfefbdSPeter Wemm #endif 316df8bae1dSRodney W. Grimes default: 31706a429a3SArchie Cobbs printf("if_simloop: can't handle af=%d\n", af); 318df8bae1dSRodney W. Grimes m_freem(m); 319df8bae1dSRodney W. Grimes return (EAFNOSUPPORT); 320df8bae1dSRodney W. Grimes } 321df8bae1dSRodney W. Grimes ifp->if_ipackets++; 322df8bae1dSRodney W. Grimes ifp->if_ibytes += m->m_pkthdr.len; 3233161f583SAndre Oppermann netisr_queue(isr, m); /* mbuf is free'd on failure. */ 324df8bae1dSRodney W. Grimes return (0); 325df8bae1dSRodney W. Grimes } 326df8bae1dSRodney W. Grimes 327df8bae1dSRodney W. Grimes /* ARGSUSED */ 3283bda9f9bSPoul-Henning Kamp static void 3298071913dSRuslan Ermilov lortrequest(cmd, rt, info) 330df8bae1dSRodney W. Grimes int cmd; 331df8bae1dSRodney W. Grimes struct rtentry *rt; 3328071913dSRuslan Ermilov struct rt_addrinfo *info; 333df8bae1dSRodney W. Grimes { 334d1dd20beSSam Leffler RT_LOCK_ASSERT(rt); 33597d8d152SAndre Oppermann rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; 336df8bae1dSRodney W. Grimes } 337df8bae1dSRodney W. Grimes 338df8bae1dSRodney W. Grimes /* 339df8bae1dSRodney W. Grimes * Process an ioctl request. 340df8bae1dSRodney W. Grimes */ 341df8bae1dSRodney W. Grimes /* ARGSUSED */ 342cfa1ca9dSYoshinobu Inoue int 343df8bae1dSRodney W. Grimes loioctl(ifp, cmd, data) 344df8bae1dSRodney W. Grimes register struct ifnet *ifp; 345ecbb00a2SDoug Rabson u_long cmd; 346df8bae1dSRodney W. Grimes caddr_t data; 347df8bae1dSRodney W. Grimes { 348df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 34990fd8c38SDavid Greenman register struct ifreq *ifr = (struct ifreq *)data; 350df8bae1dSRodney W. Grimes register int error = 0; 351df8bae1dSRodney W. Grimes 352df8bae1dSRodney W. Grimes switch (cmd) { 353df8bae1dSRodney W. Grimes 354df8bae1dSRodney W. Grimes case SIOCSIFADDR: 35513f4c340SRobert Watson ifp->if_flags |= IFF_UP; 35613f4c340SRobert Watson ifp->if_drv_flags |= IFF_DRV_RUNNING; 357df8bae1dSRodney W. Grimes ifa = (struct ifaddr *)data; 358df8bae1dSRodney W. Grimes ifa->ifa_rtrequest = lortrequest; 359df8bae1dSRodney W. Grimes /* 360df8bae1dSRodney W. Grimes * Everything else is done at a higher level. 361df8bae1dSRodney W. Grimes */ 362df8bae1dSRodney W. Grimes break; 363df8bae1dSRodney W. Grimes 364df8bae1dSRodney W. Grimes case SIOCADDMULTI: 365df8bae1dSRodney W. Grimes case SIOCDELMULTI: 366df8bae1dSRodney W. Grimes if (ifr == 0) { 367df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; /* XXX */ 368df8bae1dSRodney W. Grimes break; 369df8bae1dSRodney W. Grimes } 370df8bae1dSRodney W. Grimes switch (ifr->ifr_addr.sa_family) { 371df8bae1dSRodney W. Grimes 372df8bae1dSRodney W. Grimes #ifdef INET 373df8bae1dSRodney W. Grimes case AF_INET: 374df8bae1dSRodney W. Grimes break; 375df8bae1dSRodney W. Grimes #endif 37682cd038dSYoshinobu Inoue #ifdef INET6 37782cd038dSYoshinobu Inoue case AF_INET6: 37882cd038dSYoshinobu Inoue break; 37982cd038dSYoshinobu Inoue #endif 380df8bae1dSRodney W. Grimes 381df8bae1dSRodney W. Grimes default: 382df8bae1dSRodney W. Grimes error = EAFNOSUPPORT; 383df8bae1dSRodney W. Grimes break; 384df8bae1dSRodney W. Grimes } 385df8bae1dSRodney W. Grimes break; 386df8bae1dSRodney W. Grimes 38790fd8c38SDavid Greenman case SIOCSIFMTU: 38890fd8c38SDavid Greenman ifp->if_mtu = ifr->ifr_mtu; 38990fd8c38SDavid Greenman break; 39090fd8c38SDavid Greenman 391ce42f1fbSPoul-Henning Kamp case SIOCSIFFLAGS: 392ce42f1fbSPoul-Henning Kamp break; 393ce42f1fbSPoul-Henning Kamp 394df8bae1dSRodney W. Grimes default: 395df8bae1dSRodney W. Grimes error = EINVAL; 396df8bae1dSRodney W. Grimes } 397df8bae1dSRodney W. Grimes return (error); 398df8bae1dSRodney W. Grimes } 399