16 #ifndef NC_SESSION_SERVER_H_
17 #define NC_SESSION_SERVER_H_
23 #include <libyang/libyang.h>
25 #include <sys/types.h>
30 #ifdef NC_ENABLED_SSH_TLS
31 # include <libssh/callbacks.h>
32 # include <libssh/libssh.h>
33 # include <libssh/server.h>
56 typedef struct nc_server_reply *(*nc_rpc_clb)(
struct lyd_node *rpc,
struct nc_session *session);
213 void (*free_user_data)(
void *user_data));
260 struct nc_session **session);
304 struct nc_session *
nc_ps_get_session(
const struct nc_pollsession *ps, uint16_t idx);
336 #define NC_PSPOLL_NOSESSIONS 0x0001
337 #define NC_PSPOLL_TIMEOUT 0x0002
338 #define NC_PSPOLL_RPC 0x0004
339 #define NC_PSPOLL_BAD_RPC 0x0008
340 #define NC_PSPOLL_REPLY_ERROR 0x0010
341 #define NC_PSPOLL_SESSION_TERM 0x0020
342 #define NC_PSPOLL_SESSION_ERROR 0x0040
343 #define NC_PSPOLL_ERROR 0x0080
345 #ifdef NC_ENABLED_SSH_TLS
346 # define NC_PSPOLL_SSH_MSG 0x00100
347 # define NC_PSPOLL_SSH_CHANNEL 0x0200
364 int nc_ps_poll(
struct nc_pollsession *ps,
int timeout,
struct nc_session **session);
376 void nc_ps_clear(
struct nc_pollsession *ps,
int all,
void (*data_free)(
void *));
448 #ifdef NC_ENABLED_SSH_TLS
515 ssh_session ssh_sess, ssh_message msg,
void *user_data);
625 #ifdef NC_ENABLED_SSH_TLS
643 void *user_data,
void (*free_data)(
void *));
NC_MSG_TYPE
Enumeration of NETCONF message types.
char ** nc_server_get_cpblts_version(const struct ly_ctx *ctx, LYS_VERSION version)
Get the server capabilities including the schemas with the specified YANG version.
int nc_server_init_ctx(struct ly_ctx **ctx)
Initialize a context which can serve as a default server context.
void nc_server_get_capab_withdefaults(NC_WD_MODE *basic_mode, int *also_supported)
Get with-defaults capability extra parameters.
NC_MSG_TYPE nc_accept(int timeout, const struct ly_ctx *ctx, struct nc_session **session)
Accept new sessions on all the listening endpoints.
int nc_server_add_endpt_unix_socket_listen(const char *endpt_name, const char *unix_socket_path, mode_t mode, uid_t uid, gid_t gid)
Create a new UNIX socket endpoint and start listening.
int nc_session_get_notif_status(const struct nc_session *session)
Get session notification subscription flag.
void nc_session_inc_notif_status(struct nc_session *session)
Increase session notification subscription flag count. Supports multiple subscriptions on one session...
int(* nc_server_ssh_interactive_auth_clb)(const struct nc_session *session, ssh_session ssh_sess, ssh_message msg, void *user_data)
Keyboard interactive authentication callback.
int nc_server_endpt_count(void)
Get the number of currently configured listening endpoints. Note that an ednpoint without address and...
NC_MSG_TYPE nc_ps_accept_ssh_channel(struct nc_pollsession *ps, struct nc_session **session)
Accept a new NETCONF session on an SSH session of a running NETCONF session that was polled in ps...
libnetconf2 session manipulation
char ** nc_server_get_cpblts(const struct ly_ctx *ctx)
Get all the server capabilities including all the schemas.
int nc_server_set_capability(const char *value)
Set capability of the server.
NC_STATUS
Enumeration of possible session statuses.
int nc_server_ssh_kbdint_get_nanswers(const struct nc_session *session, ssh_session libssh_session)
Get the number of answers to Keyboard interactive authentication prompts.
int nc_server_init(void)
Initialize libssh and/or libssl/libcrypto and the server.
void nc_server_destroy(void)
Destroy any dynamically allocated libssh and/or libssl/libcrypto and server resources.
int nc_server_notif_cert_expiration_thread_start(nc_cert_exp_notif_clb cert_exp_notif_clb, void *user_data, void(*free_data)(void *))
Start the certificate expiration notification thread.
struct nc_session * nc_ps_find_session(const struct nc_pollsession *ps, nc_ps_session_match_cb match_cb, void *cb_data)
Find a session in a pollsession structure using a matching callback.
void nc_ps_clear(struct nc_pollsession *ps, int all, void(*data_free)(void *))
Remove sessions from a pollsession structure and call nc_session_free() on them.
void nc_server_set_content_id_clb(char *(*content_id_clb)(void *user_data), void *user_data, void(*free_user_data)(void *user_data))
Set the callback for getting yang-library capability identifier. If none is set, libyang context chan...
struct nc_server_reply *(* nc_rpc_clb)(struct lyd_node *rpc, struct nc_session *session)
Prototype of callbacks that are called if some RPCs are received.
int nc_server_ssh_set_pam_conf_filename(const char *filename)
Set the name of the PAM configuration file.
int nc_ps_del_session(struct nc_pollsession *ps, struct nc_session *session)
Remove a session from a pollsession structure.
void nc_session_set_status(struct nc_session *session, NC_STATUS status)
Set the status of a session.
NC_SESSION_TERM_REASON
Enumeration of reasons of the NETCONF session termination as defined in RFC 6470. ...
void(* nc_cert_exp_notif_clb)(const char *expiration_time, const char *xpath, void *user_data)
Callback for certificate expiration notification.
void nc_session_dec_notif_status(struct nc_session *session)
Decrease session notification subscription flag count. Supports multiple subscriptions on one session...
void nc_set_global_rpc_clb(nc_rpc_clb clb)
Set a global nc_rpc_clb that is called if the particular RPC request is received and the private fiel...
enum NC_WITHDEFAULTS_MODE NC_WD_MODE
Enumeration of NETCONF with-defaults capability modes.
int nc_server_ssh_set_authkey_path_format(const char *path)
Set the format of the path to authorized_keys files.
uint16_t nc_ps_session_count(struct nc_pollsession *ps)
Learn the number of sessions in a pollsession structure.
void nc_server_del_endpt_unix_socket(const char *endpt_name)
Deletes a UNIX socket endpoint.
const void * nc_session_get_client_cert(const struct nc_session *session)
Get client certificate.
struct nc_session * nc_ps_get_session(const struct nc_pollsession *ps, uint16_t idx)
Get a session from a pollsession structure matching the session ID.
NC_MSG_TYPE nc_session_accept_ssh_channel(struct nc_session *orig_session, struct nc_session **session)
Accept a new NETCONF session on an SSH session of a running NETCONF orig_session. Call this function ...
void nc_server_notif_cert_expiration_thread_stop(int wait)
Stop the certificate expiration notification thread.
void nc_session_set_killed_by(struct nc_session *session, uint32_t sid)
Set the session-id of the session responsible for this session's termination.
int(* nc_ps_session_match_cb)(struct nc_session *session, void *cb_data)
Callback for finding a session in a pollsession structure.
int nc_server_set_capab_withdefaults(NC_WD_MODE basic_mode, int also_supported)
Set the with-defaults capability extra parameters.
void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason)
Set the termination reason for a session. Use only in nc_rpc_clb callbacks.
void nc_ps_free(struct nc_pollsession *ps)
Free a pollsession structure.
NC_MSG_TYPE nc_accept_inout(int fdin, int fdout, const char *username, const struct ly_ctx *ctx, struct nc_session **session)
Accept a new session on a pre-established transport session.
int nc_ps_add_session(struct nc_pollsession *ps, struct nc_session *session)
Add a session to a pollsession structure.
struct nc_pollsession * nc_ps_new(void)
Create an empty structure for polling sessions.
struct timespec nc_session_get_start_time(const struct nc_session *session)
Get session start time.
void nc_server_ssh_set_interactive_auth_clb(nc_server_ssh_interactive_auth_clb auth_clb, void *user_data, void(*free_user_data)(void *user_data))
Set the callback for SSH interactive authentication.
void nc_server_tls_set_verify_clb(int(*verify_clb)(const struct nc_session *session))
Set TLS authentication additional verify callback.
struct nc_server_reply * nc_clb_default_get_schema(struct lyd_node *rpc, struct nc_session *session)
Default RPC callback used for "ietf-netconf-monitoring:get-schema" RPC if no other specific or global...
libnetconf2's general public functions and structures definitions.
int nc_ps_poll(struct nc_pollsession *ps, int timeout, struct nc_session **session)
Poll sessions and process any received RPCs.
struct nc_server_reply * nc_clb_default_close_session(struct lyd_node *rpc, struct nc_session *session)
Default RPC callback used for "ietf-netconf:close-session" RPC if no other specific or global callbac...