/*
* Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * Copyright (c) 2010 Advanced Micro Devices, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*
* Authors: Nathan Binkert
* Steve Reinhardt
+ * Gabe Black
*/
#ifndef __BASE_INET_HH__
#include <vector>
#include "base/range.hh"
+#include "base/types.hh"
#include "dev/etherpkt.hh"
-#include "sim/host.hh"
-
#include "dnet/os.h"
#include "dnet/eth.h"
#include "dnet/ip.h"
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return 0; }
+ int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
};
/*
* IP Stuff
*/
+struct IpAddress
+{
+ protected:
+ uint32_t _ip;
+
+ public:
+ IpAddress() : _ip(0)
+ {}
+ IpAddress(const uint32_t __ip) : _ip(__ip)
+ {}
+
+ uint32_t ip() const { return _ip; }
+
+ std::string string() const;
+};
+
+std::ostream &operator<<(std::ostream &stream, const IpAddress &ia);
+bool operator==(const IpAddress &left, const IpAddress &right);
+
+struct IpNetmask : public IpAddress
+{
+ protected:
+ uint8_t _netmask;
+
+ public:
+ IpNetmask() : IpAddress(), _netmask(0)
+ {}
+ IpNetmask(const uint32_t __ip, const uint8_t __netmask) :
+ IpAddress(__ip), _netmask(__netmask)
+ {}
+
+ uint8_t netmask() const { return _netmask; }
+
+ std::string string() const;
+};
+
+std::ostream &operator<<(std::ostream &stream, const IpNetmask &in);
+bool operator==(const IpNetmask &left, const IpNetmask &right);
+
+struct IpWithPort : public IpAddress
+{
+ protected:
+ uint16_t _port;
+
+ public:
+ IpWithPort() : IpAddress(), _port(0)
+ {}
+ IpWithPort(const uint32_t __ip, const uint16_t __port) :
+ IpAddress(__ip), _port(__port)
+ {}
+
+ uint8_t port() const { return _port; }
+
+ std::string string() const;
+};
+
+std::ostream &operator<<(std::ostream &stream, const IpWithPort &iwp);
+bool operator==(const IpWithPort &left, const IpWithPort &right);
+
struct IpOpt;
struct IpHdr : public ip_hdr
{
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return sizeof(eth_hdr); }
+ int pstart() const { return off() + get()->size(); }
};
uint16_t cksum(const IpPtr &ptr);
{
protected:
EthPacketPtr p;
- int off;
+ int _off;
- void set(const EthPacketPtr &ptr, int offset) { p = ptr; off = offset; }
+ void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
void set(const IpPtr &ptr)
{
if (ptr && ptr->proto() == IP_PROTO_TCP)
}
public:
- TcpPtr() : p(0), off(0) {}
- TcpPtr(const IpPtr &ptr) : p(0), off(0) { set(ptr); }
- TcpPtr(const TcpPtr &ptr) : p(ptr.p), off(ptr.off) {}
+ TcpPtr() : p(0), _off(0) {}
+ TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
+ TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
- TcpHdr *get() { return (TcpHdr *)(p->data + off); }
+ TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
TcpHdr *operator->() { return get(); }
TcpHdr &operator*() { return *get(); }
- const TcpHdr *get() const { return (const TcpHdr *)(p->data + off); }
+ const TcpHdr *get() const { return (const TcpHdr *)(p->data + _off); }
const TcpHdr *operator->() const { return get(); }
const TcpHdr &operator*() const { return *get(); }
const TcpPtr &operator=(const IpPtr &i) { set(i); return *this; }
- const TcpPtr &operator=(const TcpPtr &t) { set(t.p, t.off); return *this; }
+ const TcpPtr &operator=(const TcpPtr &t) { set(t.p, t._off); return *this; }
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return _off; }
+ int pstart() const { return off() + get()->size(); }
};
uint16_t cksum(const TcpPtr &ptr);
{
protected:
EthPacketPtr p;
- int off;
+ int _off;
- void set(const EthPacketPtr &ptr, int offset) { p = ptr; off = offset; }
+ void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
void set(const IpPtr &ptr)
{
if (ptr && ptr->proto() == IP_PROTO_UDP)
}
public:
- UdpPtr() : p(0), off(0) {}
- UdpPtr(const IpPtr &ptr) : p(0), off(0) { set(ptr); }
- UdpPtr(const UdpPtr &ptr) : p(ptr.p), off(ptr.off) {}
+ UdpPtr() : p(0), _off(0) {}
+ UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
+ UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
- UdpHdr *get() { return (UdpHdr *)(p->data + off); }
+ UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
UdpHdr *operator->() { return get(); }
UdpHdr &operator*() { return *get(); }
- const UdpHdr *get() const { return (const UdpHdr *)(p->data + off); }
+ const UdpHdr *get() const { return (const UdpHdr *)(p->data + _off); }
const UdpHdr *operator->() const { return get(); }
const UdpHdr &operator*() const { return *get(); }
const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
- const UdpPtr &operator=(const UdpPtr &t) { set(t.p, t.off); return *this; }
+ const UdpPtr &operator=(const UdpPtr &t) { set(t.p, t._off); return *this; }
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return _off; }
+ int pstart() const { return off() + get()->size(); }
};
uint16_t cksum(const UdpPtr &ptr);
-/* namespace Net */ }
+int hsplit(const EthPacketPtr &ptr);
+
+} // namespace Net
#endif // __BASE_INET_HH__