- removed 'arpback' networking module (ARP simulation still exists in the 'vnet' module)

This commit is contained in:
Volker Ruppert 2011-07-10 20:56:54 +00:00
parent 988b6e4ac5
commit 20ae4af54c
13 changed files with 1 additions and 661 deletions

View File

@ -782,7 +782,6 @@ private_colormap: enabled=0
# If you don't want to make connections to any physical networks,
# you can use the following 'ethmod's to simulate a virtual network.
# null: All packets are discarded, but logged to a few files.
# arpback: ARP is simulated. Disabled by default.
# vde: Virtual Distributed Ethernet
# vnet: ARP, ICMP-echo(ping), DHCP and read/write TFTP are simulated.
# The virtual host uses 192.168.10.1.

View File

@ -1427,9 +1427,6 @@ void bx_init_options()
#if BX_NETMOD_FBSD
"fbsd",
#endif
#if BX_NETMOD_ARPBACK
"arpback",
#endif
#if BX_NETMOD_VDE
"vde",
#endif

View File

@ -806,7 +806,6 @@ typedef
// which networking modules will be enabled
// determined by configure script
#define BX_NETMOD_ARPBACK 0
#define BX_NETMOD_FBSD 0
#define BX_NETMOD_LINUX 0
#define BX_NETMOD_WIN32 0

View File

@ -4197,14 +4197,6 @@ version where this module was added.
</row>
</thead>
<tbody>
<row>
<entry>arpback</entry>
<entry>ARP simulator - disabled by default.
</entry>
<entry>No</entry>
<entry>No</entry>
<entry>1.3</entry>
</row>
<row>
<entry>fbsd</entry>
<entry>FreeBSD / OpenBSD packetmover.

View File

@ -1,5 +1,5 @@
.\"Document Author: Timothy R. Butler - tbutler@uninetsolutions.com"
.TH bochsrc 5 "13 Mar 2011" "bochsrc" "The Bochs Project"
.TH bochsrc 5 "10 Jul 2011" "bochsrc" "The Bochs Project"
.\"SKIP_SECTION"
.SH NAME
bochsrc \- Configuration file for Bochs.
@ -881,7 +881,6 @@ to access physical ethernet interface. Current implemented values include
If you don't want to make connections to any physical networks,
you can use the following 'ethmod's to simulate a virtual network.
- null : All packets are discarded, but logged to a few files
- arpback: ARP is simulated (disabled by default)
- vde : Virtual Distributed Ethernet
- vnet : ARP, ICMP-echo(ping), DHCP and TFTP are simulated
The virtual host uses 192.168.10.1

View File

@ -254,7 +254,6 @@ cmos.o: cmos.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h cmos.h
crc32.o: crc32.@CPP_SUFFIX@ crc32.h ../config.h
devices.o: devices.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
@ -272,11 +271,6 @@ es1370.o: es1370.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h pci.h es1370.h \
soundmod.h soundlnx.h soundwin.h soundosx.h
eth_arpback.o: eth_arpback.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h
eth.o: eth.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
@ -297,11 +291,6 @@ eth_null.o: eth_null.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h eth.h
eth_packetmaker.o: eth_packetmaker.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h \
../osdep.h ../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h
eth_slirp.o: eth_slirp.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
@ -608,7 +597,6 @@ cmos.lo: cmos.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h cmos.h
crc32.lo: crc32.@CPP_SUFFIX@ crc32.h ../config.h
devices.lo: devices.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
@ -626,11 +614,6 @@ es1370.lo: es1370.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h pci.h es1370.h \
soundmod.h soundlnx.h soundwin.h soundosx.h
eth_arpback.lo: eth_arpback.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h
eth.lo: eth.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
@ -651,11 +634,6 @@ eth_null.lo: eth_null.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h eth.h
eth_packetmaker.lo: eth_packetmaker.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h \
../osdep.h ../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \
../pc_system.h ../plugin.h ../extplugin.h ../ltdl.h ../gui/gui.h \
../instrument/stubs/instrument.h ../param_names.h
eth_slirp.lo: eth_slirp.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../gui/paramtree.h ../memory/memory.h \

