roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 1 | /** |
| 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 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 19 | #include <libyang/libyang.h> |
| 20 | #include <stdint.h> |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 21 | #include <stdlib.h> |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 22 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 23 | #include "session_p.h" |
| 24 | |
| 25 | /** |
| 26 | * Enumeration of ietf-netconf-server's modules/trees (top-level containers) |
| 27 | */ |
| 28 | typedef enum { |
| 29 | NC_MODULE_NETCONF_SERVER, |
| 30 | NC_MODULE_KEYSTORE, |
roman | e474d4d | 2024-07-09 14:12:06 +0200 | [diff] [blame] | 31 | NC_MODULE_TRUSTSTORE, |
| 32 | NC_MODULE_LIBNETCONF2_NETCONF_SERVER |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 33 | } NC_MODULE; |
| 34 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 35 | #ifdef NC_ENABLED_SSH_TLS |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 36 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 37 | /** |
| 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 | */ |
| 43 | NC_PRIVKEY_FORMAT nc_server_config_get_private_key_type(const char *format); |
| 44 | |
| 45 | #endif /* NC_ENABLED_SSH_TLS */ |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 46 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 47 | /** |
| 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 | */ |
| 55 | int 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 | */ |
| 66 | int 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 | */ |
roman | 0bbc19c | 2023-05-26 09:59:09 +0200 | [diff] [blame] | 76 | int nc_server_config_parse_tree(const struct lyd_node *node, NC_OPERATION parent_op, NC_MODULE module); |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 77 | |
| 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 | */ |
roman | 6430c15 | 2023-10-12 11:28:47 +0200 | [diff] [blame] | 85 | int nc_server_config_listen(const struct lyd_node *node, NC_OPERATION op); |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 86 | |
roman | 6430c15 | 2023-10-12 11:28:47 +0200 | [diff] [blame] | 87 | /** |
| 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 | */ |
| 94 | int nc_server_config_ch(const struct lyd_node *node, NC_OPERATION op); |
roman | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame] | 95 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 96 | #ifdef NC_ENABLED_SSH_TLS |
| 97 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 98 | /** 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 | */ |
| 107 | int 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 | */ |
| 116 | int 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 | */ |
| 125 | int 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 | */ |
| 136 | int 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 | */ |
| 145 | int 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 | */ |
| 154 | int nc_server_config_ts_truststore(const struct lyd_node *node, NC_OPERATION op); |
| 155 | |
roman | e474d4d | 2024-07-09 14:12:06 +0200 | [diff] [blame] | 156 | /** 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 | */ |
| 165 | int nc_server_config_ln2_netconf_server(const struct lyd_node *node, NC_OPERATION op); |
| 166 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 167 | #endif /* NC_ENABLED_SSH_TLS */ |
| 168 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 169 | #endif /* NC_CONFIG_SERVER_P_H_ */ |