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 11, 2024
1 parent 5eb5c30 commit be0f4a3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
18 changes: 13 additions & 5 deletions src/util-dpdk-rte-flow-pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@
*
*/

#include "util-debug.h"

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

enum index {
/* Special tokens. */
Expand Down Expand Up @@ -1366,11 +1365,20 @@ static int flow_parse(
return (ret >= 0 && !strlen(src)) ? 0 : -1;
}

/**
* \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);
SCReturnInt(flow_parse(pattern, (void *)data, size, items););
}

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

#ifdef HAVE_DPDK
#include <rte_ethdev.h>
#endif

#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

#endif /* SURICATA_RTE_FLOW_RULES_PATTERN_H */
/**
* @}
Expand Down
36 changes: 32 additions & 4 deletions src/util-dpdk-rte-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ static int RuleStorageExtendCapacity(RuleStorage *rule_storage)
SCReturnInt(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 (rule_storage->rules == NULL) {
Expand All @@ -112,6 +117,15 @@ void RuleStorageFree(RuleStorage *rule_storage)
rule_storage->rules = NULL;
}

/**
* \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)
{
Expand Down Expand Up @@ -142,7 +156,10 @@ int ConfigLoadRTEFlowRules(

/**
* \brief Check and log whether pattern is broad / not-specific
* as ice does not accept them */
* as ice does not accept them
*
* \param items array of pattern items
*/
static void iceDeviceError(struct rte_flow_item *items)
{
int i = 0;
Expand All @@ -157,14 +174,27 @@ static void iceDeviceError(struct rte_flow_item *items)

/**
* \brief Specify ambigous error messages as some drivers have specific
* behaviour when creating rte_flow rules */
* 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);
}
}

/**
* \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)
{
SCEnter();
Expand All @@ -187,14 +217,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 Down

0 comments on commit be0f4a3

Please sign in to comment.