blob: 52626e8a5fcc3f399daa35c61a4099f1e8f22310 [file] [log] [blame]
Radek Krejci43390242015-10-08 15:34:04 +02001/**
Michal Vasko95ea9ff2021-11-09 12:29:14 +01002 * @file session.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskodc96bb92023-03-28 08:52:48 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Michal Vasko95ea9ff2021-11-09 12:29:14 +01005 * @brief libnetconf2 session manipulation
Radek Krejci43390242015-10-08 15:34:04 +02006 *
Michal Vasko95ea9ff2021-11-09 12:29:14 +01007 * @copyright
Michal Vaskodc96bb92023-03-28 08:52:48 +02008 * Copyright (c) 2015 - 2023 CESNET, z.s.p.o.
Radek Krejci43390242015-10-08 15:34:04 +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 Krejci43390242015-10-08 15:34:04 +020015 */
16
17#ifndef NC_SESSION_H_
18#define NC_SESSION_H_
19
Michal Vaskoc09730e2019-01-17 10:07:26 +010020#ifdef __cplusplus
21extern "C" {
22#endif
23
Radek Krejci6e36bfb2016-12-01 21:40:16 +010024#include "netconf.h"
25
roman2eab4742023-06-06 10:00:26 +020026#ifdef NC_ENABLED_SSH_TLS
Michal Vasko4ef14932015-12-04 11:09:10 +010027
Michal Vaskof0537d82016-01-29 14:42:38 +010028/**
29 * @brief Enumeration of NETCONF SSH authentication methods
30 */
Michal Vasko4ef14932015-12-04 11:09:10 +010031typedef enum {
Michal Vaskof0537d82016-01-29 14:42:38 +010032 NC_SSH_AUTH_PUBLICKEY = 0x01, /**< publickey SSH authentication */
33 NC_SSH_AUTH_PASSWORD = 0x02, /**< password SSH authentication */
34 NC_SSH_AUTH_INTERACTIVE = 0x04 /**< interactive SSH authentication */
Michal Vasko4ef14932015-12-04 11:09:10 +010035} NC_SSH_AUTH_TYPE;
36
romanf6e32012023-04-24 15:51:26 +020037/**
38 * @brief Enumeration of host key checking and known_hosts entry adding modes
39 */
40typedef enum {
41 NC_SSH_KNOWNHOSTS_ASK = 0, /**< add a known_hosts entry, but with a prompt */
42 NC_SSH_KNOWNHOSTS_STRICT, /**< do not add a known_hosts entry and the server's host key must be present in the configured known_hosts file */
43 NC_SSH_KNOWNHOSTS_ACCEPT_NEW, /**< add a known_hosts entry without a prompt */
44 NC_SSH_KNOWNHOSTS_ACCEPT, /**< add a known_hosts entry without a prompt and allow connections to servers which changed their host key */
45 NC_SSH_KNOWNHOSTS_SKIP /**< do not add a known_hosts entry and skip all host key checks */
46} NC_SSH_KNOWNHOSTS_MODE;
47
Michal Vaskof0537d82016-01-29 14:42:38 +010048/**
49 * @brief Enumeration of cert-to-name mapping types
50 */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010051typedef enum {
Michal Vaskof0537d82016-01-29 14:42:38 +010052 NC_TLS_CTN_UNKNOWN = 0, /**< unknown mapping */
53 NC_TLS_CTN_SPECIFIED, /**< username explicitly specified */
54 NC_TLS_CTN_SAN_RFC822_NAME, /**< email address as username */
55 NC_TLS_CTN_SAN_DNS_NAME, /**< DNS name as username */
56 NC_TLS_CTN_SAN_IP_ADDRESS, /**< IP address as username */
57 NC_TLS_CTN_SAN_ANY, /**< any certificate Subject Alternative Name as username */
58 NC_TLS_CTN_COMMON_NAME /**< common name as username */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010059} NC_TLS_CTN_MAPTYPE;
60
roman12644fe2023-06-08 11:06:42 +020061/**
62 * @brief Enumeration of TLS versions.
63 */
64typedef enum {
65 NC_TLS_VERSION_10 = 1, /**< TLS1.0 */
66 NC_TLS_VERSION_11 = 2, /**< TLS1.1 */
67 NC_TLS_VERSION_12 = 4, /**< TLS1.2 */
68 NC_TLS_VERSION_13 = 8 /**< TLS1.3 */
69} NC_TLS_VERSION;
70
roman2eab4742023-06-06 10:00:26 +020071#endif /* NC_ENABLED_SSH_TLS */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010072
Radek Krejci43390242015-10-08 15:34:04 +020073/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020074 * @brief Enumeration of possible session statuses
75 */
76typedef enum {
Radek Krejci465308c2017-05-22 14:49:10 +020077 NC_STATUS_ERR = -1, /**< error return code for function getting the session status */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010078 NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */
79 NC_STATUS_CLOSING, /**< session is being closed */
Michal Vasko428087d2016-01-14 16:04:28 +010080 NC_STATUS_INVALID, /**< session is not running and is supposed to be closed (nc_session_free()) */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010081 NC_STATUS_RUNNING /**< up and running */
Radek Krejci695d4fa2015-10-22 13:23:54 +020082} NC_STATUS;
83
84/**
Michal Vasko38a7c6c2015-12-04 12:29:20 +010085 * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol)
86 */
87typedef enum {
88 NC_TI_NONE = 0, /**< none - session is not connected yet */
89 NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented
90 outside the current application */
Olivier Matzac7fa2f2018-10-11 10:02:04 +020091 NC_TI_UNIX, /**< unix socket */
roman2eab4742023-06-06 10:00:26 +020092#ifdef NC_ENABLED_SSH_TLS
Michal Vasko38a7c6c2015-12-04 12:29:20 +010093 NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */
roman2eab4742023-06-06 10:00:26 +020094
Michal Vasko38a7c6c2015-12-04 12:29:20 +010095 NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */
roman2eab4742023-06-06 10:00:26 +020096#endif /* NC_ENABLED_SSH_TLS */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010097} NC_TRANSPORT_IMPL;
98
99/**
Michal Vasko2e6defd2016-10-07 15:48:15 +0200100 * @brief Enumeration of Call Home connection types.
101 */
102typedef enum {
103 NC_CH_CT_NOT_SET = 0,
104 NC_CH_PERSIST,
105 NC_CH_PERIOD
106} NC_CH_CONN_TYPE;
107
108/**
109 * @brief Enumeration of Call Home client priority policy.
110 */
111typedef enum {
Michal Vaskob83a3fa2021-05-26 09:53:42 +0200112 NC_CH_FIRST_LISTED = 0, // default
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200113 NC_CH_LAST_CONNECTED,
114 NC_CH_RANDOM
Michal Vasko2e6defd2016-10-07 15:48:15 +0200115} NC_CH_START_WITH;
116
117/**
Radek Krejci43390242015-10-08 15:34:04 +0200118 * @brief NETCONF session object
119 */
120struct nc_session;
121
Radek Krejci695d4fa2015-10-22 13:23:54 +0200122/**
Michal Vasko8dadf782016-01-15 10:29:36 +0100123 * @brief Get session status.
124 *
125 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100126 * @return Session status.
127 */
128NC_STATUS nc_session_get_status(const struct nc_session *session);
129
130/**
Radek Krejci6e36bfb2016-12-01 21:40:16 +0100131 * @brief Get session termination reason.
132 *
133 * @param[in] session Session to get the information from.
134 * @return Session termination reason enum value.
135 */
Michal Vasko142cfea2017-08-07 10:12:11 +0200136NC_SESSION_TERM_REASON nc_session_get_term_reason(const struct nc_session *session);
137
138/**
139 * @brief Get session killer session ID.
140 *
141 * @param[in] session Session to get the information from.
142 * @return Session killer ID.
143 */
144uint32_t nc_session_get_killed_by(const struct nc_session *session);
Radek Krejci6e36bfb2016-12-01 21:40:16 +0100145
146/**
Michal Vasko8dadf782016-01-15 10:29:36 +0100147 * @brief Get session ID.
148 *
149 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100150 * @return Session ID.
151 */
152uint32_t nc_session_get_id(const struct nc_session *session);
153
154/**
Michal Vasko174fe8e2016-02-17 15:38:09 +0100155 * @brief Get session NETCONF version.
156 *
157 * @param[in] session Session to get the information from.
158 * @return 0 for version 1.0, non-zero for version 1.1.
159 */
160int nc_session_get_version(const struct nc_session *session);
161
162/**
Michal Vasko8dadf782016-01-15 10:29:36 +0100163 * @brief Get session transport used.
164 *
165 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100166 * @return Session transport.
167 */
168NC_TRANSPORT_IMPL nc_session_get_ti(const struct nc_session *session);
169
170/**
171 * @brief Get session username.
172 *
173 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100174 * @return Session username.
175 */
176const char *nc_session_get_username(const struct nc_session *session);
177
178/**
179 * @brief Get session host.
180 *
181 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100182 * @return Session host.
183 */
184const char *nc_session_get_host(const struct nc_session *session);
185
186/**
187 * @brief Get session port.
188 *
189 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100190 * @return Session port.
191 */
192uint16_t nc_session_get_port(const struct nc_session *session);
193
194/**
Olivier Matzac7fa2f2018-10-11 10:02:04 +0200195 * @brief Get session path (unix socket only).
196 *
197 * @param[in] session Session to get the information from.
198 * @return Session unix socket path.
199 */
200const char *nc_session_get_path(const struct nc_session *session);
201
202/**
Michal Vasko9a25e932016-02-01 10:36:42 +0100203 * @brief Get session context.
204 *
205 * @param[in] session Session to get the information from.
206 * @return Session context.
207 */
Michal Vasko93224072021-11-09 12:14:28 +0100208const struct ly_ctx *nc_session_get_ctx(const struct nc_session *session);
Michal Vasko9a25e932016-02-01 10:36:42 +0100209
210/**
Michal Vasko2cc4c682016-03-01 09:16:48 +0100211 * @brief Assign arbitrary data to a session.
212 *
213 * @param[in] session Session to modify.
214 * @param[in] data Data to be stored in the session.
215 */
216void nc_session_set_data(struct nc_session *session, void *data);
217
218/**
219 * @brief Get the data assigned to a session.
220 *
221 * @param[in] session Session to get the data from.
222 * @return Session-specific data.
223 */
224void *nc_session_get_data(const struct nc_session *session);
225
226/**
Michal Vaskodc96bb92023-03-28 08:52:48 +0200227 * @brief Learn whether a session was created using Call Home or not.
228 *
229 * @param[in] session Session to get the information from.
230 * @return 0 if a standard session, non-zero if a Call Home session.
231 */
232int nc_session_is_callhome(const struct nc_session *session);
233
234/**
Radek Krejci695d4fa2015-10-22 13:23:54 +0200235 * @brief Free the NETCONF session object.
236 *
237 * @param[in] session Object to free.
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100238 * @param[in] data_free Session user data destructor.
Radek Krejci695d4fa2015-10-22 13:23:54 +0200239 */
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100240void nc_session_free(struct nc_session *session, void (*data_free)(void *));
Radek Krejci695d4fa2015-10-22 13:23:54 +0200241
Michal Vaskoc09730e2019-01-17 10:07:26 +0100242#ifdef __cplusplus
243}
244#endif
245
Radek Krejci43390242015-10-08 15:34:04 +0200246#endif /* NC_SESSION_H_ */