Fix kni bug.

BUG:
When set config.ini:
[kni]
enable=1
method=reject
tcp_port=80

Packets that not belond to tcp port 80 will not be transmitted to kernel.
dev
logwang 2017-05-02 18:05:26 +08:00
parent 3fc788461b
commit f47e38d9dd
3 changed files with 29 additions and 26 deletions

View File

@ -82,7 +82,8 @@
#define BITS_PER_HEX 4
static int enable_kni = 0;
static int enable_kni;
static int kni_accept;
static struct rte_timer freebsd_clock;
@ -493,14 +494,12 @@ static int
init_kni(void)
{
int nb_ports = rte_eth_dev_count();
int accept = 0;
kni_accept = 0;
if(strcasecmp(ff_global_cfg.kni.method, "accept") == 0)
accept = 1;
kni_accept = 1;
ff_kni_init(nb_ports,
ff_global_cfg.kni.tcp_port,
ff_global_cfg.kni.udp_port,
accept);
ff_kni_init(nb_ports, ff_global_cfg.kni.tcp_port,
ff_global_cfg.kni.udp_port);
unsigned socket_id = lcore_conf.socket_id;
struct rte_mempool *mbuf_pool = pktmbuf_pool[socket_id];
@ -738,11 +737,7 @@ process_packets(uint8_t port_id, uint16_t queue_id, struct rte_mbuf **bufs,
uint16_t len = rte_pktmbuf_data_len(rtem);
enum FilterReturn filter = protocol_filter(data, len);
if (filter == FILTER_UNKNOWN) {
ff_veth_input(ifp, rtem);
} else if (filter == FILTER_KNI) {
ff_kni_enqueue(port_id, rtem);
} else {
if (filter == FILTER_ARP) {
struct rte_mempool *mbuf_pool;
struct rte_mbuf *mbuf_clone;
if (pkts_from_ring == 0) {
@ -769,6 +764,11 @@ process_packets(uint8_t port_id, uint16_t queue_id, struct rte_mbuf **bufs,
}
}
ff_veth_input(ifp, rtem);
} else if (enable_kni && ((filter == FILTER_KNI && kni_accept) ||
(filter == FILTER_UNKNOWN && !kni_accept)) ) {
ff_kni_enqueue(port_id, rtem);
} else {
ff_veth_input(ifp, rtem);
}
}

View File

@ -61,8 +61,6 @@ static const int magic_bits[8] = {
static unsigned char *udp_port_bitmap = NULL;
static unsigned char *tcp_port_bitmap = NULL;
static int kni_accept = 0;
/* Structure type for recording kni interface specific stats */
struct kni_interface_stats {
struct rte_kni *kni;
@ -134,7 +132,7 @@ kni_change_mtu(uint8_t port_id, unsigned new_mtu)
static int
kni_config_network_interface(uint8_t port_id, uint8_t if_up)
{
{
int ret = 0;
if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
@ -149,9 +147,21 @@ kni_config_network_interface(uint8_t port_id, uint8_t if_up)
rte_eth_dev_set_link_up(port_id) :
rte_eth_dev_set_link_down(port_id);
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");
port_id, if_up ? "up" : "down");
return ret;
}
@ -210,13 +220,7 @@ static enum FilterReturn
protocol_filter_l4(uint16_t port, unsigned char *bitmap)
{
if(get_bitmap(port, bitmap)) {
if (kni_accept) {
return FILTER_KNI;
}
} else {
if (!kni_accept) {
return FILTER_KNI;
}
return FILTER_KNI;
}
return FILTER_UNKNOWN;
@ -277,8 +281,7 @@ ff_kni_proto_filter(const void *data, uint16_t len)
}
void
ff_kni_init(uint16_t nb_ports, const char *tcp_ports,
const char *udp_ports, int accept)
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",

View File

@ -38,7 +38,7 @@ enum FilterReturn {
};
void ff_kni_init(uint16_t nb_ports, const char *tcp_ports,
const char *udp_ports, int accept);
const char *udp_ports);
void ff_kni_alloc(uint8_t port_id, unsigned socket_id,
struct rte_mempool *mbuf_pool);