blob: f468165b4076348098610562876b3c656a7d9e5b [file] [log] [blame]
Radek Krejci43390242015-10-08 15:34:04 +02001/**
2 * \file session.h
3 * \author Radek Krejci <rkrejci@cesnet.cz>
4 * \brief libnetconf2 session manipulation
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01008 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010011 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejci43390242015-10-08 15:34:04 +020013 */
14
15#ifndef NC_SESSION_H_
16#define NC_SESSION_H_
17
Radek Krejci6e36bfb2016-12-01 21:40:16 +010018#include "netconf.h"
19
Radek Krejci53691be2016-02-22 13:58:37 +010020#ifdef NC_ENABLED_SSH
Michal Vasko4ef14932015-12-04 11:09:10 +010021
Michal Vaskof0537d82016-01-29 14:42:38 +010022/**
23 * @brief Enumeration of NETCONF SSH authentication methods
24 */
Michal Vasko4ef14932015-12-04 11:09:10 +010025typedef enum {
Michal Vaskof0537d82016-01-29 14:42:38 +010026 NC_SSH_AUTH_PUBLICKEY = 0x01, /**< publickey SSH authentication */
27 NC_SSH_AUTH_PASSWORD = 0x02, /**< password SSH authentication */
28 NC_SSH_AUTH_INTERACTIVE = 0x04 /**< interactive SSH authentication */
Michal Vasko4ef14932015-12-04 11:09:10 +010029} NC_SSH_AUTH_TYPE;
30
Radek Krejci53691be2016-02-22 13:58:37 +010031#endif /* NC_ENABLED_SSH */
Radek Krejci695d4fa2015-10-22 13:23:54 +020032
Radek Krejci53691be2016-02-22 13:58:37 +010033#ifdef NC_ENABLED_TLS
Michal Vaskoc14e3c82016-01-11 16:14:30 +010034
Michal Vaskof0537d82016-01-29 14:42:38 +010035/**
36 * @brief Enumeration of cert-to-name mapping types
37 */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010038typedef enum {
Michal Vaskof0537d82016-01-29 14:42:38 +010039 NC_TLS_CTN_UNKNOWN = 0, /**< unknown mapping */
40 NC_TLS_CTN_SPECIFIED, /**< username explicitly specified */
41 NC_TLS_CTN_SAN_RFC822_NAME, /**< email address as username */
42 NC_TLS_CTN_SAN_DNS_NAME, /**< DNS name as username */
43 NC_TLS_CTN_SAN_IP_ADDRESS, /**< IP address as username */
44 NC_TLS_CTN_SAN_ANY, /**< any certificate Subject Alternative Name as username */
45 NC_TLS_CTN_COMMON_NAME /**< common name as username */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010046} NC_TLS_CTN_MAPTYPE;
47
Radek Krejci53691be2016-02-22 13:58:37 +010048#endif /* NC_ENABLED_TLS */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010049
Radek Krejci43390242015-10-08 15:34:04 +020050/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020051 * @brief Enumeration of possible session statuses
52 */
53typedef enum {
Radek Krejci465308c2017-05-22 14:49:10 +020054 NC_STATUS_ERR = -1, /**< error return code for function getting the session status */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010055 NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */
56 NC_STATUS_CLOSING, /**< session is being closed */
Michal Vasko428087d2016-01-14 16:04:28 +010057 NC_STATUS_INVALID, /**< session is not running and is supposed to be closed (nc_session_free()) */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010058 NC_STATUS_RUNNING /**< up and running */
Radek Krejci695d4fa2015-10-22 13:23:54 +020059} NC_STATUS;
60
61/**
Michal Vasko38a7c6c2015-12-04 12:29:20 +010062 * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol)
63 */
64typedef enum {
65 NC_TI_NONE = 0, /**< none - session is not connected yet */
66 NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented
67 outside the current application */
Olivier Matzac7fa2f2018-10-11 10:02:04 +020068 NC_TI_UNIX, /**< unix socket */
Radek Krejci53691be2016-02-22 13:58:37 +010069#ifdef NC_ENABLED_SSH
Michal Vasko38a7c6c2015-12-04 12:29:20 +010070 NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */
71#endif
Radek Krejci53691be2016-02-22 13:58:37 +010072#ifdef NC_ENABLED_TLS
Michal Vasko38a7c6c2015-12-04 12:29:20 +010073 NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */
74#endif
75} NC_TRANSPORT_IMPL;
76
77/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020078 * @brief Enumeration of Call Home connection types.
79 */
80typedef enum {
81 NC_CH_CT_NOT_SET = 0,
82 NC_CH_PERSIST,
83 NC_CH_PERIOD
84} NC_CH_CONN_TYPE;
85
86/**
87 * @brief Enumeration of Call Home client priority policy.
88 */
89typedef enum {
90 NC_CH_FIRST_LISTED = 0, //default
91 NC_CH_LAST_CONNECTED
92} NC_CH_START_WITH;
93
94/**
Michal Vasko17dfda92016-12-01 14:06:16 +010095 * @brief Enumeration of SSH key types.
96 */
97typedef enum {
98 NC_SSH_KEY_UNKNOWN = 0,
99 NC_SSH_KEY_DSA,
100 NC_SSH_KEY_RSA,
101 NC_SSH_KEY_ECDSA
102} NC_SSH_KEY_TYPE;
103
104/**
Radek Krejci43390242015-10-08 15:34:04 +0200105 * @brief NETCONF session object
106 */
107struct nc_session;
108
Radek Krejci695d4fa2015-10-22 13:23:54 +0200109/**
Michal Vasko8dadf782016-01-15 10:29:36 +0100110 * @brief Get session status.
111 *
112 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100113 * @return Session status.
114 */
115NC_STATUS nc_session_get_status(const struct nc_session *session);
116
117/**
Radek Krejci6e36bfb2016-12-01 21:40:16 +0100118 * @brief Get session termination reason.
119 *
120 * @param[in] session Session to get the information from.
121 * @return Session termination reason enum value.
122 */
Michal Vasko142cfea2017-08-07 10:12:11 +0200123NC_SESSION_TERM_REASON nc_session_get_term_reason(const struct nc_session *session);
124
125/**
126 * @brief Get session killer session ID.
127 *
128 * @param[in] session Session to get the information from.
129 * @return Session killer ID.
130 */
131uint32_t nc_session_get_killed_by(const struct nc_session *session);
Radek Krejci6e36bfb2016-12-01 21:40:16 +0100132
133/**
Michal Vasko8dadf782016-01-15 10:29:36 +0100134 * @brief Get session ID.
135 *
136 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100137 * @return Session ID.
138 */
139uint32_t nc_session_get_id(const struct nc_session *session);
140
141/**
Michal Vasko174fe8e2016-02-17 15:38:09 +0100142 * @brief Get session NETCONF version.
143 *
144 * @param[in] session Session to get the information from.
145 * @return 0 for version 1.0, non-zero for version 1.1.
146 */
147int nc_session_get_version(const struct nc_session *session);
148
149/**
Michal Vasko8dadf782016-01-15 10:29:36 +0100150 * @brief Get session transport used.
151 *
152 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100153 * @return Session transport.
154 */
155NC_TRANSPORT_IMPL nc_session_get_ti(const struct nc_session *session);
156
157/**
158 * @brief Get session username.
159 *
160 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100161 * @return Session username.
162 */
163const char *nc_session_get_username(const struct nc_session *session);
164
165/**
166 * @brief Get session host.
167 *
168 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100169 * @return Session host.
170 */
171const char *nc_session_get_host(const struct nc_session *session);
172
173/**
174 * @brief Get session port.
175 *
176 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100177 * @return Session port.
178 */
179uint16_t nc_session_get_port(const struct nc_session *session);
180
181/**
Olivier Matzac7fa2f2018-10-11 10:02:04 +0200182 * @brief Get session path (unix socket only).
183 *
184 * @param[in] session Session to get the information from.
185 * @return Session unix socket path.
186 */
187const char *nc_session_get_path(const struct nc_session *session);
188
189/**
Michal Vasko9a25e932016-02-01 10:36:42 +0100190 * @brief Get session context.
191 *
192 * @param[in] session Session to get the information from.
193 * @return Session context.
194 */
195struct ly_ctx *nc_session_get_ctx(const struct nc_session *session);
196
197/**
Michal Vasko2cc4c682016-03-01 09:16:48 +0100198 * @brief Assign arbitrary data to a session.
199 *
200 * @param[in] session Session to modify.
201 * @param[in] data Data to be stored in the session.
202 */
203void nc_session_set_data(struct nc_session *session, void *data);
204
205/**
206 * @brief Get the data assigned to a session.
207 *
208 * @param[in] session Session to get the data from.
209 * @return Session-specific data.
210 */
211void *nc_session_get_data(const struct nc_session *session);
212
213/**
Radek Krejci695d4fa2015-10-22 13:23:54 +0200214 * @brief Free the NETCONF session object.
215 *
216 * @param[in] session Object to free.
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100217 * @param[in] data_free Session user data destructor.
Radek Krejci695d4fa2015-10-22 13:23:54 +0200218 */
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100219void nc_session_free(struct nc_session *session, void (*data_free)(void *));
Radek Krejci695d4fa2015-10-22 13:23:54 +0200220
Radek Krejci62aa0642017-05-25 16:33:49 +0200221#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
222
223/**
224 * @brief Free all the dynamically allocated thread-specific libssl/libcrypto
225 * resources.
226 *
227 * This function should be called only if init (nc_client_init(), respectively nc_server_init()) was called.
228 * Call it in every thread your application creates just before the thread exits. In the last thread
229 * (usually the main one) call nc_client_destroy(), respectively nc_server_destroy().
230 */
231void nc_thread_destroy(void);
232
233#endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */
234
Radek Krejci43390242015-10-08 15:34:04 +0200235#endif /* NC_SESSION_H_ */