1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #include <netinet/in.h>
6 #ifdef RTE_EXEC_ENV_LINUX
8 #include <linux/if_tun.h>
10 #include <sys/ioctl.h>
18 #include <rte_string_fns.h>
20 #include "rte_eth_softnic_internals.h"
22 #define TAP_DEV "/dev/net/tun"
25 softnic_tap_init(struct pmd_internals *p)
27 TAILQ_INIT(&p->tap_list);
33 softnic_tap_free(struct pmd_internals *p)
36 struct softnic_tap *tap;
38 tap = TAILQ_FIRST(&p->tap_list);
42 TAILQ_REMOVE(&p->tap_list, tap, node);
48 softnic_tap_find(struct pmd_internals *p,
51 struct softnic_tap *tap;
56 TAILQ_FOREACH(tap, &p->tap_list, node)
57 if (strcmp(tap->name, name) == 0)
63 #ifndef RTE_EXEC_ENV_LINUX
66 softnic_tap_create(struct pmd_internals *p __rte_unused,
67 const char *name __rte_unused)
75 softnic_tap_create(struct pmd_internals *p,
78 struct softnic_tap *tap;
82 /* Check input params */
84 softnic_tap_find(p, name))
88 fd = open(TAP_DEV, O_RDWR | O_NONBLOCK);
92 memset(&ifr, 0, sizeof(ifr));
93 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
94 strlcpy(ifr.ifr_name, name, IFNAMSIZ);
96 status = ioctl(fd, TUNSETIFF, (void *)&ifr);
102 /* Node allocation */
103 tap = calloc(1, sizeof(struct softnic_tap));
109 strlcpy(tap->name, name, sizeof(tap->name));
112 /* Node add to list */
113 TAILQ_INSERT_TAIL(&p->tap_list, tap, node);