gem5  v22.1.0.0
inet.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2002-2005 The Regents of The University of Michigan
15  * Copyright (c) 2010 Advanced Micro Devices, Inc.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 #ifndef __BASE_INET_HH__
43 #define __BASE_INET_HH__
44 
45 #include <iosfwd>
46 #include <string>
47 #include <utility>
48 #include <vector>
49 
50 #include "base/compiler.hh"
51 #include "base/types.hh"
52 #include "dev/net/etherpkt.hh"
53 #include "dnet/os.h"
54 #include "dnet/eth.h"
55 #include "dnet/ip.h"
56 #include "dnet/ip6.h"
57 #include "dnet/addr.h"
58 #include "dnet/arp.h"
59 #include "dnet/icmp.h"
60 #include "dnet/tcp.h"
61 #include "dnet/udp.h"
62 #include "dnet/intf.h"
63 #include "dnet/route.h"
64 #include "dnet/fw.h"
65 #include "dnet/blob.h"
66 #include "dnet/rand.h"
67 
68 namespace gem5
69 {
70 
71 GEM5_DEPRECATED_NAMESPACE(Net, networking);
72 namespace networking
73 {
74 
75 /*
76  * Ethernet Stuff
77  */
78 struct EthAddr : protected eth_addr
79 {
80  protected:
81  void parse(const std::string &addr);
82 
83  public:
88  EthAddr();
89  EthAddr(const uint8_t ea[ETH_ADDR_LEN]);
90  EthAddr(const eth_addr &ea);
91  EthAddr(const std::string &addr);
92  const EthAddr &operator=(const eth_addr &ea);
93  const EthAddr &operator=(const std::string &addr); // end of api_inet
95 
99  int size() const { return sizeof(eth_addr); }
100 
101 
106  const uint8_t *bytes() const { return &data[0]; }
107  uint8_t *bytes() { return &data[0]; } // end of api_inet
109 
114  const uint8_t *addr() const { return &data[0]; }
115  bool unicast() const { return !(data[0] & 0x01); }
116  bool multicast() const { return !unicast() && !broadcast(); }
117  bool broadcast() const
118  {
119  bool isBroadcast = true;
120  for (int i = 0; i < ETH_ADDR_LEN; ++i) {
121  isBroadcast = isBroadcast && data[i] == 0xff;
122  }
123 
124  return isBroadcast;
125  } // end of api_inet
127 
131  std::string string() const;
132 
136  operator uint64_t() const
137  {
138  uint64_t reg = 0;
139  reg |= ((uint64_t)data[0]) << 40;
140  reg |= ((uint64_t)data[1]) << 32;
141  reg |= ((uint64_t)data[2]) << 24;
142  reg |= ((uint64_t)data[3]) << 16;
143  reg |= ((uint64_t)data[4]) << 8;
144  reg |= ((uint64_t)data[5]) << 0;
145  return reg;
146  }
147 
148 };
149 
154 std::ostream &operator<<(std::ostream &stream, const EthAddr &ea);
155 bool operator==(const EthAddr &left, const EthAddr &right); // end of api_inet
157 
158 struct EthHdr : public eth_hdr
159 {
160  bool isVlan() const { return (ntohs(eth_type) == ETH_TYPE_8021Q); }
161  uint16_t type() const {
162  if (!isVlan())
163  return ntohs(eth_type);
164  else
165  // L3 type is now 16 bytes into the hdr with 802.1Q
166  // instead of 12. dnet/eth.h only supports 802.1
167  return ntohs(*((uint16_t*)(((uint8_t *)this) + 16)));
168  }
169  uint16_t vlanId() const {
170  if (isVlan())
171  return ntohs(*((uint16_t*)(((uint8_t *)this) + 14)));
172  else
173  return 0x0000;
174  }
175 
176  const EthAddr &src() const { return *(EthAddr *)&eth_src; }
177  const EthAddr &dst() const { return *(EthAddr *)&eth_dst; }
178 
179  int size() const {
180  if (!isVlan())
181  return sizeof(eth_hdr);
182  else
183  return (sizeof(eth_hdr)+4);
184  }
185 
186  const uint8_t *bytes() const { return (const uint8_t *)this; }
187  const uint8_t *payload() const { return bytes() + size(); }
188  uint8_t *bytes() { return (uint8_t *)this; }
189  uint8_t *payload() { return bytes() + size(); }
190 };
191 
192 class EthPtr
193 {
194  protected:
195  friend class IpPtr;
196  friend class Ip6Ptr;
198 
199  public:
204  EthPtr() {}
205  EthPtr(const EthPacketPtr &ptr) : p(ptr) { } // end of api_inet
207 
208  EthHdr *operator->() { return (EthHdr *)p->data; }
209  EthHdr &operator*() { return *(EthHdr *)p->data; }
210  operator EthHdr *() { return (EthHdr *)p->data; }
211 
212  const EthHdr *operator->() const { return (const EthHdr *)p->data; }
213  const EthHdr &operator*() const { return *(const EthHdr *)p->data; }
214  operator const EthHdr *() const { return (const EthHdr *)p->data; }
215 
219  const EthPtr &operator=(const EthPacketPtr &ptr) { p = ptr; return *this; }
220 
225  const EthPacketPtr packet() const { return p; }
226  EthPacketPtr packet() { return p; }
227  bool operator!() const { return !p; }
228  operator bool() const { return (p != nullptr); }
229  int off() const { return 0; }
230  int pstart() const { return off() + ((const EthHdr*)p->data)->size(); } // end of api_inet
232 };
233 
234 /*
235  * IP Stuff
236  */
237 struct IpAddress
238 {
239  protected:
240  uint32_t _ip;
241 
242  public:
247  IpAddress() : _ip(0)
248  {}
249  IpAddress(const uint32_t __ip) : _ip(__ip)
250  {} // end of api_net
252 
256  uint32_t ip() const { return _ip; }
257 
261  std::string string() const;
262 };
263 
268 std::ostream &operator<<(std::ostream &stream, const IpAddress &ia);
269 bool operator==(const IpAddress &left, const IpAddress &right); // end of api_inet
271 
272 struct IpNetmask : public IpAddress
273 {
274  protected:
275  uint8_t _netmask;
276 
277  public:
279  {}
280  IpNetmask(const uint32_t __ip, const uint8_t __netmask) :
281  IpAddress(__ip), _netmask(__netmask)
282  {}
283 
287  uint8_t netmask() const { return _netmask; }
288 
289  std::string string() const;
290 };
291 
296 std::ostream &operator<<(std::ostream &stream, const IpNetmask &in);
297 bool operator==(const IpNetmask &left, const IpNetmask &right); // end of api_inet
299 
300 struct IpWithPort : public IpAddress
301 {
302  protected:
303  uint16_t _port;
304 
305  public:
307  {}
308  IpWithPort(const uint32_t __ip, const uint16_t __port) :
309  IpAddress(__ip), _port(__port)
310  {}
311 
315  uint8_t port() const { return _port; }
316 
317  std::string string() const;
318 };
319 
324 std::ostream &operator<<(std::ostream &stream, const IpWithPort &iwp);
325 bool operator==(const IpWithPort &left, const IpWithPort &right); // end of api_inet
327 
328 struct IpOpt;
329 struct IpHdr : public ip_hdr
330 {
331  uint8_t version() const { return ip_v; }
332  uint8_t hlen() const { return ip_hl * 4; }
333  uint8_t tos() const { return ip_tos; }
334  uint16_t len() const { return ntohs(ip_len); }
335  uint16_t id() const { return ntohs(ip_id); }
336  uint16_t frag_flags() const { return ntohs(ip_off) >> 13; }
337  uint16_t frag_off() const { return ntohs(ip_off) & 0x1fff; }
338  uint8_t ttl() const { return ip_ttl; }
339  uint8_t proto() const { return ip_p; }
340  uint16_t sum() const { return ip_sum; }
341  uint32_t src() const { return ntohl(ip_src); }
342  uint32_t dst() const { return ntohl(ip_dst); }
343 
344  void sum(uint16_t sum) { ip_sum = sum; }
345  void id(uint16_t _id) { ip_id = htons(_id); }
346  void len(uint16_t _len) { ip_len = htons(_len); }
347 
349 
350  int size() const { return hlen(); }
351  const uint8_t *bytes() const { return (const uint8_t *)this; }
352  const uint8_t *payload() const { return bytes() + size(); }
353  uint8_t *bytes() { return (uint8_t *)this; }
354  uint8_t *payload() { return bytes() + size(); }
355 };
356 
357 class IpPtr
358 {
359  protected:
360  friend class TcpPtr;
361  friend class UdpPtr;
364 
365  void set(const EthPacketPtr &ptr)
366  {
367  p = 0;
368  eth_hdr_vlan = false;
369 
370  if (ptr) {
371  EthHdr *eth = (EthHdr *)ptr->data;
372  if (eth->type() == ETH_TYPE_IP)
373  p = ptr;
374  if (eth->isVlan())
375  eth_hdr_vlan = true;
376  }
377  }
378 
379  public:
384  IpPtr() : p(0), eth_hdr_vlan(false) {}
385  IpPtr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
386  IpPtr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
387  IpPtr(const IpPtr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { } // end of api_inet
389 
390  IpHdr *get() { return (IpHdr *)(p->data + sizeof(eth_hdr) +
391  ((eth_hdr_vlan) ? 4 : 0)); }
392  IpHdr *operator->() { return get(); }
393  IpHdr &operator*() { return *get(); }
394 
399  const IpHdr *get() const
400  { return (const IpHdr *)(p->data + sizeof(eth_hdr) +
401  ((eth_hdr_vlan) ? 4 : 0)); }
402  const IpHdr *operator->() const { return get(); }
403  const IpHdr &operator*() const { return *get(); } // end of api_inet
405 
406  const IpPtr &operator=(const EthPacketPtr &ptr) { set(ptr); return *this; }
407  const IpPtr &operator=(const EthPtr &ptr) { set(ptr.p); return *this; }
408  const IpPtr &operator=(const IpPtr &ptr) { p = ptr.p; return *this; }
409 
414  const EthPacketPtr packet() const { return p; }
415  EthPacketPtr packet() { return p; }
416  bool operator!() const { return !p; }
417  operator bool() const { return (p != nullptr); }
418  int off() const { return (sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0)); }
419  int pstart() const { return (off() + get()->size()); } // end of api_inet
421 };
422 
426 uint16_t cksum(const IpPtr &ptr);
427 
428 struct IpOpt : public ip_opt
429 {
430  uint8_t type() const { return opt_type; }
431  uint8_t typeNumber() const { return IP_OPT_NUMBER(opt_type); }
432  uint8_t typeClass() const { return IP_OPT_CLASS(opt_type); }
433  uint8_t typeCopied() const { return IP_OPT_COPIED(opt_type); }
434  uint8_t len() const { return IP_OPT_TYPEONLY(type()) ? 1 : opt_len; }
435 
436  bool isNumber(int num) const { return typeNumber() == IP_OPT_NUMBER(num); }
437  bool isClass(int cls) const { return typeClass() == IP_OPT_CLASS(cls); }
438  bool isCopied(int cpy) const { return typeCopied() == IP_OPT_COPIED(cpy); }
439 
440  const uint8_t *data() const { return opt_data.data8; }
441  void sec(ip_opt_data_sec &sec) const;
442  void lsrr(ip_opt_data_rr &rr) const;
443  void ssrr(ip_opt_data_rr &rr) const;
444  void ts(ip_opt_data_ts &ts) const;
445  uint16_t satid() const { return ntohs(opt_data.satid); }
446  uint16_t mtup() const { return ntohs(opt_data.mtu); }
447  uint16_t mtur() const { return ntohs(opt_data.mtu); }
448  void tr(ip_opt_data_tr &tr) const;
449  uint16_t rtralt() const { return ntohs(opt_data.rtralt); }
451 };
452 
453 /*
454  * Ip6 Classes
455  */
456 struct Ip6Opt;
457 struct Ip6Hdr : public ip6_hdr
458 {
459  uint8_t version() const { return ip6_vfc; }
460  uint32_t flow() const { return ntohl(ip6_flow); }
461  uint16_t plen() const { return ntohs(ip6_plen); }
462  uint16_t hlen() const { return IP6_HDR_LEN; }
463  uint8_t nxt() const { return ip6_nxt; }
464  uint8_t hlim() const { return ip6_hlim; }
465 
466  const uint8_t* src() const { return ip6_src.data; }
467  const uint8_t* dst() const { return ip6_dst.data; }
468 
469  int extensionLength() const;
470  const Ip6Opt* getExt(uint8_t ext) const;
471  const Ip6Opt* fragmentExt() const { return getExt(IP_PROTO_FRAGMENT); }
472  const Ip6Opt* rtTypeExt() const { return getExt(IP_PROTO_ROUTING); }
473  const Ip6Opt* dstOptExt() const { return getExt(IP_PROTO_DSTOPTS); }
474  uint8_t proto() const;
475 
476  void plen(uint16_t _plen) { ip6_plen = htons(_plen); }
477 
478  int size() const { return IP6_HDR_LEN + extensionLength(); }
479  const uint8_t *bytes() const { return (const uint8_t *)this; }
480  const uint8_t *payload() const { return bytes() + IP6_HDR_LEN
481  + extensionLength(); }
482  uint8_t *bytes() { return (uint8_t *)this; }
483  uint8_t *payload() { return bytes() + IP6_HDR_LEN
484  + extensionLength(); }
485 };
486 
487 class Ip6Ptr
488 {
489  protected:
490  friend class TcpPtr;
491  friend class UdpPtr;
494 
495  void set(const EthPacketPtr &ptr)
496  {
497  p = 0;
498  eth_hdr_vlan = false;
499 
500  if (ptr) {
501  EthHdr *eth = (EthHdr *)ptr->data;
502  if (eth->type() == ETH_TYPE_IPV6)
503  p = ptr;
504  if (eth->isVlan())
505  eth_hdr_vlan = true;
506  }
507  }
508 
509  public:
514  Ip6Ptr() : p(0), eth_hdr_vlan(false) {}
515  Ip6Ptr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
516  Ip6Ptr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
517  Ip6Ptr(const Ip6Ptr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { } // end of api_inet
519 
520  Ip6Hdr *get() { return (Ip6Hdr *)(p->data + sizeof(eth_hdr)
521  + ((eth_hdr_vlan) ? 4 : 0)); }
522  Ip6Hdr *operator->() { return get(); }
523  Ip6Hdr &operator*() { return *get(); }
524 
525  const Ip6Hdr *get() const
526  { return (const Ip6Hdr *)(p->data + sizeof(eth_hdr)
527  + ((eth_hdr_vlan) ? 4 : 0)); }
528  const Ip6Hdr *operator->() const { return get(); }
529  const Ip6Hdr &operator*() const { return *get(); }
530 
535  const Ip6Ptr &operator=(const EthPacketPtr &ptr)
536  { set(ptr); return *this; }
537  const Ip6Ptr &operator=(const EthPtr &ptr)
538  { set(ptr.p); return *this; }
539  const Ip6Ptr &operator=(const Ip6Ptr &ptr)
540  { p = ptr.p; return *this; } // end of api_inet
542 
547  const EthPacketPtr packet() const { return p; }
548  EthPacketPtr packet() { return p; }
549  bool operator!() const { return !p; }
550  operator bool() const { return (p != nullptr); }
551  int off() const { return sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0); }
552  int pstart() const { return off() + get()->size(); } // end of api_inet
554 };
555 
556 // Dnet supplied ipv6 opt header is incomplete and
557 // newer NIC card filters expect a more robust
558 // ipv6 header option declaration.
560 {
561  uint16_t offlg;
562  uint32_t ident;
563 };
564 
566 {
567  uint8_t type;
568  uint8_t segleft;
569  uint32_t reserved;
570  ip6_addr_t addr;
571 };
572 
574 {
575  uint8_t type;
576  uint8_t length;
577  ip6_addr_t addr;
578 };
579 
581 {
582  uint8_t ext_nxt;
583  uint8_t ext_len;
584  union
585  {
586  struct ip6_opt_fragment fragment;
587  struct ip6_opt_routing_type2 rtType2;
588  struct ip6_opt_dstopts dstOpts;
589  } ext_data;
590 };
591 
592 struct Ip6Opt : public ip6_opt_hdr
593 {
594  uint8_t nxt() const { return ext_nxt; }
595  uint8_t extlen() const { return ext_len; }
596  uint8_t len() const { return extlen() + 8; }
597 
598  // Supporting the types of header extensions likely to be encountered:
599  // fragment, routing type 2 and dstopts.
600 
601  // Routing type 2
602  uint8_t rtType2Type() const { return ext_data.rtType2.type; }
603  uint8_t rtType2SegLft() const { return ext_data.rtType2.segleft; }
604  const uint8_t* rtType2Addr() const { return ext_data.rtType2.addr.data; }
605 
606  // Fragment
607  uint16_t fragmentOfflg() const { return ntohs(ext_data.fragment.offlg); }
608  uint32_t fragmentIdent() const { return ntohl(ext_data.fragment.ident); }
609 
610  // Dst Options/Home Address Option
611  uint8_t dstOptType() const { return ext_data.dstOpts.type; }
612  uint8_t dstOptLength() const { return ext_data.dstOpts.length; }
613  const uint8_t* dstOptAddr() const { return ext_data.dstOpts.addr.data; }
614 };
615 
616 
617 /*
618  * TCP Stuff
619  */
620 struct TcpOpt;
621 struct TcpHdr : public tcp_hdr
622 {
623  uint16_t sport() const { return ntohs(th_sport); }
624  uint16_t dport() const { return ntohs(th_dport); }
625  uint32_t seq() const { return ntohl(th_seq); }
626  uint32_t ack() const { return ntohl(th_ack); }
627  uint8_t off() const { return th_off*4; }
628  uint8_t flags() const { return th_flags & 0x3f; }
629  uint16_t win() const { return ntohs(th_win); }
630  uint16_t sum() const { return th_sum; }
631  uint16_t urp() const { return ntohs(th_urp); }
632 
633  void sum(uint16_t sum) { th_sum = sum; }
634  void seq(uint32_t _seq) { th_seq = htonl(_seq); }
635  void flags(uint8_t _flags) { th_flags = _flags; }
636 
638 
639  int size() const { return off(); }
640  const uint8_t *bytes() const { return (const uint8_t *)this; }
641  const uint8_t *payload() const { return bytes() + size(); }
642  uint8_t *bytes() { return (uint8_t *)this; }
643  uint8_t *payload() { return bytes() + size(); }
644 };
645 
646 class TcpPtr
647 {
648  protected:
650  int _off;
651 
652  void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
653  void set(const IpPtr &ptr)
654  {
655  if (ptr && ptr->proto() == IP_PROTO_TCP)
656  set(ptr.p, ptr.pstart());
657  else
658  set(0, 0);
659  }
660  void set(const Ip6Ptr &ptr)
661  {
662  if (ptr && ptr->proto() == IP_PROTO_TCP)
663  set(ptr.p, ptr.pstart());
664  else
665  set(0, 0);
666  }
667 
668  public:
673  TcpPtr() : p(0), _off(0) {}
674  TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
675  TcpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
676  TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {} // end of api_inet
678 
679  TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
680  TcpHdr *operator->() { return get(); }
681  TcpHdr &operator*() { return *get(); }
682 
683  const TcpHdr *get() const { return (const TcpHdr *)(p->data + _off); }
684  const TcpHdr *operator->() const { return get(); }
685  const TcpHdr &operator*() const { return *get(); }
686 
691  const TcpPtr &operator=(const IpPtr &i)
692  { set(i); return *this; }
693  const TcpPtr &operator=(const TcpPtr &t)
694  { set(t.p, t._off); return *this; } // end of api_inet
696 
701  const EthPacketPtr packet() const { return p; }
702  EthPacketPtr packet() { return p; }
703  bool operator!() const { return !p; }
704  operator bool() const { return (p != nullptr); }
705  int off() const { return _off; }
706  int pstart() const { return off() + get()->size(); } // end of api_inet
708 };
709 
713 uint16_t cksum(const TcpPtr &ptr);
714 
715 struct TcpOpt : public tcp_opt
716 {
717  uint8_t type() const { return opt_type; }
718  uint8_t len() const { return TCP_OPT_TYPEONLY(type()) ? 1 : opt_len; }
719 
720  bool isopt(int opt) const { return type() == opt; }
721 
722  const uint8_t *data() const { return opt_data.data8; }
723 
724  uint16_t mss() const { return ntohs(opt_data.mss); }
725  uint8_t wscale() const { return opt_data.wscale; }
726  uint32_t echo() const { return ntohl(opt_data.echo); }
727  uint32_t tsval() const { return ntohl(opt_data.timestamp[0]); }
728  uint32_t tsecr() const { return ntohl(opt_data.timestamp[1]); }
729  uint32_t cc() const { return ntohl(opt_data.cc); }
730  uint8_t cksum() const{ return opt_data.cksum; }
731  const uint8_t *md5() const { return opt_data.md5; }
732 
733  int size() const { return len(); }
734  const uint8_t *bytes() const { return (const uint8_t *)this; }
735  const uint8_t *payload() const { return bytes() + size(); }
736  uint8_t *bytes() { return (uint8_t *)this; }
737  uint8_t *payload() { return bytes() + size(); }
738 };
739 
740 /*
741  * UDP Stuff
742  */
743 struct UdpHdr : public udp_hdr
744 {
745  uint16_t sport() const { return ntohs(uh_sport); }
746  uint16_t dport() const { return ntohs(uh_dport); }
747  uint16_t len() const { return ntohs(uh_ulen); }
748  uint16_t sum() const { return uh_sum; }
749 
750  void sum(uint16_t sum) { uh_sum = sum; }
751  void len(uint16_t _len) { uh_ulen = htons(_len); }
752 
753  int size() const { return sizeof(udp_hdr); }
754  const uint8_t *bytes() const { return (const uint8_t *)this; }
755  const uint8_t *payload() const { return bytes() + size(); }
756  uint8_t *bytes() { return (uint8_t *)this; }
757  uint8_t *payload() { return bytes() + size(); }
758 };
759 
760 class UdpPtr
761 {
762  protected:
764  int _off;
765 
766  void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
767  void set(const IpPtr &ptr)
768  {
769  if (ptr && ptr->proto() == IP_PROTO_UDP)
770  set(ptr.p, ptr.pstart());
771  else
772  set(0, 0);
773  }
774  void set(const Ip6Ptr &ptr)
775  {
776  if (ptr && ptr->proto() == IP_PROTO_UDP)
777  set(ptr.p, ptr.pstart());
778  else
779  set(0, 0);
780  }
781 
782  public:
786  UdpPtr() : p(0), _off(0) {}
787  UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
788  UdpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
789  UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {} // end of api_inet
791 
792  UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
793  UdpHdr *operator->() { return get(); }
794  UdpHdr &operator*() { return *get(); }
795 
796  const UdpHdr *get() const { return (const UdpHdr *)(p->data + _off); }
797  const UdpHdr *operator->() const { return get(); }
798  const UdpHdr &operator*() const { return *get(); }
799 
804  const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
805  const UdpPtr &operator=(const UdpPtr &t)
806  { set(t.p, t._off); return *this; } // end of api_inet
808 
813  const EthPacketPtr packet() const { return p; }
814  EthPacketPtr packet() { return p; }
815  bool operator!() const { return !p; }
816  operator bool() const { return (p != nullptr); }
817  int off() const { return _off; }
818  int pstart() const { return off() + get()->size(); } // end of api_inet
820 };
821 
826 uint16_t __tu_cksum6(const Ip6Ptr &ip6);
827 uint16_t __tu_cksum(const IpPtr &ip);
828 uint16_t cksum(const UdpPtr &ptr); // end of api_inet
830 
834 int hsplit(const EthPacketPtr &ptr);
835 
836 } // namespace networking
837 } // namespace gem5
838 
839 #endif // __BASE_INET_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
const EthHdr * operator->() const
Definition: inet.hh:212
EthPacketPtr p
Definition: inet.hh:197
EthHdr * operator->()
Definition: inet.hh:208
EthHdr & operator*()
Definition: inet.hh:209
const EthHdr & operator*() const
Definition: inet.hh:213
const Ip6Hdr & operator*() const
Definition: inet.hh:529
const Ip6Hdr * operator->() const
Definition: inet.hh:528
EthPacketPtr p
Definition: inet.hh:492
void set(const EthPacketPtr &ptr)
Definition: inet.hh:495
Ip6Hdr * operator->()
Definition: inet.hh:522
Ip6Hdr & operator*()
Definition: inet.hh:523
const Ip6Hdr * get() const
Definition: inet.hh:525
IpHdr * operator->()
Definition: inet.hh:392
EthPacketPtr p
Definition: inet.hh:362
void set(const EthPacketPtr &ptr)
Definition: inet.hh:365
const IpPtr & operator=(const IpPtr &ptr)
Definition: inet.hh:408
const IpPtr & operator=(const EthPacketPtr &ptr)
Definition: inet.hh:406
IpHdr & operator*()
Definition: inet.hh:393
const IpPtr & operator=(const EthPtr &ptr)
Definition: inet.hh:407
EthPacketPtr p
Definition: inet.hh:649
TcpHdr & operator*()
Definition: inet.hh:681
void set(const EthPacketPtr &ptr, int offset)
Definition: inet.hh:652
void set(const Ip6Ptr &ptr)
Definition: inet.hh:660
TcpHdr * operator->()
Definition: inet.hh:680
const TcpHdr * get() const
Definition: inet.hh:683
const TcpHdr * operator->() const
Definition: inet.hh:684
const TcpHdr & operator*() const
Definition: inet.hh:685
void set(const IpPtr &ptr)
Definition: inet.hh:653
UdpPtr(const Ip6Ptr &ptr)
Definition: inet.hh:788
const UdpHdr * operator->() const
Definition: inet.hh:797
UdpHdr & operator*()
Definition: inet.hh:794
UdpPtr(const UdpPtr &ptr)
Definition: inet.hh:789
void set(const Ip6Ptr &ptr)
Definition: inet.hh:774
const UdpHdr & operator*() const
Definition: inet.hh:798
EthPacketPtr p
Definition: inet.hh:763
void set(const IpPtr &ptr)
Definition: inet.hh:767
void set(const EthPacketPtr &ptr, int offset)
Definition: inet.hh:766
UdpHdr * operator->()
Definition: inet.hh:793
UdpPtr(const IpPtr &ptr)
Definition: inet.hh:787
const UdpHdr * get() const
Definition: inet.hh:796
STL vector class.
Definition: stl.hh:37
uint8_t netmask() const
Definition: inet.hh:287
Ip6Ptr(const EthPacketPtr &ptr)
Definition: inet.hh:515
const EthPacketPtr packet() const
Definition: inet.hh:414
const IpHdr * operator->() const
Definition: inet.hh:402
int pstart() const
Definition: inet.hh:818
bool broadcast() const
Definition: inet.hh:117
const EthPacketPtr packet() const
Definition: inet.hh:225
bool operator!() const
Definition: inet.hh:416
bool operator!() const
Definition: inet.hh:703
uint16_t cksum(const IpPtr &ptr)
Definition: inet.cc:209
EthPacketPtr packet()
Definition: inet.hh:702
uint16_t __tu_cksum6(const Ip6Ptr &ip6)
Definition: inet.cc:226
int hsplit(const EthPacketPtr &ptr)
Definition: inet.cc:387
const TcpPtr & operator=(const TcpPtr &t)
Definition: inet.hh:693
const EthPacketPtr packet() const
Definition: inet.hh:813
const TcpPtr & operator=(const IpPtr &i)
Definition: inet.hh:691
bool multicast() const
Definition: inet.hh:116
int pstart() const
Definition: inet.hh:706
bool unicast() const
Definition: inet.hh:115
const Ip6Ptr & operator=(const Ip6Ptr &ptr)
Definition: inet.hh:539
uint16_t __tu_cksum(const IpPtr &ip)
Definition: inet.cc:216
uint8_t port() const
Definition: inet.hh:315
const UdpPtr & operator=(const UdpPtr &t)
Definition: inet.hh:805
std::string string() const
Definition: inet.cc:142
int size() const
Definition: inet.hh:99
EthPtr(const EthPacketPtr &ptr)
Definition: inet.hh:205
const EthPacketPtr packet() const
Definition: inet.hh:547
const EthPtr & operator=(const EthPacketPtr &ptr)
Definition: inet.hh:219
Ip6Ptr(const Ip6Ptr &ptr)
Definition: inet.hh:517
int pstart() const
Definition: inet.hh:230
TcpPtr(const IpPtr &ptr)
Definition: inet.hh:674
const IpHdr * get() const
Definition: inet.hh:399
bool operator==(const EthAddr &left, const EthAddr &right)
Definition: inet.cc:128
TcpPtr(const Ip6Ptr &ptr)
Definition: inet.hh:675
int off() const
Definition: inet.hh:229
int pstart() const
Definition: inet.hh:552
const UdpPtr & operator=(const IpPtr &i)
Definition: inet.hh:804
int off() const
Definition: inet.hh:551
EthPacketPtr packet()
Definition: inet.hh:814
const uint8_t * addr() const
Definition: inet.hh:114
bool operator!() const
Definition: inet.hh:549
IpPtr(const EthPtr &ptr)
Definition: inet.hh:386
int off() const
Definition: inet.hh:817
std::string string() const
Definition: inet.cc:120
int pstart() const
Definition: inet.hh:419
Ip6Ptr(const EthPtr &ptr)
Definition: inet.hh:516
const EthPacketPtr packet() const
Definition: inet.hh:701
std::ostream & operator<<(std::ostream &stream, const EthAddr &ea)
Definition: inet.cc:134
IpPtr(const IpPtr &ptr)
Definition: inet.hh:387
const Ip6Ptr & operator=(const EthPacketPtr &ptr)
Definition: inet.hh:535
EthPacketPtr packet()
Definition: inet.hh:226
EthPacketPtr packet()
Definition: inet.hh:415
const EthAddr & operator=(const eth_addr &ea)
Definition: inet.cc:84
const Ip6Ptr & operator=(const EthPtr &ptr)
Definition: inet.hh:537
IpPtr(const EthPacketPtr &ptr)
Definition: inet.hh:385
bool operator!() const
Definition: inet.hh:815
uint8_t * bytes()
Definition: inet.hh:107
bool operator!() const
Definition: inet.hh:227
const IpHdr & operator*() const
Definition: inet.hh:403
IpAddress(const uint32_t __ip)
Definition: inet.hh:249
int off() const
Definition: inet.hh:705
uint32_t ip() const
Definition: inet.hh:256
EthPacketPtr packet()
Definition: inet.hh:548
const uint8_t * bytes() const
Definition: inet.hh:106
TcpPtr(const TcpPtr &ptr)
Definition: inet.hh:676
int off() const
Definition: inet.hh:418
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 3 > ea
Definition: misc_types.hh:335
Bitfield< 14 > rr
Definition: misc_types.hh:375
Bitfield< 12 > ext
Definition: misc_types.hh:434
Bitfield< 14 > ip6
Bitfield< 18, 16 > ia
Bitfield< 25 > vec
Definition: misc.hh:113
Bitfield< 11, 7 > fragment
Definition: pagetable.hh:58
Bitfield< 51 > t
Definition: pagetable.hh:56
Bitfield< 5, 3 > reg
Definition: types.hh:92
bool ip(TxDesc *d)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
PM4 packets.
Definition: pm4_defines.hh:78
void parse(const std::string &addr)
Definition: inet.cc:98
uint8_t * payload()
Definition: inet.hh:189
uint8_t * bytes()
Definition: inet.hh:188
const uint8_t * bytes() const
Definition: inet.hh:186
int size() const
Definition: inet.hh:179
bool isVlan() const
Definition: inet.hh:160
const EthAddr & dst() const
Definition: inet.hh:177
const uint8_t * payload() const
Definition: inet.hh:187
uint16_t type() const
Definition: inet.hh:161
uint16_t vlanId() const
Definition: inet.hh:169
const EthAddr & src() const
Definition: inet.hh:176
const uint8_t * src() const
Definition: inet.hh:466
uint32_t flow() const
Definition: inet.hh:460
int size() const
Definition: inet.hh:478
const Ip6Opt * rtTypeExt() const
Definition: inet.hh:472
const uint8_t * dst() const
Definition: inet.hh:467
const Ip6Opt * fragmentExt() const
Definition: inet.hh:471
const uint8_t * payload() const
Definition: inet.hh:480
uint8_t nxt() const
Definition: inet.hh:463
uint16_t plen() const
Definition: inet.hh:461
uint16_t hlen() const
Definition: inet.hh:462
const Ip6Opt * getExt(uint8_t ext) const
Definition: inet.cc:323
const Ip6Opt * dstOptExt() const
Definition: inet.hh:473
uint8_t * bytes()
Definition: inet.hh:482
uint8_t version() const
Definition: inet.hh:459
uint8_t hlim() const
Definition: inet.hh:464
uint8_t proto() const
Definition: inet.cc:349
uint8_t * payload()
Definition: inet.hh:483
void plen(uint16_t _plen)
Definition: inet.hh:476
int extensionLength() const
Definition: inet.cc:300
const uint8_t * bytes() const
Definition: inet.hh:479
uint16_t fragmentOfflg() const
Definition: inet.hh:607
uint8_t nxt() const
Definition: inet.hh:594
uint8_t dstOptType() const
Definition: inet.hh:611
const uint8_t * rtType2Addr() const
Definition: inet.hh:604
const uint8_t * dstOptAddr() const
Definition: inet.hh:613
uint32_t fragmentIdent() const
Definition: inet.hh:608
uint8_t rtType2Type() const
Definition: inet.hh:602
uint8_t len() const
Definition: inet.hh:596
uint8_t extlen() const
Definition: inet.hh:595
uint8_t dstOptLength() const
Definition: inet.hh:612
uint8_t rtType2SegLft() const
Definition: inet.hh:603
uint16_t len() const
Definition: inet.hh:334
uint16_t frag_flags() const
Definition: inet.hh:336
uint8_t proto() const
Definition: inet.hh:339
uint8_t * payload()
Definition: inet.hh:354
void id(uint16_t _id)
Definition: inet.hh:345
uint8_t version() const
Definition: inet.hh:331
uint8_t hlen() const
Definition: inet.hh:332
uint8_t * bytes()
Definition: inet.hh:353
int size() const
Definition: inet.hh:350
const uint8_t * payload() const
Definition: inet.hh:352
void len(uint16_t _len)
Definition: inet.hh:346
uint16_t sum() const
Definition: inet.hh:340
uint16_t frag_off() const
Definition: inet.hh:337
uint8_t ttl() const
Definition: inet.hh:338
uint32_t src() const
Definition: inet.hh:341
const uint8_t * bytes() const
Definition: inet.hh:351
uint8_t tos() const
Definition: inet.hh:333
bool options(std::vector< const IpOpt * > &vec) const
Definition: inet.cc:263
uint32_t dst() const
Definition: inet.hh:342
uint16_t id() const
Definition: inet.hh:335
void sum(uint16_t sum)
Definition: inet.hh:344
IpNetmask(const uint32_t __ip, const uint8_t __netmask)
Definition: inet.hh:280
std::string string() const
Definition: inet.cc:166
bool isNumber(int num) const
Definition: inet.hh:436
uint16_t mtup() const
Definition: inet.hh:446
uint8_t len() const
Definition: inet.hh:434
uint8_t typeNumber() const
Definition: inet.hh:431
bool isClass(int cls) const
Definition: inet.hh:437
uint8_t typeClass() const
Definition: inet.hh:432
uint16_t mtur() const
Definition: inet.hh:447
uint16_t rtralt() const
Definition: inet.hh:449
const uint8_t * data() const
Definition: inet.hh:440
void sdb(std::vector< uint32_t > &vec) const
uint8_t type() const
Definition: inet.hh:430
void ssrr(ip_opt_data_rr &rr) const
void ts(ip_opt_data_ts &ts) const
uint8_t typeCopied() const
Definition: inet.hh:433
void sec(ip_opt_data_sec &sec) const
uint16_t satid() const
Definition: inet.hh:445
void tr(ip_opt_data_tr &tr) const
bool isCopied(int cpy) const
Definition: inet.hh:438
void lsrr(ip_opt_data_rr &rr) const
std::string string() const
Definition: inet.cc:188
IpWithPort(const uint32_t __ip, const uint16_t __port)
Definition: inet.hh:308
void sum(uint16_t sum)
Definition: inet.hh:633
uint8_t * payload()
Definition: inet.hh:643
const uint8_t * bytes() const
Definition: inet.hh:640
uint8_t * bytes()
Definition: inet.hh:642
bool options(std::vector< const TcpOpt * > &vec) const
Definition: inet.cc:366
uint16_t win() const
Definition: inet.hh:629
uint32_t ack() const
Definition: inet.hh:626
int size() const
Definition: inet.hh:639
uint16_t sum() const
Definition: inet.hh:630
void seq(uint32_t _seq)
Definition: inet.hh:634
uint16_t urp() const
Definition: inet.hh:631
uint32_t seq() const
Definition: inet.hh:625
const uint8_t * payload() const
Definition: inet.hh:641
void flags(uint8_t _flags)
Definition: inet.hh:635
uint8_t flags() const
Definition: inet.hh:628
uint16_t sport() const
Definition: inet.hh:623
uint8_t off() const
Definition: inet.hh:627
uint16_t dport() const
Definition: inet.hh:624
const uint8_t * bytes() const
Definition: inet.hh:734
uint8_t len() const
Definition: inet.hh:718
uint32_t cc() const
Definition: inet.hh:729
uint8_t cksum() const
Definition: inet.hh:730
uint8_t wscale() const
Definition: inet.hh:725
const uint8_t * md5() const
Definition: inet.hh:731
int size() const
Definition: inet.hh:733
const uint8_t * data() const
Definition: inet.hh:722
const uint8_t * payload() const
Definition: inet.hh:735
uint8_t * bytes()
Definition: inet.hh:736
uint8_t * payload()
Definition: inet.hh:737
uint32_t echo() const
Definition: inet.hh:726
uint8_t type() const
Definition: inet.hh:717
uint16_t mss() const
Definition: inet.hh:724
bool isopt(int opt) const
Definition: inet.hh:720
uint32_t tsval() const
Definition: inet.hh:727
uint32_t tsecr() const
Definition: inet.hh:728
const uint8_t * bytes() const
Definition: inet.hh:754
int size() const
Definition: inet.hh:753
uint16_t len() const
Definition: inet.hh:747
void sum(uint16_t sum)
Definition: inet.hh:750
uint16_t sum() const
Definition: inet.hh:748
const uint8_t * payload() const
Definition: inet.hh:755
uint16_t sport() const
Definition: inet.hh:745
uint8_t * bytes()
Definition: inet.hh:756
uint8_t * payload()
Definition: inet.hh:757
uint16_t dport() const
Definition: inet.hh:746
void len(uint16_t _len)
Definition: inet.hh:751
union gem5::networking::ip6_opt_hdr::@37 ext_data

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1