vnet_buffer_t flags cleanup
[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 #define foreach_vnet_buffer_field \
46   _( 1, L4_CHECKSUM_COMPUTED)                           \
47   _( 2, L4_CHECKSUM_CORRECT)                            \
48   _( 3, VLAN_2_DEEP)                                    \
49   _( 4, VLAN_1_DEEP)                                    \
50   _( 6, HANDOFF_NEXT_VALID)                             \
51   _( 7, LOCALLY_ORIGINATED)                             \
52   _( 8, SPAN_CLONE)
53
54 #define VNET_BUFFER_FLAGS_VLAN_BITS \
55   (VNET_BUFFER_F_VLAN_1_DEEP | VNET_BUFFER_F_VLAN_2_DEEP)
56
57 enum
58 {
59 #define _(bit, name) VNET_BUFFER_F_##name  = (1 << LOG2_VLIB_BUFFER_FLAG_USER(bit)),
60   foreach_vnet_buffer_field
61 #undef _
62 };
63
64 enum
65 {
66 #define _(bit, name) VNET_BUFFER_F_LOG2_##name  = LOG2_VLIB_BUFFER_FLAG_USER(bit),
67   foreach_vnet_buffer_field
68 #undef _
69 };
70
71
72 #define foreach_buffer_opaque_union_subtype     \
73 _(ip)                                           \
74 _(swt)                                          \
75 _(l2)                                           \
76 _(l2t)                                          \
77 _(gre)                                          \
78 _(l2_classify)                                  \
79 _(handoff)                                      \
80 _(policer)                                      \
81 _(ipsec)                                        \
82 _(map)                                          \
83 _(map_t)                                        \
84 _(ip_frag)                                      \
85 _(tcp)
86
87 /*
88  * vnet stack buffer opaque array overlay structure.
89  * The vnet_buffer_opaque_t *must* be the same size as the
90  * vlib_buffer_t "opaque" structure member, 32 bytes.
91  *
92  * When adding a union type, please add a stanza to
93  * foreach_buffer_opaque_union_subtype (directly above).
94  * Code in vnet_interface_init(...) verifies the size
95  * of the union, and will announce any deviations in an
96  * impossible-to-miss manner.
97  */
98 typedef struct
99 {
100   u32 sw_if_index[VLIB_N_RX_TX];
101   i16 l2_hdr_offset;
102   i16 l3_hdr_offset;
103   i16 l4_hdr_offset;
104
105   union
106   {
107     /* IP4/6 buffer opaque. */
108     struct
109     {
110       /* Adjacency from destination IP address lookup [VLIB_TX].
111          Adjacency from source IP address lookup [VLIB_RX].
112          This gets set to ~0 until source lookup is performed. */
113       u32 adj_index[VLIB_N_RX_TX];
114
115       union
116       {
117         struct
118         {
119           /* Flow hash value for this packet computed from IP src/dst address
120              protocol and ports. */
121           u32 flow_hash;
122
123           /* next protocol */
124           u32 save_protocol;
125
126           /* Rewrite length */
127           u32 save_rewrite_length;
128
129           /* MFIB RPF ID */
130           u32 rpf_id;
131         };
132
133         /* ICMP */
134         struct
135         {
136           u8 type;
137           u8 code;
138           u32 data;
139         } icmp;
140       };
141
142     } ip;
143
144     /*
145      * MPLS:
146      * data copied from the MPLS header that was popped from the packet
147      * during the look-up.
148      */
149     struct
150     {
151       u8 ttl;
152       u8 exp;
153       u8 first;
154     } mpls;
155
156     /* ip4-in-ip6 softwire termination, only valid there */
157     struct
158     {
159       u8 swt_disable;
160       u32 mapping_index;
161     } swt;
162
163     /* l2 bridging path, only valid there */
164     struct opaque_l2
165     {
166       u32 feature_bitmap;
167       u16 bd_index;             /* bridge-domain index */
168       u8 l2_len;                /* ethernet header length */
169       u8 shg;                   /* split-horizon group */
170       u16 l2fib_sn;             /* l2fib bd/int seq_num */
171     } l2;
172
173     /* l2tpv3 softwire encap, only valid there */
174     struct
175     {
176       u32 pad[4];               /* do not overlay w/ ip.adj_index[0,1] */
177       u8 next_index;
178       u32 session_index;
179     } l2t;
180
181     struct
182     {
183       u32 src, dst;
184     } gre;
185
186     /* L2 classify */
187     struct
188     {
189       struct opaque_l2 pad;
190       union
191       {
192         u32 table_index;
193         u32 opaque_index;
194       };
195       u64 hash;
196     } l2_classify;
197
198     /* IO - worker thread handoff */
199     struct
200     {
201       u32 next_index;
202     } handoff;
203
204     /* vnet policer */
205     struct
206     {
207       u32 pad[8 - VLIB_N_RX_TX - 1];    /* to end of opaque */
208       u32 index;
209     } policer;
210
211     /* interface output features */
212     struct
213     {
214       u32 flags;
215       u32 sad_index;
216     } ipsec;
217
218     /* MAP */
219     struct
220     {
221       u16 mtu;
222     } map;
223
224     /* MAP-T */
225     struct
226     {
227       u32 map_domain_index;
228       struct
229       {
230         u32 saddr, daddr;
231         u16 frag_offset;        //Fragmentation header offset
232         u16 l4_offset;          //L4 header overall offset
233         u8 l4_protocol;         //The final protocol number
234       } v6;                     //Used by ip6_map_t only
235       u16 checksum_offset;      //L4 checksum overall offset
236       u16 mtu;                  //Exit MTU
237     } map_t;
238
239     /* IP Fragmentation */
240     struct
241     {
242       u16 header_offset;
243       u16 mtu;
244       u8 next_index;
245       u8 flags;                 //See ip_frag.h
246     } ip_frag;
247
248     /* COP - configurable junk filter(s) */
249     struct
250     {
251       /* Current configuration index. */
252       u32 current_config_index;
253     } cop;
254
255     /* LISP */
256     struct
257     {
258       /* overlay address family */
259       u16 overlay_afi;
260     } lisp;
261
262     /* Driver rx feature */
263     struct
264     {
265       u32 saved_next_index;             /**< saved by drivers for short-cut */
266       u16 buffer_advance;
267     } device_input_feat;
268
269     /* TCP */
270     struct
271     {
272       u32 connection_index;
273       u32 seq_number;
274       u32 seq_end;
275       u32 ack_number;
276       u16 hdr_offset;           /**< offset relative to ip hdr */
277       u16 data_offset;          /**< offset relative to ip hdr */
278       u16 data_len;             /**< data len */
279       u8 flags;
280     } tcp;
281
282     u32 unused[6];
283   };
284 } vnet_buffer_opaque_t;
285
286 /*
287  * The opaque field of the vlib_buffer_t is intepreted as a
288  * vnet_buffer_opaque_t. Hence it should be big enough to accommodate one.
289  */
290 STATIC_ASSERT (sizeof (vnet_buffer_opaque_t) <=
291                STRUCT_SIZE_OF (vlib_buffer_t, opaque),
292                "VNET buffer meta-data too large for vlib_buffer");
293
294 #define vnet_buffer(b) ((vnet_buffer_opaque_t *) (b)->opaque)
295
296 /* Full cache line (64 bytes) of additional space */
297 typedef struct
298 {
299   union
300   {
301   };
302 } vnet_buffer_opaque2_t;
303
304
305
306 #endif /* included_vnet_buffer_h */
307
308 /*
309  * fd.io coding-style-patch-verification: ON
310  *
311  * Local Variables:
312  * eval: (c-set-style "gnu")
313  * End:
314  */