View File

@ -1,52 +0,0 @@
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
/* CRC-32 calculator
* Adapted from http://www.createwindow.org/programming/crc32/
*/
#include "crc32.h"
CRC_Generator::CRC_Generator() {
init();
}
void CRC_Generator::init(void)
{
Bit32u POLYNOMIAL = 0x04c11db7;
int i;
for(i = 0; i<0xFF; i++) {
int j;
crc32_table[i]=reflect(i,8) << 24;
for(j=0; j<8; j++)
crc32_table[i] = (crc32_table[i]<<1)^(crc32_table[i] & (1<<31) ? POLYNOMIAL : 0);
crc32_table[i] = reflect(crc32_table[i], 32);
}
}
Bit32u CRC_Generator::reflect(Bit32u ref, Bit8u ch)
{
Bit32u value(0);
int i;
for(i=1; i<(ch+1); i++) {
if(ref & 1)
value |= 1 << (ch-i);
ref >>= 1;
}
return value;
}
Bit32u CRC_Generator::get_CRC(Bit8u * buf, Bit32u buflen)
{
Bit32u ulCRC(0xFFFFFFFF);
Bit32u len(buflen);
Bit8u * buffer=(Bit8u *) buf;
while(len--)
ulCRC=(ulCRC>>8)^crc32_table[(ulCRC & 0xFF)^*buffer++];
return ulCRC ^ 0xFFFFFFFF;
}

View File

@ -1,25 +0,0 @@
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
/* CRC-32 calculator
* Adapted from http://www.createwindow.org/programming/crc32/
*/
#ifndef _CRC_32_H_
#define _CRC_32_H_
#include "config.h"
class CRC_Generator {
private:
Bit32u crc32_table[256];
Bit32u reflect(Bit32u ref, Bit8u ch);
public:
void init(void);
CRC_Generator();
Bit32u get_CRC(Bit8u * buf, Bit32u buflen);
};
#endif //_CRC_32_H_

View File

@ -63,7 +63,6 @@ Attached devices
| | +-- Host specific Modules eth_fbsd.cc, eth_linux.cc, eth_win32.cc
| |
| +---- Dummy module eth_null.cc
| +---- ARP simulator eth_arpback.cc, eth_packetmaker.cc, crc32.cc
| +---- TAP Interface eth_tap.cc
| +---- TUN/TAP Interface eth_tuntap.cc
| +---- VDE Interface eth_vde.cc

View File

