1999-12-13 16:24:22 +00:00
|
|
|
/*-
|
2000-09-30 14:33:53 +00:00
|
|
|
* Copyright (c) 1999, 2000 Boris Popov
|
1999-12-13 16:24:22 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_ipx.h"
|
2000-01-23 03:35:11 +00:00
|
|
|
#include "opt_ef.h"
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
#include <sys/vimage.h>
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_llc.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPX
|
|
|
|
#include <netipx/ipx.h>
|
|
|
|
#include <netipx/ipx_if.h>
|
|
|
|
#endif
|
|
|
|
|
2005-03-06 23:03:58 +00:00
|
|
|
/* If none of the supported layers is enabled explicitly enable them all */
|
|
|
|
#if !defined(ETHER_II) && !defined(ETHER_8023) && !defined(ETHER_8022) && \
|
|
|
|
!defined(ETHER_SNAP)
|
|
|
|
#define ETHER_II 1
|
|
|
|
#define ETHER_8023 1
|
|
|
|
#define ETHER_8022 1
|
|
|
|
#define ETHER_SNAP 1
|
|
|
|
#endif
|
|
|
|
|
1999-12-13 16:24:22 +00:00
|
|
|
/* internal frame types */
|
|
|
|
#define ETHER_FT_EII 0 /* Ethernet_II - default */
|
|
|
|
#define ETHER_FT_8023 1 /* 802.3 (Novell) */
|
|
|
|
#define ETHER_FT_8022 2 /* 802.2 */
|
|
|
|
#define ETHER_FT_SNAP 3 /* SNAP */
|
|
|
|
#define EF_NFT 4 /* total number of frame types */
|
|
|
|
|
|
|
|
#ifdef EF_DEBUG
|
2001-12-10 08:09:49 +00:00
|
|
|
#define EFDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
|
1999-12-13 16:24:22 +00:00
|
|
|
#else
|
|
|
|
#define EFDEBUG(format, args...)
|
|
|
|
#endif
|
|
|
|
|
2001-12-10 08:09:49 +00:00
|
|
|
#define EFERROR(format, args...) printf("%s: "format, __func__ ,## args)
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
struct efnet {
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ef_ifp;
|
|
|
|
struct ifnet *ef_pifp;
|
2003-10-31 18:32:15 +00:00
|
|
|
int ef_frametype;
|
1999-12-13 16:24:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ef_link {
|
2000-05-26 02:09:24 +00:00
|
|
|
SLIST_ENTRY(ef_link) el_next;
|
1999-12-13 16:24:22 +00:00
|
|
|
struct ifnet *el_ifp; /* raw device for this clones */
|
|
|
|
struct efnet *el_units[EF_NFT]; /* our clones */
|
|
|
|
};
|
|
|
|
|
2000-05-26 02:09:24 +00:00
|
|
|
static SLIST_HEAD(ef_link_head, ef_link) efdev = {NULL};
|
1999-12-13 16:24:22 +00:00
|
|
|
static int efcount;
|
|
|
|
|
|
|
|
extern int (*ef_inputp)(struct ifnet*, struct ether_header *eh, struct mbuf *m);
|
2000-04-27 10:13:52 +00:00
|
|
|
extern int (*ef_outputp)(struct ifnet *ifp, struct mbuf **mp,
|
2000-09-30 14:33:53 +00:00
|
|
|
struct sockaddr *dst, short *tp, int *hlen);
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
static void ef_reset (struct ifnet *);
|
|
|
|
*/
|
|
|
|
static int ef_attach(struct efnet *sc);
|
|
|
|
static int ef_detach(struct efnet *sc);
|
|
|
|
static void ef_init(void *);
|
|
|
|
static int ef_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void ef_start(struct ifnet *);
|
|
|
|
static int ef_input(struct ifnet*, struct ether_header *, struct mbuf *);
|
2000-04-27 10:13:52 +00:00
|
|
|
static int ef_output(struct ifnet *ifp, struct mbuf **mp,
|
2000-09-30 14:33:53 +00:00
|
|
|
struct sockaddr *dst, short *tp, int *hlen);
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
static int ef_load(void);
|
|
|
|
static int ef_unload(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install the interface, most of structure initialization done in ef_clone()
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ef_attach(struct efnet *sc)
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ef_ifp;
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
ifp->if_start = ef_start;
|
|
|
|
ifp->if_watchdog = NULL;
|
|
|
|
ifp->if_init = ef_init;
|
|
|
|
ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
|
|
|
|
/*
|
|
|
|
* Attach the interface
|
|
|
|
*/
|
2005-11-11 16:04:59 +00:00
|
|
|
ether_ifattach(ifp, IF_LLADDR(sc->ef_pifp));
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
ifp->if_resolvemulti = 0;
|
|
|
|
ifp->if_type = IFT_XETHER;
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
1999-12-13 16:24:22 +00:00
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
EFDEBUG("%s: attached\n", ifp->if_xname);
|
1999-12-13 16:24:22 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is for _testing_only_, just removes interface from interfaces list
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ef_detach(struct efnet *sc)
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ef_ifp;
|
1999-12-13 16:24:22 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ether_ifdetach(ifp);
|
|
|
|
if_free(ifp);
|
|
|
|
|
1999-12-13 16:24:22 +00:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ef_init(void *foo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ef_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|
|
|
{
|
2003-10-31 18:32:15 +00:00
|
|
|
struct efnet *sc = ifp->if_softc;
|
1999-12-13 16:24:22 +00:00
|
|
|
struct ifaddr *ifa = (struct ifaddr*)data;
|
|
|
|
int s, error;
|
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
EFDEBUG("IOCTL %ld for %s\n", cmd, ifp->if_xname);
|
1999-12-13 16:24:22 +00:00
|
|
|
error = 0;
|
|
|
|
s = splimp();
|
|
|
|
switch (cmd) {
|
2002-11-15 00:00:15 +00:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
error = 0;
|
|
|
|
break;
|
1999-12-13 16:24:22 +00:00
|
|
|
case SIOCSIFADDR:
|
2003-10-31 18:32:15 +00:00
|
|
|
if (sc->ef_frametype == ETHER_FT_8023 &&
|
1999-12-13 16:24:22 +00:00
|
|
|
ifa->ifa_addr->sa_family != AF_IPX) {
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
/* FALL THROUGH */
|
2002-11-15 00:00:15 +00:00
|
|
|
default:
|
1999-12-13 16:24:22 +00:00
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently packet prepared in the ether_output(), but this can be a better
|
|
|
|
* place.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ef_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct efnet *sc = (struct efnet*)ifp->if_softc;
|
|
|
|
struct ifnet *p;
|
|
|
|
struct mbuf *m;
|
2004-06-15 23:57:42 +00:00
|
|
|
int error;
|
1999-12-13 16:24:22 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2005-06-10 16:49:24 +00:00
|
|
|
p = sc->ef_pifp;
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
EFDEBUG("\n");
|
|
|
|
for (;;) {
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
if (m == 0)
|
|
|
|
break;
|
2002-11-15 00:00:15 +00:00
|
|
|
BPF_MTAP(ifp, m);
|
2004-06-15 23:57:42 +00:00
|
|
|
IFQ_HANDOFF(p, m, error);
|
|
|
|
if (error) {
|
2000-04-27 10:13:52 +00:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
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
|
|
|
ifp->if_opackets++;
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1999-12-13 16:24:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inline functions do not put additional overhead to procedure call or
|
|
|
|
* parameter passing but simplify the code
|
|
|
|
*/
|
|
|
|
static int __inline
|
2003-03-04 23:19:55 +00:00
|
|
|
ef_inputEII(struct mbuf *m, struct ether_header *eh, u_short ether_type)
|
1999-12-13 16:24:22 +00:00
|
|
|
{
|
2003-03-04 23:19:55 +00:00
|
|
|
int isr;
|
|
|
|
|
1999-12-13 16:24:22 +00:00
|
|
|
switch(ether_type) {
|
|
|
|
#ifdef IPX
|
2003-03-04 23:19:55 +00:00
|
|
|
case ETHERTYPE_IPX:
|
|
|
|
isr = NETISR_IPX;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET
|
2003-03-04 23:19:55 +00:00
|
|
|
case ETHERTYPE_IP:
|
2006-01-18 14:24:39 +00:00
|
|
|
if ((m = ip_fastforward(m)) == NULL)
|
2003-03-04 23:19:55 +00:00
|
|
|
return (0);
|
|
|
|
isr = NETISR_IP;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
|
2003-03-04 23:19:55 +00:00
|
|
|
case ETHERTYPE_ARP:
|
|
|
|
isr = NETISR_ARP;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2003-03-04 23:19:55 +00:00
|
|
|
default:
|
|
|
|
return (EPROTONOSUPPORT);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2003-03-04 23:19:55 +00:00
|
|
|
netisr_dispatch(isr, m);
|
|
|
|
return (0);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __inline
|
|
|
|
ef_inputSNAP(struct mbuf *m, struct ether_header *eh, struct llc* l,
|
2003-03-04 23:19:55 +00:00
|
|
|
u_short ether_type)
|
1999-12-13 16:24:22 +00:00
|
|
|
{
|
2003-03-04 23:19:55 +00:00
|
|
|
int isr;
|
|
|
|
|
1999-12-13 16:24:22 +00:00
|
|
|
switch(ether_type) {
|
|
|
|
#ifdef IPX
|
2003-03-04 23:19:55 +00:00
|
|
|
case ETHERTYPE_IPX:
|
1999-12-13 16:24:22 +00:00
|
|
|
m_adj(m, 8);
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = NETISR_IPX;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2003-03-04 23:19:55 +00:00
|
|
|
default:
|
|
|
|
return (EPROTONOSUPPORT);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2003-03-04 23:19:55 +00:00
|
|
|
netisr_dispatch(isr, m);
|
|
|
|
return (0);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __inline
|
|
|
|
ef_input8022(struct mbuf *m, struct ether_header *eh, struct llc* l,
|
2003-03-04 23:19:55 +00:00
|
|
|
u_short ether_type)
|
1999-12-13 16:24:22 +00:00
|
|
|
{
|
2003-03-04 23:19:55 +00:00
|
|
|
int isr;
|
|
|
|
|
1999-12-13 16:24:22 +00:00
|
|
|
switch(ether_type) {
|
|
|
|
#ifdef IPX
|
2003-03-04 23:19:55 +00:00
|
|
|
case 0xe0:
|
1999-12-13 16:24:22 +00:00
|
|
|
m_adj(m, 3);
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = NETISR_IPX;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2003-03-04 23:19:55 +00:00
|
|
|
default:
|
|
|
|
return (EPROTONOSUPPORT);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2003-03-04 23:19:55 +00:00
|
|
|
netisr_dispatch(isr, m);
|
|
|
|
return (0);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2003-03-04 23:19:55 +00:00
|
|
|
|
1999-12-13 16:24:22 +00:00
|
|
|
/*
|
|
|
|
* Called from ether_input()
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ef_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m)
|
|
|
|
{
|
|
|
|
u_short ether_type;
|
2001-02-01 08:34:38 +00:00
|
|
|
int ft = -1;
|
1999-12-13 16:24:22 +00:00
|
|
|
struct efnet *efp;
|
|
|
|
struct ifnet *eifp;
|
|
|
|
struct llc *l;
|
|
|
|
struct ef_link *efl;
|
2003-03-04 23:19:55 +00:00
|
|
|
int isr;
|
1999-12-13 16:24:22 +00:00
|
|
|
|
|
|
|
ether_type = ntohs(eh->ether_type);
|
2004-07-28 06:48:36 +00:00
|
|
|
l = NULL;
|
1999-12-13 16:24:22 +00:00
|
|
|
if (ether_type < ETHERMTU) {
|
|
|
|
l = mtod(m, struct llc*);
|
|
|
|
if (l->llc_dsap == 0xff && l->llc_ssap == 0xff) {
|
|
|
|
/*
|
|
|
|
* Novell's "802.3" frame
|
|
|
|
*/
|
|
|
|
ft = ETHER_FT_8023;
|
|
|
|
} else if (l->llc_dsap == 0xaa && l->llc_ssap == 0xaa) {
|
|
|
|
/*
|
|
|
|
* 802.2/SNAP
|
|
|
|
*/
|
|
|
|
ft = ETHER_FT_SNAP;
|
|
|
|
ether_type = ntohs(l->llc_un.type_snap.ether_type);
|
|
|
|
} else if (l->llc_dsap == l->llc_ssap) {
|
|
|
|
/*
|
|
|
|
* 802.3/802.2
|
|
|
|
*/
|
|
|
|
ft = ETHER_FT_8022;
|
|
|
|
ether_type = l->llc_ssap;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ft = ETHER_FT_EII;
|
|
|
|
|
|
|
|
if (ft == -1) {
|
|
|
|
EFDEBUG("Unrecognised ether_type %x\n", ether_type);
|
2000-04-27 10:13:52 +00:00
|
|
|
return EPROTONOSUPPORT;
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if interface configured for the given frame
|
|
|
|
*/
|
|
|
|
efp = NULL;
|
|
|
|
SLIST_FOREACH(efl, &efdev, el_next) {
|
|
|
|
if (efl->el_ifp == ifp) {
|
|
|
|
efp = efl->el_units[ft];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (efp == NULL) {
|
|
|
|
EFDEBUG("Can't find if for %d\n", ft);
|
2000-04-27 10:13:52 +00:00
|
|
|
return EPROTONOSUPPORT;
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2005-06-10 16:49:24 +00:00
|
|
|
eifp = efp->ef_ifp;
|
1999-12-13 16:24:22 +00:00
|
|
|
if ((eifp->if_flags & IFF_UP) == 0)
|
2000-04-27 10:13:52 +00:00
|
|
|
return EPROTONOSUPPORT;
|
1999-12-13 16:24:22 +00:00
|
|
|
eifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh);
|
|
|
|
m->m_pkthdr.rcvif = eifp;
|
|
|
|
|
2003-12-28 03:56:00 +00:00
|
|
|
BPF_MTAP2(eifp, eh, ETHER_HDR_LEN, m);
|
1999-12-13 16:24:22 +00:00
|
|
|
/*
|
|
|
|
* Now we ready to adjust mbufs and pass them to protocol intr's
|
|
|
|
*/
|
|
|
|
switch(ft) {
|
2003-03-04 23:19:55 +00:00
|
|
|
case ETHER_FT_EII:
|
|
|
|
return (ef_inputEII(m, eh, ether_type));
|
1999-12-13 16:24:22 +00:00
|
|
|
#ifdef IPX
|
2003-03-04 23:19:55 +00:00
|
|
|
case ETHER_FT_8023: /* only IPX can be here */
|
|
|
|
isr = NETISR_IPX;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2003-03-04 23:19:55 +00:00
|
|
|
case ETHER_FT_SNAP:
|
|
|
|
return (ef_inputSNAP(m, eh, l, ether_type));
|
|
|
|
case ETHER_FT_8022:
|
|
|
|
return (ef_input8022(m, eh, l, ether_type));
|
|
|
|
default:
|
1999-12-13 16:24:22 +00:00
|
|
|
EFDEBUG("No support for frame %d and proto %04x\n",
|
|
|
|
ft, ether_type);
|
2003-03-04 23:19:55 +00:00
|
|
|
return (EPROTONOSUPPORT);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2003-03-04 23:19:55 +00:00
|
|
|
netisr_dispatch(isr, m);
|
|
|
|
return (0);
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-09-30 14:33:53 +00:00
|
|
|
ef_output(struct ifnet *ifp, struct mbuf **mp, struct sockaddr *dst, short *tp,
|
|
|
|
int *hlen)
|
1999-12-13 16:24:22 +00:00
|
|
|
{
|
2003-10-31 18:32:15 +00:00
|
|
|
struct efnet *sc = (struct efnet*)ifp->if_softc;
|
2000-04-27 10:13:52 +00:00
|
|
|
struct mbuf *m = *mp;
|
1999-12-13 16:24:22 +00:00
|
|
|
u_char *cp;
|
|
|
|
short type;
|
|
|
|
|
|
|
|
if (ifp->if_type != IFT_XETHER)
|
2000-04-27 10:13:52 +00:00
|
|
|
return ENETDOWN;
|
2003-10-31 18:32:15 +00:00
|
|
|
switch (sc->ef_frametype) {
|
1999-12-13 16:24:22 +00:00
|
|
|
case ETHER_FT_EII:
|
|
|
|
#ifdef IPX
|
|
|
|
type = htons(ETHERTYPE_IPX);
|
|
|
|
#else
|
2000-04-27 10:13:52 +00:00
|
|
|
return EPFNOSUPPORT;
|
1999-12-13 16:24:22 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case ETHER_FT_8023:
|
|
|
|
type = htons(m->m_pkthdr.len);
|
|
|
|
break;
|
|
|
|
case ETHER_FT_8022:
|
2008-03-25 09:39:02 +00:00
|
|
|
M_PREPEND(m, ETHER_HDR_LEN + 3, M_WAIT);
|
2000-04-27 10:13:52 +00:00
|
|
|
/*
|
|
|
|
* Ensure that ethernet header and next three bytes
|
|
|
|
* will fit into single mbuf
|
|
|
|
*/
|
|
|
|
m = m_pullup(m, ETHER_HDR_LEN + 3);
|
|
|
|
if (m == NULL) {
|
|
|
|
*mp = NULL;
|
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
m_adj(m, ETHER_HDR_LEN);
|
1999-12-13 16:24:22 +00:00
|
|
|
type = htons(m->m_pkthdr.len);
|
|
|
|
cp = mtod(m, u_char *);
|
|
|
|
*cp++ = 0xE0;
|
|
|
|
*cp++ = 0xE0;
|
|
|
|
*cp++ = 0x03;
|
2000-09-30 14:33:53 +00:00
|
|
|
*hlen += 3;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
case ETHER_FT_SNAP:
|
2008-03-25 09:39:02 +00:00
|
|
|
M_PREPEND(m, 8, M_WAIT);
|
1999-12-13 16:24:22 +00:00
|
|
|
type = htons(m->m_pkthdr.len);
|
|
|
|
cp = mtod(m, u_char *);
|
|
|
|
bcopy("\xAA\xAA\x03\x00\x00\x00\x81\x37", cp, 8);
|
2000-09-30 14:33:53 +00:00
|
|
|
*hlen += 8;
|
1999-12-13 16:24:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-04-27 10:13:52 +00:00
|
|
|
return EPFNOSUPPORT;
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
2000-04-27 10:13:52 +00:00
|
|
|
*mp = m;
|
1999-12-13 16:24:22 +00:00
|
|
|
*tp = type;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create clone from the given interface
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ef_clone(struct ef_link *efl, int ft)
|
|
|
|
{
|
|
|
|
struct efnet *efp;
|
|
|
|
struct ifnet *eifp;
|
|
|
|
struct ifnet *ifp = efl->el_ifp;
|
|
|
|
|
2000-12-08 21:51:06 +00:00
|
|
|
efp = (struct efnet*)malloc(sizeof(struct efnet), M_IFADDR,
|
2003-02-19 05:47:46 +00:00
|
|
|
M_WAITOK | M_ZERO);
|
1999-12-13 16:24:22 +00:00
|
|
|
if (efp == NULL)
|
|
|
|
return ENOMEM;
|
2005-06-10 16:49:24 +00:00
|
|
|
efp->ef_pifp = ifp;
|
2003-10-31 18:32:15 +00:00
|
|
|
efp->ef_frametype = ft;
|
2005-06-10 16:49:24 +00:00
|
|
|
eifp = efp->ef_ifp = if_alloc(IFT_ETHER);
|
2006-01-13 23:24:09 +00:00
|
|
|
if (eifp == NULL) {
|
|
|
|
free(efp, M_IFADDR);
|
2005-06-10 16:49:24 +00:00
|
|
|
return (ENOSPC);
|
2006-01-13 23:24:09 +00:00
|
|
|
}
|
2003-10-31 18:32:15 +00:00
|
|
|
snprintf(eifp->if_xname, IFNAMSIZ,
|
|
|
|
"%sf%d", ifp->if_xname, efp->ef_frametype);
|
|
|
|
eifp->if_dname = "ef";
|
|
|
|
eifp->if_dunit = IF_DUNIT_NONE;
|
1999-12-13 16:24:22 +00:00
|
|
|
eifp->if_softc = efp;
|
|
|
|
if (ifp->if_ioctl)
|
|
|
|
eifp->if_ioctl = ef_ioctl;
|
|
|
|
efl->el_units[ft] = efp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ef_load(void)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct efnet *efp;
|
2006-01-13 23:20:46 +00:00
|
|
|
struct ef_link *efl = NULL, *efl_temp;
|
1999-12-13 16:24:22 +00:00
|
|
|
int error = 0, d;
|
|
|
|
|
2002-12-22 05:35:03 +00:00
|
|
|
IFNET_RLOCK();
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
|
1999-12-13 16:24:22 +00:00
|
|
|
if (ifp->if_type != IFT_ETHER) continue;
|
2003-10-31 18:32:15 +00:00
|
|
|
EFDEBUG("Found interface %s\n", ifp->if_xname);
|
1999-12-13 16:24:22 +00:00
|
|
|
efl = (struct ef_link*)malloc(sizeof(struct ef_link),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_IFADDR, M_WAITOK | M_ZERO);
|
1999-12-13 16:24:22 +00:00
|
|
|
if (efl == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
efl->el_ifp = ifp;
|
|
|
|
#ifdef ETHER_II
|
|
|
|
error = ef_clone(efl, ETHER_FT_EII);
|
|
|
|
if (error) break;
|
|
|
|
#endif
|
|
|
|
#ifdef ETHER_8023
|
|
|
|
error = ef_clone(efl, ETHER_FT_8023);
|
|
|
|
if (error) break;
|
|
|
|
#endif
|
|
|
|
#ifdef ETHER_8022
|
|
|
|
error = ef_clone(efl, ETHER_FT_8022);
|
|
|
|
if (error) break;
|
|
|
|
#endif
|
|
|
|
#ifdef ETHER_SNAP
|
|
|
|
error = ef_clone(efl, ETHER_FT_SNAP);
|
|
|
|
if (error) break;
|
|
|
|
#endif
|
|
|
|
efcount++;
|
|
|
|
SLIST_INSERT_HEAD(&efdev, efl, el_next);
|
|
|
|
}
|
2002-12-22 05:35:03 +00:00
|
|
|
IFNET_RUNLOCK();
|
1999-12-13 16:24:22 +00:00
|
|
|
if (error) {
|
|
|
|
if (efl)
|
|
|
|
SLIST_INSERT_HEAD(&efdev, efl, el_next);
|
2006-01-13 23:20:46 +00:00
|
|
|
SLIST_FOREACH_SAFE(efl, &efdev, el_next, efl_temp) {
|
1999-12-13 16:24:22 +00:00
|
|
|
for (d = 0; d < EF_NFT; d++)
|
2005-06-10 16:49:24 +00:00
|
|
|
if (efl->el_units[d]) {
|
|
|
|
if (efl->el_units[d]->ef_pifp != NULL)
|
|
|
|
if_free(efl->el_units[d]->ef_pifp);
|
1999-12-13 16:24:22 +00:00
|
|
|
free(efl->el_units[d], M_IFADDR);
|
2005-06-10 16:49:24 +00:00
|
|
|
}
|
1999-12-13 16:24:22 +00:00
|
|
|
free(efl, M_IFADDR);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
SLIST_FOREACH(efl, &efdev, el_next) {
|
|
|
|
for (d = 0; d < EF_NFT; d++) {
|
|
|
|
efp = efl->el_units[d];
|
|
|
|
if (efp)
|
|
|
|
ef_attach(efp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ef_inputp = ef_input;
|
|
|
|
ef_outputp = ef_output;
|
|
|
|
EFDEBUG("Loaded\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ef_unload(void)
|
|
|
|
{
|
|
|
|
struct efnet *efp;
|
|
|
|
struct ef_link *efl;
|
|
|
|
int d;
|
|
|
|
|
|
|
|
ef_inputp = NULL;
|
|
|
|
ef_outputp = NULL;
|
|
|
|
SLIST_FOREACH(efl, &efdev, el_next) {
|
|
|
|
for (d = 0; d < EF_NFT; d++) {
|
|
|
|
efp = efl->el_units[d];
|
|
|
|
if (efp) {
|
|
|
|
ef_detach(efp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EFDEBUG("Unloaded\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
if_ef_modevent(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
switch ((modeventtype_t)type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
return ef_load();
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
return ef_unload();
|
|
|
|
default:
|
2004-07-15 08:26:07 +00:00
|
|
|
return EOPNOTSUPP;
|
1999-12-13 16:24:22 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static moduledata_t if_ef_mod = {
|
|
|
|
"if_ef", if_ef_modevent, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_MODULE(if_ef, if_ef_mod, SI_SUB_PSEUDO, SI_ORDER_MIDDLE);
|