Deleted Added
sdiff udiff text old ( 9554:406fbcf60223 ) new ( 9955:5d8722ab804b )
full compact
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * Copyright (c) 2010 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;

--- 14 unchanged lines hidden (view full) ---

24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Nathan Binkert
30 * Steve Reinhardt
31 * Gabe Black
32 */
33
34#ifndef __BASE_INET_HH__
35#define __BASE_INET_HH__
36
37#include <iosfwd>
38#include <string>
39#include <utility>

--- 59 unchanged lines hidden (view full) ---

99
100};
101
102std::ostream &operator<<(std::ostream &stream, const EthAddr &ea);
103bool operator==(const EthAddr &left, const EthAddr &right);
104
105struct EthHdr : public eth_hdr
106{
107 uint16_t type() const { return ntohs(eth_type); }
108 const EthAddr &src() const { return *(EthAddr *)&eth_src; }
109 const EthAddr &dst() const { return *(EthAddr *)&eth_dst; }
110
111 int size() const { return sizeof(eth_hdr); }
112
113 const uint8_t *bytes() const { return (const uint8_t *)this; }
114 const uint8_t *payload() const { return bytes() + size(); }
115 uint8_t *bytes() { return (uint8_t *)this; }
116 uint8_t *payload() { return bytes() + size(); }
117};
118
119class EthPtr
120{
121 protected:
122 friend class IpPtr;
123 EthPacketPtr p;
124
125 public:
126 EthPtr() {}
127 EthPtr(const EthPacketPtr &ptr) : p(ptr) { }
128
129 EthHdr *operator->() { return (EthHdr *)p->data; }
130 EthHdr &operator*() { return *(EthHdr *)p->data; }

--- 90 unchanged lines hidden (view full) ---

221 uint16_t sum() const { return ip_sum; }
222 uint32_t src() const { return ntohl(ip_src); }
223 uint32_t dst() const { return ntohl(ip_dst); }
224
225 void sum(uint16_t sum) { ip_sum = sum; }
226 void id(uint16_t _id) { ip_id = htons(_id); }
227 void len(uint16_t _len) { ip_len = htons(_len); }
228
229
230 bool options(std::vector<const IpOpt *> &vec) const;
231
232 int size() const { return hlen(); }
233 const uint8_t *bytes() const { return (const uint8_t *)this; }
234 const uint8_t *payload() const { return bytes() + size(); }
235 uint8_t *bytes() { return (uint8_t *)this; }
236 uint8_t *payload() { return bytes() + size(); }
237};
238
239class IpPtr
240{
241 protected:
242 friend class TcpPtr;
243 friend class UdpPtr;
244 EthPacketPtr p;
245
246 void set(const EthPacketPtr &ptr)
247 {
248 p = 0;
249
250 if (ptr) {
251 EthHdr *eth = (EthHdr *)ptr->data;
252 if (eth->type() == ETH_TYPE_IP)
253 p = ptr;
254 }
255 }
256
257 public:
258 IpPtr() : p(0) {}
259 IpPtr(const EthPacketPtr &ptr) : p(0) { set(ptr); }
260 IpPtr(const EthPtr &ptr) : p(0) { set(ptr.p); }
261 IpPtr(const IpPtr &ptr) : p(ptr.p) { }
262
263 IpHdr *get() { return (IpHdr *)(p->data + sizeof(eth_hdr)); }
264 IpHdr *operator->() { return get(); }
265 IpHdr &operator*() { return *get(); }
266
267 const IpHdr *get() const
268 { return (const IpHdr *)(p->data + sizeof(eth_hdr)); }
269 const IpHdr *operator->() const { return get(); }
270 const IpHdr &operator*() const { return *get(); }
271
272 const IpPtr &operator=(const EthPacketPtr &ptr) { set(ptr); return *this; }
273 const IpPtr &operator=(const EthPtr &ptr) { set(ptr.p); return *this; }
274 const IpPtr &operator=(const IpPtr &ptr) { p = ptr.p; return *this; }
275
276 const EthPacketPtr packet() const { return p; }
277 EthPacketPtr packet() { return p; }
278 bool operator!() const { return !p; }
279 operator bool() const { return p; }
280 int off() const { return sizeof(eth_hdr); }
281 int pstart() const { return off() + get()->size(); }
282};
283
284uint16_t cksum(const IpPtr &ptr);
285
286struct IpOpt : public ip_opt
287{
288 uint8_t type() const { return opt_type; }
289 uint8_t typeNumber() const { return IP_OPT_NUMBER(opt_type); }

--- 15 unchanged lines hidden (view full) ---

305 uint16_t mtur() const { return ntohs(opt_data.mtu); }
306 void tr(ip_opt_data_tr &tr) const;
307 const uint32_t *addext() const { return &opt_data.addext[0]; }
308 uint16_t rtralt() const { return ntohs(opt_data.rtralt); }
309 void sdb(std::vector<uint32_t> &vec) const;
310};
311
312/*
313 * TCP Stuff
314 */
315struct TcpOpt;
316struct TcpHdr : public tcp_hdr
317{
318 uint16_t sport() const { return ntohs(th_sport); }
319 uint16_t dport() const { return ntohs(th_dport); }
320 uint32_t seq() const { return ntohl(th_seq); }
321 uint32_t ack() const { return ntohl(th_ack); }
322 uint8_t off() const { return th_off; }
323 uint8_t flags() const { return th_flags & 0x3f; }
324 uint16_t win() const { return ntohs(th_win); }
325 uint16_t sum() const { return th_sum; }
326 uint16_t urp() const { return ntohs(th_urp); }
327
328 void sum(uint16_t sum) { th_sum = sum; }
329 void seq(uint32_t _seq) { th_seq = htonl(_seq); }
330 void flags(uint8_t _flags) { th_flags = _flags; }

--- 12 unchanged lines hidden (view full) ---

343 protected:
344 EthPacketPtr p;
345 int _off;
346
347 void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
348 void set(const IpPtr &ptr)
349 {
350 if (ptr && ptr->proto() == IP_PROTO_TCP)
351 set(ptr.p, sizeof(eth_hdr) + ptr->hlen());
352 else
353 set(0, 0);
354 }
355
356 public:
357 TcpPtr() : p(0), _off(0) {}
358 TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
359 TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
360
361 TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
362 TcpHdr *operator->() { return get(); }
363 TcpHdr &operator*() { return *get(); }
364
365 const TcpHdr *get() const { return (const TcpHdr *)(p->data + _off); }
366 const TcpHdr *operator->() const { return get(); }
367 const TcpHdr &operator*() const { return *get(); }
368
369 const TcpPtr &operator=(const IpPtr &i) { set(i); return *this; }
370 const TcpPtr &operator=(const TcpPtr &t) { set(t.p, t._off); return *this; }
371
372 const EthPacketPtr packet() const { return p; }
373 EthPacketPtr packet() { return p; }
374 bool operator!() const { return !p; }
375 operator bool() const { return p; }
376 int off() const { return _off; }
377 int pstart() const { return off() + get()->size(); }
378};

