From ee6c3aa356275838f6fc3d11b6ed28facc99d0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fengbojiang=28=E5=A7=9C=E5=87=A4=E6=B3=A2=29?= Date: Fri, 8 Mar 2019 15:12:57 +0800 Subject: [PATCH] modify packet_dispatcher to support response package direct. --- lib/ff_api.h | 4 +++- lib/ff_dpdk_if.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ff_api.h b/lib/ff_api.h index 9f518bf1..be80b762 100644 --- a/lib/ff_api.h +++ b/lib/ff_api.h @@ -144,6 +144,8 @@ int ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag, /* dispatch api begin */ +#define FF_DISPATCH_ERROR (-1) +#define FF_DISPATCH_RESPONSE (-2) /* * Packet dispatch callback function. @@ -164,7 +166,7 @@ int ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag, * Error occurs or packet is handled by user, packet will be freed. * */ -typedef int (*dispatch_func_t)(void *data, uint16_t len, +typedef int (*dispatch_func_t)(void *data, uint16_t *len, uint16_t queue_id, uint16_t nb_queues); /* regist a packet dispath function */ diff --git a/lib/ff_dpdk_if.c b/lib/ff_dpdk_if.c index 21e13074..6b136a7f 100644 --- a/lib/ff_dpdk_if.c +++ b/lib/ff_dpdk_if.c @@ -172,6 +172,8 @@ static dispatch_func_t packet_dispatcher; static uint16_t rss_reta_size[RTE_MAX_ETHPORTS]; +static inline int send_single_packet(struct rte_mbuf *m, uint8_t port); + struct ff_msg_ring { char ring_name[2][RTE_RING_NAMESIZE]; /* ring[0] for lcore recv msg, other send */ @@ -1011,8 +1013,14 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs, } if (!pkts_from_ring && packet_dispatcher) { - int ret = (*packet_dispatcher)(data, len, queue_id, nb_queues); - if (ret < 0 || ret >= nb_queues) { + int ret = (*packet_dispatcher)(data, &len, queue_id, nb_queues); + if (ret == FF_DISPATCH_RESPONSE) { + rte_pktmbuf_pkt_len(rtem) = rte_pktmbuf_data_len(rtem) = len; + send_single_packet(rtem, port_id); + continue; + } + + if (ret == FF_DISPATCH_ERROR || ret >= nb_queues) { rte_pktmbuf_free(rtem); continue; }