Skip to content

Commit b211126

Browse files
committed
add an API ff_regist_packet_dispatcher_context that allows to pass more context to callback
1 parent 930bdd0 commit b211126

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

lib/ff_api.h

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

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

261+
/* Register a packet dispatch function with context support */
262+
void ff_regist_packet_dispatcher_context(dispatch_func_context_t func);
263+
225264
/*
226265
* RAW packet send direty with DPDK by user APP.
227266
*

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

@@ -1614,10 +1615,27 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs,
16141615
ff_traffic.rx_bytes += rte_pktmbuf_pkt_len(rtem);
16151616
}
16161617

1617-
if (!pkts_from_ring && packet_dispatcher) {
1618-
uint64_t cur_tsc = rte_rdtsc();
1619-
int ret = (*packet_dispatcher)(data, &len, queue_id, nb_queues);
1620-
usr_cb_tsc += rte_rdtsc() - cur_tsc;
1618+
if (!pkts_from_ring && (packet_dispatcher || packet_dispatcher_with_context)) {
1619+
uint64_t cur_tsc;
1620+
int ret;
1621+
if (packet_dispatcher) {
1622+
cur_tsc = rte_rdtsc();
1623+
ret = (*packet_dispatcher)(data, &len, queue_id, nb_queues);
1624+
usr_cb_tsc += rte_rdtsc() - cur_tsc;
1625+
} else if (packet_dispatcher_with_context) {
1626+
struct ff_dispatcher_context ctx;
1627+
if (rtem->ol_flags & RTE_MBUF_F_RX_VLAN_STRIPPED) {
1628+
ctx.vlan.stripped = 1;
1629+
ctx.vlan.vlan_tci = rte_cpu_to_be_16(rtem->vlan_tci);
1630+
} else {
1631+
ctx.vlan.stripped = 0;
1632+
ctx.vlan.vlan_tci = 0;
1633+
}
1634+
cur_tsc = rte_rdtsc();
1635+
ret = (*packet_dispatcher_with_context)(data, &len, queue_id, nb_queues, ctx);
1636+
usr_cb_tsc += rte_rdtsc() - cur_tsc;
1637+
}
1638+
16211639
if (ret == FF_DISPATCH_RESPONSE) {
16221640
rte_pktmbuf_pkt_len(rtem) = rte_pktmbuf_data_len(rtem) = len;
16231641
/*
@@ -2772,6 +2790,12 @@ ff_regist_packet_dispatcher(dispatch_func_t func)
27722790
packet_dispatcher = func;
27732791
}
27742792

2793+
void
2794+
ff_regist_packet_dispatcher_context(dispatch_func_context_t func)
2795+
{
2796+
packet_dispatcher_with_context = func;
2797+
}
2798+
27752799
uint64_t
27762800
ff_get_tsc_ns()
27772801
{

0 commit comments

Comments
 (0)