Adding pad for reasm vnet_buffer reasm struct sothat adj_index is retained
[vpp.git] / src / vnet / buffer.h
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * vnet/buffer.h: vnet buffer flags
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39
40 #ifndef included_vnet_buffer_h
41 #define included_vnet_buffer_h
42
43 #include <vlib/vlib.h>
44
45 /**
46  * Flags that are set in the high order bits of ((vlib_buffer*)b)->flags
47  */
48 #define foreach_vnet_buffer_flag \
49   _( 1, L4_CHECKSUM_COMPUTED, "l4-cksum-computed")      \
50   _( 2, L4_CHECKSUM_CORRECT, "l4-cksum-correct")        \
51   _( 3, VLAN_2_DEEP, "vlan-2-deep")                     \
52   _( 4, VLAN_1_DEEP, "vlan-1-deep")                     \
53   _( 5, SPAN_CLONE, "span-clone")                       \
54   _( 6, HANDOFF_NEXT_VALID, "handoff-next-valid")       \
55   _( 7, LOCALLY_ORIGINATED, "local")                    \
56   _( 8, IS_IP4, "ip4")                                  \
57   _( 9, IS_IP6, "ip6")                                  \
58   _(10, OFFLOAD_IP_CKSUM, "offload-ip-cksum")           \
59   _(11, OFFLOAD_TCP_CKSUM, "offload-tcp-cksum")         \
60   _(12, OFFLOAD_UDP_CKSUM, "offload-udp-cksum")         \
61   _(13, IS_NATED, "nated")                              \
62   _(14, L2_HDR_OFFSET_VALID, 0)                         \
63   _(15, L3_HDR_OFFSET_VALID, 0)                         \
64   _(16, L4_HDR_OFFSET_VALID, 0)                         \
65   _(17, FLOW_REPORT, "flow-report")                     \
66   _(18, IS_DVR, "dvr")                                  \
67   _(19, QOS_DATA_VALID, 0)
68
69 #define VNET_BUFFER_FLAGS_VLAN_BITS \
70   (VNET_BUFFER_F_VLAN_1_DEEP | VNET_BUFFER_F_VLAN_2_DEEP)
71
72 enum
73 {
74 #define _(bit, name, v) VNET_BUFFER_F_##name  = (1 << LOG2_VLIB_BUFFER_FLAG_USER(bit)),
75   foreach_vnet_buffer_flag
76 #undef _
77 };
78
79 enum
80 {
81 #define _(bit, name, v) VNET_BUFFER_F_LOG2_##name  = LOG2_VLIB_BUFFER_FLAG_USER(bit),
82   foreach_vnet_buffer_flag
83 #undef _
84 };
85
86 #define foreach_buffer_opaque_union_subtype     \
87 _(ip)                                           \
88 _(swt)                                          \
89 _(l2)                                           \
90 _(l2t)                                          \
91 _(l2_classify)                                  \
92 _(handoff)                                      \
93 _(policer)                                      \
94 _(ipsec)                                        \
95 _(map)                                          \
96 _(map_t)                                        \
97 _(ip_frag)                                      \
98 _(mpls)                                         \
99 _(tcp)
100
101 /*
102  * vnet stack buffer opaque array overlay structure.
103  * The vnet_buffer_opaque_t *must* be the same size as the
104  * vlib_buffer_t "opaque" structure member, 32 bytes.
105  *
106  * When adding a union type, please add a stanza to
107  * foreach_buffer_opaque_union_subtype (directly above).
108  * Code in vnet_interface_init(...) verifies the size
109  * of the union, and will announce any deviations in an
110  * impossible-to-miss manner.
111  */
112 typedef struct
113 {
114   u32 sw_if_index[VLIB_N_RX_TX];
115   i16 l2_hdr_offset;
116   i16 l3_hdr_offset;
117   i16 l4_hdr_offset;
118   u8 feature_arc_index;
119   u8 dont_waste_me;
120
121   union
122   {
123     /* IP4/6 buffer opaque. */
124     struct
125     {
126       /* Adjacency from destination IP address lookup [VLIB_TX].
127          Adjacency from source IP address lookup [VLIB_RX].
128          This gets set to ~0 until source lookup is performed. */
129       u32 adj_index[VLIB_N_RX_TX];
130
131       union
132       {
133         struct
134         {
135           /* Flow hash value for this packet computed from IP src/dst address
136              protocol and ports. */
137           u32 flow_hash;
138
139           union
140           {
141             /* next protocol */
142             u32 save_protocol;
143
144             /* Hint for transport protocols */
145             u32 fib_index;
146           };
147
148           /* Rewrite length */
149           u32 save_rewrite_length;
150
151           /* MFIB RPF ID */
152           u32 rpf_id;
153         };
154
155         /* ICMP */
156         struct
157         {
158           u8 type;
159           u8 code;
160           u32 data;
161         } icmp;
162
163         /* reassembly */
164         union
165         {
166           u32 pad[2];           /* do not overlay w/ ip.adj_index[0,1] */
167           /* in/out variables */
168           struct
169           {
170             u32 next_index;     /* index of next node - ignored if "feature" node */
171             u16 estimated_mtu;  /* estimated MTU calculated during reassembly */
172           };
173           /* internal variables used during reassembly */
174           struct
175           {
176             u16 fragment_first;
177             u16 fragment_last;
178             u16 range_first;
179             u16 range_last;
180             u32 next_range_bi;
181             u16 ip6_frag_hdr_offset;
182           };
183         } reass;
184       };
185
186     } ip;
187
188     /*
189      * MPLS:
190      * data copied from the MPLS header that was popped from the packet
191      * during the look-up.
192      */
193     struct
194     {
195       /* do not overlay w/ ip.adj_index[0,1] nor flow hash */
196       u32 pad[VLIB_N_RX_TX + 1];
197       u8 ttl;
198       u8 exp;
199       u8 first;
200       /* Rewrite length */
201       u32 save_rewrite_length;
202       /*
203        * BIER - the nubmer of bytes in the header.
204        *  the len field inthe header is not authoritative. It's the
205        * value in the table that counts.
206        */
207       struct
208       {
209         u8 n_bytes;
210       } bier;
211     } mpls;
212
213     /* ip4-in-ip6 softwire termination, only valid there */
214     struct
215     {
216       u8 swt_disable;
217       u32 mapping_index;
218     } swt;
219
220     /* l2 bridging path, only valid there */
221     struct opaque_l2
222     {
223       u32 feature_bitmap;
224       u16 bd_index;             /* bridge-domain index */
225       u8 l2_len;                /* ethernet header length */
226       u8 shg;                   /* split-horizon group */
227       u16 l2fib_sn;             /* l2fib bd/int seq_num */
228       u8 bd_age;                /* aging enabled */
229     } l2;
230
231     /* l2tpv3 softwire encap, only valid there */
232     struct
233     {
234       u32 pad[4];               /* do not overlay w/ ip.adj_index[0,1] */
235       u8 next_index;
236       u32 session_index;
237     } l2t;
238
239     /* L2 classify */
240     struct
241     {
242       struct opaque_l2 pad;
243       union
244       {
245         u32 table_index;
246         u32 opaque_index;
247       };
248       u64 hash;
249     } l2_classify;
250
251     /* IO - worker thread handoff */
252     struct
253     {
254       u32 next_index;
255     } handoff;
256
257     /* vnet policer */
258     struct
259     {
260       u32 pad[8 - VLIB_N_RX_TX - 1];    /* to end of opaque */
261       u32 index;
262     } policer;
263
264     /* interface output features */
265     struct
266     {
267       u32 flags;
268       u32 sad_index;
269     } ipsec;
270
271     /* MAP */
272     struct
273     {
274       u16 mtu;
275     } map;
276
277     /* MAP-T */
278     struct
279     {
280       u32 map_domain_index;
281       struct
282       {
283         u32 saddr, daddr;
284         u16 frag_offset;        //Fragmentation header offset
285         u16 l4_offset;          //L4 header overall offset
286         u8 l4_protocol;         //The final protocol number
287       } v6;                     //Used by ip6_map_t only
288       u16 checksum_offset;      //L4 checksum overall offset
289       u16 mtu;                  //Exit MTU
290     } map_t;
291
292     /* IP Fragmentation */
293     struct
294     {
295       u32 pad[2];               /* do not overlay w/ ip.adj_index[0,1] */
296       u16 header_offset;
297       u16 mtu;
298       u8 next_index;
299       u8 flags;                 //See ip_frag.h
300     } ip_frag;
301
302     /* COP - configurable junk filter(s) */
303     struct
304     {
305       /* Current configuration index. */
306       u32 current_config_index;
307     } cop;
308
309     /* LISP */
310     struct
311     {
312       /* overlay address family */
313       u16 overlay_afi;
314     } lisp;
315
316     /* Driver rx feature */
317     struct
318     {
319       u32 saved_next_index;             /**< saved by drivers for short-cut */
320       u16 buffer_advance;
321     } device_input_feat;
322
323     /* TCP */
324     struct
325     {
326       u32 connection_index;
327       u32 seq_number;
328       u32 seq_end;
329       u32 ack_number;
330       u16 hdr_offset;           /**< offset relative to ip hdr */
331       u16 data_offset;          /**< offset relative to ip hdr */
332       u16 data_len;             /**< data len */
333       u8 flags;
334     } tcp;
335
336     /* SCTP */
337     struct
338     {
339       u32 connection_index;
340       u16 sid; /**< Stream ID */
341       u16 ssn; /**< Stream Sequence Number */
342       u32 tsn; /**< Transmission Sequence Number */
343       u16 hdr_offset;           /**< offset relative to ip hdr */
344       u16 data_offset;          /**< offset relative to ip hdr */
345       u16 data_len;             /**< data len */
346       u8 subconn_idx; /**< index of the sub_connection being used */
347       u8 flags;
348     } sctp;
349
350     /* SNAT */
351     struct
352     {
353       u32 flags;
354     } snat;
355
356     u32 unused[6];
357   };
358 } vnet_buffer_opaque_t;
359
360 /*
361  * The opaque field of the vlib_buffer_t is intepreted as a
362  * vnet_buffer_opaque_t. Hence it should be big enough to accommodate one.
363  */
364 STATIC_ASSERT (sizeof (vnet_buffer_opaque_t) <=
365                STRUCT_SIZE_OF (vlib_buffer_t, opaque),
366                "VNET buffer meta-data too large for vlib_buffer");
367
368 #define vnet_buffer(b) ((vnet_buffer_opaque_t *) (b)->opaque)
369
370 /* Full cache line (64 bytes) of additional space */
371 typedef struct
372 {
373   /**
374    * QoS marking data that needs to persist from the recording nodes
375    * (nominally in the ingress path) to the marking node (in the
376    * egress path)
377    */
378   struct
379   {
380     u8 bits;
381     u8 source;
382   } qos;
383
384   u8 __unused[2];
385
386   /* Group Based Policy */
387   struct
388   {
389     u32 src_epg;
390   } gbp;
391
392   union
393   {
394     struct
395     {
396 #if VLIB_BUFFER_TRACE_TRAJECTORY > 0
397       /* buffer trajectory tracing */
398       u16 *trajectory_trace;
399 #endif
400     };
401     struct
402     {
403       u64 pad[1];
404       u64 pg_replay_timestamp;
405     };
406     u32 unused[10];
407   };
408 } vnet_buffer_opaque2_t;
409
410 #define vnet_buffer2(b) ((vnet_buffer_opaque2_t *) (b)->opaque2)
411
412 /*
413  * The opaque2 field of the vlib_buffer_t is intepreted as a
414  * vnet_buffer_opaque2_t. Hence it should be big enough to accommodate one.
415  */
416 STATIC_ASSERT (sizeof (vnet_buffer_opaque2_t) <=
417                STRUCT_SIZE_OF (vlib_buffer_t, opaque2),
418                "VNET buffer opaque2 meta-data too large for vlib_buffer");
419
420 format_function_t format_vnet_buffer;
421
422 #endif /* included_vnet_buffer_h */
423
424 /*
425  * fd.io coding-style-patch-verification: ON
426  *
427  * Local Variables:
428  * eval: (c-set-style "gnu")
429  * End:
430  */