sysrepo  5.2.34
YANG-based system repository for all-around configuration management.
Collector

Receiving, reassembling and parsing UDP-Notif messages. More...

Collaboration diagram for Collector:

Data Structures

struct  srudpn_stats_t
 UDP-Notif collector diagnostic counters. More...
 

Typedefs

typedef struct srudpn_msg_s srudpn_msg_t
 Complete (reassembled) UDP-Notif message. More...
 
typedef struct srudpn_notif_s srudpn_notif_t
 Parsed notification of a UDP-Notif message. More...
 
typedef struct srudpn_s srudpn_t
 UDP-Notif collector receiving and reassembling notifications over UDP. More...
 

Functions

void srudpn_close (srudpn_t *udp)
 Close a collector, any incomplete messages are dropped. More...
 
int srudpn_get_fd (const srudpn_t *udp)
 Get the socket of a collector for polling. More...
 
uint16_t srudpn_get_port (const srudpn_t *udp)
 Get the port a collector is bound to. More...
 
srudpn_stats_t srudpn_get_stats (const srudpn_t *udp)
 Get the diagnostic counters of a collector. More...
 
void srudpn_msg_free (srudpn_msg_t *msg)
 Free a message. More...
 
const srudpn_hdr_t * srudpn_msg_get_hdr (const srudpn_msg_t *msg)
 Get the header of a message. More...
 
srudpn_media_type_t srudpn_msg_get_media_type (const srudpn_msg_t *msg)
 Get the media type of a message. More...
 
void srudpn_msg_get_payload (const srudpn_msg_t *msg, const uint8_t **payload, uint32_t *payload_len)
 Get the payload of a message. More...
 
void srudpn_msg_get_source (const srudpn_msg_t *msg, char *addr, uint16_t *port)
 Get the source address and port of a message. More...
 
int srudpn_msg_parse (const srudpn_msg_t *msg, const struct ly_ctx *ly_ctx, srudpn_notif_t **notif)
 Parse the notification of a message. More...
 
void srudpn_notif_free (srudpn_notif_t *notif)
 Free a parsed notification. More...
 
const struct lyd_node * srudpn_notif_get_envelope (const srudpn_notif_t *notif)
 Get the envelope of a parsed notification. More...
 
const struct timespec * srudpn_notif_get_event_time (const srudpn_notif_t *notif)
 Get the event time of a parsed notification. More...
 
const struct lyd_node * srudpn_notif_get_tree (const srudpn_notif_t *notif)
 Get the notification data tree of a parsed notification. More...
 
int srudpn_open (const char *address, uint16_t port, srudpn_t **udp)
 Open a UDP-Notif collector bound to a local address. More...
 
int srudpn_read_msg (srudpn_t *udp, int32_t timeout_ms, srudpn_msg_t **msg)
 Read one complete UDP-Notif message. More...
 

Detailed Description

Receiving, reassembling and parsing UDP-Notif messages.


Data Structure Documentation

◆ srudpn_stats_t

struct srudpn_stats_t

UDP-Notif collector diagnostic counters.

Definition at line 101 of file udp_notif.h.

Data Fields
uint32_t datagrams

all received datagrams

uint32_t dup_segments

duplicate segments dropped

uint32_t malformed

datagrams discarded for an invalid header or length

uint32_t messages

complete messages returned

uint32_t reasm_discarded

incomplete messages dropped on a timeout or eviction

uint32_t unsupported

datagrams discarded for a version, option or media type

Typedef Documentation

◆ srudpn_msg_t

typedef struct srudpn_msg_s srudpn_msg_t

Complete (reassembled) UDP-Notif message.

Definition at line 1 of file udp_notif.h.

◆ srudpn_notif_t

typedef struct srudpn_notif_s srudpn_notif_t

Parsed notification of a UDP-Notif message.

The notification is sent in the RFC 5277 envelope (RFC 8040 for JSON), the getters return these parts of it:

<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"> <- srudpn_notif_get_envelope()
<eventTime>2026-10-23T10:00:00Z</eventTime> <- srudpn_notif_get_event_time()
<link-down xmlns="urn:example:interfaces"> <- srudpn_notif_get_tree()
<if-name>eth0</if-name>
</link-down>
</notification>

Definition at line 1 of file udp_notif.h.

◆ srudpn_t

typedef struct srudpn_s srudpn_t

UDP-Notif collector receiving and reassembling notifications over UDP.

Definition at line 1 of file udp_notif.h.

Function Documentation

◆ srudpn_close()

void srudpn_close ( srudpn_t *  udp)

Close a collector, any incomplete messages are dropped.

Parameters
[in]udpCollector to close.

◆ srudpn_get_fd()

int srudpn_get_fd ( const srudpn_t *  udp)

Get the socket of a collector for polling.

The socket must not be closed or read from.

Parameters
[in]udpCollector to use.
Returns
Socket file descriptor.

◆ srudpn_get_port()

uint16_t srudpn_get_port ( const srudpn_t *  udp)

Get the port a collector is bound to.

Parameters
[in]udpCollector to use.
Returns
Bound port.

◆ srudpn_get_stats()

srudpn_stats_t srudpn_get_stats ( const srudpn_t *  udp)

Get the diagnostic counters of a collector.

Parameters
[in]udpCollector to use.
Returns
Current counters.

◆ srudpn_msg_free()

void srudpn_msg_free ( srudpn_msg_t *  msg)

Free a message.

Parameters
[in]msgMessage to free.

◆ srudpn_msg_get_hdr()

const srudpn_hdr_t* srudpn_msg_get_hdr ( const srudpn_msg_t *  msg)

Get the header of a message.

Parameters
[in]msgMessage to use.
Returns
Header of the message.

◆ srudpn_msg_get_media_type()

srudpn_media_type_t srudpn_msg_get_media_type ( const srudpn_msg_t *  msg)

Get the media type of a message.

Only SRUDPN_MT_JSON and SRUDPN_MT_XML can be parsed by srudpn_msg_parse(), any other media type has to be decoded from srudpn_msg_get_payload() by the caller.

Parameters
[in]msgMessage to use.
Returns
Media type, SRUDPN_MT_PRIVATE for any private one, an unknown standard one as its MT value.

◆ srudpn_msg_get_payload()

void srudpn_msg_get_payload ( const srudpn_msg_t *  msg,
const uint8_t **  payload,
uint32_t *  payload_len 
)

Get the payload of a message.

Meant for the media types srudpn_msg_parse() cannot parse, see srudpn_msg_get_media_type().

Parameters
[in]msgMessage to use.
[out]payloadReassembled payload.
[out]payload_lenLength of payload.

◆ srudpn_msg_get_source()

void srudpn_msg_get_source ( const srudpn_msg_t *  msg,
char *  addr,
uint16_t *  port 
)

Get the source address and port of a message.

Parameters
[in]msgMessage to use.
[out]addrBuffer of SRUDPN_ADDR_STRLEN for the numeric IPv4 or IPv6 source address.
[out]portSource port.

◆ srudpn_msg_parse()

int srudpn_msg_parse ( const srudpn_msg_t *  msg,
const struct ly_ctx *  ly_ctx,
srudpn_notif_t **  notif 
)

Parse the notification of a message.

Parameters
[in]msgMessage to parse.
[in]ly_ctxLibyang context to use for parsing.
[out]notifParsed notification, free with srudpn_notif_free().
Returns
Error code (SR_ERR_OK on success).

◆ srudpn_notif_free()

void srudpn_notif_free ( srudpn_notif_t *  notif)

Free a parsed notification.

Parameters
[in]notifParsed notification to free.

◆ srudpn_notif_get_envelope()

const struct lyd_node* srudpn_notif_get_envelope ( const srudpn_notif_t *  notif)

Get the envelope of a parsed notification.

The envelope is the outer notification element of RFC 5277 (RFC 8040 for JSON) with the eventTime, without the notification data itself, see srudpn_notif_t.

Note
The envelope nodes are opaque (no schema), read them with LYD_NAME() and lyd_get_value().
Parameters
[in]notifParsed notification to use.
Returns
Envelope data tree.

◆ srudpn_notif_get_event_time()

const struct timespec* srudpn_notif_get_event_time ( const srudpn_notif_t *  notif)

Get the event time of a parsed notification.

Parameters
[in]notifParsed notification to use.
Returns
Event time from the notification envelope.

◆ srudpn_notif_get_tree()

const struct lyd_node* srudpn_notif_get_tree ( const srudpn_notif_t *  notif)

Get the notification data tree of a parsed notification.

Parameters
[in]notifParsed notification to use.
Returns
Notification data tree.

◆ srudpn_open()

int srudpn_open ( const char *  address,
uint16_t  port,
srudpn_t **  udp 
)

Open a UDP-Notif collector bound to a local address.

Parameters
[in]addressNumeric IPv4 or IPv6 address to bind to, NULL for all local addresses.
[in]portPort to bind to, 0 for any free port.
[out]udpCreated collector.
Returns
Error code (SR_ERR_OK on success).

◆ srudpn_read_msg()

int srudpn_read_msg ( srudpn_t *  udp,
int32_t  timeout_ms,
srudpn_msg_t **  msg 
)

Read one complete UDP-Notif message.

Parameters
[in]udpCollector to read from.
[in]timeout_msTimeout of the whole call, -1 for infinite, 0 to only process the already queued datagrams without waiting.
[out]msgRead message, free with srudpn_msg_free().
Returns
SR_ERR_OK on success,
SR_ERR_TIME_OUT if no message was completed in time or a signal interrupted the wait,
another error code on failure.