diff options
author | Lisa Hsu <hsul@eecs.umich.edu> | 2004-06-10 14:40:51 -0400 |
---|---|---|
committer | Lisa Hsu <hsul@eecs.umich.edu> | 2004-06-10 14:40:51 -0400 |
commit | c78d847c01ac5507dbd64adf63ade5d4514414fe (patch) | |
tree | e86735d9d9da8d2c374bcb52d233007515343889 | |
parent | 02f69b94c540a6b116c1a71a97f16facd21a5c44 (diff) | |
parent | 3c7f9617516ff650cd6e30d35b0b88562c0c552d (diff) | |
download | gem5-c78d847c01ac5507dbd64adf63ade5d4514414fe.tar.xz |
Merge zizzer.eecs.umich.edu:/bk/linux
into lush.(none):/z/hsul/work/linux
--HG--
extra : convert_revision : 30b93e7a4548a00ba18e86aad85df4c790f51d43
-rw-r--r-- | dev/etherpkt.hh | 85 | ||||
-rw-r--r-- | dev/ns_gige.cc | 16 |
2 files changed, 27 insertions, 74 deletions
diff --git a/dev/etherpkt.hh b/dev/etherpkt.hh index e51210e2e..8d0022363 100644 --- a/dev/etherpkt.hh +++ b/dev/etherpkt.hh @@ -38,67 +38,9 @@ #include "sim/host.hh" #include "base/refcnt.hh" - -#define EADDR_LEN 6 +#include "base/inet_hdrs.hh" class Checkpoint; - -struct pseudo_header -{ - uint32_t src_ip_addr; - uint32_t dest_ip_addr; - uint16_t protocol; - uint16_t len; -}; - -/** Ethernet header struct for casting purposes */ -struct eth_header -{ - uint8_t dest[EADDR_LEN]; - uint8_t src[EADDR_LEN]; - uint16_t type; -}; - -struct ip_header -{ - uint8_t vers_len; - uint8_t service_type; - uint16_t dgram_len; - uint16_t ID; - uint16_t flags_frag_offset; - uint8_t TTL; - uint8_t protocol; - uint16_t hdr_chksum; - uint32_t src_ip_addr; - uint32_t dest_ip_addr; - uint8_t *options; - uint8_t *transport_header; -}; - -struct tcp_header -{ - uint16_t src_port_num; - uint16_t dest_port_num; - uint32_t seq_num; - uint32_t ack_num; - uint8_t hdr_len; - uint8_t flags; - uint16_t rcv_window; - uint16_t chksum; - uint16_t urgent; - uint8_t *options; - uint8_t *data; -}; - -struct udp_header -{ - uint16_t src_port_num; - uint16_t dest_port_num; - uint16_t len; - uint16_t chksum; - uint8_t *data; -}; - /* * Reference counted class containing ethernet packet data */ @@ -119,14 +61,31 @@ class EtherPacket : public RefCounted bool IsMulticast() { return data[0] == 0x01; } bool IsBroadcast() { return data[0] == 0xff; } - ip_header *getIpHdr() { return (ip_header *) (data + 14); } - - void *getTransportHdr() { + bool isIpPkt() { + eth_header *eth = (eth_header *) data; + return (eth->type == 0x800); + } + bool isTcpPkt() { ip_header *ip = getIpHdr(); - return (void *) (ip + (ip->vers_len & 0xf)); + return (ip->protocol == 6); + } + bool isUdpPkt() { + ip_header *ip = getIpHdr(); + return (ip->protocol == 17); + } + + ip_header *getIpHdr() { + assert(isIpPkt()); + return (ip_header *) (data + sizeof(eth_header)); } + tcp_header *getTcpHdr(ip_header *ip) { + return (tcp_header *) (ip + (ip->vers_len & 0xf)); + } + udp_header *getUdpHdr(ip_header *ip) { + return (udp_header *) (ip + (ip->vers_len & 0xf)); + } typedef RefCountingPtr<EtherPacket> PacketPtr; void serialize(std::ostream &os); diff --git a/dev/ns_gige.cc b/dev/ns_gige.cc index fa65b68ab..b72f4ca36 100644 --- a/dev/ns_gige.cc +++ b/dev/ns_gige.cc @@ -1309,19 +1309,15 @@ NSGigE::rxKick() } #endif - eth_header *eth = (eth_header *) rxPacket->data; - // eth->type 0x800 indicated that it's an ip packet. - if (eth->type == 0x800 && extstsEnable) { - rxDescCache.extsts |= EXTSTS_IPPKT; + if (rxPacket->isIpPkt() && extstsEnable) { rxDescCache.extsts |= EXTSTS_IPPKT; if (!ipChecksum(rxPacket, false)) rxDescCache.extsts |= EXTSTS_IPERR; - ip_header *ip = rxFifo.front()->getIpHdr(); - if (ip->protocol == 6) { + if (rxPacket->isTcpPkt()) { rxDescCache.extsts |= EXTSTS_TCPPKT; if (!tcpChecksum(rxPacket, false)) rxDescCache.extsts |= EXTSTS_TCPERR; - } else if (ip->protocol == 17) { + } else if (rxPacket->isUdpPkt()) { rxDescCache.extsts |= EXTSTS_UDPPKT; if (!udpChecksum(rxPacket, false)) rxDescCache.extsts |= EXTSTS_UDPERR; @@ -1924,9 +1920,8 @@ NSGigE::recvPacket(PacketPtr packet) bool NSGigE::udpChecksum(PacketPtr packet, bool gen) { - udp_header *hdr = (udp_header *) packet->getTransportHdr(); - ip_header *ip = packet->getIpHdr(); + udp_header *hdr = packet->getUdpHdr(ip); pseudo_header *pseudo = new pseudo_header; @@ -1951,9 +1946,8 @@ NSGigE::udpChecksum(PacketPtr packet, bool gen) bool NSGigE::tcpChecksum(PacketPtr packet, bool gen) { - tcp_header *hdr = (tcp_header *) packet->getTransportHdr(); - ip_header *ip = packet->getIpHdr(); + tcp_header *hdr = packet->getTcpHdr(ip); pseudo_header *pseudo = new pseudo_header; |