CNDP  22.08.0
uds.h File Reference
#include <stdint.h>
#include <sys/socket.h>
#include <sys/un.h>
#include "cne_common.h"

Go to the source code of this file.

Typedefs

typedef struct uds_group uds_group_t
 
typedef int(* uds_cb) (uds_client_t *client, const char *cmd, const char *params)
 

Enumerations

enum  {
  UDS_START = 0 , UDS_CONNECTED , UDS_HOST_OK , UDS_GOT_FD ,
  UDS_FD_NAK , UDS_FIN , UDS_HOST_NAK , UDS_HOST_ERR ,
  UDS_BUSY_POLL_ACK , UDS_BUSY_POLL_NAK
}
 

Functions

CNDP_API int uds_register (const uds_group_t *grp, const char *cmd, uds_cb fn)
 
CNDP_API uds_info_t * uds_create (const char *runtime_dir, const char *uds_name, const char **err_str, void *priv)
 
CNDP_API uds_info_t * uds_get_default (void *priv)
 
CNDP_API const uds_group_tuds_create_group (const uds_info_t *info, const char *group, void *priv)
 
CNDP_API int uds_destroy_group (const uds_group_t *group)
 
CNDP_API const uds_group_tuds_get_group_by_name (const uds_info_t *info, const char *name)
 
CNDP_API uds_info_t * uds_connect (const char *uds_name, const char **err_str, void *priv)
 
CNDP_API void uds_destroy (uds_info_t *info)
 
CNDP_API int uds_append (uds_client_t *client, const char *format,...)
 
CNDP_API const char * uds_cmd (uds_client_t *client)
 
CNDP_API const char * uds_params (uds_client_t *client)
 

Detailed Description

uds-related utility functions

Definition in file uds.h.

Typedef Documentation

◆ uds_group_t

typedef struct uds_group uds_group_t

returned by uds_cb to indicate UDS should not send its output buffer. This is usually used when the application sends its own data, not necessarily json formatted.

◆ uds_cb

typedef int(* uds_cb) (uds_client_t *client, const char *cmd, const char *params)

callback returns json data in buffer, up to buf_len long. returns 0 on success, UDS_NO_OUTPUT on success and to indicate that UDS should not send any output in its buffer, or an otherwise negative value indicate failure.

Definition at line 94 of file uds.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
UDS_START 

initial state

UDS_CONNECTED 

xskdev_connect() returned non-null

UDS_HOST_OK 

received a /host_ok message

UDS_GOT_FD 

successfully retrieved xsk_map_fd

UDS_FD_NAK 

error on retrieving xsk_map_fd

UDS_FIN 

received a /fin msg

UDS_HOST_NAK 

received a /host_nak response

UDS_HOST_ERR 

timeout waiting for /host_ok response

UDS_BUSY_POLL_ACK 

busy poll socket cfg success

UDS_BUSY_POLL_NAK 

busy poll socket cfg failure

Definition at line 63 of file uds.h.

Function Documentation

◆ uds_register()

CNDP_API int uds_register ( const uds_group_t grp,
const char *  cmd,
uds_cb  fn 
)

Register a new command to the uds interface

Parameters
grpUDS command group to register the callback for
cmdThe command string including the '/' e.g. '/pktdev:stats'
fnThe function to callback for this command
Returns
0 on success or -1 on error
Examples
examples/cndpfwd/stats.c.

◆ uds_create()

CNDP_API uds_info_t* uds_create ( const char *  runtime_dir,
const char *  uds_name,
const char **  err_str,
void *  priv 
)

Create a uds instance.

Parameters
runtime_dirThe base directory to create the local domain socket file.
uds_nameThe name of the local domain socket.
err_strThe error return pointer, used to send back error messages, Can be NULL
privThe private data to be passed to uds_info_t, Can be NULL
Returns
The uds_info_t pointer or NULL on error

◆ uds_get_default()

CNDP_API uds_info_t* uds_get_default ( void *  priv)

Returns default UDS instance.

Returns
The uds_info_t pointer or NULL on error.
Examples
examples/cndpfwd/stats.c.

◆ uds_create_group()

CNDP_API const uds_group_t* uds_create_group ( const uds_info_t *  info,
const char *  group,
void *  priv 
)

Register a new command group to the uds interface.

Parameters
infoUDS socket information
groupGroup name
privPrivate data to be associated with the command group.
Returns
Pointer to group handle on success, NULL on error, with errno indicating reason for failure.
Examples
examples/cndpfwd/stats.c.

◆ uds_destroy_group()

CNDP_API int uds_destroy_group ( const uds_group_t group)

Destroy a command group, freeing all associated callbacks.

Parameters
groupUDS command group handle to destroy.
Returns
0 on success, -1 on failure, with errno indicating reason for failure.

◆ uds_get_group_by_name()

CNDP_API const uds_group_t* uds_get_group_by_name ( const uds_info_t *  info,
const char *  name 
)

Get command group by name for this UDS interface.

Parameters
infoUDS socket information
nameGroup name to look up. Set to NULL to get root command group.
Returns
Pointer to group handle on success, NULL on error, with errno indicating reason for failure.

◆ uds_connect()

CNDP_API uds_info_t* uds_connect ( const char *  uds_name,
const char **  err_str,
void *  priv 
)

Connect to a an existing UDS without creating it. Creates a uds_info_t instance.

Parameters
uds_nameThe name of the local domain socket to connect to.
err_strThe error return pointer, used to send back error messages, Can be NULL
privThe private data to be passed to uds_info_t, Can be NULL
Returns
The uds_info_t pointer or NULL on error

◆ uds_destroy()

CNDP_API void uds_destroy ( uds_info_t *  info)

Destroy and stop the uds threads and close sockets

Parameters
infoThe pointer returned from the uds_create() call.
Examples
examples/cndpfwd/main.c.

◆ uds_append()

CNDP_API int uds_append ( uds_client_t *  client,
const char *  format,
  ... 
)

A snprintf() like routine to add text or data to the output buffer.

Parameters
clientThe client pointer that holds the buffer to append the text data.
formatThe snprintf() like format string with variable arguments
...Arguments for the format string to use
Returns
The number of bytes appended to the data buffer.
Examples
examples/cndpfwd/acl-func.c, and examples/cndpfwd/stats.c.

◆ uds_cmd()

CNDP_API const char* uds_cmd ( uds_client_t *  client)

Return the command string pointer

Parameters
clientThe client structure pointer
Returns
NULL if not defined or the string pointer.

◆ uds_params()

CNDP_API const char* uds_params ( uds_client_t *  client)

Return the params string pointer

Parameters
clientThe client structure pointer
Returns
NULL if not defined or the string pointer.