2009-11-20 05:14:56 +03:00
|
|
|
/* $NetBSD: if_ecosubr.c,v 1.33 2009/11/20 02:14:56 christos Exp $ */
|
2001-09-11 03:11:05 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 Ben Harris
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
2005-02-27 01:45:09 +03:00
|
|
|
*
|
2001-09-11 03:11:05 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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-09-13 22:01:34 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2001-09-13 22:01:34 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* @(#)if_ethersubr.c 8.2 (Berkeley) 4/4/96
|
|
|
|
*/
|
2001-09-11 03:11:05 +04:00
|
|
|
|
2001-11-13 02:49:33 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-11-20 05:14:56 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.33 2009/11/20 02:14:56 christos Exp $");
|
2001-11-13 02:49:33 +03:00
|
|
|
|
2001-09-11 03:11:05 +04:00
|
|
|
#include "bpfilter.h"
|
2001-09-15 21:27:24 +04:00
|
|
|
#include "opt_inet.h"
|
2003-06-23 15:00:59 +04:00
|
|
|
#include "opt_pfil_hooks.h"
|
2001-09-11 03:11:05 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/errno.h>
|
2001-09-13 22:01:34 +04:00
|
|
|
#include <sys/kernel.h>
|
2001-09-11 03:11:05 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_eco.h>
|
|
|
|
#include <net/if_types.h>
|
2001-09-15 21:27:24 +04:00
|
|
|
#include <net/netisr.h>
|
2001-09-13 22:01:34 +04:00
|
|
|
#include <net/route.h>
|
2001-09-11 03:11:05 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-15 21:27:24 +04:00
|
|
|
#ifdef INET
|
|
|
|
#include <net/ethertypes.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-18 02:41:59 +04:00
|
|
|
struct eco_retryparms {
|
|
|
|
int erp_delay;
|
|
|
|
int erp_count;
|
|
|
|
};
|
|
|
|
|
2001-09-11 03:11:05 +04:00
|
|
|
/* Default broadcast address */
|
2008-02-20 20:05:52 +03:00
|
|
|
static const uint8_t eco_broadcastaddr[] = { 0xff, 0xff };
|
2001-09-11 03:11:05 +04:00
|
|
|
|
2009-01-07 23:56:40 +03:00
|
|
|
static int eco_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
|
2001-09-11 03:11:05 +04:00
|
|
|
struct rtentry *);
|
|
|
|
static void eco_input(struct ifnet *, struct mbuf *);
|
|
|
|
static void eco_start(struct ifnet *);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int eco_ioctl(struct ifnet *, u_long, void *);
|
2001-09-11 03:11:05 +04:00
|
|
|
|
|
|
|
static int eco_interestingp(struct ifnet *ifp, struct mbuf *m);
|
|
|
|
static struct mbuf *eco_immediate(struct ifnet *ifp, struct mbuf *m);
|
|
|
|
static struct mbuf *eco_ack(struct ifnet *ifp, struct mbuf *m);
|
|
|
|
|
2001-09-18 02:41:59 +04:00
|
|
|
static void eco_defer(struct ifnet *, struct mbuf *, int);
|
|
|
|
static void eco_retry_free(struct eco_retry *er);
|
|
|
|
static void eco_retry(void *);
|
|
|
|
|
2001-09-11 03:11:05 +04:00
|
|
|
void
|
2008-02-20 20:05:52 +03:00
|
|
|
eco_ifattach(struct ifnet *ifp, const uint8_t *lla)
|
2001-09-11 03:11:05 +04:00
|
|
|
{
|
2001-09-18 02:41:59 +04:00
|
|
|
struct ecocom *ec = (void *)ifp;
|
2001-09-11 03:11:05 +04:00
|
|
|
|
2001-11-12 23:19:04 +03:00
|
|
|
ifp->if_type = IFT_ECONET;
|
2001-09-11 03:11:05 +04:00
|
|
|
ifp->if_addrlen = ECO_ADDR_LEN;
|
|
|
|
ifp->if_hdrlen = ECO_HDR_LEN;
|
|
|
|
ifp->if_dlt = DLT_ECONET;
|
|
|
|
ifp->if_mtu = ECO_MTU;
|
|
|
|
|
|
|
|
ifp->if_output = eco_output;
|
|
|
|
ifp->if_input = eco_input;
|
|
|
|
ifp->if_start = eco_start;
|
|
|
|
ifp->if_ioctl = eco_ioctl;
|
|
|
|
|
|
|
|
/* ifp->if_baudrate...; */
|
2009-01-07 23:56:40 +03:00
|
|
|
if_set_sadl(ifp, lla, ECO_ADDR_LEN, FALSE);
|
2001-09-11 03:11:05 +04:00
|
|
|
|
2006-02-12 13:32:46 +03:00
|
|
|
ifp->if_broadcastaddr = eco_broadcastaddr;
|
2001-09-18 02:41:59 +04:00
|
|
|
|
|
|
|
LIST_INIT(&ec->ec_retries);
|
|
|
|
|
2001-09-11 03:11:05 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
bpfattach(ifp, ifp->if_dlt, ECO_HDR_LEN);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#define senderr(e) do { \
|
|
|
|
error = (e); \
|
|
|
|
goto bad; \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
2001-09-15 21:27:24 +04:00
|
|
|
int
|
*** 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
|
|
|
eco_init(struct ifnet *ifp)
|
|
|
|
{
|
2001-09-15 21:27:24 +04:00
|
|
|
struct ecocom *ec = (struct ecocom *)ifp;
|
|
|
|
|
2001-09-18 02:41:59 +04:00
|
|
|
if ((ifp->if_flags & IFF_RUNNING) == 0)
|
|
|
|
ec->ec_state = ECO_UNKNOWN;
|
2001-09-15 21:27:24 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-18 02:41:59 +04:00
|
|
|
void
|
|
|
|
eco_stop(struct ifnet *ifp, int disable)
|
|
|
|
{
|
|
|
|
struct ecocom *ec = (struct ecocom *)ifp;
|
|
|
|
|
|
|
|
while (!LIST_EMPTY(&ec->ec_retries))
|
|
|
|
eco_retry_free(LIST_FIRST(&ec->ec_retries));
|
|
|
|
}
|
|
|
|
|
2001-09-11 03:11:05 +04:00
|
|
|
static int
|
2009-01-07 23:56:40 +03:00
|
|
|
eco_output(struct ifnet *ifp, struct mbuf *m0, const struct sockaddr *dst,
|
2001-09-11 03:11:05 +04:00
|
|
|
struct rtentry *rt0)
|
|
|
|
{
|
|
|
|
struct eco_header ehdr, *eh;
|
2005-03-31 19:48:13 +04:00
|
|
|
int error;
|
2001-09-15 21:27:24 +04:00
|
|
|
struct mbuf *m = m0, *mcopy = NULL;
|
2001-09-13 22:01:34 +04:00
|
|
|
struct rtentry *rt;
|
2001-09-11 03:11:05 +04:00
|
|
|
int hdrcmplt;
|
2006-02-12 13:32:46 +03:00
|
|
|
int retry_delay, retry_count;
|
2003-01-17 11:11:49 +03:00
|
|
|
struct m_tag *mtag;
|
2001-09-18 02:41:59 +04:00
|
|
|
struct eco_retryparms *erp;
|
2001-09-15 21:27:24 +04:00
|
|
|
#ifdef INET
|
|
|
|
struct mbuf *m1;
|
|
|
|
struct arphdr *ah;
|
2009-01-07 23:56:40 +03:00
|
|
|
void *tha;
|
2001-09-15 21:27:24 +04:00
|
|
|
struct eco_arp *ecah;
|
|
|
|
#endif
|
2001-09-11 03:11:05 +04:00
|
|
|
ALTQ_DECL(struct altq_pktattr pktattr;)
|
|
|
|
|
|
|
|
if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
|
|
|
|
senderr(ENETDOWN);
|
2001-09-13 22:01:34 +04:00
|
|
|
if ((rt = rt0) != NULL) {
|
|
|
|
if ((rt->rt_flags & RTF_UP) == 0) {
|
|
|
|
if ((rt0 = rt = rtalloc1(dst, 1)) != NULL) {
|
|
|
|
rt->rt_refcnt--;
|
|
|
|
if (rt->rt_ifp != ifp)
|
|
|
|
return (*rt->rt_ifp->if_output)
|
|
|
|
(ifp, m0, dst, rt);
|
2005-02-27 01:45:09 +03:00
|
|
|
} else
|
2001-09-13 22:01:34 +04:00
|
|
|
senderr(EHOSTUNREACH);
|
|
|
|
}
|
|
|
|
if ((rt->rt_flags & RTF_GATEWAY) && dst->sa_family != AF_NS) {
|
|
|
|
if (rt->rt_gwroute == 0)
|
|
|
|
goto lookup;
|
|
|
|
if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
|
|
|
|
rtfree(rt); rt = rt0;
|
|
|
|
lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1);
|
|
|
|
if ((rt = rt->rt_gwroute) == 0)
|
|
|
|
senderr(EHOSTUNREACH);
|
|
|
|
/* the "G" test below also prevents rt == rt0 */
|
|
|
|
if ((rt->rt_flags & RTF_GATEWAY) ||
|
|
|
|
(rt->rt_ifp != ifp)) {
|
|
|
|
rt->rt_refcnt--;
|
|
|
|
rt0->rt_gwroute = 0;
|
|
|
|
senderr(EHOSTUNREACH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rt->rt_flags & RTF_REJECT)
|
|
|
|
if (rt->rt_rmx.rmx_expire == 0 ||
|
2006-06-08 02:33:33 +04:00
|
|
|
time_second < rt->rt_rmx.rmx_expire)
|
2001-09-13 22:01:34 +04:00
|
|
|
senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
|
|
|
|
}
|
2001-09-11 03:11:05 +04:00
|
|
|
/*
|
|
|
|
* If the queueing discipline needs packet classification,
|
|
|
|
* do it before prepending link headers.
|
|
|
|
*/
|
|
|
|
IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family, &pktattr);
|
|
|
|
|
|
|
|
hdrcmplt = 0;
|
2006-02-12 13:32:46 +03:00
|
|
|
retry_delay = hz / 16;
|
|
|
|
retry_count = 16;
|
2001-09-11 03:11:05 +04:00
|
|
|
switch (dst->sa_family) {
|
2001-09-15 21:27:24 +04:00
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (m->m_flags & M_BCAST)
|
|
|
|
memcpy(ehdr.eco_dhost, eco_broadcastaddr,
|
|
|
|
ECO_ADDR_LEN);
|
|
|
|
|
|
|
|
else if (!arpresolve(ifp, rt, m, dst, ehdr.eco_dhost))
|
|
|
|
return (0); /* if not yet resolved */
|
|
|
|
/* If broadcasting on a simplex interface, loopback a copy */
|
|
|
|
if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
|
|
|
|
mcopy = m_copy(m, 0, (int)M_COPYALL);
|
|
|
|
ehdr.eco_port = ECO_PORT_IP;
|
|
|
|
ehdr.eco_control = ECO_CTL_IP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_ARP:
|
|
|
|
ah = mtod(m, struct arphdr *);
|
|
|
|
|
|
|
|
if (ntohs(ah->ar_pro) != ETHERTYPE_IP)
|
|
|
|
return EAFNOSUPPORT;
|
|
|
|
ehdr.eco_port = ECO_PORT_IP;
|
|
|
|
switch (ntohs(ah->ar_op)) {
|
|
|
|
case ARPOP_REQUEST:
|
|
|
|
ehdr.eco_control = ECO_CTL_ARP_REQUEST;
|
|
|
|
break;
|
|
|
|
case ARPOP_REPLY:
|
|
|
|
ehdr.eco_control = ECO_CTL_ARP_REPLY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m->m_flags & M_BCAST)
|
|
|
|
memcpy(ehdr.eco_dhost, eco_broadcastaddr,
|
|
|
|
ECO_ADDR_LEN);
|
2009-01-07 23:56:40 +03:00
|
|
|
else {
|
|
|
|
tha = ar_tha(ah);
|
2009-11-20 05:14:56 +03:00
|
|
|
if (tha == NULL)
|
|
|
|
return 0;
|
2009-01-07 23:56:40 +03:00
|
|
|
memcpy(ehdr.eco_dhost, tha, ECO_ADDR_LEN);
|
|
|
|
}
|
2001-09-15 21:27:24 +04:00
|
|
|
|
|
|
|
MGETHDR(m1, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m1 == NULL)
|
|
|
|
senderr(ENOBUFS);
|
2005-08-18 04:30:58 +04:00
|
|
|
M_MOVE_PKTHDR(m1, m);
|
2001-09-15 21:27:24 +04:00
|
|
|
m1->m_len = sizeof(*ecah);
|
|
|
|
m1->m_pkthdr.len = m1->m_len;
|
|
|
|
MH_ALIGN(m1, m1->m_len);
|
|
|
|
ecah = mtod(m1, struct eco_arp *);
|
|
|
|
memset(ecah, 0, m1->m_len);
|
|
|
|
memcpy(ecah->ecar_spa, ar_spa(ah), ah->ar_pln);
|
|
|
|
memcpy(ecah->ecar_tpa, ar_tpa(ah), ah->ar_pln);
|
|
|
|
m_freem(m);
|
|
|
|
m = m1;
|
|
|
|
break;
|
|
|
|
#endif
|
2001-09-11 03:11:05 +04:00
|
|
|
case pseudo_AF_HDRCMPLT:
|
|
|
|
hdrcmplt = 1;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case AF_UNSPEC:
|
2009-01-07 23:56:40 +03:00
|
|
|
ehdr = *(struct eco_header const *)dst->sa_data;
|
2001-09-11 03:11:05 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log(LOG_ERR, "%s: can't handle af%d\n", ifp->if_xname,
|
|
|
|
dst->sa_family);
|
|
|
|
senderr(EAFNOSUPPORT);
|
|
|
|
}
|
|
|
|
|
2001-09-15 21:27:24 +04:00
|
|
|
if (mcopy)
|
|
|
|
(void) looutput(ifp, mcopy, dst, rt);
|
|
|
|
|
2001-09-11 03:11:05 +04:00
|
|
|
/*
|
|
|
|
* Add local net header. If no space in first mbuf,
|
|
|
|
* allocate another.
|
|
|
|
*/
|
|
|
|
M_PREPEND(m, sizeof (struct eco_header), M_DONTWAIT);
|
|
|
|
if (m == 0)
|
|
|
|
senderr(ENOBUFS);
|
|
|
|
eh = mtod(m, struct eco_header *);
|
|
|
|
*eh = ehdr;
|
|
|
|
if (!hdrcmplt)
|
2007-08-27 02:59:08 +04:00
|
|
|
memcpy(eh->eco_shost, CLLADDR(ifp->if_sadl),
|
2001-09-11 03:11:05 +04:00
|
|
|
ECO_ADDR_LEN);
|
|
|
|
|
2001-09-18 02:41:59 +04:00
|
|
|
if ((m->m_flags & M_BCAST) == 0) {
|
|
|
|
/* Attach retry info to packet. */
|
2003-01-17 11:11:49 +03:00
|
|
|
mtag = m_tag_get(PACKET_TAG_ECO_RETRYPARMS,
|
|
|
|
sizeof(struct eco_retryparms), M_NOWAIT);
|
|
|
|
if (mtag == NULL)
|
2001-09-18 02:41:59 +04:00
|
|
|
senderr(ENOBUFS);
|
2003-01-17 11:11:49 +03:00
|
|
|
erp = (struct eco_retryparms *)(mtag + 1);
|
2006-02-12 13:32:46 +03:00
|
|
|
erp->erp_delay = retry_delay;
|
|
|
|
erp->erp_count = retry_count;
|
2001-09-18 02:41:59 +04:00
|
|
|
}
|
|
|
|
|
2001-09-11 03:11:05 +04:00
|
|
|
#ifdef PFIL_HOOKS
|
|
|
|
if ((error = pfil_run_hooks(&ifp->if_pfil, &m, ifp, PFIL_OUT)) != 0)
|
|
|
|
return (error);
|
|
|
|
if (m == NULL)
|
|
|
|
return (0);
|
|
|
|
#endif
|
2005-02-27 01:45:09 +03:00
|
|
|
|
2006-02-12 13:32:46 +03:00
|
|
|
return ifq_enqueue(ifp, m ALTQ_COMMA ALTQ_DECL(&pktattr));
|
2001-09-11 03:11:05 +04:00
|
|
|
|
|
|
|
bad:
|
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a scout, decide if we want the rest of the packet.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
eco_interestingp(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
2001-09-15 21:27:24 +04:00
|
|
|
struct eco_header *eh;
|
2001-09-11 03:11:05 +04:00
|
|
|
|
2001-09-15 21:27:24 +04:00
|
|
|
eh = mtod(m, struct eco_header *);
|
|
|
|
switch (eh->eco_port) {
|
|
|
|
#ifdef INET
|
|
|
|
case ECO_PORT_IP:
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
2001-09-11 03:11:05 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eco_input(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
2001-09-15 21:27:24 +04:00
|
|
|
struct ifqueue *inq;
|
2001-09-16 16:16:50 +04:00
|
|
|
struct eco_header ehdr, *eh;
|
2001-09-16 19:08:39 +04:00
|
|
|
int s, i;
|
2001-09-15 21:27:24 +04:00
|
|
|
#ifdef INET
|
|
|
|
struct arphdr *ah;
|
|
|
|
struct eco_arp *ecah;
|
|
|
|
struct mbuf *m1;
|
2009-01-07 23:56:40 +03:00
|
|
|
void *tha;
|
2001-09-15 21:27:24 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PFIL_HOOKS
|
|
|
|
if (pfil_run_hooks(&ifp->if_pfil, &m, ifp, PFIL_IN) != 0)
|
|
|
|
return;
|
|
|
|
if (m == NULL)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2001-09-16 16:16:50 +04:00
|
|
|
/* Copy the mbuf header and trim it off. */
|
|
|
|
/* XXX use m_split? */
|
|
|
|
eh = &ehdr;
|
2007-03-04 08:59:00 +03:00
|
|
|
m_copydata(m, 0, ECO_HDR_LEN, (void *)eh);
|
2001-09-15 21:27:24 +04:00
|
|
|
m_adj(m, ECO_HDR_LEN);
|
|
|
|
|
|
|
|
switch (eh->eco_port) {
|
|
|
|
#ifdef INET
|
|
|
|
case ECO_PORT_IP:
|
|
|
|
switch (eh->eco_control) {
|
|
|
|
case ECO_CTL_IP:
|
|
|
|
schednetisr(NETISR_IP);
|
|
|
|
inq = &ipintrq;
|
|
|
|
break;
|
|
|
|
case ECO_CTL_ARP_REQUEST:
|
|
|
|
case ECO_CTL_ARP_REPLY:
|
|
|
|
/*
|
|
|
|
* ARP over Econet is strange, because Econet only
|
|
|
|
* supports 8 bytes of data in a broadcast packet.
|
|
|
|
* To cope with this, only the source and destination
|
|
|
|
* IP addresses are actually contained in the packet
|
|
|
|
* and we have to infer the rest and build a fake ARP
|
|
|
|
* packet to pass upwards.
|
|
|
|
*/
|
2001-09-16 16:16:50 +04:00
|
|
|
if (m->m_pkthdr.len != sizeof(struct eco_arp))
|
|
|
|
goto drop;
|
|
|
|
if (m->m_len < sizeof(struct eco_arp)) {
|
|
|
|
m = m_pullup(m, sizeof(struct eco_arp));
|
|
|
|
if (m == NULL) goto drop;
|
|
|
|
}
|
2001-09-15 21:27:24 +04:00
|
|
|
ecah = mtod(m, struct eco_arp *);
|
|
|
|
/* This code derived from arprequest() */
|
|
|
|
MGETHDR(m1, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m1 == NULL)
|
|
|
|
goto drop;
|
2005-08-18 04:30:58 +04:00
|
|
|
M_MOVE_PKTHDR(m1, m);
|
2001-09-15 21:27:24 +04:00
|
|
|
m1->m_len = sizeof(*ah) + 2*sizeof(struct in_addr) +
|
|
|
|
2*ifp->if_data.ifi_addrlen;
|
|
|
|
m1->m_pkthdr.len = m1->m_len;
|
|
|
|
MH_ALIGN(m1, m1->m_len);
|
|
|
|
ah = mtod(m1, struct arphdr *);
|
2009-03-18 19:00:08 +03:00
|
|
|
memset((void *)ah, 0, m1->m_len);
|
2001-09-15 21:27:24 +04:00
|
|
|
ah->ar_pro = htons(ETHERTYPE_IP);
|
|
|
|
ah->ar_hln = ifp->if_data.ifi_addrlen;
|
|
|
|
ah->ar_pln = sizeof(struct in_addr);
|
|
|
|
if (eh->eco_control == ECO_CTL_ARP_REQUEST)
|
|
|
|
ah->ar_op = htons(ARPOP_REQUEST);
|
|
|
|
else
|
|
|
|
ah->ar_op = htons(ARPOP_REPLY);
|
2009-01-07 23:56:40 +03:00
|
|
|
tha = ar_tha(ah);
|
|
|
|
KASSERT(tha != NULL);
|
2001-09-15 21:27:24 +04:00
|
|
|
memcpy(ar_sha(ah), eh->eco_shost, ah->ar_hln);
|
2009-01-07 23:56:40 +03:00
|
|
|
memcpy(tha, eh->eco_dhost, ah->ar_hln);
|
2001-09-15 21:27:24 +04:00
|
|
|
memcpy(ar_spa(ah), ecah->ecar_spa, ah->ar_pln);
|
|
|
|
memcpy(ar_tpa(ah), ecah->ecar_tpa, ah->ar_pln);
|
|
|
|
m_freem(m);
|
|
|
|
m = m1;
|
|
|
|
schednetisr(NETISR_ARP);
|
|
|
|
inq = &arpintrq;
|
|
|
|
break;
|
2001-09-16 19:08:39 +04:00
|
|
|
case ECO_CTL_IPBCAST_REQUEST:
|
|
|
|
{
|
|
|
|
struct sockaddr_storage dst_store;
|
|
|
|
struct sockaddr *dst = (struct sockaddr *)&dst_store;
|
|
|
|
|
|
|
|
/* Queue? */
|
|
|
|
memcpy(eh->eco_dhost, eh->eco_shost, ECO_ADDR_LEN);
|
|
|
|
eh->eco_control = ECO_CTL_IPBCAST_REPLY;
|
|
|
|
/* dst->sa_len??? */
|
|
|
|
dst->sa_family = AF_UNSPEC;
|
|
|
|
memcpy(dst->sa_data, eh, ECO_HDR_LEN);
|
|
|
|
ifp->if_output(ifp, m, dst, NULL);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-15 21:27:24 +04:00
|
|
|
default:
|
2001-09-16 19:08:39 +04:00
|
|
|
printf("%s: unknown IP stn %s ctl 0x%02x len %d:",
|
2001-09-15 21:27:24 +04:00
|
|
|
ifp->if_xname, eco_sprintf(eh->eco_shost),
|
2001-09-16 19:08:39 +04:00
|
|
|
eh->eco_control, m->m_pkthdr.len);
|
|
|
|
if (m->m_len == 0) {
|
|
|
|
m = m_pullup(m, 1);
|
|
|
|
if (m == 0) {
|
|
|
|
printf("\n");
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < m->m_len; i++)
|
2008-02-20 20:05:52 +03:00
|
|
|
printf(" %02x", mtod(m, uint8_t *)[i]);
|
2001-09-16 19:08:39 +04:00
|
|
|
printf("\n");
|
2001-09-15 21:27:24 +04:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
printf("%s: unknown port stn %s port 0x%02x ctl 0x%02x\n",
|
|
|
|
ifp->if_xname, eco_sprintf(eh->eco_shost),
|
|
|
|
eh->eco_port, eh->eco_control);
|
|
|
|
drop:
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-18 02:41:59 +04:00
|
|
|
|
2001-09-15 21:27:24 +04:00
|
|
|
s = splnet();
|
|
|
|
if (IF_QFULL(inq)) {
|
|
|
|
IF_DROP(inq);
|
|
|
|
m_freem(m);
|
|
|
|
} else
|
|
|
|
IF_ENQUEUE(inq, m);
|
|
|
|
splx(s);
|
2001-09-11 03:11:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eco_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ecocom *ec = (void *)ifp;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct eco_header *eh;
|
|
|
|
|
2001-09-15 21:27:24 +04:00
|
|
|
if (ec->ec_state != ECO_IDLE) return;
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
if (m == NULL) return;
|
|
|
|
if (ec->ec_claimwire(ifp) == 0) {
|
|
|
|
eh = mtod(m, struct eco_header *);
|
|
|
|
if (eh->eco_port == ECO_PORT_IMMEDIATE) {
|
|
|
|
ec->ec_txframe(ifp, m);
|
|
|
|
ec->ec_state = ECO_IMMED_SENT;
|
|
|
|
} else if (eh->eco_dhost[0] == 255) {
|
|
|
|
ec->ec_txframe(ifp, m);
|
|
|
|
ec->ec_state = ECO_DONE;
|
2001-09-11 03:11:05 +04:00
|
|
|
} else {
|
2001-09-15 21:27:24 +04:00
|
|
|
ec->ec_packet = m;
|
|
|
|
m = m_copym(m, 0, ECO_HDR_LEN, M_DONTWAIT);
|
|
|
|
if (m == NULL) {
|
|
|
|
m_freem(ec->ec_packet);
|
2001-09-18 02:41:59 +04:00
|
|
|
ec->ec_packet = NULL;
|
2001-09-15 21:27:24 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ec->ec_txframe(ifp, m);
|
|
|
|
ec->ec_state = ECO_SCOUT_SENT;
|
2001-09-11 03:11:05 +04:00
|
|
|
}
|
2001-09-15 21:27:24 +04:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
} else {
|
|
|
|
log(LOG_ERR, "%s: line jammed\n", ifp->if_xname);
|
|
|
|
m_freem(m);
|
2001-09-11 03:11:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
eco_ioctl(struct ifnet *ifp, u_long cmd, void *data)
|
2001-09-11 03:11:05 +04:00
|
|
|
{
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
2008-03-12 21:22:24 +03:00
|
|
|
int error;
|
2001-09-11 03:11:05 +04:00
|
|
|
|
|
|
|
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:
|
2001-09-11 03:11:05 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
*** 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 ((ifp->if_flags & IFF_RUNNING) == 0 &&
|
|
|
|
(error = (*ifp->if_init)(ifp)) != 0)
|
|
|
|
return error;
|
2001-09-11 03:11:05 +04:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
2001-09-15 21:27:24 +04:00
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
arp_ifinit(ifp, ifa);
|
|
|
|
break;
|
|
|
|
#endif
|
2001-09-11 03:11:05 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-03-12 21:22:24 +03:00
|
|
|
return 0;
|
2001-09-11 03:11:05 +04:00
|
|
|
case SIOCSIFMTU:
|
2009-01-07 23:56:40 +03:00
|
|
|
if ((error = ifioctl_common(ifp, cmd, data)) != ENETRESET)
|
2008-03-12 21:22:24 +03:00
|
|
|
return error;
|
2008-02-07 04:21:52 +03:00
|
|
|
else if (ifp->if_flags & IFF_UP)
|
2008-03-12 21:22:24 +03:00
|
|
|
return (*ifp->if_init)(ifp);
|
2008-02-07 04:21:52 +03:00
|
|
|
else
|
2008-03-12 21:22:24 +03:00
|
|
|
return 0;
|
2001-09-11 03:11:05 +04:00
|
|
|
break;
|
|
|
|
case SIOCSIFFLAGS:
|
*** 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 ((error = ifioctl_common(ifp, cmd, data)) != 0)
|
|
|
|
return error;
|
2008-03-12 21:22:24 +03:00
|
|
|
switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
|
|
|
|
case IFF_RUNNING:
|
2001-09-11 03:11:05 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running,
|
|
|
|
* then stop and disable it.
|
|
|
|
*/
|
|
|
|
(*ifp->if_stop)(ifp, 1);
|
2008-03-12 21:22:24 +03:00
|
|
|
return 0;
|
|
|
|
case IFF_UP:
|
2001-09-11 03:11:05 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
2008-03-12 21:22:24 +03:00
|
|
|
return (*ifp->if_init)(ifp);
|
|
|
|
case IFF_UP|IFF_RUNNING:
|
2001-09-11 03:11:05 +04:00
|
|
|
/*
|
|
|
|
* Reset the interface to pick up changes in any other
|
|
|
|
* flags that affect the hardware state.
|
|
|
|
*/
|
2008-03-12 21:22:24 +03:00
|
|
|
return (*ifp->if_init)(ifp);
|
|
|
|
case 0:
|
|
|
|
return 0;
|
2001-09-11 03:11:05 +04: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
|
|
|
return ifioctl_common(ifp, cmd, data);
|
2001-09-11 03:11:05 +04:00
|
|
|
}
|
|
|
|
|
2008-03-12 21:22:24 +03:00
|
|
|
return 0;
|
2001-09-11 03:11:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a raw Econet frame off the interface. The interface may be
|
|
|
|
* flag-filling for a response.
|
|
|
|
*
|
|
|
|
* May be called from IPL_NET or IPL_SOFTNET.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct mbuf *
|
|
|
|
eco_inputframe(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct ecocom *ec = (void *)ifp;
|
2001-09-16 03:03:11 +04:00
|
|
|
struct eco_header *eh, *eh0;
|
2001-09-11 03:11:05 +04:00
|
|
|
struct mbuf *m0;
|
|
|
|
struct mbuf *reply;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
eh = mtod(m, struct eco_header *);
|
|
|
|
switch (ec->ec_state) {
|
2001-09-16 03:03:11 +04:00
|
|
|
case ECO_IDLE: /* Start of a packet (bcast, immed, scout) */
|
|
|
|
if (m->m_pkthdr.len < ECO_HDR_LEN) {
|
|
|
|
log(LOG_NOTICE, "%s: undersize scout\n",
|
|
|
|
ifp->if_xname);
|
|
|
|
goto drop;
|
|
|
|
}
|
2001-09-11 03:11:05 +04:00
|
|
|
if (memcmp(eh->eco_dhost, eco_broadcastaddr,
|
|
|
|
ECO_ADDR_LEN) == 0) {
|
|
|
|
/* Broadcast */
|
2001-09-13 23:19:21 +04:00
|
|
|
eco_input(ifp, m);
|
2007-08-27 02:59:08 +04:00
|
|
|
} else if (memcmp(eh->eco_dhost, CLLADDR(ifp->if_sadl),
|
2001-09-11 03:11:05 +04:00
|
|
|
ECO_ADDR_LEN) == 0) {
|
|
|
|
/* Unicast for us */
|
|
|
|
if (eh->eco_port == ECO_PORT_IMMEDIATE)
|
|
|
|
return eco_immediate(ifp, m);
|
|
|
|
else {
|
|
|
|
if (eco_interestingp(ifp, m)) {
|
|
|
|
reply = eco_ack(ifp, m);
|
|
|
|
if (reply == NULL) {
|
|
|
|
m_freem(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ec->ec_state = ECO_SCOUT_RCVD;
|
|
|
|
ec->ec_scout = m;
|
|
|
|
return reply;
|
|
|
|
} else {
|
|
|
|
m_freem(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
/* Not for us. Throw it away. */
|
|
|
|
m_freem(m);
|
|
|
|
break;
|
2001-09-16 03:03:11 +04:00
|
|
|
case ECO_SCOUT_RCVD: /* Packet data */
|
2001-09-11 03:11:05 +04:00
|
|
|
KASSERT(ec->ec_scout != NULL);
|
2001-09-16 03:03:11 +04:00
|
|
|
m0 = ec->ec_scout;
|
|
|
|
eh0 = mtod(m0, struct eco_header *);
|
|
|
|
if (m->m_pkthdr.len < ECO_SHDR_LEN ||
|
|
|
|
memcmp(eh->eco_shost, eh0->eco_shost, ECO_ADDR_LEN) != 0 ||
|
|
|
|
memcmp(eh->eco_dhost, eh0->eco_dhost, ECO_ADDR_LEN) != 0) {
|
|
|
|
log(LOG_NOTICE, "%s: garbled data packet header\n",
|
|
|
|
ifp->if_xname);
|
|
|
|
goto drop;
|
|
|
|
}
|
2001-09-11 03:11:05 +04:00
|
|
|
reply = eco_ack(ifp, m);
|
|
|
|
/*
|
|
|
|
* Chop off the small header from this frame, and put
|
|
|
|
* the scout (which holds the control byte and port)
|
|
|
|
* in its place.
|
|
|
|
*/
|
|
|
|
ec->ec_scout = NULL;
|
|
|
|
m_adj(m, ECO_SHDR_LEN);
|
|
|
|
len = m0->m_pkthdr.len + m->m_pkthdr.len;
|
|
|
|
m_cat(m0, m);
|
|
|
|
m0->m_pkthdr.len = len;
|
|
|
|
ec->ec_state = ECO_DONE;
|
|
|
|
eco_input(ifp, m0);
|
|
|
|
return reply;
|
2001-09-16 03:03:11 +04:00
|
|
|
case ECO_SCOUT_SENT: /* Scout ack */
|
2001-09-11 03:11:05 +04:00
|
|
|
KASSERT(ec->ec_packet != NULL);
|
2001-09-16 03:03:11 +04:00
|
|
|
m0 = ec->ec_packet;
|
|
|
|
eh0 = mtod(m0, struct eco_header *);
|
|
|
|
if (m->m_pkthdr.len != ECO_SHDR_LEN ||
|
|
|
|
memcmp(eh->eco_shost, eh0->eco_dhost, ECO_ADDR_LEN) != 0 ||
|
|
|
|
memcmp(eh->eco_dhost, eh0->eco_shost, ECO_ADDR_LEN) != 0) {
|
|
|
|
log(LOG_NOTICE, "%s: garbled scout ack\n",
|
|
|
|
ifp->if_xname);
|
|
|
|
goto drop;
|
|
|
|
}
|
2001-09-11 03:11:05 +04:00
|
|
|
m_freem(m);
|
|
|
|
/* Chop out the control and port bytes. */
|
|
|
|
m0 = m_copym(ec->ec_packet, 0, ECO_SHDR_LEN, M_DONTWAIT);
|
|
|
|
if (m0 == NULL) {
|
|
|
|
m_freem(ec->ec_packet);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-18 02:41:59 +04:00
|
|
|
m = ec->ec_packet;
|
|
|
|
ec->ec_packet = m_copypacket(m, M_DONTWAIT);
|
|
|
|
if (ec->ec_packet == NULL) {
|
2001-09-11 03:11:05 +04:00
|
|
|
m_freem(m0);
|
2001-09-18 02:41:59 +04:00
|
|
|
m_freem(m);
|
2001-09-11 03:11:05 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
m_adj(m, ECO_HDR_LEN);
|
|
|
|
len = m0->m_pkthdr.len + m->m_pkthdr.len;
|
|
|
|
m_cat(m0, m); /* Doesn't update packet header */
|
|
|
|
m0->m_pkthdr.len = len;
|
|
|
|
ec->ec_state = ECO_DATA_SENT;
|
|
|
|
return m0;
|
2001-09-16 03:03:11 +04:00
|
|
|
case ECO_DATA_SENT: /* Data ack */
|
2001-09-11 03:11:05 +04:00
|
|
|
KASSERT(ec->ec_packet != NULL);
|
2001-09-16 03:03:11 +04:00
|
|
|
m0 = ec->ec_packet;
|
|
|
|
eh0 = mtod(m0, struct eco_header *);
|
|
|
|
if (m->m_pkthdr.len != ECO_SHDR_LEN ||
|
|
|
|
memcmp(eh->eco_shost, eh0->eco_dhost, ECO_ADDR_LEN) != 0 ||
|
|
|
|
memcmp(eh->eco_dhost, eh0->eco_shost, ECO_ADDR_LEN) != 0) {
|
|
|
|
log(LOG_NOTICE, "%s: garbled data ack\n",
|
|
|
|
ifp->if_xname);
|
|
|
|
goto drop;
|
|
|
|
}
|
2001-09-11 03:11:05 +04:00
|
|
|
m_freem(m);
|
|
|
|
m_freem(ec->ec_packet);
|
|
|
|
ec->ec_packet = NULL;
|
|
|
|
ec->ec_state = ECO_DONE;
|
|
|
|
return NULL;
|
|
|
|
default:
|
2001-09-16 03:03:11 +04:00
|
|
|
drop:
|
2001-09-11 03:11:05 +04:00
|
|
|
m_freem(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an immediate operation, and return the reply, or NULL not to reply.
|
|
|
|
* Frees the incoming mbuf.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct mbuf *
|
|
|
|
eco_immediate(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct eco_header *eh, *reh;
|
|
|
|
struct mbuf *n;
|
2008-02-20 20:05:52 +03:00
|
|
|
static const uint8_t machinepeek_data[] = { 42, 0, 0, 1 };
|
2001-09-11 03:11:05 +04:00
|
|
|
|
|
|
|
eh = mtod(m, struct eco_header *);
|
|
|
|
switch (eh->eco_control) {
|
|
|
|
case ECO_CTL_MACHINEPEEK:
|
|
|
|
MGETHDR(n, M_DONTWAIT, MT_DATA);
|
|
|
|
if (n == NULL)
|
|
|
|
goto bad;
|
|
|
|
n->m_len = n->m_pkthdr.len = ECO_SHDR_LEN + 4;
|
|
|
|
reh = mtod(n, struct eco_header *);
|
|
|
|
memcpy(reh->eco_dhost, eh->eco_shost,
|
|
|
|
ECO_ADDR_LEN);
|
2007-08-27 02:59:08 +04:00
|
|
|
memcpy(reh->eco_shost, CLLADDR(ifp->if_sadl),
|
2001-09-11 03:11:05 +04:00
|
|
|
ECO_ADDR_LEN);
|
2009-01-07 23:56:40 +03:00
|
|
|
memcpy(mtod(n, char *) + ECO_SHDR_LEN, machinepeek_data,
|
2001-09-11 03:11:05 +04:00
|
|
|
sizeof(machinepeek_data));
|
|
|
|
m_freem(m);
|
|
|
|
return n;
|
|
|
|
default:
|
|
|
|
bad:
|
|
|
|
m_freem(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate (and return) an acknowledgement for a frame. Doesn't free the
|
|
|
|
* original frame, since it's probably needed elsewhere.
|
|
|
|
*/
|
|
|
|
static struct mbuf *
|
|
|
|
eco_ack(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct eco_header *eh, *reh;
|
|
|
|
struct mbuf *n;
|
|
|
|
|
|
|
|
eh = mtod(m, struct eco_header *);
|
|
|
|
MGETHDR(n, M_DONTWAIT, MT_DATA);
|
|
|
|
if (n == NULL)
|
|
|
|
return NULL;
|
|
|
|
n->m_len = n->m_pkthdr.len = ECO_SHDR_LEN;
|
|
|
|
reh = mtod(n, struct eco_header *);
|
|
|
|
memcpy(reh->eco_dhost, eh->eco_shost, ECO_ADDR_LEN);
|
2007-08-27 02:59:08 +04:00
|
|
|
memcpy(reh->eco_shost, CLLADDR(ifp->if_sadl), ECO_ADDR_LEN);
|
2001-09-11 03:11:05 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
eco_inputidle(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ecocom *ec = (void *)ifp;
|
2003-01-17 11:11:49 +03:00
|
|
|
struct mbuf *m;
|
|
|
|
struct m_tag *mtag;
|
2001-09-18 02:41:59 +04:00
|
|
|
struct eco_retryparms *erp;
|
2001-09-11 03:11:05 +04:00
|
|
|
|
2001-09-18 02:41:59 +04:00
|
|
|
switch (ec->ec_state) {
|
|
|
|
case ECO_SCOUT_SENT:
|
|
|
|
case ECO_DATA_SENT:
|
|
|
|
case ECO_IMMED_SENT:
|
|
|
|
/* Outgoing packet failed. Check if we should retry. */
|
|
|
|
m = ec->ec_packet;
|
|
|
|
ec->ec_packet = NULL;
|
2003-01-17 11:11:49 +03:00
|
|
|
mtag = m_tag_find(m, PACKET_TAG_ECO_RETRYPARMS, NULL);
|
|
|
|
if (mtag == NULL)
|
2001-09-18 02:41:59 +04:00
|
|
|
m_freem(m);
|
|
|
|
else {
|
2003-01-17 11:11:49 +03:00
|
|
|
erp = (struct eco_retryparms *)(mtag + 1);
|
2001-09-18 02:41:59 +04:00
|
|
|
if (--erp->erp_count > 0)
|
|
|
|
eco_defer(ifp, m, erp->erp_delay);
|
2003-01-17 11:11:49 +03:00
|
|
|
else
|
2001-09-18 02:41:59 +04:00
|
|
|
printf("%s: pkt failed\n", ifp->if_xname);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECO_SCOUT_RCVD:
|
|
|
|
m_freem(ec->ec_scout);
|
|
|
|
ec->ec_scout = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-09-11 03:11:05 +04:00
|
|
|
ec->ec_state = ECO_IDLE;
|
2001-09-15 21:27:24 +04:00
|
|
|
ifp->if_start(ifp);
|
2001-09-11 03:11:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert Econet address to printable (loggable) representation.
|
|
|
|
*/
|
|
|
|
char *
|
2008-02-20 20:05:52 +03:00
|
|
|
eco_sprintf(const uint8_t *ea)
|
2001-09-11 03:11:05 +04:00
|
|
|
{
|
|
|
|
static char buf[8];
|
|
|
|
|
|
|
|
if (ea[1] == 0)
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(buf, sizeof(buf), "%d", ea[0]);
|
2001-09-11 03:11:05 +04:00
|
|
|
else
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(buf, sizeof(buf), "%d.%d", ea[1], ea[0]);
|
2001-09-11 03:11:05 +04:00
|
|
|
return buf;
|
|
|
|
}
|
2005-02-27 01:45:09 +03:00
|
|
|
|
2001-09-18 02:41:59 +04:00
|
|
|
/*
|
|
|
|
* Econet retry handling.
|
|
|
|
*/
|
|
|
|
static void
|
2006-02-12 13:32:46 +03:00
|
|
|
eco_defer(struct ifnet *ifp, struct mbuf *m, int retry_delay)
|
2001-09-18 02:41:59 +04:00
|
|
|
{
|
|
|
|
struct ecocom *ec = (struct ecocom *)ifp;
|
|
|
|
struct eco_retry *er;
|
|
|
|
int s;
|
|
|
|
|
2008-12-17 23:51:31 +03:00
|
|
|
er = malloc(sizeof(*er), M_TEMP, M_NOWAIT);
|
2001-09-18 02:41:59 +04:00
|
|
|
if (er == NULL) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&er->er_callout, 0);
|
2001-09-18 02:41:59 +04:00
|
|
|
er->er_packet = m;
|
|
|
|
er->er_ifp = ifp;
|
|
|
|
s = splnet();
|
|
|
|
LIST_INSERT_HEAD(&ec->ec_retries, er, er_link);
|
|
|
|
splx(s);
|
2006-02-12 13:32:46 +03:00
|
|
|
callout_reset(&er->er_callout, retry_delay, eco_retry, er);
|
2001-09-18 02:41:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eco_retry_free(struct eco_retry *er)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
callout_stop(&er->er_callout);
|
|
|
|
m_freem(er->er_packet);
|
|
|
|
s = splnet();
|
|
|
|
LIST_REMOVE(er, er_link);
|
|
|
|
splx(s);
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_destroy(&er->er_callout);
|
2008-12-17 23:51:31 +03:00
|
|
|
free(er, M_TEMP);
|
2001-09-18 02:41:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eco_retry(void *arg)
|
|
|
|
{
|
|
|
|
struct eco_retry *er = arg;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = er->er_ifp;
|
|
|
|
m = er->er_packet;
|
|
|
|
LIST_REMOVE(er, er_link);
|
2005-03-31 19:48:13 +04:00
|
|
|
(void)ifq_enqueue(ifp, m ALTQ_COMMA ALTQ_DECL(NULL));
|
2008-12-17 23:51:31 +03:00
|
|
|
free(er, M_TEMP);
|
2001-09-18 02:41:59 +04:00
|
|
|
}
|