2018-12-22 17:28:56 +03:00
|
|
|
/* $NetBSD: if_ieee1394subr.c,v 1.65 2018/12/22 14:28:56 maxv Exp $ */
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Atsushi Onoe.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 02:49:33 +03:00
|
|
|
#include <sys/cdefs.h>
|
2018-12-22 17:28:56 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.65 2018/12/22 14:28:56 maxv Exp $");
|
2001-11-13 02:49:33 +03:00
|
|
|
|
2015-08-25 01:21:26 +03:00
|
|
|
#ifdef _KERNEL_OPT
|
2000-11-05 20:17:12 +03:00
|
|
|
#include "opt_inet.h"
|
2015-08-25 01:21:26 +03:00
|
|
|
#endif
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2010-03-29 07:05:27 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/device.h>
|
2000-11-05 20:17:12 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
2010-03-29 07:05:27 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
2010-03-31 16:17:01 +04:00
|
|
|
#include <sys/select.h>
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ieee1394.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/ethertypes.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
2002-06-24 12:06:20 +04:00
|
|
|
#include <netinet/if_inarp.h>
|
2000-11-05 20:17:12 +03:00
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet6/in6_var.h>
|
|
|
|
#include <netinet6/nd6.h>
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
2005-07-11 19:29:05 +04:00
|
|
|
#include <dev/ieee1394/firewire.h>
|
|
|
|
|
|
|
|
#include <dev/ieee1394/firewirereg.h>
|
|
|
|
#include <dev/ieee1394/iec13213.h>
|
|
|
|
#include <dev/ieee1394/if_fwipvar.h>
|
|
|
|
|
2000-11-20 15:12:18 +03:00
|
|
|
#define IEEE1394_REASS_TIMEOUT 3 /* 3 sec */
|
|
|
|
|
2000-11-05 20:17:12 +03:00
|
|
|
#define senderr(e) do { error = (e); goto bad; } while(0/*CONSTCOND*/)
|
|
|
|
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
static int ieee1394_output(struct ifnet *, struct mbuf *,
|
2016-04-28 03:16:56 +03:00
|
|
|
const struct sockaddr *, const struct rtentry *);
|
2008-02-20 20:05:52 +03:00
|
|
|
static struct mbuf *ieee1394_reass(struct ifnet *, struct mbuf *, uint16_t);
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
static int
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
ieee1394_output(struct ifnet *ifp, struct mbuf *m0, const struct sockaddr *dst,
|
2016-04-28 03:16:56 +03:00
|
|
|
const struct rtentry *rt)
|
2000-11-05 20:17:12 +03:00
|
|
|
{
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t etype = 0;
|
2000-11-14 14:14:55 +03:00
|
|
|
struct mbuf *m;
|
2016-04-28 04:37:17 +03:00
|
|
|
int hdrlen, error = 0;
|
2000-11-05 20:17:12 +03:00
|
|
|
struct mbuf *mcopy = NULL;
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
struct ieee1394_hwaddr *hwdst, baddr;
|
|
|
|
const struct ieee1394_hwaddr *myaddr;
|
2002-06-25 07:42:28 +04:00
|
|
|
#ifdef INET
|
|
|
|
struct arphdr *ah;
|
|
|
|
#endif /* INET */
|
2005-07-11 19:29:05 +04:00
|
|
|
struct m_tag *mtag;
|
|
|
|
int unicast;
|
2000-12-14 01:07:50 +03:00
|
|
|
|
2000-11-05 20:17:12 +03:00
|
|
|
if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
|
|
|
|
senderr(ENETDOWN);
|
2002-03-05 07:12:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the queueing discipline needs packet classification,
|
|
|
|
* do it before prepending link headers.
|
|
|
|
*/
|
2016-04-20 12:01:03 +03:00
|
|
|
IFQ_CLASSIFY(&ifp->if_snd, m0, dst->sa_family);
|
2002-03-05 07:12:57 +03:00
|
|
|
|
2005-07-11 19:29:05 +04:00
|
|
|
/*
|
|
|
|
* For unicast, we make a tag to store the lladdr of the
|
|
|
|
* destination. This might not be the first time we have seen
|
|
|
|
* the packet (for instance, the arp code might be trying to
|
|
|
|
* re-send it after receiving an arp reply) so we only
|
|
|
|
* allocate a tag if there isn't one there already. For
|
|
|
|
* multicast, we will eventually use a different tag to store
|
|
|
|
* the channel number.
|
|
|
|
*/
|
|
|
|
unicast = !(m0->m_flags & (M_BCAST | M_MCAST));
|
|
|
|
if (unicast) {
|
2018-11-15 13:23:55 +03:00
|
|
|
mtag = m_tag_find(m0, MTAG_FIREWIRE_HWADDR);
|
2005-07-11 19:29:05 +04:00
|
|
|
if (!mtag) {
|
2010-03-29 07:05:27 +04:00
|
|
|
mtag = m_tag_get(MTAG_FIREWIRE_HWADDR,
|
2005-07-11 19:29:05 +04:00
|
|
|
sizeof (struct ieee1394_hwaddr), M_NOWAIT);
|
|
|
|
if (!mtag) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
m_tag_prepend(m0, mtag);
|
|
|
|
}
|
|
|
|
hwdst = (struct ieee1394_hwaddr *)(mtag + 1);
|
|
|
|
} else {
|
|
|
|
hwdst = &baddr;
|
|
|
|
}
|
|
|
|
|
2000-11-05 20:17:12 +03:00
|
|
|
switch (dst->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2015-10-13 15:33:07 +03:00
|
|
|
if (unicast &&
|
2016-04-07 06:22:15 +03:00
|
|
|
(error = arpresolve(ifp, rt, m0, dst, hwdst,
|
|
|
|
sizeof(*hwdst))) != 0)
|
2015-10-13 15:33:07 +03:00
|
|
|
return error == EWOULDBLOCK ? 0 : error;
|
2000-11-05 20:17:12 +03:00
|
|
|
/* if broadcasting on a simplex interface, loopback a copy */
|
2000-11-14 14:14:55 +03:00
|
|
|
if ((m0->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
|
2018-05-09 09:35:10 +03:00
|
|
|
mcopy = m_copypacket(m0, M_DONTWAIT);
|
2000-11-05 20:17:12 +03:00
|
|
|
etype = htons(ETHERTYPE_IP);
|
|
|
|
break;
|
|
|
|
case AF_ARP:
|
2002-06-25 07:42:28 +04:00
|
|
|
ah = mtod(m0, struct arphdr *);
|
|
|
|
ah->ar_hrd = htons(ARPHRD_IEEE1394);
|
2000-11-05 20:17:12 +03:00
|
|
|
etype = htons(ETHERTYPE_ARP);
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2017-02-14 06:05:06 +03:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* XXX This code was in nd6_storelladdr, which was replaced with
|
|
|
|
* nd6_resolve, but it never be used because nd6_storelladdr was
|
|
|
|
* called only if unicast. Should it be enabled?
|
|
|
|
*/
|
|
|
|
if (m0->m_flags & M_BCAST)
|
|
|
|
memcpy(hwdst->iha_uid, ifp->if_broadcastaddr,
|
|
|
|
MIN(IEEE1394_ADDR_LEN, ifp->if_addrlen));
|
|
|
|
#endif
|
|
|
|
if (unicast) {
|
|
|
|
error = nd6_resolve(ifp, rt, m0, dst, hwdst->iha_uid,
|
|
|
|
IEEE1394_ADDR_LEN);
|
|
|
|
if (error != 0)
|
|
|
|
return error == EWOULDBLOCK ? 0 : error;
|
2000-11-05 20:17:12 +03:00
|
|
|
}
|
|
|
|
etype = htons(ETHERTYPE_IPV6);
|
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
case pseudo_AF_HDRCMPLT:
|
|
|
|
case AF_UNSPEC:
|
|
|
|
/* TODO? */
|
|
|
|
default:
|
|
|
|
printf("%s: can't handle af%d\n", ifp->if_xname,
|
|
|
|
dst->sa_family);
|
|
|
|
senderr(EAFNOSUPPORT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mcopy)
|
|
|
|
looutput(ifp, mcopy, dst, rt);
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
myaddr = (const struct ieee1394_hwaddr *)CLLADDR(ifp->if_sadl);
|
2005-08-06 18:09:54 +04:00
|
|
|
if (ifp->if_bpf) {
|
|
|
|
struct ieee1394_bpfhdr h;
|
|
|
|
if (unicast)
|
|
|
|
memcpy(h.ibh_dhost, hwdst->iha_uid, 8);
|
|
|
|
else
|
|
|
|
memcpy(h.ibh_dhost,
|
|
|
|
((const struct ieee1394_hwaddr *)
|
|
|
|
ifp->if_broadcastaddr)->iha_uid, 8);
|
|
|
|
memcpy(h.ibh_shost, myaddr->iha_uid, 8);
|
|
|
|
h.ibh_type = etype;
|
2018-06-26 09:47:57 +03:00
|
|
|
bpf_mtap2(ifp->if_bpf, &h, sizeof(h), m0, BPF_D_OUT);
|
2005-08-06 18:09:54 +04:00
|
|
|
}
|
2000-11-14 14:14:55 +03:00
|
|
|
if ((ifp->if_flags & IFF_SIMPLEX) &&
|
2005-07-11 19:29:05 +04:00
|
|
|
unicast &&
|
|
|
|
memcmp(hwdst, myaddr, IEEE1394_ADDR_LEN) == 0)
|
2000-11-14 14:14:55 +03:00
|
|
|
return looutput(ifp, m0, dst, rt);
|
|
|
|
|
2000-11-20 15:12:18 +03:00
|
|
|
/*
|
|
|
|
* XXX:
|
|
|
|
* The maximum possible rate depends on the topology.
|
|
|
|
* So the determination of maxrec and fragmentation should be
|
|
|
|
* called from the driver after probing the topology map.
|
|
|
|
*/
|
2005-07-11 19:29:05 +04:00
|
|
|
if (unicast) {
|
2000-11-14 14:14:55 +03:00
|
|
|
hdrlen = IEEE1394_GASP_LEN;
|
2005-07-11 19:29:05 +04:00
|
|
|
hwdst->iha_speed = 0; /* XXX */
|
2000-11-14 14:14:55 +03:00
|
|
|
} else
|
|
|
|
hdrlen = 0;
|
2005-07-11 19:29:05 +04:00
|
|
|
|
|
|
|
if (hwdst->iha_speed > myaddr->iha_speed)
|
|
|
|
hwdst->iha_speed = myaddr->iha_speed;
|
|
|
|
if (hwdst->iha_maxrec > myaddr->iha_maxrec)
|
|
|
|
hwdst->iha_maxrec = myaddr->iha_maxrec;
|
|
|
|
if (hwdst->iha_maxrec > (8 + hwdst->iha_speed))
|
|
|
|
hwdst->iha_maxrec = 8 + hwdst->iha_speed;
|
|
|
|
if (hwdst->iha_maxrec < 8)
|
|
|
|
hwdst->iha_maxrec = 8;
|
|
|
|
|
|
|
|
m0 = ieee1394_fragment(ifp, m0, (2<<hwdst->iha_maxrec) - hdrlen, etype);
|
2000-11-14 14:14:55 +03:00
|
|
|
if (m0 == NULL)
|
|
|
|
senderr(ENOBUFS);
|
2000-11-20 15:12:18 +03:00
|
|
|
|
2000-11-14 14:14:55 +03:00
|
|
|
while ((m = m0) != NULL) {
|
|
|
|
m0 = m->m_nextpkt;
|
2016-04-28 04:37:17 +03:00
|
|
|
|
2016-06-22 13:44:31 +03:00
|
|
|
error = if_transmit_lock(ifp, m);
|
2002-03-05 07:12:57 +03:00
|
|
|
if (error) {
|
|
|
|
/* mbuf is already freed */
|
|
|
|
goto bad;
|
|
|
|
}
|
2000-11-14 14:14:55 +03:00
|
|
|
}
|
|
|
|
return 0;
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
bad:
|
|
|
|
while (m0 != NULL) {
|
|
|
|
m = m0->m_nextpkt;
|
|
|
|
m_freem(m0);
|
|
|
|
m0 = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-11-14 14:14:55 +03:00
|
|
|
struct mbuf *
|
|
|
|
ieee1394_fragment(struct ifnet *ifp, struct mbuf *m0, int maxsize,
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t etype)
|
2000-11-14 14:14:55 +03:00
|
|
|
{
|
|
|
|
struct ieee1394com *ic = (struct ieee1394com *)ifp;
|
|
|
|
int totlen, fraglen, off;
|
|
|
|
struct mbuf *m, **mp;
|
|
|
|
struct ieee1394_fraghdr *ifh;
|
|
|
|
struct ieee1394_unfraghdr *iuh;
|
|
|
|
|
|
|
|
totlen = m0->m_pkthdr.len;
|
|
|
|
if (totlen + sizeof(struct ieee1394_unfraghdr) <= maxsize) {
|
|
|
|
M_PREPEND(m0, sizeof(struct ieee1394_unfraghdr), M_DONTWAIT);
|
|
|
|
if (m0 == NULL)
|
|
|
|
goto bad;
|
|
|
|
iuh = mtod(m0, struct ieee1394_unfraghdr *);
|
|
|
|
iuh->iuh_ft = 0;
|
|
|
|
iuh->iuh_etype = etype;
|
|
|
|
return m0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fraglen = maxsize - sizeof(struct ieee1394_fraghdr);
|
|
|
|
|
|
|
|
M_PREPEND(m0, sizeof(struct ieee1394_fraghdr), M_DONTWAIT);
|
|
|
|
if (m0 == NULL)
|
|
|
|
goto bad;
|
|
|
|
ifh = mtod(m0, struct ieee1394_fraghdr *);
|
|
|
|
ifh->ifh_ft_size = htons(IEEE1394_FT_MORE | (totlen - 1));
|
|
|
|
ifh->ifh_etype_off = etype;
|
|
|
|
ifh->ifh_dgl = htons(ic->ic_dgl);
|
|
|
|
ifh->ifh_reserved = 0;
|
|
|
|
off = fraglen;
|
|
|
|
mp = &m0->m_nextpkt;
|
|
|
|
while (off < totlen) {
|
|
|
|
if (off + fraglen > totlen)
|
|
|
|
fraglen = totlen - off;
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_HEADER);
|
|
|
|
if (m == NULL)
|
|
|
|
goto bad;
|
|
|
|
m->m_flags |= m0->m_flags & (M_BCAST|M_MCAST); /* copy bcast */
|
2018-12-22 17:28:56 +03:00
|
|
|
m_align(m, sizeof(struct ieee1394_fraghdr));
|
2000-11-14 14:14:55 +03:00
|
|
|
m->m_len = sizeof(struct ieee1394_fraghdr);
|
|
|
|
ifh = mtod(m, struct ieee1394_fraghdr *);
|
|
|
|
ifh->ifh_ft_size =
|
|
|
|
htons(IEEE1394_FT_SUBSEQ | IEEE1394_FT_MORE | (totlen - 1));
|
|
|
|
ifh->ifh_etype_off = htons(off);
|
|
|
|
ifh->ifh_dgl = htons(ic->ic_dgl);
|
|
|
|
ifh->ifh_reserved = 0;
|
2018-04-26 22:56:55 +03:00
|
|
|
m->m_next = m_copym(m0, sizeof(*ifh) + off, fraglen, M_DONTWAIT);
|
2016-08-15 12:14:12 +03:00
|
|
|
if (m->m_next == NULL) {
|
|
|
|
m_freem(m);
|
2000-11-14 14:14:55 +03:00
|
|
|
goto bad;
|
2016-08-15 12:14:12 +03:00
|
|
|
}
|
2000-11-20 15:12:18 +03:00
|
|
|
m->m_pkthdr.len = sizeof(*ifh) + fraglen;
|
2000-11-14 14:14:55 +03:00
|
|
|
off += fraglen;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_nextpkt;
|
|
|
|
}
|
|
|
|
ifh->ifh_ft_size &= ~htons(IEEE1394_FT_MORE); /* last fragment */
|
|
|
|
m_adj(m0, -(m0->m_pkthdr.len - maxsize));
|
|
|
|
|
|
|
|
ic->ic_dgl++;
|
|
|
|
return m0;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
while ((m = m0) != NULL) {
|
|
|
|
m0 = m->m_nextpkt;
|
|
|
|
m->m_nextpkt = NULL;
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-11 19:29:05 +04:00
|
|
|
void
|
2008-02-20 20:05:52 +03:00
|
|
|
ieee1394_input(struct ifnet *ifp, struct mbuf *m, uint16_t src)
|
2000-11-05 20:17:12 +03:00
|
|
|
{
|
2014-06-06 03:48:16 +04:00
|
|
|
pktqueue_t *pktq = NULL;
|
2000-11-05 20:17:12 +03:00
|
|
|
struct ifqueue *inq;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t etype;
|
2000-11-05 20:17:12 +03:00
|
|
|
struct ieee1394_unfraghdr *iuh;
|
2014-05-15 13:04:03 +04:00
|
|
|
int isr = 0;
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
2005-07-11 19:29:05 +04:00
|
|
|
if (m->m_len < sizeof(*iuh)) {
|
|
|
|
if ((m = m_pullup(m, sizeof(*iuh))) == NULL)
|
2000-11-14 14:14:55 +03:00
|
|
|
return;
|
|
|
|
}
|
2000-11-05 20:17:12 +03:00
|
|
|
|
2005-07-11 19:29:05 +04:00
|
|
|
iuh = mtod(m, struct ieee1394_unfraghdr *);
|
2000-11-14 14:14:55 +03:00
|
|
|
|
|
|
|
if (ntohs(iuh->iuh_ft) & (IEEE1394_FT_SUBSEQ | IEEE1394_FT_MORE)) {
|
2005-07-11 19:29:05 +04:00
|
|
|
if ((m = ieee1394_reass(ifp, m, src)) == NULL)
|
2000-11-14 14:14:55 +03:00
|
|
|
return;
|
2005-07-11 19:29:05 +04:00
|
|
|
iuh = mtod(m, struct ieee1394_unfraghdr *);
|
2000-11-05 20:17:12 +03:00
|
|
|
}
|
|
|
|
etype = ntohs(iuh->iuh_etype);
|
|
|
|
|
|
|
|
/* strip off the ieee1394 header */
|
2005-07-11 19:29:05 +04:00
|
|
|
m_adj(m, sizeof(*iuh));
|
2005-08-06 18:09:54 +04:00
|
|
|
if (ifp->if_bpf) {
|
|
|
|
struct ieee1394_bpfhdr h;
|
|
|
|
struct m_tag *mtag;
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
const struct ieee1394_hwaddr *myaddr;
|
2005-08-06 18:09:54 +04:00
|
|
|
|
2018-11-15 13:23:55 +03:00
|
|
|
mtag = m_tag_find(m, MTAG_FIREWIRE_SENDER_EUID);
|
2005-08-06 18:09:54 +04:00
|
|
|
if (mtag)
|
|
|
|
memcpy(h.ibh_shost, mtag + 1, 8);
|
|
|
|
else
|
|
|
|
memset(h.ibh_shost, 0, 8);
|
|
|
|
if (m->m_flags & M_BCAST)
|
|
|
|
memcpy(h.ibh_dhost,
|
|
|
|
((const struct ieee1394_hwaddr *)
|
|
|
|
ifp->if_broadcastaddr)->iha_uid, 8);
|
|
|
|
else {
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
myaddr =
|
|
|
|
(const struct ieee1394_hwaddr *)CLLADDR(ifp->if_sadl);
|
2005-08-06 18:09:54 +04:00
|
|
|
memcpy(h.ibh_dhost, myaddr->iha_uid, 8);
|
|
|
|
}
|
|
|
|
h.ibh_type = htons(etype);
|
2018-06-26 09:47:57 +03:00
|
|
|
bpf_mtap2(ifp->if_bpf, &h, sizeof(h), m, BPF_D_IN);
|
2005-08-06 18:09:54 +04:00
|
|
|
}
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
switch (etype) {
|
|
|
|
#ifdef INET
|
|
|
|
case ETHERTYPE_IP:
|
2014-06-06 03:48:16 +04:00
|
|
|
pktq = ip_pktq;
|
2000-11-05 20:17:12 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETHERTYPE_ARP:
|
2014-05-15 13:04:03 +04:00
|
|
|
isr = NETISR_ARP;
|
2002-06-24 12:06:20 +04:00
|
|
|
inq = &arpintrq;
|
2002-06-24 16:00:49 +04:00
|
|
|
break;
|
2000-11-05 20:17:12 +03:00
|
|
|
#endif /* INET */
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
case ETHERTYPE_IPV6:
|
2014-06-06 03:48:16 +04:00
|
|
|
pktq = ip6_pktq;
|
2000-11-05 20:17:12 +03:00
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-06 03:48:16 +04:00
|
|
|
if (__predict_true(pktq)) {
|
|
|
|
if (__predict_false(!pktq_enqueue(pktq, m, 0))) {
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_LOCK(inq);
|
2000-11-05 20:17:12 +03:00
|
|
|
if (IF_QFULL(inq)) {
|
|
|
|
IF_DROP(inq);
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_UNLOCK(inq);
|
2000-11-05 20:17:12 +03:00
|
|
|
m_freem(m);
|
2014-05-15 13:04:03 +04:00
|
|
|
} else {
|
2000-11-05 20:17:12 +03:00
|
|
|
IF_ENQUEUE(inq, m);
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_UNLOCK(inq);
|
2014-05-15 13:04:03 +04:00
|
|
|
schednetisr(isr);
|
|
|
|
}
|
2000-11-05 20:17:12 +03:00
|
|
|
}
|
|
|
|
|
2000-11-14 14:14:55 +03:00
|
|
|
static struct mbuf *
|
2008-02-20 20:05:52 +03:00
|
|
|
ieee1394_reass(struct ifnet *ifp, struct mbuf *m0, uint16_t src)
|
2000-11-14 14:14:55 +03:00
|
|
|
{
|
|
|
|
struct ieee1394com *ic = (struct ieee1394com *)ifp;
|
|
|
|
struct ieee1394_fraghdr *ifh;
|
|
|
|
struct ieee1394_unfraghdr *iuh;
|
|
|
|
struct ieee1394_reassq *rq;
|
2003-10-26 22:09:44 +03:00
|
|
|
struct ieee1394_reass_pkt *rp, *trp, *nrp = NULL;
|
2000-11-14 14:14:55 +03:00
|
|
|
int len;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t etype, off, ftype, size, dgl;
|
|
|
|
uint32_t id;
|
2000-11-14 14:14:55 +03:00
|
|
|
|
2005-07-11 19:29:05 +04:00
|
|
|
if (m0->m_len < sizeof(*ifh)) {
|
|
|
|
if ((m0 = m_pullup(m0, sizeof(*ifh))) == NULL)
|
2000-11-14 14:14:55 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-11 19:29:05 +04:00
|
|
|
ifh = mtod(m0, struct ieee1394_fraghdr *);
|
|
|
|
m_adj(m0, sizeof(*ifh));
|
2000-11-14 14:14:55 +03:00
|
|
|
size = ntohs(ifh->ifh_ft_size);
|
|
|
|
ftype = size & (IEEE1394_FT_SUBSEQ | IEEE1394_FT_MORE);
|
|
|
|
size = (size & ~ftype) + 1;
|
2005-07-11 19:29:05 +04:00
|
|
|
dgl = ntohs(ifh->ifh_dgl);
|
2000-11-14 14:14:55 +03:00
|
|
|
len = m0->m_pkthdr.len;
|
2005-07-11 19:29:05 +04:00
|
|
|
id = dgl | (src << 16);
|
2000-11-14 14:14:55 +03:00
|
|
|
if (ftype & IEEE1394_FT_SUBSEQ) {
|
2018-05-07 12:51:02 +03:00
|
|
|
m_remove_pkthdr(m0);
|
2005-07-11 19:29:05 +04:00
|
|
|
etype = 0;
|
2000-11-14 14:14:55 +03:00
|
|
|
off = ntohs(ifh->ifh_etype_off);
|
2005-07-11 19:29:05 +04:00
|
|
|
} else {
|
|
|
|
etype = ifh->ifh_etype_off;
|
2000-11-14 14:14:55 +03:00
|
|
|
off = 0;
|
2005-07-11 19:29:05 +04:00
|
|
|
}
|
2000-11-14 14:14:55 +03:00
|
|
|
|
|
|
|
for (rq = LIST_FIRST(&ic->ic_reassq); ; rq = LIST_NEXT(rq, rq_node)) {
|
|
|
|
if (rq == NULL) {
|
|
|
|
/*
|
|
|
|
* Create a new reassemble queue head for the node.
|
|
|
|
*/
|
|
|
|
rq = malloc(sizeof(*rq), M_FTABLE, M_NOWAIT);
|
|
|
|
if (rq == NULL) {
|
|
|
|
m_freem(m0);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-11 19:29:05 +04:00
|
|
|
rq->fr_id = id;
|
2000-11-14 14:14:55 +03:00
|
|
|
LIST_INIT(&rq->rq_pkt);
|
|
|
|
LIST_INSERT_HEAD(&ic->ic_reassq, rq, rq_node);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-11 19:29:05 +04:00
|
|
|
if (rq->fr_id == id)
|
2000-11-14 14:14:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (rp = LIST_FIRST(&rq->rq_pkt); rp != NULL; rp = nrp) {
|
|
|
|
nrp = LIST_NEXT(rp, rp_next);
|
|
|
|
if (rp->rp_dgl != dgl)
|
|
|
|
continue;
|
2000-11-20 15:12:18 +03:00
|
|
|
/*
|
|
|
|
* sanity check:
|
|
|
|
* datagram size must be same for all fragments, and
|
|
|
|
* no overlap is allowed.
|
|
|
|
*/
|
|
|
|
if (rp->rp_size != size ||
|
|
|
|
(off < rp->rp_off + rp->rp_len && off + len > rp->rp_off)) {
|
2000-11-14 14:14:55 +03:00
|
|
|
/*
|
2000-11-20 15:12:18 +03:00
|
|
|
* This happens probably due to wrapping dgl value.
|
|
|
|
* Destroy all previously received fragment and
|
|
|
|
* enqueue current fragment.
|
2000-11-14 14:14:55 +03:00
|
|
|
*/
|
2000-11-20 15:12:18 +03:00
|
|
|
for (rp = LIST_FIRST(&rq->rq_pkt); rp != NULL;
|
|
|
|
rp = nrp) {
|
|
|
|
nrp = LIST_NEXT(rp, rp_next);
|
|
|
|
if (rp->rp_dgl == dgl) {
|
|
|
|
LIST_REMOVE(rp, rp_next);
|
|
|
|
m_freem(rp->rp_m);
|
|
|
|
free(rp, M_FTABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-11-14 14:14:55 +03:00
|
|
|
}
|
|
|
|
if (rp->rp_off + rp->rp_len == off) {
|
|
|
|
/*
|
|
|
|
* All the subsequent fragments received in sequence
|
|
|
|
* come here.
|
|
|
|
* Concatinate mbuf to previous one instead of
|
|
|
|
* allocating new reassemble queue structure,
|
|
|
|
* and try to merge more with the subsequent fragment
|
|
|
|
* in the queue.
|
|
|
|
*/
|
|
|
|
m_cat(rp->rp_m, m0);
|
|
|
|
rp->rp_len += len;
|
|
|
|
while (rp->rp_off + rp->rp_len < size &&
|
|
|
|
nrp != NULL && nrp->rp_dgl == dgl &&
|
|
|
|
nrp->rp_off == rp->rp_off + rp->rp_len) {
|
|
|
|
LIST_REMOVE(nrp, rp_next);
|
|
|
|
m_cat(rp->rp_m, nrp->rp_m);
|
|
|
|
rp->rp_len += nrp->rp_len;
|
2000-11-20 15:12:18 +03:00
|
|
|
free(nrp, M_FTABLE);
|
2000-11-14 14:14:55 +03:00
|
|
|
nrp = LIST_NEXT(rp, rp_next);
|
|
|
|
}
|
|
|
|
m0 = NULL; /* mark merged */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (off + m0->m_pkthdr.len == rp->rp_off) {
|
|
|
|
m_cat(m0, rp->rp_m);
|
|
|
|
rp->rp_m = m0;
|
|
|
|
rp->rp_off = off;
|
2005-07-11 19:29:05 +04:00
|
|
|
rp->rp_etype = etype; /* over writing trust etype */
|
2000-11-14 14:14:55 +03:00
|
|
|
rp->rp_len += len;
|
|
|
|
m0 = NULL; /* mark merged */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rp->rp_off > off) {
|
|
|
|
/* insert before rp */
|
|
|
|
nrp = rp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nrp == NULL || nrp->rp_dgl != dgl) {
|
|
|
|
/* insert after rp */
|
|
|
|
nrp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m0 == NULL) {
|
|
|
|
if (rp->rp_off != 0 || rp->rp_len != size)
|
|
|
|
return NULL;
|
|
|
|
/* fragment done */
|
|
|
|
LIST_REMOVE(rp, rp_next);
|
|
|
|
m0 = rp->rp_m;
|
|
|
|
m0->m_pkthdr.len = rp->rp_len;
|
2005-07-11 19:29:05 +04:00
|
|
|
M_PREPEND(m0, sizeof(*iuh), M_DONTWAIT);
|
2000-11-14 14:14:55 +03:00
|
|
|
if (m0 != NULL) {
|
2005-07-11 19:29:05 +04:00
|
|
|
iuh = mtod(m0, struct ieee1394_unfraghdr *);
|
2000-11-14 14:14:55 +03:00
|
|
|
iuh->iuh_ft = 0;
|
|
|
|
iuh->iuh_etype = rp->rp_etype;
|
|
|
|
}
|
|
|
|
free(rp, M_FTABLE);
|
|
|
|
return m0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* New fragment received. Allocate reassemble queue structure.
|
|
|
|
*/
|
|
|
|
trp = malloc(sizeof(*trp), M_FTABLE, M_NOWAIT);
|
|
|
|
if (trp == NULL) {
|
|
|
|
m_freem(m0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
trp->rp_m = m0;
|
|
|
|
trp->rp_size = size;
|
2005-07-11 19:29:05 +04:00
|
|
|
trp->rp_etype = etype; /* valid only if off==0 */
|
2000-11-14 14:14:55 +03:00
|
|
|
trp->rp_off = off;
|
|
|
|
trp->rp_dgl = dgl;
|
|
|
|
trp->rp_len = len;
|
2000-11-20 15:12:18 +03:00
|
|
|
trp->rp_ttl = IEEE1394_REASS_TIMEOUT;
|
|
|
|
if (trp->rp_ttl <= ifp->if_timer)
|
|
|
|
trp->rp_ttl = ifp->if_timer + 1;
|
2000-11-14 14:14:55 +03:00
|
|
|
|
|
|
|
if (rp == NULL) {
|
|
|
|
/* first fragment for the dgl */
|
|
|
|
LIST_INSERT_HEAD(&rq->rq_pkt, trp, rp_next);
|
|
|
|
} else if (nrp == NULL) {
|
|
|
|
/* no next fragment for the dgl */
|
|
|
|
LIST_INSERT_AFTER(rp, trp, rp_next);
|
|
|
|
} else {
|
|
|
|
/* there is a hole */
|
|
|
|
LIST_INSERT_BEFORE(nrp, trp, rp_next);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-11-20 15:12:18 +03:00
|
|
|
void
|
|
|
|
ieee1394_drain(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ieee1394com *ic = (struct ieee1394com *)ifp;
|
|
|
|
struct ieee1394_reassq *rq;
|
|
|
|
struct ieee1394_reass_pkt *rp;
|
|
|
|
|
|
|
|
while ((rq = LIST_FIRST(&ic->ic_reassq)) != NULL) {
|
|
|
|
LIST_REMOVE(rq, rq_node);
|
|
|
|
while ((rp = LIST_FIRST(&rq->rq_pkt)) != NULL) {
|
|
|
|
LIST_REMOVE(rp, rp_next);
|
|
|
|
m_freem(rp->rp_m);
|
|
|
|
free(rp, M_FTABLE);
|
|
|
|
}
|
|
|
|
free(rq, M_FTABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ieee1394_watchdog(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ieee1394com *ic = (struct ieee1394com *)ifp;
|
|
|
|
struct ieee1394_reassq *rq;
|
|
|
|
struct ieee1394_reass_pkt *rp, *nrp;
|
|
|
|
int dec;
|
|
|
|
|
|
|
|
dec = (ifp->if_timer > 0) ? ifp->if_timer : 1;
|
|
|
|
for (rq = LIST_FIRST(&ic->ic_reassq); rq != NULL;
|
|
|
|
rq = LIST_NEXT(rq, rq_node)) {
|
|
|
|
for (rp = LIST_FIRST(&rq->rq_pkt); rp != NULL; rp = nrp) {
|
|
|
|
nrp = LIST_NEXT(rp, rp_next);
|
|
|
|
if (rp->rp_ttl >= dec)
|
|
|
|
rp->rp_ttl -= dec;
|
|
|
|
else {
|
|
|
|
LIST_REMOVE(rp, rp_next);
|
|
|
|
m_freem(rp->rp_m);
|
|
|
|
free(rp, M_FTABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-05 20:17:12 +03:00
|
|
|
const char *
|
2008-02-20 20:05:52 +03:00
|
|
|
ieee1394_sprintf(const uint8_t *laddr)
|
2000-11-05 20:17:12 +03:00
|
|
|
{
|
|
|
|
static char buf[3*8];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
laddr[0], laddr[1], laddr[2], laddr[3],
|
|
|
|
laddr[4], laddr[5], laddr[6], laddr[7]);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ieee1394_ifattach(struct ifnet *ifp, const struct ieee1394_hwaddr *hwaddr)
|
|
|
|
{
|
2000-11-14 14:14:55 +03:00
|
|
|
struct ieee1394_hwaddr *baddr;
|
|
|
|
struct ieee1394com *ic = (struct ieee1394com *)ifp;
|
2000-11-05 20:17:12 +03:00
|
|
|
|
|
|
|
ifp->if_type = IFT_IEEE1394;
|
|
|
|
ifp->if_hdrlen = sizeof(struct ieee1394_header);
|
2000-12-18 22:44:33 +03:00
|
|
|
ifp->if_dlt = DLT_EN10MB; /* XXX */
|
2000-11-05 20:17:12 +03:00
|
|
|
ifp->if_mtu = IEEE1394MTU;
|
|
|
|
ifp->if_output = ieee1394_output;
|
2000-11-20 15:12:18 +03:00
|
|
|
ifp->if_drain = ieee1394_drain;
|
|
|
|
ifp->if_watchdog = ieee1394_watchdog;
|
|
|
|
ifp->if_timer = 1;
|
2000-11-05 20:17:12 +03:00
|
|
|
if (ifp->if_baudrate == 0)
|
|
|
|
ifp->if_baudrate = IF_Mbps(100);
|
2001-01-17 03:30:49 +03:00
|
|
|
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
if_set_sadl(ifp, hwaddr, sizeof(struct ieee1394_hwaddr), true);
|
2001-01-17 03:30:49 +03:00
|
|
|
|
2005-01-08 06:18:18 +03:00
|
|
|
baddr = malloc(ifp->if_addrlen, M_DEVBUF, M_WAITOK);
|
2000-11-14 14:14:55 +03:00
|
|
|
memset(baddr->iha_uid, 0xff, IEEE1394_ADDR_LEN);
|
2000-11-20 15:12:18 +03:00
|
|
|
baddr->iha_speed = 0; /*XXX: how to determine the speed for bcast? */
|
2000-11-14 14:14:55 +03:00
|
|
|
baddr->iha_maxrec = 512 << baddr->iha_speed;
|
|
|
|
memset(baddr->iha_offset, 0, sizeof(baddr->iha_offset));
|
2005-01-08 06:18:18 +03:00
|
|
|
ifp->if_broadcastaddr = (uint8_t *)baddr;
|
2000-11-14 14:14:55 +03:00
|
|
|
LIST_INIT(&ic->ic_reassq);
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_attach(ifp, DLT_APPLE_IP_OVER_IEEE1394,
|
|
|
|
sizeof(struct ieee1394_hwaddr));
|
2000-11-05 20:17:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ieee1394_ifdetach(struct ifnet *ifp)
|
|
|
|
{
|
2000-11-20 15:12:18 +03:00
|
|
|
ieee1394_drain(ifp);
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_detach(ifp);
|
2005-01-08 06:18:18 +03:00
|
|
|
free(__UNCONST(ifp->if_broadcastaddr), M_DEVBUF);
|
2001-01-17 03:30:49 +03:00
|
|
|
ifp->if_broadcastaddr = NULL;
|
2000-11-05 20:17:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
ieee1394_ioctl(struct ifnet *ifp, u_long cmd, void *data)
|
2000-11-05 20:17:12 +03:00
|
|
|
{
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
case SIOCINITIFADDR:
|
2000-11-05 20:17:12 +03:00
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if ((error = (*ifp->if_init)(ifp)) != 0)
|
|
|
|
break;
|
2002-06-24 12:06:20 +04:00
|
|
|
arp_ifinit(ifp, ifa);
|
2000-11-05 20:17:12 +03:00
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
default:
|
|
|
|
error = (*ifp->if_init)(ifp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
if (ifr->ifr_mtu > IEEE1394MTU)
|
|
|
|
error = EINVAL;
|
2008-02-07 04:21:52 +03:00
|
|
|
else if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET)
|
|
|
|
error = 0;
|
2000-11-05 20:17:12 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
error = ifioctl_common(ifp, cmd, data);
|
2000-11-05 20:17:12 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|