changeset 5d8722ab804b in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=5d8722ab804b
description:
base: Add support for ipv6 into inet.hh/inet.cc
diffstat:
src/base/inet.cc | 132 +++++++++++++++++++++++++++++-
src/base/inet.hh | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 352 insertions(+), 19 deletions(-)
diffs (truncated from 552 to 300 lines):
diff -r 72a72649a156 -r 5d8722ab804b src/base/inet.cc
--- a/src/base/inet.cc Thu Oct 31 13:41:13 2013 -0500
+++ b/src/base/inet.cc Thu Oct 31 13:41:13 2013 -0500
@@ -1,4 +1,16 @@
/*
+ * Copyright (c) 2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
* Copyright (c) 2002-2005 The Regents of The University of Michigan
* Copyright (c) 2010 Advanced Micro Devices, Inc.
* All rights reserved.
@@ -28,6 +40,7 @@
*
* Authors: Nathan Binkert
* Gabe Black
+ * Geoffrey Blake
*/
#include <cstddef>
@@ -205,12 +218,41 @@
}
uint16_t
+__tu_cksum6(const Ip6Ptr &ip6)
+{
+ int tcplen = ip6->plen() - ip6->extensionLength();
+ int sum = ip_cksum_add(ip6->payload(), tcplen, 0);
+ sum = ip_cksum_add(ip6->src(), 32, sum);
+ sum += htons(ip6->proto() + tcplen);
+ return ip_cksum_carry(sum);
+}
+
+uint16_t
cksum(const TcpPtr &tcp)
-{ return __tu_cksum(IpPtr(tcp.packet())); }
+{
+ if (IpPtr(tcp.packet())) {
+ return __tu_cksum(IpPtr(tcp.packet()));
+ } else if (Ip6Ptr(tcp.packet())) {
+ return __tu_cksum6(Ip6Ptr(tcp.packet()));
+ } else {
+ assert(0);
+ }
+ // Should never reach here
+ return 0;
+}
uint16_t
cksum(const UdpPtr &udp)
-{ return __tu_cksum(IpPtr(udp.packet())); }
+{
+ if (IpPtr(udp.packet())) {
+ return __tu_cksum(IpPtr(udp.packet()));
+ } else if (Ip6Ptr(udp.packet())) {
+ return __tu_cksum6(Ip6Ptr(udp.packet()));
+ } else {
+ assert(0);
+ }
+ return 0;
+}
bool
IpHdr::options(vector<const IpOpt *> &vec) const
@@ -233,6 +275,82 @@
return true;
}
+#define IP6_EXTENSION(nxt) (nxt == IP_PROTO_HOPOPTS) ? true : \
+ (nxt == IP_PROTO_ROUTING) ? true : \
+ (nxt == IP_PROTO_FRAGMENT) ? true : \
+ (nxt == IP_PROTO_AH) ? true : \
+ (nxt == IP_PROTO_ESP) ? true: \
+ (nxt == IP_PROTO_DSTOPTS) ? true : false
+
+/* Scan the IP6 header for all header extensions
+ * and return the number of headers found
+ */
+int
+Ip6Hdr::extensionLength() const
+{
+ const uint8_t *data = bytes() + IP6_HDR_LEN;
+ uint8_t nxt = ip6_nxt;
+ int len = 0;
+ int all = plen();
+
+ while (IP6_EXTENSION(nxt)) {
+ const Ip6Opt *ext = (const Ip6Opt *)data;
+ nxt = ext->nxt();
+ len += ext->len();
+ data += ext->len();
+ all -= ext->len();
+ assert(all >= 0);
+ }
+ return len;
+}
+
+/* Scan the IP6 header for a particular extension
+ * header type and return a pointer to it if it
+ * exists, otherwise return NULL
+ */
+const Ip6Opt*
+Ip6Hdr::getExt(uint8_t ext_type) const
+{
+ const uint8_t *data = bytes() + IP6_HDR_LEN;
+ uint8_t nxt = ip6_nxt;
+ Ip6Opt* opt = NULL;
+ int all = plen();
+
+ while (IP6_EXTENSION(nxt)) {
+ opt = (Ip6Opt *)data;
+ if (nxt == ext_type) {
+ break;
+ }
+ nxt = opt->nxt();
+ data += opt->len();
+ all -= opt->len();
+ opt = NULL;
+ assert(all >= 0);
+ }
+ return (const Ip6Opt*)opt;
+}
+
+/* Scan the IP6 header and any extension headers
+ * to find what type of Layer 4 header exists
+ * after this header
+ */
+uint8_t
+Ip6Hdr::proto() const
+{
+ const uint8_t *data = bytes() + IP6_HDR_LEN;
+ uint8_t nxt = ip6_nxt;
+ int all = plen();
+
+ while (IP6_EXTENSION(nxt)) {
+ const Ip6Opt *ext = (const Ip6Opt *)data;
+ nxt = ext->nxt();
+ data += ext->len();
+ all -= ext->len();
+ assert(all >= 0);
+ }
+ return nxt;
+}
+
bool
TcpHdr::options(vector<const TcpOpt *> &vec) const
{
@@ -260,6 +378,7 @@
int split_point = 0;
IpPtr ip(ptr);
+ Ip6Ptr ip6(ptr);
if (ip) {
split_point = ip.pstart();
@@ -270,6 +389,15 @@
UdpPtr udp(ip);
if (udp)
split_point = udp.pstart();
+ } else if (ip6) {
+ split_point = ip6.pstart();
+
+ TcpPtr tcp(ip6);
+ if (tcp)
+ split_point = tcp.pstart();
+ UdpPtr udp(ip6);
+ if (udp)
+ split_point = udp.pstart();
}
return split_point;
}
diff -r 72a72649a156 -r 5d8722ab804b src/base/inet.hh
--- a/src/base/inet.hh Thu Oct 31 13:41:13 2013 -0500
+++ b/src/base/inet.hh Thu Oct 31 13:41:13 2013 -0500
@@ -1,4 +1,16 @@
/*
+ * Copyright (c) 2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
* Copyright (c) 2002-2005 The Regents of The University of Michigan
* Copyright (c) 2010 Advanced Micro Devices, Inc.
* All rights reserved.
@@ -29,6 +41,7 @@
* Authors: Nathan Binkert
* Steve Reinhardt
* Gabe Black
+ * Geoffrey Blake
*/
#ifndef __BASE_INET_HH__
@@ -104,11 +117,31 @@
struct EthHdr : public eth_hdr
{
- uint16_t type() const { return ntohs(eth_type); }
+ bool isVlan() const { return (ntohs(eth_type) == ETH_TYPE_8021Q); }
+ uint16_t type() const {
+ if (!isVlan())
+ return ntohs(eth_type);
+ else
+ // L3 type is now 16 bytes into the hdr with 802.1Q
+ // instead of 12. dnet/eth.h only supports 802.1
+ return ntohs(*((uint16_t*)(((uint8_t *)this) + 16)));
+ }
+ uint16_t vlanId() const {
+ if (isVlan())
+ return ntohs(*((uint16_t*)(((uint8_t *)this) + 14)));
+ else
+ return 0x0000;
+ }
+
const EthAddr &src() const { return *(EthAddr *)ð_src; }
const EthAddr &dst() const { return *(EthAddr *)ð_dst; }
- int size() const { return sizeof(eth_hdr); }
+ int size() const {
+ if (!isVlan())
+ return sizeof(eth_hdr);
+ else
+ return (sizeof(eth_hdr)+4);
+ }
const uint8_t *bytes() const { return (const uint8_t *)this; }
const uint8_t *payload() const { return bytes() + size(); }
@@ -120,6 +153,7 @@
{
protected:
friend class IpPtr;
+ friend class Ip6Ptr;
EthPacketPtr p;
public:
@@ -226,7 +260,6 @@
void id(uint16_t _id) { ip_id = htons(_id); }
void len(uint16_t _len) { ip_len = htons(_len); }
-
bool options(std::vector<const IpOpt *> &vec) const;
int size() const { return hlen(); }
@@ -242,30 +275,36 @@
friend class TcpPtr;
friend class UdpPtr;
EthPacketPtr p;
+ bool eth_hdr_vlan;
void set(const EthPacketPtr &ptr)
{
p = 0;
+ eth_hdr_vlan = false;
if (ptr) {
EthHdr *eth = (EthHdr *)ptr->data;
if (eth->type() == ETH_TYPE_IP)
p = ptr;
+ if (eth->isVlan())
+ eth_hdr_vlan = true;
}
}
public:
- IpPtr() : p(0) {}
- IpPtr(const EthPacketPtr &ptr) : p(0) { set(ptr); }
- IpPtr(const EthPtr &ptr) : p(0) { set(ptr.p); }
- IpPtr(const IpPtr &ptr) : p(ptr.p) { }
+ IpPtr() : p(0), eth_hdr_vlan(false) {}
+ IpPtr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
+ IpPtr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
+ IpPtr(const IpPtr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { }
- IpHdr *get() { return (IpHdr *)(p->data + sizeof(eth_hdr)); }
+ IpHdr *get() { return (IpHdr *)(p->data + sizeof(eth_hdr) +
+ ((eth_hdr_vlan) ? 4 : 0)); }
IpHdr *operator->() { return get(); }
IpHdr &operator*() { return *get(); }
const IpHdr *get() const
- { return (const IpHdr *)(p->data + sizeof(eth_hdr)); }
+ { return (const IpHdr *)(p->data + sizeof(eth_hdr) +
+ ((eth_hdr_vlan) ? 4 : 0)); }
const IpHdr *operator->() const { return get(); }
const IpHdr &operator*() const { return *get(); }
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev