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>
22 #define TAP_DEV "/dev/net/tun"
24 static struct tap_list tap_list;
29 TAILQ_INIT(&tap_list);
35 tap_find(const char *name)
42 TAILQ_FOREACH(tap, &tap_list, node)
43 if (strcmp(tap->name, name) == 0)
49 #ifndef RTE_EXEC_ENV_LINUX
52 tap_create(const char *name __rte_unused)
60 tap_create(const char *name)
66 /* Check input params */
72 fd = open(TAP_DEV, O_RDWR | O_NONBLOCK);
76 memset(&ifr, 0, sizeof(ifr));
77 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
78 strlcpy(ifr.ifr_name, name, IFNAMSIZ);
80 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
87 tap = calloc(1, sizeof(struct tap));
93 strlcpy(tap->name, name, sizeof(tap->name));
96 /* Node add to list */
97 TAILQ_INSERT_TAIL(&tap_list, tap, node);