Skip to content

Commit

Permalink
chnl: add chnl_port to get port from connected channel
Browse files Browse the repository at this point in the history
Signed-off-by: Jalal Mostafa <jalal.a.mostapha@gmail.com>
  • Loading branch information
jalalmostafa authored and KeithWiles committed Jul 30, 2024
1 parent 956a808 commit 9414578
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/cnet/chnl/cnet_chnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 10 additions & 0 deletions lib/cnet/chnl/cnet_chnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 9414578

Please sign in to comment.