blob: cb0000b43b0f188bc53e99f37864accfad799e42 [file] [log] [blame]
Radek Krejcib1c12512015-08-11 11:22:04 +02001/**
2 * @file validation.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Data tree validation functions
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci54f6fb32016-02-24 12:56:39 +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 Vasko8de098c2016-02-26 10:00:25 +010011 *
Radek Krejci54f6fb32016-02-24 12:56:39 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejcib1c12512015-08-11 11:22:04 +020013 */
14
Radek Krejcieab784a2015-08-27 09:56:53 +020015#include <assert.h>
Radek Krejcib1c12512015-08-11 11:22:04 +020016#include <stdlib.h>
Michal Vaskocf024702015-10-08 15:01:42 +020017#include <string.h>
Radek Krejcib1c12512015-08-11 11:22:04 +020018
Radek Krejcieab784a2015-08-27 09:56:53 +020019#include "common.h"
Michal Vaskocf024702015-10-08 15:01:42 +020020#include "validation.h"
Radek Krejcib1c12512015-08-11 11:22:04 +020021#include "libyang.h"
Michal Vaskocf024702015-10-08 15:01:42 +020022#include "xpath.h"
Radek Krejcicf509982015-12-15 09:22:44 +010023#include "parser.h"
Michal Vaskocf024702015-10-08 15:01:42 +020024#include "resolve.h"
25#include "tree_internal.h"
Michal Vaskofc5744d2015-10-22 12:09:34 +020026#include "xml_internal.h"
Radek Krejcib1c12512015-08-11 11:22:04 +020027
Radek Krejcib45b3082016-09-09 16:08:51 +020028static int
Radek Krejci48464ed2016-03-17 15:44:09 +010029lyv_keys(const struct lyd_node *list)
Radek Krejcib1c12512015-08-11 11:22:04 +020030{
Radek Krejci702deb82016-03-09 12:37:57 +010031 struct lyd_node *child;
32 struct lys_node_list *schema = (struct lys_node_list *)list->schema; /* shortcut */
Radek Krejcib1c12512015-08-11 11:22:04 +020033 int i;
34
Radek Krejci702deb82016-03-09 12:37:57 +010035 for (i = 0, child = list->child; i < schema->keys_size; i++, child = child->next) {
36 if (!child || child->schema != (struct lys_node *)schema->keys[i]) {
37 /* key not found on the correct place */
Radek Krejci48464ed2016-03-17 15:44:09 +010038 LOGVAL(LYE_MISSELEM, LY_VLOG_LYD, list, schema->keys[i]->name, schema->name);
Radek Krejci702deb82016-03-09 12:37:57 +010039 for ( ; child; child = child->next) {
40 if (child->schema == (struct lys_node *)schema->keys[i]) {
Radek Krejci48464ed2016-03-17 15:44:09 +010041 LOGVAL(LYE_SPEC, LY_VLOG_LYD, child, "Invalid position of the key element.");
Radek Krejci702deb82016-03-09 12:37:57 +010042 break;
43 }
Radek Krejcib1c12512015-08-11 11:22:04 +020044 }
Radek Krejci702deb82016-03-09 12:37:57 +010045 return EXIT_FAILURE;
Radek Krejcib1c12512015-08-11 11:22:04 +020046 }
47 }
Radek Krejcib1c12512015-08-11 11:22:04 +020048 return EXIT_SUCCESS;
49}
Radek Krejcieab784a2015-08-27 09:56:53 +020050
51int
Radek Krejci48464ed2016-03-17 15:44:09 +010052lyv_data_context(const struct lyd_node *node, int options, struct unres_data *unres)
Radek Krejcieab784a2015-08-27 09:56:53 +020053{
Radek Krejci6baaa9a2016-02-23 16:07:12 +010054 const struct lys_node *siter = NULL;
Radek Krejcib1f318b2016-08-22 16:18:37 +020055 struct lyd_node_leaf_list *leaf = (struct lyd_node_leaf_list *)node;
Radek Krejci4a49bdf2016-01-12 17:17:01 +010056
Michal Vaskocf024702015-10-08 15:01:42 +020057 assert(node);
Radek Krejci03b71f72016-03-16 11:10:09 +010058 assert(unres);
Radek Krejcieab784a2015-08-27 09:56:53 +020059
60 /* check if the node instance is enabled by if-feature */
Michal Vaskocf024702015-10-08 15:01:42 +020061 if (lys_is_disabled(node->schema, 2)) {
Radek Krejci48464ed2016-03-17 15:44:09 +010062 LOGVAL(LYE_INELEM, LY_VLOG_LYD, node, node->schema->name);
Michal Vaskocf024702015-10-08 15:01:42 +020063 return EXIT_FAILURE;
64 }
65
Radek Krejcib1f318b2016-08-22 16:18:37 +020066 if (node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
Michal Vaskoe3886bb2017-01-02 11:33:28 +010067 /* if union with leafref/intsid, leafref itself (invalid) or instance-identifier, store the node for later resolving */
68 if ((((struct lys_node_leaf *)leaf->schema)->type.base == LY_TYPE_UNION)
69 && ((struct lys_node_leaf *)leaf->schema)->type.info.uni.has_ptr_type) {
70 if (unres_data_add(unres, (struct lyd_node *)node, UNRES_UNION)) {
71 return EXIT_FAILURE;
Radek Krejci0b7704f2016-03-18 12:16:14 +010072 }
Michal Vaskoe3886bb2017-01-02 11:33:28 +010073 } else if ((((struct lys_node_leaf *)leaf->schema)->type.base == LY_TYPE_LEAFREF) && (leaf->validity & LYD_VAL_LEAFREF)) {
74 if (unres_data_add(unres, (struct lyd_node *)node, UNRES_LEAFREF)) {
75 return EXIT_FAILURE;
76 }
77 } else if (((struct lys_node_leaf *)leaf->schema)->type.base == LY_TYPE_INST) {
78 if (unres_data_add(unres, (struct lyd_node *)node, UNRES_INSTID)) {
79 return EXIT_FAILURE;
Radek Krejci0b7704f2016-03-18 12:16:14 +010080 }
Michal Vasko0d182ba2015-10-09 09:29:14 +020081 }
Radek Krejci0b7704f2016-03-18 12:16:14 +010082 }
83
Michal Vaskocf024702015-10-08 15:01:42 +020084 /* check all relevant when conditions */
Michal Vaskob1bc1d92017-01-05 11:47:41 +010085 if (!(options & LYD_OPT_TRUSTED) && (node->when_status & LYD_WHEN)) {
Radek Krejci0b7704f2016-03-18 12:16:14 +010086 if (unres_data_add(unres, (struct lyd_node *)node, UNRES_WHEN)) {
Michal Vasko0d182ba2015-10-09 09:29:14 +020087 return EXIT_FAILURE;
88 }
Radek Krejcieab784a2015-08-27 09:56:53 +020089 }
90
91 /* check for (non-)presence of status data in edit-config data */
Radek Krejci4a49bdf2016-01-12 17:17:01 +010092 if ((options & (LYD_OPT_EDIT | LYD_OPT_GETCONFIG | LYD_OPT_CONFIG)) && (node->schema->flags & LYS_CONFIG_R)) {
Radek Krejci48464ed2016-03-17 15:44:09 +010093 LOGVAL(LYE_INELEM, LY_VLOG_LYD, node, node->schema->name);
Radek Krejcieab784a2015-08-27 09:56:53 +020094 return EXIT_FAILURE;
95 }
96
Radek Krejci4a49bdf2016-01-12 17:17:01 +010097 /* check elements order in case of RPC's input and output */
Michal Vaskoad2e44a2017-01-03 10:31:35 +010098 if (!(options & (LYD_OPT_TRUSTED | LYD_OPT_NOTIF_FILTER)) && (node->validity & LYD_VAL_MAND) && lyp_is_rpc_action(node->schema)) {
Michal Vasko15e0bab2016-02-24 13:58:21 +010099 if ((node->prev != node) && node->prev->next) {
Michal Vaskodcf98e62016-05-05 17:53:53 +0200100 for (siter = lys_getnext(node->schema, lys_parent(node->schema), node->schema->module, 0);
Radek Krejci6baaa9a2016-02-23 16:07:12 +0100101 siter;
Michal Vaskodcf98e62016-05-05 17:53:53 +0200102 siter = lys_getnext(siter, lys_parent(siter), siter->module, 0)) {
Radek Krejci6baaa9a2016-02-23 16:07:12 +0100103 if (siter == node->prev->schema) {
104 /* data predecessor has the schema node after
105 * the schema node of the data node being checked */
Radek Krejci48464ed2016-03-17 15:44:09 +0100106 LOGVAL(LYE_INORDER, LY_VLOG_LYD, node, node->schema->name, siter->name);
Radek Krejci6baaa9a2016-02-23 16:07:12 +0100107 return EXIT_FAILURE;
Radek Krejci4a49bdf2016-01-12 17:17:01 +0100108 }
Radek Krejci4a49bdf2016-01-12 17:17:01 +0100109 }
110
Radek Krejci4a49bdf2016-01-12 17:17:01 +0100111 }
112 }
113
Radek Krejcieab784a2015-08-27 09:56:53 +0200114 return EXIT_SUCCESS;
115}
Michal Vaskocf024702015-10-08 15:01:42 +0200116
Radek Krejci63b79c82016-08-10 10:09:33 +0200117struct eq_item {
118 struct lyd_node *node;
119 uint32_t hash;
120 uint32_t over;
121};
122
123static int
124eq_table_insert(struct eq_item *table, struct lyd_node *node, uint32_t hash, uint32_t tablesize, int action)
125{
126 uint32_t i, c;
127
128 if (table[hash].node) {
129 /* is it collision or is the cell just filled by an overflow item? */
130 for (i = hash; table[i].node && table[i].hash != hash; i = (i + 1) % tablesize);
131 if (!table[i].node) {
132 goto first;
133 }
134
135 /* collision or instance duplication */
136 c = table[i].over;
137 do {
138 if (table[i].hash != hash) {
139 i = (i + 1) % tablesize;
140 continue;
141 }
142
143 /* compare nodes */
144 if (lyd_list_equal(node, table[i].node, action, 1)) {
145 /* instance duplication */
146 return EXIT_FAILURE;
147 }
148 } while (c--);
149
150 /* collision, insert item into next free cell */
151 table[hash].over++;
152 for (i = (i + 1) % tablesize; table[i].node; i = (i + 1) % tablesize);
153 table[i].hash = hash;
154 table[i].node = node;
155 } else {
156first:
157 /* first hash instance */
158 table[hash].node = node;
159 table[hash].hash = hash;
160 }
161
162 return EXIT_SUCCESS;
163}
164
165int
166lyv_data_unique(struct lyd_node *node, struct lyd_node *start)
167{
168 struct lyd_node *diter, *key;
169 struct lys_node_list *slist;
170 struct ly_set *set;
171 int i, j, n = 0, ret = EXIT_SUCCESS;
172 uint32_t hash, u, usize = 0, hashmask;
173 struct eq_item *keystable = NULL, **uniquetables = NULL;
174 const char *id;
175
176 /* get the first list/leaflist instance sibling */
177 if (!start) {
178 start = lyd_first_sibling(node);
179 }
180
181 /* check uniqueness of the list/leaflist instances (compare values) */
182 set = ly_set_new();
183 for (diter = start; diter; diter = diter->next) {
184 if (diter->schema != node->schema) {
185 /* check only instances of the same list/leaflist */
186 continue;
187 }
188
189 /* remove the flag */
190 diter->validity &= ~LYD_VAL_UNIQUE;
191
192 /* store for comparison */
193 ly_set_add(set, diter, LY_SET_OPT_USEASLIST);
194 }
195
196 if (set->number == 2) {
197 /* simple comparison */
198 if (lyd_list_equal(set->set.d[0], set->set.d[1], -1, 1)) {
199 /* instance duplication */
200 ly_set_free(set);
201 return EXIT_FAILURE;
202 }
203 } else if (set->number > 2) {
204 /* use hashes for comparison */
205 /* first, allocate the table, the size depends on number of items in the set */
206 for (u = 31; u > 0; u--) {
207 usize = set->number << u;
208 usize = usize >> u;
209 if (usize == set->number) {
210 break;
211 }
212 }
213 if (u == 0) {
214 usize = hashmask = 0xffffffff;
215 } else {
216 u = 32 - u;
217 usize = 1 << u;
218 hashmask = usize - 1;
219 }
220 keystable = calloc(usize, sizeof *keystable);
221 if (!keystable) {
222 LOGMEM;
223 ret = EXIT_FAILURE;
224 goto unique_cleanup;
225 }
226 n = 0;
227 if (node->schema->nodetype == LYS_LIST) {
228 n = ((struct lys_node_list *)node->schema)->unique_size;
229 uniquetables = malloc(n * sizeof *uniquetables);
230 if (!uniquetables) {
231 LOGMEM;
232 ret = EXIT_FAILURE;
Radek Krejci70292d22016-08-15 09:39:22 +0200233 n = 0;
Radek Krejci63b79c82016-08-10 10:09:33 +0200234 goto unique_cleanup;
235 }
236 for (j = 0; j < n; j++) {
237 uniquetables[j] = calloc(usize, sizeof **uniquetables);
238 if (!uniquetables[j]) {
239 LOGMEM;
240 ret = EXIT_FAILURE;
241 goto unique_cleanup;
242 }
243 }
244 }
245
246 for (u = 0; u < set->number; u++) {
247 /* get the hash for the instance - keys */
248 if (node->schema->nodetype == LYS_LEAFLIST) {
249 id = ((struct lyd_node_leaf_list *)set->set.d[u])->value_str;
250 hash = dict_hash_multi(0, id, strlen(id));
251 } else { /* LYS_LIST */
252 for (hash = i = 0, key = set->set.d[u]->child;
253 i < ((struct lys_node_list *)set->set.d[u]->schema)->keys_size;
254 i++, key = key->next) {
255 id = ((struct lyd_node_leaf_list *)key)->value_str;
256 hash = dict_hash_multi(hash, id, strlen(id));
257 }
258 }
259 /* finish the hash value */
260 hash = dict_hash_multi(hash, NULL, 0) & hashmask;
261
262 /* insert into the hashtable */
263 if (eq_table_insert(keystable, set->set.d[u], hash, usize, 0)) {
264 ret = EXIT_FAILURE;
265 goto unique_cleanup;
266 }
267
268 /* and the same loop for unique (n is !0 only in case of list) - get the hash for the instances */
269 for (j = 0; j < n; j++) {
270 slist = (struct lys_node_list *)node->schema;
Radek Krejci50dc7ae2016-09-01 09:56:37 +0200271 id = NULL;
Radek Krejci63b79c82016-08-10 10:09:33 +0200272 for (i = hash = 0; i < slist->unique[j].expr_size; i++) {
273 diter = resolve_data_descendant_schema_nodeid(slist->unique[j].expr[i], set->set.d[u]->child);
274 if (diter) {
275 id = ((struct lyd_node_leaf_list *)diter)->value_str;
276 } else {
277 /* use default value */
Radek Krejcid5a5c282016-08-15 15:38:08 +0200278 id = lyd_get_unique_default(slist->unique[j].expr[i], set->set.d[u]);
Radek Krejci63b79c82016-08-10 10:09:33 +0200279 if (ly_errno) {
280 ret = EXIT_FAILURE;
281 goto unique_cleanup;
282 }
283 }
Radek Krejci2a5f52b2016-08-15 09:14:36 +0200284 if (!id) {
285 /* unique item not present nor has default value */
286 break;
287 }
Radek Krejci63b79c82016-08-10 10:09:33 +0200288 hash = dict_hash_multi(hash, id, strlen(id));
289 }
Radek Krejci2a5f52b2016-08-15 09:14:36 +0200290 if (!id) {
291 /* skip this list instance since its unique set is incomplete */
292 continue;
293 }
Radek Krejci63b79c82016-08-10 10:09:33 +0200294
295 /* finish the hash value */
296 hash = dict_hash_multi(hash, NULL, 0) & hashmask;
297
298 /* insert into the hashtable */
299 if (eq_table_insert(uniquetables[j], set->set.d[u], hash, usize, j + 1)) {
300 ret = EXIT_FAILURE;
301 goto unique_cleanup;
302 }
303 }
304 }
305 }
306
307unique_cleanup:
308 /* cleanup */
309 ly_set_free(set);
310 free(keystable);
311 for (j = 0; j < n; j++) {
312 if (!uniquetables[j]) {
313 /* failed when allocating uniquetables[j], following j are not allocated */
314 break;
315 }
316 free(uniquetables[j]);
317 }
318 free(uniquetables);
319
320 return ret;
321}
322
Radek Krejcieab784a2015-08-27 09:56:53 +0200323int
Radek Krejci48464ed2016-03-17 15:44:09 +0100324lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres)
Radek Krejcieab784a2015-08-27 09:56:53 +0200325{
Michal Vasko1e62a092015-12-01 12:27:20 +0100326 const struct lys_node *schema, *siter;
Radek Krejcid788a522016-07-25 14:57:38 +0200327 struct lyd_node *diter, *start = NULL;
Radek Krejcicf509982015-12-15 09:22:44 +0100328 struct lys_ident *ident;
Radek Krejci4eaf5a82015-12-15 15:10:38 +0100329 struct lys_tpdf *tpdf;
Radek Krejcie6a71b52016-08-10 15:11:16 +0200330 struct lys_type *type = NULL;
Radek Krejcif1ee2e22016-08-02 16:36:48 +0200331 struct lyd_node_leaf_list *leaf;
Radek Krejcie6a71b52016-08-10 15:11:16 +0200332 int i, j = 0;
Radek Krejcif1ee2e22016-08-02 16:36:48 +0200333 uint8_t iff_size;
334 struct lys_iffeature *iff;
335 const char *id, *idname;
Radek Krejcieab784a2015-08-27 09:56:53 +0200336
337 assert(node);
338 assert(node->schema);
Radek Krejci0b7704f2016-03-18 12:16:14 +0100339 assert(unres);
Radek Krejcieab784a2015-08-27 09:56:53 +0200340
341 schema = node->schema; /* shortcut */
342
Michal Vaskoad2e44a2017-01-03 10:31:35 +0100343 if (!(options & (LYD_OPT_TRUSTED | LYD_OPT_NOTIF_FILTER)) && (node->validity & LYD_VAL_MAND)) {
Radek Krejci702deb82016-03-09 12:37:57 +0100344 /* check presence and correct order of all keys in case of list */
Radek Krejci92ece002016-04-04 15:45:05 +0200345 if (schema->nodetype == LYS_LIST && !(options & (LYD_OPT_GET | LYD_OPT_GETCONFIG))) {
Radek Krejci48464ed2016-03-17 15:44:09 +0100346 if (lyv_keys(node)) {
Radek Krejcica7efb72016-01-18 13:06:01 +0100347 return EXIT_FAILURE;
Radek Krejcieab784a2015-08-27 09:56:53 +0200348 }
349 }
Radek Krejcieab784a2015-08-27 09:56:53 +0200350
Radek Krejci46165822016-08-26 14:06:27 +0200351 if (schema->nodetype & (LYS_CONTAINER | LYS_LEAF | LYS_ANYDATA)) {
Radek Krejcid788a522016-07-25 14:57:38 +0200352 /* check number of instances (similar to list uniqueness) for non-list nodes */
Radek Krejci3e0addb2015-08-27 16:37:59 +0200353
Radek Krejcica7efb72016-01-18 13:06:01 +0100354 /* find duplicity */
Radek Krejcid788a522016-07-25 14:57:38 +0200355 start = lyd_first_sibling(node);
Radek Krejcica7efb72016-01-18 13:06:01 +0100356 for (diter = start; diter; diter = diter->next) {
357 if (diter->schema == schema && diter != node) {
Radek Krejci92ece002016-04-04 15:45:05 +0200358 LOGVAL(LYE_TOOMANY, LY_VLOG_LYD, node, schema->name,
Michal Vaskodcf98e62016-05-05 17:53:53 +0200359 lys_parent(schema) ? lys_parent(schema)->name : "data tree");
Radek Krejci92ece002016-04-04 15:45:05 +0200360 return EXIT_FAILURE;
Radek Krejcieab784a2015-08-27 09:56:53 +0200361 }
Radek Krejcieab784a2015-08-27 09:56:53 +0200362 }
Radek Krejcid788a522016-07-25 14:57:38 +0200363 }
Radek Krejcieab784a2015-08-27 09:56:53 +0200364
Michal Vaskoe3886bb2017-01-02 11:33:28 +0100365 if (options & LYD_OPT_OBSOLETE) {
366 /* status - of the node's schema node itself and all its parents that
367 * cannot have their own instance (like a choice statement) */
368 siter = node->schema;
369 do {
370 if (((siter->flags & LYS_STATUS_MASK) == LYS_STATUS_OBSLT) && (options & LYD_OPT_OBSOLETE)) {
371 LOGVAL(LYE_OBSDATA, LY_VLOG_LYD, node, schema->name);
372 return EXIT_FAILURE;
373 }
374 siter = lys_parent(siter);
375 } while (siter && !(siter->nodetype & (LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYDATA)));
376
377 /* status of the identity value */
378 if (schema->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
379 if (options & LYD_OPT_OBSOLETE) {
380 /* check that we are not instantiating obsolete type */
381 tpdf = ((struct lys_node_leaf *)node->schema)->type.der;
382 while (tpdf) {
383 if ((tpdf->flags & LYS_STATUS_MASK) == LYS_STATUS_OBSLT) {
384 LOGVAL(LYE_OBSTYPE, LY_VLOG_LYD, node, schema->name, tpdf->name);
385 return EXIT_FAILURE;
386 }
387 tpdf = tpdf->type.der;
388 }
389 }
390 if (((struct lyd_node_leaf_list *)node)->value_type == LY_TYPE_IDENT) {
391 ident = ((struct lyd_node_leaf_list *)node)->value.ident;
392 if (lyp_check_status(schema->flags, schema->module, schema->name,
393 ident->flags, ident->module, ident->name, NULL)) {
394 LOGPATH(LY_VLOG_LYD, node);
395 return EXIT_FAILURE;
396 }
397 }
398 }
399 }
400
Radek Krejcid788a522016-07-25 14:57:38 +0200401 /* remove the flag */
402 node->validity &= ~LYD_VAL_MAND;
403 }
Radek Krejci4eaf5a82015-12-15 15:10:38 +0100404
Michal Vaskob1bc1d92017-01-05 11:47:41 +0100405 if (!(options & (LYD_OPT_TRUSTED | LYD_OPT_GET | LYD_OPT_GETCONFIG))) {
Radek Krejci63b79c82016-08-10 10:09:33 +0200406 /* skip key uniqueness check in case of get/get-config data */
407 if (schema->nodetype & (LYS_LIST | LYS_CONTAINER)) {
408 LY_TREE_FOR(schema->child, siter) {
409 if (siter->nodetype & (LYS_LIST | LYS_LEAFLIST)) {
410 LY_TREE_FOR(node->child, diter) {
411 if (diter->schema == siter && (diter->validity & LYD_VAL_UNIQUE)) {
412 if (lyv_data_unique(diter, node->child)) {
413 return EXIT_FAILURE;
414 }
415 /* all schema instances checked, continue with another schema node */
416 break;
417 }
418 }
Radek Krejcica7efb72016-01-18 13:06:01 +0100419 }
Radek Krejci4eaf5a82015-12-15 15:10:38 +0100420 }
421 }
Radek Krejcid788a522016-07-25 14:57:38 +0200422 }
423
Radek Krejcif1ee2e22016-08-02 16:36:48 +0200424 if (schema->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
425 /* since feature can be enabled/disabled, do this check despite the validity flag,
426 * - check if the type value (enum, bit, identity) is disabled via feature */
427 leaf = (struct lyd_node_leaf_list *)node;
428 switch (leaf->value_type) {
429 case LY_TYPE_BITS:
430 id = "Bit";
431 /* get the count of bits */
432 for (type = &((struct lys_node_leaf *)leaf->schema)->type; !type->info.bits.count; type = &type->der->type);
433 for (j = iff_size = 0; j < type->info.bits.count; j++) {
434 if (!leaf->value.bit[j]) {
435 continue;
436 }
437 idname = leaf->value.bit[j]->name;
438 iff_size = leaf->value.bit[j]->iffeature_size;
439 iff = leaf->value.bit[j]->iffeature;
440 break;
441nextbit:
442 iff_size = 0;
443 }
444 break;
445 case LY_TYPE_ENUM:
446 id = "Enum";
447 idname = leaf->value_str;
448 iff_size = leaf->value.enm->iffeature_size;
449 iff = leaf->value.enm->iffeature;
450 break;
451 case LY_TYPE_IDENT:
452 id = "Identity";
453 idname = leaf->value_str;
454 iff_size = leaf->value.ident->iffeature_size;
455 iff = leaf->value.ident->iffeature;
456 break;
457 default:
458 iff_size = 0;
459 break;
460 }
461
462 if (iff_size) {
463 for (i = 0; i < iff_size; i++) {
464 if (!resolve_iffeature(&iff[i])) {
465 LOGVAL(LYE_INVAL, LY_VLOG_LYD, node, leaf->value_str, schema->name);
466 LOGVAL(LYE_SPEC, LY_VLOG_LYD, node, "%s \"%s\" is disabled by its if-feature condition.",
467 id, idname);
468 return EXIT_FAILURE;
469 }
470 }
471 if (leaf->value_type == LY_TYPE_BITS) {
472 goto nextbit;
473 }
474 }
475 }
476
Michal Vaskoad2e44a2017-01-03 10:31:35 +0100477 /* check must conditions */
478 if (!(options & (LYD_OPT_TRUSTED | LYD_OPT_NOTIF_FILTER | LYD_OPT_EDIT | LYD_OPT_GET | LYD_OPT_GETCONFIG))) {
Michal Vasko4b5b6252016-10-11 12:18:00 +0000479 i = resolve_applies_must(node);
480 if ((i & 0x1) && (unres_data_add(unres, node, UNRES_MUST) == -1)) {
481 return EXIT_FAILURE;
482 }
483 if ((i & 0x2) && (unres_data_add(unres, node, UNRES_MUST_INOUT) == -1)) {
484 return EXIT_FAILURE;
485 }
Michal Vaskobf19d252015-10-08 15:39:17 +0200486 }
487
Radek Krejcieab784a2015-08-27 09:56:53 +0200488 return EXIT_SUCCESS;
489}