numam-dpdk/examples/ip_pipeline/tap.c
Jasvinder Singh 7959831b4d examples/ip_pipeline: replace strncpy with strlcpy
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>
2018-05-08 13:35:10 +02:00

103 lines
1.6 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2018 Intel Corporation
*/
#include <netinet/in.h>
#ifdef RTE_EXEC_ENV_LINUXAPP
#include <linux/if.h>
#include <linux/if_tun.h>
#endif
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <rte_string_fns.h>
#include "tap.h"
#define TAP_DEV "/dev/net/tun"
static struct tap_list tap_list;
int
tap_init(void)
{
TAILQ_INIT(&tap_list);
return 0;
}
struct tap *
tap_find(const char *name)
{
struct tap *tap;
if (name == NULL)
return NULL;
TAILQ_FOREACH(tap, &tap_list, node)
if (strcmp(tap->name, name) == 0)
return tap;
return NULL;
}
#ifndef RTE_EXEC_ENV_LINUXAPP
struct tap *
tap_create(const char *name __rte_unused)
{
return NULL;
}
#else
struct tap *
tap_create(const char *name)
{
struct tap *tap;
struct ifreq ifr;
int fd, status;
/* Check input params */
if ((name == NULL) ||
tap_find(name))
return NULL;
/* Resource create */
fd = open(TAP_DEV, O_RDWR | O_NONBLOCK);
if (fd < 0)
return NULL;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
status = ioctl(fd, TUNSETIFF, (void *) &ifr);
if (status < 0) {
close(fd);
return NULL;
}
/* Node allocation */
tap = calloc(1, sizeof(struct tap));
if (tap == NULL) {
close(fd);
return NULL;
}
/* Node fill in */
strlcpy(tap->name, name, sizeof(tap->name));
tap->fd = fd;
/* Node add to list */
TAILQ_INSERT_TAIL(&tap_list, tap, node);
return tap;
}
#endif