ethdev: introduce conntrack flow action and item
[dpdk.git] / lib / ethdev / rte_flow.h
index 203c4cd..c16f5ba 100644 (file)
@@ -30,6 +30,7 @@
 #include <rte_esp.h>
 #include <rte_higig.h>
 #include <rte_ecpri.h>
+#include <rte_bitops.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 
@@ -551,6 +552,26 @@ enum rte_flow_item_type {
         * See struct rte_flow_item_geneve_opt
         */
        RTE_FLOW_ITEM_TYPE_GENEVE_OPT,
+
+       /**
+        * [META]
+        *
+        * Matches on packet integrity.
+        * For some devices application needs to enable integration checks in HW
+        * before using this item.
+        *
+        * @see struct rte_flow_item_integrity.
+        */
+       RTE_FLOW_ITEM_TYPE_INTEGRITY,
+
+       /**
+        * [META]
+        *
+        * Matches conntrack state.
+        *
+        * @see struct rte_flow_item_conntrack.
+        */
+       RTE_FLOW_ITEM_TYPE_CONNTRACK,
 };
 
 /**
@@ -1685,6 +1706,90 @@ rte_flow_item_geneve_opt_mask = {
 };
 #endif
 
+struct rte_flow_item_integrity {
+       /**< Tunnel encapsulation level the item should apply to.
+        * @see rte_flow_action_rss
+        */
+       uint32_t level;
+       RTE_STD_C11
+       union {
+               __extension__
+               struct {
+                       /**< The packet is valid after passing all HW checks. */
+                       uint64_t packet_ok:1;
+                       /**< L2 layer is valid after passing all HW checks. */
+                       uint64_t l2_ok:1;
+                       /**< L3 layer is valid after passing all HW checks. */
+                       uint64_t l3_ok:1;
+                       /**< L4 layer is valid after passing all HW checks. */
+                       uint64_t l4_ok:1;
+                       /**< L2 layer CRC is valid. */
+                       uint64_t l2_crc_ok:1;
+                       /**< IPv4 layer checksum is valid. */
+                       uint64_t ipv4_csum_ok:1;
+                       /**< L4 layer checksum is valid. */
+                       uint64_t l4_csum_ok:1;
+                       /**< The l3 length is smaller than the frame length. */
+                       uint64_t l3_len_ok:1;
+                       uint64_t reserved:56;
+               };
+               uint64_t value;
+       };
+};
+
+#ifndef __cplusplus
+static const struct rte_flow_item_integrity
+rte_flow_item_integrity_mask = {
+       .level = 0,
+       .value = 0,
+};
+#endif
+
+/**
+ * The packet is valid after conntrack checking.
+ */
+#define RTE_FLOW_CONNTRACK_PKT_STATE_VALID RTE_BIT32(0)
+/**
+ * The state of the connection is changed.
+ */
+#define RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED RTE_BIT32(1)
+/**
+ * Error is detected on this packet for this connection and
+ * an invalid state is set.
+ */
+#define RTE_FLOW_CONNTRACK_PKT_STATE_INVALID RTE_BIT32(2)
+/**
+ * The HW connection tracking module is disabled.
+ * It can be due to application command or an invalid state.
+ */
+#define RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED RTE_BIT32(3)
+/**
+ * The packet contains some bad field(s) and cannot continue
+ * with the conntrack module checking.
+ */
+#define RTE_FLOW_CONNTRACK_PKT_STATE_BAD RTE_BIT32(4)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ITEM_TYPE_CONNTRACK
+ *
+ * Matches the state of a packet after it passed the connection tracking
+ * examination. The state is a bitmap of one RTE_FLOW_CONNTRACK_PKT_STATE*
+ * or a reasonable combination of these bits.
+ */
+struct rte_flow_item_conntrack {
+       uint32_t flags;
+};
+
+/** Default mask for RTE_FLOW_ITEM_TYPE_CONNTRACK. */
+#ifndef __cplusplus
+static const struct rte_flow_item_conntrack rte_flow_item_conntrack_mask = {
+       .flags = 0xffffffff,
+};
+#endif
+
 /**
  * Matching pattern item definition.
  *
@@ -1821,7 +1926,7 @@ enum rte_flow_action_type {
         * Enables counters for this flow rule.
         *
         * These counters can be retrieved and reset through rte_flow_query() or
-        * rte_flow_shared_action_query() if the action provided via handle,
+        * rte_flow_action_handle_query() if the action provided via handle,
         * see struct rte_flow_query_count.
         *
         * See struct rte_flow_action_count.
@@ -2250,6 +2355,9 @@ enum rte_flow_action_type {
        RTE_FLOW_ACTION_TYPE_SAMPLE,
 
        /**
+        * @deprecated
+        * @see RTE_FLOW_ACTION_TYPE_INDIRECT
+        *
         * Describe action shared across multiple flow rules.
         *
         * Allow multiple rules reference the same action by handle (see
@@ -2267,6 +2375,23 @@ enum rte_flow_action_type {
         * See struct rte_flow_action_modify_field.
         */
        RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
