blob: 15584257845da29cac4c8b4fcd1abfb54be8eb13 [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,
31 NC_MODULE_TRUSTSTORE
32} NC_MODULE;
33
roman2eab4742023-06-06 10:00:26 +020034#ifdef NC_ENABLED_SSH_TLS
romanf02273a2023-05-25 09:44:11 +020035
roman2eab4742023-06-06 10:00:26 +020036/**
37 * @brief Get private key type from YANG identity stored in a string.
38 *
39 * @param[in] format Value of the YANG identityref.
40 * @return Private key format on success, NC_PRIVKEY_FORMAT_UNKNOWN otherwise.
41 */
42NC_PRIVKEY_FORMAT nc_server_config_get_private_key_type(const char *format);
43
44#endif /* NC_ENABLED_SSH_TLS */
roman3f9b65c2023-06-05 14:26:58 +020045
romanf02273a2023-05-25 09:44:11 +020046/**
47 * @brief Compares the nth-parent name.
48 *
49 * @param[in] node Node of which nth-parent to compare.
50 * @param[in] parent_count Count of parents.
51 * @param[in] parent_name Expected name of the parent.
52 * @return 1 if the name matches, 0 otherwise.
53 */
54int equal_parent_name(const struct lyd_node *node, uint16_t parent_count, const char *parent_name);
55
56/**
57 * @brief Generic realloc function for arrays of structures representing YANG lists whose first member is the key (char *)
58 *
59 * @param[in] key_value Value of the key, which will be assigned to the first member of the given struct.
60 * @param[in] size Size of a member of the array.
61 * @param[in,out] ptr Pointer to the beginning of the given array, which will be reallocated.
62 * @param[in,out] count Count of members in the array, incremented at the end.
63 * @return 0 on success, 1 on error.
64 */
65int nc_server_config_realloc(const char *key_value, void **ptr, size_t size, uint16_t *count);
66
67/**
68 * @brief Recursively parse the given tree and apply it's data to the server's configuration.
69 *
70 * @param[in] node YANG data tree.
71 * @param[in] parent_op Operation of the parent.
72 * @param[in] module Module for which to parse the data - either ietf-netconf-server, ietf-keystore or ietf-truststore
73 * @return 0 on success, 1 on error.
74 */
roman0bbc19c2023-05-26 09:59:09 +020075int nc_server_config_parse_tree(const struct lyd_node *node, NC_OPERATION parent_op, NC_MODULE module);
romanf02273a2023-05-25 09:44:11 +020076
77/**
78 * @brief Configures the listen subtree in the ietf-netconf-server module.
79 *
80 * @param[in] node Listen YANG data node.
81 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
82 * @return 0 on success, 1 on error.
83 */
roman6430c152023-10-12 11:28:47 +020084int nc_server_config_listen(const struct lyd_node *node, NC_OPERATION op);
romanf02273a2023-05-25 09:44:11 +020085
roman6430c152023-10-12 11:28:47 +020086/**
87 * @brief Configures the Call Home subtree in the ietf-netconf-server module.
88 *
89 * @param[in] node call-home YANG data node.
90 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
91 * @return 0 on success, 1 on error.
92 */
93int nc_server_config_ch(const struct lyd_node *node, NC_OPERATION op);
roman5cbb6532023-06-22 12:53:17 +020094
roman2eab4742023-06-06 10:00:26 +020095#ifdef NC_ENABLED_SSH_TLS
96
romanf02273a2023-05-25 09:44:11 +020097/** KEYSTORE **/
98
99/**
100 * @brief Checks if keystore tree is present in the data and if yes, tries to apply it's data.
101 *
102 * @param[in] data YANG data tree.
103 * @param[in] op Operation saying what to do with the top-level node.
104 * @return 0 either if keystore is not present or if it is and application was successful, 1 on error.
105 */
106int nc_server_config_fill_keystore(const struct lyd_node *data, NC_OPERATION op);
107
108/**
109 * @brief Parse the given node, which belongs to the ietf-keystore subtree, and apply it's data to the server's configuration.
110 *
111 * @param[in] node YANG data node.
112 * @param[in] op Operation saying what to do with the node.
113 * @return 0 on success, 1 on error.
114 */
115int nc_server_config_parse_keystore(const struct lyd_node *node, NC_OPERATION op);
116
117/**
118 * @brief Configures the keystore subtree in the ietf-keystore module.
119 *
120 * @param[in] node Keystore YANG data node.
121 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
122 * @return 0.
123 */
124int nc_server_config_ks_keystore(const struct lyd_node *node, NC_OPERATION op);
125
126/** TRUSTSTORE **/
127
128/**
129 * @brief Checks if truststore tree is present in the data and if yes, tries to apply it's data.
130 *
131 * @param[in] data YANG data tree.
132 * @param[in] op Operation saying what to do with the top-level node.
133 * @return 0 either if truststore is not present or if it is and application was successful, 1 on error.
134 */
135int nc_server_config_fill_truststore(const struct lyd_node *data, NC_OPERATION op);
136
137/**
138 * @brief Parse the given node, which belongs to the ietf-truststore subtree, and apply it's data to the server's configuration.
139 *
140 * @param[in] node YANG data node.
141 * @param[in] op Operation saying what to do with the node.
142 * @return 0 on success, 1 on error.
143 */
144int nc_server_config_parse_truststore(const struct lyd_node *node, NC_OPERATION op);
145
146/**
147 * @brief Configures the truststore subtree in the ietf-truststore module.
148 *
149 * @param[in] node Truststore YANG data node.
150 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
151 * @return 0.
152 */
153int nc_server_config_ts_truststore(const struct lyd_node *node, NC_OPERATION op);
154
roman2eab4742023-06-06 10:00:26 +0200155#endif /* NC_ENABLED_SSH_TLS */
156
romanf02273a2023-05-25 09:44:11 +0200157#endif /* NC_CONFIG_SERVER_P_H_ */