1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef RTE_EXEC_ENV_LINUX
6 #error "KNI is not supported"
12 #include <sys/ioctl.h>
13 #include <linux/version.h>
15 #include <rte_spinlock.h>
16 #include <rte_string_fns.h>
17 #include <rte_ethdev.h>
18 #include <rte_malloc.h>
21 #include <rte_memzone.h>
22 #include <rte_tailq.h>
23 #include <rte_rwlock.h>
24 #include <rte_eal_memconfig.h>
25 #include <rte_kni_common.h>
26 #include "rte_kni_fifo.h"
28 #define MAX_MBUF_BURST_NUM 32
30 /* Maximum number of ring entries */
31 #define KNI_FIFO_COUNT_MAX 1024
32 #define KNI_FIFO_SIZE (KNI_FIFO_COUNT_MAX * sizeof(void *) + \
33 sizeof(struct rte_kni_fifo))
35 #define KNI_REQUEST_MBUF_NUM_MAX 32
37 #define KNI_MEM_CHECK(cond, fail) do { if (cond) goto fail; } while (0)
39 #define KNI_MZ_NAME_FMT "kni_info_%s"
40 #define KNI_TX_Q_MZ_NAME_FMT "kni_tx_%s"
41 #define KNI_RX_Q_MZ_NAME_FMT "kni_rx_%s"
42 #define KNI_ALLOC_Q_MZ_NAME_FMT "kni_alloc_%s"
43 #define KNI_FREE_Q_MZ_NAME_FMT "kni_free_%s"
44 #define KNI_REQ_Q_MZ_NAME_FMT "kni_req_%s"
45 #define KNI_RESP_Q_MZ_NAME_FMT "kni_resp_%s"
46 #define KNI_SYNC_ADDR_MZ_NAME_FMT "kni_sync_%s"
48 TAILQ_HEAD(rte_kni_list, rte_tailq_entry);
50 static struct rte_tailq_elem rte_kni_tailq = {
53 EAL_REGISTER_TAILQ(rte_kni_tailq)
59 char name[RTE_KNI_NAMESIZE]; /**< KNI interface name */
60 uint16_t group_id; /**< Group ID of KNI devices */
61 uint32_t slot_id; /**< KNI pool slot ID */
62 struct rte_mempool *pktmbuf_pool; /**< pkt mbuf mempool */
63 unsigned int mbuf_size; /**< mbuf size */
65 const struct rte_memzone *m_tx_q; /**< TX queue memzone */
66 const struct rte_memzone *m_rx_q; /**< RX queue memzone */
67 const struct rte_memzone *m_alloc_q;/**< Alloc queue memzone */
68 const struct rte_memzone *m_free_q; /**< Free queue memzone */
70 struct rte_kni_fifo *tx_q; /**< TX queue */
71 struct rte_kni_fifo *rx_q; /**< RX queue */
72 struct rte_kni_fifo *alloc_q; /**< Allocated mbufs queue */
73 struct rte_kni_fifo *free_q; /**< To be freed mbufs queue */
75 const struct rte_memzone *m_req_q; /**< Request queue memzone */
76 const struct rte_memzone *m_resp_q; /**< Response queue memzone */
77 const struct rte_memzone *m_sync_addr;/**< Sync addr memzone */
79 /* For request & response */
80 struct rte_kni_fifo *req_q; /**< Request queue */
81 struct rte_kni_fifo *resp_q; /**< Response queue */
82 void *sync_addr; /**< Req/Resp Mem address */
84 struct rte_kni_ops ops; /**< operations for request */
88 KNI_REQ_NO_REGISTER = 0,
92 static void kni_free_mbufs(struct rte_kni *kni);
93 static void kni_allocate_mbufs(struct rte_kni *kni);
95 static volatile int kni_fd = -1;
97 /* Shall be called before any allocation happens */
99 rte_kni_init(unsigned int max_kni_ifaces __rte_unused)
101 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
102 if (rte_eal_iova_mode() != RTE_IOVA_PA) {
103 RTE_LOG(ERR, KNI, "KNI requires IOVA as PA\n");
108 /* Check FD and open */
110 kni_fd = open("/dev/" KNI_DEVICE, O_RDWR);
113 "Can not open /dev/%s\n", KNI_DEVICE);
121 static struct rte_kni *
122 __rte_kni_get(const char *name)
125 struct rte_tailq_entry *te;
126 struct rte_kni_list *kni_list;
128 kni_list = RTE_TAILQ_CAST(rte_kni_tailq.head, rte_kni_list);
130 TAILQ_FOREACH(te, kni_list, next) {
132 if (strncmp(name, kni->name, RTE_KNI_NAMESIZE) == 0)
143 kni_reserve_mz(struct rte_kni *kni)
145 char mz_name[RTE_MEMZONE_NAMESIZE];
147 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, KNI_TX_Q_MZ_NAME_FMT, kni->name);
148 kni->m_tx_q = rte_memzone_reserve(mz_name, KNI_FIFO_SIZE, SOCKET_ID_ANY,
149 RTE_MEMZONE_IOVA_CONTIG);
150 KNI_MEM_CHECK(kni->m_tx_q == NULL, tx_q_fail);
152 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, KNI_RX_Q_MZ_NAME_FMT, kni->name);
153 kni->m_rx_q = rte_memzone_reserve(mz_name, KNI_FIFO_SIZE, SOCKET_ID_ANY,
154 RTE_MEMZONE_IOVA_CONTIG);
155 KNI_MEM_CHECK(kni->m_rx_q == NULL, rx_q_fail);
157 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, KNI_ALLOC_Q_MZ_NAME_FMT, kni->name);
158 kni->m_alloc_q = rte_memzone_reserve(mz_name, KNI_FIFO_SIZE, SOCKET_ID_ANY,
159 RTE_MEMZONE_IOVA_CONTIG);
160 KNI_MEM_CHECK(kni->m_alloc_q == NULL, alloc_q_fail);
162 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, KNI_FREE_Q_MZ_NAME_FMT, kni->name);
163 kni->m_free_q = rte_memzone_reserve(mz_name, KNI_FIFO_SIZE, SOCKET_ID_ANY,
164 RTE_MEMZONE_IOVA_CONTIG);
165 KNI_MEM_CHECK(kni->m_free_q == NULL, free_q_fail);
167 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, KNI_REQ_Q_MZ_NAME_FMT, kni->name);
168 kni->m_req_q = rte_memzone_reserve(mz_name, KNI_FIFO_SIZE, SOCKET_ID_ANY,
169 RTE_MEMZONE_IOVA_CONTIG);
170 KNI_MEM_CHECK(kni->m_req_q == NULL, req_q_fail);
172 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, KNI_RESP_Q_MZ_NAME_FMT, kni->name);
173 kni->m_resp_q = rte_memzone_reserve(mz_name, KNI_FIFO_SIZE, SOCKET_ID_ANY,
174 RTE_MEMZONE_IOVA_CONTIG);
175 KNI_MEM_CHECK(kni->m_resp_q == NULL, resp_q_fail);
177 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, KNI_SYNC_ADDR_MZ_NAME_FMT, kni->name);
178 kni->m_sync_addr = rte_memzone_reserve(mz_name, KNI_FIFO_SIZE, SOCKET_ID_ANY,
179 RTE_MEMZONE_IOVA_CONTIG);
180 KNI_MEM_CHECK(kni->m_sync_addr == NULL, sync_addr_fail);
185 rte_memzone_free(kni->m_resp_q);
187 rte_memzone_free(kni->m_req_q);
189 rte_memzone_free(kni->m_free_q);
191 rte_memzone_free(kni->m_alloc_q);
193 rte_memzone_free(kni->m_rx_q);
195 rte_memzone_free(kni->m_tx_q);
201 kni_release_mz(struct rte_kni *kni)
203 rte_memzone_free(kni->m_tx_q);
204 rte_memzone_free(kni->m_rx_q);
205 rte_memzone_free(kni->m_alloc_q);
206 rte_memzone_free(kni->m_free_q);
207 rte_memzone_free(kni->m_req_q);
208 rte_memzone_free(kni->m_resp_q);
209 rte_memzone_free(kni->m_sync_addr);
213 rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
214 const struct rte_kni_conf *conf,
215 struct rte_kni_ops *ops)
218 struct rte_kni_device_info dev_info;
220 struct rte_tailq_entry *te;
221 struct rte_kni_list *kni_list;
223 if (!pktmbuf_pool || !conf || !conf->name[0])
226 /* Check if KNI subsystem has been initialized */
228 RTE_LOG(ERR, KNI, "KNI subsystem has not been initialized. Invoke rte_kni_init() first\n");
232 rte_mcfg_tailq_write_lock();
234 kni = __rte_kni_get(conf->name);
236 RTE_LOG(ERR, KNI, "KNI already exists\n");
240 te = rte_zmalloc("KNI_TAILQ_ENTRY", sizeof(*te), 0);
242 RTE_LOG(ERR, KNI, "Failed to allocate tailq entry\n");
246 kni = rte_zmalloc("KNI", sizeof(struct rte_kni), RTE_CACHE_LINE_SIZE);
248 RTE_LOG(ERR, KNI, "KNI memory allocation failed\n");
252 strlcpy(kni->name, conf->name, RTE_KNI_NAMESIZE);
255 memcpy(&kni->ops, ops, sizeof(struct rte_kni_ops));
257 kni->ops.port_id = UINT16_MAX;
259 memset(&dev_info, 0, sizeof(dev_info));
260 dev_info.core_id = conf->core_id;
261 dev_info.force_bind = conf->force_bind;
262 dev_info.group_id = conf->group_id;
263 dev_info.mbuf_size = conf->mbuf_size;
264 dev_info.mtu = conf->mtu;
265 dev_info.min_mtu = conf->min_mtu;
266 dev_info.max_mtu = conf->max_mtu;
268 memcpy(dev_info.mac_addr, conf->mac_addr, RTE_ETHER_ADDR_LEN);
270 strlcpy(dev_info.name, conf->name, RTE_KNI_NAMESIZE);
272 ret = kni_reserve_mz(kni);
277 kni->tx_q = kni->m_tx_q->addr;
278 kni_fifo_init(kni->tx_q, KNI_FIFO_COUNT_MAX);
279 dev_info.tx_phys = kni->m_tx_q->iova;
282 kni->rx_q = kni->m_rx_q->addr;
283 kni_fifo_init(kni->rx_q, KNI_FIFO_COUNT_MAX);
284 dev_info.rx_phys = kni->m_rx_q->iova;
287 kni->alloc_q = kni->m_alloc_q->addr;
288 kni_fifo_init(kni->alloc_q, KNI_FIFO_COUNT_MAX);
289 dev_info.alloc_phys = kni->m_alloc_q->iova;
292 kni->free_q = kni->m_free_q->addr;
293 kni_fifo_init(kni->free_q, KNI_FIFO_COUNT_MAX);
294 dev_info.free_phys = kni->m_free_q->iova;
297 kni->req_q = kni->m_req_q->addr;
298 kni_fifo_init(kni->req_q, KNI_FIFO_COUNT_MAX);
299 dev_info.req_phys = kni->m_req_q->iova;
302 kni->resp_q = kni->m_resp_q->addr;
303 kni_fifo_init(kni->resp_q, KNI_FIFO_COUNT_MAX);
304 dev_info.resp_phys = kni->m_resp_q->iova;
306 /* Req/Resp sync mem area */
307 kni->sync_addr = kni->m_sync_addr->addr;
308 dev_info.sync_va = kni->m_sync_addr->addr;
309 dev_info.sync_phys = kni->m_sync_addr->iova;
311 kni->pktmbuf_pool = pktmbuf_pool;
312 kni->group_id = conf->group_id;
313 kni->mbuf_size = conf->mbuf_size;
315 dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
317 ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
323 kni_list = RTE_TAILQ_CAST(rte_kni_tailq.head, rte_kni_list);
324 TAILQ_INSERT_TAIL(kni_list, te, next);
326 rte_mcfg_tailq_write_unlock();
328 /* Allocate mbufs and then put them into alloc_q */
329 kni_allocate_mbufs(kni);
340 rte_mcfg_tailq_write_unlock();
346 kni_free_fifo(struct rte_kni_fifo *fifo)
349 struct rte_mbuf *pkt;
352 ret = kni_fifo_get(fifo, (void **)&pkt, 1);
354 rte_pktmbuf_free(pkt);
359 va2pa(struct rte_mbuf *m)
361 return (void *)((unsigned long)m -
362 ((unsigned long)m->buf_addr -
363 (unsigned long)m->buf_iova));
367 va2pa_all(struct rte_mbuf *mbuf)
369 void *phy_mbuf = va2pa(mbuf);
370 struct rte_mbuf *next = mbuf->next;
372 mbuf->next = va2pa(next);
380 obj_free(struct rte_mempool *mp __rte_unused, void *opaque, void *obj,
381 unsigned obj_idx __rte_unused)
383 struct rte_mbuf *m = obj;
384 void *mbuf_phys = opaque;
386 if (va2pa(m) == mbuf_phys)
391 kni_free_fifo_phy(struct rte_mempool *mp, struct rte_kni_fifo *fifo)
397 ret = kni_fifo_get(fifo, &mbuf_phys, 1);
399 rte_mempool_obj_iter(mp, obj_free, mbuf_phys);
404 rte_kni_release(struct rte_kni *kni)
406 struct rte_tailq_entry *te;
407 struct rte_kni_list *kni_list;
408 struct rte_kni_device_info dev_info;
414 kni_list = RTE_TAILQ_CAST(rte_kni_tailq.head, rte_kni_list);
416 rte_mcfg_tailq_write_lock();
418 TAILQ_FOREACH(te, kni_list, next) {
426 strlcpy(dev_info.name, kni->name, sizeof(dev_info.name));
427 if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
428 RTE_LOG(ERR, KNI, "Fail to release kni device\n");
432 TAILQ_REMOVE(kni_list, te, next);
434 rte_mcfg_tailq_write_unlock();
436 /* mbufs in all fifo should be released, except request/response */
438 /* wait until all rxq packets processed by kernel */
439 while (kni_fifo_count(kni->rx_q) && retry--)
442 if (kni_fifo_count(kni->rx_q))
443 RTE_LOG(ERR, KNI, "Fail to free all Rx-q items\n");
445 kni_free_fifo_phy(kni->pktmbuf_pool, kni->alloc_q);
446 kni_free_fifo(kni->tx_q);
447 kni_free_fifo(kni->free_q);
458 rte_mcfg_tailq_write_unlock();
463 /* default callback for request of configuring device mac address */
465 kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
469 if (!rte_eth_dev_is_valid_port(port_id)) {
470 RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id);
474 RTE_LOG(INFO, KNI, "Configure mac address of %d", port_id);
476 ret = rte_eth_dev_default_mac_addr_set(port_id,
477 (struct rte_ether_addr *)mac_addr);
479 RTE_LOG(ERR, KNI, "Failed to config mac_addr for port %d\n",
485 /* default callback for request of configuring promiscuous mode */
487 kni_config_promiscusity(uint16_t port_id, uint8_t to_on)
491 if (!rte_eth_dev_is_valid_port(port_id)) {
492 RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id);
496 RTE_LOG(INFO, KNI, "Configure promiscuous mode of %d to %d\n",
500 ret = rte_eth_promiscuous_enable(port_id);
502 ret = rte_eth_promiscuous_disable(port_id);
506 "Failed to %s promiscuous mode for port %u: %s\n",
507 to_on ? "enable" : "disable", port_id,
513 /* default callback for request of configuring allmulticast mode */
515 kni_config_allmulticast(uint16_t port_id, uint8_t to_on)
517 if (!rte_eth_dev_is_valid_port(port_id)) {
518 RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id);
522 RTE_LOG(INFO, KNI, "Configure allmulticast mode of %d to %d\n",
526 rte_eth_allmulticast_enable(port_id);
528 rte_eth_allmulticast_disable(port_id);
534 rte_kni_handle_request(struct rte_kni *kni)
537 struct rte_kni_request *req = NULL;
542 /* Get request mbuf */
543 ret = kni_fifo_get(kni->req_q, (void **)&req, 1);
545 return 0; /* It is OK of can not getting the request mbuf */
547 if (req != kni->sync_addr) {
548 RTE_LOG(ERR, KNI, "Wrong req pointer %p\n", req);
552 /* Analyze the request and call the relevant actions for it */
553 switch (req->req_id) {
554 case RTE_KNI_REQ_CHANGE_MTU: /* Change MTU */
555 if (kni->ops.change_mtu)
556 req->result = kni->ops.change_mtu(kni->ops.port_id,
559 case RTE_KNI_REQ_CFG_NETWORK_IF: /* Set network interface up/down */
560 if (kni->ops.config_network_if)
561 req->result = kni->ops.config_network_if(kni->ops.port_id,
564 case RTE_KNI_REQ_CHANGE_MAC_ADDR: /* Change MAC Address */
565 if (kni->ops.config_mac_address)
566 req->result = kni->ops.config_mac_address(
567 kni->ops.port_id, req->mac_addr);
568 else if (kni->ops.port_id != UINT16_MAX)
569 req->result = kni_config_mac_address(
570 kni->ops.port_id, req->mac_addr);
572 case RTE_KNI_REQ_CHANGE_PROMISC: /* Change PROMISCUOUS MODE */
573 if (kni->ops.config_promiscusity)
574 req->result = kni->ops.config_promiscusity(
575 kni->ops.port_id, req->promiscusity);
576 else if (kni->ops.port_id != UINT16_MAX)
577 req->result = kni_config_promiscusity(
578 kni->ops.port_id, req->promiscusity);
580 case RTE_KNI_REQ_CHANGE_ALLMULTI: /* Change ALLMULTICAST MODE */
581 if (kni->ops.config_allmulticast)
582 req->result = kni->ops.config_allmulticast(
583 kni->ops.port_id, req->allmulti);
584 else if (kni->ops.port_id != UINT16_MAX)
585 req->result = kni_config_allmulticast(
586 kni->ops.port_id, req->allmulti);
589 RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id);
590 req->result = -EINVAL;
594 /* if needed, construct response buffer and put it back to resp_q */
596 ret = kni_fifo_put(kni->resp_q, (void **)&req, 1);
600 RTE_LOG(ERR, KNI, "Fail to put the muf back to resp_q\n");
601 return -1; /* It is an error of can't putting the mbuf back */
608 rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned int num)
610 num = RTE_MIN(kni_fifo_free_count(kni->rx_q), num);
611 void *phy_mbufs[num];
615 for (i = 0; i < num; i++)
616 phy_mbufs[i] = va2pa_all(mbufs[i]);
618 ret = kni_fifo_put(kni->rx_q, phy_mbufs, num);
620 /* Get mbufs from free_q and then free them */
627 rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned int num)
629 unsigned int ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num);
631 /* If buffers removed, allocate mbufs and then put them into alloc_q */
633 kni_allocate_mbufs(kni);
639 kni_free_mbufs(struct rte_kni *kni)
642 struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM];
644 ret = kni_fifo_get(kni->free_q, (void **)pkts, MAX_MBUF_BURST_NUM);
645 if (likely(ret > 0)) {
646 for (i = 0; i < ret; i++)
647 rte_pktmbuf_free(pkts[i]);
652 kni_allocate_mbufs(struct rte_kni *kni)
655 struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM];
656 void *phys[MAX_MBUF_BURST_NUM];
659 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pool) !=
660 offsetof(struct rte_kni_mbuf, pool));
661 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, buf_addr) !=
662 offsetof(struct rte_kni_mbuf, buf_addr));
663 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, next) !=
664 offsetof(struct rte_kni_mbuf, next));
665 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) !=
666 offsetof(struct rte_kni_mbuf, data_off));
667 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
668 offsetof(struct rte_kni_mbuf, data_len));
669 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
670 offsetof(struct rte_kni_mbuf, pkt_len));
671 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
672 offsetof(struct rte_kni_mbuf, ol_flags));
674 /* Check if pktmbuf pool has been configured */
675 if (kni->pktmbuf_pool == NULL) {
676 RTE_LOG(ERR, KNI, "No valid mempool for allocating mbufs\n");
680 allocq_free = kni_fifo_free_count(kni->alloc_q);
681 allocq_free = (allocq_free > MAX_MBUF_BURST_NUM) ?
682 MAX_MBUF_BURST_NUM : allocq_free;
683 for (i = 0; i < allocq_free; i++) {
684 pkts[i] = rte_pktmbuf_alloc(kni->pktmbuf_pool);
685 if (unlikely(pkts[i] == NULL)) {
687 RTE_LOG(ERR, KNI, "Out of memory\n");
690 phys[i] = va2pa(pkts[i]);
693 /* No pkt mbuf allocated */
697 ret = kni_fifo_put(kni->alloc_q, phys, i);
699 /* Check if any mbufs not put into alloc_q, and then free them */
700 if (ret >= 0 && ret < i && ret < MAX_MBUF_BURST_NUM) {
703 for (j = ret; j < i; j++)
704 rte_pktmbuf_free(pkts[j]);
709 rte_kni_get(const char *name)
713 if (name == NULL || name[0] == '\0')
716 rte_mcfg_tailq_read_lock();
718 kni = __rte_kni_get(name);
720 rte_mcfg_tailq_read_unlock();
726 rte_kni_get_name(const struct rte_kni *kni)
731 static enum kni_ops_status
732 kni_check_request_register(struct rte_kni_ops *ops)
734 /* check if KNI request ops has been registered*/
736 return KNI_REQ_NO_REGISTER;
738 if (ops->change_mtu == NULL
739 && ops->config_network_if == NULL
740 && ops->config_mac_address == NULL
741 && ops->config_promiscusity == NULL
742 && ops->config_allmulticast == NULL)
743 return KNI_REQ_NO_REGISTER;
745 return KNI_REQ_REGISTERED;
749 rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops)
751 enum kni_ops_status req_status;
754 RTE_LOG(ERR, KNI, "Invalid KNI request operation.\n");
759 RTE_LOG(ERR, KNI, "Invalid kni info.\n");
763 req_status = kni_check_request_register(&kni->ops);
764 if (req_status == KNI_REQ_REGISTERED) {
765 RTE_LOG(ERR, KNI, "The KNI request operation has already registered.\n");
769 memcpy(&kni->ops, ops, sizeof(struct rte_kni_ops));
774 rte_kni_unregister_handlers(struct rte_kni *kni)
777 RTE_LOG(ERR, KNI, "Invalid kni info.\n");
781 memset(&kni->ops, 0, sizeof(struct rte_kni_ops));
787 rte_kni_update_link(struct rte_kni *kni, unsigned int linkup)
791 const char *new_carrier;
798 snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier",
801 fd = open(path, O_RDWR);
803 RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path);
807 ret = read(fd, old_carrier, 2);
812 old_linkup = (old_carrier[0] == '1');
814 if (old_linkup == (int)linkup)
817 new_carrier = linkup ? "1" : "0";
818 ret = write(fd, new_carrier, 1);
820 RTE_LOG(ERR, KNI, "Failed to write file: %s.\n", path);