2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2011-01-24 23:35:51 +03:00
|
|
|
// Copyright (C) 2001-2011 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-02-08 00:05:31 +03:00
|
|
|
//
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Peter Grehan (grehan@iprg.nokia.com) coded all of this
|
|
|
|
// NE2000/ether stuff.
|
|
|
|
|
|
|
|
// eth_fbsd.cc - A FreeBSD packet filter implementation of
|
|
|
|
// an ethernet pktmover. There are some problems and limitations
|
|
|
|
// with FreeBSD:
|
|
|
|
// - the source address of the frame is overwritten by
|
|
|
|
// the hosts's source address. This causes problems with
|
|
|
|
// learning bridges - since they cannot determine where
|
|
|
|
// BOCHS 'is', they broadcast the frame to all ports.
|
|
|
|
// - packets cannot be sent from BOCHS to the host
|
|
|
|
// - TCP performance seems to be abysmal; I think this is
|
|
|
|
// a timing problem somewhere.
|
|
|
|
// - I haven't handled the case where multiple frames arrive
|
2008-01-27 01:24:03 +03:00
|
|
|
// in a single BPF read.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// The /dev/bpf* devices need to be set up with the appropriate
|
|
|
|
// permissions for this to work.
|
|
|
|
//
|
|
|
|
// The config line in .bochsrc should look something like:
|
|
|
|
//
|
2001-05-23 23:47:14 +04:00
|
|
|
// ne2k: ioaddr=0x280, irq=9, mac=00:a:b:c:1:2, ethmod=fbsd, ethdev=fxp0
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
|
2002-11-20 22:06:23 +03:00
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
2008-01-27 01:24:03 +03:00
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
2002-11-20 22:06:23 +03:00
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2011-08-16 21:27:27 +04:00
|
|
|
#include "netmod.h"
|
2005-12-10 21:37:35 +03:00
|
|
|
|
2011-02-26 23:10:06 +03:00
|
|
|
#if BX_NETWORKING && BX_NETMOD_FBSD
|
2002-11-19 08:47:45 +03:00
|
|
|
|
2009-04-13 17:33:11 +04:00
|
|
|
#define LOG_THIS netdev->
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-02-26 23:10:06 +03:00
|
|
|
#define BX_ETH_FBSD_LOGGING 0
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
extern "C" {
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/bpf.h>
|
2001-06-27 23:16:01 +04:00
|
|
|
#include <errno.h>
|
2001-04-10 05:04:59 +04:00
|
|
|
};
|
|
|
|
|
2001-11-06 20:14:34 +03:00
|
|
|
#define BX_BPF_POLL 1000 // Poll for a frame every 250 usecs
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#define BX_BPF_INSNSIZ 8 // number of bpf insns
|
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
// template filter for a unicast mac address and all
|
2001-04-10 05:04:59 +04:00
|
|
|
// multicast/broadcast frames
|
|
|
|
static const struct bpf_insn macfilter[] = {
|
2001-11-06 20:14:34 +03:00
|
|
|
BPF_STMT(BPF_LD|BPF_W|BPF_ABS, 2), // A <- P[2:4]
|
|
|
|
BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 0xaaaaaaaa, 0, 2), // if A != 0xaaaaaaa GOTO LABEL-1
|
|
|
|
BPF_STMT(BPF_LD|BPF_H|BPF_ABS, 0), // A <- P[0:2]
|
|
|
|
BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 0x0000aaaa, 2, 0), // if A == 0xaaaa GOTO ACCEPT
|
|
|
|
// LABEL-1
|
|
|
|
BPF_STMT(BPF_LD|BPF_B|BPF_ABS, 0), // A <- P[0:1]
|
|
|
|
BPF_JUMP(BPF_JMP|BPF_JSET|BPF_K, 0x01, 0, 1), // if !(A & 1) GOTO LABEL-REJECT
|
|
|
|
// LABEL-ACCEPT
|
|
|
|
BPF_STMT(BPF_RET, 1514), // Accept packet
|
|
|
|
// LABEL-REJECT
|
|
|
|
BPF_STMT(BPF_RET, 0), // Reject packet
|
2001-04-10 05:04:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// template filter for all frames
|
|
|
|
static const struct bpf_insn promiscfilter[] = {
|
|
|
|
BPF_STMT(BPF_RET, 1514)
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Define the class. This is private to this module
|
|
|
|
//
|
|
|
|
class bx_fbsd_pktmover_c : public eth_pktmover_c {
|
|
|
|
public:
|
2008-01-27 01:24:03 +03:00
|
|
|
bx_fbsd_pktmover_c(const char *netif,
|
2009-04-13 17:33:11 +04:00
|
|
|
const char *macaddr,
|
|
|
|
eth_rx_handler_t rxh,
|
2011-12-17 12:22:33 +04:00
|
|
|
eth_rx_status_t rxstat,
|
2009-04-13 17:33:11 +04:00
|
|
|
bx_devmodel_c *dev, const char *script);
|
2001-04-10 05:04:59 +04:00
|
|
|
void sendpkt(void *buf, unsigned io_len);
|
|
|
|
|
|
|
|
private:
|
|
|
|
char *fbsd_macaddr[6];
|
|
|
|
int bpf_fd;
|
|
|
|
static void rx_timer_handler(void *);
|
|
|
|
void rx_timer(void);
|
|
|
|
int rx_timer_index;
|
|
|
|
struct bpf_insn filter[BX_BPF_INSNSIZ];
|
2001-06-19 20:57:55 +04:00
|
|
|
FILE *ne2klog, *ne2klog_txt;
|
2001-04-10 05:04:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Define the static class that registers the derived pktmover class,
|
|
|
|
// and allocates one on request.
|
|
|
|
//
|
|
|
|
class bx_fbsd_locator_c : public eth_locator_c {
|
|
|
|
public:
|
|
|
|
bx_fbsd_locator_c(void) : eth_locator_c("fbsd") {}
|
|
|
|
protected:
|
2008-01-27 01:24:03 +03:00
|
|
|
eth_pktmover_c *allocate(const char *netif,
|
2009-04-13 17:33:11 +04:00
|
|
|
const char *macaddr,
|
|
|
|
eth_rx_handler_t rxh,
|
2011-12-17 12:22:33 +04:00
|
|
|
eth_rx_status_t rxstat,
|
2009-04-13 17:33:11 +04:00
|
|
|
bx_devmodel_c *dev, const char *script) {
|
2011-12-17 12:22:33 +04:00
|
|
|
return (new bx_fbsd_pktmover_c(netif, macaddr, rxh, rxstat, dev, script));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
} bx_fbsd_match;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Define the methods for the bx_fbsd_pktmover derived class
|
|
|
|
//
|
|
|
|
|
|
|
|
// the constructor
|
|
|
|
//
|
|
|
|
// Open a bpf file descriptor, and attempt to bind to
|
|
|
|
// the specified netif (Replicates libpcap open code)
|
|
|
|
//
|
2008-01-27 01:24:03 +03:00
|
|
|
bx_fbsd_pktmover_c::bx_fbsd_pktmover_c(const char *netif,
|
2009-04-13 17:33:11 +04:00
|
|
|
const char *macaddr,
|
|
|
|
eth_rx_handler_t rxh,
|
2011-12-17 12:22:33 +04:00
|
|
|
eth_rx_stat_t rxstat,
|
2009-04-13 17:33:11 +04:00
|
|
|
bx_devmodel_c *dev,
|
|
|
|
const char *script)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
char device[sizeof "/dev/bpf000"];
|
|
|
|
int tmpfd;
|
|
|
|
int n = 0;
|
|
|
|
struct ifreq ifr;
|
|
|
|
struct bpf_version bv;
|
|
|
|
struct bpf_program bp;
|
|
|
|
u_int v;
|
|
|
|
|
2009-04-13 17:33:11 +04:00
|
|
|
this->netdev = dev;
|
|
|
|
BX_INFO(("freebsd network driver"));
|
2001-04-10 05:04:59 +04:00
|
|
|
memcpy(fbsd_macaddr, macaddr, 6);
|
|
|
|
|
|
|
|
do {
|
|
|
|
(void)sprintf(device, "/dev/bpf%d", n++);
|
|
|
|
this->bpf_fd = open(device, O_RDWR);
|
2009-04-13 17:33:11 +04:00
|
|
|
BX_DEBUG(("tried %s, returned %d (%s)",device,this->bpf_fd,strerror(errno)));
|
|
|
|
if(errno == EACCES)
|
|
|
|
break;
|
2001-06-27 23:16:01 +04:00
|
|
|
} while (this->bpf_fd == -1);
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2001-06-27 23:16:01 +04:00
|
|
|
if (this->bpf_fd == -1) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not open packet filter: %s", strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(this->bpf_fd, BIOCVERSION, (caddr_t)&bv) < 0) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not retrieve bpf version"));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
2001-10-06 21:31:44 +04:00
|
|
|
if (bv.bv_major != BPF_MAJOR_VERSION || bv.bv_minor < BPF_MINOR_VERSION) {
|
|
|
|
BX_PANIC(("eth_freebsd: bpf version mismatch between compilation and runtime"));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set buffer size
|
2004-10-07 21:38:03 +04:00
|
|
|
v = BX_PACKET_BUFSIZE;
|
2001-04-10 05:04:59 +04:00
|
|
|
if (ioctl(this->bpf_fd, BIOCSBLEN, (caddr_t)&v) < 0) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not set buffer size: %s", strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)strncpy(ifr.ifr_name, netif, sizeof(ifr.ifr_name));
|
|
|
|
if (ioctl(this->bpf_fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not enable interface '%s': %s", netif, strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd == -1;
|
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// Verify that the device is an ethernet.
|
|
|
|
if (ioctl(this->bpf_fd, BIOCGDLT, (caddr_t)&v) < 0) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not retrieve datalink type: %s", strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (v != DLT_EN10MB) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: incorrect datalink type %d, expected 10mb ethernet", v));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the device into promisc mode. This could be optimised
|
|
|
|
// to filter on a MAC address, broadcast, and all-multi,
|
|
|
|
// but this will do for now.
|
|
|
|
//
|
|
|
|
if (ioctl(this->bpf_fd, BIOCPROMISC, NULL) < 0) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not enable promisc mode: %s", strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
2006-11-19 19:16:35 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = 1;
|
|
|
|
if (ioctl(this->bpf_fd, BIOCIMMEDIATE, &v) < 0) {
|
|
|
|
BX_PANIC(("eth_freebsd: could not enable immediate mode"));
|
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up non-blocking i/o
|
|
|
|
v = 1;
|
|
|
|
if (ioctl(this->bpf_fd, FIONBIO, &v) < 0) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not enable non-blocking i/o: %s", strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install a filter
|
|
|
|
#ifdef notdef
|
|
|
|
memcpy(&this->filter, promiscfilter, sizeof(promiscfilter));
|
|
|
|
bp.bf_len = 1;
|
2001-11-06 20:14:34 +03:00
|
|
|
#else
|
2001-04-10 05:04:59 +04:00
|
|
|
memcpy(&this->filter, macfilter, sizeof(macfilter));
|
2001-11-06 20:14:34 +03:00
|
|
|
this->filter[1].k =
|
|
|
|
(macaddr[2] & 0xff) << 24 |
|
2001-04-10 05:04:59 +04:00
|
|
|
(macaddr[3] & 0xff) << 16 |
|
|
|
|
(macaddr[4] & 0xff) << 8 |
|
|
|
|
(macaddr[5] & 0xff);
|
2001-11-06 20:14:34 +03:00
|
|
|
this->filter[3].k =
|
|
|
|
(macaddr[0] & 0xff) << 8 |
|
2001-04-10 05:04:59 +04:00
|
|
|
(macaddr[1] & 0xff);
|
|
|
|
bp.bf_len = 8;
|
2001-11-06 20:14:34 +03:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
bp.bf_insns = &this->filter[0];
|
|
|
|
if (ioctl(this->bpf_fd, BIOCSETF, &bp) < 0) {
|
2001-10-06 21:31:44 +04:00
|
|
|
BX_PANIC(("eth_freebsd: could not set filter: %s", strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
close(this->bpf_fd);
|
|
|
|
this->bpf_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
// Start the rx poll
|
|
|
|
this->rx_timer_index =
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_pc_system.register_timer(this, this->rx_timer_handler, BX_BPF_POLL,
|
2009-04-13 17:33:11 +04:00
|
|
|
1, 1, "eth_fbsd"); // continuous, active
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-12-17 12:22:33 +04:00
|
|
|
this->rxh = rxh;
|
|
|
|
this->rxstat = rxstat;
|
2001-06-19 20:09:13 +04:00
|
|
|
|
|
|
|
#if BX_ETH_FBSD_LOGGING
|
2001-06-19 20:57:55 +04:00
|
|
|
// eventually Bryce wants ne2klog to dump in pcap format so that
|
2001-06-19 20:09:13 +04:00
|
|
|
// tcpdump -r FILE can read it and interpret packets.
|
2009-04-13 17:33:11 +04:00
|
|
|
ne2klog = fopen("ne2k.raw", "wb");
|
|
|
|
if (!ne2klog) BX_PANIC(("open ne2k-tx.log failed"));
|
|
|
|
ne2klog_txt = fopen("ne2k.txt", "wb");
|
|
|
|
if (!ne2klog_txt) BX_PANIC(("open ne2k-txdump.txt failed"));
|
|
|
|
fprintf(ne2klog_txt, "null packetmover readable log file\n");
|
|
|
|
fprintf(ne2klog_txt, "net IF = %s\n", netif);
|
|
|
|
fprintf(ne2klog_txt, "MAC address = ");
|
2001-06-19 20:57:55 +04:00
|
|
|
for (int i=0; i<6; i++)
|
2009-04-13 17:33:11 +04:00
|
|
|
fprintf(ne2klog_txt, "%02x%s", 0xff & macaddr[i], i<5?":" : "");
|
|
|
|
fprintf(ne2klog_txt, "\n--\n");
|
|
|
|
fflush(ne2klog_txt);
|
2001-06-19 20:09:13 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// the output routine - called with pre-formatted ethernet frame.
|
|
|
|
void
|
|
|
|
bx_fbsd_pktmover_c::sendpkt(void *buf, unsigned io_len)
|
|
|
|
{
|
2001-06-19 20:09:13 +04:00
|
|
|
#if BX_ETH_FBSD_LOGGING
|
2009-04-13 17:33:11 +04:00
|
|
|
BX_DEBUG(("sendpkt length %u", io_len));
|
2001-06-19 20:09:13 +04:00
|
|
|
// dump raw bytes to a file, eventually dump in pcap format so that
|
|
|
|
// tcpdump -r FILE can interpret them for us.
|
2009-04-13 17:33:11 +04:00
|
|
|
int n = fwrite(buf, io_len, 1, ne2klog);
|
|
|
|
if (n != 1) BX_ERROR(("fwrite to ne2klog failed", io_len));
|
2001-06-19 20:09:13 +04:00
|
|
|
// dump packet in hex into an ascii log file
|
2009-04-19 21:25:40 +04:00
|
|
|
write_pktlog_txt(ne2klog_txt, (const Bit8u *)buf, io_len, 0);
|
2001-06-19 20:09:13 +04:00
|
|
|
// flush log so that we see the packets as they arrive w/o buffering
|
2009-04-13 17:33:11 +04:00
|
|
|
fflush(ne2klog);
|
2001-06-19 20:09:13 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
int status;
|
|
|
|
|
|
|
|
if (this->bpf_fd != -1)
|
|
|
|
status = write(this->bpf_fd, buf, io_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The receive poll process
|
|
|
|
void
|
|
|
|
bx_fbsd_pktmover_c::rx_timer_handler(void *this_ptr)
|
|
|
|
{
|
|
|
|
bx_fbsd_pktmover_c *class_ptr = (bx_fbsd_pktmover_c *) this_ptr;
|
|
|
|
|
|
|
|
class_ptr->rx_timer();
|
|
|
|
}
|
|
|
|
|
2001-11-06 20:14:34 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
void
|
|
|
|
bx_fbsd_pktmover_c::rx_timer(void)
|
|
|
|
{
|
|
|
|
int nbytes = 0;
|
2008-01-27 01:24:03 +03:00
|
|
|
unsigned char rxbuf[BX_PACKET_BUFSIZE];
|
2001-04-10 05:04:59 +04:00
|
|
|
struct bpf_hdr *bhdr;
|
2001-11-06 20:14:34 +03:00
|
|
|
struct bpf_stat bstat;
|
|
|
|
static struct bpf_stat previous_bstat;
|
|
|
|
int counter = 10;
|
|
|
|
#define phdr ((unsigned char*)bhdr)
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-04-13 17:33:11 +04:00
|
|
|
bhdr = (struct bpf_hdr *) rxbuf;
|
2001-04-10 05:04:59 +04:00
|
|
|
nbytes = read(this->bpf_fd, rxbuf, sizeof(rxbuf));
|
|
|
|
|
2009-04-13 17:33:11 +04:00
|
|
|
while (phdr < (rxbuf + nbytes)) {
|
|
|
|
if (ioctl(this->bpf_fd, BIOCGSTATS, &bstat) < 0) {
|
|
|
|
BX_PANIC(("eth_freebsd: could not stat filter: %s", strerror(errno)));
|
|
|
|
}
|
|
|
|
if (bstat.bs_drop > previous_bstat.bs_drop) {
|
|
|
|
BX_INFO(("eth_freebsd: %d packets dropped by the kernel.",
|
|
|
|
bstat.bs_drop - previous_bstat.bs_drop));
|
|
|
|
}
|
|
|
|
previous_bstat = bstat;
|
|
|
|
if (bhdr->bh_caplen < 20 || bhdr->bh_caplen > 1514) {
|
|
|
|
BX_ERROR(("eth_freebsd: received too weird packet length: %d", bhdr->bh_caplen));
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// filter out packets sourced from this node
|
2009-04-13 17:33:11 +04:00
|
|
|
if (memcmp(bhdr + bhdr->bh_hdrlen + 6, this->fbsd_macaddr, 6)) {
|
2011-12-18 13:12:38 +04:00
|
|
|
if (this->rxstat(this->netdev) & BX_NETDEV_RXREADY) {
|
|
|
|
this->rxh(this->netdev, phdr + bhdr->bh_hdrlen, bhdr->bh_caplen);
|
|
|
|
} else {
|
|
|
|
BX_ERROR(("device not ready to receive data"));
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2009-04-13 17:33:11 +04:00
|
|
|
|
2001-06-19 20:09:13 +04:00
|
|
|
#if BX_ETH_FBSD_LOGGING
|
2009-04-13 17:33:11 +04:00
|
|
|
BX_DEBUG(("receive packet length %u", nbytes));
|
2001-06-19 20:09:13 +04:00
|
|
|
// dump raw bytes to a file, eventually dump in pcap format so that
|
|
|
|
// tcpdump -r FILE can interpret them for us.
|
2009-04-13 17:33:11 +04:00
|
|
|
if (1 != fwrite(bhdr, bhdr->bh_caplen, 1, ne2klog)) {
|
|
|
|
BX_PANIC(("fwrite to ne2klog failed: %s", strerror(errno)));
|
|
|
|
}
|
2001-06-19 20:09:13 +04:00
|
|
|
// dump packet in hex into an ascii log file
|
2009-04-19 21:25:40 +04:00
|
|
|
write_pktlog_txt(ne2klog_txt, rxbuf, bhdr->bh_caplen, 1);
|
2001-06-19 20:09:13 +04:00
|
|
|
// flush log so that we see the packets as they arrive w/o buffering
|
2001-06-19 20:57:55 +04:00
|
|
|
fflush (this->ne2klog);
|
2001-06-19 20:09:13 +04:00
|
|
|
#endif
|
|
|
|
|
2009-04-13 17:33:11 +04:00
|
|
|
// Advance bhdr and phdr pointers to next packet
|
|
|
|
bhdr = (struct bpf_hdr*) ((char*) bhdr + BPF_WORDALIGN(bhdr->bh_hdrlen + bhdr->bh_caplen));
|
2008-01-27 01:24:03 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2002-11-19 08:47:45 +03:00
|
|
|
|
2011-02-26 23:10:06 +03:00
|
|
|
#endif /* if BX_NETWORKING && BX_NETMOD_FBSD */
|