From a32eaa3d00beef6bb81e2aadc2088e9a937d1fd0 Mon Sep 17 00:00:00 2001 From: Konstantin Ananyev Date: Thu, 3 Jun 2021 17:38:38 +0000 Subject: l4p: add ability to assign user-data to the stream Add ability for the user to assign user provided data to the stream. Right now this user provided 64-bit value is passed as a parameter for lookup4/lookup6 callbacks. Another change: change interpretation of lookup4()/lookup6() return value: < 0: error code (existing behaviour). == 0: success, TLDK will update L3 header src/dst addresses based on tldk dev values (existing behaviour). > 0: success, TLDK will not update L3 header src/dst addresses, will rely on user provided values. Signed-off-by: Konstantin Ananyev Change-Id: I32521422e0372d79c4b2781dd6fc9740e4ca93ab --- app/nginx/src/tldk/be.c | 8 ++++---- app/nginx/src/tldk/be.h | 4 ++-- examples/l4fwd/lcore.h | 8 ++++---- lib/libtle_l4p/stream.h | 30 +++++++++++++++++------------- lib/libtle_l4p/tcp_stream.c | 3 +++ lib/libtle_l4p/tle_ctx.h | 8 ++++---- lib/libtle_l4p/tle_tcp.h | 2 ++ test/gtest/test_common.cpp | 8 ++++++-- test/gtest/test_common.h | 6 ++++-- test/gtest/test_tle_udp_stream_gen.h | 7 ++++--- 10 files changed, 50 insertions(+), 34 deletions(-) diff --git a/app/nginx/src/tldk/be.c b/app/nginx/src/tldk/be.c index b226c26..1309aa4 100644 --- a/app/nginx/src/tldk/be.c +++ b/app/nginx/src/tldk/be.c @@ -122,8 +122,8 @@ be_lcore_lpm_init(struct tldk_ctx *tcx, uint32_t sid, } int -be_lpm4_dst_lookup(void *data, const struct in_addr *addr, - struct tle_dest *res) +be_lpm4_dst_lookup(void *data, __rte_unused uint64_t sdata, + const struct in_addr *addr, struct tle_dest *res) { int32_t rc; uint32_t idx; @@ -142,8 +142,8 @@ be_lpm4_dst_lookup(void *data, const struct in_addr *addr, } int -be_lpm6_dst_lookup(void *data, const struct in6_addr *addr, - struct tle_dest *res) +be_lpm6_dst_lookup(void *data, __rte_unused uint64_t sdata, + const struct in6_addr *addr, struct tle_dest *res) { int32_t rc; struct tldk_ctx *tcx; diff --git a/app/nginx/src/tldk/be.h b/app/nginx/src/tldk/be.h index 900dfa8..035a698 100644 --- a/app/nginx/src/tldk/be.h +++ b/app/nginx/src/tldk/be.h @@ -31,9 +31,9 @@ extern volatile int force_quit; -int be_lpm4_dst_lookup(void *data, const struct in_addr *addr, +int be_lpm4_dst_lookup(void *data, uint64_t sdata, const struct in_addr *addr, struct tle_dest *res); -int be_lpm6_dst_lookup(void *data, const struct in6_addr *addr, +int be_lpm6_dst_lookup(void *data, uint64_t sdata, const struct in6_addr *addr, struct tle_dest *res); int be_lcore_lpm_init(struct tldk_ctx *tcx, uint32_t sid, const struct tldk_ctx_conf *cf); diff --git a/examples/l4fwd/lcore.h b/examples/l4fwd/lcore.h index ac2fbbd..8d69c4f 100644 --- a/examples/l4fwd/lcore.h +++ b/examples/l4fwd/lcore.h @@ -24,8 +24,8 @@ * IPv4 destination lookup callback. */ static int -lpm4_dst_lookup(void *data, const struct in_addr *addr, - struct tle_dest *res) +lpm4_dst_lookup(void *data, __rte_unused uint64_t sdata, + const struct in_addr *addr, struct tle_dest *res) { int32_t rc; uint32_t idx; @@ -47,8 +47,8 @@ lpm4_dst_lookup(void *data, const struct in_addr *addr, * IPv6 destination lookup callback. */ static int -lpm6_dst_lookup(void *data, const struct in6_addr *addr, - struct tle_dest *res) +lpm6_dst_lookup(void *data, __rte_unused uint64_t sdata, + const struct in6_addr *addr, struct tle_dest *res) { int32_t rc; dpdk_lpm6_idx_t idx; diff --git a/lib/libtle_l4p/stream.h b/lib/libtle_l4p/stream.h index ebefa6c..405f662 100644 --- a/lib/libtle_l4p/stream.h +++ b/lib/libtle_l4p/stream.h @@ -33,6 +33,8 @@ struct tle_stream { uint8_t type; /* TLE_V4 or TLE_V6 */ + uint64_t udata; /* user data associated wih the stream */ + /* Stream address information. */ union l4_ports port; union l4_ports pmsk; @@ -137,10 +139,10 @@ stream_get_dest(struct tle_stream *s, const void *dst_addr, if (s->type == TLE_V4) { d4 = dst_addr; - rc = ctx->prm.lookup4(ctx->prm.lookup4_data, d4, dst); + rc = ctx->prm.lookup4(ctx->prm.lookup4_data, s->udata, d4, dst); } else if (s->type == TLE_V6) { d6 = dst_addr; - rc = ctx->prm.lookup6(ctx->prm.lookup6_data, d6, dst); + rc = ctx->prm.lookup6(ctx->prm.lookup6_data, s->udata, d6, dst); } else rc = -ENOENT; @@ -150,17 +152,19 @@ stream_get_dest(struct tle_stream *s, const void *dst_addr, dev = dst->dev; dst->ol_flags = dev->tx.ol_flags[s->type]; - if (s->type == TLE_V4) { - struct rte_ipv4_hdr *l3h; - l3h = (struct rte_ipv4_hdr *)(dst->hdr + dst->l2_len); - l3h->src_addr = dev->prm.local_addr4.s_addr; - l3h->dst_addr = d4->s_addr; - } else { - struct rte_ipv6_hdr *l3h; - l3h = (struct rte_ipv6_hdr *)(dst->hdr + dst->l2_len); - rte_memcpy(l3h->src_addr, &dev->prm.local_addr6, - sizeof(l3h->src_addr)); - rte_memcpy(l3h->dst_addr, d6, sizeof(l3h->dst_addr)); + if (rc == 0) { + if (s->type == TLE_V4) { + struct rte_ipv4_hdr *l3h; + l3h = (struct rte_ipv4_hdr *)(dst->hdr + dst->l2_len); + l3h->src_addr = dev->prm.local_addr4.s_addr; + l3h->dst_addr = d4->s_addr; + } else { + struct rte_ipv6_hdr *l3h; + l3h = (struct rte_ipv6_hdr *)(dst->hdr + dst->l2_len); + rte_memcpy(l3h->src_addr, &dev->prm.local_addr6, + sizeof(l3h->src_addr)); + rte_memcpy(l3h->dst_addr, d6, sizeof(l3h->dst_addr)); + } } return dev - ctx->dev; diff --git a/lib/libtle_l4p/tcp_stream.c b/lib/libtle_l4p/tcp_stream.c index c1a007a..dbed84e 100644 --- a/lib/libtle_l4p/tcp_stream.c +++ b/lib/libtle_l4p/tcp_stream.c @@ -381,6 +381,8 @@ tcp_stream_fill_cfg(struct tle_tcp_stream *s, const struct tle_ctx_param *cprm, cprm->icw; s->tcb.snd.rto_tw = (cprm->timewait == TLE_TCP_TIMEWAIT_DEFAULT) ? TCP_RTO_2MSL : cprm->timewait; + + s->s.udata = scfg->udata; } static int @@ -717,6 +719,7 @@ stream_update_cfg(struct tle_stream *ts,struct tle_tcp_stream_cfg *prm) /* store other params */ s->tcb.snd.nb_retm = (prm->nb_retries != 0) ? prm->nb_retries : TLE_TCP_DEFAULT_RETRIES; + s->s.udata = prm->udata; /* invoke async notifications, if any */ if (rte_ring_count(s->rx.q) != 0) { diff --git a/lib/libtle_l4p/tle_ctx.h b/lib/libtle_l4p/tle_ctx.h index 391cfe3..e730441 100644 --- a/lib/libtle_l4p/tle_ctx.h +++ b/lib/libtle_l4p/tle_ctx.h @@ -123,14 +123,14 @@ struct tle_ctx_param { uint32_t send_bulk_size; /**< expected # of packets per send call. */ uint32_t flags; /**< specific flags */ - int (*lookup4)(void *opaque, const struct in_addr *addr, - struct tle_dest *res); + int (*lookup4)(void *opaque, uint64_t stream_udata, + const struct in_addr *addr, struct tle_dest *res); /**< will be called by send() to get IPv4 packet destination info. */ void *lookup4_data; /**< opaque data pointer for lookup4() callback. */ - int (*lookup6)(void *opaque, const struct in6_addr *addr, - struct tle_dest *res); + int (*lookup6)(void *opaque, uint64_t stream_udata, + const struct in6_addr *addr, struct tle_dest *res); /**< will be called by send() to get IPv6 packet destination info. */ void *lookup6_data; /**< opaque data pointer for lookup6() callback. */ diff --git a/lib/libtle_l4p/tle_tcp.h b/lib/libtle_l4p/tle_tcp.h index 9947041..76f3476 100644 --- a/lib/libtle_l4p/tle_tcp.h +++ b/lib/libtle_l4p/tle_tcp.h @@ -35,6 +35,8 @@ struct tle_tcp_stream_addr { struct tle_tcp_stream_cfg { uint8_t nb_retries; /**< max number of retransmission attempts. */ + uint64_t udata; /**< user data to be associated with the stream. */ + /* _cb and _ev are mutually exclusive */ struct tle_event *err_ev; /**< error event to use. */ struct tle_stream_cb err_cb; /**< error callback to use. */ diff --git a/test/gtest/test_common.cpp b/test/gtest/test_common.cpp index a91c8ba..e7fa788 100644 --- a/test/gtest/test_common.cpp +++ b/test/gtest/test_common.cpp @@ -255,18 +255,22 @@ typen_rx_callback(dpdk_port_t port, __rte_unused uint16_t queue, } int -dummy_lookup4(void *opaque, const struct in_addr *addr, struct tle_dest *res) +dummy_lookup4(void *opaque, uint64_t sdata, const struct in_addr *addr, + struct tle_dest *res) { RTE_SET_USED(opaque); + RTE_SET_USED(sdata); RTE_SET_USED(addr); RTE_SET_USED(res); return -ENOENT; } int -dummy_lookup6(void *opaque, const struct in6_addr *addr, struct tle_dest *res) +dummy_lookup6(void *opaque, uint64_t sdata, const struct in6_addr *addr, + struct tle_dest *res) { RTE_SET_USED(opaque); + RTE_SET_USED(sdata); RTE_SET_USED(addr); RTE_SET_USED(res); return -ENOENT; diff --git a/test/gtest/test_common.h b/test/gtest/test_common.h index 5b01114..d747857 100644 --- a/test/gtest/test_common.h +++ b/test/gtest/test_common.h @@ -98,9 +98,11 @@ typen_rx_callback(dpdk_port_t port, __rte_unused uint16_t queue, __rte_unused uint16_t max_pkts, void *user_param); int -dummy_lookup4(void *opaque, const struct in_addr *addr, struct tle_dest *res); +dummy_lookup4(void *opaque, uint64_t sdata, const struct in_addr *addr, + struct tle_dest *res); int -dummy_lookup6(void *opaque, const struct in6_addr *addr, struct tle_dest *res); +dummy_lookup6(void *opaque, uint64_t sdata, const struct in6_addr *addr, + struct tle_dest *res); #endif /* TEST_COMMON_H_ */ diff --git a/test/gtest/test_tle_udp_stream_gen.h b/test/gtest/test_tle_udp_stream_gen.h index 8476375..855980c 100644 --- a/test/gtest/test_tle_udp_stream_gen.h +++ b/test/gtest/test_tle_udp_stream_gen.h @@ -62,7 +62,8 @@ extern struct rte_mempool *mbuf_pool; /* Dummy lookup functions, TX operations are not performed in these tests */ static int -lookup4_function(void *opaque, const struct in_addr *addr, struct tle_dest *res) +lookup4_function(void *opaque, __rte_unused uint64_t sdata, + const struct in_addr *addr, struct tle_dest *res) { struct in_addr route; struct rte_ether_hdr *eth; @@ -98,8 +99,8 @@ lookup4_function(void *opaque, const struct in_addr *addr, struct tle_dest *res) } static int -lookup6_function(void *opaque, const struct in6_addr *addr, - struct tle_dest *res) +lookup6_function(void *opaque, __rte_unused uint64_t sdata, + const struct in6_addr *addr, struct tle_dest *res) { struct rte_ether_hdr *eth; struct rte_ipv6_hdr *ip6h; -- cgit 1.2.3-korg