]> git.feebdaed.xyz Git - 0xmirror/f-stack.git/commitdiff
Remove the code for rte_kni.ko, only retain virtio.
authorfengbojiang <fengbojiang@tencent.com>
Mon, 3 Nov 2025 03:50:05 +0000 (11:50 +0800)
committerfengbojiang <fengbojiang@tencent.com>
Mon, 3 Nov 2025 03:50:05 +0000 (11:50 +0800)
config.ini
lib/Makefile
lib/ff_config.c
lib/ff_config.h
lib/ff_dpdk_if.c
lib/ff_dpdk_kni.c
lib/ff_dpdk_kni.h

index adb8a565935c8744dff6656cf33c9ff0427c2049..304f89ad6ad75139f49a66751c5c1d18ef4e4e95 100644 (file)
@@ -251,9 +251,7 @@ rss_tbl=0 192.168.1.1 192.168.2.1 80;0 192.168.1.1 192.168.2.1 443
 # all packets that do not belong to the following tcp_port and udp_port
 # will transmit to kernel; if method=accept, all packets that belong to
 # the following tcp_port and udp_port will transmit to kernel.
-#      type: exception path type, 0 means kni(must set meson -Ddisable_libs=flow_classif to re-enable kni in DPDK first), 1 means virtio_user(linux only)
 #[kni]
-#type=1
 #enable=1
 #method=reject
 # The format is same as port_list
index 279c00193f366bbaa24712a6c1c886334750a378..9421400eb27eb6b100acd07c4c44119f88490873 100644 (file)
@@ -1,4 +1,4 @@
-# 
+#
 # Copyright (c) 2013 Patrick Kelsey. All rights reserved.
 # Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
 # All rights reserved.
@@ -31,9 +31,9 @@ HOST_OS:=$(shell uname -s)
 #DEBUG=-O0 -gdwarf-2 -g3 -Wno-format-truncation
 
 # No DPDK KNI support on FreeBSD
+# Enable KNI, via viritio only, no longer support rte_kni.ko.
 ifneq ($(TGT_OS),FreeBSD)
 FF_KNI=1
-#FF_KNI_KNI=1
 endif
 
 #FF_FLOW_ISOLATE=1
@@ -79,17 +79,13 @@ endif
 ifndef DEBUG
 HOST_CFLAGS = -O2 -frename-registers  -funswitch-loops -fweb -Wno-format-truncation
 else
-HOST_CFLAGS = ${DEBUG} 
+HOST_CFLAGS = ${DEBUG}
 endif
 
 ifdef FF_KNI
 HOST_CFLAGS+= -DFF_KNI
 endif
 
-ifdef FF_KNI_KNI
-HOST_CFLAGS+= -DFF_KNI_KNI
-endif
-
 HOST_CFLAGS+= ${DPDK_CFLAGS}
 HOST_CFLAGS+= ${CONF_CFLAGS}
 
@@ -124,7 +120,7 @@ CFLAGS+= -DINET
 GCCVERGE10 = $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 10)
 ifeq "$(GCCVERGE10)" "1"
     CFLAGS+= -Wno-error=stringop-overflow
-endif 
+endif
 
 GCCVERGE11 = $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 11)
 ifeq "$(GCCVERGE11)" "1"
@@ -288,7 +284,7 @@ FF_HOST_SRCS+=              \
        ff_dpdk_pcap.c      \
        ff_epoll.c          \
        ff_log.c            \
-       ff_init.c       
+       ff_init.c
 
 ifdef FF_KNI
 FF_HOST_SRCS+=              \
@@ -578,7 +574,7 @@ EXTRA_TCP_STACKS_SRCS+=             \
        bbr.c
 endif
 
+
 ifneq ($(TGT_OS),FreeBSD)
 ifndef FF_KNI
 FF_HOST_SRCS+=         \
@@ -677,7 +673,7 @@ all: libfstack.a
 libfstack.a: machine_includes ff_api.symlist ${MHEADERS} ${MSRCS} ${HOST_OBJS} ${ASM_OBJS} ${OBJS}
        ${LD} -d -r -o $*.ro ${ASM_OBJS} ${OBJS}
        nm $*.ro  | grep -v ' U ' | cut -d ' ' -f 3 > $*_localize_list.tmp
-       objcopy --localize-symbols=$*_localize_list.tmp $*.ro 
+       objcopy --localize-symbols=$*_localize_list.tmp $*.ro
        rm $*_localize_list.tmp
        objcopy --globalize-symbols=ff_api.symlist $*.ro
        rm -f $@
index 6cdfa44849af41b4bac61d4de2547e66eb8c2493..14c193a3b58f0f736ee071c8c6c58ecb22367ee4 100644 (file)
@@ -988,8 +988,6 @@ ini_parse_handler(void* user, const char* section, const char* name,
         pconfig->dpdk.symmetric_rss = atoi(value);
     } else if (MATCH("kni", "enable")) {
         pconfig->kni.enable= atoi(value);
-    } else if (MATCH("kni", "type")) {
-        pconfig->kni.type= atoi(value);
     } else if (MATCH("kni", "console_packets_ratelimit")) {
         pconfig->kni.console_packets_ratelimit= atoi(value);
     } else if (MATCH("kni", "general_packets_ratelimit")) {
@@ -1311,12 +1309,6 @@ ff_check_config(struct ff_config *cfg)
                          lcore_id, pc->port_id);
                 return -1;
             }
-
-            if (cfg->kni.type != KNI_TYPE_KNI && cfg->kni.type != KNI_TYPE_VIRTIO) {
-                fprintf(stderr,
-                         "kni type value must be 0 or 1, now is:%d\n", cfg->kni.type);
-                return -1;
-            }
         }
     }
 
index 2a623079922feca212d558e2739d7c27682eeac1..52c4729f83df0a324e1f3758ef5dfc8c5d3fa83a 100644 (file)
@@ -57,10 +57,6 @@ extern char *dpdk_argv[DPDK_CONFIG_NUM + 1];
 
 #define VIP_MAX_NUM 64
 
-/* exception path(KNI) type */
-#define KNI_TYPE_KNI        0
-#define KNI_TYPE_VIRTIO     1
-
 /* ff_rss_check table args */
 /* remote IP:PORT */
 #define FF_RSS_TBL_MAX_SADDR        (4)
