libnetconf2
3.5.4
NETCONF server and client library in C.
|
Client-side NETCONF session manipulation. More...
Typedefs | |
typedef void(* | nc_client_monitoring_clb )(struct nc_session *session, void *user_data) |
Callback for monitoring client sessions. More... | |
typedef void(* | nc_notif_dispatch_clb )(struct nc_session *session, const struct lyd_node *envp, const struct lyd_node *op, void *user_data) |
Callback for receiving notifications in a separate thread. More... | |
Functions | |
void | nc_client_enable_tcp_keepalives (int enable) |
Enable or disable TCP keepalives. Only affects new sessions. More... | |
int | nc_client_monitoring_thread_start (nc_client_monitoring_clb monitoring_clb, void *user_data, void(*free_data)(void *)) |
Start a thread that monitors client sessions. More... | |
void | nc_client_monitoring_thread_stop (void) |
Stop the client session monitoring thread. More... | |
void | nc_client_session_set_not_strict (struct nc_session *session) |
Make a session not strict when sending RPCs and receiving RPC replies. In other words, it will silently skip unknown nodes without an error. More... | |
void | nc_client_set_tcp_keepalives (uint16_t idle_time, uint16_t max_probes, uint16_t probe_interval) |
Set TCP keepalive options. More... | |
struct nc_session * | nc_connect_inout (int fdin, int fdout, struct ly_ctx *ctx) |
Connect to the NETCONF server via proviaded input/output file descriptors. More... | |
struct nc_session * | nc_connect_unix (const char *address, struct ly_ctx *ctx) |
Connect to the NETCONF server via unix socket. More... | |
NC_MSG_TYPE | nc_recv_notif (struct nc_session *session, int timeout, struct lyd_node **envp, struct lyd_node **op) |
Receive NETCONF Notification. More... | |
int | nc_recv_notif_dispatch (struct nc_session *session, nc_notif_dispatch_clb notif_clb) |
Receive NETCONF Notifications in a separate thread until the session is terminated or <notificationComplete> is received. More... | |
int | nc_recv_notif_dispatch_data (struct nc_session *session, nc_notif_dispatch_clb notif_clb, void *user_data, void(*free_data)(void *)) |
Receive NETCONF Notifications in a separate thread until the session is terminated or <notificationComplete> is received. Similar to nc_recv_notif_dispatch() but allows to set arbitrary user data that can be freed as well. More... | |
NC_MSG_TYPE | nc_recv_reply (struct nc_session *session, struct nc_rpc *rpc, uint64_t msgid, int timeout, struct lyd_node **envp, struct lyd_node **op) |
Receive NETCONF RPC reply. More... | |
NC_MSG_TYPE | nc_send_rpc (struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_t *msgid) |
Send NETCONF RPC message via the session. More... | |
const char * | nc_session_cpblt (const struct nc_session *session, const char *capab) |
Check capability presence in a session. More... | |
const char *const * | nc_session_get_cpblts (const struct nc_session *session) |
Get session capabilities. More... | |
int | nc_session_ntf_thread_running (const struct nc_session *session) |
Check whether the session has a notification thread running. More... | |
Client-side NETCONF session manipulation.
typedef void(* nc_notif_dispatch_clb)(struct nc_session *session, const struct lyd_node *envp, const struct lyd_node *op, void *user_data) |
Callback for receiving notifications in a separate thread.
[in] | session | NC session that received the notification. |
[in] | envp | Notification envelope data tree. |
[in] | op | Notification body data tree. |
[in] | user_data | Arbitrary user data passed to the callback. |
Definition at line 564 of file session_client.h.
typedef void(* nc_client_monitoring_clb)(struct nc_session *session, void *user_data) |
Callback for monitoring client sessions.
This callback is called whenever the client finds out that a session was disconnected by the server.
[in] | session | Disconnected session. The session will not be freed, so it is safe to call nc_session_free() on it. |
[in] | user_data | Arbitrary user data passed to the callback. |
Definition at line 628 of file session_client.h.
struct nc_session* nc_connect_inout | ( | int | fdin, |
int | fdout, | ||
struct ly_ctx * | ctx | ||
) |
Connect to the NETCONF server via proviaded input/output file descriptors.
Transport layer is supposed to be already set. Function do not cover authentication or any other manipulation with the transport layer, it only establish NETCONF session by sending and processing NETCONF <hello> messages.
[in] | fdin | Input file descriptor for reading (clear) data from NETCONF server. |
[in] | fdout | Output file descriptor for writing (clear) data for NETCONF server. |
[in,out] | ctx | Optional custom context to use for the session. If not set, a default context is created. Any YANG modules not present in the context and supported by the server are loaded using <get-schema> (if supported) and/or by searching the searchpath (see nc_client_set_schema_searchpath()). |
struct nc_session* nc_connect_unix | ( | const char * | address, |
struct ly_ctx * | ctx | ||
) |
Connect to the NETCONF server via unix socket.
Connect to netconf server via an unix socket. Function do not cover authentication or any other manipulation with the transport layer, it only establish NETCONF session by sending and processing NETCONF <hello> messages.
[in] | address | Path to the unix socket. |
[in,out] | ctx | Optional custom context to use for the session. If not set, a default context is created. Any YANG modules not present in the context and supported by the server are loaded using <get-schema> (if supported) and/or by searching the searchpath (see nc_client_set_schema_searchpath()). |
const char* const* nc_session_get_cpblts | ( | const struct nc_session * | session | ) |
Get session capabilities.
[in] | session | Session to get the information from. |
session
capabilities. const char* nc_session_cpblt | ( | const struct nc_session * | session, |
const char * | capab | ||
) |
Check capability presence in a session.
[in] | session | Session to check. |
[in] | capab | Capability to look for, capability with any additional suffix will match. |
int nc_session_ntf_thread_running | ( | const struct nc_session * | session | ) |
Check whether the session has a notification thread running.
[in] | session | Session to check. |
NC_MSG_TYPE nc_recv_reply | ( | struct nc_session * | session, |
struct nc_rpc * | rpc, | ||
uint64_t | msgid, | ||
int | timeout, | ||
struct lyd_node ** | envp, | ||
struct lyd_node ** | op | ||
) |
Receive NETCONF RPC reply.
[in] | session | NETCONF session from which the function gets data. It must be the client side session object. |
[in] | rpc | Original RPC this should be the reply to. |
[in] | msgid | Expected message ID of the reply. |
[in] | timeout | Timeout for reading in milliseconds. Use negative value for infinite waiting and 0 for immediate return if data are not available on the wire. |
[out] | envp | NETCONF rpc-reply XML envelopes. |
[out] | op | Parsed NETCONF reply data, if any (none for <ok> or error replies). Set only on NC_MSG_REPLY and NC_MSG_REPLY_ERR_MSGID return. |
timeout
has elapsed, NC_MSG_ERROR if reading has failed, NC_MSG_NOTIF if a notification was read instead (call this function again to get the reply), and NC_MSG_REPLY_ERR_MSGID if a reply with missing or wrong message-id was received. NC_MSG_TYPE nc_recv_notif | ( | struct nc_session * | session, |
int | timeout, | ||
struct lyd_node ** | envp, | ||
struct lyd_node ** | op | ||
) |
Receive NETCONF Notification.
[in] | session | NETCONF session from which the function gets data. It must be the client side session object. |
[in] | timeout | Timeout for reading in milliseconds. Use negative value for infinite waiting and 0 for immediate return if data are not available on the wire. |
[out] | envp | NETCONF notification XML envelopes. |
[out] | op | Parsed NETCONF notification data. |
timeout
has elapsed, NC_MSG_ERROR if reading has failed, and NC_MSG_REPLY if a reply was read instead (call this function again to get a notification). int nc_recv_notif_dispatch | ( | struct nc_session * | session, |
nc_notif_dispatch_clb | notif_clb | ||
) |
Receive NETCONF Notifications in a separate thread until the session is terminated or <notificationComplete> is received.
[in] | session | Netconf session to read notifications from. |
[in] | notif_clb | Function that is called for every received notification (including <notificationComplete>). Parameters are the session the notification was received on and the notification data. |
int nc_recv_notif_dispatch_data | ( | struct nc_session * | session, |
nc_notif_dispatch_clb | notif_clb, | ||
void * | user_data, | ||
void(*)(void *) | free_data | ||
) |
Receive NETCONF Notifications in a separate thread until the session is terminated or <notificationComplete> is received. Similar to nc_recv_notif_dispatch() but allows to set arbitrary user data that can be freed as well.
[in] | session | Netconf session to read notifications from. |
[in] | notif_clb | Callback that is called for every received notification (including <notificationComplete>). Parameters are the session the notification was received on and the notification data. |
[in] | user_data | Arbitrary user data. |
[in] | free_data | Callback for freeing the user data after notif thread exit. |
NC_MSG_TYPE nc_send_rpc | ( | struct nc_session * | session, |
struct nc_rpc * | rpc, | ||
int | timeout, | ||
uint64_t * | msgid | ||
) |
Send NETCONF RPC message via the session.
[in] | session | NETCONF session where the RPC will be written. |
[in] | rpc | NETCONF RPC object to send via the specified session. |
[in] | timeout | Timeout for writing in milliseconds. Use negative value for infinite waiting and 0 for return if data cannot be sent immediately. |
[out] | msgid | If RPC was successfully sent, this is it's message ID. |
void nc_client_session_set_not_strict | ( | struct nc_session * | session | ) |
Make a session not strict when sending RPCs and receiving RPC replies. In other words, it will silently skip unknown nodes without an error.
Generally, no such data should be worked with, so use this function only when you know what you are doing and you understand the consequences.
[in] | session | NETCONF client session. |
int nc_client_monitoring_thread_start | ( | nc_client_monitoring_clb | monitoring_clb, |
void * | user_data, | ||
void(*)(void *) | free_data | ||
) |
Start a thread that monitors client sessions.
Once the thread is running, new sessions will be monitored automatically.
Note that once you start the monitoring thread, any other client thread that calls nc_session_free() needs to share the same thread context (or be the same thread) as the thread that called this function (see nc_client_set_thread_context()).
[in] | monitoring_clb | Callback called whenever a session is terminated. |
[in] | user_data | Arbitrary user data passed to the callback. |
[in] | free_data | Callback for freeing the user data after monitoring thread exits. |
void nc_client_monitoring_thread_stop | ( | void | ) |
Stop the client session monitoring thread.
void nc_client_enable_tcp_keepalives | ( | int | enable | ) |
Enable or disable TCP keepalives. Only affects new sessions.
Client-side TCP keepalives have the following default values:
[in] | enable | Whether to enable or disable TCP keepalives. |
void nc_client_set_tcp_keepalives | ( | uint16_t | idle_time, |
uint16_t | max_probes, | ||
uint16_t | probe_interval | ||
) |
Set TCP keepalive options.
[in] | idle_time | Time in seconds before the first keepalive probe is sent. If 0, the default value 1 is used. |
[in] | max_probes | Maximum number of keepalive probes to send before considering the connection dead. If 0, the default value 10 is used. |
[in] | probe_interval | Time in seconds between individual keepalive probes. If 0, the default value 5 is used. |