Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chnl: add chnl_port to get port from connected channel #388

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading