From 81721b68ac5010e228de43d83ae7c87e8e51f95e Mon Sep 17 00:00:00 2001 From: whl739 Date: Thu, 21 Jun 2018 17:39:17 +0800 Subject: [PATCH] F-Stack: disable kni module by default. This commit adds a macro `FF_KNI` to determine whether to enable kni. In Makefile, uncomment the `FF_KNI=1`, kni will be compiled into f-stack. --- lib/Makefile | 17 ++++++++++++++--- lib/ff_dpdk_if.c | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 8166ba72..a4ff03a3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -16,7 +16,10 @@ OVERRIDE_INCLUDES_ROOT:=${CURDIR}/include X86_INCLUDES=0 HOST_OS:=$(shell uname -s) -#DEBUG=-O0 -gdwarf-2 -g3 + +#DEBUG=-O0 -gdwarf-2 -g3 -Wno-format-truncation + +#FF_KNI=1 #FF_NETGRAPH=1 #FF_IPFW=1 @@ -40,11 +43,15 @@ INCLUDES+= -I./opt # Include search path for files that only include host OS headers HOST_INCLUDES= -I. ifndef DEBUG -HOST_CFLAGS = -O2 -frename-registers -funswitch-loops -fweb +HOST_CFLAGS = -O2 -frename-registers -funswitch-loops -fweb -Wno-format-truncation else HOST_CFLAGS = ${DEBUG} endif +ifdef FF_KNI +HOST_CFLAGS+= -DFF_KNI +endif + HOST_CFLAGS+= ${DPDK_CFLAGS} HOST_CFLAGS+= ${CONF_CFLAGS} @@ -165,11 +172,15 @@ FF_HOST_SRCS+= \ ff_config.c \ ff_ini_parser.c \ ff_dpdk_if.c \ - ff_dpdk_kni.c \ ff_dpdk_pcap.c \ ff_epoll.c \ ff_init.c +ifdef FF_KNI +FF_HOST_SRCS+= \ + ff_dpdk_kni.c +endif + ifdef FF_IPSEC CRYPTO_ASM_SRCS+= \ aesencdec_${MACHINE_CPUARCH}.S \ diff --git a/lib/ff_dpdk_if.c b/lib/ff_dpdk_if.c index 66152d44..1e7d8e7c 100644 --- a/lib/ff_dpdk_if.c +++ b/lib/ff_dpdk_if.c @@ -91,8 +91,10 @@ #define KNI_MBUF_MAX 2048 #define KNI_QUEUE_SIZE 2048 +#ifdef FF_KNI static int enable_kni; static int kni_accept; +#endif static int numa_on; @@ -520,6 +522,7 @@ init_msg_ring(void) return 0; } +#ifdef FF_KNI static int init_kni(void) { @@ -543,6 +546,7 @@ init_kni(void) return 0; } +#endif static void set_rss_table(uint16_t port_id, uint16_t reta_size, uint16_t nb_queues) @@ -820,10 +824,12 @@ ff_dpdk_init(int argc, char **argv) init_msg_ring(); +#ifdef FF_KNI enable_kni = ff_global_cfg.kni.enable; if (enable_kni) { init_kni(); } +#endif ret = init_port_start(); if (ret < 0) { @@ -891,6 +897,9 @@ protocol_filter(const void *data, uint16_t len) if(ntohs(hdr->ether_type) == ETHER_TYPE_ARP) return FILTER_ARP; +#ifndef FF_KNI + return FILTER_UNKNOWN; +#else if (!enable_kni) { return FILTER_UNKNOWN; } @@ -900,6 +909,7 @@ protocol_filter(const void *data, uint16_t len) return ff_kni_proto_filter(data + ETHER_HDR_LEN, len - ETHER_HDR_LEN); +#endif } static inline void @@ -1024,6 +1034,7 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs, } } +#ifdef FF_KNI if (enable_kni && rte_eal_process_type() == RTE_PROC_PRIMARY) { mbuf_pool = pktmbuf_pool[qconf->socket_id]; mbuf_clone = pktmbuf_deep_clone(rtem, mbuf_pool); @@ -1031,12 +1042,14 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs, ff_kni_enqueue(port_id, mbuf_clone); } } - +#endif ff_veth_input(ctx, rtem); +#ifdef FF_KNI } else if (enable_kni && ((filter == FILTER_KNI && kni_accept) || (filter == FILTER_UNKNOWN && !kni_accept)) ) { ff_kni_enqueue(port_id, rtem); +#endif } else { ff_veth_input(ctx, rtem); } @@ -1443,9 +1456,11 @@ main_loop(void *arg) queue_id = qconf->rx_queue_list[i].queue_id; ctx = veth_ctx[port_id]; +#ifdef FF_KNI if (enable_kni && rte_eal_process_type() == RTE_PROC_PRIMARY) { ff_kni_process(port_id, queue_id, pkts_burst, MAX_PKT_BURST); } +#endif process_dispatch_ring(port_id, queue_id, pkts_burst, ctx);