Skip to content

Commit

Permalink
Merge pull request #709 from weiyanhua100/icmp-bug-0127
Browse files Browse the repository at this point in the history
  • Loading branch information
ywc689 authored Mar 31, 2021
2 parents 64c4ec2 + 182ffcf commit e9eb922
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 4 deletions.
1 change: 1 addition & 0 deletions conf/dpvs.bond.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ worker_defs {
<init> worker cpu8 {
type slave
cpu_id 8
icmp_redirect_core
port bond0 {
rx_queue_ids 7
tx_queue_ids 7
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.items
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ worker_defs {
<init> worker cpu5 {
type kni
cpu_id 5
icmp_redirect_core
port dpdk0 {
tx_queue_ids 6
}
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ worker_defs {
<init> worker cpu8 {
type slave
cpu_id 8
icmp_redirect_core
port dpdk0 {
rx_queue_ids 7
tx_queue_ids 7
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.single-bond.sample
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ worker_defs {
<init> worker cpu8 {
type slave
cpu_id 8
icmp_redirect_core
port bond0 {
rx_queue_ids 7
tx_queue_ids 7
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.single-nic.sample
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ worker_defs {
<init> worker cpu8 {
type slave
cpu_id 8
icmp_redirect_core
port dpdk0 {
rx_queue_ids 7
tx_queue_ids 7
Expand Down
5 changes: 5 additions & 0 deletions include/icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ void icmp_send(struct rte_mbuf *imbuf, int type, int code, uint32_t info);

#define icmp4_id(icmph) (((icmph)->un).echo.id)

#ifdef CONFIG_ICMP_REDIRECT_CORE
int icmp_recv_proc(struct rte_mbuf *mbuf);
void icmp_redirect_proc(void *args);
extern lcoreid_t g_icmp_redirect_lcore_id;
#endif
#endif /* __DPVS_ICMP_H__ */
1 change: 1 addition & 0 deletions include/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ int ip4_defrag(struct rte_mbuf *mbuf, int user);

uint32_t ip4_select_id(struct ipv4_hdr *iph);
int ipv4_local_out(struct rte_mbuf *mbuf);
int ipv4_rcv_fin(struct rte_mbuf *mbuf);

/* helper functions */
static inline struct ipv4_hdr *ip4_hdr(const struct rte_mbuf *mbuf)
Expand Down
2 changes: 1 addition & 1 deletion include/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ int netif_ctrl_term(void); /* netif ctrl plane cleanup */
void netif_cfgfile_init(void);
void netif_keyword_value_init(void);
void install_netif_keywords(void);

void kni_ingress(struct rte_mbuf *mbuf, struct netif_port *dev);

static inline void *netif_priv(struct netif_port *dev)
{
Expand Down
1 change: 1 addition & 0 deletions src/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CFLAGS += -D DPVS_MAX_LCORE=64
#CFLAGS += -D CONFIG_NDISC_DEBUG
#CFLAGS += -D CONFIG_MSG_DEBUG
#CFLAGS += -D CONFIG_DPVS_MP_DEBUG
#CFLAGS += -D CONFIG_ICMP_REDIRECT_CORE

ifeq ($(CONFIG_PDUMP), y)
CFLAGS += -D CONFIG_DPVS_PDUMP
Expand Down
108 changes: 108 additions & 0 deletions src/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include "icmp.h"
#include "netinet/in.h"
#include "netinet/ip_icmp.h"
#ifdef CONFIG_ICMP_REDIRECT_CORE
#include "netif.h"
#include "scheduler.h"
#include "global_data.h"
#endif

#define ICMP
#define RTE_LOGTYPE_ICMP RTE_LOGTYPE_USER1
Expand Down Expand Up @@ -318,10 +323,113 @@ static struct inet_protocol icmp_protocol = {
.handler = icmp_rcv,
};

#ifdef CONFIG_ICMP_REDIRECT_CORE
static struct rte_ring *icmp_redirect_ring;
#define ICMP_RING_SIZE 2048
lcoreid_t g_icmp_redirect_lcore_id = 0;

static struct dpvs_lcore_job icmp_redirect = {
.name = "icmp_redirect_proc",
.type = LCORE_JOB_LOOP,
.func = icmp_redirect_proc,
.data = NULL,
};

static int icmp_redirect_init(void)
{
int ret = 0;
int socket_id;

socket_id = rte_socket_id();
icmp_redirect_ring = rte_ring_create("icmp_redirect_ring", ICMP_RING_SIZE, socket_id, RING_F_SC_DEQ);
if (icmp_redirect_ring == NULL) {
rte_panic("create ring:icmp_redirect_ring failed!\n");
return EDPVS_NOMEM;
}

ret = dpvs_lcore_job_register(&icmp_redirect, LCORE_ROLE_FWD_WORKER);
if (ret < 0) {
rte_ring_free(icmp_redirect_ring);
return ret;
}

return EDPVS_OK;
}

int icmp_recv_proc(struct rte_mbuf *mbuf)
{
int ret = 0;
ret = rte_ring_enqueue(icmp_redirect_ring, mbuf);
if (unlikely(-EDQUOT == ret)) {
RTE_LOG(WARNING, ICMP, "%s: icmp ring quota exceeded\n", __func__);
}
else if (ret < 0) {
RTE_LOG(WARNING, ICMP, "%s: icmp ring enqueue failed\n", __func__);
rte_pktmbuf_free(mbuf);
}

return 0;
}

void icmp_redirect_proc(void *args)
{
int ret = 0;
int i = 0;
lcoreid_t cid;
struct rte_mbuf *mbufs[NETIF_MAX_PKT_BURST];
uint16_t nb_rb = 0;
uint16_t data_off;

cid = rte_lcore_id();
if (cid != g_icmp_redirect_lcore_id)
return;

nb_rb = rte_ring_dequeue_burst(icmp_redirect_ring, (void**)mbufs, NETIF_MAX_PKT_BURST, NULL);
if (nb_rb <= 0) {
return;
}

for (i = 0; i < nb_rb; i++) {
struct rte_mbuf *mbuf = mbufs[i];
struct netif_port *dev = netif_port_get(mbuf->port);

/* Remove ether_hdr at the beginning of an mbuf */
data_off = mbuf->data_off;
if (unlikely(NULL == rte_pktmbuf_adj(mbuf, sizeof(struct ether_hdr)))) {
rte_pktmbuf_free(mbuf);
return;
}

ret = INET_HOOK(AF_INET, INET_HOOK_PRE_ROUTING,
mbuf, dev, NULL, ipv4_rcv_fin);
if (ret == EDPVS_KNICONTINUE) {
if (dev->flag & NETIF_PORT_FLAG_FORWARD2KNI) {
rte_pktmbuf_free(mbuf);
return;
}
if (likely(NULL != rte_pktmbuf_prepend(mbuf,
(mbuf->data_off - data_off)))) {
kni_ingress(mbuf, dev);
} else {
rte_pktmbuf_free(mbuf);
}
}
}

return;
}
#endif

int icmp_init(void)
{
int err;

#ifdef CONFIG_ICMP_REDIRECT_CORE
err = icmp_redirect_init();
if (err)
return err;
#endif

err = ipv4_register_protocol(&icmp_protocol, IPPROTO_ICMP);

return err;
Expand Down
17 changes: 16 additions & 1 deletion src/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static int ip4_rcv_options(struct rte_mbuf *mbuf)
return EDPVS_OK;
}

static int ipv4_rcv_fin(struct rte_mbuf *mbuf)
int ipv4_rcv_fin(struct rte_mbuf *mbuf)
{
int err;
struct route_entry *rt = NULL;
Expand Down Expand Up @@ -378,6 +378,9 @@ static int ipv4_rcv_fin(struct rte_mbuf *mbuf)

static int ipv4_rcv(struct rte_mbuf *mbuf, struct netif_port *port)
{
#ifdef CONFIG_ICMP_REDIRECT_CORE
struct icmphdr *ich, _icmph;
#endif
struct ipv4_hdr *iph;
uint16_t hlen, len;
eth_type_t etype = mbuf->packet_type; /* FIXME: use other field ? */
Expand Down Expand Up @@ -430,6 +433,18 @@ static int ipv4_rcv(struct rte_mbuf *mbuf, struct netif_port *port)

if (unlikely(iph->next_proto_id == IPPROTO_OSPF))
return EDPVS_KNICONTINUE;
#ifdef CONFIG_ICMP_REDIRECT_CORE
else if (unlikely(iph->next_proto_id == IPPROTO_ICMP)) {
ich = mbuf_header_pointer(mbuf, hlen, sizeof(_icmph), &_icmph);
if (unlikely(!ich))
goto drop;
if (ich->type == ICMP_ECHOREPLY || ich->type == ICMP_ECHO) {
rte_pktmbuf_prepend(mbuf, (uint16_t)sizeof(struct ether_hdr));
icmp_recv_proc(mbuf);
return EDPVS_OK;
}
}
#endif

return INET_HOOK(AF_INET, INET_HOOK_PRE_ROUTING,
mbuf, port, NULL, ipv4_rcv_fin);
Expand Down
21 changes: 19 additions & 2 deletions src/netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ipvs/redirect.h>
#ifdef CONFIG_ICMP_REDIRECT_CORE
#include "icmp.h"
#endif

#define NETIF_PKTPOOL_NB_MBUF_DEF 65535
#define NETIF_PKTPOOL_NB_MBUF_MIN 1023
Expand Down Expand Up @@ -145,7 +148,6 @@ static struct list_head port_ntab[NETIF_PORT_TABLE_BUCKETS]; /* hashed by name *
#define NETIF_CTRL_BUFFER_LEN 4096

/* function declarations */
static void kni_ingress(struct rte_mbuf *mbuf, struct netif_port *dev);
static void kni_lcore_loop(void *dummy);


Expand Down Expand Up @@ -734,6 +736,18 @@ static void cpu_id_handler(vector_t tokens)
FREE_PTR(str);
}

#ifdef CONFIG_ICMP_REDIRECT_CORE
static void cpu_icmp_redirect_handler(vector_t tokens)
{
struct worker_conf_stream *current_worker = list_entry(worker_list.next,
struct worker_conf_stream, worker_list_node);

RTE_LOG(INFO, NETIF, "%s(%d) used to redirect icmp packets\n",
current_worker->name, current_worker->cpu_id);
g_icmp_redirect_lcore_id = current_worker->cpu_id;
}
#endif

static void worker_port_handler(vector_t tokens)
{
assert(VECTOR_SIZE(tokens) >= 1);
Expand Down Expand Up @@ -918,6 +932,9 @@ void install_netif_keywords(void)
install_sublevel();
install_keyword("type", worker_type_handler, KW_TYPE_INIT);
install_keyword("cpu_id", cpu_id_handler, KW_TYPE_INIT);
#ifdef CONFIG_ICMP_REDIRECT_CORE
install_keyword("icmp_redirect_core", cpu_icmp_redirect_handler, KW_TYPE_INIT);
#endif
install_keyword("port", worker_port_handler, KW_TYPE_INIT);
install_sublevel();
install_keyword("rx_queue_ids", rx_queue_ids_handler, KW_TYPE_INIT);
Expand Down Expand Up @@ -2691,7 +2708,7 @@ static inline void free_mbufs(struct rte_mbuf **pkts, unsigned num)
}
}

static void kni_ingress(struct rte_mbuf *mbuf, struct netif_port *dev)
void kni_ingress(struct rte_mbuf *mbuf, struct netif_port *dev)
{
if (!kni_dev_exist(dev))
goto freepkt;
Expand Down

0 comments on commit e9eb922

Please sign in to comment.