Skip to content

Commit 4e65d71

Browse files
authored
Merge pull request #1041 from jinliu777/1.21
sync PR#1029
2 parents d4d24b4 + 494c08e commit 4e65d71

2 files changed

Lines changed: 67 additions & 4 deletions

File tree

lib/ff_api.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,48 @@ int ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag,
212212
typedef int (*dispatch_func_t)(void *data, uint16_t *len,
213213
uint16_t queue_id, uint16_t nb_queues);
214214

215+
/*
216+
* Packet dispatcher context structure.
217+
* Contains additional context information for packet dispatching.
218+
*/
219+
struct ff_dispatcher_context {
220+
struct {
221+
uint8_t stripped;
222+
uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */
223+
} vlan;
224+
};
225+
226+
/*
227+
* Enhanced packet dispatch callback function with context.
228+
* Implemented by user.
229+
*
230+
* @param data
231+
* The data pointer of this packet.
232+
* @param len
233+
* The length of this packet.
234+
* @param queue_id
235+
* Current queue of this packet.
236+
* @param nb_queues
237+
* Number of queues to be dispatched.
238+
* @param context
239+
* Additional context information for packet dispatching.
240+
*
241+
* @return 0 to (nb_queues - 1)
242+
* The queue id that the packet will be dispatched to.
243+
* @return FF_DISPATCH_ERROR (-1)
244+
* Error occurs or packet is handled by user, packet will be freed.
245+
* @return FF_DISPATCH_RESPONSE (-2)
246+
* Packet is handled by user, packet will be responsed.
247+
*/
248+
typedef int (*dispatch_func_context_t)(void *data, uint16_t *len,
249+
uint16_t queue_id, uint16_t nb_queues, struct ff_dispatcher_context context);
250+
215251
/* regist a packet dispath function */
216252
void ff_regist_packet_dispatcher(dispatch_func_t func);
217253

254+
/* Register a packet dispatch function with context support */
255+
void ff_regist_packet_dispatcher_context(dispatch_func_context_t func);
256+
218257
/*
219258
* RAW packet send direty with DPDK by user APP.
220259
*

lib/ff_dpdk_if.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static pcblddr_func_t pcblddr_fun;
125125

126126
static struct rte_ring **dispatch_ring[RTE_MAX_ETHPORTS];
127127
static dispatch_func_t packet_dispatcher;
128+
static dispatch_func_context_t packet_dispatcher_with_context;
128129

129130
static uint16_t rss_reta_size[RTE_MAX_ETHPORTS];
130131

@@ -1662,10 +1663,27 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs,
16621663
ff_traffic.rx_bytes += rte_pktmbuf_pkt_len(rtem);
16631664
}
16641665

1665-
if (!pkts_from_ring && packet_dispatcher) {
1666-
uint64_t cur_tsc = rte_rdtsc();
1667-
int ret = (*packet_dispatcher)(data, &len, queue_id, nb_queues);
1668-
usr_cb_tsc += rte_rdtsc() - cur_tsc;
1666+
if (!pkts_from_ring && (packet_dispatcher || packet_dispatcher_with_context)) {
1667+
uint64_t cur_tsc;
1668+
int ret;
1669+
if (packet_dispatcher) {
1670+
cur_tsc = rte_rdtsc();
1671+
ret = (*packet_dispatcher)(data, &len, queue_id, nb_queues);
1672+
usr_cb_tsc += rte_rdtsc() - cur_tsc;
1673+
} else if (packet_dispatcher_with_context) {
1674+
struct ff_dispatcher_context ctx;
1675+
if (rtem->ol_flags & RTE_MBUF_F_RX_VLAN_STRIPPED) {
1676+
ctx.vlan.stripped = 1;
1677+
ctx.vlan.vlan_tci = rte_cpu_to_be_16(rtem->vlan_tci);
1678+
} else {
1679+
ctx.vlan.stripped = 0;
1680+
ctx.vlan.vlan_tci = 0;
1681+
}
1682+
cur_tsc = rte_rdtsc();
1683+
ret = (*packet_dispatcher_with_context)(data, &len, queue_id, nb_queues, ctx);
1684+
usr_cb_tsc += rte_rdtsc() - cur_tsc;
1685+
}
1686+
16691687
if (ret == FF_DISPATCH_RESPONSE) {
16701688
rte_pktmbuf_pkt_len(rtem) = rte_pktmbuf_data_len(rtem) = len;
16711689
/*
@@ -2818,6 +2836,12 @@ ff_regist_packet_dispatcher(dispatch_func_t func)
28182836
packet_dispatcher = func;
28192837
}
28202838

2839+
void
2840+
ff_regist_packet_dispatcher_context(dispatch_func_context_t func)
2841+
{
2842+
packet_dispatcher_with_context = func;
2843+
}
2844+
28212845
uint64_t
28222846
ff_get_tsc_ns()
28232847
{

0 commit comments

Comments
 (0)