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>
83 lines
1.5 KiB
C
83 lines
1.5 KiB
C
/* SPDX-License-Identifier: BSD-3-Clause
|
|
* Copyright(c) 2010-2018 Intel Corporation
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <rte_mbuf.h>
|
|
#include <rte_string_fns.h>
|
|
|
|
#include "mempool.h"
|
|
|
|
#define BUFFER_SIZE_MIN (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
|
|
|
|
static struct mempool_list mempool_list;
|
|
|
|
int
|
|
mempool_init(void)
|
|
{
|
|
TAILQ_INIT(&mempool_list);
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct mempool *
|
|
mempool_find(const char *name)
|
|
{
|
|
struct mempool *mempool;
|
|
|
|
if (name == NULL)
|
|
return NULL;
|
|
|
|
TAILQ_FOREACH(mempool, &mempool_list, node)
|
|
if (strcmp(mempool->name, name) == 0)
|
|
return mempool;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
struct mempool *
|
|
mempool_create(const char *name, struct mempool_params *params)
|
|
{
|
|
struct mempool *mempool;
|
|
struct rte_mempool *m;
|
|
|
|
/* Check input params */
|
|
if ((name == NULL) ||
|
|
mempool_find(name) ||
|
|
(params == NULL) ||
|
|
(params->buffer_size < BUFFER_SIZE_MIN) ||
|
|
(params->pool_size == 0))
|
|
return NULL;
|
|
|
|
/* Resource create */
|
|
m = rte_pktmbuf_pool_create(
|
|
name,
|
|
params->pool_size,
|
|
params->cache_size,
|
|
0,
|
|
params->buffer_size - sizeof(struct rte_mbuf),
|
|
params->cpu_id);
|
|
|
|
if (m == NULL)
|
|
return NULL;
|
|
|
|
/* Node allocation */
|
|
mempool = calloc(1, sizeof(struct mempool));
|
|
if (mempool == NULL) {
|
|
rte_mempool_free(m);
|
|
return NULL;
|
|
}
|
|
|
|
/* Node fill in */
|
|
strlcpy(mempool->name, name, sizeof(mempool->name));
|
|
mempool->m = m;
|
|
mempool->buffer_size = params->buffer_size;
|
|
|
|
/* Node add to list */
|
|
TAILQ_INSERT_TAIL(&mempool_list, mempool, node);
|
|
|
|
return mempool;
|
|
}
|