c20da251884f323204dbeb17470118bf8f151e0e
[vpp.git] / src / plugins / dpdk / device / flow.c
1 /*
2  * Copyright (c) 2019 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 #include <vnet/vnet.h>
17 #include <vppinfra/vec.h>
18 #include <vppinfra/format.h>
19 #include <vlib/unix/cj.h>
20 #include <assert.h>
21
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/ethernet/arp_packet.h>
25 #include <vnet/vxlan/vxlan.h>
26 #include <dpdk/device/dpdk.h>
27
28 #include <dpdk/device/dpdk_priv.h>
29 #include <vppinfra/error.h>
30
31 /* constant structs */
32 static const struct rte_flow_attr ingress = {.ingress = 1 };
33
34 static int
35 dpdk_flow_add (dpdk_device_t * xd, vnet_flow_t * f, dpdk_flow_entry_t * fe)
36 {
37   struct rte_flow_item_ipv4 ip4[2] = { };
38   struct rte_flow_item_ipv4 inner_ip4[2] = { };
39   struct rte_flow_item_ipv6 ip6[2] = { };
40   struct rte_flow_item_ipv6 inner_ip6[2] = { };
41   struct rte_flow_item_udp udp[2] = { };
42   struct rte_flow_item_tcp tcp[2] = { };
43   struct rte_flow_item_gtp gtp[2] = { };
44   struct rte_flow_action_mark mark = { 0 };
45   struct rte_flow_action_queue queue = { 0 };
46   struct rte_flow_item *item, *items = 0;
47   struct rte_flow_action *action, *actions = 0;
48   bool fate = false;
49
50   enum
51   {
52     vxlan_hdr_sz = sizeof (vxlan_header_t),
53     raw_sz = sizeof (struct rte_flow_item_raw)
54   };
55
56   union
57   {
58     struct rte_flow_item_raw item;
59     u8 val[raw_sz + vxlan_hdr_sz];
60   } raw[2];
61
62   u16 src_port, dst_port, src_port_mask, dst_port_mask;
63   u8 protocol;
64   int rv = 0;
65
66   if (f->actions & (~xd->supported_flow_actions))
67     return VNET_FLOW_ERROR_NOT_SUPPORTED;
68
69   /* Match items */
70   /* Ethernet */
71   vec_add2 (items, item, 1);
72   item->type = RTE_FLOW_ITEM_TYPE_ETH;
73   item->spec = NULL;
74   item->mask = NULL;
75
76   /* VLAN */
77   if ((f->type == VNET_FLOW_TYPE_IP4_N_TUPLE) ||
78       (f->type == VNET_FLOW_TYPE_IP6_N_TUPLE))
79     {
80       vec_add2 (items, item, 1);
81       item->type = RTE_FLOW_ITEM_TYPE_VLAN;
82       item->spec = NULL;
83       item->mask = NULL;
84     }
85
86   /* IP */
87   vec_add2 (items, item, 1);
88   if ((f->type == VNET_FLOW_TYPE_IP6_N_TUPLE) ||
89       (f->type == VNET_FLOW_TYPE_IP6_GTPC) ||
90       (f->type == VNET_FLOW_TYPE_IP6_GTPU) ||
91       (f->type == VNET_FLOW_TYPE_IP6_GTPU_IP4) ||
92       (f->type == VNET_FLOW_TYPE_IP6_GTPU_IP6))
93     {
94       vnet_flow_ip6_n_tuple_t *t6 = &f->ip6_n_tuple;
95       item->type = RTE_FLOW_ITEM_TYPE_IPV6;
96
97       if (!clib_memcmp (&t6->src_addr.mask, &zero_addr, 16) &&
98           !clib_memcmp (&t6->dst_addr.mask, &zero_addr, 16))
99         {
100           item->spec = NULL;
101           item->mask = NULL;
102         }
103       else
104         {
105           clib_memcpy_fast (ip6[0].hdr.src_addr, &t6->src_addr.addr, 16);
106           clib_memcpy_fast (ip6[1].hdr.src_addr, &t6->src_addr.mask, 16);
107           clib_memcpy_fast (ip6[0].hdr.dst_addr, &t6->dst_addr.addr, 16);
108           clib_memcpy_fast (ip6[1].hdr.dst_addr, &t6->dst_addr.mask, 16);
109           item->spec = ip6;
110           item->mask = ip6 + 1;
111         }
112
113       src_port = t6->src_port.port;
114       dst_port = t6->dst_port.port;
115       src_port_mask = t6->src_port.mask;
116       dst_port_mask = t6->dst_port.mask;
117       protocol = t6->protocol;
118     }
119   else if ((f->type == VNET_FLOW_TYPE_IP4_N_TUPLE) ||
120            (f->type == VNET_FLOW_TYPE_IP4_GTPC) ||
121            (f->type == VNET_FLOW_TYPE_IP4_GTPU) ||
122            (f->type == VNET_FLOW_TYPE_IP4_GTPU_IP4) ||
123            (f->type == VNET_FLOW_TYPE_IP4_GTPU_IP6))
124     {
125       vnet_flow_ip4_n_tuple_t *t4 = &f->ip4_n_tuple;
126       item->type = RTE_FLOW_ITEM_TYPE_IPV4;
127
128       if (!t4->src_addr.mask.as_u32 && !t4->dst_addr.mask.as_u32)
129         {
130           item->spec = NULL;
131           item->mask = NULL;
132         }
133       else
134         {
135           ip4[0].hdr.src_addr = t4->src_addr.addr.as_u32;
136           ip4[1].hdr.src_addr = t4->src_addr.mask.as_u32;
137           ip4[0].hdr.dst_addr = t4->dst_addr.addr.as_u32;
138           ip4[1].hdr.dst_addr = t4->dst_addr.mask.as_u32;
139           item->spec = ip4;
140           item->mask = ip4 + 1;
141         }
142
143       src_port = t4->src_port.port;
144       dst_port = t4->dst_port.port;
145       src_port_mask = t4->src_port.mask;
146       dst_port_mask = t4->dst_port.mask;
147       protocol = t4->protocol;
148     }
149   else if (f->type == VNET_FLOW_TYPE_IP4_VXLAN)
150     {
151       vnet_flow_ip4_vxlan_t *v4 = &f->ip4_vxlan;
152       ip4[0].hdr.src_addr = v4->src_addr.as_u32;
153       ip4[1].hdr.src_addr = -1;
154       ip4[0].hdr.dst_addr = v4->dst_addr.as_u32;
155       ip4[1].hdr.dst_addr = -1;
156       item->type = RTE_FLOW_ITEM_TYPE_IPV4;
157       item->spec = ip4;
158       item->mask = ip4 + 1;
159
160       dst_port = v4->dst_port;
161       dst_port_mask = -1;
162       src_port = 0;
163       src_port_mask = 0;
164       protocol = IP_PROTOCOL_UDP;
165     }
166   else
167     {
168       rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
169       goto done;
170     }
171
172   /* Layer 4 */
173   vec_add2 (items, item, 1);
174   if (protocol == IP_PROTOCOL_UDP)
175     {
176       item->type = RTE_FLOW_ITEM_TYPE_UDP;
177
178       if ((src_port_mask == 0) && (dst_port_mask == 0))
179         {
180           item->spec = NULL;
181           item->mask = NULL;
182         }
183       else
184         {
185           udp[0].hdr.src_port = clib_host_to_net_u16 (src_port);
186           udp[1].hdr.src_port = clib_host_to_net_u16 (src_port_mask);
187           udp[0].hdr.dst_port = clib_host_to_net_u16 (dst_port);
188           udp[1].hdr.dst_port = clib_host_to_net_u16 (dst_port_mask);
189           item->spec = udp;
190           item->mask = udp + 1;
191         }
192     }
193   else if (protocol == IP_PROTOCOL_TCP)
194     {
195       item->type = RTE_FLOW_ITEM_TYPE_TCP;
196
197       if ((src_port_mask == 0) && (dst_port_mask == 0))
198         {
199           item->spec = NULL;
200           item->mask = NULL;
201         }
202
203       tcp[0].hdr.src_port = clib_host_to_net_u16 (src_port);
204       tcp[1].hdr.src_port = clib_host_to_net_u16 (src_port_mask);
205       tcp[0].hdr.dst_port = clib_host_to_net_u16 (dst_port);
206       tcp[1].hdr.dst_port = clib_host_to_net_u16 (dst_port_mask);
207       item->spec = tcp;
208       item->mask = tcp + 1;
209     }
210   else
211     {
212       rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
213       goto done;
214     }
215
216   /* Tunnel header match */
217   if (f->type == VNET_FLOW_TYPE_IP4_VXLAN)
218     {
219       u32 vni = f->ip4_vxlan.vni;
220       vxlan_header_t spec_hdr = {
221         .flags = VXLAN_FLAGS_I,
222         .vni_reserved = clib_host_to_net_u32 (vni << 8)
223       };
224       vxlan_header_t mask_hdr = {
225         .flags = 0xff,
226         .vni_reserved = clib_host_to_net_u32 (((u32) - 1) << 8)
227       };
228
229       clib_memset (raw, 0, sizeof raw);
230       raw[0].item.relative = 1;
231       raw[0].item.length = vxlan_hdr_sz;
232
233       clib_memcpy_fast (raw[0].val + raw_sz, &spec_hdr, vxlan_hdr_sz);
234       raw[0].item.pattern = raw[0].val + raw_sz;
235       clib_memcpy_fast (raw[1].val + raw_sz, &mask_hdr, vxlan_hdr_sz);
236       raw[1].item.pattern = raw[1].val + raw_sz;
237
238       vec_add2 (items, item, 1);
239       item->type = RTE_FLOW_ITEM_TYPE_RAW;
240       item->spec = raw;
241       item->mask = raw + 1;
242     }
243   else if (f->type == VNET_FLOW_TYPE_IP4_GTPC)
244     {
245       vnet_flow_ip4_gtpc_t *gc = &f->ip4_gtpc;
246       gtp[0].teid = clib_host_to_net_u32 (gc->teid);
247       gtp[1].teid = ~0;
248
249       vec_add2 (items, item, 1);
250       item->type = RTE_FLOW_ITEM_TYPE_GTPC;
251       item->spec = gtp;
252       item->mask = gtp + 1;
253     }
254   else if (f->type == VNET_FLOW_TYPE_IP4_GTPU)
255     {
256       vnet_flow_ip4_gtpu_t *gu = &f->ip4_gtpu;
257       gtp[0].teid = clib_host_to_net_u32 (gu->teid);
258       gtp[1].teid = ~0;
259
260       vec_add2 (items, item, 1);
261       item->type = RTE_FLOW_ITEM_TYPE_GTPU;
262       item->spec = gtp;
263       item->mask = gtp + 1;
264     }
265   else if ((f->type == VNET_FLOW_TYPE_IP4_GTPU_IP4) ||
266            (f->type == VNET_FLOW_TYPE_IP4_GTPU_IP6))
267     {
268       vnet_flow_ip4_gtpu_t *gu = &f->ip4_gtpu;
269       gtp[0].teid = clib_host_to_net_u32 (gu->teid);
270       gtp[1].teid = ~0;
271
272       vec_add2 (items, item, 1);
273       item->type = RTE_FLOW_ITEM_TYPE_GTPU;
274       item->spec = gtp;
275       item->mask = gtp + 1;
276
277       /* inner IP4 header */
278       if (f->type == VNET_FLOW_TYPE_IP4_GTPU_IP4)
279         {
280           vec_add2 (items, item, 1);
281           item->type = RTE_FLOW_ITEM_TYPE_IPV4;
282
283           vnet_flow_ip4_gtpu_ip4_t *gu4 = &f->ip4_gtpu_ip4;
284           if (!gu4->inner_src_addr.mask.as_u32 &&
285               !gu4->inner_dst_addr.mask.as_u32)
286             {
287               item->spec = NULL;
288               item->mask = NULL;
289             }
290           else
291             {
292               inner_ip4[0].hdr.src_addr = gu4->inner_src_addr.addr.as_u32;
293               inner_ip4[1].hdr.src_addr = gu4->inner_src_addr.mask.as_u32;
294               inner_ip4[0].hdr.dst_addr = gu4->inner_dst_addr.addr.as_u32;
295               inner_ip4[1].hdr.dst_addr = gu4->inner_dst_addr.mask.as_u32;
296               item->spec = inner_ip4;
297               item->mask = inner_ip4 + 1;
298             }
299         }
300       else if (f->type == VNET_FLOW_TYPE_IP4_GTPU_IP6)
301         {
302           ip6_address_t zero_addr;
303           vnet_flow_ip4_gtpu_ip6_t *gu6 = &f->ip4_gtpu_ip6;
304
305           clib_memset (&zero_addr, 0, sizeof (ip6_address_t));
306
307           vec_add2 (items, item, 1);
308           item->type = RTE_FLOW_ITEM_TYPE_IPV6;
309
310           if (!clib_memcmp (&gu6->inner_src_addr.mask, &zero_addr, 16) &&
311               !clib_memcmp (&gu6->inner_dst_addr.mask, &zero_addr, 16))
312             {
313               item->spec = NULL;
314               item->mask = NULL;
315             }
316           else
317             {
318               clib_memcpy_fast (inner_ip6[0].hdr.src_addr,
319                                 &gu6->inner_src_addr.addr, 16);
320               clib_memcpy_fast (inner_ip6[1].hdr.src_addr,
321                                 &gu6->inner_src_addr.mask, 16);
322               clib_memcpy_fast (inner_ip6[0].hdr.dst_addr,
323                                 &gu6->inner_dst_addr.addr, 16);
324               clib_memcpy_fast (inner_ip6[1].hdr.dst_addr,
325                                 &gu6->inner_dst_addr.mask, 16);
326               item->spec = inner_ip6;
327               item->mask = inner_ip6 + 1;
328             }
329         }
330     }
331   else if (f->type == VNET_FLOW_TYPE_IP6_GTPC)
332     {
333       vnet_flow_ip6_gtpc_t *gc = &f->ip6_gtpc;
334       gtp[0].teid = clib_host_to_net_u32 (gc->teid);
335       gtp[1].teid = ~0;
336
337       vec_add2 (items, item, 1);
338       item->type = RTE_FLOW_ITEM_TYPE_GTPC;
339       item->spec = gtp;
340       item->mask = gtp + 1;
341     }
342   else if (f->type == VNET_FLOW_TYPE_IP6_GTPU)
343     {
344       vnet_flow_ip6_gtpu_t *gu = &f->ip6_gtpu;
345       gtp[0].teid = clib_host_to_net_u32 (gu->teid);
346       gtp[1].teid = ~0;
347
348       vec_add2 (items, item, 1);
349       item->type = RTE_FLOW_ITEM_TYPE_GTPU;
350       item->spec = gtp;
351       item->mask = gtp + 1;
352     }
353   else if ((f->type == VNET_FLOW_TYPE_IP6_GTPU_IP4) ||
354            (f->type == VNET_FLOW_TYPE_IP6_GTPU_IP6))
355     {
356       vnet_flow_ip6_gtpu_t *gu = &f->ip6_gtpu;
357       gtp[0].teid = clib_host_to_net_u32 (gu->teid);
358       gtp[1].teid = ~0;
359
360       vec_add2 (items, item, 1);
361       item->type = RTE_FLOW_ITEM_TYPE_GTPU;
362       item->spec = gtp;
363       item->mask = gtp + 1;
364
365       /* inner IP4 header */
366       if (f->type == VNET_FLOW_TYPE_IP6_GTPU_IP4)
367         {
368           vec_add2 (items, item, 1);
369           item->type = RTE_FLOW_ITEM_TYPE_IPV4;
370
371           vnet_flow_ip6_gtpu_ip4_t *gu4 = &f->ip6_gtpu_ip4;
372
373           if (!gu4->inner_src_addr.mask.as_u32 &&
374               !gu4->inner_dst_addr.mask.as_u32)
375             {
376               item->spec = NULL;
377               item->mask = NULL;
378             }
379           else
380             {
381               inner_ip4[0].hdr.src_addr = gu4->inner_src_addr.addr.as_u32;
382               inner_ip4[1].hdr.src_addr = gu4->inner_src_addr.mask.as_u32;
383               inner_ip4[0].hdr.dst_addr = gu4->inner_dst_addr.addr.as_u32;
384               inner_ip4[1].hdr.dst_addr = gu4->inner_dst_addr.mask.as_u32;
385               item->spec = inner_ip4;
386               item->mask = inner_ip4 + 1;
387             }
388         }
389
390       if (f->type == VNET_FLOW_TYPE_IP6_GTPU_IP6)
391         {
392           ip6_address_t zero_addr;
393           vnet_flow_ip6_gtpu_ip6_t *gu6 = &f->ip6_gtpu_ip6;
394
395           clib_memset (&zero_addr, 0, sizeof (ip6_address_t));
396
397           vec_add2 (items, item, 1);
398           item->type = RTE_FLOW_ITEM_TYPE_IPV6;
399
400           if (!clib_memcmp (&gu6->inner_src_addr.mask, &zero_addr, 16) &&
401               !clib_memcmp (&gu6->inner_dst_addr.mask, &zero_addr, 16))
402             {
403               item->spec = NULL;
404               item->mask = NULL;
405             }
406           else
407             {
408               clib_memcpy_fast (inner_ip6[0].hdr.src_addr,
409                                 &gu6->inner_src_addr.addr, 16);
410               clib_memcpy_fast (inner_ip6[1].hdr.src_addr,
411                                 &gu6->inner_src_addr.mask, 16);
412               clib_memcpy_fast (inner_ip6[0].hdr.dst_addr,
413                                 &gu6->inner_dst_addr.addr, 16);
414               clib_memcpy_fast (inner_ip6[1].hdr.dst_addr,
415                                 &gu6->inner_dst_addr.mask, 16);
416               item->spec = inner_ip6;
417               item->mask = inner_ip6 + 1;
418             }
419
420         }
421     }
422
423   vec_add2 (items, item, 1);
424   item->type = RTE_FLOW_ITEM_TYPE_END;
425
426   /* Actions */
427   /* Only one 'fate' can be assigned */
428   if (f->actions & VNET_FLOW_ACTION_REDIRECT_TO_QUEUE)
429     {
430       vec_add2 (actions, action, 1);
431       queue.index = f->redirect_queue;
432       action->type = RTE_FLOW_ACTION_TYPE_QUEUE;
433       action->conf = &queue;
434       fate = true;
435     }
436   if (f->actions & VNET_FLOW_ACTION_DROP)
437     {
438       vec_add2 (actions, action, 1);
439       action->type = RTE_FLOW_ACTION_TYPE_DROP;
440       if (fate == true)
441         {
442           rv = VNET_FLOW_ERROR_INTERNAL;
443           goto done;
444         }
445       else
446         fate = true;
447     }
448   if (fate == false)
449     {
450       vec_add2 (actions, action, 1);
451       action->type = RTE_FLOW_ACTION_TYPE_PASSTHRU;
452     }
453
454   if (f->actions & VNET_FLOW_ACTION_MARK)
455     {
456       vec_add2 (actions, action, 1);
457       mark.id = fe->mark;
458       action->type = RTE_FLOW_ACTION_TYPE_MARK;
459       action->conf = &mark;
460     }
461
462   vec_add2 (actions, action, 1);
463   action->type = RTE_FLOW_ACTION_TYPE_END;
464
465   rv = rte_flow_validate (xd->device_index, &ingress, items, actions,
466                           &xd->last_flow_error);
467
468   if (rv)
469     {
470       if (rv == -EINVAL)
471         rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
472       else if (rv == -EEXIST)
473         rv = VNET_FLOW_ERROR_ALREADY_EXISTS;
474       else
475         rv = VNET_FLOW_ERROR_INTERNAL;
476       goto done;
477     }
478
479   fe->handle = rte_flow_create (xd->device_index, &ingress, items, actions,
480                                 &xd->last_flow_error);
481
482   if (!fe->handle)
483     rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
484
485 done:
486   vec_free (items);
487   vec_free (actions);
488   return rv;
489 }
490
491 int
492 dpdk_flow_ops_fn (vnet_main_t * vnm, vnet_flow_dev_op_t op, u32 dev_instance,
493                   u32 flow_index, uword * private_data)
494 {
495   dpdk_main_t *dm = &dpdk_main;
496   vnet_flow_t *flow = vnet_get_flow (flow_index);
497   dpdk_device_t *xd = vec_elt_at_index (dm->devices, dev_instance);
498   dpdk_flow_entry_t *fe;
499   dpdk_flow_lookup_entry_t *fle = 0;
500   int rv;
501
502   /* recycle old flow lookup entries only after the main loop counter
503      increases - i.e. previously DMA'ed packets were handled */
504   if (vec_len (xd->parked_lookup_indexes) > 0 &&
505       xd->parked_loop_count != dm->vlib_main->main_loop_count)
506     {
507       u32 *fl_index;
508
509       vec_foreach (fl_index, xd->parked_lookup_indexes)
510         pool_put_index (xd->flow_lookup_entries, *fl_index);
511       vec_reset_length (xd->flow_lookup_entries);
512     }
513
514   if (op == VNET_FLOW_DEV_OP_DEL_FLOW)
515     {
516       fe = vec_elt_at_index (xd->flow_entries, *private_data);
517
518       if ((rv = rte_flow_destroy (xd->device_index, fe->handle,
519                                   &xd->last_flow_error)))
520         return VNET_FLOW_ERROR_INTERNAL;
521
522       if (fe->mark)
523         {
524           /* make sure no action is taken for in-flight (marked) packets */
525           fle = pool_elt_at_index (xd->flow_lookup_entries, fe->mark);
526           clib_memset (fle, -1, sizeof (*fle));
527           vec_add1 (xd->parked_lookup_indexes, fe->mark);
528           xd->parked_loop_count = dm->vlib_main->main_loop_count;
529         }
530
531       clib_memset (fe, 0, sizeof (*fe));
532       pool_put (xd->flow_entries, fe);
533
534       goto disable_rx_offload;
535     }
536
537   if (op != VNET_FLOW_DEV_OP_ADD_FLOW)
538     return VNET_FLOW_ERROR_NOT_SUPPORTED;
539
540   pool_get (xd->flow_entries, fe);
541   fe->flow_index = flow->index;
542
543   if (flow->actions == 0)
544     {
545       rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
546       goto done;
547     }
548
549   /* if we need to mark packets, assign one mark */
550   if (flow->actions & (VNET_FLOW_ACTION_MARK |
551                        VNET_FLOW_ACTION_REDIRECT_TO_NODE |
552                        VNET_FLOW_ACTION_BUFFER_ADVANCE))
553     {
554       /* reserve slot 0 */
555       if (xd->flow_lookup_entries == 0)
556         pool_get_aligned (xd->flow_lookup_entries, fle,
557                           CLIB_CACHE_LINE_BYTES);
558       pool_get_aligned (xd->flow_lookup_entries, fle, CLIB_CACHE_LINE_BYTES);
559       fe->mark = fle - xd->flow_lookup_entries;
560
561       /* install entry in the lookup table */
562       clib_memset (fle, -1, sizeof (*fle));
563       if (flow->actions & VNET_FLOW_ACTION_MARK)
564         fle->flow_id = flow->mark_flow_id;
565       if (flow->actions & VNET_FLOW_ACTION_REDIRECT_TO_NODE)
566         fle->next_index = flow->redirect_device_input_next_index;
567       if (flow->actions & VNET_FLOW_ACTION_BUFFER_ADVANCE)
568         fle->buffer_advance = flow->buffer_advance;
569     }
570   else
571     fe->mark = 0;
572
573   if ((xd->flags & DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD) == 0)
574     {
575       xd->flags |= DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD;
576       dpdk_device_setup (xd);
577     }
578
579   switch (flow->type)
580     {
581     case VNET_FLOW_TYPE_IP4_N_TUPLE:
582     case VNET_FLOW_TYPE_IP6_N_TUPLE:
583     case VNET_FLOW_TYPE_IP4_VXLAN:
584     case VNET_FLOW_TYPE_IP4_GTPC:
585     case VNET_FLOW_TYPE_IP4_GTPU:
586     case VNET_FLOW_TYPE_IP4_GTPU_IP4:
587     case VNET_FLOW_TYPE_IP4_GTPU_IP6:
588     case VNET_FLOW_TYPE_IP6_GTPC:
589     case VNET_FLOW_TYPE_IP6_GTPU:
590     case VNET_FLOW_TYPE_IP6_GTPU_IP4:
591     case VNET_FLOW_TYPE_IP6_GTPU_IP6:
592       if ((rv = dpdk_flow_add (xd, flow, fe)))
593         goto done;
594       break;
595     default:
596       rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
597       goto done;
598     }
599
600   *private_data = fe - xd->flow_entries;
601
602 done:
603   if (rv)
604     {
605       clib_memset (fe, 0, sizeof (*fe));
606       pool_put (xd->flow_entries, fe);
607       if (fle)
608         {
609           clib_memset (fle, -1, sizeof (*fle));
610           pool_put (xd->flow_lookup_entries, fle);
611         }
612     }
613 disable_rx_offload:
614   if ((xd->flags & DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD) != 0
615       && pool_elts (xd->flow_entries) == 0)
616     {
617       xd->flags &= ~DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD;
618       dpdk_device_setup (xd);
619     }
620
621   return rv;
622 }
623
624 u8 *
625 format_dpdk_flow (u8 * s, va_list * args)
626 {
627   u32 dev_instance = va_arg (*args, u32);
628   u32 flow_index = va_arg (*args, u32);
629   uword private_data = va_arg (*args, uword);
630   dpdk_main_t *dm = &dpdk_main;
631   dpdk_device_t *xd = vec_elt_at_index (dm->devices, dev_instance);
632   dpdk_flow_entry_t *fe;
633
634   if (flow_index == ~0)
635     {
636       s = format (s, "%-25s: %U\n", "supported flow actions",
637                   format_flow_actions, xd->supported_flow_actions);
638       s = format (s, "%-25s: %d\n", "last DPDK error type",
639                   xd->last_flow_error.type);
640       s = format (s, "%-25s: %s\n", "last DPDK error message",
641                   xd->last_flow_error.message ? xd->last_flow_error.message :
642                   "n/a");
643       return s;
644     }
645
646   if (private_data >= vec_len (xd->flow_entries))
647     return format (s, "unknown flow");
648
649   fe = vec_elt_at_index (xd->flow_entries, private_data);
650   s = format (s, "mark %u", fe->mark);
651   return s;
652 }
653
654 /*
655  * fd.io coding-style-patch-verification: ON
656  *
657  * Local Variables:
658  * eval: (c-set-style "gnu")
659  * End:
660  */