CNDP
22.08.0
|
#include <stdio.h>
#include <sys/socket.h>
#include <sys/queue.h>
#include <netinet/in.h>
#include <bsd/bitstring.h>
#include <pktmbuf.h>
#include <cnet_const.h>
#include <cne_vec.h>
#include <cnet_protosw.h>
#include <cne_graph_worker.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/types.h>
#include "cne_log.h"
#include "cnet_tcp.h"
#include "cnet_udp.h"
Go to the source code of this file.
Macros | |
#define | CHNL_ENABLE_UDP_CHECKSUM (1 << 0) |
Typedefs | |
typedef int(* | chnl_cb_t) (int chnl_type, int cd) |
Enumerations | |
enum | { SHUT_BIT_RD = 0x01 , SHUT_BIT_WR = 0x02 , SHUT_BIT_RDWR = 0x03 } |
enum | chnl_type_t { CHNL_UDP_RECV_TYPE , CHNL_UDP_CLOSE_TYPE , CHNL_TCP_ACCEPT_TYPE , CHNL_TCP_RECV_TYPE , CHNL_TCP_CLOSE_TYPE , CHNL_CALLBACK_TYPES } |
Functions | |
CNDP_API void | chnl_dump (const char *msg, struct chnl *ch) |
Dump out a channel structure. More... | |
CNDP_API int | chnl_connect_common (struct chnl *ch, struct in_caddr *to, int32_t tolen) |
Common channel connect routine used by protocols. More... | |
CNDP_API int | chnl_bind_common (struct chnl *ch, struct in_caddr *pAddr, int32_t len, struct pcb_hd *pHd) |
Channel Bind common routine used by protocols. More... | |
CNDP_API int | channel (int domain, int type, int proto, chnl_cb_t cb) |
The routine to create a channel structure similar to 'socket()'. More... | |
CNDP_API int | chnl_bind (int cd, struct sockaddr *addr, int addrlen) |
Bind an address to a channel similar to 'bind()'. More... | |
CNDP_API int | chnl_listen (int cd, int backlog) |
Listen on a channel similar to 'listen()'. More... | |
CNDP_API int | chnl_accept (int cd, struct sockaddr *sa, socklen_t *addrlen) |
Accept on a channel similar to 'accept()'. More... | |
CNDP_API int | chnl_connect (int cd, struct sockaddr *sa, int addrlen) |
Connect to a channel, similar to 'connect()'. More... | |
CNDP_API int | chnl_recv (int cd, pktmbuf_t **mbufs, size_t len) |
CNDP_API int | chnl_send (int cd, pktmbuf_t **mbufs, uint16_t nb_mbufs) |
CNDP_API int | chnl_sendto (int cd, struct sockaddr *sa, pktmbuf_t **mbufs, uint16_t nb_mbufs) |
Send data to a channel similar to 'sendto()'. More... | |
CNDP_API int | chnl_getchnlname (int cd, struct sockaddr *name, socklen_t *namelen) |
CNDP_API int | chnl_getpeername (int cd, struct sockaddr *sa, socklen_t *salen) |
CNDP_API int | chnl_close (int cd) |
CNDP_API int | chnl_shutdown (int cd, int how) |
Shutdown a channel connection similar to 'shutdown()'. More... | |
CNDP_API int | chnl_open (const char *str, int flags, chnl_cb_t fn) |
CNET Channel routines and constants.
Definition in file cnet_chnl.h.
#define CHNL_ENABLE_UDP_CHECKSUM (1 << 0) |
Enable UDP checksum
Definition at line 53 of file cnet_chnl.h.
typedef int(* chnl_cb_t) (int chnl_type, int cd) |
Callback function for a channel to accept or receive packets
chnl_type | The type of channel callback defined by chnl_type_t enum. |
cd | The channel descriptor value |
Definition at line 50 of file cnet_chnl.h.
anonymous enum |
Enumerator | |
---|---|
SHUT_BIT_RD | Shutdown Read side |
SHUT_BIT_WR | Shutdown Write side |
SHUT_BIT_RDWR | Shutdown Read and write side |
Definition at line 59 of file cnet_chnl.h.
enum chnl_type_t |
Channel callback types
Definition at line 66 of file cnet_chnl.h.
CNDP_API void chnl_dump | ( | const char * | msg, |
struct chnl * | ch | ||
) |
Dump out a channel structure.
msg | A message to print if present, can be NULL |
ch | The chnl structure to dump out. |
CNDP_API int chnl_connect_common | ( | struct chnl * | ch, |
struct in_caddr * | to, | ||
int32_t | tolen | ||
) |
Common channel connect routine used by protocols.
ch | The channel structure pointer |
to | The IP address of the 'to' or foreign address. |
tolen | The length of the 'to' address. |
CNDP_API int chnl_bind_common | ( | struct chnl * | ch, |
struct in_caddr * | pAddr, | ||
int32_t | len, | ||
struct pcb_hd * | pHd | ||
) |
Channel Bind common routine used by protocols.
ch | The channel structure pointer |
pAddr | The IP address to bind |
len | The length of the IP address to bind |
pHd | The head of the PCB list to add the channel |
CNDP_API int channel | ( | int | domain, |
int | type, | ||
int | proto, | ||
chnl_cb_t | cb | ||
) |
The routine to create a channel structure similar to 'socket()'.
domain | The domain ID value |
type | The protocol type value |
proto | The proto value |
cb | The callback routine to call when data is received. |
CNDP_API int chnl_bind | ( | int | cd, |
struct sockaddr * | addr, | ||
int | addrlen | ||
) |
Bind an address to a channel similar to 'bind()'.
cd | The channel descriptor index |
addr | The IP address to bind to the channel. |
addrlen | The IP address length in bytes |
CNDP_API int chnl_listen | ( | int | cd, |
int | backlog | ||
) |
Listen on a channel similar to 'listen()'.
cd | The channel descriptor index |
backlog | The number of backlog connections allowed (not fully used) |
CNDP_API int chnl_accept | ( | int | cd, |
struct sockaddr * | sa, | ||
socklen_t * | addrlen | ||
) |
Accept on a channel similar to 'accept()'.
cd | The channel descriptor index |
sa | The sockaddr to fill in when accepting a connection. |
addrlen | The length of the new accepted connection |
CNDP_API int chnl_connect | ( | int | cd, |
struct sockaddr * | sa, | ||
int | addrlen | ||
) |
Connect to a channel, similar to 'connect()'.
cd | The channel descriptor index |
sa | The sockaddr to fill in when accepting a connection. |
addrlen | The length of the new accepted connection |
CNDP_API int chnl_recv | ( | int | cd, |
pktmbuf_t ** | mbufs, | ||
size_t | len | ||
) |
This routine receives data from a chnl. It is normally used with connected chnls, because it does not return the source address of the received data.
cd | The channel descriptor index |
mbufs | Vector list of pktmbuf_t pointers. |
len | Number of entries in the mbufs array. |
CNDP_API int chnl_send | ( | int | cd, |
pktmbuf_t ** | mbufs, | ||
uint16_t | nb_mbufs | ||
) |
This routine transmits data to a previously connected chnl.
cd | The channel descriptor index |
mbufs | List of pointer vectors |
nb_mbufs | Number of mbufs in the vector list. |
CNDP_API int chnl_sendto | ( | int | cd, |
struct sockaddr * | sa, | ||
pktmbuf_t ** | mbufs, | ||
uint16_t | nb_mbufs | ||
) |
Send data to a channel similar to 'sendto()'.
cd | The channel descriptor index |
sa | The sockaddr to fill in when accepting a connection. |
mbufs | The mbuf array to send multiple data buffers |
nb_mbufs | Number of mbufs in the mbufs array |
CNDP_API int chnl_getchnlname | ( | int | cd, |
struct sockaddr * | name, | ||
socklen_t * | namelen | ||
) |
This routine gets the current name for the specified chnl.
cd | The channel descriptor index |
name | Buffer to receive the chnl name. |
namelen | Length of name. This is a value/result parameter. On entry, it must be initialized to the size of the buffer pointed to by name. On return, it contains the size of the chnl name. |
CNDP_API int chnl_getpeername | ( | int | cd, |
struct sockaddr * | sa, | ||
socklen_t * | salen | ||
) |
This routine gets the name of the peer connected to the specified chnl.
cd | The channel descriptor index |
sa | Buffer to receive the chnl name. |
salen | Length of name. This is a value/result parameter. On entry, it must be initialized to the size of the buffer pointed to by name. On return, it contains the size of the chnl name. |
CNDP_API int chnl_close | ( | int | cd | ) |
Close a connection to the specified chnl descriptor.
cd | The chnl descriptor index |
CNDP_API int chnl_shutdown | ( | int | cd, |
int | how | ||
) |
Shutdown a channel connection similar to 'shutdown()'.
cd | The channel descriptor index |
how | How to shutdown the connection SHUT_RD, SHUT_WR or SHUT_RDWR. |
CNDP_API int chnl_open | ( | const char * | str, |
int | flags, | ||
chnl_cb_t | fn | ||
) |
Open a channel with a string configuration.
The channel string is similar to socat style strings, but not all string types are support. Some string types supported are: udp4-listen:0.0.0.0:5678 - Open a listening UDP4 channel on port 5678 or udp4-listen:5678 - Open a listening UDP4 channel on port 5678. tcp4-listen:0.0.0.0:4433 - Open a listening TCP4 channel on port 4433 or tcp4-listen:4433 - Open a listening TCP4 channel on port 4433. tcp4-connect:198.18.2.1:2222 - Open TCP4 connection to port 2222 and IP address
Port value can be in hex '0x1234' or decimal format.
str | The string to parse to open or create a channel. |
flags | Some flags to control the creation of a channel, see CHNL_ENABLE_UDP_CHECKSUM and other flags to be defined. |
fn | Function pointer for channel callback. |