Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file netconf.h |
| 3 | * \author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * \brief libnetconf2's general public functions and structures definitions. |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifndef NC_NETCONF_H_ |
| 24 | #define NC_NETCONF_H_ |
| 25 | |
| 26 | #include <time.h> |
| 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 32 | #define NC_NS_BASE "urn:ietf:params:xml:ns:netconf:base:1.0" |
| 33 | #define NC_NS_NOTIF "urn:ietf:params:xml:ns:netconf:notification:1.0" |
| 34 | |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 35 | /** @brief Default NETCONF over SSH port */ |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 36 | #define NC_PORT_SSH 830 |
| 37 | /** @brief Default NETCONF over SSH Call Home port */ |
| 38 | #define NC_PORT_CH_SSH 6666 |
| 39 | |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 40 | /** @brief Default NETCONF over TLS port */ |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 41 | #define NC_PORT_TLS 6513 |
| 42 | /** @brief Default NETCONF over TLS Call Home port */ |
| 43 | #define NC_PORT_CH_TLS 6667 |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 44 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 45 | /** @brief Microseconds after which tasks are repeated until the full timeout elapses */ |
| 46 | #define NC_TIMEOUT_STEP 10 |
| 47 | |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 48 | /** |
| 49 | * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470. |
| 50 | */ |
| 51 | typedef enum NC_SESSION_TERM_REASON { |
Michal Vasko | 428087d | 2016-01-14 16:04:28 +0100 | [diff] [blame] | 52 | NC_SESSION_TERM_NONE = 0, /**< session still running */ |
| 53 | NC_SESSION_TERM_CLOSED, /**< closed by client in a normal fashion */ |
| 54 | NC_SESSION_TERM_KILLED, /**< session was terminated by \<kill-session\> operation */ |
| 55 | NC_SESSION_TERM_DROPPED, /**< transport layer connection was unexpectedly closed */ |
| 56 | NC_SESSION_TERM_TIMEOUT, /**< terminated because of inactivity */ |
| 57 | NC_SESSION_TERM_BADHELLO, /**< \<hello\> message was invalid */ |
| 58 | NC_SESSION_TERM_OTHER /**< terminated for some other reason */ |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 59 | } NC_SESSION_TERM_REASON; |
| 60 | |
| 61 | /** |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 62 | * @brief Enumeration of NETCONF message types. |
| 63 | */ |
| 64 | typedef enum NC_MSG_TYPE { |
| 65 | NC_MSG_ERROR, /**< error return value */ |
| 66 | NC_MSG_WOULDBLOCK, /**< timeout return value */ |
| 67 | NC_MSG_NONE, /**< no message at input or message was processed internally */ |
| 68 | NC_MSG_HELLO, /**< \<hello\> message */ |
| 69 | NC_MSG_RPC, /**< \<rpc\> message */ |
| 70 | NC_MSG_REPLY, /**< \<rpc-reply\> message */ |
Radek Krejci | 5686ff7 | 2015-10-09 13:33:56 +0200 | [diff] [blame] | 71 | NC_MSG_NOTIF /**< \<notification\> message */ |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 72 | } NC_MSG_TYPE; |
| 73 | |
| 74 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 75 | * @brief Enumeration of the supported types of datastores defined by NETCONF |
| 76 | */ |
| 77 | typedef enum NC_DATASTORE_TYPE { |
Michal Vasko | 7f1c78b | 2016-01-19 09:52:14 +0100 | [diff] [blame] | 78 | NC_DATASTORE_ERROR = 0, /**< error state of functions returning the datastore type */ |
| 79 | NC_DATASTORE_CONFIG, /**< value describing that the datastore is set as config */ |
| 80 | NC_DATASTORE_URL, /**< value describing that the datastore data should be given from the URL */ |
| 81 | NC_DATASTORE_RUNNING, /**< base NETCONF's datastore containing the current device configuration */ |
| 82 | NC_DATASTORE_STARTUP, /**< separated startup datastore as defined in Distinct Startup Capability */ |
| 83 | NC_DATASTORE_CANDIDATE /**< separated working datastore as defined in Candidate Configuration Capability */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 84 | } NC_DATASTORE; |
| 85 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 86 | /** |
| 87 | * @brief Enumeration of NETCONF with-defaults capability modes. |
| 88 | */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 89 | typedef enum NC_WITHDEFAULTS_MODE { |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 90 | NC_WD_UNKNOWN = 0, /**< invalid mode */ |
| 91 | NC_WD_ALL = 0x01, /**< report-all mode */ |
| 92 | NC_WD_ALL_TAG = 0x02, /**< report-all-tagged mode */ |
| 93 | NC_WD_TRIM = 0x04, /**< trim mode */ |
| 94 | NC_WD_EXPLICIT = 0x08 /**< explicit mode */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 95 | } NC_WD_MODE; |
| 96 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 97 | /** |
| 98 | * @brief Enumeration of NETCONF (both server and client) rpc-reply types. |
| 99 | */ |
Michal Vasko | 495c946 | 2016-01-15 11:27:43 +0100 | [diff] [blame] | 100 | typedef enum NC_REPLY { |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 101 | NC_RPL_OK, /**< OK rpc-reply */ |
| 102 | NC_RPL_DATA, /**< DATA rpc-reply */ |
| 103 | NC_RPL_ERROR, /**< ERROR rpc-reply */ |
| 104 | NC_RPL_NOTIF /**< notification (client-only) */ |
Michal Vasko | 495c946 | 2016-01-15 11:27:43 +0100 | [diff] [blame] | 105 | } NC_RPL; |
| 106 | |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 107 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 108 | * @brief Enumeration of function parameter treatments. |
| 109 | */ |
| 110 | typedef enum NC_PARAMTYPE { |
| 111 | NC_PARAMTYPE_CONST, /**< use the parameter directly, do not free */ |
| 112 | NC_PARAMTYPE_FREE, /**< use the parameter directly, free afterwards */ |
| 113 | NC_PARAMTYPE_DUP_AND_FREE /**< make a copy of the argument, free afterwards */ |
| 114 | } NC_PARAMTYPE; |
| 115 | |
Michal Vasko | 58f3155 | 2016-01-19 12:39:15 +0100 | [diff] [blame] | 116 | #ifdef ENABLE_SSH |
| 117 | |
| 118 | /** |
| 119 | * @brief Initialize libssh so that libnetconf2 can be safely used in a multi-threaded environment. |
| 120 | * |
| 121 | * Must be called before using any other SSH functions. Afterwards can libssh be used in the application |
| 122 | * as well. |
| 123 | */ |
| 124 | void nc_ssh_init(void); |
| 125 | |
| 126 | /** |
| 127 | * @brief Free all the resources allocated by libssh. |
| 128 | * |
| 129 | * Must be called before nc_tls_destroy() (if called) as libssh uses libcrypto as well. |
| 130 | */ |
| 131 | void nc_ssh_destroy(void); |
| 132 | |
| 133 | #endif /* ENABLE_SSH */ |
| 134 | |
| 135 | #ifdef ENABLE_TLS |
| 136 | |
| 137 | /** |
| 138 | * @brief Initialize libcrypto so that libnetconf2 can be safely used in a multi-threaded environment. |
| 139 | * |
| 140 | * Must be called before using any other TLS functions. Afterwards can libcrypto be used in the application |
| 141 | * as well. |
| 142 | */ |
| 143 | void nc_tls_init(void); |
| 144 | |
| 145 | /** |
| 146 | * @brief Free all the resources allocated by libcrypto and libssl. |
| 147 | */ |
| 148 | void nc_tls_destroy(void); |
| 149 | |
| 150 | #endif /* ENABLE_TLS */ |
| 151 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 152 | /** |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 153 | * @brief Transform given time_t (seconds since the epoch) into the RFC 3339 format |
| 154 | * accepted by NETCONF functions. |
| 155 | * |
| 156 | * This is a reverse function to nc_datetime2time(). |
| 157 | * |
| 158 | * @param[in] time time_t type value returned e.g. by time(). |
| 159 | * @param[in] tz timezone name for the result. See tzselect(1) for list of |
| 160 | * correct values. If not specified (NULL), the result is provided in UTC (Zulu). |
| 161 | * @return Printed string in a format compliant to RFC 3339. It is up to the |
| 162 | * caller to free the returned string. |
| 163 | */ |
| 164 | char* nc_time2datetime(time_t time, const char* tz); |
| 165 | |
| 166 | /** |
| 167 | * @brief Transform given string in RFC 3339 compliant format to the time_t |
| 168 | * (seconds since the epoch) accepted by most Linux functions. |
| 169 | * |
| 170 | * This is a reverse function to nc_time2datetime(). |
| 171 | * |
| 172 | * @param[in] datetime Time structure returned e.g. by localtime(). |
| 173 | * @return time_t value of the given string. |
| 174 | */ |
| 175 | time_t nc_datetime2time(const char* datetime); |
| 176 | |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 177 | #ifdef __cplusplus |
| 178 | } |
| 179 | #endif |
| 180 | |
| 181 | #endif /* NC_NETCONF_H_ */ |