Changed the format for eth_arpback to be more versatile for use with

UDP and TCP.
This commit is contained in:
Gregory Alexander 2001-06-21 01:45:17 +00:00
parent 519d231cd4
commit 2ee630f3fc
3 changed files with 231 additions and 15 deletions

View File

@ -29,12 +29,15 @@
#include "bochs.h"
#include "crc32.h"
#include "eth_packetmaker.h"
#define LOG_THIS bx_ne2k.
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 broadcast_mac[]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
static const Bit8u ethtype_arp[]={0x08, 0x06, 0x00};
//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 broadcast_mac[]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
//static const Bit8u ethtype_arp[]={0x08, 0x06, 0x00};
#define MAX_FRAME_SIZE 2048
@ -52,10 +55,11 @@ private:
static void rx_timer_handler(void *);
void rx_timer(void);
FILE *txlog, *txlog_txt;
Bit8u arpbuf[MAX_FRAME_SIZE];
Bit32u buflen;
Boolean bufvalid;
CRC_Generator mycrc;
//Bit8u arpbuf[MAX_FRAME_SIZE];
//Bit32u buflen;
//Boolean bufvalid;
//CRC_Generator mycrc;
eth_ETHmaker packetmaker;
};
@ -90,7 +94,8 @@ bx_arpback_pktmover_c::bx_arpback_pktmover_c(const char *netif,
1, 1); // continuous, active
this->rxh = rxh;
this->rxarg = rxarg;
bufvalid=0;
//bufvalid=0;
packetmaker.init();
#if BX_ETH_NULL_LOGGING
// Start the rx poll
// eventually Bryce wants txlog to dump in pcap format so that
@ -113,6 +118,13 @@ void
bx_arpback_pktmover_c::sendpkt(void *buf, unsigned io_len)
{
if(io_len<MAX_FRAME_SIZE) {
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_mac, 6)) )
&& (!memcmp(((Bit8u *)buf)+12, ethtype_arp, 2)) ) {
Bit32u tempcrc;
@ -125,9 +137,10 @@ bx_arpback_pktmover_c::sendpkt(void *buf, unsigned io_len)
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*/;
buflen=io_len;//+4
bufvalid=1;
}
*/
}
#if BX_ETH_NULL_LOGGING
BX_DEBUG (("sendpkt length %u", io_len));
@ -164,11 +177,12 @@ void bx_arpback_pktmover_c::rx_timer (void)
{
int nbytes = 0;
struct bpf_hdr *bhdr;
if(bufvalid) {
bufvalid=0;
void * buf=arpbuf;
unsigned io_len=buflen;
eth_packet rubble;
if(packetmaker.getpacket(rubble)) {
//bufvalid=0;
void * buf=rubble.buf;
unsigned io_len=rubble.len;
Bit32u n;
fprintf (txlog_txt, "NE2K receiving a packet, length %u\n", io_len);
Bit8u *charbuf = (Bit8u *)buf;

View File

@ -0,0 +1,87 @@
#include "eth_packetmaker.h"
#include "bochs.h"
void
eth_ETHmaker::init(void) {
arper.init();
}
Boolean
eth_ETHmaker::getpacket(eth_packet& inpacket) {
return arper.getpacket(inpacket);
}
Boolean
eth_ETHmaker::ishandler(const eth_packet& outpacket) {
if((outpacket.len>=60) &&
( (!memcmp(outpacket.buf, external_mac, 6))
|| (!memcmp(outpacket.buf, broadcast_mac, 6)) ) &&
( (!memcmp(outpacket.buf+12, ethtype_arp, 2)) ||
(!memcmp(outpacket.buf+12, ethtype_ip, 2)) ) &&
(outpacket.len<PACKET_BUF_SIZE)
) {
return 1;
}
return 0;
}
Boolean
eth_ETHmaker::sendpacket(const eth_packet& outpacket) {
return arper.sendpacket(outpacket);
}
void
eth_ARPmaker::init(void) {
is_pending=0;
pending.len=0;
}
Boolean
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;
}
Boolean
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_mac, 6)) )
) {
return 1;
}
return 0;
}
Boolean
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;
}
}

View File

@ -0,0 +1,115 @@
#ifndef _ETH_PACKETMAKER_H_
#define _ETH_PACKETMAKER_H_
#include "../config.h"
#define PACKET_BUF_SIZE 2048
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 broadcast_mac[]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
static const Bit8u ethtype_arp[]={0x08, 0x06, 0x00};
static const Bit8u ethtype_ip[]={0x08, 0x00, 0x00};
class eth_packet {
public:
Bit8u buf[PACKET_BUF_SIZE];
Bit32u len;
};
class eth_packetmaker {
public:
virtual Boolean getpacket(eth_packet& inpacket) = 0;
virtual Boolean ishandler(const eth_packet& outpacket) = 0;
virtual Boolean sendpacket(const eth_packet& outpacket) = 0;
};
class eth_ARPmaker : public eth_packetmaker {
public:
void init(void);
Boolean ishandler(const eth_packet& outpacket);
Boolean sendpacket(const eth_packet& outpacket);
Boolean getpacket(eth_packet& inpacket);
private:
eth_packet pending;
Boolean is_pending;
};
/*
class eth_IPmaker : eth_packetmaker {
public:
void init(void);
virtual Boolean ishandler(const eth_packet& outpacket);
virtual Boolean sendpacket(const eth_packet& outpacket);
virtual Boolean getpacket(eth_packet& inpacket);
private:
eth_packet pending;
Boolean is_pending;
Bit32u Destination;
Bit32u Source;
//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 Boolean getpacket(eth_packet& inpacket);
virtual Boolean ishandler(const eth_packet& outpacket);
virtual Boolean sendpacket(const eth_packet& outpacket);
private:
eth_ARPmaker arper;
};
#endif // _ETH_PACKETMAKER_H_