Loading...
Searching...
No Matches
gnrc_pktsnip Struct Reference

Type to represent parts (either headers or payload) of a packet, called snips. More...

Detailed Description

Type to represent parts (either headers or payload) of a packet, called snips.

The idea behind the packet snips is that they either can represent protocol-specific headers or payload. A packet can be comprised of multiple pktsnip_t elements.

Example:

                                                    buffer
+---------------------------+                      +------+
| size = 14                 | data +-------------->|      |
| type = NETTYPE_ETHERNET   |------+               +------+
+---------------------------+                      .      .
      | next                                       .      .
      v                                            +------+
+---------------------------+         +----------->|      |
| size = 40                 | data    |            |      |
| type = NETTYPE_IPV6       |---------+            +------+
+---------------------------+                      .      .
      | next                                       .      .
      v                                            +------+
+---------------------------+            +-------->|      |
| size = 8                  | data       |         +------+
| type = NETTYPE_UDP        |------------+         .      .
+---------------------------+                      .      .
      | next                                       +------+
      v                                     +----->|      |
+---------------------------+               |      |      |
| size = 59                 | data          |      .      .
| type = NETTYPE_UNDEF      |---------------+      .      .
+---------------------------+                      .      .

To keep data duplication as low as possible the order of the snips in a packet will be reversed depending on if you send the packet or if you received it. For sending the order is from (in the network stack) lowest protocol snip to the highest, for receiving the order is from highest snip to the lowest. This way, if a layer needs to duplicate the packet a tree is created rather than a duplication of the whole package.

A very extreme example for this (we only expect one or two duplications at maximum per package) can be seen here:

 Sending                          Receiving
 =======                          =========

 * Payload                        * L2 header
 ^                                ^
 |                                |
 |\                               |\
 | * L4 header 1                  | * L2.5 header 1
 | * L3 header 1                  | * L3 header 1
 | * netif header 1               | * L4 header 1
 * L4 header 2                    | * Payload 1
 ^                                * L3 header 2
 |                                ^
 |\                               |
 | * L3 header 2                  |\
 | * L2 header 2                  | * L4 header 2
 * L2 header 3                    | * Payload 2
 |\                               * Payload 3
 | * L2 header 3
 * L2 header 4

The first three fields (next, data, size) match iolist_t (named iol_next, iol_base and iol_len there). That means that any pktsnip can be casted to iolist_t for direct passing to e.g., netdev send() functions.

Note
This type has no initializer on purpose. Please use Packet buffer as factory.

Definition at line 108 of file pkt.h.

#include <pkt.h>

Data Fields

struct gnrc_pktsnipnext
 next snip in the packet
 
void * data
 pointer to the data of the snip
 
size_t size
 the length of the snip in byte
 
unsigned int users
 Counter of threads currently having control over this packet.
 
gnrc_nettype_t type
 protocol of the packet snip
 

Field Documentation

◆ data

void* gnrc_pktsnip::data

pointer to the data of the snip

Definition at line 111 of file pkt.h.

◆ next

struct gnrc_pktsnip* gnrc_pktsnip::next

next snip in the packet

Definition at line 110 of file pkt.h.

◆ size

size_t gnrc_pktsnip::size

the length of the snip in byte

Definition at line 112 of file pkt.h.

◆ type

gnrc_nettype_t gnrc_pktsnip::type

protocol of the packet snip

Definition at line 119 of file pkt.h.

◆ users

unsigned int gnrc_pktsnip::users

Counter of threads currently having control over this packet.

Definition at line 118 of file pkt.h.


The documentation for this struct was generated from the following file: