#include <vnet/vnet.h>
#include <vppinfra/vec.h>
#include <vppinfra/format.h>
-#include <vlib/unix/cj.h>
#include <assert.h>
#include <vnet/ip/ip.h>
#include <dpdk/device/dpdk_priv.h>
#include <vppinfra/error.h>
+/* check if flow is L2 flow */
+#define FLOW_IS_L2_LAYER(f) \
+ (f->type == VNET_FLOW_TYPE_ETHERNET)
+
+/* check if flow is VLAN sensitive */
+#define FLOW_IS_VLAN_TAGGED(f) \
+ ((f->type == VNET_FLOW_TYPE_IP4_N_TUPLE_TAGGED) || \
+ (f->type == VNET_FLOW_TYPE_IP6_N_TUPLE_TAGGED))
+
+/* check if flow is L4 type */
+#define FLOW_IS_L4_LAYER(f) \
+ ((f->type == VNET_FLOW_TYPE_IP4_N_TUPLE) || \
+ (f->type == VNET_FLOW_TYPE_IP6_N_TUPLE))
+
+/* check if flow is L4 tunnel type */
+#define FLOW_IS_L4_TUNNEL_LAYER(f) \
+ ((f->type >= VNET_FLOW_TYPE_IP4_VXLAN) || \
+ (f->type <= VNET_FLOW_TYPE_IP6_GTPU_IP6))
+
/* constant structs */
static const struct rte_flow_attr ingress = {.ingress = 1 };
+static inline bool
+mac_address_is_all_zero (const u8 addr[6])
+{
+ int i = 0;
+
+ for (i = 0; i < 6; i++)
+ if (addr[i] != 0)
+ return false;
+
+ return true;
+}
+
+static inline void
+dpdk_flow_convert_rss_types (u64 type, u64 * dpdk_rss_type)
+{
+#define BIT_IS_SET(v, b) \
+ ((v) & (u64)1<<(b))
+
+ *dpdk_rss_type = 0;
+
+#undef _
+#define _(n, f, s) \
+ if (n != -1 && BIT_IS_SET(type, n)) \
+ *dpdk_rss_type |= f;
+
+ foreach_dpdk_rss_hf
+#undef _
+ return;
+}
+
static int
dpdk_flow_add (dpdk_device_t * xd, vnet_flow_t * f, dpdk_flow_entry_t * fe)
{
+ struct rte_flow_item_eth eth[2] = { };
struct rte_flow_item_ipv4 ip4[2] = { };
struct rte_flow_item_ipv4 inner_ip4[2] = { };
struct rte_flow_item_ipv6 ip6[2] = { };
struct rte_flow_item_gtp gtp[2] = { };
struct rte_flow_action_mark mark = { 0 };
struct rte_flow_action_queue queue = { 0 };
+ struct rte_flow_action_rss rss = { 0 };
struct rte_flow_item *item, *items = 0;
struct rte_flow_action *action, *actions = 0;
bool fate = false;
/* Ethernet */
vec_add2 (items, item, 1);
item->type = RTE_FLOW_ITEM_TYPE_ETH;
- item->spec = NULL;
- item->mask = NULL;
+ if (f->type == VNET_FLOW_TYPE_ETHERNET)
+ {
+ vnet_flow_ethernet_t *te = &f->ethernet;
+
+ clib_memset (ð[0], 0, sizeof (eth[0]));
+ clib_memset (ð[1], 0, sizeof (eth[1]));
+
+ /* check if SMAC/DMAC/Ether_type assigned */
+ if (!mac_address_is_all_zero (te->eth_hdr.dst_address))
+ {
+ clib_memcpy_fast (ð[0].dst, &te->eth_hdr.dst_address,
+ sizeof (eth[0].dst));
+ clib_memset (ð[1].dst, 0xFF, sizeof (eth[1].dst));
+ }
+
+ if (!mac_address_is_all_zero (te->eth_hdr.src_address))
+ {
+ clib_memcpy_fast (ð[0].src, &te->eth_hdr.src_address,
+ sizeof (eth[0].src));
+ clib_memset (ð[1].src, 0xFF, sizeof (eth[1].src));
+ }
+
+ if (te->eth_hdr.type)
+ {
+ eth[0].type = clib_host_to_net_u16 (te->eth_hdr.type);
+ eth[1].type = clib_host_to_net_u16 (0xFFFF);
+ }
- /* VLAN */
- if ((f->type == VNET_FLOW_TYPE_IP4_N_TUPLE) ||
- (f->type == VNET_FLOW_TYPE_IP6_N_TUPLE))
+ item->spec = eth;
+ item->mask = eth + 1;
+ }
+ else
+ {
+ item->spec = NULL;
+ item->mask = NULL;
+ }
+
+ if (FLOW_IS_VLAN_TAGGED (f))
{
vec_add2 (items, item, 1);
item->type = RTE_FLOW_ITEM_TYPE_VLAN;
item->mask = NULL;
}
+ if (FLOW_IS_L2_LAYER (f))
+ goto pattern_end;
+
/* IP */
vec_add2 (items, item, 1);
if ((f->type == VNET_FLOW_TYPE_IP6_N_TUPLE) ||
item->spec = NULL;
item->mask = NULL;
}
-
- tcp[0].hdr.src_port = clib_host_to_net_u16 (src_port);
- tcp[1].hdr.src_port = clib_host_to_net_u16 (src_port_mask);
- tcp[0].hdr.dst_port = clib_host_to_net_u16 (dst_port);
- tcp[1].hdr.dst_port = clib_host_to_net_u16 (dst_port_mask);
- item->spec = tcp;
- item->mask = tcp + 1;
+ else
+ {
+ tcp[0].hdr.src_port = clib_host_to_net_u16 (src_port);
+ tcp[1].hdr.src_port = clib_host_to_net_u16 (src_port_mask);
+ tcp[0].hdr.dst_port = clib_host_to_net_u16 (dst_port);
+ tcp[1].hdr.dst_port = clib_host_to_net_u16 (dst_port_mask);
+ item->spec = tcp;
+ item->mask = tcp + 1;
+ }
}
else
{
}
}
+pattern_end:
vec_add2 (items, item, 1);
item->type = RTE_FLOW_ITEM_TYPE_END;
{
vec_add2 (actions, action, 1);
action->type = RTE_FLOW_ACTION_TYPE_DROP;
+ if (fate == true)
+ {
+ rv = VNET_FLOW_ERROR_INTERNAL;
+ goto done;
+ }
+ else
+ fate = true;
+ }
+ if (f->actions & VNET_FLOW_ACTION_RSS)
+ {
+ u64 rss_type = 0;
+ vec_add2 (actions, action, 1);
+ action->type = RTE_FLOW_ACTION_TYPE_RSS;
+ action->conf = &rss;
+
+ /* convert types to DPDK rss bitmask */
+ dpdk_flow_convert_rss_types (f->rss_types, &rss_type);
+
+ rss.types = rss_type;
+ rss.func = (enum rte_eth_hash_function) f->rss_fun;
+
if (fate == true)
{
rv = VNET_FLOW_ERROR_INTERNAL;
vec_foreach (fl_index, xd->parked_lookup_indexes)
pool_put_index (xd->flow_lookup_entries, *fl_index);
- vec_reset_length (xd->flow_lookup_entries);
+ vec_reset_length (xd->parked_lookup_indexes);
}
if (op == VNET_FLOW_DEV_OP_DEL_FLOW)
switch (flow->type)
{
+ case VNET_FLOW_TYPE_ETHERNET:
case VNET_FLOW_TYPE_IP4_N_TUPLE:
case VNET_FLOW_TYPE_IP6_N_TUPLE:
case VNET_FLOW_TYPE_IP4_VXLAN: