]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/yang.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / yang.c
index ec8de85e900c67ba1c14788c74a975452fc45e90..4dd8654217183cfcdec1d41abf4c14cb689f2d5c 100644 (file)
@@ -1,20 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2018  NetDEF, Inc.
  *                     Renato Westphal
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -263,6 +250,23 @@ void yang_snode_get_path(const struct lysc_node *snode,
        }
 }
 
+struct lysc_node *yang_find_snode(struct ly_ctx *ly_ctx, const char *xpath,
+                                 uint32_t options)
+{
+       struct lysc_node *snode;
+       struct ly_set *set;
+       LY_ERR err;
+
+       err = lys_find_xpath(ly_native_ctx, NULL, xpath, options, &set);
+       if (err || !set->count)
+               return NULL;
+
+       snode = set->snodes[0];
+       ly_set_free(set, NULL);
+
+       return snode;
+}
+
 struct lysc_node *yang_snode_real_parent(const struct lysc_node *snode)
 {
        struct lysc_node *parent = snode->parent;
@@ -408,7 +412,12 @@ struct lyd_node *yang_dnode_get(const struct lyd_node *dnode, const char *xpath)
                xpath += 2;
 
        if (lyd_find_xpath(dnode, xpath, &set)) {
-               assert(0); /* XXX replicates old libyang1 base code */
+               /*
+                * Commenting out the below assert failure as it crashes mgmtd
+                * when bad xpath is passed.
+                *
+                * assert(0);  XXX replicates old libyang1 base code
+                */
                goto exit;
        }
        if (set->count == 0)