blob: ce1642d9ede60b2d7de1c551bc194b65f5c4d7af [file] [log] [blame]
Radek Krejcid0d19522015-09-02 13:49:25 +02001/**
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 *
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 Krejcid0d19522015-09-02 13:49:25 +020013 */
14
15#ifndef NC_NETCONF_H_
16#define NC_NETCONF_H_
17
Radek Krejcid0d19522015-09-02 13:49:25 +020018#ifdef __cplusplus
19extern "C" {
20#endif
21
Michal Vaskoc09730e2019-01-17 10:07:26 +010022#include <time.h>
23
Radek Krejci6799a052017-05-19 14:23:23 +020024/**
25 * @addtogroup misc
26 * @{
27 */
28
29/** @brief Base NETCONF namespace */
Radek Krejci206fcd62015-10-07 15:42:48 +020030#define NC_NS_BASE "urn:ietf:params:xml:ns:netconf:base:1.0"
Radek Krejci6799a052017-05-19 14:23:23 +020031/** @brief Notifications namespace */
Radek Krejci206fcd62015-10-07 15:42:48 +020032#define NC_NS_NOTIF "urn:ietf:params:xml:ns:netconf:notification:1.0"
33
Radek Krejciac6d3472015-10-22 15:47:18 +020034/** @brief Default NETCONF over SSH port */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010035#define NC_PORT_SSH 830
36/** @brief Default NETCONF over SSH Call Home port */
Michal Vasko3b090292017-02-03 11:43:47 +010037#define NC_PORT_CH_SSH 4334
Michal Vasko38a7c6c2015-12-04 12:29:20 +010038
Radek Krejciac6d3472015-10-22 15:47:18 +020039/** @brief Default NETCONF over TLS port */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010040#define NC_PORT_TLS 6513
41/** @brief Default NETCONF over TLS Call Home port */
Michal Vasko3b090292017-02-03 11:43:47 +010042#define NC_PORT_CH_TLS 4335
Radek Krejciac6d3472015-10-22 15:47:18 +020043
Michal Vasko0190bc32016-03-02 15:47:49 +010044/** @brief Microseconds after which tasks are repeated until the full timeout elapses.
Michal Vaskof471fa02017-02-15 10:48:12 +010045 * A millisecond (1000) should be divisible by this number without remain.
Michal Vasko0190bc32016-03-02 15:47:49 +010046 */
Michal Vasko36c7be82017-02-22 13:37:59 +010047#define NC_TIMEOUT_STEP 50
Michal Vasko086311b2016-01-08 09:53:11 +010048
Radek Krejcid0d19522015-09-02 13:49:25 +020049/**
Michal Vasko3a889fd2016-09-30 12:16:37 +020050 * @brief Set RPC callback to a schema node.
51 *
52 * @param[in] node const struct lys_node *node
53 * @param[in] cb nc_rpc_clb cb
54 */
55#define nc_set_rpc_callback(node, cb) lys_set_private(node, cb)
56
57/**
Radek Krejcid0d19522015-09-02 13:49:25 +020058 * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
59 */
60typedef enum NC_SESSION_TERM_REASON {
Radek Krejci465308c2017-05-22 14:49:10 +020061 NC_SESSION_TERM_ERR = -1, /**< error return code for function getting the session termination reason */
Michal Vasko428087d2016-01-14 16:04:28 +010062 NC_SESSION_TERM_NONE = 0, /**< session still running */
63 NC_SESSION_TERM_CLOSED, /**< closed by client in a normal fashion */
64 NC_SESSION_TERM_KILLED, /**< session was terminated by \<kill-session\> operation */
65 NC_SESSION_TERM_DROPPED, /**< transport layer connection was unexpectedly closed */
66 NC_SESSION_TERM_TIMEOUT, /**< terminated because of inactivity */
67 NC_SESSION_TERM_BADHELLO, /**< \<hello\> message was invalid */
68 NC_SESSION_TERM_OTHER /**< terminated for some other reason */
Radek Krejcid0d19522015-09-02 13:49:25 +020069} NC_SESSION_TERM_REASON;
70
71/**
Radek Krejci43390242015-10-08 15:34:04 +020072 * @brief Enumeration of NETCONF message types.
73 */
74typedef enum NC_MSG_TYPE {
Michal Vasko71ba2da2016-05-04 10:53:16 +020075 NC_MSG_ERROR, /**< error return value */
76 NC_MSG_WOULDBLOCK, /**< timeout return value */
77 NC_MSG_NONE, /**< no message at input or message was processed internally */
78 NC_MSG_HELLO, /**< \<hello\> message */
Michal Vasko71090fc2016-05-24 16:37:28 +020079 NC_MSG_BAD_HELLO, /**< \<hello\> message parsing failed */
Michal Vasko71ba2da2016-05-04 10:53:16 +020080 NC_MSG_RPC, /**< \<rpc\> message */
81 NC_MSG_REPLY, /**< \<rpc-reply\> message */
82 NC_MSG_REPLY_ERR_MSGID, /**< \<rpc-reply\> message with missing or wrong message-id attribute value */
83 NC_MSG_NOTIF /**< \<notification\> message */
Radek Krejci43390242015-10-08 15:34:04 +020084} NC_MSG_TYPE;
85
86/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020087 * @brief Enumeration of the supported types of datastores defined by NETCONF
88 */
89typedef enum NC_DATASTORE_TYPE {
Michal Vasko7f1c78b2016-01-19 09:52:14 +010090 NC_DATASTORE_ERROR = 0, /**< error state of functions returning the datastore type */
91 NC_DATASTORE_CONFIG, /**< value describing that the datastore is set as config */
92 NC_DATASTORE_URL, /**< value describing that the datastore data should be given from the URL */
93 NC_DATASTORE_RUNNING, /**< base NETCONF's datastore containing the current device configuration */
94 NC_DATASTORE_STARTUP, /**< separated startup datastore as defined in Distinct Startup Capability */
95 NC_DATASTORE_CANDIDATE /**< separated working datastore as defined in Candidate Configuration Capability */
Radek Krejci695d4fa2015-10-22 13:23:54 +020096} NC_DATASTORE;
97
Michal Vasko1a38c862016-01-15 15:50:07 +010098/**
99 * @brief Enumeration of NETCONF with-defaults capability modes.
100 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100101typedef enum NC_WITHDEFAULTS_MODE {
Michal Vasko1a38c862016-01-15 15:50:07 +0100102 NC_WD_UNKNOWN = 0, /**< invalid mode */
Radek Krejci36dfdb32016-09-01 16:56:35 +0200103 NC_WD_ALL, /**< report-all mode */
104 NC_WD_ALL_TAG, /**< report-all-tagged mode */
105 NC_WD_TRIM, /**< trim mode */
106 NC_WD_EXPLICIT /**< explicit mode */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100107} NC_WD_MODE;
108
Michal Vasko1a38c862016-01-15 15:50:07 +0100109/**
110 * @brief Enumeration of NETCONF (both server and client) rpc-reply types.
111 */
Michal Vasko495c9462016-01-15 11:27:43 +0100112typedef enum NC_REPLY {
Michal Vasko1a38c862016-01-15 15:50:07 +0100113 NC_RPL_OK, /**< OK rpc-reply */
114 NC_RPL_DATA, /**< DATA rpc-reply */
115 NC_RPL_ERROR, /**< ERROR rpc-reply */
116 NC_RPL_NOTIF /**< notification (client-only) */
Michal Vasko495c9462016-01-15 11:27:43 +0100117} NC_RPL;
118
Radek Krejci695d4fa2015-10-22 13:23:54 +0200119/**
Michal Vasko1a38c862016-01-15 15:50:07 +0100120 * @brief Enumeration of function parameter treatments.
121 */
122typedef enum NC_PARAMTYPE {
123 NC_PARAMTYPE_CONST, /**< use the parameter directly, do not free */
124 NC_PARAMTYPE_FREE, /**< use the parameter directly, free afterwards */
125 NC_PARAMTYPE_DUP_AND_FREE /**< make a copy of the argument, free afterwards */
126} NC_PARAMTYPE;
127
128/**
Radek Krejcid0d19522015-09-02 13:49:25 +0200129 * @brief Transform given time_t (seconds since the epoch) into the RFC 3339 format
130 * accepted by NETCONF functions.
131 *
132 * This is a reverse function to nc_datetime2time().
133 *
Michal Vasko8c1bfab2016-05-25 11:17:02 +0200134 * @param[in] time Time to convert.
135 * @param[in] tz Timezone name for the result. See tzselect(1) for list of
Radek Krejciebe263f2016-05-31 15:59:07 +0200136 * correct values. If not specified (NULL) or unknown/invalid, the result is provided in UTC (Zulu).
Michal Vasko8c1bfab2016-05-25 11:17:02 +0200137 * @param[in] buf Optional buffer to print the datetime into, should be at least 26 characters long!
138 * @return Printed string in a format compliant to RFC 3339 stored in \p buf if provided,
Radek Krejciebe263f2016-05-31 15:59:07 +0200139 * otherwise it is up to the caller to free the returned string. NULL on error.
Radek Krejcid0d19522015-09-02 13:49:25 +0200140 */
Michal Vasko8c1bfab2016-05-25 11:17:02 +0200141char* nc_time2datetime(time_t time, const char* tz, char *buf);
Radek Krejcid0d19522015-09-02 13:49:25 +0200142
143/**
144 * @brief Transform given string in RFC 3339 compliant format to the time_t
145 * (seconds since the epoch) accepted by most Linux functions.
146 *
147 * This is a reverse function to nc_time2datetime().
148 *
149 * @param[in] datetime Time structure returned e.g. by localtime().
Radek Krejciebe263f2016-05-31 15:59:07 +0200150 * @return time_t value of the given string, -1 on error.
Radek Krejcid0d19522015-09-02 13:49:25 +0200151 */
152time_t nc_datetime2time(const char* datetime);
153
Radek Krejci6799a052017-05-19 14:23:23 +0200154/**@} Miscellaneous */
155
Radek Krejcid0d19522015-09-02 13:49:25 +0200156#ifdef __cplusplus
157}
158#endif
159
160#endif /* NC_NETCONF_H_ */