Skip to content

Commit

Permalink
dpdk/rte_flow: add doxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Kiripolsky authored and Adam Kiripolsky committed Dec 18, 2024
1 parent e825e5b commit 933dceb
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/runmode-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ static void DPDKDerefConfig(void *conf)
{
SCEnter();
DPDKIfaceConfig *iconf = (DPDKIfaceConfig *)conf;

iconf->RTERulesFree(&iconf->drop_filter);

if (SC_ATOMIC_SUB(iconf->ref, 1) == 1) {
Expand Down
1 change: 1 addition & 0 deletions src/source-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ static TmEcode ReceiveDPDKThreadInit(ThreadVars *tv, const void *initdata, void
SCLogError("%s: error when creating rte_flow rules", dpdk_config->iface);
goto fail;
}

// some PMDs requires additional actions only after the device has started
DevicePostStartPMDSpecificActions(ptv, dev_info.driver_name);

Expand Down
25 changes: 21 additions & 4 deletions src/util-dpdk-rte-flow-pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@
*/

#include "util-debug.h"
#include "util-dpdk.h"
#include "util-dpdk-rte-flow-pattern.h"

#ifdef HAVE_DPDK
#if RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)

#include <cmdline_parse_etheraddr.h>
#include "util-dpdk-rte-flow-pattern.h"

enum index {
/* Special tokens. */
Expand Down Expand Up @@ -392,6 +395,7 @@ struct arg {
uint32_t size; /**< Field size. */
const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
};

struct buffer {
enum index command; /**< Flow command. */
union {
Expand Down Expand Up @@ -1365,12 +1369,25 @@ static int flow_parse(

return (ret >= 0 && !strlen(src)) ? 0 : -1;
}

#endif /* RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)*/
/**
* \brief Parse rte_flow rule pattern and store individual pattern items in items and their
* attributes in buffer data
*
* \param pattern rte_flow rule pattern to be parsed
* \param data buffer to store parsed pattern
* \param size size of buffer
* \param items parsed items used when creating rte_flow rules
* \return int 0 on success, -1 on error
*/
int ParsePattern(char *pattern, uint8_t *data, unsigned int size, struct rte_flow_item **items)
{
SCEnter();
int ret = flow_parse(pattern, (void *)data, size, items);
SCReturnInt(ret);
#if RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)
SCReturnInt(flow_parse(pattern, (void *)data, size, items));
#else
SCReturnInt(0);
#endif /* RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)*/
}

#endif /* HAVE_DPDK */
Expand Down
9 changes: 6 additions & 3 deletions src/util-dpdk-rte-flow-pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@
*
*/

#ifdef HAVE_DPDK
#include <rte_ethdev.h>
#endif
#include "util-dpdk.h"

#ifndef SURICATA_RTE_FLOW_RULES_PATTERN_H
#define SURICATA_RTE_FLOW_RULES_PATTERN_H

#ifdef HAVE_DPDK

#include <rte_ethdev.h>

int ParsePattern(char *pattern, uint8_t *data, unsigned int size, struct rte_flow_item **items);

#endif /* HAVE_DPDK */
#endif /* SURICATA_RTE_FLOW_RULES_PATTERN_H */
/**
* @}
Expand Down
92 changes: 64 additions & 28 deletions src/util-dpdk-rte-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
#include "decode.h"
#include "runmode-dpdk.h"
#include "util-debug.h"
#include "util-dpdk.h"
#include "util-dpdk-rte-flow.h"
#include "util-dpdk-rte-flow-pattern.h"

#ifdef HAVE_DPDK
#if RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)

#define INITIAL_RULE_COUNT_CAPACITY 5
#define DATA_BUFFER_SIZE 1024
Expand Down Expand Up @@ -100,8 +102,47 @@ static int RuleStorageExtendCapacity(RuleStorage *rule_storage)
SCReturnInt(0);
}

/**
* \brief Check and log whether pattern is broad / not-specific
* as ice does not accept them
*
* \param items array of pattern items
*/
static void iceDeviceError(struct rte_flow_item *items)
{
int i = 0;
while (items[i].type != RTE_FLOW_ITEM_TYPE_END) {
if (items[i].spec != NULL) {
SCReturn;
}
++i;
}
SCLogError("ice driver does not support broad patterns");
}

/**
* \brief Specify ambigous error messages as some drivers have specific
* behaviour when creating rte_flow rules
*
* \param driver_name name of a driver
* \param items array of pattern items
*/
static void DriverSpecificErrorMessage(const char *driver_name, struct rte_flow_item *items)
{
if (strcmp(driver_name, "net_ice") == 0) {
iceDeviceError(items);
}
}
#endif /* RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0) */

/**
* \brief Deallocation of memory containing user set rte_flow rules
*
* \param rule_storage rules loaded from suricata.yaml
*/
void RuleStorageFree(RuleStorage *rule_storage)
{
#if RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)
if (rule_storage->rules == NULL) {
SCReturn;
}
Expand All @@ -110,11 +151,22 @@ void RuleStorageFree(RuleStorage *rule_storage)
}
SCFree(rule_storage->rules);
rule_storage->rules = NULL;
#endif /* RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0) */
}

/**
* \brief Load rte_flow rules patterns from suricata.yaml
*
* \param if_root root node in suricata.yaml
* \param if_default default value
* \param filter_type type of rte_flow rules to be loaded, only drop_filter is supported
* \param rule_storage pointer to structure to load rte_flow rules into
* \return int 0 on success, -1 on failure
*/
int ConfigLoadRTEFlowRules(
ConfNode *if_root, ConfNode *if_default, const char *filter_type, RuleStorage *rule_storage)
{
#if RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)
SCEnter();
ConfNode *node = ConfNodeLookupChild(if_root, filter_type);
if (node == NULL) {
Expand All @@ -137,36 +189,22 @@ int ConfigLoadRTEFlowRules(
}
}
}
#endif
SCReturnInt(0);
}

/**
* \brief Check and log whether pattern is broad / not-specific
* as ice does not accept them */
static void iceDeviceError(struct rte_flow_item *items)
{
int i = 0;
while (items[i].type != RTE_FLOW_ITEM_TYPE_END) {
if (items[i].spec != NULL) {
SCReturn;
}
++i;
}
SCLogError("ice driver does not support broad patterns");
}

/**
* \brief Specify ambigous error messages as some drivers have specific
* behaviour when creating rte_flow rules */
static void DriverSpecificErrorMessage(const char *driver_name, struct rte_flow_item *items)
{
if (strcmp(driver_name, "net_ice") == 0) {
iceDeviceError(items);
}
}

* \brief Create rte_flow drop rules with patterns stored in rule_storage on a port with id port_id
*
* \param port_name name of a port
* \param port_id identificator of a port
* \param rule_storage pointer to structure containing rte_flow rule patterns
* \param driver_name name of a driver
* \return int 0 on success, -1 on error
*/
int CreateRules(char *port_name, int port_id, RuleStorage *rule_storage, const char *driver_name)
{
#if RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)
SCEnter();
int failed_count = 0;
struct rte_flow_error flush_error = { 0 };
Expand All @@ -187,14 +225,12 @@ int CreateRules(char *port_name, int port_id, RuleStorage *rule_storage, const c
if ((ret = ParsePattern(rule_storage->rules[i], data, sizeof(data), &items)) != 0) {
failed_count++;
SCLogError("Error when parsing rte_flow rule: %s", rule_storage->rules[i]);
continue;
} else if ((ret = rte_flow_validate(port_id, &attr, items, action, &flow_error)) != 0) {
failed_count++;
SCLogError("Error when validating rte_flow rule with pattern %s for port %s: %s "
"errmsg: %s",
rule_storage->rules[i], port_name, rte_strerror(-ret), flow_error.message);
DriverSpecificErrorMessage(driver_name, items);
continue;
} else if ((flow = rte_flow_create(port_id, &attr, items, action, &flow_error)) == NULL) {
failed_count++;
SCLogError("Error when creating rte_flow rule with pattern %s on %s: %s",
Expand All @@ -214,9 +250,9 @@ int CreateRules(char *port_name, int port_id, RuleStorage *rule_storage, const c
SCLogError("Unable to flush rte_flow rules of %s: %s Flush error msg: %s", port_name,
rte_strerror(-ret), flush_error.message);
}
SCReturn(-1);
SCReturnInt(-1);
}

#endif /* RTE_VERSION >= RTE_VERSION_NUM(21, 0, 0, 0)*/
SCReturnInt(0);
}

Expand Down
8 changes: 8 additions & 0 deletions src/util-dpdk-rte-flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@
* DPDK rte_flow rules util functions
*
*/

#include "conf.h"
#include "util-dpdk.h"

#ifndef SURICATA_RTE_FLOW_RULES_H
#define SURICATA_RTE_FLOW_RULES_H

#ifdef HAVE_DPDK

void RuleStorageFree(RuleStorage *rule_storage);
int ConfigLoadRTEFlowRules(ConfNode *if_root, ConfNode *if_default, const char *filter_type,
RuleStorage *rule_storage);
int CreateRules(char *port_name, int port_id, RuleStorage *rule_storage, const char *driver_name);

#endif /* HAVE_DPDK */
#endif /* SURICATA_RTE_FLOW_RULES_H */
/**
* @}
*/

0 comments on commit 933dceb

Please sign in to comment.