@ -69,9 +69,6 @@ extern class bx_tuntap_locator_c bx_tuntap_match;
#if BX_NETMOD_VDE
extern class bx_vde_locator_c bx_vde_match;
#endif
#if BX_NETMOD_ARPBACK
extern class bx_arpback_locator_c bx_arpback_match;
#endif
#if BX_NETMOD_SLIRP
extern class bx_slirp_locator_c bx_slirp_match;
#endif
@ -98,12 +95,6 @@ eth_locator_c::create(const char *type, const char *netif,
if (!strcmp(type, "null")) {
ptr = (eth_locator_c *) &bx_null_match;
}
#if BX_NETMOD_ARPBACK
{
if (!strcmp(type, "arpback"))
ptr = (eth_locator_c *) &bx_arpback_match;
}
#endif
#if BX_NETMOD_FBSD
{
if (!strcmp(type, "fbsd"))

View File

@ -1,190 +0,0 @@
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2011 The Bochs Project
//
// 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
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
// eth_arpback.cc - basic ethernet packetmover, only responds to ARP
// Various networking docs:
// http://www.graphcomp.com/info/rfc/
// rfc0826: arp
// rfc0903: rarp
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE
#include "iodev.h"
#if BX_NETWORKING && BX_NETMOD_ARPBACK
#include "eth.h"
#include "crc32.h"
#include "eth_packetmaker.h"
#define LOG_THIS netdev->
#define BX_ETH_ARPBACK_LOGGING 1
//static const Bit8u external_mac[]={0xB0, 0xC4, 0x20, 0x20, 0x00, 0x00, 0x00};
//static const Bit8u internal_mac[]={0xB0, 0xC4, 0x20, 0x00, 0x00, 0x00, 0x00};
//static const Bit8u external_ip[]={ 192, 168, 0, 2, 0x00 };
//static const Bit8u ethtype_arp[]={0x08, 0x06, 0x00};
//
// Define the class. This is private to this module
//
class bx_arpback_pktmover_c : public eth_pktmover_c {
public:
bx_arpback_pktmover_c(const char *netif, const char *macaddr,
eth_rx_handler_t rxh,
bx_devmodel_c *dev);
void sendpkt(void *buf, unsigned io_len);
private:
int rx_timer_index;
static void rx_timer_handler(void *);
void rx_timer(void);
FILE *pktlog, *pktlog_txt;
//Bit8u arpbuf[MAX_FRAME_SIZE];
//Bit32u buflen;
//bx_bool bufvalid;
//CRC_Generator mycrc;
eth_ETHmaker packetmaker;
};
//
// Define the static class that registers the derived pktmover class,
// and allocates one on request.
//
class bx_arpback_locator_c : public eth_locator_c {
public:
bx_arpback_locator_c(void) : eth_locator_c("arpback") {}
protected:
eth_pktmover_c *allocate(const char *netif, const char *macaddr,
eth_rx_handler_t rxh,
bx_devmodel_c *dev, const char *script) {
return (new bx_arpback_pktmover_c(netif, macaddr, rxh, dev, script));
}
} bx_arpback_match;
//
// Define the methods for the bx_arpback_pktmover derived class
//
// the constructor
bx_arpback_pktmover_c::bx_arpback_pktmover_c(const char *netif,
const char *macaddr,
eth_rx_handler_t rxh,
bx_devmodel_c *dev,
const char *script)
{
this->netdev = dev;
BX_INFO(("arpback network driver"));
this->rx_timer_index =
bx_pc_system.register_timer(this, this->rx_timer_handler, 1000,
1, 1, "eth_arpback"); // continuous, active
this->rxh = rxh;
//bufvalid=0;
packetmaker.init();
#if BX_ETH_ARPBACK_LOGGING
// Start the rx poll
// eventually Bryce wants txlog to dump in pcap format so that
// tcpdump -r FILE can read it and interpret packets.
pktlog = fopen("ne2k-pkt.log", "wb");
if (!pktlog) BX_PANIC(("open ne2k-pkt.log failed"));
pktlog_txt = fopen("ne2k-pktlog.txt", "wb");
if (!pktlog_txt) BX_PANIC(("open ne2k-pktlog.txt failed"));
fprintf(pktlog_txt, "arpback packetmover readable log file\n");
fprintf(pktlog_txt, "net IF = %s\n", netif);
fprintf(pktlog_txt, "MAC address = ");
for (int i=0; i<6; i++)
fprintf(pktlog_txt, "%02x%s", 0xff & macaddr[i], i<5?":" : "");
fprintf(pktlog_txt, "\n--\n");
fflush(pktlog_txt);
#endif
}
void
bx_arpback_pktmover_c::sendpkt(void *buf, unsigned io_len)
{
if(io_len<BX_PACKET_BUFSIZE) {
eth_packet barney;
memcpy(barney.buf,buf,io_len);
barney.len=io_len;
if(packetmaker.ishandler(barney)) {
packetmaker.sendpacket(barney);
}
/*
if(( (!memcmp(buf, external_mac, 6)) || (!memcmp(buf, broadcast_macaddr, 6)) )
&& (!memcmp(((Bit8u *)buf)+12, ethtype_arp, 2)) ) {
Bit32u tempcrc;
memcpy(arpbuf,buf,io_len); //move to temporary buffer
memcpy(arpbuf, arpbuf+6, 6); //set destination to sender
memcpy(arpbuf+6, external_mac, 6); //set sender to us
memcpy(arpbuf+32, arpbuf+22, 10); //move destination to sender
memcpy(arpbuf+22, external_mac, 6); //set sender to us
memcpy(arpbuf+28, external_ip, 4); //set sender to us
arpbuf[21]=2; //make this a reply and not a request
tempcrc=mycrc.get_CRC(arpbuf,io_len);
memcpy(arpbuf+io_len, &tempcrc, 4);
buflen=io_len;//+4
bufvalid=1;
}
*/
}
#if BX_ETH_ARPBACK_LOGGING
BX_DEBUG(("sendpkt length %u", io_len));
// dump raw bytes to a file, eventually dump in pcap format so that
// tcpdump -r FILE can interpret them for us.
int n = fwrite (buf, io_len, 1, pktlog);
if (n != 1) BX_ERROR (("fwrite to pktlog failed, length %u", io_len));
// dump packet in hex into an ascii log file
write_pktlog_txt(pktlog_txt, (const Bit8u *)buf, io_len, 0);
// flush log so that we see the packets as they arrive w/o buffering
fflush(pktlog);
#endif
}
void bx_arpback_pktmover_c::rx_timer_handler (void * this_ptr)
{
#if BX_ETH_ARPBACK_LOGGING
BX_DEBUG(("rx_timer_handler"));
#endif
bx_arpback_pktmover_c *class_ptr = ((bx_arpback_pktmover_c *)this_ptr);
class_ptr->rx_timer();
}
void bx_arpback_pktmover_c::rx_timer (void)
{
eth_packet rubble;
if (packetmaker.getpacket(rubble)) {
#if BX_ETH_ARPBACK_LOGGING
write_pktlog_txt(pktlog_txt, rubble.buf, rubble.len, 1);
#endif
(*rxh)(this->netdev, rubble.buf, rubble.len);
}
}
#endif /* if BX_NETWORKING && BX_NETMOD_ARPBACK */

View File

@ -1,202 +0,0 @@
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2000-2011 The Bochs Project
//
// 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
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE
#include "iodev.h"
#if BX_NETWORKING && BX_NETMOD_ARPBACK
#include "eth_packetmaker.h"
bx_bool sendable(const eth_packet& outpacket) {
//FINISH ME!
return 0;
}
Bit32u eth_IPmaker::datalen(const eth_packet& outpacket)
{
Bit32u out;
out=((outpacket.buf[16]<<8)+outpacket.buf[17])-(4*(0xF & outpacket.buf[14]));
return out;
}
const Bit8u *eth_IPmaker::datagram(const eth_packet& outpacket)
{
const Bit8u *out;
out=outpacket.buf+14+(4*(0xF & outpacket.buf[14]));
return out;
}
Bit32u eth_IPmaker::build_packet_header(Bit32u source, Bit32u dest, Bit8u protocol, Bit32u datalen)
{
Bit32u temp;
Bit32u i;
memcpy(pending.buf,internal_mac,6);
memcpy(pending.buf+6,external_mac,6);
memcpy(pending.buf+12,ethtype_ip,2);
pending.buf[14]=0x45;
pending.buf[15]=0;
temp=datalen+20;
pending.buf[16]=(temp>>8) & 0xFF;
pending.buf[17]=temp & 0xFF;
pending.buf[18]=0;
pending.buf[19]=0;
pending.buf[20]=0;
pending.buf[21]=0;
pending.buf[22]=30;
pending.buf[23]=protocol;
pending.buf[24]=0;
pending.buf[25]=0;
pending.buf[26]=(source>>24) & 0xFF;
pending.buf[27]=(source>>16) & 0xFF;
pending.buf[28]=(source>>8) & 0xFF;
pending.buf[29]=(source) & 0xFF;
pending.buf[30]=(dest>>24) & 0xFF;
pending.buf[31]=(dest>>16) & 0xFF;
pending.buf[32]=(dest>>8) & 0xFF;
pending.buf[33]=(dest) & 0xFF;
//Compute Checksum
temp=0;
for(i=14;i<34;i=i+2) {
Bit32u addee=pending.buf[i];
addee=(addee<<8) & pending.buf[i+1];
temp=temp+addee;
}
temp=(temp>>16)+(temp&0xFFFF);
temp=(temp>>16)+(temp&0xFFFF);
pending.buf[24]=~(Bit8u)((temp>>8) & 0xFF);
pending.buf[25]=~(Bit8u)(temp & 0xFF);
return(34);
}
Bit8u eth_IPmaker::protocol(const eth_packet& outpacket)
{
return (*(outpacket.buf+23) & 0xff);
}
Bit32u eth_IPmaker::source(const eth_packet& outpacket)
{
Bit32u out=0xFF & *(outpacket.buf+26);
out=(out<<8) | (0xFF & *(outpacket.buf+27));
out=(out<<8) | (0xFF & *(outpacket.buf+28));
out=(out<<8) | (0xFF & *(outpacket.buf+29));
return out;
}
Bit32u eth_IPmaker::destination(const eth_packet& outpacket)
{
Bit32u out=0xFF & *(outpacket.buf+30);
out=(out<<8) | (0xFF & *(outpacket.buf+31));
out=(out<<8) | (0xFF & *(outpacket.buf+32));
out=(out<<8) | (0xFF & *(outpacket.buf+33));
return out;
}
void eth_IPmaker::init(void)
{
is_pending=0;
}
void eth_ETHmaker::init(void)
{
arper.init();
}
bx_bool eth_ETHmaker::getpacket(eth_packet& inpacket)
{
return arper.getpacket(inpacket);
}
bx_bool eth_ETHmaker::ishandler(const eth_packet& outpacket)
{
if((outpacket.len>=60) &&
( (!memcmp(outpacket.buf, external_mac, 6))
|| (!memcmp(outpacket.buf, broadcast_macaddr, 6))) &&
( (!memcmp(outpacket.buf+12, ethtype_arp, 2)) ||
(!memcmp(outpacket.buf+12, ethtype_ip, 2))) &&
(outpacket.len<PACKET_BUF_SIZE)
) {
return 1;
}
return 0;
}
bx_bool eth_ETHmaker::sendpacket(const eth_packet& outpacket)
{
return arper.sendpacket(outpacket);
}
void eth_ARPmaker::init(void)
{
is_pending=0;
pending.len=0;
}
bx_bool eth_ARPmaker::getpacket(eth_packet& inpacket)
{
if(is_pending) {
memcpy(inpacket.buf,pending.buf,pending.len);
inpacket.len=pending.len;
is_pending=0;
return 1;
}
return 0;
}
bx_bool eth_ARPmaker::ishandler(const eth_packet& outpacket)
{
if((outpacket.len>=60) &&
(!memcmp(outpacket.buf+12, ethtype_arp, 2)) &&
(outpacket.len<PACKET_BUF_SIZE) &&
( (!memcmp(outpacket.buf, external_mac, 6))
|| (!memcmp(outpacket.buf, broadcast_macaddr, 6)) ) &&
(!memcmp(outpacket.buf+38, external_ip, 4))
) {
return 1;
}
return 0;
}
bx_bool eth_ARPmaker::sendpacket(const eth_packet& outpacket)
{
if(is_pending || !ishandler(outpacket)) {
return 0;
} else {
//Bit32u tempcrc;
memcpy(pending.buf,outpacket.buf,outpacket.len); //move to temporary buffer
memcpy(pending.buf, pending.buf+6, 6); //set destination to sender
memcpy(pending.buf+6, external_mac, 6); //set sender to us
memcpy(pending.buf+32, pending.buf+22, 10); //move destination to sender
memcpy(pending.buf+22, external_mac, 6); //set sender to us
memcpy(pending.buf+28, external_ip, 4); //set sender to us
pending.buf[21]=2; //make this a reply and not a request
//tempcrc=mycrc.get_CRC(pending.buf,len);
//memcpy(pending.buf+len, &tempcrc, 4);
pending.len=outpacket.len; //+4
is_pending=1;
return 1;
}
}
#endif /* if BX_NETWORKING && BX_NETMOD_ARPBACK */

View File

@ -1,145 +0,0 @@
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2000-2009 The Bochs Project
//
// 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
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef _ETH_PACKETMAKER_H_
#define _ETH_PACKETMAKER_H_
#if BX_NETMOD_ARPBACK
static const Bit8u internal_mac[]={0xB0, 0xC4, 0x20, 0x20, 0x00, 0x00, 0x00};
static const Bit8u external_mac[]={0xB0, 0xC4, 0x20, 0x20, 0x00, 0x00, 0x00};
static const Bit8u external_ip[]={ 192, 168, 0, 2, 0x00 };
static const Bit8u ethtype_arp[]={0x08, 0x06, 0x00};
static const Bit8u ethtype_ip[]={0x08, 0x00, 0x00};
static const Bit8u prot_udp=17;
static const Bit8u prot_tcp=6;
class eth_packet {
public:
Bit8u buf[BX_PACKET_BUFSIZE];
Bit32u len;
};
class eth_packetmaker {
public:
virtual bx_bool getpacket(eth_packet& inpacket) = 0;
virtual bx_bool ishandler(const eth_packet& outpacket) = 0;
virtual bx_bool sendpacket(const eth_packet& outpacket) = 0;
};
class eth_ARPmaker : public eth_packetmaker {
public:
void init(void);
bx_bool ishandler(const eth_packet& outpacket);
bx_bool sendpacket(const eth_packet& outpacket);
bx_bool getpacket(eth_packet& inpacket);
private:
eth_packet pending;
bx_bool is_pending;
};
class eth_IPmaker : eth_packetmaker {
public:
void init(void);
virtual bx_bool ishandler(const eth_packet& outpacket)=0;
virtual bx_bool sendpacket(const eth_packet& outpacket)=0;
virtual bx_bool getpacket(eth_packet& inpacket)=0;
protected:
bx_bool sendable(const eth_packet& outpacket);
Bit32u source(const eth_packet& outpacket);
Bit32u destination(const eth_packet& outpacket);
Bit8u protocol(const eth_packet& outpacket);
const Bit8u * datagram(const eth_packet& outpacket);
Bit32u datalen(const eth_packet& outpacket);
//Build a header in pending, return header length in bytes.
Bit32u build_packet_header(Bit32u source, Bit32u dest, Bit8u protocol, Bit32u datalen);
eth_packet pending;
bx_bool is_pending;
//Bit8u Version; //=4 (4 bits)
//It better be!
//Bit8u IHL; //Header length in 32-bit bytes (4 bits)
//Used to strip layer
//Bit8u Type_of_Service; //not relevent, set to 0;
//Ignore on receive, set to 0 on send.
//Bit16u Total_Length;//length of the datagram in octets. use 576 or less;
//Use 576 or less on send.
//Use to get length on receive
//Bit16u Identification;//Identifier for assembling fragments
//Ignore, we'll drop fragments
//Bit8u Flags;//0,Don't fragment, More Fragments (vs last fragment)
//Set to 0 on send
//Drop if more fragments set.
//Bit16u Fragment Offset;//where in the datagram this fragment belongs
//Should be 0 for send and receive.
//Bit8u TTL;//Set to something sorta big.
//Shouldn't be 0 on receive
//Set to something big on send
//Bit8u Protocol;
//Defines Protocol.
//TCP=?, UDP=?
//Bit16u Header_Checksum;//16-bit one's complement of the one's complement
//sum of all 16-bit words in header;
//Could check on receive, must set on send.
//Bit32u Source;//source address
//Bit32u Destination;//destination address
};
/*
class eth_TCPmaker : eth_packetmaker {
};
class eth_UDPmaker : eth_packetmaker {
};
*/
class eth_ETHmaker : public eth_packetmaker {
public:
//handles all packets to a MAC addr.
void init(void);
virtual bx_bool getpacket(eth_packet& inpacket);
virtual bx_bool ishandler(const eth_packet& outpacket);
virtual bx_bool sendpacket(const eth_packet& outpacket);
private:
eth_ARPmaker arper;
};
#endif // BX_NETMOD_ARPBACK
#endif // _ETH_PACKETMAKER_H_