7959831b4d
The destination string may not have a null termination if the source string's length is equal to the sizeof. Fix by replacing strncpy with strlcpy that guarantees NULL-termination. [merged several commits] Coverty issue: 272606 Fixes:d75c371e9b
("examples/ip_pipeline: add pipeline object") Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com> Coverty issue: 272594 Fixes:133c2c6565
("examples/ip_pipeline: add link object") Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com> Coverty issue: 272603 Fixes:2f74ae28e2
("examples/ip_pipeline: add tap object") Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com> Coverity issue: 272588 Fixes:6bfe74f8c9
("examples/ip_pipeline: add mempool object") Signed-off-by: Kevin Laatz <kevin.laatz@intel.com> Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com> Coverity issue: 272592 Fixes:25961ff3bc
("examples/ip_pipeline: add traffic manager object") Signed-off-by: Kevin Laatz <kevin.laatz@intel.com> Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com> Coverity issue: 272562 Fixes:9a408cc8ac
("examples/ip_pipeline: add KNI object") Signed-off-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com> Coverity issue: 272580 Fixes:719374345c
("examples/ip_pipeline: add action profile objects") Signed-off-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com> Coverity issue: 272572 Fixes:719374345c
("examples/ip_pipeline: add action profile objects") Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com> Coverity issue: 272563 Fixes:8245472c58
("examples/ip_pipeline: add sw queue object") Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
359 lines
7.1 KiB
C
359 lines
7.1 KiB
C
/* SPDX-License-Identifier: BSD-3-Clause
|
|
* Copyright(c) 2010-2018 Intel Corporation
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <rte_string_fns.h>
|
|
|
|
#include "action.h"
|
|
#include "hash_func.h"
|
|
|
|
/**
|
|
* Input port
|
|
*/
|
|
static struct port_in_action_profile_list port_in_action_profile_list;
|
|
|
|
int
|
|
port_in_action_profile_init(void)
|
|
{
|
|
TAILQ_INIT(&port_in_action_profile_list);
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct port_in_action_profile *
|
|
port_in_action_profile_find(const char *name)
|
|
{
|
|
struct port_in_action_profile *profile;
|
|
|
|
if (name == NULL)
|
|
return NULL;
|
|
|
|
TAILQ_FOREACH(profile, &port_in_action_profile_list, node)
|
|
if (strcmp(profile->name, name) == 0)
|
|
return profile;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
struct port_in_action_profile *
|
|
port_in_action_profile_create(const char *name,
|
|
struct port_in_action_profile_params *params)
|
|
{
|
|
struct port_in_action_profile *profile;
|
|
struct rte_port_in_action_profile *ap;
|
|
int status;
|
|
|
|
/* Check input params */
|
|
if ((name == NULL) ||
|
|
port_in_action_profile_find(name) ||
|
|
(params == NULL))
|
|
return NULL;
|
|
|
|
if ((params->action_mask & (1LLU << RTE_PORT_IN_ACTION_LB)) &&
|
|
(params->lb.f_hash == NULL)) {
|
|
switch (params->lb.key_size) {
|
|
case 8:
|
|
params->lb.f_hash = hash_default_key8;
|
|
break;
|
|
|
|
case 16:
|
|
params->lb.f_hash = hash_default_key16;
|
|
break;
|
|
|
|
case 24:
|
|
params->lb.f_hash = hash_default_key24;
|
|
break;
|
|
|
|
case 32:
|
|
params->lb.f_hash = hash_default_key32;
|
|
break;
|
|
|
|
case 40:
|
|
params->lb.f_hash = hash_default_key40;
|
|
break;
|
|
|
|
case 48:
|
|
params->lb.f_hash = hash_default_key48;
|
|
break;
|
|
|
|
case 56:
|
|
params->lb.f_hash = hash_default_key56;
|
|
break;
|
|
|
|
case 64:
|
|
params->lb.f_hash = hash_default_key64;
|
|
break;
|
|
|
|
default:
|
|
return NULL;
|
|
}
|
|
|
|
params->lb.seed = 0;
|
|
}
|
|
/* Resource */
|
|
ap = rte_port_in_action_profile_create(0);
|
|
if (ap == NULL)
|
|
return NULL;
|
|
|
|
if (params->action_mask & (1LLU << RTE_PORT_IN_ACTION_FLTR)) {
|
|
status = rte_port_in_action_profile_action_register(ap,
|
|
RTE_PORT_IN_ACTION_FLTR,
|
|
¶ms->fltr);
|
|
|
|
if (status) {
|
|
rte_port_in_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_PORT_IN_ACTION_LB)) {
|
|
status = rte_port_in_action_profile_action_register(ap,
|
|
RTE_PORT_IN_ACTION_LB,
|
|
¶ms->lb);
|
|
|
|
if (status) {
|
|
rte_port_in_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
status = rte_port_in_action_profile_freeze(ap);
|
|
if (status) {
|
|
rte_port_in_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
|
|
/* Node allocation */
|
|
profile = calloc(1, sizeof(struct port_in_action_profile));
|
|
if (profile == NULL) {
|
|
rte_port_in_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
|
|
/* Node fill in */
|
|
strlcpy(profile->name, name, sizeof(profile->name));
|
|
memcpy(&profile->params, params, sizeof(*params));
|
|
profile->ap = ap;
|
|
|
|
/* Node add to list */
|
|
TAILQ_INSERT_TAIL(&port_in_action_profile_list, profile, node);
|
|
|
|
return profile;
|
|
}
|
|
|
|
/**
|
|
* Table
|
|
*/
|
|
static struct table_action_profile_list table_action_profile_list;
|
|
|
|
int
|
|
table_action_profile_init(void)
|
|
{
|
|
TAILQ_INIT(&table_action_profile_list);
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct table_action_profile *
|
|
table_action_profile_find(const char *name)
|
|
{
|
|
struct table_action_profile *profile;
|
|
|
|
if (name == NULL)
|
|
return NULL;
|
|
|
|
TAILQ_FOREACH(profile, &table_action_profile_list, node)
|
|
if (strcmp(profile->name, name) == 0)
|
|
return profile;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
struct table_action_profile *
|
|
table_action_profile_create(const char *name,
|
|
struct table_action_profile_params *params)
|
|
{
|
|
struct table_action_profile *profile;
|
|
struct rte_table_action_profile *ap;
|
|
int status;
|
|
|
|
/* Check input params */
|
|
if ((name == NULL) ||
|
|
table_action_profile_find(name) ||
|
|
(params == NULL) ||
|
|
((params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) == 0))
|
|
return NULL;
|
|
|
|
if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) &&
|
|
(params->lb.f_hash == NULL)) {
|
|
switch (params->lb.key_size) {
|
|
case 8:
|
|
params->lb.f_hash = hash_default_key8;
|
|
break;
|
|
|
|
case 16:
|
|
params->lb.f_hash = hash_default_key16;
|
|
break;
|
|
|
|
case 24:
|
|
params->lb.f_hash = hash_default_key24;
|
|
break;
|
|
|
|
case 32:
|
|
params->lb.f_hash = hash_default_key32;
|
|
break;
|
|
|
|
case 40:
|
|
params->lb.f_hash = hash_default_key40;
|
|
break;
|
|
|
|
case 48:
|
|
params->lb.f_hash = hash_default_key48;
|
|
break;
|
|
|
|
case 56:
|
|
params->lb.f_hash = hash_default_key56;
|
|
break;
|
|
|
|
case 64:
|
|
params->lb.f_hash = hash_default_key64;
|
|
break;
|
|
|
|
default:
|
|
return NULL;
|
|
}
|
|
|
|
params->lb.seed = 0;
|
|
}
|
|
|
|
/* Resource */
|
|
ap = rte_table_action_profile_create(¶ms->common);
|
|
if (ap == NULL)
|
|
return NULL;
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_FWD,
|
|
NULL);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_LB,
|
|
¶ms->lb);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_MTR,
|
|
¶ms->mtr);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_TM,
|
|
¶ms->tm);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_ENCAP,
|
|
¶ms->encap);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_NAT,
|
|
¶ms->nat);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_TTL,
|
|
¶ms->ttl);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_STATS,
|
|
¶ms->stats);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
|
|
status = rte_table_action_profile_action_register(ap,
|
|
RTE_TABLE_ACTION_TIME,
|
|
NULL);
|
|
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
status = rte_table_action_profile_freeze(ap);
|
|
if (status) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
|
|
/* Node allocation */
|
|
profile = calloc(1, sizeof(struct table_action_profile));
|
|
if (profile == NULL) {
|
|
rte_table_action_profile_free(ap);
|
|
return NULL;
|
|
}
|
|
|
|
/* Node fill in */
|
|
strlcpy(profile->name, name, sizeof(profile->name));
|
|
memcpy(&profile->params, params, sizeof(*params));
|
|
profile->ap = ap;
|
|
|
|
/* Node add to list */
|
|
TAILQ_INSERT_TAIL(&table_action_profile_list, profile, node);
|
|
|
|
return profile;
|
|
}
|