Home | History | Annotate | Line # | Download | only in net
if_ieee1394subr.c revision 1.33
      1  1.33    dyoung /*	$NetBSD: if_ieee1394subr.c,v 1.33 2007/02/17 22:34:08 dyoung Exp $	*/
      2   1.1      onoe 
      3   1.1      onoe /*
      4   1.1      onoe  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5   1.1      onoe  * All rights reserved.
      6   1.1      onoe  *
      7   1.1      onoe  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      onoe  * by Atsushi Onoe.
      9   1.1      onoe  *
     10   1.1      onoe  * Redistribution and use in source and binary forms, with or without
     11   1.1      onoe  * modification, are permitted provided that the following conditions
     12   1.1      onoe  * are met:
     13   1.1      onoe  * 1. Redistributions of source code must retain the above copyright
     14   1.1      onoe  *    notice, this list of conditions and the following disclaimer.
     15   1.1      onoe  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      onoe  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      onoe  *    documentation and/or other materials provided with the distribution.
     18   1.1      onoe  * 3. All advertising materials mentioning features or use of this software
     19   1.1      onoe  *    must display the following acknowledgement:
     20   1.1      onoe  *	This product includes software developed by the NetBSD
     21   1.1      onoe  *	Foundation, Inc. and its contributors.
     22   1.1      onoe  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1      onoe  *    contributors may be used to endorse or promote products derived
     24   1.1      onoe  *    from this software without specific prior written permission.
     25   1.1      onoe  *
     26   1.1      onoe  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1      onoe  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1      onoe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1      onoe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1      onoe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1      onoe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1      onoe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1      onoe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1      onoe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1      onoe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1      onoe  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1      onoe  */
     38  1.12     lukem 
     39  1.12     lukem #include <sys/cdefs.h>
     40  1.33    dyoung __KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.33 2007/02/17 22:34:08 dyoung Exp $");
     41   1.1      onoe 
     42   1.1      onoe #include "opt_inet.h"
     43   1.1      onoe #include "bpfilter.h"
     44   1.1      onoe 
     45   1.1      onoe #include <sys/param.h>
     46   1.1      onoe #include <sys/systm.h>
     47   1.1      onoe #include <sys/socket.h>
     48   1.1      onoe #include <sys/sockio.h>
     49   1.1      onoe #include <sys/kernel.h>
     50   1.1      onoe #include <sys/mbuf.h>
     51   1.1      onoe #include <sys/device.h>
     52   1.1      onoe 
     53   1.1      onoe #include <net/if.h>
     54   1.1      onoe #include <net/if_dl.h>
     55   1.1      onoe #include <net/if_ieee1394.h>
     56   1.1      onoe #include <net/if_types.h>
     57   1.1      onoe #include <net/if_media.h>
     58   1.1      onoe #include <net/ethertypes.h>
     59   1.1      onoe #include <net/netisr.h>
     60   1.1      onoe #include <net/route.h>
     61   1.1      onoe 
     62   1.1      onoe #if NBPFILTER > 0
     63   1.1      onoe #include <net/bpf.h>
     64   1.1      onoe #endif
     65   1.1      onoe 
     66   1.1      onoe #ifdef INET
     67   1.1      onoe #include <netinet/in.h>
     68   1.1      onoe #include <netinet/in_var.h>
     69  1.16    itojun #include <netinet/if_inarp.h>
     70   1.1      onoe #endif /* INET */
     71   1.1      onoe #ifdef INET6
     72   1.1      onoe #include <netinet/in.h>
     73   1.1      onoe #include <netinet6/in6_var.h>
     74   1.1      onoe #include <netinet6/nd6.h>
     75   1.1      onoe #endif /* INET6 */
     76   1.1      onoe 
     77  1.29  kiyohara #include <dev/ieee1394/fw_port.h>
     78  1.29  kiyohara #include <dev/ieee1394/firewire.h>
     79  1.29  kiyohara 
     80  1.29  kiyohara #include <dev/ieee1394/firewirereg.h>
     81  1.29  kiyohara #include <dev/ieee1394/iec13213.h>
     82  1.29  kiyohara #include <dev/ieee1394/if_fwipvar.h>
     83  1.29  kiyohara 
     84   1.3      onoe #define	IEEE1394_REASS_TIMEOUT	3	/* 3 sec */
     85   1.3      onoe 
     86   1.1      onoe #define	senderr(e)	do { error = (e); goto bad; } while(0/*CONSTCOND*/)
     87   1.1      onoe 
     88  1.33    dyoung static int  ieee1394_output(struct ifnet *, struct mbuf *,
     89  1.33    dyoung 		const struct sockaddr *, struct rtentry *);
     90  1.29  kiyohara static struct mbuf *ieee1394_reass(struct ifnet *, struct mbuf *, u_int16_t);
     91   1.1      onoe 
     92   1.1      onoe static int
     93  1.33    dyoung ieee1394_output(struct ifnet *ifp, struct mbuf *m0, const struct sockaddr *dst,
     94   1.1      onoe     struct rtentry *rt0)
     95   1.1      onoe {
     96   1.1      onoe 	u_int16_t etype = 0;
     97   1.2      onoe 	struct mbuf *m;
     98   1.2      onoe 	int s, hdrlen, error = 0;
     99   1.1      onoe 	struct rtentry *rt;
    100   1.1      onoe 	struct mbuf *mcopy = NULL;
    101  1.29  kiyohara 	struct ieee1394_hwaddr *hwdst, *myaddr, baddr;
    102  1.14    itojun 	ALTQ_DECL(struct altq_pktattr pktattr;)
    103  1.18      onoe #ifdef INET
    104  1.18      onoe 	struct arphdr *ah;
    105  1.18      onoe #endif /* INET */
    106  1.29  kiyohara 	struct m_tag *mtag;
    107  1.29  kiyohara 	int unicast;
    108   1.1      onoe 
    109   1.1      onoe 	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
    110   1.1      onoe 		senderr(ENETDOWN);
    111   1.1      onoe 	if ((rt = rt0) != NULL) {
    112   1.1      onoe 		if ((rt->rt_flags & RTF_UP) == 0) {
    113   1.1      onoe 			if ((rt0 = rt = rtalloc1(dst, 1)) != NULL) {
    114   1.1      onoe 				rt->rt_refcnt--;
    115   1.1      onoe 				if (rt->rt_ifp != ifp)
    116   1.1      onoe 					return (*rt->rt_ifp->if_output)
    117   1.1      onoe 							(ifp, m0, dst, rt);
    118   1.1      onoe 			} else
    119   1.1      onoe 				senderr(EHOSTUNREACH);
    120   1.1      onoe 		}
    121   1.1      onoe 		if (rt->rt_flags & RTF_GATEWAY) {
    122   1.3      onoe 			if (rt->rt_gwroute == NULL)
    123   1.1      onoe 				goto lookup;
    124   1.1      onoe 			if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
    125   1.1      onoe 				rtfree(rt);
    126   1.1      onoe 				rt = rt0;
    127   1.1      onoe   lookup:
    128   1.1      onoe 				rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1);
    129   1.3      onoe 				if ((rt = rt->rt_gwroute) == NULL)
    130   1.1      onoe 					senderr(EHOSTUNREACH);
    131   1.1      onoe 				/* the "G" test below also prevents rt == rt0 */
    132   1.1      onoe 				if ((rt->rt_flags & RTF_GATEWAY) ||
    133   1.1      onoe 				    (rt->rt_ifp != ifp)) {
    134   1.1      onoe 					rt->rt_refcnt--;
    135   1.3      onoe 					rt0->rt_gwroute = NULL;
    136   1.1      onoe 					senderr(EHOSTUNREACH);
    137   1.1      onoe 				}
    138   1.1      onoe 			}
    139   1.1      onoe 		}
    140   1.1      onoe 		if (rt->rt_flags & RTF_REJECT)
    141   1.1      onoe 			if (rt->rt_rmx.rmx_expire == 0 ||
    142  1.32    kardel 			    time_second < rt->rt_rmx.rmx_expire)
    143   1.1      onoe 				senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
    144   1.1      onoe 	}
    145  1.14    itojun 
    146  1.14    itojun 	/*
    147  1.14    itojun 	 * If the queueing discipline needs packet classification,
    148  1.14    itojun 	 * do it before prepending link headers.
    149  1.14    itojun 	 */
    150  1.18      onoe 	IFQ_CLASSIFY(&ifp->if_snd, m0, dst->sa_family, &pktattr);
    151  1.14    itojun 
    152  1.29  kiyohara 	/*
    153  1.29  kiyohara 	 * For unicast, we make a tag to store the lladdr of the
    154  1.29  kiyohara 	 * destination. This might not be the first time we have seen
    155  1.29  kiyohara 	 * the packet (for instance, the arp code might be trying to
    156  1.29  kiyohara 	 * re-send it after receiving an arp reply) so we only
    157  1.29  kiyohara 	 * allocate a tag if there isn't one there already. For
    158  1.29  kiyohara 	 * multicast, we will eventually use a different tag to store
    159  1.29  kiyohara 	 * the channel number.
    160  1.29  kiyohara 	 */
    161  1.29  kiyohara 	unicast = !(m0->m_flags & (M_BCAST | M_MCAST));
    162  1.29  kiyohara 	if (unicast) {
    163  1.29  kiyohara 		mtag =
    164  1.29  kiyohara 		    m_tag_locate(m0, MTAG_FIREWIRE, MTAG_FIREWIRE_HWADDR, NULL);
    165  1.29  kiyohara 		if (!mtag) {
    166  1.29  kiyohara 			mtag = m_tag_alloc(MTAG_FIREWIRE, MTAG_FIREWIRE_HWADDR,
    167  1.29  kiyohara 			    sizeof (struct ieee1394_hwaddr), M_NOWAIT);
    168  1.29  kiyohara 			if (!mtag) {
    169  1.29  kiyohara 				error = ENOMEM;
    170  1.29  kiyohara 				goto bad;
    171  1.29  kiyohara 			}
    172  1.29  kiyohara 			m_tag_prepend(m0, mtag);
    173  1.29  kiyohara 		}
    174  1.29  kiyohara 		hwdst = (struct ieee1394_hwaddr *)(mtag + 1);
    175  1.29  kiyohara 	} else {
    176  1.29  kiyohara 		hwdst = &baddr;
    177  1.29  kiyohara 	}
    178  1.29  kiyohara 
    179   1.1      onoe 	switch (dst->sa_family) {
    180   1.1      onoe #ifdef INET
    181   1.1      onoe 	case AF_INET:
    182  1.29  kiyohara 		if (unicast && (!arpresolve(ifp, rt, m0, dst, (u_char *)hwdst)))
    183   1.1      onoe 			return 0;	/* if not yet resolved */
    184   1.1      onoe 		/* if broadcasting on a simplex interface, loopback a copy */
    185   1.2      onoe 		if ((m0->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
    186   1.2      onoe 			mcopy = m_copy(m0, 0, M_COPYALL);
    187   1.1      onoe 		etype = htons(ETHERTYPE_IP);
    188   1.1      onoe 		break;
    189   1.1      onoe 	case AF_ARP:
    190  1.18      onoe 		ah = mtod(m0, struct arphdr *);
    191  1.18      onoe 		ah->ar_hrd = htons(ARPHRD_IEEE1394);
    192   1.1      onoe 		etype = htons(ETHERTYPE_ARP);
    193   1.1      onoe 		break;
    194   1.1      onoe #endif /* INET */
    195   1.1      onoe #ifdef INET6
    196   1.1      onoe 	case AF_INET6:
    197  1.33    dyoung 		if (unicast && (!nd6_storelladdr(ifp, rt, m0, dst,
    198  1.33    dyoung 		    hwdst->iha_uid, IEEE1394_ADDR_LEN))) {
    199  1.20    itojun 			/* something bad happened */
    200   1.1      onoe 			return 0;
    201   1.1      onoe 		}
    202   1.1      onoe 		etype = htons(ETHERTYPE_IPV6);
    203   1.1      onoe 		break;
    204   1.1      onoe #endif /* INET6 */
    205   1.1      onoe 
    206   1.1      onoe 	case pseudo_AF_HDRCMPLT:
    207   1.1      onoe 	case AF_UNSPEC:
    208   1.1      onoe 		/* TODO? */
    209   1.1      onoe 	default:
    210   1.1      onoe 		printf("%s: can't handle af%d\n", ifp->if_xname,
    211   1.1      onoe 		    dst->sa_family);
    212   1.1      onoe 		senderr(EAFNOSUPPORT);
    213   1.1      onoe 		break;
    214   1.1      onoe 	}
    215   1.1      onoe 
    216   1.1      onoe 	if (mcopy)
    217   1.1      onoe 		looutput(ifp, mcopy, dst, rt);
    218  1.30  kiyohara 	myaddr = (struct ieee1394_hwaddr *)LLADDR(ifp->if_sadl);
    219   1.1      onoe #if NBPFILTER > 0
    220  1.30  kiyohara 	if (ifp->if_bpf) {
    221  1.30  kiyohara 		struct ieee1394_bpfhdr h;
    222  1.30  kiyohara 		if (unicast)
    223  1.30  kiyohara 			memcpy(h.ibh_dhost, hwdst->iha_uid, 8);
    224  1.30  kiyohara 		else
    225  1.30  kiyohara 			memcpy(h.ibh_dhost,
    226  1.30  kiyohara 			    ((const struct ieee1394_hwaddr *)
    227  1.30  kiyohara 			    ifp->if_broadcastaddr)->iha_uid, 8);
    228  1.30  kiyohara 		memcpy(h.ibh_shost, myaddr->iha_uid, 8);
    229  1.30  kiyohara 		h.ibh_type = etype;
    230  1.30  kiyohara 		bpf_mtap2(ifp->if_bpf, &h, sizeof(h), m0);
    231  1.30  kiyohara 	}
    232   1.1      onoe #endif
    233   1.2      onoe 	if ((ifp->if_flags & IFF_SIMPLEX) &&
    234  1.29  kiyohara 	    unicast &&
    235  1.29  kiyohara 	    memcmp(hwdst, myaddr, IEEE1394_ADDR_LEN) == 0)
    236   1.2      onoe 		return looutput(ifp, m0, dst, rt);
    237   1.2      onoe 
    238   1.3      onoe 	/*
    239   1.3      onoe 	 * XXX:
    240   1.3      onoe 	 * The maximum possible rate depends on the topology.
    241   1.3      onoe 	 * So the determination of maxrec and fragmentation should be
    242   1.3      onoe 	 * called from the driver after probing the topology map.
    243   1.3      onoe 	 */
    244  1.29  kiyohara 	if (unicast) {
    245   1.2      onoe 		hdrlen = IEEE1394_GASP_LEN;
    246  1.29  kiyohara 		hwdst->iha_speed = 0;	/* XXX */
    247   1.2      onoe 	} else
    248   1.2      onoe 		hdrlen = 0;
    249   1.1      onoe 
    250  1.29  kiyohara 	if (hwdst->iha_speed > myaddr->iha_speed)
    251  1.29  kiyohara 		hwdst->iha_speed = myaddr->iha_speed;
    252  1.29  kiyohara 	if (hwdst->iha_maxrec > myaddr->iha_maxrec)
    253  1.29  kiyohara 		hwdst->iha_maxrec = myaddr->iha_maxrec;
    254  1.29  kiyohara 	if (hwdst->iha_maxrec > (8 + hwdst->iha_speed))
    255  1.29  kiyohara 		hwdst->iha_maxrec = 8 + hwdst->iha_speed;
    256  1.29  kiyohara 	if (hwdst->iha_maxrec < 8)
    257  1.29  kiyohara 			hwdst->iha_maxrec = 8;
    258  1.29  kiyohara 
    259  1.29  kiyohara 	m0 = ieee1394_fragment(ifp, m0, (2<<hwdst->iha_maxrec) - hdrlen, etype);
    260   1.2      onoe 	if (m0 == NULL)
    261   1.2      onoe 		senderr(ENOBUFS);
    262   1.3      onoe 
    263  1.10   thorpej 	s = splnet();
    264   1.2      onoe 	ifp->if_obytes += m0->m_pkthdr.len;
    265   1.1      onoe 	if (m0->m_flags & M_MCAST)
    266   1.1      onoe 		ifp->if_omcasts++;
    267   1.2      onoe 	while ((m = m0) != NULL) {
    268   1.2      onoe 		m0 = m->m_nextpkt;
    269   1.2      onoe 		if (m == NULL) {
    270   1.2      onoe 			splx(s);
    271   1.2      onoe 			senderr(ENOBUFS);
    272   1.2      onoe 		}
    273  1.14    itojun 		IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
    274  1.14    itojun 		if (error) {
    275  1.14    itojun 			/* mbuf is already freed */
    276  1.14    itojun 			splx(s);
    277  1.14    itojun 			goto bad;
    278  1.14    itojun 		}
    279   1.2      onoe 	}
    280   1.1      onoe 	if ((ifp->if_flags & IFF_OACTIVE) == 0)
    281   1.1      onoe 		(*ifp->if_start)(ifp);
    282   1.1      onoe 	splx(s);
    283   1.2      onoe 	return 0;
    284   1.1      onoe 
    285   1.1      onoe   bad:
    286   1.1      onoe 	while (m0 != NULL) {
    287   1.1      onoe 		m = m0->m_nextpkt;
    288   1.1      onoe 		m_freem(m0);
    289   1.1      onoe 		m0 = m;
    290   1.1      onoe 	}
    291   1.1      onoe 
    292   1.1      onoe 	return error;
    293   1.1      onoe }
    294   1.1      onoe 
    295   1.2      onoe struct mbuf *
    296   1.2      onoe ieee1394_fragment(struct ifnet *ifp, struct mbuf *m0, int maxsize,
    297   1.2      onoe     u_int16_t etype)
    298   1.2      onoe {
    299   1.2      onoe 	struct ieee1394com *ic = (struct ieee1394com *)ifp;
    300   1.2      onoe 	int totlen, fraglen, off;
    301   1.2      onoe 	struct mbuf *m, **mp;
    302   1.2      onoe 	struct ieee1394_fraghdr *ifh;
    303   1.2      onoe 	struct ieee1394_unfraghdr *iuh;
    304   1.2      onoe 
    305   1.2      onoe 	totlen = m0->m_pkthdr.len;
    306   1.2      onoe 	if (totlen + sizeof(struct ieee1394_unfraghdr) <= maxsize) {
    307   1.2      onoe 		M_PREPEND(m0, sizeof(struct ieee1394_unfraghdr), M_DONTWAIT);
    308   1.2      onoe 		if (m0 == NULL)
    309   1.2      onoe 			goto bad;
    310   1.2      onoe 		iuh = mtod(m0, struct ieee1394_unfraghdr *);
    311   1.2      onoe 		iuh->iuh_ft = 0;
    312   1.2      onoe 		iuh->iuh_etype = etype;
    313   1.2      onoe 		return m0;
    314   1.2      onoe 	}
    315   1.2      onoe 
    316   1.2      onoe 	fraglen = maxsize - sizeof(struct ieee1394_fraghdr);
    317   1.2      onoe 
    318   1.2      onoe 	M_PREPEND(m0, sizeof(struct ieee1394_fraghdr), M_DONTWAIT);
    319   1.2      onoe 	if (m0 == NULL)
    320   1.2      onoe 		goto bad;
    321   1.2      onoe 	ifh = mtod(m0, struct ieee1394_fraghdr *);
    322   1.2      onoe 	ifh->ifh_ft_size = htons(IEEE1394_FT_MORE | (totlen - 1));
    323   1.2      onoe 	ifh->ifh_etype_off = etype;
    324   1.2      onoe 	ifh->ifh_dgl = htons(ic->ic_dgl);
    325   1.2      onoe 	ifh->ifh_reserved = 0;
    326   1.2      onoe 	off = fraglen;
    327   1.2      onoe 	mp = &m0->m_nextpkt;
    328   1.2      onoe 	while (off < totlen) {
    329   1.2      onoe 		if (off + fraglen > totlen)
    330   1.2      onoe 			fraglen = totlen - off;
    331   1.2      onoe 		MGETHDR(m, M_DONTWAIT, MT_HEADER);
    332   1.2      onoe 		if (m == NULL)
    333   1.2      onoe 			goto bad;
    334   1.2      onoe 		m->m_flags |= m0->m_flags & (M_BCAST|M_MCAST);	/* copy bcast */
    335   1.2      onoe 		MH_ALIGN(m, sizeof(struct ieee1394_fraghdr));
    336   1.2      onoe 		m->m_len = sizeof(struct ieee1394_fraghdr);
    337   1.2      onoe 		ifh = mtod(m, struct ieee1394_fraghdr *);
    338   1.2      onoe 		ifh->ifh_ft_size =
    339   1.2      onoe 		    htons(IEEE1394_FT_SUBSEQ | IEEE1394_FT_MORE | (totlen - 1));
    340   1.2      onoe 		ifh->ifh_etype_off = htons(off);
    341   1.2      onoe 		ifh->ifh_dgl = htons(ic->ic_dgl);
    342   1.2      onoe 		ifh->ifh_reserved = 0;
    343   1.3      onoe 		m->m_next = m_copy(m0, sizeof(*ifh) + off, fraglen);
    344   1.2      onoe 		if (m->m_next == NULL)
    345   1.2      onoe 			goto bad;
    346   1.3      onoe 		m->m_pkthdr.len = sizeof(*ifh) + fraglen;
    347   1.2      onoe 		off += fraglen;
    348   1.2      onoe 		*mp = m;
    349   1.2      onoe 		mp = &m->m_nextpkt;
    350   1.2      onoe 	}
    351   1.2      onoe 	ifh->ifh_ft_size &= ~htons(IEEE1394_FT_MORE);	/* last fragment */
    352   1.2      onoe 	m_adj(m0, -(m0->m_pkthdr.len - maxsize));
    353   1.2      onoe 
    354   1.2      onoe 	ic->ic_dgl++;
    355   1.2      onoe 	return m0;
    356   1.2      onoe 
    357   1.2      onoe   bad:
    358   1.2      onoe 	while ((m = m0) != NULL) {
    359   1.2      onoe 		m0 = m->m_nextpkt;
    360   1.2      onoe 		m->m_nextpkt = NULL;
    361   1.2      onoe 		m_freem(m);
    362   1.2      onoe 	}
    363   1.2      onoe 	return NULL;
    364   1.2      onoe }
    365   1.2      onoe 
    366  1.29  kiyohara void
    367  1.29  kiyohara ieee1394_input(struct ifnet *ifp, struct mbuf *m, u_int16_t src)
    368   1.1      onoe {
    369   1.1      onoe 	struct ifqueue *inq;
    370   1.1      onoe 	u_int16_t etype;
    371   1.1      onoe 	int s;
    372   1.1      onoe 	struct ieee1394_unfraghdr *iuh;
    373   1.1      onoe 
    374   1.1      onoe 	if ((ifp->if_flags & IFF_UP) == 0) {
    375   1.1      onoe 		m_freem(m);
    376   1.1      onoe 		return;
    377   1.1      onoe 	}
    378  1.29  kiyohara 	if (m->m_len < sizeof(*iuh)) {
    379  1.29  kiyohara 		if ((m = m_pullup(m, sizeof(*iuh))) == NULL)
    380   1.2      onoe 			return;
    381   1.2      onoe 	}
    382   1.1      onoe 
    383  1.29  kiyohara 	iuh = mtod(m, struct ieee1394_unfraghdr *);
    384   1.2      onoe 
    385   1.2      onoe 	if (ntohs(iuh->iuh_ft) & (IEEE1394_FT_SUBSEQ | IEEE1394_FT_MORE)) {
    386  1.29  kiyohara 		if ((m = ieee1394_reass(ifp, m, src)) == NULL)
    387   1.2      onoe 			return;
    388  1.29  kiyohara 		iuh = mtod(m, struct ieee1394_unfraghdr *);
    389   1.1      onoe 	}
    390   1.1      onoe 	etype = ntohs(iuh->iuh_etype);
    391   1.1      onoe 
    392   1.1      onoe 	/* strip off the ieee1394 header */
    393  1.29  kiyohara 	m_adj(m, sizeof(*iuh));
    394   1.1      onoe #if NBPFILTER > 0
    395  1.30  kiyohara 	if (ifp->if_bpf) {
    396  1.30  kiyohara 		struct ieee1394_bpfhdr h;
    397  1.30  kiyohara 		struct m_tag *mtag;
    398  1.30  kiyohara 		struct ieee1394_hwaddr *myaddr;
    399  1.30  kiyohara 
    400  1.30  kiyohara 		mtag = m_tag_locate(m,
    401  1.30  kiyohara 		    MTAG_FIREWIRE, MTAG_FIREWIRE_SENDER_EUID, 0);
    402  1.30  kiyohara 		if (mtag)
    403  1.30  kiyohara 			memcpy(h.ibh_shost, mtag + 1, 8);
    404  1.30  kiyohara 		else
    405  1.30  kiyohara 			memset(h.ibh_shost, 0, 8);
    406  1.30  kiyohara 		if (m->m_flags & M_BCAST)
    407  1.30  kiyohara 			memcpy(h.ibh_dhost,
    408  1.30  kiyohara 			    ((const struct ieee1394_hwaddr *)
    409  1.30  kiyohara 			    ifp->if_broadcastaddr)->iha_uid, 8);
    410  1.30  kiyohara 		else {
    411  1.30  kiyohara 			myaddr = (struct ieee1394_hwaddr *)LLADDR(ifp->if_sadl);
    412  1.30  kiyohara 			memcpy(h.ibh_dhost, myaddr->iha_uid, 8);
    413  1.30  kiyohara 		}
    414  1.30  kiyohara 		h.ibh_type = htons(etype);
    415  1.30  kiyohara 		bpf_mtap2(ifp->if_bpf, &h, sizeof(h), m);
    416  1.30  kiyohara 	}
    417   1.1      onoe #endif
    418   1.1      onoe 
    419   1.1      onoe 	switch (etype) {
    420   1.1      onoe #ifdef INET
    421   1.1      onoe 	case ETHERTYPE_IP:
    422   1.1      onoe 		schednetisr(NETISR_IP);
    423   1.1      onoe 		inq = &ipintrq;
    424   1.1      onoe 		break;
    425   1.1      onoe 
    426   1.1      onoe 	case ETHERTYPE_ARP:
    427  1.16    itojun 		schednetisr(NETISR_ARP);
    428  1.16    itojun 		inq = &arpintrq;
    429  1.17     enami 		break;
    430   1.1      onoe #endif /* INET */
    431   1.1      onoe 
    432   1.1      onoe #ifdef INET6
    433   1.1      onoe 	case ETHERTYPE_IPV6:
    434   1.1      onoe 		schednetisr(NETISR_IPV6);
    435   1.1      onoe 		inq = &ip6intrq;
    436   1.1      onoe 		break;
    437   1.1      onoe #endif /* INET6 */
    438   1.1      onoe 
    439   1.1      onoe 	default:
    440   1.1      onoe 		m_freem(m);
    441   1.1      onoe 		return;
    442   1.1      onoe 	}
    443   1.1      onoe 
    444  1.10   thorpej 	s = splnet();
    445   1.1      onoe 	if (IF_QFULL(inq)) {
    446   1.1      onoe 		IF_DROP(inq);
    447   1.1      onoe 		m_freem(m);
    448   1.1      onoe 	} else
    449   1.1      onoe 		IF_ENQUEUE(inq, m);
    450   1.1      onoe 	splx(s);
    451   1.1      onoe }
    452   1.1      onoe 
    453   1.2      onoe static struct mbuf *
    454  1.29  kiyohara ieee1394_reass(struct ifnet *ifp, struct mbuf *m0, u_int16_t src)
    455   1.2      onoe {
    456   1.2      onoe 	struct ieee1394com *ic = (struct ieee1394com *)ifp;
    457   1.2      onoe 	struct ieee1394_fraghdr *ifh;
    458   1.2      onoe 	struct ieee1394_unfraghdr *iuh;
    459   1.2      onoe 	struct ieee1394_reassq *rq;
    460  1.25  christos 	struct ieee1394_reass_pkt *rp, *trp, *nrp = NULL;
    461   1.2      onoe 	int len;
    462  1.29  kiyohara 	u_int16_t etype, off, ftype, size, dgl;
    463  1.29  kiyohara 	u_int32_t id;
    464   1.2      onoe 
    465  1.29  kiyohara 	if (m0->m_len < sizeof(*ifh)) {
    466  1.29  kiyohara 		if ((m0 = m_pullup(m0, sizeof(*ifh))) == NULL)
    467   1.2      onoe 			return NULL;
    468   1.2      onoe 	}
    469  1.29  kiyohara 	ifh = mtod(m0, struct ieee1394_fraghdr *);
    470  1.29  kiyohara 	m_adj(m0, sizeof(*ifh));
    471   1.2      onoe 	size = ntohs(ifh->ifh_ft_size);
    472   1.2      onoe 	ftype = size & (IEEE1394_FT_SUBSEQ | IEEE1394_FT_MORE);
    473   1.2      onoe 	size = (size & ~ftype) + 1;
    474  1.29  kiyohara 	dgl = ntohs(ifh->ifh_dgl);
    475   1.2      onoe 	len = m0->m_pkthdr.len;
    476  1.29  kiyohara 	id = dgl | (src << 16);
    477   1.2      onoe 	if (ftype & IEEE1394_FT_SUBSEQ) {
    478  1.24    itojun 		m_tag_delete_chain(m0, NULL);
    479   1.2      onoe 		m0->m_flags &= ~M_PKTHDR;
    480  1.29  kiyohara 		etype = 0;
    481   1.2      onoe 		off = ntohs(ifh->ifh_etype_off);
    482  1.29  kiyohara 	} else {
    483  1.29  kiyohara 		etype = ifh->ifh_etype_off;
    484   1.2      onoe 		off = 0;
    485  1.29  kiyohara 	}
    486   1.2      onoe 
    487   1.2      onoe 	for (rq = LIST_FIRST(&ic->ic_reassq); ; rq = LIST_NEXT(rq, rq_node)) {
    488   1.2      onoe 		if (rq == NULL) {
    489   1.2      onoe 			/*
    490   1.2      onoe 			 * Create a new reassemble queue head for the node.
    491   1.2      onoe 			 */
    492   1.2      onoe 			rq = malloc(sizeof(*rq), M_FTABLE, M_NOWAIT);
    493   1.2      onoe 			if (rq == NULL) {
    494   1.2      onoe 				m_freem(m0);
    495   1.2      onoe 				return NULL;
    496   1.2      onoe 			}
    497  1.29  kiyohara 			rq->fr_id = id;
    498   1.2      onoe 			LIST_INIT(&rq->rq_pkt);
    499   1.2      onoe 			LIST_INSERT_HEAD(&ic->ic_reassq, rq, rq_node);
    500   1.2      onoe 			break;
    501   1.2      onoe 		}
    502  1.29  kiyohara 		if (rq->fr_id == id)
    503   1.2      onoe 			break;
    504   1.2      onoe 	}
    505   1.2      onoe 	for (rp = LIST_FIRST(&rq->rq_pkt); rp != NULL; rp = nrp) {
    506   1.2      onoe 		nrp = LIST_NEXT(rp, rp_next);
    507   1.2      onoe 		if (rp->rp_dgl != dgl)
    508   1.2      onoe 			continue;
    509   1.3      onoe 		/*
    510   1.3      onoe 		 * sanity check:
    511   1.3      onoe 		 * datagram size must be same for all fragments, and
    512   1.3      onoe 		 * no overlap is allowed.
    513   1.3      onoe 		 */
    514   1.3      onoe 		if (rp->rp_size != size ||
    515   1.3      onoe 		    (off < rp->rp_off + rp->rp_len && off + len > rp->rp_off)) {
    516   1.2      onoe 			/*
    517   1.3      onoe 			 * This happens probably due to wrapping dgl value.
    518   1.3      onoe 			 * Destroy all previously received fragment and
    519   1.3      onoe 			 * enqueue current fragment.
    520   1.2      onoe 			 */
    521   1.3      onoe 			for (rp = LIST_FIRST(&rq->rq_pkt); rp != NULL;
    522   1.3      onoe 			    rp = nrp) {
    523   1.3      onoe 				nrp = LIST_NEXT(rp, rp_next);
    524   1.3      onoe 				if (rp->rp_dgl == dgl) {
    525   1.3      onoe 					LIST_REMOVE(rp, rp_next);
    526   1.3      onoe 					m_freem(rp->rp_m);
    527   1.3      onoe 					free(rp, M_FTABLE);
    528   1.3      onoe 				}
    529   1.3      onoe 			}
    530   1.3      onoe 			break;
    531   1.2      onoe 		}
    532   1.2      onoe 		if (rp->rp_off + rp->rp_len == off) {
    533   1.2      onoe 			/*
    534   1.2      onoe 			 * All the subsequent fragments received in sequence
    535   1.2      onoe 			 * come here.
    536   1.2      onoe 			 * Concatinate mbuf to previous one instead of
    537   1.2      onoe 			 * allocating new reassemble queue structure,
    538   1.2      onoe 			 * and try to merge more with the subsequent fragment
    539   1.2      onoe 			 * in the queue.
    540   1.2      onoe 			 */
    541   1.2      onoe 			m_cat(rp->rp_m, m0);
    542   1.2      onoe 			rp->rp_len += len;
    543   1.2      onoe 			while (rp->rp_off + rp->rp_len < size &&
    544   1.2      onoe 			    nrp != NULL && nrp->rp_dgl == dgl &&
    545   1.2      onoe 			    nrp->rp_off == rp->rp_off + rp->rp_len) {
    546   1.2      onoe 				LIST_REMOVE(nrp, rp_next);
    547   1.2      onoe 				m_cat(rp->rp_m, nrp->rp_m);
    548   1.2      onoe 				rp->rp_len += nrp->rp_len;
    549   1.3      onoe 				free(nrp, M_FTABLE);
    550   1.2      onoe 				nrp = LIST_NEXT(rp, rp_next);
    551   1.2      onoe 			}
    552   1.2      onoe 			m0 = NULL;	/* mark merged */
    553   1.2      onoe 			break;
    554   1.2      onoe 		}
    555   1.2      onoe 		if (off + m0->m_pkthdr.len == rp->rp_off) {
    556   1.2      onoe 			m_cat(m0, rp->rp_m);
    557   1.2      onoe 			rp->rp_m = m0;
    558   1.2      onoe 			rp->rp_off = off;
    559  1.29  kiyohara 			rp->rp_etype = etype;	 /* over writing trust etype */
    560   1.2      onoe 			rp->rp_len += len;
    561   1.2      onoe 			m0 = NULL;	/* mark merged */
    562   1.2      onoe 			break;
    563   1.2      onoe 		}
    564   1.2      onoe 		if (rp->rp_off > off) {
    565   1.2      onoe 			/* insert before rp */
    566   1.2      onoe 			nrp = rp;
    567   1.2      onoe 			break;
    568   1.2      onoe 		}
    569   1.2      onoe 		if (nrp == NULL || nrp->rp_dgl != dgl) {
    570   1.2      onoe 			/* insert after rp */
    571   1.2      onoe 			nrp = NULL;
    572   1.2      onoe 			break;
    573   1.2      onoe 		}
    574   1.2      onoe 	}
    575   1.2      onoe 	if (m0 == NULL) {
    576   1.2      onoe 		if (rp->rp_off != 0 || rp->rp_len != size)
    577   1.2      onoe 			return NULL;
    578   1.2      onoe 		/* fragment done */
    579   1.2      onoe 		LIST_REMOVE(rp, rp_next);
    580   1.2      onoe 		m0 = rp->rp_m;
    581   1.2      onoe 		m0->m_pkthdr.len = rp->rp_len;
    582  1.29  kiyohara 		M_PREPEND(m0, sizeof(*iuh), M_DONTWAIT);
    583   1.2      onoe 		if (m0 != NULL) {
    584  1.29  kiyohara 			iuh = mtod(m0, struct ieee1394_unfraghdr *);
    585   1.2      onoe 			iuh->iuh_ft = 0;
    586   1.2      onoe 			iuh->iuh_etype = rp->rp_etype;
    587   1.2      onoe 		}
    588   1.2      onoe 		free(rp, M_FTABLE);
    589   1.2      onoe 		return m0;
    590   1.2      onoe 	}
    591   1.2      onoe 
    592   1.2      onoe 	/*
    593   1.2      onoe 	 * New fragment received.  Allocate reassemble queue structure.
    594   1.2      onoe 	 */
    595   1.2      onoe 	trp = malloc(sizeof(*trp), M_FTABLE, M_NOWAIT);
    596   1.2      onoe 	if (trp == NULL) {
    597   1.2      onoe 		m_freem(m0);
    598   1.2      onoe 		return NULL;
    599   1.2      onoe 	}
    600   1.2      onoe 	trp->rp_m = m0;
    601   1.2      onoe 	trp->rp_size = size;
    602  1.29  kiyohara 	trp->rp_etype = etype;		 /* valid only if off==0 */
    603   1.2      onoe 	trp->rp_off = off;
    604   1.2      onoe 	trp->rp_dgl = dgl;
    605   1.2      onoe 	trp->rp_len = len;
    606   1.3      onoe 	trp->rp_ttl = IEEE1394_REASS_TIMEOUT;
    607   1.3      onoe 	if (trp->rp_ttl <= ifp->if_timer)
    608   1.3      onoe 		trp->rp_ttl = ifp->if_timer + 1;
    609   1.2      onoe 
    610   1.2      onoe 	if (rp == NULL) {
    611   1.2      onoe 		/* first fragment for the dgl */
    612   1.2      onoe 		LIST_INSERT_HEAD(&rq->rq_pkt, trp, rp_next);
    613   1.2      onoe 	} else if (nrp == NULL) {
    614   1.2      onoe 		/* no next fragment for the dgl */
    615   1.2      onoe 		LIST_INSERT_AFTER(rp, trp, rp_next);
    616   1.2      onoe 	} else {
    617   1.2      onoe 		/* there is a hole */
    618   1.2      onoe 		LIST_INSERT_BEFORE(nrp, trp, rp_next);
    619   1.2      onoe 	}
    620   1.2      onoe 	return NULL;
    621   1.2      onoe }
    622   1.2      onoe 
    623   1.3      onoe void
    624   1.3      onoe ieee1394_drain(struct ifnet *ifp)
    625   1.3      onoe {
    626   1.3      onoe 	struct ieee1394com *ic = (struct ieee1394com *)ifp;
    627   1.3      onoe 	struct ieee1394_reassq *rq;
    628   1.3      onoe 	struct ieee1394_reass_pkt *rp;
    629   1.3      onoe 
    630   1.3      onoe 	while ((rq = LIST_FIRST(&ic->ic_reassq)) != NULL) {
    631   1.3      onoe 		LIST_REMOVE(rq, rq_node);
    632   1.3      onoe 		while ((rp = LIST_FIRST(&rq->rq_pkt)) != NULL) {
    633   1.3      onoe 			LIST_REMOVE(rp, rp_next);
    634   1.3      onoe 			m_freem(rp->rp_m);
    635   1.3      onoe 			free(rp, M_FTABLE);
    636   1.3      onoe 		}
    637   1.3      onoe 		free(rq, M_FTABLE);
    638   1.3      onoe 	}
    639   1.3      onoe }
    640   1.3      onoe 
    641   1.3      onoe void
    642   1.3      onoe ieee1394_watchdog(struct ifnet *ifp)
    643   1.3      onoe {
    644   1.3      onoe 	struct ieee1394com *ic = (struct ieee1394com *)ifp;
    645   1.3      onoe 	struct ieee1394_reassq *rq;
    646   1.3      onoe 	struct ieee1394_reass_pkt *rp, *nrp;
    647   1.3      onoe 	int dec;
    648   1.3      onoe 
    649   1.3      onoe 	dec = (ifp->if_timer > 0) ? ifp->if_timer : 1;
    650   1.3      onoe 	for (rq = LIST_FIRST(&ic->ic_reassq); rq != NULL;
    651   1.3      onoe 	    rq = LIST_NEXT(rq, rq_node)) {
    652   1.3      onoe 		for (rp = LIST_FIRST(&rq->rq_pkt); rp != NULL; rp = nrp) {
    653   1.3      onoe 			nrp = LIST_NEXT(rp, rp_next);
    654   1.3      onoe 			if (rp->rp_ttl >= dec)
    655   1.3      onoe 				rp->rp_ttl -= dec;
    656   1.3      onoe 			else {
    657   1.3      onoe 				LIST_REMOVE(rp, rp_next);
    658   1.3      onoe 				m_freem(rp->rp_m);
    659   1.3      onoe 				free(rp, M_FTABLE);
    660   1.3      onoe 			}
    661   1.3      onoe 		}
    662   1.3      onoe 	}
    663   1.3      onoe }
    664   1.3      onoe 
    665   1.1      onoe const char *
    666   1.1      onoe ieee1394_sprintf(const u_int8_t *laddr)
    667   1.1      onoe {
    668   1.1      onoe 	static char buf[3*8];
    669   1.1      onoe 
    670   1.1      onoe 	snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
    671   1.1      onoe 	    laddr[0], laddr[1], laddr[2], laddr[3],
    672   1.1      onoe 	    laddr[4], laddr[5], laddr[6], laddr[7]);
    673   1.1      onoe 	return buf;
    674   1.1      onoe }
    675   1.1      onoe 
    676   1.1      onoe void
    677   1.1      onoe ieee1394_ifattach(struct ifnet *ifp, const struct ieee1394_hwaddr *hwaddr)
    678   1.1      onoe {
    679   1.2      onoe 	struct ieee1394_hwaddr *baddr;
    680   1.2      onoe 	struct ieee1394com *ic = (struct ieee1394com *)ifp;
    681   1.1      onoe 
    682   1.1      onoe 	ifp->if_type = IFT_IEEE1394;
    683   1.1      onoe 	ifp->if_addrlen = sizeof(struct ieee1394_hwaddr);
    684   1.1      onoe 	ifp->if_hdrlen = sizeof(struct ieee1394_header);
    685   1.6   thorpej 	ifp->if_dlt = DLT_EN10MB;	/* XXX */
    686   1.1      onoe 	ifp->if_mtu = IEEE1394MTU;
    687   1.1      onoe 	ifp->if_output = ieee1394_output;
    688   1.3      onoe 	ifp->if_drain = ieee1394_drain;
    689   1.3      onoe 	ifp->if_watchdog = ieee1394_watchdog;
    690   1.3      onoe 	ifp->if_timer = 1;
    691   1.1      onoe 	if (ifp->if_baudrate == 0)
    692   1.1      onoe 		ifp->if_baudrate = IF_Mbps(100);
    693   1.7   thorpej 
    694   1.7   thorpej 	if_alloc_sadl(ifp);
    695   1.9   thorpej 	memcpy(LLADDR(ifp->if_sadl), hwaddr, ifp->if_addrlen);
    696   1.7   thorpej 
    697  1.28      yamt 	baddr = malloc(ifp->if_addrlen, M_DEVBUF, M_WAITOK);
    698   1.2      onoe 	memset(baddr->iha_uid, 0xff, IEEE1394_ADDR_LEN);
    699   1.3      onoe 	baddr->iha_speed = 0;	/*XXX: how to determine the speed for bcast? */
    700   1.2      onoe 	baddr->iha_maxrec = 512 << baddr->iha_speed;
    701   1.2      onoe 	memset(baddr->iha_offset, 0, sizeof(baddr->iha_offset));
    702  1.28      yamt 	ifp->if_broadcastaddr = (uint8_t *)baddr;
    703   1.2      onoe 	LIST_INIT(&ic->ic_reassq);
    704   1.4   thorpej #if NBPFILTER > 0
    705  1.30  kiyohara 	bpfattach(ifp,
    706  1.30  kiyohara 	    DLT_APPLE_IP_OVER_IEEE1394, sizeof(struct ieee1394_hwaddr));
    707   1.4   thorpej #endif
    708   1.1      onoe }
    709   1.1      onoe 
    710   1.1      onoe void
    711   1.1      onoe ieee1394_ifdetach(struct ifnet *ifp)
    712   1.1      onoe {
    713   1.3      onoe 	ieee1394_drain(ifp);
    714   1.4   thorpej #if NBPFILTER > 0
    715   1.4   thorpej 	bpfdetach(ifp);
    716   1.4   thorpej #endif
    717  1.28      yamt 	free(__UNCONST(ifp->if_broadcastaddr), M_DEVBUF);
    718   1.7   thorpej 	ifp->if_broadcastaddr = NULL;
    719  1.23    itojun #if 0	/* done in if_detach() */
    720   1.7   thorpej 	if_free_sadl(ifp);
    721  1.23    itojun #endif
    722   1.1      onoe }
    723   1.1      onoe 
    724   1.1      onoe int
    725   1.1      onoe ieee1394_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
    726   1.1      onoe {
    727   1.1      onoe 	struct ifreq *ifr = (struct ifreq *)data;
    728   1.1      onoe 	struct ifaddr *ifa = (struct ifaddr *)data;
    729   1.1      onoe 	int error = 0;
    730  1.15      haya #if __NetBSD_Version__ < 105080000
    731   1.1      onoe 	int fw_init(struct ifnet *);
    732   1.1      onoe 	void fw_stop(struct ifnet *, int);
    733   1.1      onoe #endif
    734   1.1      onoe 
    735   1.1      onoe 	switch (cmd) {
    736   1.1      onoe 	case SIOCSIFADDR:
    737   1.1      onoe 		ifp->if_flags |= IFF_UP;
    738   1.1      onoe 		switch (ifa->ifa_addr->sa_family) {
    739   1.1      onoe #ifdef INET
    740   1.1      onoe 		case AF_INET:
    741  1.15      haya #if __NetBSD_Version__ >= 105080000
    742   1.1      onoe 			if ((error = (*ifp->if_init)(ifp)) != 0)
    743   1.1      onoe #else
    744   1.1      onoe 			if ((error = fw_init(ifp)) != 0)
    745   1.1      onoe #endif
    746   1.1      onoe 				break;
    747  1.16    itojun 			arp_ifinit(ifp, ifa);
    748   1.1      onoe 			break;
    749   1.1      onoe #endif /* INET */
    750   1.1      onoe 		default:
    751  1.15      haya #if __NetBSD_Version__ >= 105080000
    752   1.1      onoe 			error = (*ifp->if_init)(ifp);
    753   1.1      onoe #else
    754   1.1      onoe 			error = fw_init(ifp);
    755   1.1      onoe #endif
    756   1.1      onoe 			break;
    757   1.1      onoe 		}
    758   1.1      onoe 		break;
    759   1.1      onoe 
    760   1.1      onoe 	case SIOCGIFADDR:
    761   1.1      onoe 		memcpy(((struct sockaddr *)&ifr->ifr_data)->sa_data,
    762   1.1      onoe 		    LLADDR(ifp->if_sadl), IEEE1394_ADDR_LEN);
    763   1.1      onoe 		    break;
    764   1.1      onoe 
    765   1.1      onoe 	case SIOCSIFMTU:
    766   1.1      onoe 		if (ifr->ifr_mtu > IEEE1394MTU)
    767   1.1      onoe 			error = EINVAL;
    768   1.1      onoe 		else
    769   1.1      onoe 			ifp->if_mtu = ifr->ifr_mtu;
    770   1.1      onoe 		break;
    771   1.1      onoe 
    772   1.1      onoe 	default:
    773   1.1      onoe 		error = ENOTTY;
    774   1.1      onoe 		break;
    775   1.1      onoe 	}
    776   1.1      onoe 
    777   1.1      onoe 	return error;
    778   1.1      onoe }
    779