Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 1 | /** |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 2 | * @file session_client.h |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief libnetconf2 session client manipulation |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 5 | * |
Michal Vasko | 95ea9ff | 2021-11-09 12:29:14 +0100 | [diff] [blame] | 6 | * @copyright |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2021 CESNET, z.s.p.o. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 8 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
Michal Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 12 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 13 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef NC_SESSION_CLIENT_H_ |
| 17 | #define NC_SESSION_CLIENT_H_ |
| 18 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 23 | #include <libyang/libyang.h> |
| 24 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 25 | #ifdef NC_ENABLED_SSH_TLS |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 26 | # include <libssh/libssh.h> |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 27 | # include <openssl/ssl.h> |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 28 | #endif /* NC_ENABLED_SSH_TLS */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 29 | |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 30 | #include "messages_client.h" |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 31 | #include "netconf.h" |
| 32 | #include "session.h" |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 33 | |
| 34 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 35 | * @addtogroup client |
| 36 | * @{ |
| 37 | */ |
| 38 | |
| 39 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 40 | * @brief Set location where libnetconf tries to search for YANG/YIN schemas. |
| 41 | * |
Michal Vasko | 7f1c0ef | 2016-03-11 11:13:06 +0100 | [diff] [blame] | 42 | * The location is searched when connecting to a NETCONF server and building |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 43 | * YANG context for further processing of the NETCONF messages and data. |
| 44 | * |
Radek Krejci | fd5b668 | 2017-06-13 15:52:53 +0200 | [diff] [blame] | 45 | * The searchpath is also used to store schemas retreived via \<get-schema\> |
| 46 | * operation - if the schema is not found in searchpath neither via schema |
| 47 | * callback provided via nc_client_set_schema_callback() and server supports |
| 48 | * the NETCONF \<get-schema\> operation, the schema is retrieved this way and |
| 49 | * stored into the searchpath (if specified). |
| 50 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 51 | * @param[in] path Directory where to search for YANG/YIN schemas. |
| 52 | * @return 0 on success, 1 on (memory allocation) failure. |
| 53 | */ |
Michal Vasko | 7f1c0ef | 2016-03-11 11:13:06 +0100 | [diff] [blame] | 54 | int nc_client_set_schema_searchpath(const char *path); |
| 55 | |
| 56 | /** |
| 57 | * @brief Get schema searchpath that was set by nc_client_set_schema_searchpath(). |
| 58 | * |
| 59 | * @return Schema searchpath directory, NULL if not set. |
| 60 | */ |
| 61 | const char *nc_client_get_schema_searchpath(void); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 62 | |
| 63 | /** |
Radek Krejci | fd5b668 | 2017-06-13 15:52:53 +0200 | [diff] [blame] | 64 | * @brief Set callback function to get missing schemas. |
| 65 | * |
| 66 | * @param[in] clb Callback responsible for returning the missing model. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 67 | * @param[in] user_data Arbitrary data that will always be passed to the callback @p clb. |
Radek Krejci | fd5b668 | 2017-06-13 15:52:53 +0200 | [diff] [blame] | 68 | * @return 0 on success, 1 on (memory allocation) failure. |
| 69 | */ |
| 70 | int nc_client_set_schema_callback(ly_module_imp_clb clb, void *user_data); |
| 71 | |
| 72 | /** |
| 73 | * @brief Get callback function used to get missing schemas. |
| 74 | * |
| 75 | * @param[out] user_data Optionally return the private data set with the callback. |
| 76 | * Note that the caller is responsible for freeing the private data, so before |
| 77 | * changing the callback, private data used for the previous callback should be |
| 78 | * freed. |
| 79 | * @return Pointer to the set callback, NULL if no such callback was set. |
| 80 | */ |
| 81 | ly_module_imp_clb nc_client_get_schema_callback(void **user_data); |
| 82 | |
| 83 | /** |
Michal Vasko | a272e09 | 2023-07-10 14:34:03 +0200 | [diff] [blame] | 84 | * @brief Enable/disable loading of all the YANG modules supported by |
| 85 | * the server when a new session is created. If disabled, it is expected |
| 86 | * that users update the context themselves and load the YANG modules |
| 87 | * that are planned to be used. Otherwise even basic RPCs may fail to be sent! |
| 88 | * |
| 89 | * @param[in] enabled Whether context autofill is enabled or disabled. |
| 90 | */ |
| 91 | void nc_client_set_new_session_context_autofill(int enabled); |
| 92 | |
| 93 | /** |
Radek Krejci | 5cebc6b | 2017-05-26 13:24:38 +0200 | [diff] [blame] | 94 | * @brief Use the provided thread-specific client's context in the current thread. |
| 95 | * |
| 96 | * Note that from this point the context is shared with the thread from which the context was taken and any |
| 97 | * nc_client_*set* functions and functions creating connection in these threads should be protected from the |
| 98 | * concurrent execution. |
| 99 | * |
Radek Krejci | fd5b668 | 2017-06-13 15:52:53 +0200 | [diff] [blame] | 100 | * Context contains schema searchpath/callback, call home binds, TLS and SSH authentication data (username, keys, |
Radek Krejci | 5cebc6b | 2017-05-26 13:24:38 +0200 | [diff] [blame] | 101 | * various certificates and callbacks). |
| 102 | * |
| 103 | * @param[in] context Client's thread-specific context provided by nc_client_get_thread_context(). |
| 104 | */ |
| 105 | void nc_client_set_thread_context(void *context); |
| 106 | |
| 107 | /** |
| 108 | * @brief Get thread-specific client context for sharing with some other thread using |
| 109 | * nc_client_set_thread_context(). |
| 110 | * |
| 111 | * @return Pointer to the client's context of the current thread. |
| 112 | */ |
| 113 | void *nc_client_get_thread_context(void); |
| 114 | |
| 115 | /** |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 116 | * @brief Destroy all libssh and/or libssl/libcrypto dynamic memory and |
Michal Vasko | df0fa45 | 2022-03-02 11:06:01 +0100 | [diff] [blame] | 117 | * the client options, for both SSH and TLS, and for Call Home too. |
Michal Vasko | b7558c5 | 2016-02-26 15:04:19 +0100 | [diff] [blame] | 118 | */ |
| 119 | void nc_client_destroy(void); |
| 120 | |
Michal Vasko | 4e6d324 | 2021-05-26 09:13:24 +0200 | [diff] [blame] | 121 | /** @} Client */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * @defgroup client_session Client Session |
| 125 | * @ingroup client |
| 126 | * |
| 127 | * @brief Client-side NETCONF session manipulation. |
| 128 | * @{ |
| 129 | */ |
| 130 | |
Michal Vasko | b7558c5 | 2016-02-26 15:04:19 +0100 | [diff] [blame] | 131 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 132 | * @brief Connect to the NETCONF server via proviaded input/output file descriptors. |
| 133 | * |
| 134 | * Transport layer is supposed to be already set. Function do not cover authentication |
| 135 | * or any other manipulation with the transport layer, it only establish NETCONF session |
| 136 | * by sending and processing NETCONF \<hello\> messages. |
| 137 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 138 | * @param[in] fdin Input file descriptor for reading (clear) data from NETCONF server. |
| 139 | * @param[in] fdout Output file descriptor for writing (clear) data for NETCONF server. |
Michal Vasko | 94d6140 | 2023-03-16 08:21:52 +0100 | [diff] [blame] | 140 | * @param[in,out] ctx Optional custom context to use for the session. If not set, a default context is created. |
| 141 | * Any YANG modules not present in the context and supported by the server are loaded using \<get-schema\> |
| 142 | * (if supported) and/or by searching the searchpath (see ::nc_client_set_schema_searchpath()). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 143 | * @return Created NETCONF session object or NULL in case of error. |
| 144 | */ |
| 145 | struct nc_session *nc_connect_inout(int fdin, int fdout, struct ly_ctx *ctx); |
| 146 | |
Olivier Matz | ac7fa2f | 2018-10-11 10:02:04 +0200 | [diff] [blame] | 147 | /** |
| 148 | * @brief Connect to the NETCONF server via unix socket. |
| 149 | * |
| 150 | * Connect to netconf server via an unix socket. Function do not cover authentication |
| 151 | * or any other manipulation with the transport layer, it only establish NETCONF session |
| 152 | * by sending and processing NETCONF \<hello\> messages. |
| 153 | * |
| 154 | * @param[in] address Path to the unix socket. |
Michal Vasko | 94d6140 | 2023-03-16 08:21:52 +0100 | [diff] [blame] | 155 | * @param[in,out] ctx Optional custom context to use for the session. If not set, a default context is created. |
| 156 | * Any YANG modules not present in the context and supported by the server are loaded using \<get-schema\> |
| 157 | * (if supported) and/or by searching the searchpath (see ::nc_client_set_schema_searchpath()). |
Olivier Matz | ac7fa2f | 2018-10-11 10:02:04 +0200 | [diff] [blame] | 158 | * @return Created NETCONF session object or NULL in case of error. |
| 159 | */ |
| 160 | struct nc_session *nc_connect_unix(const char *address, struct ly_ctx *ctx); |
| 161 | |
Michal Vasko | 4e6d324 | 2021-05-26 09:13:24 +0200 | [diff] [blame] | 162 | /** @} Client Session */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 163 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 164 | #ifdef NC_ENABLED_SSH_TLS |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 165 | |
| 166 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 167 | * @defgroup client_ssh Client SSH |
| 168 | * @ingroup client |
| 169 | * |
| 170 | * @brief Client-side settings for SSH connections. |
| 171 | * @{ |
| 172 | */ |
| 173 | |
| 174 | /** |
roman | f6e3201 | 2023-04-24 15:51:26 +0200 | [diff] [blame] | 175 | * @brief Set the behaviour of checking the host key and adding/reading entries to/from the known_hosts file. |
Michal Vasko | ef112d7 | 2016-02-18 13:28:25 +0100 | [diff] [blame] | 176 | * |
roman | f6e3201 | 2023-04-24 15:51:26 +0200 | [diff] [blame] | 177 | * @param[in] mode Server host key checking mode. |
Michal Vasko | ef112d7 | 2016-02-18 13:28:25 +0100 | [diff] [blame] | 178 | */ |
roman | f6e3201 | 2023-04-24 15:51:26 +0200 | [diff] [blame] | 179 | void nc_client_ssh_set_knownhosts_mode(NC_SSH_KNOWNHOSTS_MODE mode); |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 180 | |
| 181 | /** |
roman | f6e3201 | 2023-04-24 15:51:26 +0200 | [diff] [blame] | 182 | * @brief Set the path to the known_hosts file. |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 183 | * |
roman | f6e3201 | 2023-04-24 15:51:26 +0200 | [diff] [blame] | 184 | * Repetetive calling replaces the value. If the given file doesn't exist and the process has sufficient |
| 185 | * rights, it gets created whenever the file is needed, otherwise an error occurs. If NULL is passed or the |
| 186 | * path isn't set, the default known_hosts file will be used. |
| 187 | * |
| 188 | * @param[in] path Path to the known_hosts file. |
| 189 | * @return 0 on success, 1 on error. |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 190 | */ |
roman | f6e3201 | 2023-04-24 15:51:26 +0200 | [diff] [blame] | 191 | int nc_client_ssh_set_knownhosts_path(const char *path); |
Michal Vasko | ef112d7 | 2016-02-18 13:28:25 +0100 | [diff] [blame] | 192 | |
| 193 | /** |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 194 | * @brief Set SSH password authentication callback. |
| 195 | * |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 196 | * Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for |
| 197 | * freeing the private data when necessary (the private data can be obtained by |
| 198 | * nc_client_ssh_get_auth_password_clb()). |
| 199 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 200 | * @param[in] auth_password Function to call, returns the password for username\@hostname. |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 201 | * If NULL, the default callback is set. |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 202 | * @param[in] priv Optional private data to be passed to the callback function. |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 203 | */ |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 204 | void nc_client_ssh_set_auth_password_clb(char *(*auth_password)(const char *username, const char *hostname, void *priv), |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 205 | void *priv); |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * @brief Get currently set SSH password authentication callback and its private data previously set |
| 209 | * by nc_client_ssh_set_auth_password_clb(). |
| 210 | * |
| 211 | * @param[out] auth_password Currently set callback, NULL in case of the default callback. |
| 212 | * @param[out] priv Currently set (optional) private data to be passed to the callback function. |
| 213 | */ |
| 214 | void nc_client_ssh_get_auth_password_clb(char *(**auth_password)(const char *username, const char *hostname, void *priv), |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 215 | void **priv); |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * @brief Set SSH interactive authentication callback. |
| 219 | * |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 220 | * Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for |
| 221 | * freeing the private data when necessary (the private data can be obtained by |
| 222 | * nc_client_ssh_get_auth_interactive_clb()). |
| 223 | * |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 224 | * @param[in] auth_interactive Function to call for every question, returns the answer for |
| 225 | * authentication name with instruction and echoing prompt. |
| 226 | * If NULL, the default callback is set. |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 227 | * @param[in] priv Optional private data to be passed to the callback function. |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 228 | */ |
| 229 | void nc_client_ssh_set_auth_interactive_clb(char *(*auth_interactive)(const char *auth_name, const char *instruction, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 230 | const char *prompt, int echo, void *priv), |
| 231 | void *priv); |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * @brief Get currently set SSH interactive authentication callback and its private data previously set |
| 235 | * by nc_client_ssh_set_auth_interactive_clb(). |
| 236 | * |
| 237 | * @param[out] auth_interactive Currently set callback, NULL in case of the default callback. |
| 238 | * @param[out] priv Currently set (optional) private data to be passed to the callback function. |
| 239 | */ |
| 240 | void nc_client_ssh_get_auth_interactive_clb(char *(**auth_interactive)(const char *auth_name, const char *instruction, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 241 | const char *prompt, int echo, void *priv), |
| 242 | void **priv); |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * @brief Set SSH publickey authentication encrypted private key passphrase callback. |
| 246 | * |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 247 | * Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for |
| 248 | * freeing the private data when necessary (the private data can be obtained by |
| 249 | * nc_client_ssh_get_auth_privkey_passphrase_clb()). |
| 250 | * |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 251 | * @param[in] auth_privkey_passphrase Function to call for every question, returns |
| 252 | * the passphrase for the specific private key. |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 253 | * @param[in] priv Optional private data to be passed to the callback function. |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 254 | */ |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 255 | void nc_client_ssh_set_auth_privkey_passphrase_clb(char *(*auth_privkey_passphrase)(const char *privkey_path, void *priv), |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 256 | void *priv); |
Radek Krejci | 90a84a2 | 2017-05-25 13:53:00 +0200 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * @brief Get currently set SSH publickey authentication encrypted private key passphrase callback and its private data |
| 260 | * previously set by nc_client_ssh_set_auth_privkey_passphrase_clb(). |
| 261 | * |
| 262 | * @param[out] auth_privkey_passphrase Currently set callback, NULL in case of the default callback. |
| 263 | * @param[out] priv Currently set (optional) private data to be passed to the callback function. |
| 264 | */ |
| 265 | void nc_client_ssh_get_auth_privkey_passphrase_clb(char *(**auth_privkey_passphrase)(const char *privkey_path, void *priv), |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 266 | void **priv); |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 267 | |
| 268 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 269 | * @brief Add an SSH public and private key pair to be used for client authentication. |
| 270 | * |
| 271 | * Private key can be encrypted, the passphrase will be asked for before using it. |
| 272 | * |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 273 | * @param[in] pub_key Path to the public key. |
| 274 | * @param[in] priv_key Path to the private key. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 275 | * @return 0 on success, -1 on error. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 276 | */ |
| 277 | int nc_client_ssh_add_keypair(const char *pub_key, const char *priv_key); |
| 278 | |
| 279 | /** |
| 280 | * @brief Remove an SSH public and private key pair that was used for client authentication. |
| 281 | * |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 282 | * @param[in] idx Index of the keypair starting with 0. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 283 | * @return 0 on success, -1 on error. |
| 284 | */ |
| 285 | int nc_client_ssh_del_keypair(int idx); |
| 286 | |
| 287 | /** |
| 288 | * @brief Get the number of public an private key pairs set to be used for client authentication. |
| 289 | * |
| 290 | * @return Keypair count. |
| 291 | */ |
| 292 | int nc_client_ssh_get_keypair_count(void); |
| 293 | |
| 294 | /** |
| 295 | * @brief Get a specific keypair set to be used for client authentication. |
| 296 | * |
| 297 | * @param[in] idx Index of the specific keypair. |
| 298 | * @param[out] pub_key Path to the public key. |
| 299 | * @param[out] priv_key Path to the private key. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 300 | * @return 0 on success, -1 on error. |
| 301 | */ |
| 302 | int nc_client_ssh_get_keypair(int idx, const char **pub_key, const char **priv_key); |
| 303 | |
| 304 | /** |
| 305 | * @brief Set SSH authentication method preference. |
| 306 | * |
Radek Krejci | 62aa064 | 2017-05-25 16:33:49 +0200 | [diff] [blame] | 307 | * The default preference is as follows: |
| 308 | * - interactive authentication (3) |
| 309 | * - password authentication (2) |
| 310 | * - public key authentication (1) |
| 311 | * |
| 312 | * @param[in] auth_type Authentication method to modify the preference of. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 313 | * @param[in] pref Preference of @p auth_type. Higher number increases priority, negative values disable the method. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 314 | */ |
| 315 | void nc_client_ssh_set_auth_pref(NC_SSH_AUTH_TYPE auth_type, int16_t pref); |
| 316 | |
| 317 | /** |
| 318 | * @brief Get SSH authentication method preference. |
| 319 | * |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 320 | * @param[in] auth_type Authentication method to retrieve the prefrence of. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 321 | * @return Preference of the @p auth_type. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 322 | */ |
| 323 | int16_t nc_client_ssh_get_auth_pref(NC_SSH_AUTH_TYPE auth_type); |
| 324 | |
| 325 | /** |
| 326 | * @brief Set client SSH username used for authentication. |
| 327 | * |
| 328 | * @param[in] username Username to use. |
| 329 | * @return 0 on success, -1 on error. |
| 330 | */ |
| 331 | int nc_client_ssh_set_username(const char *username); |
| 332 | |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 333 | /** |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 334 | * @brief Get client SSH username used for authentication. |
| 335 | * |
| 336 | * @return Username used. |
| 337 | */ |
| 338 | const char *nc_client_ssh_get_username(void); |
| 339 | |
| 340 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 341 | * @brief Connect to the NETCONF server using SSH transport (via libssh). |
| 342 | * |
| 343 | * SSH session is created with default options. If the caller needs to use specific SSH session properties, |
| 344 | * they are supposed to use nc_connect_libssh(). |
| 345 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 346 | * @param[in] host Hostname or address (both Ipv4 and IPv6 are accepted) of the target server. |
Michal Vasko | df0fa45 | 2022-03-02 11:06:01 +0100 | [diff] [blame] | 347 | * 'localhost' is used by default if NULL is specified. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 348 | * @param[in] port Port number of the target server. Default value 830 is used if 0 is specified. |
Michal Vasko | 94d6140 | 2023-03-16 08:21:52 +0100 | [diff] [blame] | 349 | * @param[in,out] ctx Optional custom context to use for the session. If not set, a default context is created. |
| 350 | * Any YANG modules not present in the context and supported by the server are loaded using \<get-schema\> |
| 351 | * (if supported) and/or by searching the searchpath (see ::nc_client_set_schema_searchpath()). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 352 | * @return Created NETCONF session object or NULL on error. |
| 353 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 354 | struct nc_session *nc_connect_ssh(const char *host, uint16_t port, struct ly_ctx *ctx); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 355 | |
| 356 | /** |
| 357 | * @brief Connect to the NETCONF server using the provided SSH (libssh) session. |
| 358 | * |
| 359 | * SSH session can have any options set, they will not be modified. If no options were set, |
| 360 | * host 'localhost', port 22, and the username detected from the EUID is used. If socket is |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 361 | * set and connected only the host and the username must be set/is detected. Or the @p ssh_session |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 362 | * can already be authenticated in which case it is used directly. |
| 363 | * |
Michal Vasko | df0fa45 | 2022-03-02 11:06:01 +0100 | [diff] [blame] | 364 | * @param[in] ssh_session libssh structure representing SSH session object. It is fully managed by the created session |
| 365 | * including freeing it. |
Michal Vasko | 94d6140 | 2023-03-16 08:21:52 +0100 | [diff] [blame] | 366 | * @param[in,out] ctx Optional custom context to use for the session. If not set, a default context is created. |
| 367 | * Any YANG modules not present in the context and supported by the server are loaded using \<get-schema\> |
| 368 | * (if supported) and/or by searching the searchpath (see ::nc_client_set_schema_searchpath()). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 369 | * @return Created NETCONF session object or NULL on error. |
| 370 | */ |
| 371 | struct nc_session *nc_connect_libssh(ssh_session ssh_session, struct ly_ctx *ctx); |
| 372 | |
| 373 | /** |
| 374 | * @brief Create another NETCONF session on existing SSH session using separated SSH channel. |
| 375 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 376 | * @param[in] session Existing NETCONF session. The session has to be created on SSH transport layer using libssh - |
Michal Vasko | df0fa45 | 2022-03-02 11:06:01 +0100 | [diff] [blame] | 377 | * it has to be created by nc_connect_ssh(), nc_connect_libssh() or nc_connect_ssh_channel(). |
Michal Vasko | 94d6140 | 2023-03-16 08:21:52 +0100 | [diff] [blame] | 378 | * @param[in,out] ctx Optional custom context to use for the session. If not set, a default context is created. |
| 379 | * Any YANG modules not present in the context and supported by the server are loaded using \<get-schema\> |
| 380 | * (if supported) and/or by searching the searchpath (see ::nc_client_set_schema_searchpath()). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 381 | * @return Created NETCONF session object or NULL on error. |
| 382 | */ |
| 383 | struct nc_session *nc_connect_ssh_channel(struct nc_session *session, struct ly_ctx *ctx); |
| 384 | |
Michal Vasko | 4e6d324 | 2021-05-26 09:13:24 +0200 | [diff] [blame] | 385 | /** @} Client SSH */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 386 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 387 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 388 | * @defgroup client_tls Client TLS |
| 389 | * @ingroup client |
| 390 | * |
| 391 | * @brief Client-side settings for TLS connections. |
| 392 | * @{ |
| 393 | */ |
| 394 | |
| 395 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 396 | * @brief Set client authentication identity - a certificate and a private key. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 397 | * |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 398 | * @param[in] client_cert Path to the file containing the client certificate. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 399 | * @param[in] client_key Path to the file containing the private key for the @p client_cert. |
| 400 | * If NULL, key is expected to be stored with @p client_cert. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 401 | * @return 0 on success, -1 on error. |
| 402 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 403 | int nc_client_tls_set_cert_key_paths(const char *client_cert, const char *client_key); |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 404 | |
| 405 | /** |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 406 | * @brief Get client authentication identity - a certificate and a private key. |
| 407 | * |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 408 | * @param[out] client_cert Path to the file containing the client certificate. Can be NULL. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 409 | * @param[out] client_key Path to the file containing the private key for the @p client_cert. Can be NULL. |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 410 | */ |
| 411 | void nc_client_tls_get_cert_key_paths(const char **client_cert, const char **client_key); |
| 412 | |
| 413 | /** |
| 414 | * @brief Set client trusted CA certificates paths. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 415 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 416 | * @param[in] ca_file Location of the CA certificate file used to verify server certificates. |
| 417 | * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL. |
| 418 | * @param[in] ca_dir Location of the CA certificates directory used to verify the server certificates. |
| 419 | * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 420 | * @return 0 on success, -1 on error. |
| 421 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 422 | int nc_client_tls_set_trusted_ca_paths(const char *ca_file, const char *ca_dir); |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 423 | |
| 424 | /** |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 425 | * @brief Get client trusted CA certificates paths. |
| 426 | * |
| 427 | * @param[out] ca_file Location of the CA certificate file used to verify server certificates. |
| 428 | * Can be NULL. |
| 429 | * @param[out] ca_dir Location of the CA certificates directory used to verify the server certificates. |
| 430 | * Can be NULL. |
| 431 | */ |
| 432 | void nc_client_tls_get_trusted_ca_paths(const char **ca_file, const char **ca_dir); |
| 433 | |
| 434 | /** |
| 435 | * @brief Set client Certificate Revocation List paths. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 436 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 437 | * @param[in] crl_file Location of the CRL certificate file used to check for revocated certificates. |
| 438 | * @param[in] crl_dir Location of the CRL certificate directory used to check for revocated certificates. |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 439 | * @return 0 on success, -1 on error. |
| 440 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 441 | int nc_client_tls_set_crl_paths(const char *crl_file, const char *crl_dir); |
| 442 | |
| 443 | /** |
| 444 | * @brief Get client Certificate Revocation List paths. |
| 445 | * |
| 446 | * @param[out] crl_file Location of the CRL certificate file used to check for revocated certificates. |
| 447 | * @param[out] crl_dir Location of the CRL certificate directory used to check for revocated certificates. |
| 448 | */ |
| 449 | void nc_client_tls_get_crl_paths(const char **crl_file, const char **crl_dir); |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 450 | |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 451 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 452 | * @brief Connect to the NETCONF server using TLS transport (via libssl) |
| 453 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 454 | * TLS session is created with the certificates set using nc_client_tls_* functions, which must be called beforehand! |
Michal Vasko | df0fa45 | 2022-03-02 11:06:01 +0100 | [diff] [blame] | 455 | * If the caller needs to use specific TLS session properties, they are supposed to use ::nc_connect_libssl(). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 456 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 457 | * @param[in] host Hostname or address (both Ipv4 and IPv6 are accepted) of the target server. |
Michal Vasko | 9d4cca5 | 2022-09-07 11:19:57 +0200 | [diff] [blame] | 458 | * 'localhost' is used by default if NULL is specified. It is verified by TLS when connecting to it. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 459 | * @param[in] port Port number of the target server. Default value 6513 is used if 0 is specified. |
Michal Vasko | 94d6140 | 2023-03-16 08:21:52 +0100 | [diff] [blame] | 460 | * @param[in,out] ctx Optional custom context to use for the session. If not set, a default context is created. |
| 461 | * Any YANG modules not present in the context and supported by the server are loaded using \<get-schema\> |
| 462 | * (if supported) and/or by searching the searchpath (see ::nc_client_set_schema_searchpath()). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 463 | * @return Created NETCONF session object or NULL on error. |
| 464 | */ |
| 465 | struct nc_session *nc_connect_tls(const char *host, uint16_t port, struct ly_ctx *ctx); |
| 466 | |
| 467 | /** |
| 468 | * @brief Connect to the NETCONF server using the provided TLS (libssl) session. |
| 469 | * |
| 470 | * The TLS session supplied is expected to be fully connected and authenticated! |
| 471 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 472 | * @param[in] tls libssl structure representing the TLS session object. |
Michal Vasko | 94d6140 | 2023-03-16 08:21:52 +0100 | [diff] [blame] | 473 | * @param[in,out] ctx Optional custom context to use for the session. If not set, a default context is created. |
| 474 | * Any YANG modules not present in the context and supported by the server are loaded using \<get-schema\> |
| 475 | * (if supported) and/or by searching the searchpath (see ::nc_client_set_schema_searchpath()). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 476 | * @return Created NETCONF session object or NULL on error. |
| 477 | */ |
| 478 | struct nc_session *nc_connect_libssl(SSL *tls, struct ly_ctx *ctx); |
| 479 | |
Michal Vasko | 4e6d324 | 2021-05-26 09:13:24 +0200 | [diff] [blame] | 480 | /** @} Client TLS */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 481 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 482 | #endif /* NC_ENABLED_SSH_TLS */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 483 | |
| 484 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 485 | * @addtogroup client_session |
| 486 | * @{ |
| 487 | */ |
| 488 | |
| 489 | /** |
Michal Vasko | bdfb524 | 2016-05-24 09:11:01 +0200 | [diff] [blame] | 490 | * @brief Get session capabilities. |
| 491 | * |
| 492 | * @param[in] session Session to get the information from. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 493 | * @return NULL-terminated array of the @p session capabilities. |
Michal Vasko | bdfb524 | 2016-05-24 09:11:01 +0200 | [diff] [blame] | 494 | */ |
Michal Vasko | 1b2ddc9 | 2017-05-24 08:59:49 +0200 | [diff] [blame] | 495 | const char * const *nc_session_get_cpblts(const struct nc_session *session); |
Michal Vasko | bdfb524 | 2016-05-24 09:11:01 +0200 | [diff] [blame] | 496 | |
| 497 | /** |
| 498 | * @brief Check capability presence in a session. |
| 499 | * |
| 500 | * @param[in] session Session to check. |
| 501 | * @param[in] capab Capability to look for, capability with any additional suffix will match. |
| 502 | * @return Matching capability, NULL if none found. |
| 503 | */ |
| 504 | const char *nc_session_cpblt(const struct nc_session *session, const char *capab); |
| 505 | |
| 506 | /** |
Michal Vasko | 9cd26a8 | 2016-05-31 08:58:48 +0200 | [diff] [blame] | 507 | * @brief Check whether the session has a notification thread running. |
| 508 | * |
| 509 | * @param[in] session Session to check. |
| 510 | * @return 1 if notfication thread is running, 0 otherwise. |
| 511 | */ |
| 512 | int nc_session_ntf_thread_running(const struct nc_session *session); |
| 513 | |
| 514 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 515 | * @brief Receive NETCONF RPC reply. |
| 516 | * |
tadeas-vintrlik | 399af30 | 2021-08-25 10:32:21 +0200 | [diff] [blame] | 517 | * @note This function can be called in a single thread only. |
| 518 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 519 | * @param[in] session NETCONF session from which the function gets data. It must be the |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 520 | * client side session object. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 521 | * @param[in] rpc Original RPC this should be the reply to. |
| 522 | * @param[in] msgid Expected message ID of the reply. |
| 523 | * @param[in] timeout Timeout for reading in milliseconds. Use negative value for infinite |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 524 | * waiting and 0 for immediate return if data are not available on the wire. |
| 525 | * @param[out] envp NETCONF rpc-reply XML envelopes. |
| 526 | * @param[out] op Parsed NETCONF reply data, if any (none for \<ok\> or error replies). Set only on #NC_MSG_REPLY |
| 527 | * and #NC_MSG_REPLY_ERR_MSGID return. |
Michal Vasko | 71ba2da | 2016-05-04 10:53:16 +0200 | [diff] [blame] | 528 | * @return #NC_MSG_REPLY for success, |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 529 | * #NC_MSG_WOULDBLOCK if @p timeout has elapsed, |
Michal Vasko | 71ba2da | 2016-05-04 10:53:16 +0200 | [diff] [blame] | 530 | * #NC_MSG_ERROR if reading has failed, |
| 531 | * #NC_MSG_NOTIF if a notification was read instead (call this function again to get the reply), and |
| 532 | * #NC_MSG_REPLY_ERR_MSGID if a reply with missing or wrong message-id was received. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 533 | */ |
Michal Vasko | d083db6 | 2016-01-19 10:31:29 +0100 | [diff] [blame] | 534 | NC_MSG_TYPE nc_recv_reply(struct nc_session *session, struct nc_rpc *rpc, uint64_t msgid, int timeout, |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 535 | struct lyd_node **envp, struct lyd_node **op); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 536 | |
| 537 | /** |
| 538 | * @brief Receive NETCONF Notification. |
| 539 | * |
| 540 | * @param[in] session NETCONF session from which the function gets data. It must be the |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 541 | * client side session object. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 542 | * @param[in] timeout Timeout for reading in milliseconds. Use negative value for infinite |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 543 | * waiting and 0 for immediate return if data are not available on the wire. |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 544 | * @param[out] envp NETCONF notification XML envelopes. |
| 545 | * @param[out] op Parsed NETCONF notification data. |
Michal Vasko | 71ba2da | 2016-05-04 10:53:16 +0200 | [diff] [blame] | 546 | * @return #NC_MSG_NOTIF for success, |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 547 | * #NC_MSG_WOULDBLOCK if @p timeout has elapsed, |
Michal Vasko | 71ba2da | 2016-05-04 10:53:16 +0200 | [diff] [blame] | 548 | * #NC_MSG_ERROR if reading has failed, and |
| 549 | * #NC_MSG_REPLY if a reply was read instead (call this function again to get a notification). |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 550 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 551 | NC_MSG_TYPE nc_recv_notif(struct nc_session *session, int timeout, struct lyd_node **envp, struct lyd_node **op); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 552 | |
| 553 | /** |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 554 | * @brief Callback for receiving notifications in a separate thread. |
| 555 | * |
| 556 | * @param[in] session NC session that received the notification. |
| 557 | * @param[in] envp Notification envelope data tree. |
| 558 | * @param[in] op Notification body data tree. |
| 559 | * @param[in] user_data Arbitrary user data passed to the callback. |
| 560 | */ |
| 561 | typedef void (*nc_notif_dispatch_clb)(struct nc_session *session, const struct lyd_node *envp, const struct lyd_node *op, |
| 562 | void *user_data); |
| 563 | |
| 564 | /** |
Michal Vasko | a8ad448 | 2016-01-28 14:25:54 +0100 | [diff] [blame] | 565 | * @brief Receive NETCONF Notifications in a separate thread until the session is terminated |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 566 | * or \<notificationComplete\> is received. |
Michal Vasko | a8ad448 | 2016-01-28 14:25:54 +0100 | [diff] [blame] | 567 | * |
| 568 | * @param[in] session Netconf session to read notifications from. |
| 569 | * @param[in] notif_clb Function that is called for every received notification (including |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 570 | * \<notificationComplete\>). Parameters are the session the notification was received on |
| 571 | * and the notification data. |
Michal Vasko | a8ad448 | 2016-01-28 14:25:54 +0100 | [diff] [blame] | 572 | * @return 0 if the thread was successfully created, -1 on error. |
| 573 | */ |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 574 | int nc_recv_notif_dispatch(struct nc_session *session, nc_notif_dispatch_clb notif_clb); |
| 575 | |
| 576 | /** |
| 577 | * @brief Receive NETCONF Notifications in a separate thread until the session is terminated |
| 578 | * or \<notificationComplete\> is received. Similar to ::nc_recv_notif_dispatch() but allows |
| 579 | * to set arbitrary user data that can be freed as well. |
| 580 | * |
| 581 | * @param[in] session Netconf session to read notifications from. |
| 582 | * @param[in] notif_clb Callback that is called for every received notification (including |
| 583 | * \<notificationComplete\>). Parameters are the session the notification was received on |
| 584 | * and the notification data. |
| 585 | * @param[in] user_data Arbitrary user data. |
| 586 | * @param[in] free_data Callback for freeing the user data after notif thread exit. |
| 587 | * @return 0 if the thread was successfully created, -1 on error. |
| 588 | */ |
| 589 | int nc_recv_notif_dispatch_data(struct nc_session *session, nc_notif_dispatch_clb notif_clb, void *user_data, |
| 590 | void (*free_data)(void *)); |
Michal Vasko | a8ad448 | 2016-01-28 14:25:54 +0100 | [diff] [blame] | 591 | |
| 592 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 593 | * @brief Send NETCONF RPC message via the session. |
| 594 | * |
| 595 | * @param[in] session NETCONF session where the RPC will be written. |
Michal Vasko | 66fa9b9 | 2021-10-26 10:48:13 +0200 | [diff] [blame] | 596 | * @param[in] rpc NETCONF RPC object to send via the specified session. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 597 | * @param[in] timeout Timeout for writing in milliseconds. Use negative value for infinite |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 598 | * waiting and 0 for return if data cannot be sent immediately. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 599 | * @param[out] msgid If RPC was successfully sent, this is it's message ID. |
Michal Vasko | 71ba2da | 2016-05-04 10:53:16 +0200 | [diff] [blame] | 600 | * @return #NC_MSG_RPC on success, |
| 601 | * #NC_MSG_WOULDBLOCK in case of a busy session, and |
| 602 | * #NC_MSG_ERROR on error. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 603 | */ |
Michal Vasko | d083db6 | 2016-01-19 10:31:29 +0100 | [diff] [blame] | 604 | NC_MSG_TYPE nc_send_rpc(struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_t *msgid); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 605 | |
Michal Vasko | de2946c | 2017-01-12 12:19:26 +0100 | [diff] [blame] | 606 | /** |
| 607 | * @brief Make a session not strict when sending RPCs and receiving RPC replies. In other words, |
Michal Vasko | ffb35e9 | 2022-10-20 09:07:25 +0200 | [diff] [blame] | 608 | * it will silently skip unknown nodes without an error. |
Michal Vasko | de2946c | 2017-01-12 12:19:26 +0100 | [diff] [blame] | 609 | * |
| 610 | * Generally, no such data should be worked with, so use this function only when you know what you |
| 611 | * are doing and you understand the consequences. |
| 612 | * |
| 613 | * @param[in] session NETCONF client session. |
| 614 | */ |
| 615 | void nc_client_session_set_not_strict(struct nc_session *session); |
| 616 | |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 617 | /** @} Client Session */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 618 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 619 | #ifdef __cplusplus |
| 620 | } |
| 621 | #endif |
| 622 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 623 | #endif /* NC_SESSION_CLIENT_H_ */ |