Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 1 | /** |
| 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 Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 8 | * 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 Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NC_SESSION_H_ |
| 16 | #define NC_SESSION_H_ |
| 17 | |
Radek Krejci | 6e36bfb | 2016-12-01 21:40:16 +0100 | [diff] [blame] | 18 | #include "netconf.h" |
| 19 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 20 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 21 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 22 | /** |
| 23 | * @brief Enumeration of NETCONF SSH authentication methods |
| 24 | */ |
Michal Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 25 | typedef enum { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 26 | 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 Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 29 | } NC_SSH_AUTH_TYPE; |
| 30 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 31 | #endif /* NC_ENABLED_SSH */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 32 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 33 | #ifdef NC_ENABLED_TLS |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 34 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 35 | /** |
| 36 | * @brief Enumeration of cert-to-name mapping types |
| 37 | */ |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 38 | typedef enum { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 39 | 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 Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 46 | } NC_TLS_CTN_MAPTYPE; |
| 47 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 48 | #endif /* NC_ENABLED_TLS */ |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 49 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 50 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 51 | * @brief Enumeration of possible session statuses |
| 52 | */ |
| 53 | typedef enum { |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 54 | NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */ |
| 55 | NC_STATUS_CLOSING, /**< session is being closed */ |
Michal Vasko | 428087d | 2016-01-14 16:04:28 +0100 | [diff] [blame] | 56 | NC_STATUS_INVALID, /**< session is not running and is supposed to be closed (nc_session_free()) */ |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 57 | NC_STATUS_RUNNING /**< up and running */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 58 | } NC_STATUS; |
| 59 | |
| 60 | /** |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 61 | * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol) |
| 62 | */ |
| 63 | typedef enum { |
| 64 | NC_TI_NONE = 0, /**< none - session is not connected yet */ |
| 65 | NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented |
| 66 | outside the current application */ |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 67 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 68 | NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */ |
| 69 | #endif |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 70 | #ifdef NC_ENABLED_TLS |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 71 | NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */ |
| 72 | #endif |
| 73 | } NC_TRANSPORT_IMPL; |
| 74 | |
| 75 | /** |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 76 | * @brief Enumeration of Call Home connection types. |
| 77 | */ |
| 78 | typedef enum { |
| 79 | NC_CH_CT_NOT_SET = 0, |
| 80 | NC_CH_PERSIST, |
| 81 | NC_CH_PERIOD |
| 82 | } NC_CH_CONN_TYPE; |
| 83 | |
| 84 | /** |
| 85 | * @brief Enumeration of Call Home client priority policy. |
| 86 | */ |
| 87 | typedef enum { |
| 88 | NC_CH_FIRST_LISTED = 0, //default |
| 89 | NC_CH_LAST_CONNECTED |
| 90 | } NC_CH_START_WITH; |
| 91 | |
| 92 | /** |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 93 | * @brief Enumeration of SSH key types. |
| 94 | */ |
| 95 | typedef enum { |
| 96 | NC_SSH_KEY_UNKNOWN = 0, |
| 97 | NC_SSH_KEY_DSA, |
| 98 | NC_SSH_KEY_RSA, |
| 99 | NC_SSH_KEY_ECDSA |
| 100 | } NC_SSH_KEY_TYPE; |
| 101 | |
| 102 | /** |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 103 | * @brief NETCONF session object |
| 104 | */ |
| 105 | struct nc_session; |
| 106 | |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 107 | /** |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 108 | * @brief Get session status. |
| 109 | * |
| 110 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 111 | * @return Session status. |
| 112 | */ |
| 113 | NC_STATUS nc_session_get_status(const struct nc_session *session); |
| 114 | |
| 115 | /** |
Radek Krejci | 6e36bfb | 2016-12-01 21:40:16 +0100 | [diff] [blame] | 116 | * @brief Get session termination reason. |
| 117 | * |
| 118 | * @param[in] session Session to get the information from. |
| 119 | * @return Session termination reason enum value. |
| 120 | */ |
| 121 | NC_SESSION_TERM_REASON nc_session_get_termreason(const struct nc_session *session); |
| 122 | |
| 123 | /** |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 124 | * @brief Get session ID. |
| 125 | * |
| 126 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 127 | * @return Session ID. |
| 128 | */ |
| 129 | uint32_t nc_session_get_id(const struct nc_session *session); |
| 130 | |
| 131 | /** |
Michal Vasko | 174fe8e | 2016-02-17 15:38:09 +0100 | [diff] [blame] | 132 | * @brief Get session NETCONF version. |
| 133 | * |
| 134 | * @param[in] session Session to get the information from. |
| 135 | * @return 0 for version 1.0, non-zero for version 1.1. |
| 136 | */ |
| 137 | int nc_session_get_version(const struct nc_session *session); |
| 138 | |
| 139 | /** |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 140 | * @brief Get session transport used. |
| 141 | * |
| 142 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 143 | * @return Session transport. |
| 144 | */ |
| 145 | NC_TRANSPORT_IMPL nc_session_get_ti(const struct nc_session *session); |
| 146 | |
| 147 | /** |
| 148 | * @brief Get session username. |
| 149 | * |
| 150 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 151 | * @return Session username. |
| 152 | */ |
| 153 | const char *nc_session_get_username(const struct nc_session *session); |
| 154 | |
| 155 | /** |
| 156 | * @brief Get session host. |
| 157 | * |
| 158 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 159 | * @return Session host. |
| 160 | */ |
| 161 | const char *nc_session_get_host(const struct nc_session *session); |
| 162 | |
| 163 | /** |
| 164 | * @brief Get session port. |
| 165 | * |
| 166 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 167 | * @return Session port. |
| 168 | */ |
| 169 | uint16_t nc_session_get_port(const struct nc_session *session); |
| 170 | |
| 171 | /** |
Michal Vasko | 9a25e93 | 2016-02-01 10:36:42 +0100 | [diff] [blame] | 172 | * @brief Get session context. |
| 173 | * |
| 174 | * @param[in] session Session to get the information from. |
| 175 | * @return Session context. |
| 176 | */ |
| 177 | struct ly_ctx *nc_session_get_ctx(const struct nc_session *session); |
| 178 | |
| 179 | /** |
Michal Vasko | 2cc4c68 | 2016-03-01 09:16:48 +0100 | [diff] [blame] | 180 | * @brief Assign arbitrary data to a session. |
| 181 | * |
| 182 | * @param[in] session Session to modify. |
| 183 | * @param[in] data Data to be stored in the session. |
| 184 | */ |
| 185 | void nc_session_set_data(struct nc_session *session, void *data); |
| 186 | |
| 187 | /** |
| 188 | * @brief Get the data assigned to a session. |
| 189 | * |
| 190 | * @param[in] session Session to get the data from. |
| 191 | * @return Session-specific data. |
| 192 | */ |
| 193 | void *nc_session_get_data(const struct nc_session *session); |
| 194 | |
| 195 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 196 | * @brief Free the NETCONF session object. |
| 197 | * |
| 198 | * @param[in] session Object to free. |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 199 | * @param[in] data_free Session user data destructor. |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 200 | */ |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 201 | void nc_session_free(struct nc_session *session, void (*data_free)(void *)); |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 202 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 203 | #endif /* NC_SESSION_H_ */ |