From a2a570656fd8b97aee0069611cdc2b467a6e1a70 Mon Sep 17 00:00:00 2001 From: Jalal Mostafa Date: Tue, 30 Jul 2024 16:47:36 +0200 Subject: [PATCH] chnl: add chnl_port to get port from connected channel Signed-off-by: Jalal Mostafa --- lib/cnet/chnl/cnet_chnl.c | 15 +++++++++++++++ lib/cnet/chnl/cnet_chnl.h | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/cnet/chnl/cnet_chnl.c b/lib/cnet/chnl/cnet_chnl.c index 968167ee..86f81421 100644 --- a/lib/cnet/chnl/cnet_chnl.c +++ b/lib/cnet/chnl/cnet_chnl.c @@ -958,6 +958,21 @@ chnl_connect_common(struct chnl *ch, struct in_caddr *to, int32_t tolen __cne_un return 0; } +/* + * Gets lport ID from channel descriptor. A use case is to allocate pktmbufs + * directly from the port mempool using `pktdev_buf_alloc` + */ +int +chnl_port(int cd) +{ + struct chnl *ch = ch_get(cd); + + if (!ch || !ch->ch_pcb || !ch->ch_pcb->netif) + return __errno_set(EFAULT); + + return ch->ch_pcb->netif->lpid; +} + int chnl_validate_cb(const char *msg, struct chnl_buf *cb) { diff --git a/lib/cnet/chnl/cnet_chnl.h b/lib/cnet/chnl/cnet_chnl.h index 45563caf..8d1a64c9 100644 --- a/lib/cnet/chnl/cnet_chnl.h +++ b/lib/cnet/chnl/cnet_chnl.h @@ -83,6 +83,16 @@ typedef enum { */ CNDP_API void chnl_dump(const char *msg, struct chnl *ch); +/** + * @brief Gets port of connect'd or bind'd channel + * + * @param cd + * Channel descriptor + * @return + * -1 on error or pktdev port ID on success + */ +CNDP_API int chnl_port(int cd); + /** * @brief Common channel connect routine used by protocols. *