blob: 9ab8ba0b5f558e07467163ddacc47b710bd22e51 [file] [log] [blame]
romanf02273a2023-05-25 09:44:11 +02001/**
2 * @file server_config_p.h
3 * @author Roman Janota <janota@cesnet.cz>
4 * @brief libnetconf2 server configuration
5 *
6 * @copyright
7 * Copyright (c) 2023 CESNET, z.s.p.o.
8 *
9 * 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
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
16#ifndef NC_CONFIG_SERVER_P_H_
17#define NC_CONFIG_SERVER_P_H_
18
romanf02273a2023-05-25 09:44:11 +020019#include <libyang/libyang.h>
20#include <stdint.h>
roman3f9b65c2023-06-05 14:26:58 +020021#include <stdlib.h>
romanf02273a2023-05-25 09:44:11 +020022
romanf02273a2023-05-25 09:44:11 +020023#include "session_p.h"
24
25/**
26 * Enumeration of ietf-netconf-server's modules/trees (top-level containers)
27 */
28typedef enum {
29 NC_MODULE_NETCONF_SERVER,
30 NC_MODULE_KEYSTORE,
romane474d4d2024-07-09 14:12:06 +020031 NC_MODULE_TRUSTSTORE,
32 NC_MODULE_LIBNETCONF2_NETCONF_SERVER
romanf02273a2023-05-25 09:44:11 +020033} NC_MODULE;
34
roman2eab4742023-06-06 10:00:26 +020035#ifdef NC_ENABLED_SSH_TLS
romanf02273a2023-05-25 09:44:11 +020036
roman2eab4742023-06-06 10:00:26 +020037/**
38 * @brief Get private key type from YANG identity stored in a string.
39 *
40 * @param[in] format Value of the YANG identityref.
41 * @return Private key format on success, NC_PRIVKEY_FORMAT_UNKNOWN otherwise.
42 */
43NC_PRIVKEY_FORMAT nc_server_config_get_private_key_type(const char *format);
44
45#endif /* NC_ENABLED_SSH_TLS */
roman3f9b65c2023-06-05 14:26:58 +020046
romanf02273a2023-05-25 09:44:11 +020047/**
48 * @brief Compares the nth-parent name.
49 *
50 * @param[in] node Node of which nth-parent to compare.
51 * @param[in] parent_count Count of parents.
52 * @param[in] parent_name Expected name of the parent.
53 * @return 1 if the name matches, 0 otherwise.
54 */
55int equal_parent_name(const struct lyd_node *node, uint16_t parent_count, const char *parent_name);
56
57/**
58 * @brief Generic realloc function for arrays of structures representing YANG lists whose first member is the key (char *)
59 *
60 * @param[in] key_value Value of the key, which will be assigned to the first member of the given struct.
61 * @param[in] size Size of a member of the array.
62 * @param[in,out] ptr Pointer to the beginning of the given array, which will be reallocated.
63 * @param[in,out] count Count of members in the array, incremented at the end.
64 * @return 0 on success, 1 on error.
65 */
66int nc_server_config_realloc(const char *key_value, void **ptr, size_t size, uint16_t *count);
67
68/**
69 * @brief Recursively parse the given tree and apply it's data to the server's configuration.
70 *
71 * @param[in] node YANG data tree.
72 * @param[in] parent_op Operation of the parent.
73 * @param[in] module Module for which to parse the data - either ietf-netconf-server, ietf-keystore or ietf-truststore
74 * @return 0 on success, 1 on error.
75 */
roman0bbc19c2023-05-26 09:59:09 +020076int nc_server_config_parse_tree(const struct lyd_node *node, NC_OPERATION parent_op, NC_MODULE module);
romanf02273a2023-05-25 09:44:11 +020077
78/**
79 * @brief Configures the listen subtree in the ietf-netconf-server module.
80 *
81 * @param[in] node Listen YANG data node.
82 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
83 * @return 0 on success, 1 on error.
84 */
roman6430c152023-10-12 11:28:47 +020085int nc_server_config_listen(const struct lyd_node *node, NC_OPERATION op);
romanf02273a2023-05-25 09:44:11 +020086
roman6430c152023-10-12 11:28:47 +020087/**
88 * @brief Configures the Call Home subtree in the ietf-netconf-server module.
89 *
90 * @param[in] node call-home YANG data node.
91 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
92 * @return 0 on success, 1 on error.
93 */
94int nc_server_config_ch(const struct lyd_node *node, NC_OPERATION op);
roman5cbb6532023-06-22 12:53:17 +020095
roman2eab4742023-06-06 10:00:26 +020096#ifdef NC_ENABLED_SSH_TLS
97
romanf02273a2023-05-25 09:44:11 +020098/** KEYSTORE **/
99
100/**
101 * @brief Checks if keystore tree is present in the data and if yes, tries to apply it's data.
102 *
103 * @param[in] data YANG data tree.
104 * @param[in] op Operation saying what to do with the top-level node.
105 * @return 0 either if keystore is not present or if it is and application was successful, 1 on error.
106 */
107int nc_server_config_fill_keystore(const struct lyd_node *data, NC_OPERATION op);
108
109/**
110 * @brief Parse the given node, which belongs to the ietf-keystore subtree, and apply it's data to the server's configuration.
111 *
112 * @param[in] node YANG data node.
113 * @param[in] op Operation saying what to do with the node.
114 * @return 0 on success, 1 on error.
115 */
116int nc_server_config_parse_keystore(const struct lyd_node *node, NC_OPERATION op);
117
118/**
119 * @brief Configures the keystore subtree in the ietf-keystore module.
120 *
121 * @param[in] node Keystore YANG data node.
122 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
123 * @return 0.
124 */
125int nc_server_config_ks_keystore(const struct lyd_node *node, NC_OPERATION op);
126
127/** TRUSTSTORE **/
128
129/**
130 * @brief Checks if truststore tree is present in the data and if yes, tries to apply it's data.
131 *
132 * @param[in] data YANG data tree.
133 * @param[in] op Operation saying what to do with the top-level node.
134 * @return 0 either if truststore is not present or if it is and application was successful, 1 on error.
135 */
136int nc_server_config_fill_truststore(const struct lyd_node *data, NC_OPERATION op);
137
138/**
139 * @brief Parse the given node, which belongs to the ietf-truststore subtree, and apply it's data to the server's configuration.
140 *
141 * @param[in] node YANG data node.
142 * @param[in] op Operation saying what to do with the node.
143 * @return 0 on success, 1 on error.
144 */
145int nc_server_config_parse_truststore(const struct lyd_node *node, NC_OPERATION op);
146
147/**
148 * @brief Configures the truststore subtree in the ietf-truststore module.
149 *
150 * @param[in] node Truststore YANG data node.
151 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
152 * @return 0.
153 */
154int nc_server_config_ts_truststore(const struct lyd_node *node, NC_OPERATION op);
155
romane474d4d2024-07-09 14:12:06 +0200156/** LIBNETCONF2-NETCONF-SERVER **/
157
158/**
159 * @brief Configures the ln2-netconf-server subtree in the libnetconf2-netconf-server module.
160 *
161 * @param[in] node Optional ln2-netconf-server YANG data node.
162 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
163 * @return 0 on success, 1 on error.
164 */
165int nc_server_config_ln2_netconf_server(const struct lyd_node *node, NC_OPERATION op);
166
roman2eab4742023-06-06 10:00:26 +0200167#endif /* NC_ENABLED_SSH_TLS */
168
romanf02273a2023-05-25 09:44:11 +0200169#endif /* NC_CONFIG_SERVER_P_H_ */