Go to the documentation of this file.
42 #ifndef __BASE_INET_HH__
43 #define __BASE_INET_HH__
56 #include "dnet/addr.h"
58 #include "dnet/icmp.h"
61 #include "dnet/intf.h"
62 #include "dnet/route.h"
64 #include "dnet/blob.h"
65 #include "dnet/rand.h"
93 int size()
const {
return sizeof(eth_addr); }
113 bool isBroadcast =
true;
114 for (
int i = 0;
i < ETH_ADDR_LEN; ++
i) {
115 isBroadcast = isBroadcast &&
data[
i] == 0xff;
125 std::string
string()
const;
130 operator uint64_t()
const
133 reg |= ((uint64_t)
data[0]) << 40;
134 reg |= ((uint64_t)
data[1]) << 32;
135 reg |= ((uint64_t)
data[2]) << 24;
136 reg |= ((uint64_t)
data[3]) << 16;
137 reg |= ((uint64_t)
data[4]) << 8;
138 reg |= ((uint64_t)
data[5]) << 0;
148 std::ostream &
operator<<(std::ostream &stream,
const EthAddr &
ea);
149 bool operator==(
const EthAddr &left,
const EthAddr &right);
154 bool isVlan()
const {
return (ntohs(eth_type) == ETH_TYPE_8021Q); }
157 return ntohs(eth_type);
161 return ntohs(*((uint16_t*)(((uint8_t *)
this) + 16)));
165 return ntohs(*((uint16_t*)(((uint8_t *)
this) + 14)));
175 return sizeof(eth_hdr);
177 return (
sizeof(eth_hdr)+4);
180 const uint8_t *
bytes()
const {
return (
const uint8_t *)
this; }
182 uint8_t *
bytes() {
return (uint8_t *)
this; }
222 operator bool()
const {
return (
p !=
nullptr); }
223 int off()
const {
return 0; }
255 std::string
string()
const;
262 std::ostream &
operator<<(std::ostream &stream,
const IpAddress &
ia);
263 bool operator==(
const IpAddress &left,
const IpAddress &right);
274 IpNetmask(
const uint32_t __ip,
const uint8_t __netmask) :
283 std::string
string()
const;
290 std::ostream &
operator<<(std::ostream &stream,
const IpNetmask &in);
291 bool operator==(
const IpNetmask &left,
const IpNetmask &right);
311 std::string
string()
const;
318 std::ostream &
operator<<(std::ostream &stream,
const IpWithPort &iwp);
319 bool operator==(
const IpWithPort &left,
const IpWithPort &right);
326 uint8_t
hlen()
const {
return ip_hl * 4; }
327 uint8_t
tos()
const {
return ip_tos; }
328 uint16_t
len()
const {
return ntohs(ip_len); }
329 uint16_t
id()
const {
return ntohs(ip_id); }
331 uint16_t
frag_off()
const {
return ntohs(ip_off) & 0x1fff; }
332 uint8_t
ttl()
const {
return ip_ttl; }
333 uint8_t
proto()
const {
return ip_p; }
334 uint16_t
sum()
const {
return ip_sum; }
335 uint32_t
src()
const {
return ntohl(ip_src); }
336 uint32_t
dst()
const {
return ntohl(ip_dst); }
339 void id(uint16_t _id) { ip_id = htons(_id); }
340 void len(uint16_t _len) { ip_len = htons(_len); }
345 const uint8_t *
bytes()
const {
return (
const uint8_t *)
this; }
347 uint8_t *
bytes() {
return (uint8_t *)
this; }
366 if (eth->
type() == ETH_TYPE_IP)
394 {
return (
const IpHdr *)(
p->data +
sizeof(eth_hdr) +
411 operator bool()
const {
return (
p !=
nullptr); }
420 uint16_t
cksum(
const IpPtr &ptr);
422 struct IpOpt :
public ip_opt
424 uint8_t
type()
const {
return opt_type; }
425 uint8_t
typeNumber()
const {
return IP_OPT_NUMBER(opt_type); }
426 uint8_t
typeClass()
const {
return IP_OPT_CLASS(opt_type); }
427 uint8_t
typeCopied()
const {
return IP_OPT_COPIED(opt_type); }
428 uint8_t
len()
const {
return IP_OPT_TYPEONLY(
type()) ? 1 : opt_len; }
434 const uint8_t *
data()
const {
return opt_data.data8; }
435 void sec(ip_opt_data_sec &
sec)
const;
436 void lsrr(ip_opt_data_rr &
rr)
const;
437 void ssrr(ip_opt_data_rr &
rr)
const;
438 void ts(ip_opt_data_ts &
ts)
const;
439 uint16_t
satid()
const {
return ntohs(opt_data.satid); }
440 uint16_t
mtup()
const {
return ntohs(opt_data.mtu); }
441 uint16_t
mtur()
const {
return ntohs(opt_data.mtu); }
442 void tr(ip_opt_data_tr &
tr)
const;
443 uint16_t
rtralt()
const {
return ntohs(opt_data.rtralt); }
454 uint32_t
flow()
const {
return ntohl(ip6_flow); }
455 uint16_t
plen()
const {
return ntohs(ip6_plen); }
456 uint16_t
hlen()
const {
return IP6_HDR_LEN; }
457 uint8_t
nxt()
const {
return ip6_nxt; }
458 uint8_t
hlim()
const {
return ip6_hlim; }
460 const uint8_t*
src()
const {
return ip6_src.data; }
461 const uint8_t*
dst()
const {
return ip6_dst.data; }
468 uint8_t
proto()
const;
470 void plen(uint16_t _plen) { ip6_plen = htons(_plen); }
473 const uint8_t *
bytes()
const {
return (
const uint8_t *)
this; }
476 uint8_t *
bytes() {
return (uint8_t *)
this; }
496 if (eth->
type() == ETH_TYPE_IPV6)
520 {
return (
const Ip6Hdr *)(
p->data +
sizeof(eth_hdr)
530 {
set(ptr);
return *
this; }
532 {
set(ptr.
p);
return *
this; }
534 {
p = ptr.
p;
return *
this; }
544 operator bool()
const {
return (
p !=
nullptr); }
565 #define HOME_ADDRESS_OPTION 0xC9
614 uint16_t
sport()
const {
return ntohs(th_sport); }
615 uint16_t
dport()
const {
return ntohs(th_dport); }
616 uint32_t
seq()
const {
return ntohl(th_seq); }
617 uint32_t
ack()
const {
return ntohl(th_ack); }
618 uint8_t
off()
const {
return th_off*4; }
619 uint8_t
flags()
const {
return th_flags & 0x3f; }
620 uint16_t
win()
const {
return ntohs(th_win); }
621 uint16_t
sum()
const {
return th_sum; }
622 uint16_t
urp()
const {
return ntohs(th_urp); }
625 void seq(uint32_t _seq) { th_seq = htonl(_seq); }
626 void flags(uint8_t _flags) { th_flags = _flags; }
631 const uint8_t *
bytes()
const {
return (
const uint8_t *)
this; }
633 uint8_t *
bytes() {
return (uint8_t *)
this; }
646 if (ptr && ptr->
proto() == IP_PROTO_TCP)
653 if (ptr && ptr->
proto() == IP_PROTO_TCP)
683 {
set(
i);
return *
this; }
685 {
set(
t.p,
t._off);
return *
this; }
695 operator bool()
const {
return (
p !=
nullptr); }
704 uint16_t
cksum(
const TcpPtr &ptr);
708 uint8_t
type()
const {
return opt_type; }
709 uint8_t
len()
const {
return TCP_OPT_TYPEONLY(
type()) ? 1 : opt_len; }
713 const uint8_t *
data()
const {
return opt_data.data8; }
715 uint16_t
mss()
const {
return ntohs(opt_data.mss); }
716 uint8_t
wscale()
const {
return opt_data.wscale; }
717 uint32_t
echo()
const {
return ntohl(opt_data.echo); }
718 uint32_t
tsval()
const {
return ntohl(opt_data.timestamp[0]); }
719 uint32_t
tsecr()
const {
return ntohl(opt_data.timestamp[1]); }
720 uint32_t
cc()
const {
return ntohl(opt_data.cc); }
721 uint8_t
cksum()
const{
return opt_data.cksum; }
722 const uint8_t *
md5()
const {
return opt_data.md5; }
725 const uint8_t *
bytes()
const {
return (
const uint8_t *)
this; }
727 uint8_t *
bytes() {
return (uint8_t *)
this; }
736 uint16_t
sport()
const {
return ntohs(uh_sport); }
737 uint16_t
dport()
const {
return ntohs(uh_dport); }
738 uint16_t
len()
const {
return ntohs(uh_ulen); }
739 uint16_t
sum()
const {
return uh_sum; }
742 void len(uint16_t _len) { uh_ulen = htons(_len); }
744 int size()
const {
return sizeof(udp_hdr); }
745 const uint8_t *
bytes()
const {
return (
const uint8_t *)
this; }
747 uint8_t *
bytes() {
return (uint8_t *)
this; }
760 if (ptr && ptr->
proto() == IP_PROTO_UDP)
767 if (ptr && ptr->
proto() == IP_PROTO_UDP)
797 {
set(
t.p,
t._off);
return *
this; }
807 operator bool()
const {
return (
p !=
nullptr); }
819 uint16_t
cksum(
const UdpPtr &ptr);
829 #endif // __BASE_INET_HH__
const Ip6Hdr * operator->() const
int extensionLength() const
const IpHdr * get() const
bool options(std::vector< const IpOpt * > &vec) const
bool options(std::vector< const TcpOpt * > &vec) const
const UdpHdr * get() const
bool operator==(const EthAddr &left, const EthAddr &right)
const uint8_t * bytes() const
const uint8_t * bytes() const
void set(const EthPacketPtr &ptr, int offset)
const Ip6Opt * getExt(uint8_t ext) const
void set(const IpPtr &ptr)
const Ip6Ptr & operator=(const EthPacketPtr &ptr)
const TcpHdr * get() const
const EthHdr * operator->() const
uint16_t fragmentOfflg() const
const TcpHdr * operator->() const
const IpPtr & operator=(const EthPtr &ptr)
void set(const Ip6Ptr &ptr)
const Ip6Opt * fragmentExt() const
const Ip6Hdr & operator*() const
const uint8_t * bytes() const
IpAddress(const uint32_t __ip)
struct ip6_opt_routing_type2 rtType2
uint8_t rtType2Type() const
void tr(ip_opt_data_tr &tr) const
const EthPacketPtr packet() const
const EthPacketPtr packet() const
uint8_t dstOptType() const
void ssrr(ip_opt_data_rr &rr) const
const uint8_t * bytes() const
uint16_t frag_off() const
const Ip6Hdr * get() const
const uint8_t * dstOptAddr() const
const uint8_t * payload() const
const UdpPtr & operator=(const IpPtr &i)
IpNetmask(const uint32_t __ip, const uint8_t __netmask)
Ip6Ptr(const Ip6Ptr &ptr)
const TcpHdr & operator*() const
bool isClass(int cls) const
void sec(ip_opt_data_sec &sec) const
const Ip6Opt * rtTypeExt() const
uint8_t typeClass() const
void ts(ip_opt_data_ts &ts) const
void flags(uint8_t _flags)
void set(const IpPtr &ptr)
const EthPacketPtr packet() const
uint8_t typeNumber() const
const UdpHdr * operator->() const
void set(const EthPacketPtr &ptr)
const EthAddr & dst() const
uint16_t frag_flags() const
const EthAddr & src() const
const uint8_t * addr() const
const uint8_t * src() const
const uint8_t * payload() const
UdpPtr(const UdpPtr &ptr)
const uint8_t * bytes() const
const Ip6Opt * dstOptExt() const
void set(const EthPacketPtr &ptr, int offset)
uint16_t __tu_cksum6(const Ip6Ptr &ip6)
uint32_t fragmentIdent() const
void plen(uint16_t _plen)
union Net::ip6_opt_hdr::@26 ext_data
void sdb(std::vector< uint32_t > &vec) const
const IpPtr & operator=(const EthPacketPtr &ptr)
void set(const EthPacketPtr &ptr)
const Ip6Ptr & operator=(const EthPtr &ptr)
uint8_t rtType2SegLft() const
uint8_t typeCopied() const
uint16_t __tu_cksum(const IpPtr &ip)
const uint8_t * payload() const
bool isCopied(int cpy) const
const EthAddr & operator=(const eth_addr &ea)
uint16_t cksum(const IpPtr &ptr)
const TcpPtr & operator=(const TcpPtr &t)
const uint8_t * dst() const
const UdpPtr & operator=(const UdpPtr &t)
const Ip6Ptr & operator=(const Ip6Ptr &ptr)
const uint8_t * payload() const
TcpPtr(const TcpPtr &ptr)
const uint8_t * md5() const
Ip6Ptr(const EthPacketPtr &ptr)
Ip6Ptr(const EthPtr &ptr)
struct ip6_opt_dstopts dstOpts
const TcpPtr & operator=(const IpPtr &i)
EthPtr(const EthPacketPtr &ptr)
std::shared_ptr< EthPacketData > EthPacketPtr
std::string string() const
std::string string() const
const IpPtr & operator=(const IpPtr &ptr)
const IpHdr * operator->() const
std::string string() const
const UdpHdr & operator*() const
TcpPtr(const Ip6Ptr &ptr)
void set(const Ip6Ptr &ptr)
const EthPtr & operator=(const EthPacketPtr &ptr)
std::string string() const
IpPtr(const EthPacketPtr &ptr)
const IpHdr & operator*() const
uint8_t dstOptLength() const
const EthHdr & operator*() const
const EthPacketPtr packet() const
const uint8_t * rtType2Addr() const
void lsrr(ip_opt_data_rr &rr) const
struct ip6_opt_fragment fragment
bool isopt(int opt) const
const uint8_t * bytes() const
int hsplit(const EthPacketPtr &ptr)
const uint8_t * payload() const
const uint8_t * data() const
UdpPtr(const Ip6Ptr &ptr)
void parse(const std::string &addr)
const uint8_t * data() const
bool isNumber(int num) const
const EthPacketPtr packet() const
Net::Ip6Opt __attribute__
const uint8_t * bytes() const
IpWithPort(const uint32_t __ip, const uint16_t __port)
const uint8_t * payload() const
ostream & operator<<(ostream &stream, const EthAddr &ea)
Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17