gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
68namespace gem5
69{
70
71namespace networking
72{
73
74/*
75 * Ethernet Stuff
76 */
77struct EthAddr : protected eth_addr
78{
79 protected:
80 void parse(const std::string &addr);
81
82 public:
87 EthAddr();
88 EthAddr(const uint8_t ea[ETH_ADDR_LEN]);
89 EthAddr(const eth_addr &ea);
90 EthAddr(const std::string &addr);
91 const EthAddr &operator=(const eth_addr &ea);
92 const EthAddr &operator=(const std::string &addr);
93 // end of api_inet
94
98 int size() const { return sizeof(eth_addr); }
99
100
105 const uint8_t *bytes() const { return &data[0]; }
106 uint8_t *bytes() { return &data[0]; }
107 // end of api_inet
108
113 const uint8_t *addr() const { return &data[0]; }
114 bool unicast() const { return !(data[0] & 0x01); }
115 bool multicast() const { return !unicast() && !broadcast(); }
116 bool broadcast() const
117 {
118 bool isBroadcast = true;
119 for (int i = 0; i < ETH_ADDR_LEN; ++i) {
120 isBroadcast = isBroadcast && data[i] == 0xff;
121 }
122
123 return isBroadcast;
124 }
125 // end of api_inet
126
130 std::string string() const;
131
135 operator uint64_t() const
136 {
137 uint64_t reg = 0;
138 reg |= ((uint64_t)data[0]) << 40;
139 reg |= ((uint64_t)data[1]) << 32;
140 reg |= ((uint64_t)data[2]) << 24;
141 reg |= ((uint64_t)data[3]) << 16;
142 reg |= ((uint64_t)data[4]) << 8;
143 reg |= ((uint64_t)data[5]) << 0;
144 return reg;
145 }
146
147};
148
153std::ostream &operator<<(std::ostream &stream, const EthAddr &ea);
154bool operator==(const EthAddr &left, const EthAddr &right);
155 // end of api_inet
156
157struct EthHdr : public eth_hdr
158{
159 bool isVlan() const { return (ntohs(eth_type) == ETH_TYPE_8021Q); }
160 uint16_t type() const {
161 if (!isVlan())
162 return ntohs(eth_type);
163 else
164 // L3 type is now 16 bytes into the hdr with 802.1Q
165 // instead of 12. dnet/eth.h only supports 802.1
166 return ntohs(*((uint16_t*)(((uint8_t *)this) + 16)));
167 }
168 uint16_t vlanId() const {
169 if (isVlan())
170 return ntohs(*((uint16_t*)(((uint8_t *)this) + 14)));
171 else
172 return 0x0000;
173 }
174
175 const EthAddr &src() const { return *(EthAddr *)&eth_src; }
176 const EthAddr &dst() const { return *(EthAddr *)&eth_dst; }
177
178 int size() const {
179 if (!isVlan())
180 return sizeof(eth_hdr);
181 else
182 return (sizeof(eth_hdr)+4);
183 }
184
185 const uint8_t *bytes() const { return (const uint8_t *)this; }
186 const uint8_t *payload() const { return bytes() + size(); }
187 uint8_t *bytes() { return (uint8_t *)this; }
188 uint8_t *payload() { return bytes() + size(); }
189};
190
192{
193 protected:
194 friend class IpPtr;
195 friend class Ip6Ptr;
197
198 public:
204 EthPtr(const EthPacketPtr &ptr) : p(ptr) { }
205 // end of api_inet
206
207 EthHdr *operator->() { return (EthHdr *)p->data; }
208 EthHdr &operator*() { return *(EthHdr *)p->data; }
209 operator EthHdr *() { return (EthHdr *)p->data; }
210
211 const EthHdr *operator->() const { return (const EthHdr *)p->data; }
212 const EthHdr &operator*() const { return *(const EthHdr *)p->data; }
213 operator const EthHdr *() const { return (const EthHdr *)p->data; }
214
218 const EthPtr &operator=(const EthPacketPtr &ptr) { p = ptr; return *this; }
219
224 const EthPacketPtr packet() const { return p; }
225 EthPacketPtr packet() { return p; }
226 bool operator!() const { return !p; }
227 operator bool() const { return (p != nullptr); }
228 int off() const { return 0; }
229 int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
230 // end of api_inet
231};
232
233/*
234 * IP Stuff
235 */
237{
238 protected:
239 uint32_t _ip;
240
241 public:
247 {}
248 IpAddress(const uint32_t __ip) : _ip(__ip)
249 {}
250 // end of api_net
251
255 uint32_t ip() const { return _ip; }
256
260 std::string string() const;
261};
262
267std::ostream &operator<<(std::ostream &stream, const IpAddress &ia);
268bool operator==(const IpAddress &left, const IpAddress &right);
269 // end of api_inet
270
271struct IpNetmask : public IpAddress
272{
273 protected:
274 uint8_t _netmask;
275
276 public:
278 {}
279 IpNetmask(const uint32_t __ip, const uint8_t __netmask) :
280 IpAddress(__ip), _netmask(__netmask)
281 {}
282
286 uint8_t netmask() const { return _netmask; }
287
288 std::string string() const;
289};
290
295std::ostream &operator<<(std::ostream &stream, const IpNetmask &in);
296bool operator==(const IpNetmask &left, const IpNetmask &right);
297 // end of api_inet
298
299struct IpWithPort : public IpAddress
300{
301 protected:
302 uint16_t _port;
303
304 public:
306 {}
307 IpWithPort(const uint32_t __ip, const uint16_t __port) :
308 IpAddress(__ip), _port(__port)
309 {}
310
314 uint8_t port() const { return _port; }
315
316 std::string string() const;
317};
318
323std::ostream &operator<<(std::ostream &stream, const IpWithPort &iwp);
324bool operator==(const IpWithPort &left, const IpWithPort &right);
325 // end of api_inet
326
327struct IpOpt;
328struct IpHdr : public ip_hdr
329{
330 uint8_t version() const { return ip_v; }
331 uint8_t hlen() const { return ip_hl * 4; }
332 uint8_t tos() const { return ip_tos; }
333 uint16_t len() const { return ntohs(ip_len); }
334 uint16_t id() const { return ntohs(ip_id); }
335 uint16_t frag_flags() const { return ntohs(ip_off) >> 13; }
336 uint16_t frag_off() const { return ntohs(ip_off) & 0x1fff; }
337 uint8_t ttl() const { return ip_ttl; }
338 uint8_t proto() const { return ip_p; }
339 uint16_t sum() const { return ip_sum; }
340 uint32_t src() const { return ntohl(ip_src); }
341 uint32_t dst() const { return ntohl(ip_dst); }
342
343 void sum(uint16_t sum) { ip_sum = sum; }
344 void id(uint16_t _id) { ip_id = htons(_id); }
345 void len(uint16_t _len) { ip_len = htons(_len); }
346
348
349 int size() const { return hlen(); }
350 const uint8_t *bytes() const { return (const uint8_t *)this; }
351 const uint8_t *payload() const { return bytes() + size(); }
352 uint8_t *bytes() { return (uint8_t *)this; }
353 uint8_t *payload() { return bytes() + size(); }
354};
355
356class IpPtr
357{
358 protected:
359 friend class TcpPtr;
360 friend class UdpPtr;
363
364 void set(const EthPacketPtr &ptr)
365 {
366 p = 0;
367 eth_hdr_vlan = false;
368
369 if (ptr) {
370 EthHdr *eth = (EthHdr *)ptr->data;
371 if (eth->type() == ETH_TYPE_IP)
372 p = ptr;
373 if (eth->isVlan())
374 eth_hdr_vlan = true;
375 }
376 }
377
378 public:
383 IpPtr() : p(0), eth_hdr_vlan(false) {}
384 IpPtr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
385 IpPtr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
386 IpPtr(const IpPtr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { }
387 // end of api_inet
388
389 IpHdr *get() { return (IpHdr *)(p->data + sizeof(eth_hdr) +
390 ((eth_hdr_vlan) ? 4 : 0)); }
391 IpHdr *operator->() { return get(); }
392 IpHdr &operator*() { return *get(); }
393
398 const IpHdr *get() const
399 { return (const IpHdr *)(p->data + sizeof(eth_hdr) +
400 ((eth_hdr_vlan) ? 4 : 0)); }
401 const IpHdr *operator->() const { return get(); }
402 const IpHdr &operator*() const { return *get(); }
403 // end of api_inet
404
405 const IpPtr &operator=(const EthPacketPtr &ptr) { set(ptr); return *this; }
406 const IpPtr &operator=(const EthPtr &ptr) { set(ptr.p); return *this; }
407 const IpPtr &operator=(const IpPtr &ptr) { p = ptr.p; return *this; }
408
413 const EthPacketPtr packet() const { return p; }
414 EthPacketPtr packet() { return p; }
415 bool operator!() const { return !p; }
416 operator bool() const { return (p != nullptr); }
417 int off() const { return (sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0)); }
418 int pstart() const { return (off() + get()->size()); }
419 // end of api_inet
420};
421
425uint16_t cksum(const IpPtr &ptr);
426
427struct IpOpt : public ip_opt
428{
429 uint8_t type() const { return opt_type; }
430 uint8_t typeNumber() const { return IP_OPT_NUMBER(opt_type); }
431 uint8_t typeClass() const { return IP_OPT_CLASS(opt_type); }
432 uint8_t typeCopied() const { return IP_OPT_COPIED(opt_type); }
433 uint8_t len() const { return IP_OPT_TYPEONLY(type()) ? 1 : opt_len; }
434
435 bool isNumber(int num) const { return typeNumber() == IP_OPT_NUMBER(num); }
436 bool isClass(int cls) const { return typeClass() == IP_OPT_CLASS(cls); }
437 bool isCopied(int cpy) const { return typeCopied() == IP_OPT_COPIED(cpy); }
438
439 const uint8_t *data() const { return opt_data.data8; }
440 void sec(ip_opt_data_sec &sec) const;
441 void lsrr(ip_opt_data_rr &rr) const;
442 void ssrr(ip_opt_data_rr &rr) const;
443 void ts(ip_opt_data_ts &ts) const;
444 uint16_t satid() const { return ntohs(opt_data.satid); }
445 uint16_t mtup() const { return ntohs(opt_data.mtu); }
446 uint16_t mtur() const { return ntohs(opt_data.mtu); }
447 void tr(ip_opt_data_tr &tr) const;
448 uint16_t rtralt() const { return ntohs(opt_data.rtralt); }
450};
451
452/*
453 * Ip6 Classes
454 */
455struct Ip6Opt;
456struct Ip6Hdr : public ip6_hdr
457{
458 uint8_t version() const { return ip6_vfc; }
459 uint32_t flow() const { return ntohl(ip6_flow); }
460 uint16_t plen() const { return ntohs(ip6_plen); }
461 uint16_t hlen() const { return IP6_HDR_LEN; }
462 uint8_t nxt() const { return ip6_nxt; }
463 uint8_t hlim() const { return ip6_hlim; }
464
465 const uint8_t* src() const { return ip6_src.data; }
466 const uint8_t* dst() const { return ip6_dst.data; }
467
468 int extensionLength() const;
469 const Ip6Opt* getExt(uint8_t ext) const;
470 const Ip6Opt* fragmentExt() const { return getExt(IP_PROTO_FRAGMENT); }
471 const Ip6Opt* rtTypeExt() const { return getExt(IP_PROTO_ROUTING); }
472 const Ip6Opt* dstOptExt() const { return getExt(IP_PROTO_DSTOPTS); }
473 uint8_t proto() const;
474
475 void plen(uint16_t _plen) { ip6_plen = htons(_plen); }
476
477 int size() const { return IP6_HDR_LEN + extensionLength(); }
478 const uint8_t *bytes() const { return (const uint8_t *)this; }
479 const uint8_t *payload() const { return bytes() + IP6_HDR_LEN
480 + extensionLength(); }
481 uint8_t *bytes() { return (uint8_t *)this; }
482 uint8_t *payload() { return bytes() + IP6_HDR_LEN
483 + extensionLength(); }
484};
485
487{
488 protected:
489 friend class TcpPtr;
490 friend class UdpPtr;
493
494 void set(const EthPacketPtr &ptr)
495 {
496 p = 0;
497 eth_hdr_vlan = false;
498
499 if (ptr) {
500 EthHdr *eth = (EthHdr *)ptr->data;
501 if (eth->type() == ETH_TYPE_IPV6)
502 p = ptr;
503 if (eth->isVlan())
504 eth_hdr_vlan = true;
505 }
506 }
507
508 public:
513 Ip6Ptr() : p(0), eth_hdr_vlan(false) {}
514 Ip6Ptr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
515 Ip6Ptr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
516 Ip6Ptr(const Ip6Ptr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { }
517 // end of api_inet
518
519 Ip6Hdr *get() { return (Ip6Hdr *)(p->data + sizeof(eth_hdr)
520 + ((eth_hdr_vlan) ? 4 : 0)); }
521 Ip6Hdr *operator->() { return get(); }
522 Ip6Hdr &operator*() { return *get(); }
523
524 const Ip6Hdr *get() const
525 { return (const Ip6Hdr *)(p->data + sizeof(eth_hdr)
526 + ((eth_hdr_vlan) ? 4 : 0)); }
527 const Ip6Hdr *operator->() const { return get(); }
528 const Ip6Hdr &operator*() const { return *get(); }
529
534 const Ip6Ptr &operator=(const EthPacketPtr &ptr)
535 { set(ptr); return *this; }
536 const Ip6Ptr &operator=(const EthPtr &ptr)
537 { set(ptr.p); return *this; }
538 const Ip6Ptr &operator=(const Ip6Ptr &ptr)
539 { p = ptr.p; return *this; }
540 // end of api_inet
541
546 const EthPacketPtr packet() const { return p; }
547 EthPacketPtr packet() { return p; }
548 bool operator!() const { return !p; }
549 operator bool() const { return (p != nullptr); }
550 int off() const { return sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0); }
551 int pstart() const { return off() + get()->size(); }
552 // end of api_inet
553};
554
555// Dnet supplied ipv6 opt header is incomplete and
556// newer NIC card filters expect a more robust
557// ipv6 header option declaration.
559{
560 uint16_t offlg;
561 uint32_t ident;
562};
563
565{
566 uint8_t type;
567 uint8_t segleft;
568 uint32_t reserved;
569 ip6_addr_t addr;
570};
571
573{
574 uint8_t type;
575 uint8_t length;
576 ip6_addr_t addr;
577};
578
580{
581 uint8_t ext_nxt;
582 uint8_t ext_len;
583 union
584 {
585 struct ip6_opt_fragment fragment;
586 struct ip6_opt_routing_type2 rtType2;
587 struct ip6_opt_dstopts dstOpts;
588 } ext_data;
589};
590
591struct Ip6Opt : public ip6_opt_hdr
592{
593 uint8_t nxt() const { return ext_nxt; }
594 uint8_t extlen() const { return ext_len; }
595 uint8_t len() const { return extlen() + 8; }
596
597 // Supporting the types of header extensions likely to be encountered:
598 // fragment, routing type 2 and dstopts.
599
600 // Routing type 2
601 uint8_t rtType2Type() const { return ext_data.rtType2.type; }
602 uint8_t rtType2SegLft() const { return ext_data.rtType2.segleft; }
603 const uint8_t* rtType2Addr() const { return ext_data.rtType2.addr.data; }
604
605 // Fragment
606 uint16_t fragmentOfflg() const { return ntohs(ext_data.fragment.offlg); }
607 uint32_t fragmentIdent() const { return ntohl(ext_data.fragment.ident); }
608
609 // Dst Options/Home Address Option
610 uint8_t dstOptType() const { return ext_data.dstOpts.type; }
611 uint8_t dstOptLength() const { return ext_data.dstOpts.length; }
612 const uint8_t* dstOptAddr() const { return ext_data.dstOpts.addr.data; }
613};
614
615
616/*
617 * TCP Stuff
618 */
619struct TcpOpt;
620struct TcpHdr : public tcp_hdr
621{
622 uint16_t sport() const { return ntohs(th_sport); }
623 uint16_t dport() const { return ntohs(th_dport); }
624 uint32_t seq() const { return ntohl(th_seq); }
625 uint32_t ack() const { return ntohl(th_ack); }
626 uint8_t off() const { return th_off*4; }
627 uint8_t flags() const { return th_flags & 0x3f; }
628 uint16_t win() const { return ntohs(th_win); }
629 uint16_t sum() const { return th_sum; }
630 uint16_t urp() const { return ntohs(th_urp); }
631
632 void sum(uint16_t sum) { th_sum = sum; }
633 void seq(uint32_t _seq) { th_seq = htonl(_seq); }
634 void flags(uint8_t _flags) { th_flags = _flags; }
635
637
638 int size() const { return off(); }
639 const uint8_t *bytes() const { return (const uint8_t *)this; }
640 const uint8_t *payload() const { return bytes() + size(); }
641 uint8_t *bytes() { return (uint8_t *)this; }
642 uint8_t *payload() { return bytes() + size(); }
643};
644
646{
647 protected:
649 int _off;
650
651 void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
652 void set(const IpPtr &ptr)
653 {
654 if (ptr && ptr->proto() == IP_PROTO_TCP)
655 set(ptr.p, ptr.pstart());
656 else
657 set(0, 0);
658 }
659 void set(const Ip6Ptr &ptr)
660 {
661 if (ptr && ptr->proto() == IP_PROTO_TCP)
662 set(ptr.p, ptr.pstart());
663 else
664 set(0, 0);
665 }
666
667 public:
672 TcpPtr() : p(0), _off(0) {}
673 TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
674 TcpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
675 TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
676 // end of api_inet
677
678 TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
679 TcpHdr *operator->() { return get(); }
680 TcpHdr &operator*() { return *get(); }
681
682 const TcpHdr *get() const { return (const TcpHdr *)(p->data + _off); }
683 const TcpHdr *operator->() const { return get(); }
684 const TcpHdr &operator*() const { return *get(); }
685
690 const TcpPtr &operator=(const IpPtr &i)
691 { set(i); return *this; }
692 const TcpPtr &operator=(const TcpPtr &t)
693 { set(t.p, t._off); return *this; }
694 // end of api_inet
695
700 const EthPacketPtr packet() const { return p; }
701 EthPacketPtr packet() { return p; }
702 bool operator!() const { return !p; }
703 operator bool() const { return (p != nullptr); }
704 int off() const { return _off; }
705 int pstart() const { return off() + get()->size(); }
706 // end of api_inet
707};
708
712uint16_t cksum(const TcpPtr &ptr);
713
714struct TcpOpt : public tcp_opt
715{
716 uint8_t type() const { return opt_type; }
717 uint8_t len() const { return TCP_OPT_TYPEONLY(type()) ? 1 : opt_len; }
718
719 bool isopt(int opt) const { return type() == opt; }
720
721 const uint8_t *data() const { return opt_data.data8; }
722
723 uint16_t mss() const { return ntohs(opt_data.mss); }
724 uint8_t wscale() const { return opt_data.wscale; }
725 uint32_t echo() const { return ntohl(opt_data.echo); }
726 uint32_t tsval() const { return ntohl(opt_data.timestamp[0]); }
727 uint32_t tsecr() const { return ntohl(opt_data.timestamp[1]); }
728 uint32_t cc() const { return ntohl(opt_data.cc); }
729 uint8_t cksum() const{ return opt_data.cksum; }
730 const uint8_t *md5() const { return opt_data.md5; }
731
732 int size() const { return len(); }
733 const uint8_t *bytes() const { return (const uint8_t *)this; }
734 const uint8_t *payload() const { return bytes() + size(); }
735 uint8_t *bytes() { return (uint8_t *)this; }
736 uint8_t *payload() { return bytes() + size(); }
737};
738
739/*
740 * UDP Stuff
741 */
742struct UdpHdr : public udp_hdr
743{
744 uint16_t sport() const { return ntohs(uh_sport); }
745 uint16_t dport() const { return ntohs(uh_dport); }
746 uint16_t len() const { return ntohs(uh_ulen); }
747 uint16_t sum() const { return uh_sum; }
748
749 void sum(uint16_t sum) { uh_sum = sum; }
750 void len(uint16_t _len) { uh_ulen = htons(_len); }
751
752 int size() const { return sizeof(udp_hdr); }
753 const uint8_t *bytes() const { return (const uint8_t *)this; }
754 const uint8_t *payload() const { return bytes() + size(); }
755 uint8_t *bytes() { return (uint8_t *)this; }
756 uint8_t *payload() { return bytes() + size(); }
757};
758
760{
761 protected:
763 int _off;
764
765 void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
766 void set(const IpPtr &ptr)
767 {
768 if (ptr && ptr->proto() == IP_PROTO_UDP)
769 set(ptr.p, ptr.pstart());
770 else
771 set(0, 0);
772 }
773 void set(const Ip6Ptr &ptr)
774 {
775 if (ptr && ptr->proto() == IP_PROTO_UDP)
776 set(ptr.p, ptr.pstart());
777 else
778 set(0, 0);
779 }
780
781 public:
785 UdpPtr() : p(0), _off(0) {}
786 UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
787 UdpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
788 UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
789 // end of api_inet
790
791 UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
792 UdpHdr *operator->() { return get(); }
793 UdpHdr &operator*() { return *get(); }
794
795 const UdpHdr *get() const { return (const UdpHdr *)(p->data + _off); }
796 const UdpHdr *operator->() const { return get(); }
797 const UdpHdr &operator*() const { return *get(); }
798
803 const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
804 const UdpPtr &operator=(const UdpPtr &t)
805 { set(t.p, t._off); return *this; }
806 // end of api_inet
807
812 const EthPacketPtr packet() const { return p; }
813 EthPacketPtr packet() { return p; }
814 bool operator!() const { return !p; }
815 operator bool() const { return (p != nullptr); }
816 int off() const { return _off; }
817 int pstart() const { return off() + get()->size(); }
818 // end of api_inet
819};
820
825uint16_t __tu_cksum6(const Ip6Ptr &ip6);
826uint16_t __tu_cksum(const IpPtr &ip);
827uint16_t cksum(const UdpPtr &ptr);
828 // end of api_inet
829
833int hsplit(const EthPacketPtr &ptr);
834
835} // namespace networking
836} // namespace gem5
837
838#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:211
const EthHdr & operator*() const
Definition inet.hh:212
EthHdr & operator*()
Definition inet.hh:208
EthHdr * operator->()
Definition inet.hh:207
const Ip6Hdr * operator->() const
Definition inet.hh:527
const Ip6Hdr & operator*() const
Definition inet.hh:528
Ip6Hdr & operator*()
Definition inet.hh:522
void set(const EthPacketPtr &ptr)
Definition inet.hh:494
const Ip6Hdr * get() const
Definition inet.hh:524
Ip6Hdr * operator->()
Definition inet.hh:521
const IpPtr & operator=(const EthPtr &ptr)
Definition inet.hh:406
EthPacketPtr p
Definition inet.hh:361
void set(const EthPacketPtr &ptr)
Definition inet.hh:364
const IpPtr & operator=(const IpPtr &ptr)
Definition inet.hh:407
IpHdr * operator->()
Definition inet.hh:391
const IpPtr & operator=(const EthPacketPtr &ptr)
Definition inet.hh:405
IpHdr & operator*()
Definition inet.hh:392
TcpHdr * operator->()
Definition inet.hh:679
void set(const EthPacketPtr &ptr, int offset)
Definition inet.hh:651
void set(const Ip6Ptr &ptr)
Definition inet.hh:659
const TcpHdr * operator->() const
Definition inet.hh:683
const TcpHdr * get() const
Definition inet.hh:682
const TcpHdr & operator*() const
Definition inet.hh:684
TcpHdr & operator*()
Definition inet.hh:680
void set(const IpPtr &ptr)
Definition inet.hh:652
UdpHdr & operator*()
Definition inet.hh:793
UdpPtr(const Ip6Ptr &ptr)
Definition inet.hh:787
const UdpHdr * get() const
Definition inet.hh:795
UdpPtr(const UdpPtr &ptr)
Definition inet.hh:788
const UdpHdr & operator*() const
Definition inet.hh:797
void set(const Ip6Ptr &ptr)
Definition inet.hh:773
UdpHdr * operator->()
Definition inet.hh:792
void set(const IpPtr &ptr)
Definition inet.hh:766
void set(const EthPacketPtr &ptr, int offset)
Definition inet.hh:765
const UdpHdr * operator->() const
Definition inet.hh:796
UdpPtr(const IpPtr &ptr)
Definition inet.hh:786
STL vector class.
Definition stl.hh:37
uint8_t netmask() const
Definition inet.hh:286
Ip6Ptr(const EthPacketPtr &ptr)
Definition inet.hh:514
const EthPacketPtr packet() const
Definition inet.hh:413
int pstart() const
Definition inet.hh:817
bool broadcast() const
Definition inet.hh:116
const EthPacketPtr packet() const
Definition inet.hh:224
bool operator!() const
Definition inet.hh:415
const TcpPtr & operator=(const TcpPtr &t)
Definition inet.hh:692
bool operator!() const
Definition inet.hh:702
uint16_t cksum(const IpPtr &ptr)
Definition inet.cc:208
EthPacketPtr packet()
Definition inet.hh:701
const IpHdr * get() const
Definition inet.hh:398
uint16_t __tu_cksum6(const Ip6Ptr &ip6)
Definition inet.cc:225
int hsplit(const EthPacketPtr &ptr)
Definition inet.cc:386
const EthPacketPtr packet() const
Definition inet.hh:812
bool multicast() const
Definition inet.hh:115
int pstart() const
Definition inet.hh:705
const IpHdr & operator*() const
Definition inet.hh:402
const Ip6Ptr & operator=(const EthPacketPtr &ptr)
Definition inet.hh:534
bool unicast() const
Definition inet.hh:114
const Ip6Ptr & operator=(const EthPtr &ptr)
Definition inet.hh:536
uint16_t __tu_cksum(const IpPtr &ip)
Definition inet.cc:215
uint8_t port() const
Definition inet.hh:314
std::string string() const
Definition inet.cc:141
const TcpPtr & operator=(const IpPtr &i)
Definition inet.hh:690
const IpHdr * operator->() const
Definition inet.hh:401
const EthPtr & operator=(const EthPacketPtr &ptr)
Definition inet.hh:218
EthPtr(const EthPacketPtr &ptr)
Definition inet.hh:204
const EthPacketPtr packet() const
Definition inet.hh:546
const uint8_t * addr() const
Definition inet.hh:113
Ip6Ptr(const Ip6Ptr &ptr)
Definition inet.hh:516
int pstart() const
Definition inet.hh:229
TcpPtr(const IpPtr &ptr)
Definition inet.hh:673
bool operator==(const EthAddr &left, const EthAddr &right)
Definition inet.cc:127
TcpPtr(const Ip6Ptr &ptr)
Definition inet.hh:674
int pstart() const
Definition inet.hh:551
const uint8_t * bytes() const
Definition inet.hh:105
EthPacketPtr packet()
Definition inet.hh:813
bool operator!() const
Definition inet.hh:548
const UdpPtr & operator=(const UdpPtr &t)
Definition inet.hh:804
IpPtr(const EthPtr &ptr)
Definition inet.hh:385
const Ip6Ptr & operator=(const Ip6Ptr &ptr)
Definition inet.hh:538
std::string string() const
Definition inet.cc:119
int pstart() const
Definition inet.hh:418
Ip6Ptr(const EthPtr &ptr)
Definition inet.hh:515
const EthPacketPtr packet() const
Definition inet.hh:700
const UdpPtr & operator=(const IpPtr &i)
Definition inet.hh:803
std::ostream & operator<<(std::ostream &stream, const EthAddr &ea)
Definition inet.cc:133
IpPtr(const IpPtr &ptr)
Definition inet.hh:386
EthPacketPtr packet()
Definition inet.hh:225
EthPacketPtr packet()
Definition inet.hh:414
const EthAddr & operator=(const eth_addr &ea)
Definition inet.cc:83
IpPtr(const EthPacketPtr &ptr)
Definition inet.hh:384
bool operator!() const
Definition inet.hh:814
bool operator!() const
Definition inet.hh:226
IpAddress(const uint32_t __ip)
Definition inet.hh:248
uint32_t ip() const
Definition inet.hh:255
EthPacketPtr packet()
Definition inet.hh:547
TcpPtr(const TcpPtr &ptr)
Definition inet.hh:675
int off() const
Definition inet.hh:417
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 3 > ea
Bitfield< 12, 11 > set
Bitfield< 14 > rr
Bitfield< 12 > ext
Bitfield< 55, 52 > ts
Bitfield< 14 > ip6
Bitfield< 18, 16 > ia
Bitfield< 25 > vec
Definition misc.hh:113
Bitfield< 5, 3 > reg
Definition types.hh:92
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< EthPacketData > EthPacketPtr
Definition etherpkt.hh:90
PM4 packets.
void parse(const std::string &addr)
Definition inet.cc:97
uint8_t * bytes()
Definition inet.hh:187
const uint8_t * bytes() const
Definition inet.hh:185
const uint8_t * payload() const
Definition inet.hh:186
bool isVlan() const
Definition inet.hh:159
const EthAddr & dst() const
Definition inet.hh:176
const EthAddr & src() const
Definition inet.hh:175
uint16_t type() const
Definition inet.hh:160
uint16_t vlanId() const
Definition inet.hh:168
uint8_t * payload()
Definition inet.hh:188
uint32_t flow() const
Definition inet.hh:459
const Ip6Opt * dstOptExt() const
Definition inet.hh:472
uint8_t * payload()
Definition inet.hh:482
uint8_t * bytes()
Definition inet.hh:481
const uint8_t * src() const
Definition inet.hh:465
const Ip6Opt * rtTypeExt() const
Definition inet.hh:471
uint8_t nxt() const
Definition inet.hh:462
uint16_t plen() const
Definition inet.hh:460
uint16_t hlen() const
Definition inet.hh:461
const uint8_t * dst() const
Definition inet.hh:466
const Ip6Opt * getExt(uint8_t ext) const
Definition inet.cc:322
const uint8_t * bytes() const
Definition inet.hh:478
uint8_t version() const
Definition inet.hh:458
uint8_t hlim() const
Definition inet.hh:463
uint8_t proto() const
Definition inet.cc:348
void plen(uint16_t _plen)
Definition inet.hh:475
const Ip6Opt * fragmentExt() const
Definition inet.hh:470
int extensionLength() const
Definition inet.cc:299
const uint8_t * payload() const
Definition inet.hh:479
uint16_t fragmentOfflg() const
Definition inet.hh:606
uint8_t nxt() const
Definition inet.hh:593
uint8_t dstOptType() const
Definition inet.hh:610
const uint8_t * dstOptAddr() const
Definition inet.hh:612
uint32_t fragmentIdent() const
Definition inet.hh:607
uint8_t rtType2Type() const
Definition inet.hh:601
uint8_t len() const
Definition inet.hh:595
uint8_t extlen() const
Definition inet.hh:594
uint8_t dstOptLength() const
Definition inet.hh:611
uint8_t rtType2SegLft() const
Definition inet.hh:602
const uint8_t * rtType2Addr() const
Definition inet.hh:603
const uint8_t * bytes() const
Definition inet.hh:350
uint16_t len() const
Definition inet.hh:333
uint8_t * bytes()
Definition inet.hh:352
uint8_t * payload()
Definition inet.hh:353
uint16_t frag_flags() const
Definition inet.hh:335
uint8_t proto() const
Definition inet.hh:338
void id(uint16_t _id)
Definition inet.hh:344
uint8_t version() const
Definition inet.hh:330
uint8_t hlen() const
Definition inet.hh:331
int size() const
Definition inet.hh:349
const uint8_t * payload() const
Definition inet.hh:351
void len(uint16_t _len)
Definition inet.hh:345
uint16_t sum() const
Definition inet.hh:339
uint16_t frag_off() const
Definition inet.hh:336
uint8_t ttl() const
Definition inet.hh:337
uint32_t src() const
Definition inet.hh:340
uint8_t tos() const
Definition inet.hh:332
bool options(std::vector< const IpOpt * > &vec) const
Definition inet.cc:262
uint32_t dst() const
Definition inet.hh:341
uint16_t id() const
Definition inet.hh:334
void sum(uint16_t sum)
Definition inet.hh:343
IpNetmask(const uint32_t __ip, const uint8_t __netmask)
Definition inet.hh:279
std::string string() const
Definition inet.cc:165
bool isNumber(int num) const
Definition inet.hh:435
uint16_t mtup() const
Definition inet.hh:445
uint8_t len() const
Definition inet.hh:433
uint8_t typeNumber() const
Definition inet.hh:430
bool isClass(int cls) const
Definition inet.hh:436
uint8_t typeClass() const
Definition inet.hh:431
uint16_t mtur() const
Definition inet.hh:446
uint16_t rtralt() const
Definition inet.hh:448
void sdb(std::vector< uint32_t > &vec) const
uint8_t type() const
Definition inet.hh:429
void ssrr(ip_opt_data_rr &rr) const
void ts(ip_opt_data_ts &ts) const
const uint8_t * data() const
Definition inet.hh:439
uint8_t typeCopied() const
Definition inet.hh:432
void sec(ip_opt_data_sec &sec) const
uint16_t satid() const
Definition inet.hh:444
void tr(ip_opt_data_tr &tr) const
bool isCopied(int cpy) const
Definition inet.hh:437
void lsrr(ip_opt_data_rr &rr) const
std::string string() const
Definition inet.cc:187
IpWithPort(const uint32_t __ip, const uint16_t __port)
Definition inet.hh:307
uint8_t * bytes()
Definition inet.hh:641
void sum(uint16_t sum)
Definition inet.hh:632
uint8_t * payload()
Definition inet.hh:642
bool options(std::vector< const TcpOpt * > &vec) const
Definition inet.cc:365
const uint8_t * bytes() const
Definition inet.hh:639
uint16_t win() const
Definition inet.hh:628
uint32_t ack() const
Definition inet.hh:625
uint16_t sum() const
Definition inet.hh:629
void seq(uint32_t _seq)
Definition inet.hh:633
uint16_t urp() const
Definition inet.hh:630
uint32_t seq() const
Definition inet.hh:624
void flags(uint8_t _flags)
Definition inet.hh:634
uint8_t flags() const
Definition inet.hh:627
uint16_t sport() const
Definition inet.hh:622
uint8_t off() const
Definition inet.hh:626
const uint8_t * payload() const
Definition inet.hh:640
uint16_t dport() const
Definition inet.hh:623
const uint8_t * payload() const
Definition inet.hh:734
uint8_t * payload()
Definition inet.hh:736
uint8_t len() const
Definition inet.hh:717
uint32_t cc() const
Definition inet.hh:728
uint8_t cksum() const
Definition inet.hh:729
uint8_t wscale() const
Definition inet.hh:724
const uint8_t * bytes() const
Definition inet.hh:733
uint8_t * bytes()
Definition inet.hh:735
uint32_t echo() const
Definition inet.hh:725
const uint8_t * md5() const
Definition inet.hh:730
uint8_t type() const
Definition inet.hh:716
uint16_t mss() const
Definition inet.hh:723
bool isopt(int opt) const
Definition inet.hh:719
uint32_t tsval() const
Definition inet.hh:726
const uint8_t * data() const
Definition inet.hh:721
uint32_t tsecr() const
Definition inet.hh:727
uint8_t * payload()
Definition inet.hh:756
const uint8_t * bytes() const
Definition inet.hh:753
const uint8_t * payload() const
Definition inet.hh:754
uint16_t len() const
Definition inet.hh:746
void sum(uint16_t sum)
Definition inet.hh:749
uint16_t sum() const
Definition inet.hh:747
uint16_t sport() const
Definition inet.hh:744
uint8_t * bytes()
Definition inet.hh:755
uint16_t dport() const
Definition inet.hh:745
void len(uint16_t _len)
Definition inet.hh:750
union gem5::networking::ip6_opt_hdr::@46 ext_data

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0