+
+       /**
+        * An action handle is referenced in a rule through an indirect action.
+        *
+        * The same action handle may be used in multiple rules for the same
+        * or different ethdev ports.
+        */
+       RTE_FLOW_ACTION_TYPE_INDIRECT,
+
+       /**
+        * [META]
+        *
+        * Enable tracking a TCP connection state.
+        *
+        * @see struct rte_flow_action_conntrack.
+        */
+       RTE_FLOW_ACTION_TYPE_CONNTRACK,
 };
 
 /**
@@ -2357,7 +2482,7 @@ struct rte_flow_query_age {
  * ``struct rte_flow_query_count``.
  *
  * @deprecated Shared attribute is deprecated, use generic
- * RTE_FLOW_ACTION_TYPE_SHARED action.
+ * RTE_FLOW_ACTION_TYPE_INDIRECT action.
  *
  * The shared flag indicates whether the counter is unique to the flow rule the
  * action is specified with, or whether it is a shared counter.
@@ -2847,17 +2972,171 @@ struct rte_flow_action_set_dscp {
 };
 
 /**
- * RTE_FLOW_ACTION_TYPE_SHARED
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_INDIRECT
+ *
+ * Opaque type returned after successfully creating an indirect action object.
+ * The definition of the object handle is different per driver or
+ * per direct action type.
+ *
+ * This handle can be used to manage and query the related direct action:
+ * - referenced in single flow rule or across multiple flow rules
+ *   over multiple ports
+ * - update action object configuration
+ * - query action object data
+ * - destroy action object
+ */
+struct rte_flow_action_handle;
+
+/**
+ * The state of a TCP connection.
+ */
+enum rte_flow_conntrack_state {
+       /** SYN-ACK packet was seen. */
+       RTE_FLOW_CONNTRACK_STATE_SYN_RECV,
+       /** 3-way handshake was done. */
+       RTE_FLOW_CONNTRACK_STATE_ESTABLISHED,
+       /** First FIN packet was received to close the connection. */
+       RTE_FLOW_CONNTRACK_STATE_FIN_WAIT,
+       /** First FIN was ACKed. */
+       RTE_FLOW_CONNTRACK_STATE_CLOSE_WAIT,
+       /** Second FIN was received, waiting for the last ACK. */
+       RTE_FLOW_CONNTRACK_STATE_LAST_ACK,
+       /** Second FIN was ACKed, connection was closed. */
+       RTE_FLOW_CONNTRACK_STATE_TIME_WAIT,
+};
+
+/**
+ * The last passed TCP packet flags of a connection.
+ */
+enum rte_flow_conntrack_tcp_last_index {
+       RTE_FLOW_CONNTRACK_FLAG_NONE = 0, /**< No Flag. */
+       RTE_FLOW_CONNTRACK_FLAG_SYN = RTE_BIT32(0), /**< With SYN flag. */
+       RTE_FLOW_CONNTRACK_FLAG_SYNACK = RTE_BIT32(1), /**< With SYNACK flag. */
+       RTE_FLOW_CONNTRACK_FLAG_FIN = RTE_BIT32(2), /**< With FIN flag. */
+       RTE_FLOW_CONNTRACK_FLAG_ACK = RTE_BIT32(3), /**< With ACK flag. */
+       RTE_FLOW_CONNTRACK_FLAG_RST = RTE_BIT32(4), /**< With RST flag. */
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * Configuration parameters for each direction of a TCP connection.
+ * All fields should be in host byte order.
+ * If needed, driver should convert all fields to network byte order
+ * if HW needs them in that way.
+ */
+struct rte_flow_tcp_dir_param {
+       /** TCP window scaling factor, 0xF to disable. */
+       uint32_t scale:4;
+       /** The FIN was sent by this direction. */
+       uint32_t close_initiated:1;
+       /** An ACK packet has been received by this side. */
+       uint32_t last_ack_seen:1;
+       /**
+        * If set, it indicates that there is unacknowledged data for the
+        * packets sent from this direction.
+        */
+       uint32_t data_unacked:1;
+       /**
+        * Maximal value of sequence + payload length in sent
+        * packets (next ACK from the opposite direction).
+        */
+       uint32_t sent_end;
+       /**
+        * Maximal value of (ACK + window size) in received packet + length
+        * over sent packet (maximal sequence could be sent).
+        */
+       uint32_t reply_end;
+       /** Maximal value of actual window size in sent packets. */
+       uint32_t max_win;
+       /** Maximal value of ACK in sent packets. */
+       uint32_t max_ack;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
  *
- * Opaque type returned after successfully creating a shared action.
+ * RTE_FLOW_ACTION_TYPE_CONNTRACK
  *
- * This handle can be used to manage and query the related action:
- * - share it across multiple flow rules
- * - update action configuration
- * - query action data
- * - destroy action
+ * Configuration and initial state for the connection tracking module.
+ * This structure could be used for both setting and query.
+ * All fields should be in host byte order.
  */
-struct rte_flow_shared_action;
+struct rte_flow_action_conntrack {
+       /** The peer port number, can be the same port. */
+       uint16_t peer_port;
+       /**
+        * Direction of this connection when creating a flow rule, the
+        * value only affects the creation of subsequent flow rules.
+        */
+       uint32_t is_original_dir:1;
+       /**
+        * Enable / disable the conntrack HW module. When disabled, the
+        * result will always be RTE_FLOW_CONNTRACK_FLAG_DISABLED.
+        * In this state the HW will act as passthrough.
+        * It only affects this conntrack object in the HW without any effect
+        * to the other objects.
+        */
+       uint32_t enable:1;
+       /** At least one ack was seen after the connection was established. */
+       uint32_t live_connection:1;
+       /** Enable selective ACK on this connection. */
+       uint32_t selective_ack:1;
+       /** A challenge ack has passed. */
+       uint32_t challenge_ack_passed:1;
+       /**
+        * 1: The last packet is seen from the original direction.
+        * 0: The last packet is seen from the reply direction.
+        */
+       uint32_t last_direction:1;
+       /** No TCP check will be done except the state change. */
+       uint32_t liberal_mode:1;
+       /**<The current state of this connection. */
+       enum rte_flow_conntrack_state state;
+       /** Scaling factor for maximal allowed ACK window. */
+       uint8_t max_ack_window;
+       /** Maximal allowed number of retransmission times. */
+       uint8_t retransmission_limit;
+       /** TCP parameters of the original direction. */
+       struct rte_flow_tcp_dir_param original_dir;
+       /** TCP parameters of the reply direction. */
+       struct rte_flow_tcp_dir_param reply_dir;
+       /** The window value of the last packet passed this conntrack. */
+       uint16_t last_window;
+       enum rte_flow_conntrack_tcp_last_index last_index;
+       /** The sequence of the last packet passed this conntrack. */
+       uint32_t last_seq;
+       /** The acknowledgment of the last packet passed this conntrack. */
+       uint32_t last_ack;
+       /**
+        * The total value ACK + payload length of the last packet
+        * passed this conntrack.
+        */
+       uint32_t last_end;
+};
+
+/**
+ * RTE_FLOW_ACTION_TYPE_CONNTRACK
+ *
+ * Wrapper structure for the context update interface.
+ * Ports cannot support updating, and the only valid solution is to
+ * destroy the old context and create a new one instead.
+ */
+struct rte_flow_modify_conntrack {
+       /** New connection tracking parameters to be updated. */
+       struct rte_flow_action_conntrack new_ct;
+       /** The direction field will be updated. */
+       uint32_t direction:1;
+       /** All the other fields except direction will be updated. */
+       uint32_t state:1;
+       /** Reserved bits for the future usage. */
+       uint32_t reserved:30;
+};
 
 /**
  * Field IDs for MODIFY_FIELD action.
@@ -3631,25 +3910,22 @@ rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
                        uint32_t nb_contexts, struct rte_flow_error *error);
 
 /**
- * Specify shared action configuration
+ * Specify indirect action object configuration
  */
-struct rte_flow_shared_action_conf {
+struct rte_flow_indir_action_conf {
        /**
-        * Flow direction for shared action configuration.
+        * Flow direction for the indirect action configuration.
         *
-        * Shared action should be valid at least for one flow direction,
+        * Action should be valid at least for one flow direction,
         * otherwise it is invalid for both ingress and egress rules.
         */
        uint32_t ingress:1;
        /**< Action valid for rules applied to ingress traffic. */
        uint32_t egress:1;
        /**< Action valid for rules applied to egress traffic. */
-
        /**
         * When set to 1, indicates that the action is valid for
         * transfer traffic; otherwise, for non-transfer traffic.
-        *
-        * See struct rte_flow_attr.
         */
        uint32_t transfer:1;
 };
@@ -3658,16 +3934,17 @@ struct rte_flow_shared_action_conf {
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
- * Create shared action for reuse in multiple flow rules.
- * The created shared action has single state and configuration
- * across all flow rules using it.
+ * Create an indirect action object that can be used in flow rules
+ * via its handle.
+ * The created object handle has single state and configuration
+ * across all the flow rules using it.
  *
  * @param[in] port_id
  *    The port identifier of the Ethernet device.
  * @param[in] conf
- *   Shared action configuration.
+ *   Action configuration for the indirect action object creation.
  * @param[in] action
- *   Action configuration for shared action creation.
+ *   Specific configuration of the indirect action object.
  * @param[out] error
  *   Perform verbose error reporting if not NULL. PMDs initialize this
  *   structure in case of error only.
@@ -3681,9 +3958,9 @@ struct rte_flow_shared_action_conf {
  *   - (ENOTSUP) if *action* valid but unsupported.
  */
 __rte_experimental
-struct rte_flow_shared_action *
-rte_flow_shared_action_create(uint16_t port_id,
-                             const struct rte_flow_shared_action_conf *conf,
+struct rte_flow_action_handle *
+rte_flow_action_handle_create(uint16_t port_id,
+                             const struct rte_flow_indir_action_conf *conf,
                              const struct rte_flow_action *action,
                              struct rte_flow_error *error);
 
@@ -3691,12 +3968,12 @@ rte_flow_shared_action_create(uint16_t port_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
- * Destroy the shared action by handle.
+ * Destroy indirect action by handle.
  *
  * @param[in] port_id
  *    The port identifier of the Ethernet device.
- * @param[in] action
- *   Handle for the shared action to be destroyed.
+ * @param[in] handle
+ *   Handle for the indirect action object to be destroyed.
  * @param[out] error
  *   Perform verbose error reporting if not NULL. PMDs initialize this
  *   structure in case of error only.
@@ -3711,27 +3988,30 @@ rte_flow_shared_action_create(uint16_t port_id,
  */
 __rte_experimental
 int
-rte_flow_shared_action_destroy(uint16_t port_id,
-                              struct rte_flow_shared_action *action,
+rte_flow_action_handle_destroy(uint16_t port_id,
+                              struct rte_flow_action_handle *handle,
                               struct rte_flow_error *error);
 
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
- * Update in-place the shared action configuration pointed by *action* handle
- * with the configuration provided as *update* argument.
- * The update of the shared action configuration effects all flow rules reusing
- * the action via handle.
+ * Update in-place the action configuration and / or state pointed
+ * by action *handle* with the configuration provided as *update* argument.
+ * The update of the action configuration effects all flow rules reusing
+ * the action via *handle*.
+ * The update general pointer provides the ability of partial updating.
  *
  * @param[in] port_id
  *    The port identifier of the Ethernet device.
- * @param[in] action
- *   Handle for the shared action to be updated.
+ * @param[in] handle
+ *   Handle for the indirect action object to be updated.
  * @param[in] update
- *   Action specification used to modify the action pointed by handle.
- *   *update* should be of same type with the action pointed by the *action*
- *   handle argument, otherwise considered as invalid.
+ *   Update profile specification used to modify the action pointed by handle.
+ *   *update* could be with the same type of the immediate action corresponding
+ *   to the *handle* argument when creating, or a wrapper structure includes
+ *   action configuration to be updated and bit fields to indicate the member
+ *   of fields inside the action to update.
  * @param[out] error
  *   Perform verbose error reporting if not NULL. PMDs initialize this
  *   structure in case of error only.
@@ -3742,32 +4022,32 @@ rte_flow_shared_action_destroy(uint16_t port_id,
  *   - (-EIO) if underlying device is removed.
  *   - (-EINVAL) if *update* invalid.
  *   - (-ENOTSUP) if *update* valid but unsupported.
- *   - (-ENOENT) if action pointed by *ctx* was not found.
+ *   - (-ENOENT) if indirect action object pointed by *handle* was not found.
  *   rte_errno is also set.
  */
 __rte_experimental
 int
-rte_flow_shared_action_update(uint16_t port_id,
-                             struct rte_flow_shared_action *action,
-                             const struct rte_flow_action *update,
+rte_flow_action_handle_update(uint16_t port_id,
+                             struct rte_flow_action_handle *handle,
+                             const void *update,
                              struct rte_flow_error *error);
 
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
- * Query the shared action by handle.
+ * Query the direct action by corresponding indirect action object handle.
  *
  * Retrieve action-specific data such as counters.
  * Data is gathered by special action which may be present/referenced in
  * more than one flow rule definition.
  *
- * \see RTE_FLOW_ACTION_TYPE_COUNT
+ * @see RTE_FLOW_ACTION_TYPE_COUNT
  *
  * @param port_id
  *   Port identifier of Ethernet device.
- * @param[in] action
- *   Handle for the shared action to query.
+ * @param[in] handle
+ *   Handle for the action object to query.
  * @param[in, out] data
  *   Pointer to storage for the associated query data type.
  * @param[out] error
@@ -3779,10 +4059,9 @@ rte_flow_shared_action_update(uint16_t port_id,
  */
 __rte_experimental
 int
-rte_flow_shared_action_query(uint16_t port_id,
-                            const struct rte_flow_shared_action *action,
-                            void *data,
-                            struct rte_flow_error *error);
+rte_flow_action_handle_query(uint16_t port_id,
+                            const struct rte_flow_action_handle *handle,
+                            void *data, struct rte_flow_error *error);
 
 /* Tunnel has a type and the key information. */
 struct rte_flow_tunnel {