gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Nathan Binkert
42  * Steve Reinhardt
43  * Gabe Black
44  * Geoffrey Blake
45  */
46 
47 #ifndef __BASE_INET_HH__
48 #define __BASE_INET_HH__
49 
50 #include <iosfwd>
51 #include <string>
52 #include <utility>
53 #include <vector>
54 
55 #include "base/types.hh"
56 #include "dev/net/etherpkt.hh"
57 #include "dnet/os.h"
58 #include "dnet/eth.h"
59 #include "dnet/ip.h"
60 #include "dnet/ip6.h"
61 #include "dnet/addr.h"
62 #include "dnet/arp.h"
63 #include "dnet/icmp.h"
64 #include "dnet/tcp.h"
65 #include "dnet/udp.h"
66 #include "dnet/intf.h"
67 #include "dnet/route.h"
68 #include "dnet/fw.h"
69 #include "dnet/blob.h"
70 #include "dnet/rand.h"
71 
72 namespace Net {
73 
74 /*
75  * Ethernet Stuff
76  */
77 struct EthAddr : protected eth_addr
78 {
79  protected:
80  void parse(const std::string &addr);
81 
82  public:
83  EthAddr();
84  EthAddr(const uint8_t ea[ETH_ADDR_LEN]);
85  EthAddr(const eth_addr &ea);
86  EthAddr(const std::string &addr);
87  const EthAddr &operator=(const eth_addr &ea);
88  const EthAddr &operator=(const std::string &addr);
89 
90  int size() const { return sizeof(eth_addr); }
91 
92  const uint8_t *bytes() const { return &data[0]; }
93  uint8_t *bytes() { return &data[0]; }
94 
95  const uint8_t *addr() const { return &data[0]; }
96  bool unicast() const { return !(data[0] & 0x01); }
97  bool multicast() const { return !unicast() && !broadcast(); }
98  bool broadcast() const
99  {
100  bool isBroadcast = true;
101  for (int i = 0; i < ETH_ADDR_LEN; ++i) {
102  isBroadcast = isBroadcast && data[i] == 0xff;
103  }
104 
105  return isBroadcast;
106  }
107 
108  std::string string() const;
109 
110  operator uint64_t() const
111  {
112  uint64_t reg = 0;
113  reg |= ((uint64_t)data[0]) << 40;
114  reg |= ((uint64_t)data[1]) << 32;
115  reg |= ((uint64_t)data[2]) << 24;
116  reg |= ((uint64_t)data[3]) << 16;
117  reg |= ((uint64_t)data[4]) << 8;
118  reg |= ((uint64_t)data[5]) << 0;
119  return reg;
120  }
121 
122 };
123 
124 std::ostream &operator<<(std::ostream &stream, const EthAddr &ea);
125 bool operator==(const EthAddr &left, const EthAddr &right);
126 
127 struct EthHdr : public eth_hdr
128 {
129  bool isVlan() const { return (ntohs(eth_type) == ETH_TYPE_8021Q); }
130  uint16_t type() const {
131  if (!isVlan())
132  return ntohs(eth_type);
133  else
134  // L3 type is now 16 bytes into the hdr with 802.1Q
135  // instead of 12. dnet/eth.h only supports 802.1
136  return ntohs(*((uint16_t*)(((uint8_t *)this) + 16)));
137  }
138  uint16_t vlanId() const {
139  if (isVlan())
140  return ntohs(*((uint16_t*)(((uint8_t *)this) + 14)));
141  else
142  return 0x0000;
143  }
144 
145  const EthAddr &src() const { return *(EthAddr *)&eth_src; }
146  const EthAddr &dst() const { return *(EthAddr *)&eth_dst; }
147 
148  int size() const {
149  if (!isVlan())
150  return sizeof(eth_hdr);
151  else
152  return (sizeof(eth_hdr)+4);
153  }
154 
155  const uint8_t *bytes() const { return (const uint8_t *)this; }
156  const uint8_t *payload() const { return bytes() + size(); }
157  uint8_t *bytes() { return (uint8_t *)this; }
158  uint8_t *payload() { return bytes() + size(); }
159 };
160 
161 class EthPtr
162 {
163  protected:
164  friend class IpPtr;
165  friend class Ip6Ptr;
167 
168  public:
169  EthPtr() {}
170  EthPtr(const EthPacketPtr &ptr) : p(ptr) { }
171 
172  EthHdr *operator->() { return (EthHdr *)p->data; }
173  EthHdr &operator*() { return *(EthHdr *)p->data; }
174  operator EthHdr *() { return (EthHdr *)p->data; }
175 
176  const EthHdr *operator->() const { return (const EthHdr *)p->data; }
177  const EthHdr &operator*() const { return *(const EthHdr *)p->data; }
178  operator const EthHdr *() const { return (const EthHdr *)p->data; }
179 
180  const EthPtr &operator=(const EthPacketPtr &ptr) { p = ptr; return *this; }
181 
182  const EthPacketPtr packet() const { return p; }
183  EthPacketPtr packet() { return p; }
184  bool operator!() const { return !p; }
185  operator bool() const { return (p != nullptr); }
186  int off() const { return 0; }
187  int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
188 };
189 
190 /*
191  * IP Stuff
192  */
193 struct IpAddress
194 {
195  protected:
196  uint32_t _ip;
197 
198  public:
199  IpAddress() : _ip(0)
200  {}
201  IpAddress(const uint32_t __ip) : _ip(__ip)
202  {}
203 
204  uint32_t ip() const { return _ip; }
205 
206  std::string string() const;
207 };
208 
209 std::ostream &operator<<(std::ostream &stream, const IpAddress &ia);
210 bool operator==(const IpAddress &left, const IpAddress &right);
211 
212 struct IpNetmask : public IpAddress
213 {
214  protected:
215  uint8_t _netmask;
216 
217  public:
219  {}
220  IpNetmask(const uint32_t __ip, const uint8_t __netmask) :
221  IpAddress(__ip), _netmask(__netmask)
222  {}
223 
224  uint8_t netmask() const { return _netmask; }
225 
226  std::string string() const;
227 };
228 
229 std::ostream &operator<<(std::ostream &stream, const IpNetmask &in);
230 bool operator==(const IpNetmask &left, const IpNetmask &right);
231 
232 struct IpWithPort : public IpAddress
233 {
234  protected:
235  uint16_t _port;
236 
237  public:
239  {}
240  IpWithPort(const uint32_t __ip, const uint16_t __port) :
241  IpAddress(__ip), _port(__port)
242  {}
243 
244  uint8_t port() const { return _port; }
245 
246  std::string string() const;
247 };
248 
249 std::ostream &operator<<(std::ostream &stream, const IpWithPort &iwp);
250 bool operator==(const IpWithPort &left, const IpWithPort &right);
251 
252 struct IpOpt;
253 struct IpHdr : public ip_hdr
254 {
255  uint8_t version() const { return ip_v; }
256  uint8_t hlen() const { return ip_hl * 4; }
257  uint8_t tos() const { return ip_tos; }
258  uint16_t len() const { return ntohs(ip_len); }
259  uint16_t id() const { return ntohs(ip_id); }
260  uint16_t frag_flags() const { return ntohs(ip_off) >> 13; }
261  uint16_t frag_off() const { return ntohs(ip_off) & 0x1fff; }
262  uint8_t ttl() const { return ip_ttl; }
263  uint8_t proto() const { return ip_p; }
264  uint16_t sum() const { return ip_sum; }
265  uint32_t src() const { return ntohl(ip_src); }
266  uint32_t dst() const { return ntohl(ip_dst); }
267 
268  void sum(uint16_t sum) { ip_sum = sum; }
269  void id(uint16_t _id) { ip_id = htons(_id); }
270  void len(uint16_t _len) { ip_len = htons(_len); }
271 
272  bool options(std::vector<const IpOpt *> &vec) const;
273 
274  int size() const { return hlen(); }
275  const uint8_t *bytes() const { return (const uint8_t *)this; }
276  const uint8_t *payload() const { return bytes() + size(); }
277  uint8_t *bytes() { return (uint8_t *)this; }
278  uint8_t *payload() { return bytes() + size(); }
279 };
280 
281 class IpPtr
282 {
283  protected:
284  friend class TcpPtr;
285  friend class UdpPtr;
288 
289  void set(const EthPacketPtr &ptr)
290  {
291  p = 0;
292  eth_hdr_vlan = false;
293 
294  if (ptr) {
295  EthHdr *eth = (EthHdr *)ptr->data;
296  if (eth->type() == ETH_TYPE_IP)
297  p = ptr;
298  if (eth->isVlan())
299  eth_hdr_vlan = true;
300  }
301  }
302 
303  public:
304  IpPtr() : p(0), eth_hdr_vlan(false) {}
305  IpPtr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
306  IpPtr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
307  IpPtr(const IpPtr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { }
308 
309  IpHdr *get() { return (IpHdr *)(p->data + sizeof(eth_hdr) +
310  ((eth_hdr_vlan) ? 4 : 0)); }
311  IpHdr *operator->() { return get(); }
312  IpHdr &operator*() { return *get(); }
313 
314  const IpHdr *get() const
315  { return (const IpHdr *)(p->data + sizeof(eth_hdr) +
316  ((eth_hdr_vlan) ? 4 : 0)); }
317  const IpHdr *operator->() const { return get(); }
318  const IpHdr &operator*() const { return *get(); }
319 
320  const IpPtr &operator=(const EthPacketPtr &ptr) { set(ptr); return *this; }
321  const IpPtr &operator=(const EthPtr &ptr) { set(ptr.p); return *this; }
322  const IpPtr &operator=(const IpPtr &ptr) { p = ptr.p; return *this; }
323 
324  const EthPacketPtr packet() const { return p; }
325  EthPacketPtr packet() { return p; }
326  bool operator!() const { return !p; }
327  operator bool() const { return (p != nullptr); }
328  int off() const { return (sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0)); }
329  int pstart() const { return (off() + get()->size()); }
330 };
331 
332 uint16_t cksum(const IpPtr &ptr);
334 struct IpOpt : public ip_opt
335 {
336  uint8_t type() const { return opt_type; }
337  uint8_t typeNumber() const { return IP_OPT_NUMBER(opt_type); }
338  uint8_t typeClass() const { return IP_OPT_CLASS(opt_type); }
339  uint8_t typeCopied() const { return IP_OPT_COPIED(opt_type); }
340  uint8_t len() const { return IP_OPT_TYPEONLY(type()) ? 1 : opt_len; }
341 
342  bool isNumber(int num) const { return typeNumber() == IP_OPT_NUMBER(num); }
343  bool isClass(int cls) const { return typeClass() == IP_OPT_CLASS(cls); }
344  bool isCopied(int cpy) const { return typeCopied() == IP_OPT_COPIED(cpy); }
345 
346  const uint8_t *data() const { return opt_data.data8; }
347  void sec(ip_opt_data_sec &sec) const;
348  void lsrr(ip_opt_data_rr &rr) const;
349  void ssrr(ip_opt_data_rr &rr) const;
350  void ts(ip_opt_data_ts &ts) const;
351  uint16_t satid() const { return ntohs(opt_data.satid); }
352  uint16_t mtup() const { return ntohs(opt_data.mtu); }
353  uint16_t mtur() const { return ntohs(opt_data.mtu); }
354  void tr(ip_opt_data_tr &tr) const;
355  const uint32_t *addext() const { return &opt_data.addext[0]; }
356  uint16_t rtralt() const { return ntohs(opt_data.rtralt); }
357  void sdb(std::vector<uint32_t> &vec) const;
358 };
359 
360 /*
361  * Ip6 Classes
362  */
363 struct Ip6Opt;
364 struct Ip6Hdr : public ip6_hdr
365 {
366  uint8_t version() const { return ip6_vfc; }
367  uint32_t flow() const { return ntohl(ip6_flow); }
368  uint16_t plen() const { return ntohs(ip6_plen); }
369  uint16_t hlen() const { return IP6_HDR_LEN; }
370  uint8_t nxt() const { return ip6_nxt; }
371  uint8_t hlim() const { return ip6_hlim; }
372 
373  const uint8_t* src() const { return ip6_src.data; }
374  const uint8_t* dst() const { return ip6_dst.data; }
375 
376  int extensionLength() const;
377  const Ip6Opt* getExt(uint8_t ext) const;
378  const Ip6Opt* fragmentExt() const { return getExt(IP_PROTO_FRAGMENT); }
379  const Ip6Opt* rtTypeExt() const { return getExt(IP_PROTO_ROUTING); }
380  const Ip6Opt* dstOptExt() const { return getExt(IP_PROTO_DSTOPTS); }
381  uint8_t proto() const;
382 
383  void plen(uint16_t _plen) { ip6_plen = htons(_plen); }
384 
385  int size() const { return IP6_HDR_LEN + extensionLength(); }
386  const uint8_t *bytes() const { return (const uint8_t *)this; }
387  const uint8_t *payload() const { return bytes() + IP6_HDR_LEN
388  + extensionLength(); }
389  uint8_t *bytes() { return (uint8_t *)this; }
390  uint8_t *payload() { return bytes() + IP6_HDR_LEN
391  + extensionLength(); }
392 };
393 
394 class Ip6Ptr
395 {
396  protected:
397  friend class TcpPtr;
398  friend class UdpPtr;
401 
402  void set(const EthPacketPtr &ptr)
403  {
404  p = 0;
405  eth_hdr_vlan = false;
406 
407  if (ptr) {
408  EthHdr *eth = (EthHdr *)ptr->data;
409  if (eth->type() == ETH_TYPE_IPV6)
410  p = ptr;
411  if (eth->isVlan())
412  eth_hdr_vlan = true;
413  }
414  }
415 
416  public:
417  Ip6Ptr() : p(0), eth_hdr_vlan(false) {}
418  Ip6Ptr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
419  Ip6Ptr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
420  Ip6Ptr(const Ip6Ptr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { }
421 
422  Ip6Hdr *get() { return (Ip6Hdr *)(p->data + sizeof(eth_hdr)
423  + ((eth_hdr_vlan) ? 4 : 0)); }
424  Ip6Hdr *operator->() { return get(); }
425  Ip6Hdr &operator*() { return *get(); }
426 
427  const Ip6Hdr *get() const
428  { return (const Ip6Hdr *)(p->data + sizeof(eth_hdr)
429  + ((eth_hdr_vlan) ? 4 : 0)); }
430  const Ip6Hdr *operator->() const { return get(); }
431  const Ip6Hdr &operator*() const { return *get(); }
432 
433  const Ip6Ptr &operator=(const EthPacketPtr &ptr)
434  { set(ptr); return *this; }
435  const Ip6Ptr &operator=(const EthPtr &ptr)
436  { set(ptr.p); return *this; }
437  const Ip6Ptr &operator=(const Ip6Ptr &ptr)
438  { p = ptr.p; return *this; }
439 
440  const EthPacketPtr packet() const { return p; }
441  EthPacketPtr packet() { return p; }
442  bool operator!() const { return !p; }
443  operator bool() const { return (p != nullptr); }
444  int off() const { return sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0); }
445  int pstart() const { return off() + get()->size(); }
446 };
447 
448 // Dnet supplied ipv6 opt header is incomplete and
449 // newer NIC card filters expect a more robust
450 // ipv6 header option declaration.
452  uint16_t offlg;
453  uint32_t ident;
454 };
455 
457  uint8_t type;
458  uint8_t segleft;
459  uint32_t reserved;
460  ip6_addr_t addr;
461 };
462 
463 #define HOME_ADDRESS_OPTION 0xC9
465  uint8_t type;
466  uint8_t length;
467  ip6_addr_t addr;
468 } __attribute__((packed));
469 
471 {
472  uint8_t ext_nxt;
473  uint8_t ext_len;
474  union {
478  } ext_data;
479 } __attribute__((packed));
480 
481 struct Ip6Opt : public ip6_opt_hdr
482 {
483  uint8_t nxt() const { return ext_nxt; }
484  uint8_t extlen() const { return ext_len; }
485  uint8_t len() const { return extlen() + 8; }
486 
487  // Supporting the types of header extensions likely to be encountered:
488  // fragment, routing type 2 and dstopts.
489 
490  // Routing type 2
491  uint8_t rtType2Type() const { return ext_data.rtType2.type; }
492  uint8_t rtType2SegLft() const { return ext_data.rtType2.segleft; }
493  const uint8_t* rtType2Addr() const { return ext_data.rtType2.addr.data; }
494 
495  // Fragment
496  uint16_t fragmentOfflg() const { return ntohs(ext_data.fragment.offlg); }
497  uint32_t fragmentIdent() const { return ntohl(ext_data.fragment.ident); }
498 
499  // Dst Options/Home Address Option
500  uint8_t dstOptType() const { return ext_data.dstOpts.type; }
501  uint8_t dstOptLength() const { return ext_data.dstOpts.length; }
502  const uint8_t* dstOptAddr() const { return ext_data.dstOpts.addr.data; }
503 };
504 
505 
506 /*
507  * TCP Stuff
508  */
509 struct TcpOpt;
510 struct TcpHdr : public tcp_hdr
511 {
512  uint16_t sport() const { return ntohs(th_sport); }
513  uint16_t dport() const { return ntohs(th_dport); }
514  uint32_t seq() const { return ntohl(th_seq); }
515  uint32_t ack() const { return ntohl(th_ack); }
516  uint8_t off() const { return th_off*4; }
517  uint8_t flags() const { return th_flags & 0x3f; }
518  uint16_t win() const { return ntohs(th_win); }
519  uint16_t sum() const { return th_sum; }
520  uint16_t urp() const { return ntohs(th_urp); }
521 
522  void sum(uint16_t sum) { th_sum = sum; }
523  void seq(uint32_t _seq) { th_seq = htonl(_seq); }
524  void flags(uint8_t _flags) { th_flags = _flags; }
525 
526  bool options(std::vector<const TcpOpt *> &vec) const;
527 
528  int size() const { return off(); }
529  const uint8_t *bytes() const { return (const uint8_t *)this; }
530  const uint8_t *payload() const { return bytes() + size(); }
531  uint8_t *bytes() { return (uint8_t *)this; }
532  uint8_t *payload() { return bytes() + size(); }
533 };
534 
535 class TcpPtr
536 {
537  protected:
539  int _off;
540 
541  void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
542  void set(const IpPtr &ptr)
543  {
544  if (ptr && ptr->proto() == IP_PROTO_TCP)
545  set(ptr.p, ptr.pstart());
546  else
547  set(0, 0);
548  }
549  void set(const Ip6Ptr &ptr)
550  {
551  if (ptr && ptr->proto() == IP_PROTO_TCP)
552  set(ptr.p, ptr.pstart());
553  else
554  set(0, 0);
555  }
556 
557  public:
558  TcpPtr() : p(0), _off(0) {}
559  TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
560  TcpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
561  TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
562 
563  TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
564  TcpHdr *operator->() { return get(); }
565  TcpHdr &operator*() { return *get(); }
566 
567  const TcpHdr *get() const { return (const TcpHdr *)(p->data + _off); }
568  const TcpHdr *operator->() const { return get(); }
569  const TcpHdr &operator*() const { return *get(); }
570 
571  const TcpPtr &operator=(const IpPtr &i)
572  { set(i); return *this; }
573  const TcpPtr &operator=(const TcpPtr &t)
574  { set(t.p, t._off); return *this; }
575 
576  const EthPacketPtr packet() const { return p; }
577  EthPacketPtr packet() { return p; }
578  bool operator!() const { return !p; }
579  operator bool() const { return (p != nullptr); }
580  int off() const { return _off; }
581  int pstart() const { return off() + get()->size(); }
582 };
583 
584 uint16_t cksum(const TcpPtr &ptr);
585 
586 struct TcpOpt : public tcp_opt
587 {
588  uint8_t type() const { return opt_type; }
589  uint8_t len() const { return TCP_OPT_TYPEONLY(type()) ? 1 : opt_len; }
590 
591  bool isopt(int opt) const { return type() == opt; }
592 
593  const uint8_t *data() const { return opt_data.data8; }
594 
595  uint16_t mss() const { return ntohs(opt_data.mss); }
596  uint8_t wscale() const { return opt_data.wscale; }
597  uint32_t echo() const { return ntohl(opt_data.echo); }
598  uint32_t tsval() const { return ntohl(opt_data.timestamp[0]); }
599  uint32_t tsecr() const { return ntohl(opt_data.timestamp[1]); }
600  uint32_t cc() const { return ntohl(opt_data.cc); }
601  uint8_t cksum() const{ return opt_data.cksum; }
602  const uint8_t *md5() const { return opt_data.md5; }
603 
604  int size() const { return len(); }
605  const uint8_t *bytes() const { return (const uint8_t *)this; }
606  const uint8_t *payload() const { return bytes() + size(); }
607  uint8_t *bytes() { return (uint8_t *)this; }
608  uint8_t *payload() { return bytes() + size(); }
609 };
610 
611 /*
612  * UDP Stuff
613  */
614 struct UdpHdr : public udp_hdr
615 {
616  uint16_t sport() const { return ntohs(uh_sport); }
617  uint16_t dport() const { return ntohs(uh_dport); }
618  uint16_t len() const { return ntohs(uh_ulen); }
619  uint16_t sum() const { return uh_sum; }
620 
621  void sum(uint16_t sum) { uh_sum = sum; }
622  void len(uint16_t _len) { uh_ulen = htons(_len); }
623 
624  int size() const { return sizeof(udp_hdr); }
625  const uint8_t *bytes() const { return (const uint8_t *)this; }
626  const uint8_t *payload() const { return bytes() + size(); }
627  uint8_t *bytes() { return (uint8_t *)this; }
628  uint8_t *payload() { return bytes() + size(); }
629 };
630 
631 class UdpPtr
632 {
633  protected:
635  int _off;
636 
637  void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
638  void set(const IpPtr &ptr)
639  {
640  if (ptr && ptr->proto() == IP_PROTO_UDP)
641  set(ptr.p, ptr.pstart());
642  else
643  set(0, 0);
644  }
645  void set(const Ip6Ptr &ptr)
646  {
647  if (ptr && ptr->proto() == IP_PROTO_UDP)
648  set(ptr.p, ptr.pstart());
649  else
650  set(0, 0);
651  }
652 
653  public:
654  UdpPtr() : p(0), _off(0) {}
655  UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
656  UdpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
657  UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
658 
659  UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
660  UdpHdr *operator->() { return get(); }
661  UdpHdr &operator*() { return *get(); }
662 
663  const UdpHdr *get() const { return (const UdpHdr *)(p->data + _off); }
664  const UdpHdr *operator->() const { return get(); }
665  const UdpHdr &operator*() const { return *get(); }
666 
667  const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
668  const UdpPtr &operator=(const UdpPtr &t)
669  { set(t.p, t._off); return *this; }
670 
671  const EthPacketPtr packet() const { return p; }
672  EthPacketPtr packet() { return p; }
673  bool operator!() const { return !p; }
674  operator bool() const { return (p != nullptr); }
675  int off() const { return _off; }
676  int pstart() const { return off() + get()->size(); }
677 };
678 
679 uint16_t __tu_cksum6(const Ip6Ptr &ip6);
680 uint16_t __tu_cksum(const IpPtr &ip);
681 uint16_t cksum(const UdpPtr &ptr);
682 
683 int hsplit(const EthPacketPtr &ptr);
684 
685 } // namespace Net
686 
687 #endif // __BASE_INET_HH__
std::string string() const
Definition: inet.cc:140
UdpPtr(const UdpPtr &ptr)
Definition: inet.hh:657
uint16_t type() const
Definition: inet.hh:130
std::string string() const
Definition: inet.cc:118
uint16_t dport() const
Definition: inet.hh:513
EthPacketPtr p
Definition: inet.hh:538
uint16_t _port
Definition: inet.hh:235
TcpPtr(const Ip6Ptr &ptr)
Definition: inet.hh:560
const IpPtr & operator=(const EthPtr &ptr)
Definition: inet.hh:321
bool operator!() const
Definition: inet.hh:326
bool multicast() const
Definition: inet.hh:97
std::string string() const
Definition: inet.cc:186
void set(const IpPtr &ptr)
Definition: inet.hh:638
const Ip6Ptr & operator=(const Ip6Ptr &ptr)
Definition: inet.hh:437
const EthPacketPtr packet() const
Definition: inet.hh:324
bool isopt(int opt) const
Definition: inet.hh:591
Bitfield< 5, 3 > reg
Definition: types.hh:89
uint8_t rtType2Type() const
Definition: inet.hh:491
IpPtr(const EthPacketPtr &ptr)
Definition: inet.hh:305
uint8_t rtType2SegLft() const
Definition: inet.hh:492
void lsrr(ip_opt_data_rr &rr) const
EthPacketPtr p
Definition: inet.hh:634
uint8_t dstOptType() const
Definition: inet.hh:500
uint8_t proto() const
Definition: inet.cc:341
int size() const
Definition: inet.hh:604
void ts(ip_opt_data_ts &ts) const
uint32_t tsecr() const
Definition: inet.hh:599
UdpHdr & operator*()
Definition: inet.hh:661
uint8_t * bytes()
Definition: inet.hh:93
Bitfield< 7 > i
Definition: miscregs.hh:1378
uint16_t sum() const
Definition: inet.hh:264
uint32_t fragmentIdent() const
Definition: inet.hh:497
EthPtr()
Definition: inet.hh:169
uint32_t ip() const
Definition: inet.hh:204
uint16_t sport() const
Definition: inet.hh:616
TcpPtr()
Definition: inet.hh:558
UdpPtr(const IpPtr &ptr)
Definition: inet.hh:655
struct ip6_opt_dstopts dstOpts
Definition: inet.hh:477
const IpPtr & operator=(const EthPacketPtr &ptr)
Definition: inet.hh:320
const Ip6Ptr & operator=(const EthPacketPtr &ptr)
Definition: inet.hh:433
uint16_t plen() const
Definition: inet.hh:368
uint16_t vlanId() const
Definition: inet.hh:138
uint16_t hlen() const
Definition: inet.hh:369
const uint8_t * payload() const
Definition: inet.hh:387
const uint8_t * rtType2Addr() const
Definition: inet.hh:493
const UdpPtr & operator=(const IpPtr &i)
Definition: inet.hh:667
uint16_t cksum(const IpPtr &ptr)
Definition: inet.cc:207
bool isNumber(int num) const
Definition: inet.hh:342
uint8_t extlen() const
Definition: inet.hh:484
bool operator!() const
Definition: inet.hh:184
Ip6Ptr(const Ip6Ptr &ptr)
Definition: inet.hh:420
int hsplit(const EthPacketPtr &ptr)
Definition: inet.cc:379
struct ip6_opt_routing_type2 rtType2
Definition: inet.hh:476
bool broadcast() const
Definition: inet.hh:98
Ip6Ptr(const EthPtr &ptr)
Definition: inet.hh:419
int size() const
Definition: inet.hh:148
void flags(uint8_t _flags)
Definition: inet.hh:524
const EthPacketPtr packet() const
Definition: inet.hh:671
uint8_t typeCopied() const
Definition: inet.hh:339
const IpHdr * operator->() const
Definition: inet.hh:317
int pstart() const
Definition: inet.hh:445
uint8_t off() const
Definition: inet.hh:516
TcpHdr * operator->()
Definition: inet.hh:564
union Net::ip6_opt_hdr::@29 ext_data
EthPacketPtr packet()
Definition: inet.hh:183
const TcpPtr & operator=(const IpPtr &i)
Definition: inet.hh:571
uint16_t mss() const
Definition: inet.hh:595
IpAddress(const uint32_t __ip)
Definition: inet.hh:201
const IpHdr & operator*() const
Definition: inet.hh:318
int pstart() const
Definition: inet.hh:187
const uint8_t * dstOptAddr() const
Definition: inet.hh:502
const EthPacketPtr packet() const
Definition: inet.hh:576
uint16_t dport() const
Definition: inet.hh:617
void id(uint16_t _id)
Definition: inet.hh:269
int size() const
Definition: inet.hh:274
Bitfield< 12 > ext
Definition: miscregs.hh:1609
Bitfield< 23, 0 > offset
Definition: types.hh:149
void len(uint16_t _len)
Definition: inet.hh:622
void ssrr(ip_opt_data_rr &rr) const
TcpPtr(const IpPtr &ptr)
Definition: inet.hh:559
const uint8_t * bytes() const
Definition: inet.hh:386
uint32_t echo() const
Definition: inet.hh:597
IpHdr * operator->()
Definition: inet.hh:311
void set(const Ip6Ptr &ptr)
Definition: inet.hh:549
bool operator==(const EthAddr &left, const EthAddr &right)
Definition: inet.cc:126
void set(const EthPacketPtr &ptr, int offset)
Definition: inet.hh:541
const uint8_t * bytes() const
Definition: inet.hh:605
const uint8_t * payload() const
Definition: inet.hh:626
uint8_t typeClass() const
Definition: inet.hh:338
int size() const
Definition: inet.hh:90
void seq(uint32_t _seq)
Definition: inet.hh:523
const Ip6Hdr & operator*() const
Definition: inet.hh:431
const Ip6Opt * fragmentExt() const
Definition: inet.hh:378
uint32_t flow() const
Definition: inet.hh:367
uint16_t win() const
Definition: inet.hh:518
uint8_t * payload()
Definition: inet.hh:158
const uint8_t * bytes() const
Definition: inet.hh:625
STL vector class.
Definition: stl.hh:40
Bitfield< 14 > rr
Definition: miscregs.hh:1553
UdpHdr * operator->()
Definition: inet.hh:660
uint8_t len() const
Definition: inet.hh:485
void sum(uint16_t sum)
Definition: inet.hh:268
IpPtr(const IpPtr &ptr)
Definition: inet.hh:307
uint16_t frag_off() const
Definition: inet.hh:261
const char data[]
Definition: circlebuf.cc:43
const uint8_t * bytes() const
Definition: inet.hh:92
uint16_t urp() const
Definition: inet.hh:520
const uint8_t * bytes() const
Definition: inet.hh:155
uint16_t id() const
Definition: inet.hh:259
uint8_t * bytes()
Definition: inet.hh:531
uint8_t * bytes()
Definition: inet.hh:157
IpNetmask(const uint32_t __ip, const uint8_t __netmask)
Definition: inet.hh:220
uint8_t ttl() const
Definition: inet.hh:262
int pstart() const
Definition: inet.hh:329
const EthPtr & operator=(const EthPacketPtr &ptr)
Definition: inet.hh:180
uint8_t netmask() const
Definition: inet.hh:224
bool unicast() const
Definition: inet.hh:96
int _off
Definition: inet.hh:539
bool operator!() const
Definition: inet.hh:673
void set(const EthPacketPtr &ptr)
Definition: inet.hh:289
uint8_t _netmask
Definition: inet.hh:215
int _off
Definition: inet.hh:635
const EthHdr & operator*() const
Definition: inet.hh:177
const EthPacketPtr packet() const
Definition: inet.hh:440
void sec(ip_opt_data_sec &sec) const
uint32_t src() const
Definition: inet.hh:265
EthAddr()
Definition: inet.cc:59
int size() const
Definition: inet.hh:385
const Ip6Opt * dstOptExt() const
Definition: inet.hh:380
const uint8_t * addr() const
Definition: inet.hh:95
const uint8_t * md5() const
Definition: inet.hh:602
Ip6Ptr(const EthPacketPtr &ptr)
Definition: inet.hh:418
uint8_t wscale() const
Definition: inet.hh:596
void sdb(std::vector< uint32_t > &vec) const
IpWithPort(const uint32_t __ip, const uint16_t __port)
Definition: inet.hh:240
IpPtr()
Definition: inet.hh:304
Ip6Hdr & operator*()
Definition: inet.hh:425
std::string string() const
Definition: inet.cc:164
EthHdr & operator*()
Definition: inet.hh:173
uint16_t fragmentOfflg() const
Definition: inet.hh:496
bool options(std::vector< const TcpOpt * > &vec) const
Definition: inet.cc:358
uint8_t * payload()
Definition: inet.hh:608
EthPtr(const EthPacketPtr &ptr)
Definition: inet.hh:170
const UdpHdr & operator*() const
Definition: inet.hh:665
uint8_t flags() const
Definition: inet.hh:517
const uint8_t * data() const
Definition: inet.hh:346
void len(uint16_t _len)
Definition: inet.hh:270
Ip6Ptr()
Definition: inet.hh:417
uint8_t proto() const
Definition: inet.hh:263
uint8_t * payload()
Definition: inet.hh:628
uint16_t len() const
Definition: inet.hh:258
const uint8_t * dst() const
Definition: inet.hh:374
EthPacketPtr packet()
Definition: inet.hh:672
int off() const
Definition: inet.hh:444
uint8_t hlen() const
Definition: inet.hh:256
uint8_t * bytes()
Definition: inet.hh:627
uint8_t * payload()
Definition: inet.hh:278
int off() const
Definition: inet.hh:675
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
void sum(uint16_t sum)
Definition: inet.hh:522
uint8_t dstOptLength() const
Definition: inet.hh:501
uint16_t sum() const
Definition: inet.hh:619
uint8_t type() const
Definition: inet.hh:588
void set(const IpPtr &ptr)
Definition: inet.hh:542
uint8_t * payload()
Definition: inet.hh:532
const UdpPtr & operator=(const UdpPtr &t)
Definition: inet.hh:668
uint16_t satid() const
Definition: inet.hh:351
uint16_t mtur() const
Definition: inet.hh:353
uint8_t * bytes()
Definition: inet.hh:389
uint32_t cc() const
Definition: inet.hh:600
uint16_t frag_flags() const
Definition: inet.hh:260
IpPtr(const EthPtr &ptr)
Definition: inet.hh:306
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
TcpHdr & operator*()
Definition: inet.hh:565
int size() const
Definition: inet.hh:624
const TcpHdr * operator->() const
Definition: inet.hh:568
EthPacketPtr p
Definition: inet.hh:166
const uint32_t * addext() const
Definition: inet.hh:355
const UdpHdr * operator->() const
Definition: inet.hh:664
const uint8_t * src() const
Definition: inet.hh:373
EthPacketPtr packet()
Definition: inet.hh:325
void plen(uint16_t _plen)
Definition: inet.hh:383
int off() const
Definition: inet.hh:328
const IpPtr & operator=(const IpPtr &ptr)
Definition: inet.hh:322
Bitfield< 18, 16 > ia
uint8_t hlim() const
Definition: inet.hh:371
const Ip6Opt * getExt(uint8_t ext) const
Definition: inet.cc:315
EthPacketPtr p
Definition: inet.hh:286
Net::Ip6Opt __attribute__
bool operator!() const
Definition: inet.hh:578
uint16_t sport() const
Definition: inet.hh:512
bool operator!() const
Definition: inet.hh:442
ostream & operator<<(ostream &stream, const EthAddr &ea)
Definition: inet.cc:132
int extensionLength() const
Definition: inet.cc:292
int size()
Definition: pagetable.hh:146
UdpPtr()
Definition: inet.hh:654
void set(const Ip6Ptr &ptr)
Definition: inet.hh:645
uint8_t typeNumber() const
Definition: inet.hh:337
void set(const EthPacketPtr &ptr)
Definition: inet.hh:402
const uint8_t * data() const
Definition: inet.hh:593
EthPacketPtr packet()
Definition: inet.hh:577
uint8_t nxt() const
Definition: inet.hh:370
uint8_t ext_len
Definition: inet.hh:473
uint8_t len() const
Definition: inet.hh:340
EthPacketPtr p
Definition: inet.hh:399
TcpPtr(const TcpPtr &ptr)
Definition: inet.hh:561
uint16_t rtralt() const
Definition: inet.hh:356
const EthAddr & operator=(const eth_addr &ea)
Definition: inet.cc:82
void parse(const std::string &addr)
Definition: inet.cc:96
uint16_t mtup() const
Definition: inet.hh:352
bool isClass(int cls) const
Definition: inet.hh:343
uint32_t tsval() const
Definition: inet.hh:598
const EthAddr & src() const
Definition: inet.hh:145
uint8_t * bytes()
Definition: inet.hh:607
uint8_t ext_nxt
Definition: inet.hh:472
int size() const
Definition: inet.hh:528
const EthAddr & dst() const
Definition: inet.hh:146
const Ip6Opt * rtTypeExt() const
Definition: inet.hh:379
ip6_addr_t addr
Definition: inet.hh:467
void set(const EthPacketPtr &ptr, int offset)
Definition: inet.hh:637
uint16_t __tu_cksum6(const Ip6Ptr &ip6)
Definition: inet.cc:224
uint32_t ident
Definition: inet.hh:453
uint32_t _ip
Definition: inet.hh:196
const uint8_t * payload() const
Definition: inet.hh:156
const Ip6Ptr & operator=(const EthPtr &ptr)
Definition: inet.hh:435
void sum(uint16_t sum)
Definition: inet.hh:621
uint8_t nxt() const
Definition: inet.hh:483
uint16_t offlg
Definition: inet.hh:452
int pstart() const
Definition: inet.hh:581
const TcpHdr & operator*() const
Definition: inet.hh:569
const uint8_t * bytes() const
Definition: inet.hh:529
const EthHdr * operator->() const
Definition: inet.hh:176
Ip6Hdr * operator->()
Definition: inet.hh:424
bool ip(TxDesc *d)
uint16_t sum() const
Definition: inet.hh:519
const uint8_t * payload() const
Definition: inet.hh:276
Bitfield< 5 > t
Definition: miscregs.hh:1382
uint8_t version() const
Definition: inet.hh:255
uint16_t len() const
Definition: inet.hh:618
uint8_t * bytes()
Definition: inet.hh:277
uint32_t ack() const
Definition: inet.hh:515
int off() const
Definition: inet.hh:580
struct ip6_opt_fragment fragment
Definition: inet.hh:475
EthPacketPtr packet()
Definition: inet.hh:441
const EthPacketPtr packet() const
Definition: inet.hh:182
EthHdr * operator->()
Definition: inet.hh:172
uint8_t tos() const
Definition: inet.hh:257
bool eth_hdr_vlan
Definition: inet.hh:287
uint8_t port() const
Definition: inet.hh:244
uint8_t type() const
Definition: inet.hh:336
uint32_t dst() const
Definition: inet.hh:266
const uint8_t * payload() const
Definition: inet.hh:606
uint32_t seq() const
Definition: inet.hh:514
const TcpPtr & operator=(const TcpPtr &t)
Definition: inet.hh:573
bool isVlan() const
Definition: inet.hh:129
Bitfield< 3 > ea
Definition: miscregs.hh:1518
uint8_t cksum() const
Definition: inet.hh:601
if(it_gpu==gpuTypeMap.end())
Definition: gpu_nomali.cc:75
bool isCopied(int cpy) const
Definition: inet.hh:344
Bitfield< 14 > ip6
const Ip6Hdr * operator->() const
Definition: inet.hh:430
uint16_t __tu_cksum(const IpPtr &ip)
Definition: inet.cc:214
uint8_t len() const
Definition: inet.hh:589
IpHdr & operator*()
Definition: inet.hh:312
int off() const
Definition: inet.hh:186
const uint8_t * bytes() const
Definition: inet.hh:275
uint8_t version() const
Definition: inet.hh:366
bool options(std::vector< const IpOpt * > &vec) const
Definition: inet.cc:261
uint8_t length
Definition: inet.hh:466
bool eth_hdr_vlan
Definition: inet.hh:400
void tr(ip_opt_data_tr &tr) const
int pstart() const
Definition: inet.hh:676
const uint8_t * payload() const
Definition: inet.hh:530
UdpPtr(const Ip6Ptr &ptr)
Definition: inet.hh:656
uint8_t * payload()
Definition: inet.hh:390

Generated on Fri Jun 9 2017 13:03:40 for gem5 by doxygen 1.8.6