blob: 27ba007f8d3693e6586a81057e0f85058391ff34 [file] [log] [blame]
Radek Krejcid0d19522015-09-02 13:49:25 +02001/**
Michal Vaskoc446a382021-06-18 08:54:05 +02002 * @file libnetconf.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @author Michal Vasko <mvasko@cesnet.cz>
5 * @brief libnetconf2 main internal header.
Radek Krejcid0d19522015-09-02 13:49:25 +02006 *
Michal Vasko95ea9ff2021-11-09 12:29:14 +01007 * @copyright
Michal Vaskoc446a382021-06-18 08:54:05 +02008 * Copyright (c) 2015 - 2021 CESNET, z.s.p.o.
Radek Krejcid0d19522015-09-02 13:49:25 +02009 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010010 * This source code is licensed under BSD 3-Clause License (the "License").
11 * You may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010013 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010014 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejcid0d19522015-09-02 13:49:25 +020015 */
16
17#ifndef NC_LIBNETCONF_H_
18#define NC_LIBNETCONF_H_
19
20#include "config.h"
21#include "log_p.h"
Radek Krejciac6d3472015-10-22 15:47:18 +020022#include "messages_p.h"
Michal Vaskob83a3fa2021-05-26 09:53:42 +020023#include "netconf.h"
24#include "session_p.h"
Radek Krejciac6d3472015-10-22 15:47:18 +020025
26/* Tests whether string is empty or non-empty. */
27#define strisempty(str) ((str)[0] == '\0')
28#define strnonempty(str) ((str)[0] != '\0')
Radek Krejcid0d19522015-09-02 13:49:25 +020029
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010030/**
31 * @mainpage About
32 *
33 * libnetconf2 is a NETCONF library in C handling NETCONF authentication and all NETCONF
Radek Krejcib62d5b42017-05-19 10:20:00 +020034 * RPC communication both server and client-side. Note that NETCONF datastore implementation
35 * is not a part of this library. The library supports both NETCONF 1.0
36 * ([RFC 4741](https://tools.ietf.org/html/rfc4741)) as well as NETCONF 1.1
37 * ([RFC 6241](https://tools.ietf.org/html/rfc6241)).
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010038 *
39 * @section about-features Main Features
40 *
Radek Krejcib62d5b42017-05-19 10:20:00 +020041 * - Creating SSH ([RFC 4742](https://tools.ietf.org/html/rfc4742), [RFC 6242](https://tools.ietf.org/html/rfc6242)),
42 * using [libssh](https://www.libssh.org/), or TLS ([RFC 7589](https://tools.ietf.org/html/rfc7589)),
43 * using [OpenSSL](https://www.openssl.org/), authenticated NETCONF sessions.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010044 * - Creating NETCONF sessions with a pre-established transport protocol
45 * (using this mechanism the communication can be tunneled through sshd(8), for instance).
Radek Krejcib62d5b42017-05-19 10:20:00 +020046 * - Creating NETCONF Call Home sessions ([RFC 8071](https://tools.ietf.org/html/rfc8071)).
47 * - Creating, sending, receiving, and replying to RPCs ([RFC 4741](https://tools.ietf.org/html/rfc4741),
48 * [RFC 6241](https://tools.ietf.org/html/rfc6241)).
49 * - Creating, sending and receiving NETCONF Event Notifications ([RFC 5277](https://tools.ietf.org/html/rfc5277)),
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010050 *
51 * @section about-license License
52 *
Michal Vasko4e6d3242021-05-26 09:13:24 +020053 * Copyright (c) 2015-2021 CESNET, z.s.p.o.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010054 *
55 * (The BSD 3-Clause License)
56 *
57 * Redistribution and use in source and binary forms, with or without
58 * modification, are permitted provided that the following conditions
59 * are met:
60 * 1. Redistributions of source code must retain the above copyright
61 * notice, this list of conditions and the following disclaimer.
62 * 2. Redistributions in binary form must reproduce the above copyright
63 * notice, this list of conditions and the following disclaimer in
64 * the documentation and/or other materials provided with the
65 * distribution.
66 * 3. Neither the name of the Company nor the names of its contributors
67 * may be used to endorse or promote products derived from this
68 * software without specific prior written permission.
69 */
70
71/**
72 * @page howto How To ...
73 *
74 * - @subpage howtoinit
75 * - @subpage howtoclient
76 * - @subpage howtoserver
77 * - @subpage howtoclientcomm
78 * - @subpage howtoservercomm
Michal Vaskoee087c62017-02-15 11:27:16 +010079 * - @subpage howtotimeouts
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010080 */
81
82/**
83 * @page howtoinit Init and Thread-safety Information
84 *
Michal Vasko4e6d3242021-05-26 09:13:24 +020085 * Before working with the library, it must be initialized using ::nc_client_init()
86 * or ::nc_server_init(). Based on how the library was compiled, also _libssh_ and/or
Radek Krejci5cebc6b2017-05-26 13:24:38 +020087 * _libssh_/_libcrypto_ are initialized (for multi-threaded use) too. To prevent
88 * any reachable memory at the end of your application, there are complementary
Michal Vasko4e6d3242021-05-26 09:13:24 +020089 * destroy functions (::nc_server_destroy() and ::nc_client_destroy() available. If your
Radek Krejci5cebc6b2017-05-26 13:24:38 +020090 * application is multi-threaded, call the destroy functions in the main thread,
91 * after all the other threads have ended. In every other thread you should call
Michal Vasko4e6d3242021-05-26 09:13:24 +020092 * ::nc_thread_destroy() just before it exits.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010093 *
Michal Vasko15b7a982016-03-02 10:53:31 +010094 * If _libnetconf2_ is used in accordance with this information, there should
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010095 * not be memory leaks of any kind at program exit. For thread-safety details
Michal Vasko15b7a982016-03-02 10:53:31 +010096 * of _libssh_, _libssl_, and _libcrypto_, please refer to the corresponding project
97 * documentation. _libnetconf2_ thread-safety information is below.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010098 *
Radek Krejci5cebc6b2017-05-26 13:24:38 +020099 * Client
100 * ------
101 *
Radek Krejcifd5b6682017-06-13 15:52:53 +0200102 * Optionally, a client can specify two alternative ways to get schemas needed when connecting
103 * with a server. The primary way is to read local files in searchpath (and its subdirectories)
Michal Vasko4e6d3242021-05-26 09:13:24 +0200104 * specified via ::nc_client_set_schema_searchpath(). Alternatively, _libnetconf2_ can use callback
105 * provided via ::nc_client_set_schema_callback(). If these ways do not succeed and the server
Radek Krejcifd5b6682017-06-13 15:52:53 +0200106 * implements NETCONF \<get-schema\> operation, the schema is retrieved from the server and stored
107 * localy into the searchpath (if specified) for a future use. If none of these methods succeed to
108 * load particular schema, the data from this schema are ignored during the communication with the
109 * server.
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200110 *
Radek Krejcifd5b6682017-06-13 15:52:53 +0200111 * Besides the mentioned setters, there are many other @ref howtoclientssh "SSH", @ref howtoclienttls "TLS"
112 * and @ref howtoclientch "Call Home" getter/setter functions to manipulate with various settings. All these
113 * settings are internally placed in a thread-specific context so they are independent and
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200114 * initialized to the default values within each new thread. However, the context can be shared among
Michal Vasko4e6d3242021-05-26 09:13:24 +0200115 * the threads using ::nc_client_get_thread_context() and ::nc_client_set_thread_context() functions. In such
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200116 * a case, be careful and avoid concurrent execution of the mentioned setters/getters and functions
117 * creating connection (no matter if it is a standard NETCONF connection or Call Home).
118 *
Michal Vasko2d1e8d32023-03-15 07:29:09 +0100119 * In the client, it is always thread-safe to work with a NETCONF session in a single thread since the client
120 * settings are thread-specific as described above. Generally, one can access a session in several threads
121 * as well but there is little incentive to do so.
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200122 *
123 * Server
124 * ------
125 *
126 * Server is __FULLY__ thread-safe meaning you can set all the (thread-shared in contrast to
127 * client) options simultaneously while listening for or accepting new sessions or
Michal Vaskoade892d2017-02-22 13:40:35 +0100128 * polling the existing ones. It is even safe to poll one session in several
129 * pollsession structures or one pollsession structure in several threads. Generally,
130 * servers can use more threads without any problems as long as they keep their workflow sane
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100131 * (behavior such as freeing sessions only after no thread uses them or similar).
132 *
133 * Functions List
134 * --------------
135 *
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100136 * Available in __nc_client.h__.
137 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200138 * - ::nc_client_init()
139 * - ::nc_client_destroy()
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100140 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200141 * - ::nc_client_set_schema_searchpath()
142 * - ::nc_client_get_schema_searchpath()
143 * - ::nc_client_set_schema_callback()
144 * - ::nc_client_get_schema_callback()
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200145 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200146 * - ::nc_client_set_thread_context()
147 * - ::nc_client_get_thread_context()
Michal Vasko26394692016-03-17 16:24:55 +0100148 *
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100149 * Available in __nc_server.h__.
150 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200151 * - ::nc_server_init()
152 * - ::nc_server_destroy()
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100153 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100154 * Available in both __nc_client.h__ and __nc_server.h__.
155 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200156 * - ::nc_thread_destroy()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100157 */
158
159/**
160 * @page howtoclient Client sessions
161 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100162 * To connect to a NETCONF server, a NETCONF session must be established,
163 * which requires a working transport session. It is possible to create
164 * NETCONF sessions with SSH (using _libssh_) or TLS (using _libssl/libcrypto_)
165 * as the underlying transport protocol. It is also possible to establish
166 * the transport protocol outside _libnetconf2_ and then provide these file
167 * descriptors (FD) for full NETCONF session creation.
168 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100169 * There are a lot of options for both an SSH and a TLS client. All of them
170 * have setters and getters so that there is no need to duplicate them in
171 * a client.
172 *
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200173 * @anchor howtoclientssh
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100174 * SSH
175 * ===
176 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100177 * Connecting to a server using SSH does not strictly require to set any
178 * options, there are sensible default values for all the basic ones.
179 * Except all the SSH options, optionally some authetication callbacks can be set,
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100180 * which are particulary useful in automated clients (passwords cannot be
181 * asked a user) or simply if any additional information is retrieved some
182 * other way than from standard terminal input.
183 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100184 * Having the default options or changing any unsuitable ones, there are 2 functions
Michal Vasko4e6d3242021-05-26 09:13:24 +0200185 * to use for a new server connection. ::nc_connect_ssh() is the standard function
Michal Vasko15b7a982016-03-02 10:53:31 +0100186 * that creates sessions using the set options. If there are some options, which
Michal Vasko4e6d3242021-05-26 09:13:24 +0200187 * cannot be changed with the provided API, there is ::nc_connect_libssh() available.
Michal Vasko15b7a982016-03-02 10:53:31 +0100188 * It requires a _libssh_ session, in which all the SSH options can be modified
189 * and even the connection established. This allows for full customization and
190 * should fit any specific situation.
191 *
192 * New NETCONF sessions can also be created on existing authenticated SSH sessions.
193 * There is a new SSH channel needed, on which the NETCONF session is then created.
Michal Vasko4e6d3242021-05-26 09:13:24 +0200194 * Use ::nc_connect_ssh_channel() for this purpose.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100195 *
196 * Functions List
197 * --------------
198 *
199 * Available in __nc_client.h__.
200 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200201 * - ::nc_client_ssh_set_auth_hostkey_check_clb()
202 * - ::nc_client_ssh_get_auth_hostkey_check_clb()
203 * - ::nc_client_ssh_set_auth_password_clb()
204 * - ::nc_client_ssh_get_auth_password_clb()
205 * - ::nc_client_ssh_set_auth_interactive_clb()
206 * - ::nc_client_ssh_get_auth_interactive_clb()
207 * - ::nc_client_ssh_set_auth_privkey_passphrase_clb()
208 * - ::nc_client_ssh_get_auth_privkey_passphrase_clb()
209 * - ::nc_client_ssh_add_keypair()
210 * - ::nc_client_ssh_del_keypair()
211 * - ::nc_client_ssh_get_keypair_count()
212 * - ::nc_client_ssh_get_keypair()
213 * - ::nc_client_ssh_set_auth_pref()
214 * - ::nc_client_ssh_get_auth_pref()
215 * - ::nc_client_ssh_set_username()
216 * - ::nc_client_ssh_get_username()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100217 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200218 * - ::nc_connect_ssh()
219 * - ::nc_connect_libssh()
220 * - ::nc_connect_ssh_channel()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100221 *
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200222 * @anchor howtoclienttls
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100223 * TLS
224 * ===
225 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100226 * To connect to a server using TLS, there must be some client identification
227 * options set. Client must specify its certificate with a private key using
Michal Vasko4e6d3242021-05-26 09:13:24 +0200228 * ::nc_client_tls_set_cert_key_paths(). Also, the Certificate Authority of
Michal Vasko15b7a982016-03-02 10:53:31 +0100229 * a server certificate must be considered trusted. Paths to all the trusted
Michal Vasko4e6d3242021-05-26 09:13:24 +0200230 * CA certificates can be set by ::nc_client_tls_set_trusted_ca_paths().
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100231 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200232 * Then there are again 2 functions for connecting, ::nc_connect_tls() being
233 * the standard way of connecting. ::nc_connect_libssl() again enables
Michal Vasko15b7a982016-03-02 10:53:31 +0100234 * to customize the TLS session in every way _libssl_ allows.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100235 *
236 * Functions List
237 * --------------
238 *
239 * Available in __nc_client.h__.
240 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200241 * - ::nc_client_tls_set_cert_key_paths()
242 * - ::nc_client_tls_get_cert_key_paths()
243 * - ::nc_client_tls_set_trusted_ca_paths()
244 * - ::nc_client_tls_get_trusted_ca_paths()
245 * - ::nc_client_tls_set_crl_paths()
246 * - ::nc_client_tls_get_crl_paths()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100247 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200248 * - ::nc_connect_tls()
249 * - ::nc_connect_libssl()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100250 *
251 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200252 * FD and UNIX socket
253 * ==================
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100254 *
255 * If you authenticated the connection using some tunneling software, you
Michal Vasko4e6d3242021-05-26 09:13:24 +0200256 * can pass its file descriptors to _libnetconf2_ using ::nc_connect_inout(),
257 * which will continue to establish a full NETCONF session. To connect locally
258 * on a UNIX socket avoiding all cryptography use ::nc_connect_unix().
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100259 *
260 * Funtions List
261 * -------------
262 *
263 * Available in __nc_client.h__.
264 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200265 * - ::nc_connect_inout()
266 * - ::nc_connect_unix()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100267 *
268 *
Radek Krejci5cebc6b2017-05-26 13:24:38 +0200269 * @anchor howtoclientch
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100270 * Call Home
271 * =========
272 *
273 * Call Home needs the same options set as standard SSH or TLS and the functions
274 * reflect it exactly. However, to accept a connection, the client must first
Michal Vasko4e6d3242021-05-26 09:13:24 +0200275 * specify addresses and ports, which to listen on by ::nc_client_ssh_ch_add_bind_listen()
276 * and ::nc_client_tls_ch_add_bind_listen(). Then connections can be
277 * accepted using ::nc_accept_callhome().
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100278 *
279 * Functions List
280 * --------------
281 *
282 * Available in __nc_client.h__.
283 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200284 * - ::nc_client_ssh_ch_set_auth_hostkey_check_clb()
285 * - ::nc_client_ssh_ch_set_auth_password_clb()
286 * - ::nc_client_ssh_ch_set_auth_interactive_clb()
287 * - ::nc_client_ssh_ch_set_auth_privkey_passphrase_clb()
288 * - ::nc_client_ssh_ch_add_bind_listen()
289 * - ::nc_client_ssh_ch_del_bind()
290 * - ::nc_client_ssh_ch_add_keypair()
291 * - ::nc_client_ssh_ch_del_keypair()
292 * - ::nc_client_ssh_ch_get_keypair_count()
293 * - ::nc_client_ssh_ch_get_keypair()
294 * - ::nc_client_ssh_ch_set_auth_pref()
295 * - ::nc_client_ssh_ch_get_auth_pref()
296 * - ::nc_client_ssh_ch_set_username()
297 * - ::nc_client_ssh_ch_get_username()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100298 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200299 * - ::nc_client_tls_ch_add_bind_listen()
300 * - ::nc_client_tls_ch_del_bind()
301 * - ::nc_client_tls_ch_set_cert_key_paths()
302 * - ::nc_client_tls_ch_get_cert_key_paths()
303 * - ::nc_client_tls_ch_set_trusted_ca_paths()
304 * - ::nc_client_tls_ch_get_trusted_ca_paths()
305 * - ::nc_client_tls_ch_set_crl_paths()
306 * - ::nc_client_tls_ch_get_crl_paths()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100307 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200308 * - ::nc_accept_callhome()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100309 *
310 *
311 * Cleanup
312 * =======
313 *
314 * These options and the schema searchpath are stored in dynamically
Michal Vasko15b7a982016-03-02 10:53:31 +0100315 * allocated memory. They are freed as a part of [destroying the client](@ref howtoinit).
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100316 */
317
318/**
319 * @page howtoserver Server sessions
320 *
321 * Init
322 * ====
323 *
Michal Vasko93224072021-11-09 12:14:28 +0100324 * Server must start with [initialization](@ref howtoinit). Its capabilities are
325 * determined by the context used when accepting new NETCONF sessions. Few capabilities that
Michal Vasko15b7a982016-03-02 10:53:31 +0100326 * cannot be learnt from the context are set with separate functions
Michal Vasko4e6d3242021-05-26 09:13:24 +0200327 * ::nc_server_set_capab_withdefaults() and generally ::nc_server_set_capability().
Michal Vasko15b7a982016-03-02 10:53:31 +0100328 * Timeout for receiving the _hello_ message on a new session can be set
Michal Vasko4e6d3242021-05-26 09:13:24 +0200329 * by ::nc_server_set_hello_timeout() and the timeout for disconnecting
330 * an inactive session by ::nc_server_set_idle_timeout().
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100331 *
332 * Context does not only determine server modules, but its overall
333 * functionality as well. For every RPC the server should support,
Michal Vasko4e6d3242021-05-26 09:13:24 +0200334 * an nc_rpc_clb callback should be set on that node in the context using ::nc_set_rpc_callback().
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100335 * Server then calls these as appropriate [during poll](@ref howtoservercomm).
336 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100337 * Just like in the [client](@ref howtoclient), you can let _libnetconf2_
338 * establish SSH or TLS transport or do it yourself and only provide the file
339 * descriptors of the connection.
340 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100341 * Server options can be only set, there are no getters.
342 *
Michal Vaskod31b76e2017-02-15 12:18:06 +0100343 * To be able to accept any connections, endpoints must first be added
Michal Vasko4e6d3242021-05-26 09:13:24 +0200344 * with ::nc_server_add_endpt() and configured with ::nc_server_endpt_set_address()
345 * and ::nc_server_endpt_set_port(). For unix sockets, ::nc_server_endpt_set_perms()
346 * is available to set the unix socket file permissions, and ::nc_server_endpt_set_port()
Olivier Matzac7fa2f2018-10-11 10:02:04 +0200347 * is invalid.
Michal Vasko3a889fd2016-09-30 12:16:37 +0200348 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100349 * Functions List
350 * --------------
351 *
352 * Available in __nc_server.h__.
353 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200354 * - ::nc_server_set_capab_withdefaults()
355 * - ::nc_server_set_capability()
356 * - ::nc_server_set_hello_timeout()
357 * - ::nc_server_set_idle_timeout()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100358 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200359 * - ::nc_server_add_endpt()
360 * - ::nc_server_del_endpt()
361 * - ::nc_server_endpt_set_address()
362 * - ::nc_server_endpt_set_port()
363 * - ::nc_server_endpt_set_perms()
Michal Vasko3a889fd2016-09-30 12:16:37 +0200364 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100365 *
366 * SSH
367 * ===
368 *
Michal Vaskod31b76e2017-02-15 12:18:06 +0100369 * To successfully accept an SSH session you must set at least the host key using
Michal Vasko4e6d3242021-05-26 09:13:24 +0200370 * ::nc_server_ssh_endpt_add_hostkey(), which are ordered. This way you simply add
Michal Vaskod31b76e2017-02-15 12:18:06 +0100371 * some hostkey identifier, but the key itself will be retrieved always when needed
Michal Vasko4e6d3242021-05-26 09:13:24 +0200372 * by calling the callback set by ::nc_server_ssh_set_hostkey_clb().
Michal Vaskod31b76e2017-02-15 12:18:06 +0100373 *
374 * There are also some other optional settings. Note that authorized
375 * public keys are set for the server as a whole, not endpoint-specifically.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100376 *
377 * Functions List
378 * --------------
379 *
380 * Available in __nc_server.h__.
381 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200382 * - ::nc_server_ssh_endpt_add_hostkey()
383 * - ::nc_server_ssh_endpt_del_hostkey()
384 * - ::nc_server_ssh_endpt_mov_hostkey()
385 * - ::nc_server_ssh_endpt_mod_hostkey()
386 * - ::nc_server_ssh_endpt_set_auth_methods()
387 * - ::nc_server_ssh_endpt_set_auth_attempts()
388 * - ::nc_server_ssh_endpt_set_auth_timeout()
Michal Vaskod31b76e2017-02-15 12:18:06 +0100389 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200390 * - ::nc_server_ssh_set_hostkey_clb()
Michal Vaskod31b76e2017-02-15 12:18:06 +0100391 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200392 * - ::nc_server_ssh_add_authkey()
393 * - ::nc_server_ssh_add_authkey_path()
394 * - ::nc_server_ssh_del_authkey()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100395 *
396 *
397 * TLS
398 * ===
399 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100400 * TLS works with endpoints too, but its options differ
401 * significantly from the SSH ones, especially in the _cert-to-name_
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100402 * options that TLS uses to derive usernames from client certificates.
Michal Vaskod31b76e2017-02-15 12:18:06 +0100403 * So, after starting listening on an endpoint you need to set the server
Michal Vasko4e6d3242021-05-26 09:13:24 +0200404 * certificate (::nc_server_tls_endpt_set_server_cert()). Its actual content
Michal Vaskod31b76e2017-02-15 12:18:06 +0100405 * together with the matching private key will be loaded using a callback
Michal Vasko4e6d3242021-05-26 09:13:24 +0200406 * from ::nc_server_tls_set_server_cert_clb(). Additional certificates needed
Andrew Langefeld440b6c72018-08-27 16:26:20 -0500407 * for the client to verify the server's certificate chain can be loaded using
Michal Vasko4e6d3242021-05-26 09:13:24 +0200408 * a callback from ::nc_server_tls_set_server_cert_chain_clb().
Michal Vasko15b7a982016-03-02 10:53:31 +0100409 *
410 * To accept client certificates, they must first be considered trusted,
411 * which you have three ways of achieving. You can add each of their Certificate Authority
412 * certificates to the trusted ones or mark a specific client certificate
Michal Vaskod31b76e2017-02-15 12:18:06 +0100413 * as trusted. Lastly, you can set paths with all the trusted CA certificates
Michal Vasko4e6d3242021-05-26 09:13:24 +0200414 * with ::nc_server_tls_endpt_set_trusted_ca_paths(). Adding specific certificates
Michal Vaskod31b76e2017-02-15 12:18:06 +0100415 * is also performed only as an arbitrary identificator and later retrieved from
Michal Vasko4e6d3242021-05-26 09:13:24 +0200416 * callback set by ::nc_server_tls_set_trusted_cert_list_clb(). But, you can add
Michal Vaskod31b76e2017-02-15 12:18:06 +0100417 * certficates as whole lists, not one-by-one.
Michal Vasko15b7a982016-03-02 10:53:31 +0100418 *
419 * Then, from each trusted client certificate a username must be derived
420 * for the NETCONF session. This is accomplished by finding a matching
Michal Vasko4e6d3242021-05-26 09:13:24 +0200421 * _cert-to-name_ entry. They are added using ::nc_server_tls_endpt_add_ctn().
Michal Vasko15b7a982016-03-02 10:53:31 +0100422 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200423 * If you need to remove trusted certificates, you can do so with ::nc_server_tls_endpt_del_trusted_cert_list().
424 * To clear all Certificate Revocation Lists use ::nc_server_tls_endpt_clear_crls().
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100425 *
426 * Functions List
427 * --------------
428 *
429 * Available in __nc_server.h__.
430 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200431 * - ::nc_server_tls_endpt_set_server_cert()
432 * - ::nc_server_tls_endpt_add_trusted_cert_list()
433 * - ::nc_server_tls_endpt_del_trusted_cert_list()
434 * - ::nc_server_tls_endpt_set_trusted_ca_paths()
435 * - ::nc_server_tls_endpt_set_crl_paths()
436 * - ::nc_server_tls_endpt_clear_crls()
437 * - ::nc_server_tls_endpt_add_ctn()
438 * - ::nc_server_tls_endpt_del_ctn()
439 * - ::nc_server_tls_endpt_get_ctn()
Michal Vaskod31b76e2017-02-15 12:18:06 +0100440 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200441 * - ::nc_server_tls_set_server_cert_clb()
442 * - ::nc_server_tls_set_server_cert_chain_clb()
443 * - ::nc_server_tls_set_trusted_cert_list_clb()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100444 *
445 * FD
446 * ==
447 *
448 * If you used a tunneling software, which does its own authentication,
Michal Vasko15b7a982016-03-02 10:53:31 +0100449 * you can accept a NETCONF session on its file descriptors with
Michal Vasko4e6d3242021-05-26 09:13:24 +0200450 * ::nc_accept_inout().
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100451 *
452 * Functions List
453 * --------------
454 *
455 * Available in __nc_server.h__.
456 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200457 * - ::nc_accept_inout()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100458 *
459 *
460 * Call Home
461 * =========
462 *
Michal Vaskod31b76e2017-02-15 12:18:06 +0100463 * _Call Home_ works with endpoints just like standard sessions, but
464 * the options are organized a bit differently and endpoints are added
465 * for CH clients. However, one important difference is that
466 * once all the mandatory options are set, _libnetconf2_ __will not__
467 * immediately start connecting to a client. It will do so only after
Michal Vasko4e6d3242021-05-26 09:13:24 +0200468 * calling ::nc_connect_ch_client_dispatch() in a separate thread.
Michal Vaskod31b76e2017-02-15 12:18:06 +0100469 *
470 * Lastly, monitoring of these sessions is up to the application.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100471 *
472 * Functions List
473 * --------------
474 *
475 * Available in __nc_server.h__.
476 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200477 * - ::nc_server_ch_add_client()
478 * - ::nc_server_ch_del_client()
479 * - ::nc_server_ch_is_client()
480 * - ::nc_server_ch_client_add_endpt()
481 * - ::nc_server_ch_client_del_endpt()
482 * - ::nc_server_ch_client_is_endpt()
483 * - ::nc_server_ch_client_endpt_set_address()
484 * - ::nc_server_ch_client_endpt_set_port()
485 * - ::nc_server_ch_client_endpt_enable_keepalives()
486 * - ::nc_server_ch_client_endpt_set_keepalives()
487 * - ::nc_server_ch_client_set_conn_type()
488 * - ::nc_server_ch_client_periodic_set_period()
489 * - ::nc_server_ch_client_periodic_set_anchor_time()
490 * - ::nc_server_ch_client_periodic_set_idle_timeout()
491 * - ::nc_server_ch_client_set_start_with()
492 * - ::nc_server_ch_client_set_max_attempts()
493 * - ::nc_connect_ch_client_dispatch()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100494 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200495 * - ::nc_server_ssh_ch_client_endpt_add_hostkey()
496 * - ::nc_server_ssh_ch_client_endpt_del_hostkey()
497 * - ::nc_server_ssh_ch_client_endpt_mov_hostkey()
498 * - ::nc_server_ssh_ch_client_endpt_set_auth_methods()
499 * - ::nc_server_ssh_ch_client_endpt_get_auth_methods()
500 * - ::nc_server_ssh_ch_client_endpt_set_auth_attempts()
501 * - ::nc_server_ssh_ch_client_endpt_set_auth_timeout()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100502 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200503 * - ::nc_server_tls_ch_client_endpt_set_server_cert()
504 * - ::nc_server_tls_ch_client_endpt_add_trusted_cert_list()
505 * - ::nc_server_tls_ch_client_endpt_del_trusted_cert_list()
506 * - ::nc_server_tls_ch_client_endpt_set_trusted_ca_paths()
507 * - ::nc_server_tls_ch_client_endpt_set_crl_paths()
508 * - ::nc_server_tls_ch_client_endpt_clear_crls()
509 * - ::nc_server_tls_ch_client_endpt_add_ctn()
510 * - ::nc_server_tls_ch_client_endpt_del_ctn()
511 * - ::nc_server_tls_ch_client_endpt_get_ctn()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100512 *
513 *
514 * Connecting And Cleanup
515 * ======================
516 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200517 * When accepting connections with ::nc_accept(), all the endpoints are examined
Michal Vaskod31b76e2017-02-15 12:18:06 +0100518 * and the first with a pending connection is used. To remove all CH clients,
519 * endpoints, and free any used dynamic memory, [destroy](@ref howtoinit) the server.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100520 *
521 * Functions List
522 * --------------
523 *
524 * Available in __nc_server.h__.
525 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200526 * - ::nc_accept()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100527 */
528
529/**
530 * @page howtoclientcomm Client communication
531 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200532 * To send RPCs on a session, you simply create an RPC, send it using ::nc_send_rpc(),
533 * and then wait for a reply using ::nc_recv_reply(). If you are subscribed, there are 2 ways
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100534 * of receiving notifications. Either you wait for them the same way
Michal Vasko4e6d3242021-05-26 09:13:24 +0200535 * as for standard replies with ::nc_recv_notif() or you create a dispatcher
536 * with ::nc_recv_notif_dispatch() that asynchronously (in a separate thread)
Michal Vasko15b7a982016-03-02 10:53:31 +0100537 * reads notifications and passes them to your callback.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100538 *
539 * Functions List
540 * --------------
541 *
542 * Available in __nc_client.h__.
543 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200544 * - ::nc_rpc_act_generic()
545 * - ::nc_rpc_act_generic_xml()
546 * - ::nc_rpc_getconfig()
547 * - ::nc_rpc_edit()
548 * - ::nc_rpc_copy()
549 * - ::nc_rpc_delete()
550 * - ::nc_rpc_lock()
551 * - ::nc_rpc_unlock()
552 * - ::nc_rpc_get()
553 * - ::nc_rpc_kill()
554 * - ::nc_rpc_commit()
555 * - ::nc_rpc_discard()
556 * - ::nc_rpc_cancel()
557 * - ::nc_rpc_validate()
558 * - ::nc_rpc_getschema()
559 * - ::nc_rpc_subscribe()
560 * - ::nc_rpc_getdata()
561 * - ::nc_rpc_editdata()
562 * - ::nc_rpc_establishsub()
563 * - ::nc_rpc_modifysub()
564 * - ::nc_rpc_deletesub()
565 * - ::nc_rpc_killsub()
566 * - ::nc_rpc_establishpush_periodic()
567 * - ::nc_rpc_establishpush_onchange()
568 * - ::nc_rpc_modifypush_periodic()
569 * - ::nc_rpc_modifypush_onchange()
570 * - ::nc_rpc_resyncsub()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100571 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200572 * - ::nc_send_rpc()
573 * - ::nc_recv_reply()
574 * - ::nc_recv_notif()
575 * - ::nc_recv_notif_dispatch()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100576 */
577
578/**
579 * @page howtoservercomm Server communication
580 *
581 * Once at least one session is established, an nc_pollsession structure
Michal Vasko4e6d3242021-05-26 09:13:24 +0200582 * should be created with ::nc_ps_new(), filled with the session using
583 * ::nc_ps_add_session() and finally polled with ::nc_ps_poll(). Based on
Michal Vasko15b7a982016-03-02 10:53:31 +0100584 * the return value from the poll, further actions can be taken. More
585 * sessions can be polled at the same time and any requests received on
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100586 * the sessions are [handled internally](@ref howtoserver).
587 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100588 * If an SSH NETCONF session asks for a new channel, you can accept
Michal Vasko4e6d3242021-05-26 09:13:24 +0200589 * this request with ::nc_ps_accept_ssh_channel() or ::nc_session_accept_ssh_channel()
Michal Vasko3a889fd2016-09-30 12:16:37 +0200590 * depending on the structure you want to use as the argument.
Michal Vasko15b7a982016-03-02 10:53:31 +0100591 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100592 * Functions List
593 * --------------
594 *
Michal Vasko15b7a982016-03-02 10:53:31 +0100595 * Available in __nc_server.h__.
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100596 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200597 * - ::nc_ps_new()
598 * - ::nc_ps_add_session()
599 * - ::nc_ps_del_session()
600 * - ::nc_ps_session_count()
601 * - ::nc_ps_free()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100602 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200603 * - ::nc_ps_poll()
604 * - ::nc_ps_clear()
605 * - ::nc_ps_accept_ssh_channel()
606 * - ::nc_session_accept_ssh_channel()
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100607 */
608
Michal Vaskoee087c62017-02-15 11:27:16 +0100609/**
610 * @page howtotimeouts Timeouts
611 *
612 * There are several timeouts which are used throughout _libnetconf2_ to
613 * assure that it will never indefinitely hang on any operation. Normally,
614 * you should not need to worry about them much necause they are set by
615 * default to reasonable values for common systems. However, if your
616 * platform is not common (embedded, ...), adjusting these timeouts may
617 * save a lot of debugging and time.
618 *
619 * Compile Options
620 * ---------------
621 *
622 * You can adjust active and inactive read timeout using `cmake` variables.
623 * For details look into `README.md`.
624 *
625 * API Functions
626 * -------------
627 *
628 * Once a new connection is established including transport protocol negotiations,
629 * _hello_ message is exchanged. You can set how long will the server wait for
630 * receiving this message from a client before dropping it.
631 *
632 * Having a NETCONF session working, it may not communicate for a longer time.
633 * To free up some resources, it is possible to adjust the maximum idle period
634 * of a session before it is disconnected. In _Call Home_, for both a persistent
635 * and periodic connection can this idle timeout be specified separately for each
636 * client using corresponding functions.
637 *
638 * Lastly, SSH user authentication timeout can be also modified. It is the time
639 * a client has to successfully authenticate after connecting before it is disconnected.
640 *
641 * Functions List
642 * --------------
643 *
644 * Available in __nc_server.h__.
645 *
Michal Vasko4e6d3242021-05-26 09:13:24 +0200646 * - ::nc_server_set_hello_timeout()
647 * - ::nc_server_get_hello_timeout()
648 * - ::nc_server_set_idle_timeout()
649 * - ::nc_server_get_idle_timeout()
650 * - ::nc_server_ch_client_periodic_set_idle_timeout()
651 * - ::nc_server_ssh_ch_client_endpt_set_auth_timeout()
652 * - ::nc_server_ssh_ch_client_endpt_set_auth_timeout()
Michal Vaskoee087c62017-02-15 11:27:16 +0100653 */
654
Radek Krejci6799a052017-05-19 14:23:23 +0200655/**
656 * @defgroup misc Miscellaneous
657 * @brief Miscellaneous macros, types, structure and functions for a generic use by both server and client applications.
658 */
659
660/**
661 * @defgroup client Client
662 * @brief NETCONF client functionality.
663 */
664
665/**
666 * @defgroup server Server
667 * @brief NETCONF server functionality.
668 */
669
Radek Krejcid0d19522015-09-02 13:49:25 +0200670#endif /* NC_LIBNETCONF_H_ */