@@ -313,7 +309,6 @@ struct ff_config {
 
     struct {
         int enable;
-        int type;
         int console_packets_ratelimit;
         int general_packets_ratelimit;
         int kernel_packets_ratelimit;
index ee7aceb9e6330e7de21a1a8b8d07cef73c557a97..67fa1200861774864c3e29d5bad7e60aefe4947b 100644 (file)
@@ -545,7 +545,7 @@ init_kni(void)
 
     knictl_action = get_kni_action(ff_global_cfg.kni.kni_action);
 
-    ff_kni_init(nb_ports, ff_global_cfg.kni.type, ff_global_cfg.kni.tcp_port,
+    ff_kni_init(nb_ports, ff_global_cfg.kni.tcp_port,
         ff_global_cfg.kni.udp_port);
 
     unsigned socket_id = lcore_conf.socket_id;
@@ -555,7 +555,7 @@ init_kni(void)
     int i, ret;
     for (i = 0; i < nb_ports; i++) {
         uint16_t port_id = ff_global_cfg.dpdk.portid_list[i];
-        ff_kni_alloc(port_id, socket_id, ff_global_cfg.kni.type, i, mbuf_pool, KNI_QUEUE_SIZE);
+        ff_kni_alloc(port_id, socket_id, i, KNI_QUEUE_SIZE);
     }
 
     return 0;
@@ -601,12 +601,7 @@ init_port_start(void)
     total_nb_ports = nb_ports;
 #ifdef FF_KNI
     if (enable_kni && rte_eal_process_type() == RTE_PROC_PRIMARY) {
-#ifdef FF_KNI_KNI
-        if (ff_global_cfg.kni.type == KNI_TYPE_VIRTIO)
-#endif
-        {
             total_nb_ports *= 2;  /* one more virtio_user port for kernel per port */
-        }
     }
 #endif
 
index eb9ee3a63c03f3dd6a5e5a17ab2f0b5dd94e7c27..3689ba1229e096510b0d5ca1df377b8e3368e46b 100644 (file)
@@ -32,9 +32,6 @@
 #include <rte_ether.h>
 #include <rte_bus_pci.h>
 #include <rte_ethdev.h>
-#ifdef FF_KNI_KNI
-#include <rte_kni.h>
-#endif
 #include <rte_malloc.h>
 #include <rte_ring.h>
 #include <rte_ip.h>
@@ -73,10 +70,6 @@ static unsigned char *tcp_port_bitmap = NULL;
 
 /* Structure type for recording kni interface specific stats */
 struct kni_interface_stats {
-#ifdef FF_KNI_KNI
-    struct rte_kni *kni;
-#endif
-
     /* port id of dev or virtio_user */
     uint16_t port_id;
 
@@ -140,78 +133,6 @@ kni_set_bitmap(const char *p, unsigned char *port_bitmap)
     }
 }
 
-#ifdef FF_KNI_KNI
-/* Currently we don't support change mtu. */
-static int
-kni_change_mtu(__rte_unused uint16_t port_id, __rte_unused unsigned new_mtu)
-{
-    return 0;
-}
-
-static int
-kni_config_network_interface(uint16_t port_id, uint8_t if_up)
-{
-    int ret = 0;
-
-    if (!rte_eth_dev_is_valid_port(port_id)) {
-        printf("Invalid port id %d\n", port_id);
-        return -EINVAL;
-    }
-
-    printf("Configure network interface of %d %s\n",
-            port_id, if_up ? "up" : "down");
-
-    ret = (if_up) ?
-        rte_eth_dev_set_link_up(port_id) :
-        rte_eth_dev_set_link_down(port_id);
-
-    /*
-     * Some NIC drivers will crash in secondary process after config kni , Such as ENA with DPDK-21.22.3.
-     * If you meet this crash, you can try disable the code below and return 0 directly.
-     * Or run primary first, then config kni interface in kernel, and run secondary processes last.
-     */
-    if(-ENOTSUP == ret) {
-        if (if_up != 0) {
-            /* Configure network interface up */
-            rte_eth_dev_stop(port_id);
-            ret = rte_eth_dev_start(port_id);
-        } else {
-            /* Configure network interface down */
-            rte_eth_dev_stop(port_id);
-            ret = 0;
-        }
-    }
-
-    if (ret < 0)
-        printf("Failed to Configure network interface of %d %s\n",
-            port_id, if_up ? "up" : "down");
-
-    return ret;
-}
-
-/* Callback for request of configuring mac address */
-static int
-kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
-{
-    int ret = 0;
-
-    if (!rte_eth_dev_is_valid_port(port_id)) {
-        printf("Invalid port id %d\n", port_id);
-        return -EINVAL;
-    }
-
-    printf("Port %u Address:"RTE_ETHER_ADDR_PRT_FMT"\n",
-            port_id, RTE_ETHER_ADDR_BYTES((struct rte_ether_addr *)mac_addr));
-
-    ret = rte_eth_dev_default_mac_addr_set(port_id,
-                       (struct rte_ether_addr *)mac_addr);
-    if (ret < 0)
-        printf("Failed to config mac_addr for port %d\n", port_id);
-
-    return ret;
-}
-#endif
-
 static int
 kni_process_tx(uint16_t port_id, __rte_unused uint16_t queue_id,
     struct rte_mbuf **pkts_burst, unsigned count)
@@ -235,20 +156,7 @@ kni_process_tx(uint16_t port_id, __rte_unused uint16_t queue_id,
         nb_to_tx = nb_tx;
     }
 
-#ifdef FF_KNI_KNI
-    if (ff_global_cfg.kni.type == KNI_TYPE_KNI) {
-        /* NB.
-         * if nb_tx is 0,it must call rte_kni_tx_burst
-         * must Call regularly rte_kni_tx_burst(kni, NULL, 0).
-         * detail https://embedded.communities.intel.com/thread/6668
-         */
-        nb_kni_tx = rte_kni_tx_burst(kni_stat[port_id]->kni, pkts_burst, nb_to_tx);
-        rte_kni_handle_request(kni_stat[port_id]->kni);
-    } else if (ff_global_cfg.kni.type == KNI_TYPE_VIRTIO)
-#endif
-    {
-        nb_kni_tx = rte_eth_tx_burst(kni_stat[port_id]->port_id, 0, pkts_burst, nb_to_tx);
-    }
+    nb_kni_tx = rte_eth_tx_burst(kni_stat[port_id]->port_id, 0, pkts_burst, nb_to_tx);
 
     if(nb_kni_tx < nb_tx) {
         uint16_t i;
@@ -268,15 +176,7 @@ kni_process_rx(uint16_t port_id, uint16_t queue_id,
 {
     uint16_t nb_kni_rx = 0, nb_rx;
 
-#ifdef FF_KNI_KNI
-    if (ff_global_cfg.kni.type == KNI_TYPE_KNI) {
-        /* read packet from kni, and transmit to phy port */
-        nb_kni_rx = rte_kni_rx_burst(kni_stat[port_id]->kni, pkts_burst, count);
-    } else if (ff_global_cfg.kni.type == KNI_TYPE_VIRTIO)
-#endif
-    {
-        nb_kni_rx = rte_eth_rx_burst(kni_stat[port_id]->port_id, 0, pkts_burst, count);
-    }
+    nb_kni_rx = rte_eth_rx_burst(kni_stat[port_id]->port_id, 0, pkts_burst, count);
 
     if (nb_kni_rx > 0) {
         nb_rx = rte_eth_tx_burst(port_id, queue_id, pkts_burst, nb_kni_rx);
@@ -474,7 +374,7 @@ ff_kni_proto_filter(const void *data, uint16_t len, uint16_t eth_frame_type)
 }
 
 void
-ff_kni_init(uint16_t nb_ports, int type, const char *tcp_ports, const char *udp_ports)
+ff_kni_init(uint16_t nb_ports, const char *tcp_ports, const char *udp_ports)
 {
     if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
         kni_stat = rte_zmalloc("kni:stat",
@@ -483,12 +383,6 @@ ff_kni_init(uint16_t nb_ports, int type, const char *tcp_ports, const char *udp_
         if (kni_stat == NULL)
             rte_exit(EXIT_FAILURE, "rte_zmalloc(1 (struct netio_kni_stat *)) "
                 "failed\n");
-
-        if (type == KNI_TYPE_KNI) {
-#ifdef FF_KNI_KNI
-            rte_kni_init(nb_ports);
-#endif
-        }
     }
 
     uint16_t lcoreid = rte_lcore_id();
@@ -526,8 +420,8 @@ ff_kni_init(uint16_t nb_ports, int type, const char *tcp_ports, const char *udp_
 }
 
 void
-ff_kni_alloc(uint16_t port_id, unsigned socket_id, __rte_unused int type, int port_idx,
-    __rte_unused struct rte_mempool *mbuf_pool, unsigned ring_queue_size)
+ff_kni_alloc(uint16_t port_id, unsigned socket_id, int port_idx,
+    unsigned ring_queue_size)
 {
     if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
         struct rte_ether_addr addr = {{0}};
@@ -553,60 +447,27 @@ ff_kni_alloc(uint16_t port_id, unsigned socket_id, __rte_unused int type, int po
         printf("ff_kni_alloc get Port %u MAC:"RTE_ETHER_ADDR_PRT_FMT"\n",
             (unsigned)port_id, RTE_ETHER_ADDR_BYTES(&addr));
 
-#ifdef FF_KNI_KNI
-        if (type == KNI_TYPE_KNI) {
-            struct rte_kni_conf conf;
-            struct rte_kni_ops ops;
-
-            /* only support one kni */
-            memset(&conf, 0, sizeof(conf));
-            snprintf(conf.name, RTE_KNI_NAMESIZE, "veth%u", port_id);
-            conf.core_id = rte_lcore_id();
-            conf.force_bind = 1;
-            conf.group_id = port_id;
-            uint16_t mtu;
-            rte_eth_dev_get_mtu(port_id, &mtu);
-            conf.mbuf_size = mtu + KNI_ENET_HEADER_SIZE + KNI_ENET_FCS_SIZE;
-            rte_memcpy(&conf.addr, addr.addr_bytes, RTE_ETHER_ADDR_LEN);
-
-            memset(&ops, 0, sizeof(ops));
-            ops.port_id = port_id;
-            ops.change_mtu = kni_change_mtu;
-            ops.config_network_if = kni_config_network_interface;
-            ops.config_mac_address = kni_config_mac_address;
-
-            kni_stat[port_id]->kni = rte_kni_alloc(mbuf_pool, &conf, &ops);
-            if (kni_stat[port_id]->kni == NULL)
-                rte_panic("create kni on port %u failed!\n", port_id);
-            else
-                printf("create kni on port %u success!\n", port_id);
-
-            kni_stat[port_id]->port_id = port_id;
-        } else if (type == KNI_TYPE_VIRTIO)
-#endif
-        {
-            /*
-             * to add virtio port for exception path(KNI),
-             * see https://doc.dpdk.org/guides/howto/virtio_user_as_exception_path.html#virtio-user-as-exception-path
-             */
-            char port_name[32];
-            char port_args[256];
-
-            /* set the name and arguments */
-            snprintf(port_name, sizeof(port_name), "virtio_user%u", port_id);
-            snprintf(port_args, sizeof(port_args),
-                "path=/dev/vhost-net,queues=1,queue_size=%u,iface=veth%d,mac=" RTE_ETHER_ADDR_PRT_FMT,
-                ring_queue_size, port_id, RTE_ETHER_ADDR_BYTES(&addr));
-            printf("ff_kni_alloc to rte_eal_hotplug_add virtio user port, portname:%s, portargs:%s\n",
-                port_name, port_args);
-
-            /* add the vdev for virtio_user */
-            if (rte_eal_hotplug_add("vdev", port_name, port_args) < 0) {
-                rte_exit(EXIT_FAILURE, "ff_kni_alloc cannot create virtio user paired port for port %u\n", port_id);
-            }
-
-            kni_stat[port_id]->port_id = port_idx + nb_dev_ports;
+        /*
+         * to add virtio port for exception path(KNI),
+         * see https://doc.dpdk.org/guides/howto/virtio_user_as_exception_path.html#virtio-user-as-exception-path
+         */
+        char port_name[32];
+        char port_args[256];
+
+        /* set the name and arguments */
+        snprintf(port_name, sizeof(port_name), "virtio_user%u", port_id);
+        snprintf(port_args, sizeof(port_args),
+            "path=/dev/vhost-net,queues=1,queue_size=%u,iface=veth%d,mac=" RTE_ETHER_ADDR_PRT_FMT,
+            ring_queue_size, port_id, RTE_ETHER_ADDR_BYTES(&addr));
+        printf("ff_kni_alloc to rte_eal_hotplug_add virtio user port, portname:%s, portargs:%s\n",
+            port_name, port_args);
+
+        /* add the vdev for virtio_user */
+        if (rte_eal_hotplug_add("vdev", port_name, port_args) < 0) {
+            rte_exit(EXIT_FAILURE, "ff_kni_alloc cannot create virtio user paired port for port %u\n", port_id);
         }
+
+        kni_stat[port_id]->port_id = port_idx + nb_dev_ports;
     }
 
     char ring_name[RTE_KNI_NAMESIZE];
index 03169cfff8aba441b8c761f13ce09d4dfda93248..c3774b4660e259fbe0b012bb223d6c67176c2d56 100644 (file)
@@ -58,11 +58,11 @@ enum FilterReturn {
     FILTER_MULTI = 5,
 };
 
-void ff_kni_init(uint16_t nb_ports, int type, const char *tcp_ports,
+void ff_kni_init(uint16_t nb_ports, const char *tcp_ports,
     const char *udp_ports);
 
-void ff_kni_alloc(uint16_t port_id, unsigned socket_id, int type, int port_idx,
-    struct rte_mempool *mbuf_pool, unsigned ring_queue_size);
+void ff_kni_alloc(uint16_t port_id, unsigned socket_id, int port_idx,
+    unsigned ring_queue_size);
 
 void ff_kni_process(uint16_t port_id, uint16_t queue_id,
     struct rte_mbuf **pkts_burst, unsigned count);