blob: 48058cb210d4a1b01e854720db2b2476aee074ae [file] [log] [blame]
Radek Krejcid0d19522015-09-02 13:49:25 +02001/**
Michal Vaskoc446a382021-06-18 08:54:05 +02002 * @file netconf.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libnetconf2's general public functions and structures definitions.
Radek Krejcid0d19522015-09-02 13:49:25 +02005 *
Michal Vasko4848ac82021-11-09 12:29:14 +01006 * @copyright
Michal Vaskoc446a382021-06-18 08:54:05 +02007 * Copyright (c) 2015 - 2021 CESNET, z.s.p.o.
Radek Krejcid0d19522015-09-02 13:49:25 +02008 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01009 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010012 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010013 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejcid0d19522015-09-02 13:49:25 +020014 */
15
16#ifndef NC_NETCONF_H_
17#define NC_NETCONF_H_
18
Radek Krejcid0d19522015-09-02 13:49:25 +020019#ifdef __cplusplus
20extern "C" {
21#endif
22
Michal Vaskoc09730e2019-01-17 10:07:26 +010023#include <time.h>
24
Radek Krejci6799a052017-05-19 14:23:23 +020025/**
26 * @addtogroup misc
27 * @{
28 */
29
30/** @brief Base NETCONF namespace */
Radek Krejci206fcd62015-10-07 15:42:48 +020031#define NC_NS_BASE "urn:ietf:params:xml:ns:netconf:base:1.0"
Radek Krejci6799a052017-05-19 14:23:23 +020032/** @brief Notifications namespace */
Radek Krejci206fcd62015-10-07 15:42:48 +020033#define NC_NS_NOTIF "urn:ietf:params:xml:ns:netconf:notification:1.0"
34
Radek Krejciac6d3472015-10-22 15:47:18 +020035/** @brief Default NETCONF over SSH port */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010036#define NC_PORT_SSH 830
37/** @brief Default NETCONF over SSH Call Home port */
Michal Vasko3b090292017-02-03 11:43:47 +010038#define NC_PORT_CH_SSH 4334
Michal Vasko38a7c6c2015-12-04 12:29:20 +010039
Radek Krejciac6d3472015-10-22 15:47:18 +020040/** @brief Default NETCONF over TLS port */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010041#define NC_PORT_TLS 6513
42/** @brief Default NETCONF over TLS Call Home port */
Michal Vasko3b090292017-02-03 11:43:47 +010043#define NC_PORT_CH_TLS 4335
Radek Krejciac6d3472015-10-22 15:47:18 +020044
Radek Krejcid0d19522015-09-02 13:49:25 +020045/**
Michal Vasko3a889fd2016-09-30 12:16:37 +020046 * @brief Set RPC callback to a schema node.
47 *
Michal Vasko49eb3f42021-05-19 10:20:57 +020048 * @param[in] node const struct lysc_node *node
Michal Vasko3a889fd2016-09-30 12:16:37 +020049 * @param[in] cb nc_rpc_clb cb
50 */
Michal Vasko49eb3f42021-05-19 10:20:57 +020051#define nc_set_rpc_callback(node, cb) (node->priv = cb)
Michal Vasko3a889fd2016-09-30 12:16:37 +020052
53/**
Radek Krejcid0d19522015-09-02 13:49:25 +020054 * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
55 */
56typedef enum NC_SESSION_TERM_REASON {
Radek Krejci465308c2017-05-22 14:49:10 +020057 NC_SESSION_TERM_ERR = -1, /**< error return code for function getting the session termination reason */
Michal Vasko428087d2016-01-14 16:04:28 +010058 NC_SESSION_TERM_NONE = 0, /**< session still running */
59 NC_SESSION_TERM_CLOSED, /**< closed by client in a normal fashion */
60 NC_SESSION_TERM_KILLED, /**< session was terminated by \<kill-session\> operation */
61 NC_SESSION_TERM_DROPPED, /**< transport layer connection was unexpectedly closed */
62 NC_SESSION_TERM_TIMEOUT, /**< terminated because of inactivity */
63 NC_SESSION_TERM_BADHELLO, /**< \<hello\> message was invalid */
64 NC_SESSION_TERM_OTHER /**< terminated for some other reason */
Radek Krejcid0d19522015-09-02 13:49:25 +020065} NC_SESSION_TERM_REASON;
66
67/**
Radek Krejci43390242015-10-08 15:34:04 +020068 * @brief Enumeration of NETCONF message types.
69 */
70typedef enum NC_MSG_TYPE {
Michal Vasko71ba2da2016-05-04 10:53:16 +020071 NC_MSG_ERROR, /**< error return value */
72 NC_MSG_WOULDBLOCK, /**< timeout return value */
73 NC_MSG_NONE, /**< no message at input or message was processed internally */
74 NC_MSG_HELLO, /**< \<hello\> message */
Michal Vasko71090fc2016-05-24 16:37:28 +020075 NC_MSG_BAD_HELLO, /**< \<hello\> message parsing failed */
Michal Vasko71ba2da2016-05-04 10:53:16 +020076 NC_MSG_RPC, /**< \<rpc\> message */
77 NC_MSG_REPLY, /**< \<rpc-reply\> message */
78 NC_MSG_REPLY_ERR_MSGID, /**< \<rpc-reply\> message with missing or wrong message-id attribute value */
79 NC_MSG_NOTIF /**< \<notification\> message */
Radek Krejci43390242015-10-08 15:34:04 +020080} NC_MSG_TYPE;
81
82/**
Michal Vasko8fe604c2020-02-10 15:25:04 +010083 * @brief Messages of NETCONF message type enum.
84 */
85extern const char *nc_msgtype2str[];
86
87/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020088 * @brief Enumeration of the supported types of datastores defined by NETCONF
89 */
90typedef enum NC_DATASTORE_TYPE {
Michal Vasko7f1c78b2016-01-19 09:52:14 +010091 NC_DATASTORE_ERROR = 0, /**< error state of functions returning the datastore type */
92 NC_DATASTORE_CONFIG, /**< value describing that the datastore is set as config */
93 NC_DATASTORE_URL, /**< value describing that the datastore data should be given from the URL */
94 NC_DATASTORE_RUNNING, /**< base NETCONF's datastore containing the current device configuration */
95 NC_DATASTORE_STARTUP, /**< separated startup datastore as defined in Distinct Startup Capability */
96 NC_DATASTORE_CANDIDATE /**< separated working datastore as defined in Candidate Configuration Capability */
Radek Krejci695d4fa2015-10-22 13:23:54 +020097} NC_DATASTORE;
98
Michal Vasko1a38c862016-01-15 15:50:07 +010099/**
100 * @brief Enumeration of NETCONF with-defaults capability modes.
101 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100102typedef enum NC_WITHDEFAULTS_MODE {
Michal Vasko1a38c862016-01-15 15:50:07 +0100103 NC_WD_UNKNOWN = 0, /**< invalid mode */
Radek Krejci36dfdb32016-09-01 16:56:35 +0200104 NC_WD_ALL, /**< report-all mode */
105 NC_WD_ALL_TAG, /**< report-all-tagged mode */
106 NC_WD_TRIM, /**< trim mode */
107 NC_WD_EXPLICIT /**< explicit mode */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100108} NC_WD_MODE;
109
Michal Vasko1a38c862016-01-15 15:50:07 +0100110/**
111 * @brief Enumeration of NETCONF (both server and client) rpc-reply types.
112 */
Michal Vasko495c9462016-01-15 11:27:43 +0100113typedef enum NC_REPLY {
Michal Vasko1a38c862016-01-15 15:50:07 +0100114 NC_RPL_OK, /**< OK rpc-reply */
115 NC_RPL_DATA, /**< DATA rpc-reply */
116 NC_RPL_ERROR, /**< ERROR rpc-reply */
117 NC_RPL_NOTIF /**< notification (client-only) */
Michal Vasko495c9462016-01-15 11:27:43 +0100118} NC_RPL;
119
Radek Krejci695d4fa2015-10-22 13:23:54 +0200120/**
Michal Vasko1a38c862016-01-15 15:50:07 +0100121 * @brief Enumeration of function parameter treatments.
122 */
123typedef enum NC_PARAMTYPE {
124 NC_PARAMTYPE_CONST, /**< use the parameter directly, do not free */
125 NC_PARAMTYPE_FREE, /**< use the parameter directly, free afterwards */
126 NC_PARAMTYPE_DUP_AND_FREE /**< make a copy of the argument, free afterwards */
127} NC_PARAMTYPE;
128
Michal Vasko49eb3f42021-05-19 10:20:57 +0200129/** @} Miscellaneous */
Radek Krejci6799a052017-05-19 14:23:23 +0200130
Radek Krejcid0d19522015-09-02 13:49:25 +0200131#ifdef __cplusplus
132}
133#endif
134
135#endif /* NC_NETCONF_H_ */