2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1999-02-20 11:18:00 +00:00
|
|
|
* Copyright (c) 1998, Larry Lile
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* For latest sources and information on this driver, please
|
|
|
|
* go to http://anarchy.stdio.com.
|
|
|
|
*
|
|
|
|
* Questions, comments or suggestions should be directed to
|
|
|
|
* Larry Lile <lile@stdio.com>.
|
|
|
|
*
|
|
|
|
* 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 unmodified, 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 AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1999-02-20 11:18:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* General ISO 802.5 (Token Ring) support routines
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_inet.h"
|
2001-03-18 05:43:25 +00:00
|
|
|
#include "opt_inet6.h"
|
1999-02-20 11:18:00 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2003-03-15 16:37:28 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
1999-02-20 11:18:00 +00:00
|
|
|
#include <sys/mbuf.h>
|
2003-03-15 16:37:28 +00:00
|
|
|
#include <sys/module.h>
|
1999-02-20 11:18:00 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
2013-10-26 17:58:36 +00:00
|
|
|
#include <net/if_var.h>
|
2008-11-06 09:18:29 +00:00
|
|
|
#include <net/if_arp.h>
|
1999-02-20 11:18:00 +00:00
|
|
|
#include <net/if_dl.h>
|
2003-03-15 16:37:28 +00:00
|
|
|
#include <net/if_llc.h>
|
1999-02-20 11:18:00 +00:00
|
|
|
#include <net/if_types.h>
|
This main goals of this project are:
1. separating L2 tables (ARP, NDP) from the L3 routing tables
2. removing as much locking dependencies among these layers as
possible to allow for some parallelism in the search operations
3. simplify the logic in the routing code,
The most notable end result is the obsolescent of the route
cloning (RTF_CLONING) concept, which translated into code reduction
in both IPv4 ARP and IPv6 NDP related modules, and size reduction in
struct rtentry{}. The change in design obsoletes the semantics of
RTF_CLONING, RTF_WASCLONE and RTF_LLINFO routing flags. The userland
applications such as "arp" and "ndp" have been modified to reflect
those changes. The output from "netstat -r" shows only the routing
entries.
Quite a few developers have contributed to this project in the
past: Glebius Smirnoff, Luigi Rizzo, Alessandro Cerri, and
Andre Oppermann. And most recently:
- Kip Macy revised the locking code completely, thus completing
the last piece of the puzzle, Kip has also been conducting
active functional testing
- Sam Leffler has helped me improving/refactoring the code, and
provided valuable reviews
- Julian Elischer setup the perforce tree for me and has helped
me maintaining that branch before the svn conversion
2008-12-15 06:10:57 +00:00
|
|
|
#include <net/if_llatbl.h>
|
1999-02-20 11:18:00 +00:00
|
|
|
|
2008-11-06 09:18:29 +00:00
|
|
|
#include <net/ethernet.h>
|
2003-03-15 16:37:28 +00:00
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/bpf.h>
|
1999-02-20 11:18:00 +00:00
|
|
|
#include <net/iso88025.h>
|
|
|
|
|
2001-03-18 05:43:25 +00:00
|
|
|
#if defined(INET) || defined(INET6)
|
1999-02-20 11:18:00 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
#endif
|
2001-03-18 05:43:25 +00:00
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/nd6.h>
|
|
|
|
#endif
|
|
|
|
|
2006-10-22 11:52:19 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
|
2004-03-13 05:46:26 +00:00
|
|
|
static const u_char iso88025_broadcastaddr[ISO88025_ADDR_LEN] =
|
2003-03-15 19:16:39 +00:00
|
|
|
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
|
2003-03-15 16:49:08 +00:00
|
|
|
static int iso88025_resolvemulti (struct ifnet *, struct sockaddr **,
|
2003-03-15 22:25:06 +00:00
|
|
|
struct sockaddr *);
|
2003-03-15 16:49:08 +00:00
|
|
|
|
2003-03-15 19:10:19 +00:00
|
|
|
#define senderr(e) do { error = (e); goto bad; } while (0)
|
2001-03-18 05:43:25 +00:00
|
|
|
|
2003-03-15 22:52:23 +00:00
|
|
|
/*
|
|
|
|
* Perform common duties while attaching to interface list
|
|
|
|
*/
|
1999-02-20 11:18:00 +00:00
|
|
|
void
|
2005-11-11 07:36:14 +00:00
|
|
|
iso88025_ifattach(struct ifnet *ifp, const u_int8_t *lla, int bpf)
|
1999-02-20 11:18:00 +00:00
|
|
|
{
|
2003-03-15 22:37:11 +00:00
|
|
|
struct ifaddr *ifa;
|
2003-03-03 00:21:52 +00:00
|
|
|
struct sockaddr_dl *sdl;
|
1999-02-20 11:18:00 +00:00
|
|
|
|
2003-03-15 22:37:11 +00:00
|
|
|
ifa = NULL;
|
|
|
|
|
1999-02-20 11:18:00 +00:00
|
|
|
ifp->if_type = IFT_ISO88025;
|
2000-03-19 21:34:39 +00:00
|
|
|
ifp->if_addrlen = ISO88025_ADDR_LEN;
|
|
|
|
ifp->if_hdrlen = ISO88025_HDR_LEN;
|
2003-03-15 22:52:23 +00:00
|
|
|
|
|
|
|
if_attach(ifp); /* Must be called before additional assignments */
|
|
|
|
|
|
|
|
ifp->if_output = iso88025_output;
|
|
|
|
ifp->if_input = iso88025_input;
|
|
|
|
ifp->if_resolvemulti = iso88025_resolvemulti;
|
|
|
|
ifp->if_broadcastaddr = iso88025_broadcastaddr;
|
|
|
|
|
1999-02-20 11:18:00 +00:00
|
|
|
if (ifp->if_baudrate == 0)
|
2000-03-19 21:34:39 +00:00
|
|
|
ifp->if_baudrate = TR_16MBPS; /* 16Mbit should be a safe default */
|
1999-02-20 11:18:00 +00:00
|
|
|
if (ifp->if_mtu == 0)
|
|
|
|
ifp->if_mtu = ISO88025_DEFAULT_MTU;
|
|
|
|
|
2005-11-11 16:04:59 +00:00
|
|
|
ifa = ifp->if_addr;
|
|
|
|
KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
|
2003-03-15 22:52:23 +00:00
|
|
|
|
2003-03-15 16:41:35 +00:00
|
|
|
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
|
|
|
sdl->sdl_type = IFT_ISO88025;
|
|
|
|
sdl->sdl_alen = ifp->if_addrlen;
|
2005-11-11 07:36:14 +00:00
|
|
|
bcopy(lla, LLADDR(sdl), ifp->if_addrlen);
|
2003-03-15 22:52:23 +00:00
|
|
|
|
|
|
|
if (bpf)
|
|
|
|
bpfattach(ifp, DLT_IEEE802, ISO88025_HDR_LEN);
|
|
|
|
|
|
|
|
return;
|
1999-02-20 11:18:00 +00:00
|
|
|
}
|
|
|
|
|
2001-03-18 05:43:25 +00:00
|
|
|
/*
|
|
|
|
* Perform common duties while detaching a Token Ring interface
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
iso88025_ifdetach(ifp, bpf)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int bpf;
|
|
|
|
{
|
2003-03-15 17:54:49 +00:00
|
|
|
|
2001-03-18 05:43:25 +00:00
|
|
|
if (bpf)
|
|
|
|
bpfdetach(ifp);
|
2003-03-15 17:54:49 +00:00
|
|
|
|
2001-03-18 05:43:25 +00:00
|
|
|
if_detach(ifp);
|
|
|
|
|
2003-03-15 17:54:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-03-18 05:43:25 +00:00
|
|
|
|
1999-02-20 11:18:00 +00:00
|
|
|
int
|
2009-06-21 10:29:31 +00:00
|
|
|
iso88025_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
1999-02-20 11:18:00 +00:00
|
|
|
{
|
2003-03-15 17:54:49 +00:00
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct ifreq *ifr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ifa = (struct ifaddr *) data;
|
|
|
|
ifr = (struct ifreq *) data;
|
|
|
|
error = 0;
|
1999-02-20 11:18:00 +00:00
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
ifp->if_init(ifp->if_softc); /* before arpwhohas */
|
2001-10-14 20:17:53 +00:00
|
|
|
arp_ifinit(ifp, ifa);
|
1999-02-20 11:18:00 +00:00
|
|
|
break;
|
2001-03-18 05:43:25 +00:00
|
|
|
#endif /* INET */
|
1999-02-20 11:18:00 +00:00
|
|
|
default:
|
|
|
|
ifp->if_init(ifp->if_softc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-09-14 02:18:54 +00:00
|
|
|
case SIOCGIFADDR: {
|
1999-02-20 11:18:00 +00:00
|
|
|
struct sockaddr *sa;
|
|
|
|
|
|
|
|
sa = (struct sockaddr *) & ifr->ifr_data;
|
2005-11-11 16:04:59 +00:00
|
|
|
bcopy(IF_LLADDR(ifp),
|
1999-02-20 11:18:00 +00:00
|
|
|
(caddr_t) sa->sa_data, ISO88025_ADDR_LEN);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
/*
|
|
|
|
* Set the interface MTU.
|
|
|
|
*/
|
2000-03-19 21:34:39 +00:00
|
|
|
if (ifr->ifr_mtu > ISO88025_MAX_MTU) {
|
1999-02-20 11:18:00 +00:00
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
}
|
|
|
|
break;
|
2003-03-15 17:54:49 +00:00
|
|
|
default:
|
|
|
|
error = EINVAL; /* XXX netbsd has ENOTTY??? */
|
|
|
|
break;
|
1999-02-20 11:18:00 +00:00
|
|
|
}
|
2003-03-15 17:54:49 +00:00
|
|
|
|
1999-02-20 11:18:00 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ISO88025 encapsulation
|
|
|
|
*/
|
|
|
|
int
|
2013-04-26 12:50:32 +00:00
|
|
|
iso88025_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
|
|
|
|
struct route *ro)
|
1999-02-20 11:18:00 +00:00
|
|
|
{
|
2001-03-18 05:43:25 +00:00
|
|
|
u_int16_t snap_type = 0;
|
2001-12-14 19:32:47 +00:00
|
|
|
int loop_copy = 0, error = 0, rif_len = 0;
|
|
|
|
u_char edst[ISO88025_ADDR_LEN];
|
2001-03-18 05:43:25 +00:00
|
|
|
struct iso88025_header *th;
|
1999-03-10 10:11:43 +00:00
|
|
|
struct iso88025_header gen_th;
|
2001-03-18 05:43:25 +00:00
|
|
|
struct sockaddr_dl *sdl = NULL;
|
2009-04-16 20:30:28 +00:00
|
|
|
struct rtentry *rt0 = NULL;
|
2014-11-27 23:06:25 +00:00
|
|
|
int is_gw = 0;
|
2009-04-16 20:30:28 +00:00
|
|
|
|
2016-01-09 16:34:37 +00:00
|
|
|
if (ro != NULL)
|
|
|
|
is_gw = (ro->ro_flags & RT_HAS_GW) != 0;
|
2003-03-15 21:30:00 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_ifnet_check_transmit(ifp, m);
|
2003-03-15 21:30:00 +00:00
|
|
|
if (error)
|
|
|
|
senderr(error);
|
|
|
|
#endif
|
|
|
|
|
2003-03-16 00:17:44 +00:00
|
|
|
if (ifp->if_flags & IFF_MONITOR)
|
|
|
|
senderr(ENETDOWN);
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING)))
|
1999-02-20 11:18:00 +00:00
|
|
|
senderr(ENETDOWN);
|
2001-03-18 05:43:25 +00:00
|
|
|
getmicrotime(&ifp->if_lastchange);
|
|
|
|
|
This commit does two things:
1. rt_check() cleanup:
rt_check() is only necessary for some address families to gain access
to the corresponding arp entry, so call it only in/near the *resolve()
routines where it is actually used -- at the moment this is
arpresolve(), nd6_storelladdr() (the call is embedded here),
and atmresolve() (the call is just before atmresolve to reduce
the number of changes).
This change will make it a lot easier to decouple the arp table
from the routing table.
There is an extra call to rt_check() in if_iso88025subr.c to
determine the routing info length. I have left it alone for
the time being.
The interface of arpresolve() and nd6_storelladdr() now changes slightly:
+ the 'rtentry' parameter (really a hint from the upper level layer)
is now passed unchanged from *_output(), so it becomes the route
to the final destination and not to the gateway.
+ the routines will return 0 if resolution is possible, non-zero
otherwise.
+ arpresolve() returns EWOULDBLOCK in case the mbuf is being held
waiting for an arp reply -- in this case the error code is masked
in the caller so the upper layer protocol will not see a failure.
2. arpcom untangling
Where possible, use 'struct ifnet' instead of 'struct arpcom' variables,
and use the IFP2AC macro to access arpcom fields.
This mostly affects the netatalk code.
=== Detailed changes: ===
net/if_arcsubr.c
rt_check() cleanup, remove a useless variable
net/if_atmsubr.c
rt_check() cleanup
net/if_ethersubr.c
rt_check() cleanup, arpcom untangling
net/if_fddisubr.c
rt_check() cleanup, arpcom untangling
net/if_iso88025subr.c
rt_check() cleanup
netatalk/aarp.c
arpcom untangling, remove a block of duplicated code
netatalk/at_extern.h
arpcom untangling
netinet/if_ether.c
rt_check() cleanup (change arpresolve)
netinet6/nd6.c
rt_check() cleanup (change nd6_storelladdr)
2004-04-25 09:24:52 +00:00
|
|
|
/* Calculate routing info length based on arp table entry */
|
|
|
|
/* XXX any better way to do this ? */
|
1999-02-20 11:18:00 +00:00
|
|
|
|
This main goals of this project are:
1. separating L2 tables (ARP, NDP) from the L3 routing tables
2. removing as much locking dependencies among these layers as
possible to allow for some parallelism in the search operations
3. simplify the logic in the routing code,
The most notable end result is the obsolescent of the route
cloning (RTF_CLONING) concept, which translated into code reduction
in both IPv4 ARP and IPv6 NDP related modules, and size reduction in
struct rtentry{}. The change in design obsoletes the semantics of
RTF_CLONING, RTF_WASCLONE and RTF_LLINFO routing flags. The userland
applications such as "arp" and "ndp" have been modified to reflect
those changes. The output from "netstat -r" shows only the routing
entries.
Quite a few developers have contributed to this project in the
past: Glebius Smirnoff, Luigi Rizzo, Alessandro Cerri, and
Andre Oppermann. And most recently:
- Kip Macy revised the locking code completely, thus completing
the last piece of the puzzle, Kip has also been conducting
active functional testing
- Sam Leffler has helped me improving/refactoring the code, and
provided valuable reviews
- Julian Elischer setup the perforce tree for me and has helped
me maintaining that branch before the svn conversion
2008-12-15 06:10:57 +00:00
|
|
|
if (rt0 && (sdl = (struct sockaddr_dl *)rt0->rt_gateway))
|
2002-08-22 21:24:01 +00:00
|
|
|
if (SDL_ISO88025(sdl)->trld_rcf != 0)
|
2002-05-07 22:14:06 +00:00
|
|
|
rif_len = TR_RCF_RIFLEN(SDL_ISO88025(sdl)->trld_rcf);
|
1999-03-10 10:11:43 +00:00
|
|
|
|
|
|
|
/* Generate a generic 802.5 header for the packet */
|
2000-03-19 21:34:39 +00:00
|
|
|
gen_th.ac = TR_AC;
|
|
|
|
gen_th.fc = TR_LLC_FRAME;
|
2005-11-11 16:04:59 +00:00
|
|
|
(void)memcpy((caddr_t)gen_th.iso88025_shost, IF_LLADDR(ifp),
|
2003-03-15 19:25:00 +00:00
|
|
|
ISO88025_ADDR_LEN);
|
1999-03-10 10:11:43 +00:00
|
|
|
if (rif_len) {
|
2000-03-19 21:34:39 +00:00
|
|
|
gen_th.iso88025_shost[0] |= TR_RII;
|
1999-03-10 10:11:43 +00:00
|
|
|
if (rif_len > 2) {
|
2002-05-07 22:14:06 +00:00
|
|
|
gen_th.rcf = SDL_ISO88025(sdl)->trld_rcf;
|
2001-03-18 05:43:25 +00:00
|
|
|
(void)memcpy((caddr_t)gen_th.rd,
|
2002-05-07 22:14:06 +00:00
|
|
|
(caddr_t)SDL_ISO88025(sdl)->trld_route,
|
|
|
|
rif_len - 2);
|
1999-03-10 10:11:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dst->sa_family) {
|
1999-02-20 11:18:00 +00:00
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2016-06-02 17:51:29 +00:00
|
|
|
error = arpresolve(ifp, is_gw, m, dst, edst, NULL, NULL);
|
This commit does two things:
1. rt_check() cleanup:
rt_check() is only necessary for some address families to gain access
to the corresponding arp entry, so call it only in/near the *resolve()
routines where it is actually used -- at the moment this is
arpresolve(), nd6_storelladdr() (the call is embedded here),
and atmresolve() (the call is just before atmresolve to reduce
the number of changes).
This change will make it a lot easier to decouple the arp table
from the routing table.
There is an extra call to rt_check() in if_iso88025subr.c to
determine the routing info length. I have left it alone for
the time being.
The interface of arpresolve() and nd6_storelladdr() now changes slightly:
+ the 'rtentry' parameter (really a hint from the upper level layer)
is now passed unchanged from *_output(), so it becomes the route
to the final destination and not to the gateway.
+ the routines will return 0 if resolution is possible, non-zero
otherwise.
+ arpresolve() returns EWOULDBLOCK in case the mbuf is being held
waiting for an arp reply -- in this case the error code is masked
in the caller so the upper layer protocol will not see a failure.
2. arpcom untangling
Where possible, use 'struct ifnet' instead of 'struct arpcom' variables,
and use the IFP2AC macro to access arpcom fields.
This mostly affects the netatalk code.
=== Detailed changes: ===
net/if_arcsubr.c
rt_check() cleanup, remove a useless variable
net/if_atmsubr.c
rt_check() cleanup
net/if_ethersubr.c
rt_check() cleanup, arpcom untangling
net/if_fddisubr.c
rt_check() cleanup, arpcom untangling
net/if_iso88025subr.c
rt_check() cleanup
netatalk/aarp.c
arpcom untangling, remove a block of duplicated code
netatalk/at_extern.h
arpcom untangling
netinet/if_ether.c
rt_check() cleanup (change arpresolve)
netinet6/nd6.c
rt_check() cleanup (change nd6_storelladdr)
2004-04-25 09:24:52 +00:00
|
|
|
if (error)
|
|
|
|
return (error == EWOULDBLOCK ? 0 : error);
|
2001-03-18 05:43:25 +00:00
|
|
|
snap_type = ETHERTYPE_IP;
|
1999-02-20 11:18:00 +00:00
|
|
|
break;
|
2004-03-14 05:24:54 +00:00
|
|
|
case AF_ARP:
|
|
|
|
{
|
|
|
|
struct arphdr *ah;
|
|
|
|
ah = mtod(m, struct arphdr *);
|
|
|
|
ah->ar_hrd = htons(ARPHRD_IEEE802);
|
|
|
|
|
|
|
|
loop_copy = -1; /* if this is for us, don't do it */
|
|
|
|
|
|
|
|
switch(ntohs(ah->ar_op)) {
|
|
|
|
case ARPOP_REVREQUEST:
|
|
|
|
case ARPOP_REVREPLY:
|
|
|
|
snap_type = ETHERTYPE_REVARP;
|
|
|
|
break;
|
|
|
|
case ARPOP_REQUEST:
|
|
|
|
case ARPOP_REPLY:
|
|
|
|
default:
|
|
|
|
snap_type = ETHERTYPE_ARP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m->m_flags & M_BCAST)
|
|
|
|
bcopy(ifp->if_broadcastaddr, edst, ISO88025_ADDR_LEN);
|
|
|
|
else
|
|
|
|
bcopy(ar_tha(ah), edst, ISO88025_ADDR_LEN);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
2001-03-18 05:43:25 +00:00
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2016-06-02 17:51:29 +00:00
|
|
|
error = nd6_resolve(ifp, is_gw, m, dst, edst, NULL, NULL);
|
This commit does two things:
1. rt_check() cleanup:
rt_check() is only necessary for some address families to gain access
to the corresponding arp entry, so call it only in/near the *resolve()
routines where it is actually used -- at the moment this is
arpresolve(), nd6_storelladdr() (the call is embedded here),
and atmresolve() (the call is just before atmresolve to reduce
the number of changes).
This change will make it a lot easier to decouple the arp table
from the routing table.
There is an extra call to rt_check() in if_iso88025subr.c to
determine the routing info length. I have left it alone for
the time being.
The interface of arpresolve() and nd6_storelladdr() now changes slightly:
+ the 'rtentry' parameter (really a hint from the upper level layer)
is now passed unchanged from *_output(), so it becomes the route
to the final destination and not to the gateway.
+ the routines will return 0 if resolution is possible, non-zero
otherwise.
+ arpresolve() returns EWOULDBLOCK in case the mbuf is being held
waiting for an arp reply -- in this case the error code is masked
in the caller so the upper layer protocol will not see a failure.
2. arpcom untangling
Where possible, use 'struct ifnet' instead of 'struct arpcom' variables,
and use the IFP2AC macro to access arpcom fields.
This mostly affects the netatalk code.
=== Detailed changes: ===
net/if_arcsubr.c
rt_check() cleanup, remove a useless variable
net/if_atmsubr.c
rt_check() cleanup
net/if_ethersubr.c
rt_check() cleanup, arpcom untangling
net/if_fddisubr.c
rt_check() cleanup, arpcom untangling
net/if_iso88025subr.c
rt_check() cleanup
netatalk/aarp.c
arpcom untangling, remove a block of duplicated code
netatalk/at_extern.h
arpcom untangling
netinet/if_ether.c
rt_check() cleanup (change arpresolve)
netinet6/nd6.c
rt_check() cleanup (change nd6_storelladdr)
2004-04-25 09:24:52 +00:00
|
|
|
if (error)
|
2015-09-16 14:26:28 +00:00
|
|
|
return (error == EWOULDBLOCK ? 0 : error);
|
2001-03-18 05:43:25 +00:00
|
|
|
snap_type = ETHERTYPE_IPV6;
|
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
1999-02-20 11:18:00 +00:00
|
|
|
case AF_UNSPEC:
|
2001-03-18 05:43:25 +00:00
|
|
|
{
|
2013-04-26 12:50:32 +00:00
|
|
|
const struct iso88025_sockaddr_data *sd;
|
1999-03-10 10:11:43 +00:00
|
|
|
/*
|
|
|
|
* For AF_UNSPEC sockaddr.sa_data must contain all of the
|
|
|
|
* mac information needed to send the packet. This allows
|
|
|
|
* full mac, llc, and source routing function to be controlled.
|
|
|
|
* llc and source routing information must already be in the
|
|
|
|
* mbuf provided, ac/fc are set in sa_data. sockaddr.sa_data
|
2003-01-01 18:49:04 +00:00
|
|
|
* should be an iso88025_sockaddr_data structure see iso88025.h
|
1999-03-10 10:11:43 +00:00
|
|
|
*/
|
1999-02-20 11:18:00 +00:00
|
|
|
loop_copy = -1;
|
2013-04-26 12:50:32 +00:00
|
|
|
sd = (const struct iso88025_sockaddr_data *)dst->sa_data;
|
1999-03-10 10:11:43 +00:00
|
|
|
gen_th.ac = sd->ac;
|
|
|
|
gen_th.fc = sd->fc;
|
2013-04-26 12:50:32 +00:00
|
|
|
(void)memcpy(edst, sd->ether_dhost, ISO88025_ADDR_LEN);
|
|
|
|
(void)memcpy(gen_th.iso88025_shost, sd->ether_shost,
|
|
|
|
ISO88025_ADDR_LEN);
|
1999-03-10 10:11:43 +00:00
|
|
|
rif_len = 0;
|
1999-02-20 11:18:00 +00:00
|
|
|
break;
|
2001-03-18 05:43:25 +00:00
|
|
|
}
|
1999-02-20 11:18:00 +00:00
|
|
|
default:
|
2002-10-21 02:51:56 +00:00
|
|
|
if_printf(ifp, "can't handle af%d\n", dst->sa_family);
|
1999-02-20 11:18:00 +00:00
|
|
|
senderr(EAFNOSUPPORT);
|
2001-03-18 05:43:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-15 17:54:49 +00:00
|
|
|
/*
|
|
|
|
* Add LLC header.
|
|
|
|
*/
|
2001-03-18 05:43:25 +00:00
|
|
|
if (snap_type != 0) {
|
|
|
|
struct llc *l;
|
2012-12-05 08:04:20 +00:00
|
|
|
M_PREPEND(m, LLC_SNAPFRAMELEN, M_NOWAIT);
|
2016-04-15 17:30:33 +00:00
|
|
|
if (m == NULL)
|
2001-03-18 05:43:25 +00:00
|
|
|
senderr(ENOBUFS);
|
|
|
|
l = mtod(m, struct llc *);
|
2003-03-15 20:35:19 +00:00
|
|
|
l->llc_control = LLC_UI;
|
2003-03-15 17:54:49 +00:00
|
|
|
l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
|
2003-03-15 15:35:25 +00:00
|
|
|
l->llc_snap.org_code[0] =
|
|
|
|
l->llc_snap.org_code[1] =
|
|
|
|
l->llc_snap.org_code[2] = 0;
|
2003-03-15 17:54:49 +00:00
|
|
|
l->llc_snap.ether_type = htons(snap_type);
|
1999-02-20 11:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add local net header. If no space in first mbuf,
|
|
|
|
* allocate another.
|
|
|
|
*/
|
2012-12-05 08:04:20 +00:00
|
|
|
M_PREPEND(m, ISO88025_HDR_LEN + rif_len, M_NOWAIT);
|
2016-04-15 17:30:33 +00:00
|
|
|
if (m == NULL)
|
1999-02-20 11:18:00 +00:00
|
|
|
senderr(ENOBUFS);
|
2003-03-15 17:54:49 +00:00
|
|
|
th = mtod(m, struct iso88025_header *);
|
2003-03-15 22:09:29 +00:00
|
|
|
bcopy((caddr_t)edst, (caddr_t)&gen_th.iso88025_dhost, ISO88025_ADDR_LEN);
|
2001-03-18 05:43:25 +00:00
|
|
|
|
1999-03-10 10:11:43 +00:00
|
|
|
/* Copy as much of the generic header as is needed into the mbuf */
|
|
|
|
memcpy(th, &gen_th, ISO88025_HDR_LEN + rif_len);
|
|
|
|
|
1999-02-20 11:18:00 +00:00
|
|
|
/*
|
|
|
|
* If a simplex interface, and the packet is being sent to our
|
|
|
|
* Ethernet address or a broadcast address, loopback a copy.
|
|
|
|
* XXX To make a simplex device behave exactly like a duplex
|
|
|
|
* device, we should copy in the case of sending to our own
|
|
|
|
* ethernet address (thus letting the original actually appear
|
|
|
|
* on the wire). However, we don't do that here for security
|
|
|
|
* reasons and compatibility with the original behavior.
|
|
|
|
*/
|
2001-03-18 05:43:25 +00:00
|
|
|
if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
|
1999-02-20 11:18:00 +00:00
|
|
|
if ((m->m_flags & M_BCAST) || (loop_copy > 0)) {
|
2001-03-18 05:43:25 +00:00
|
|
|
struct mbuf *n;
|
2016-09-15 07:41:48 +00:00
|
|
|
n = m_copym(m, 0, M_COPYALL, M_NOWAIT);
|
2003-03-15 19:37:44 +00:00
|
|
|
(void) if_simloop(ifp, n, dst->sa_family,
|
2001-03-18 05:43:25 +00:00
|
|
|
ISO88025_HDR_LEN);
|
2003-03-15 19:37:44 +00:00
|
|
|
} else if (bcmp(th->iso88025_dhost, th->iso88025_shost,
|
2001-03-18 05:43:25 +00:00
|
|
|
ETHER_ADDR_LEN) == 0) {
|
2003-03-15 19:37:44 +00:00
|
|
|
(void) if_simloop(ifp, m, dst->sa_family,
|
|
|
|
ISO88025_HDR_LEN);
|
|
|
|
return(0); /* XXX */
|
|
|
|
}
|
1999-02-20 11:18:00 +00:00
|
|
|
}
|
|
|
|
|
2004-06-15 23:57:42 +00:00
|
|
|
IFQ_HANDOFF_ADJ(ifp, m, ISO88025_HDR_LEN + LLC_SNAPFRAMELEN, error);
|
|
|
|
if (error) {
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
printf("iso88025_output: packet dropped QFULL.\n");
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
1999-02-20 11:18:00 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
bad:
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
1999-02-20 11:18:00 +00:00
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ISO 88025 de-encapsulation
|
|
|
|
*/
|
|
|
|
void
|
2003-03-15 23:08:40 +00:00
|
|
|
iso88025_input(ifp, m)
|
2001-03-18 05:43:25 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct mbuf *m;
|
1999-02-20 11:18:00 +00:00
|
|
|
{
|
2003-03-15 23:08:40 +00:00
|
|
|
struct iso88025_header *th;
|
2003-03-03 00:21:52 +00:00
|
|
|
struct llc *l;
|
2003-03-15 23:08:40 +00:00
|
|
|
int isr;
|
|
|
|
int mac_hdr_len;
|
|
|
|
|
2003-03-16 00:17:44 +00:00
|
|
|
/*
|
|
|
|
* Do consistency checks to verify assumptions
|
|
|
|
* made by code past this point.
|
|
|
|
*/
|
|
|
|
if ((m->m_flags & M_PKTHDR) == 0) {
|
|
|
|
if_printf(ifp, "discard frame w/o packet header\n");
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
|
2003-03-16 00:17:44 +00:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m->m_pkthdr.rcvif == NULL) {
|
|
|
|
if_printf(ifp, "discard frame w/o interface pointer\n");
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
|
2003-03-16 00:17:44 +00:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-15 23:08:40 +00:00
|
|
|
m = m_pullup(m, ISO88025_HDR_LEN);
|
|
|
|
if (m == NULL) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
|
2003-03-15 23:08:40 +00:00
|
|
|
goto dropanyway;
|
|
|
|
}
|
|
|
|
th = mtod(m, struct iso88025_header *);
|
1999-02-20 11:18:00 +00:00
|
|
|
|
2003-03-15 21:42:19 +00:00
|
|
|
/*
|
|
|
|
* Discard packet if interface is not up.
|
|
|
|
*/
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING)))
|
2003-03-15 21:42:19 +00:00
|
|
|
goto dropanyway;
|
2000-03-19 21:34:39 +00:00
|
|
|
|
2003-03-16 00:17:44 +00:00
|
|
|
/*
|
|
|
|
* Give bpf a chance at the packet.
|
|
|
|
*/
|
|
|
|
BPF_MTAP(ifp, m);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface marked for monitoring; discard packet.
|
|
|
|
*/
|
|
|
|
if (ifp->if_flags & IFF_MONITOR) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-15 21:30:00 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
mac_ifnet_create_mbuf(ifp, m);
|
2003-03-15 21:30:00 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-15 21:42:19 +00:00
|
|
|
/*
|
|
|
|
* Update interface statistics.
|
|
|
|
*/
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_IBYTES, m->m_pkthdr.len);
|
2003-03-15 21:42:19 +00:00
|
|
|
getmicrotime(&ifp->if_lastchange);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discard non local unicast packets when interface
|
|
|
|
* is in promiscuous mode.
|
|
|
|
*/
|
|
|
|
if ((ifp->if_flags & IFF_PROMISC) &&
|
|
|
|
((th->iso88025_dhost[0] & 1) == 0) &&
|
2005-11-11 16:04:59 +00:00
|
|
|
(bcmp(IF_LLADDR(ifp), (caddr_t) th->iso88025_dhost,
|
2003-03-15 21:42:19 +00:00
|
|
|
ISO88025_ADDR_LEN) != 0))
|
|
|
|
goto dropanyway;
|
2001-03-18 05:43:25 +00:00
|
|
|
|
2003-03-15 20:33:30 +00:00
|
|
|
/*
|
|
|
|
* Set mbuf flags for bcast/mcast.
|
|
|
|
*/
|
1999-02-20 11:18:00 +00:00
|
|
|
if (th->iso88025_dhost[0] & 1) {
|
2004-03-13 05:46:26 +00:00
|
|
|
if (bcmp(iso88025_broadcastaddr, th->iso88025_dhost,
|
|
|
|
ISO88025_ADDR_LEN) == 0)
|
1999-02-20 11:18:00 +00:00
|
|
|
m->m_flags |= M_BCAST;
|
|
|
|
else
|
|
|
|
m->m_flags |= M_MCAST;
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_IMCASTS, 1);
|
2003-03-15 17:54:49 +00:00
|
|
|
}
|
1999-02-20 11:18:00 +00:00
|
|
|
|
2003-03-15 23:08:40 +00:00
|
|
|
mac_hdr_len = ISO88025_HDR_LEN;
|
|
|
|
/* Check for source routing info */
|
|
|
|
if (th->iso88025_shost[0] & TR_RII)
|
|
|
|
mac_hdr_len += TR_RCF_RIFLEN(th->rcf);
|
|
|
|
|
|
|
|
/* Strip off ISO88025 header. */
|
|
|
|
m_adj(m, mac_hdr_len);
|
|
|
|
|
|
|
|
m = m_pullup(m, LLC_SNAPFRAMELEN);
|
|
|
|
if (m == 0) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
|
2003-03-15 23:08:40 +00:00
|
|
|
goto dropanyway;
|
|
|
|
}
|
2001-03-18 05:43:25 +00:00
|
|
|
l = mtod(m, struct llc *);
|
|
|
|
|
|
|
|
switch (l->llc_dsap) {
|
|
|
|
case LLC_SNAP_LSAP: {
|
|
|
|
u_int16_t type;
|
|
|
|
if ((l->llc_control != LLC_UI) ||
|
2003-03-15 21:59:11 +00:00
|
|
|
(l->llc_ssap != LLC_SNAP_LSAP)) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
|
2001-03-18 05:43:25 +00:00
|
|
|
goto dropanyway;
|
2003-03-15 21:59:11 +00:00
|
|
|
}
|
2001-03-18 05:43:25 +00:00
|
|
|
|
2003-03-15 15:35:25 +00:00
|
|
|
if (l->llc_snap.org_code[0] != 0 ||
|
|
|
|
l->llc_snap.org_code[1] != 0 ||
|
2003-03-15 22:25:06 +00:00
|
|
|
l->llc_snap.org_code[2] != 0) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
|
2001-03-18 05:43:25 +00:00
|
|
|
goto dropanyway;
|
2003-03-15 22:25:06 +00:00
|
|
|
}
|
2001-03-18 05:43:25 +00:00
|
|
|
|
2003-03-15 15:35:25 +00:00
|
|
|
type = ntohs(l->llc_snap.ether_type);
|
2003-03-03 05:04:57 +00:00
|
|
|
m_adj(m, LLC_SNAPFRAMELEN);
|
2001-03-18 05:43:25 +00:00
|
|
|
switch (type) {
|
|
|
|
#ifdef INET
|
|
|
|
case ETHERTYPE_IP:
|
|
|
|
th->iso88025_shost[0] &= ~(TR_RII);
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = NETISR_IP;
|
2001-03-18 05:43:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETHERTYPE_ARP:
|
2001-06-15 21:00:32 +00:00
|
|
|
if (ifp->if_flags & IFF_NOARP)
|
|
|
|
goto dropanyway;
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = NETISR_ARP;
|
2001-03-18 05:43:25 +00:00
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case ETHERTYPE_IPV6:
|
|
|
|
th->iso88025_shost[0] &= ~(TR_RII);
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = NETISR_IPV6;
|
2001-03-18 05:43:25 +00:00
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
default:
|
|
|
|
printf("iso88025_input: unexpected llc_snap ether_type 0x%02x\n", type);
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
|
2003-03-15 21:59:11 +00:00
|
|
|
goto dropanyway;
|
2001-03-18 05:43:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-03-15 22:37:11 +00:00
|
|
|
#ifdef ISO
|
2001-03-18 05:43:25 +00:00
|
|
|
case LLC_ISO_LSAP:
|
|
|
|
switch (l->llc_control) {
|
|
|
|
case LLC_UI:
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
|
2001-03-18 05:43:25 +00:00
|
|
|
goto dropanyway;
|
|
|
|
break;
|
|
|
|
case LLC_XID:
|
|
|
|
case LLC_XID_P:
|
|
|
|
if(m->m_len < ISO88025_ADDR_LEN)
|
|
|
|
goto dropanyway;
|
|
|
|
l->llc_window = 0;
|
|
|
|
l->llc_fid = 9;
|
|
|
|
l->llc_class = 1;
|
|
|
|
l->llc_dsap = l->llc_ssap = 0;
|
|
|
|
/* Fall through to */
|
|
|
|
case LLC_TEST:
|
|
|
|
case LLC_TEST_P:
|
|
|
|
{
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct iso88025_sockaddr_data *th2;
|
|
|
|
int i;
|
2003-03-15 22:37:11 +00:00
|
|
|
u_char c;
|
|
|
|
|
|
|
|
c = l->llc_dsap;
|
2001-03-18 05:43:25 +00:00
|
|
|
|
|
|
|
if (th->iso88025_shost[0] & TR_RII) { /* XXX */
|
|
|
|
printf("iso88025_input: dropping source routed LLC_TEST\n");
|
2003-03-15 21:59:11 +00:00
|
|
|
goto dropanyway;
|
2001-03-18 05:43:25 +00:00
|
|
|
}
|
|
|
|
l->llc_dsap = l->llc_ssap;
|
|
|
|
l->llc_ssap = c;
|
|
|
|
if (m->m_flags & (M_BCAST | M_MCAST))
|
2005-11-11 16:04:59 +00:00
|
|
|
bcopy((caddr_t)IF_LLADDR(ifp),
|
2003-03-15 20:33:30 +00:00
|
|
|
(caddr_t)th->iso88025_dhost,
|
2001-03-18 05:43:25 +00:00
|
|
|
ISO88025_ADDR_LEN);
|
|
|
|
sa.sa_family = AF_UNSPEC;
|
|
|
|
sa.sa_len = sizeof(sa);
|
|
|
|
th2 = (struct iso88025_sockaddr_data *)sa.sa_data;
|
|
|
|
for (i = 0; i < ISO88025_ADDR_LEN; i++) {
|
|
|
|
th2->ether_shost[i] = c = th->iso88025_dhost[i];
|
|
|
|
th2->ether_dhost[i] = th->iso88025_dhost[i] =
|
|
|
|
th->iso88025_shost[i];
|
|
|
|
th->iso88025_shost[i] = c;
|
|
|
|
}
|
|
|
|
th2->ac = TR_AC;
|
|
|
|
th2->fc = TR_LLC_FRAME;
|
|
|
|
ifp->if_output(ifp, m, &sa, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
printf("iso88025_input: unexpected llc control 0x%02x\n", l->llc_control);
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
|
2003-03-15 21:59:11 +00:00
|
|
|
goto dropanyway;
|
2003-03-15 22:25:06 +00:00
|
|
|
break;
|
2001-03-18 05:43:25 +00:00
|
|
|
}
|
1999-02-20 11:18:00 +00:00
|
|
|
break;
|
2003-03-15 22:37:11 +00:00
|
|
|
#endif /* ISO */
|
1999-02-20 11:18:00 +00:00
|
|
|
default:
|
2001-03-18 05:43:25 +00:00
|
|
|
printf("iso88025_input: unknown dsap 0x%x\n", l->llc_dsap);
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
|
2003-03-15 21:59:11 +00:00
|
|
|
goto dropanyway;
|
2003-03-15 22:25:06 +00:00
|
|
|
break;
|
1999-02-20 11:18:00 +00:00
|
|
|
}
|
2003-03-15 17:54:49 +00:00
|
|
|
|
2011-07-03 16:08:38 +00:00
|
|
|
M_SETFIB(m, ifp->if_fib);
|
2003-03-04 23:19:55 +00:00
|
|
|
netisr_dispatch(isr, m);
|
2003-03-15 17:54:49 +00:00
|
|
|
return;
|
2003-03-15 21:59:11 +00:00
|
|
|
|
|
|
|
dropanyway:
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
|
2003-03-15 21:59:11 +00:00
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
1999-02-20 11:18:00 +00:00
|
|
|
}
|
2003-03-15 15:38:02 +00:00
|
|
|
|
2003-03-15 16:49:08 +00:00
|
|
|
static int
|
|
|
|
iso88025_resolvemulti (ifp, llsa, sa)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct sockaddr **llsa;
|
|
|
|
struct sockaddr *sa;
|
|
|
|
{
|
|
|
|
struct sockaddr_dl *sdl;
|
2008-11-06 09:18:29 +00:00
|
|
|
#ifdef INET
|
2003-03-15 16:49:08 +00:00
|
|
|
struct sockaddr_in *sin;
|
2008-11-06 09:18:29 +00:00
|
|
|
#endif
|
2003-03-15 16:49:08 +00:00
|
|
|
#ifdef INET6
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
#endif
|
|
|
|
u_char *e_addr;
|
|
|
|
|
|
|
|
switch(sa->sa_family) {
|
|
|
|
case AF_LINK:
|
|
|
|
/*
|
|
|
|
* No mapping needed. Just check that it's a valid MC address.
|
|
|
|
*/
|
|
|
|
sdl = (struct sockaddr_dl *)sa;
|
|
|
|
e_addr = LLADDR(sdl);
|
|
|
|
if ((e_addr[0] & 1) != 1) {
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
2016-04-15 17:30:33 +00:00
|
|
|
*llsa = NULL;
|
2003-03-15 16:49:08 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
sin = (struct sockaddr_in *)sa;
|
|
|
|
if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
2014-01-18 23:24:51 +00:00
|
|
|
sdl = link_init_sdl(ifp, *llsa, IFT_ISO88025);
|
2003-03-15 16:49:08 +00:00
|
|
|
sdl->sdl_alen = ISO88025_ADDR_LEN;
|
|
|
|
e_addr = LLADDR(sdl);
|
|
|
|
ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
|
|
|
|
*llsa = (struct sockaddr *)sdl;
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
sin6 = (struct sockaddr_in6 *)sa;
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
|
|
|
/*
|
|
|
|
* An IP6 address of 0 means listen to all
|
|
|
|
* of the Ethernet multicast address used for IP6.
|
|
|
|
* (This is used for multicast routers.)
|
|
|
|
*/
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
2016-04-15 17:30:33 +00:00
|
|
|
*llsa = NULL;
|
2003-03-15 16:49:08 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
2014-01-18 23:24:51 +00:00
|
|
|
sdl = link_init_sdl(ifp, *llsa, IFT_ISO88025);
|
2003-03-15 16:49:08 +00:00
|
|
|
sdl->sdl_alen = ISO88025_ADDR_LEN;
|
|
|
|
e_addr = LLADDR(sdl);
|
|
|
|
ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
|
|
|
|
*llsa = (struct sockaddr *)sdl;
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Well, the text isn't quite right, but it's the name
|
|
|
|
* that counts...
|
|
|
|
*/
|
|
|
|
return (EAFNOSUPPORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-03-15 15:38:02 +00:00
|
|
|
static moduledata_t iso88025_mod = {
|
2014-11-07 15:14:10 +00:00
|
|
|
.name = "iso88025",
|
2003-03-15 15:38:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_MODULE(iso88025, iso88025_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
|
|
|
|
MODULE_VERSION(iso88025, 1);
|