MoonGen
 All Files Functions Variables Pages
headers.lua
Go to the documentation of this file.
1 ------------------------------------------------------------------------
2 --- @file headers.lua
3 --- @brief C struct definitions for all protocol headers and respective
4 --- additional structs for instance addresses.
5 --- Please check the source code for more information.
6 ------------------------------------------------------------------------
7 
8 local ffi = require "ffi"
9 
10 -- structs
11 ffi.cdef[[
12  // TODO: vlan support (which can be offloaded to the NIC to simplify scripts)
13 
14  union payload_t {
15  uint8_t uint8[0];
16  uint16_t uint16[0];
17  uint32_t uint32[0];
18  uint64_t uint64[0];
19  };
20 
21  // -----------------------------------------------------
22  // ---- Address structs
23  // -----------------------------------------------------
24 
25  struct __attribute__ ((__packed__)) mac_address {
26  uint8_t uint8[6];
27  };
28 
29  union ip4_address {
30  uint8_t uint8[4];
31  uint32_t uint32;
32  };
33 
34  union ip6_address {
35  uint8_t uint8[16];
36  uint32_t uint32[4];
37  uint64_t uint64[2];
38  };
39 
40  union ipsec_iv {
41  uint32_t uint32[2];
42  };
43 
44  union ipsec_icv {
45  uint32_t uint32[4];
46  };
47 
48 
49  // -----------------------------------------------------
50  // ---- Header structs
51  // -----------------------------------------------------
52 
53  struct __attribute__((__packed__)) ethernet_header {
54  struct mac_address dst;
55  struct mac_address src;
56  uint16_t type;
57  };
58 
59  struct __attribute__((__packed__)) arp_header {
60  uint16_t hrd;
61  uint16_t pro;
62  uint8_t hln;
63  uint8_t pln;
64  uint16_t op;
65  struct mac_address sha;
66  union ip4_address spa;
67  struct mac_address tha;
68  union ip4_address tpa;
69  };
70 
71  struct __attribute__((__packed__)) ptp_header {
72  uint8_t messageType;
73  uint8_t versionPTP;
74  uint16_t len;
75  uint8_t domain;
76  uint8_t reserved;
77  uint16_t flags;
78  uint32_t correction[2];
79  uint32_t reserved2;
80  uint8_t oui[3];
81  uint8_t uuid[5];
82  uint16_t ptpNodePort;
83  uint16_t sequenceId;
84  uint8_t control;
85  uint8_t logMessageInterval;
86  };
87 
88  struct __attribute__((__packed__)) ip4_header {
89  uint8_t verihl;
90  uint8_t tos;
91  uint16_t len;
92  uint16_t id;
93  uint16_t frag;
94  uint8_t ttl;
95  uint8_t protocol;
96  uint16_t cs;
97  union ip4_address src;
98  union ip4_address dst;
99  };
100 
101  struct __attribute__((__packed__)) ip6_header {
102  uint32_t vtf;
103  uint16_t len;
104  uint8_t nextHeader;
105  uint8_t ttl;
106  union ip6_address src;
107  union ip6_address dst;
108  };
109 
110  struct __attribute__((__packed__)) icmp_header {
111  uint8_t type;
112  uint8_t code;
113  uint16_t cs;
114  union payload_t body;
115  };
116 
117  struct __attribute__((__packed__)) udp_header {
118  uint16_t src;
119  uint16_t dst;
120  uint16_t len;
121  uint16_t cs;
122  };
123 
124  struct __attribute__((__packed__)) tcp_header {
125  uint16_t src;
126  uint16_t dst;
127  uint32_t seq;
128  uint32_t ack;
129  uint8_t offset;
130  uint8_t flags;
131  uint16_t window;
132  uint16_t cs;
133  uint16_t urg;
134  uint32_t options[];
135  };
136 
137  struct __attribute__((__packed__)) esp_header {
138  uint32_t spi;
139  uint32_t sqn;
140  union ipsec_iv iv;
141  };
142 
143  struct __attribute__((__packed__)) ah_header {
144  uint8_t nextHeader;
145  uint8_t len;
146  uint16_t reserved;
147  uint32_t spi;
148  uint32_t sqn;
149  union ipsec_iv iv;
150  union ipsec_icv icv;
151  };
152 ]]
153 
154 return ffi.C
local ffi
low-level dpdk wrapper
Definition: dpdkc.lua:6