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 625323d2..e57e9524 100644 --- a/lib/cnet/chnl/cnet_chnl.h +++ b/lib/cnet/chnl/cnet_chnl.h @@ -85,6 +85,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. *