--- 50 unchanged lines hidden (view full) ---

429 protected:
430 EthPacketPtr p;
431 int _off;
432
433 void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
434 void set(const IpPtr &ptr)
435 {
436 if (ptr && ptr->proto() == IP_PROTO_UDP)
437 set(ptr.p, sizeof(eth_hdr) + ptr->hlen());
438 else
439 set(0, 0);
440 }
441
442 public:
443 UdpPtr() : p(0), _off(0) {}
444 UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
445 UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
446
447 UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
448 UdpHdr *operator->() { return get(); }
449 UdpHdr &operator*() { return *get(); }
450
451 const UdpHdr *get() const { return (const UdpHdr *)(p->data + _off); }
452 const UdpHdr *operator->() const { return get(); }
453 const UdpHdr &operator*() const { return *get(); }
454
455 const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
456 const UdpPtr &operator=(const UdpPtr &t) { set(t.p, t._off); return *this; }
457
458 const EthPacketPtr packet() const { return p; }
459 EthPacketPtr packet() { return p; }
460 bool operator!() const { return !p; }
461 operator bool() const { return p; }
462 int off() const { return _off; }
463 int pstart() const { return off() + get()->size(); }
464};
465
466uint16_t __tu_cksum(const IpPtr &ip);
467uint16_t cksum(const UdpPtr &ptr);
468
469int hsplit(const EthPacketPtr &ptr);
470
471} // namespace Net
472
473#endif // __BASE_INET_HH__