diff --git a/src/libsrx/src/lyx.c b/src/libsrx/src/lyx.c index a52fabf9..cce39e3a 100644 --- a/src/libsrx/src/lyx.c +++ b/src/libsrx/src/lyx.c @@ -120,6 +120,24 @@ struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...) return node; } +/* + * Similar to lydx_get_decsendant() but for, e.g., finding a named + * interface in ietf-interfaces from the top node. + */ +struct lyd_node *lydx_find_by_name(struct lyd_node *from, const char *by, const char *name) +{ + struct lyd_node *node; + + LY_LIST_FOR(lydx_get_sibling(lyd_child(from), by), node) { + if (strcmp(lydx_get_cattr(node, "name"), name)) + continue; + + return node; + } + + return NULL; +} + const char *lydx_get_mattr(struct lyd_node *node, const char *name) { struct lyd_meta *meta; diff --git a/src/libsrx/src/lyx.h b/src/libsrx/src/lyx.h index 1957e6b9..8b9e9e3f 100644 --- a/src/libsrx/src/lyx.h +++ b/src/libsrx/src/lyx.h @@ -36,6 +36,7 @@ bool lydx_get_diff(struct lyd_node *node, struct lydx_diff *nd); struct lyd_node *lydx_get_sibling(struct lyd_node *sibling, const char *name); struct lyd_node *lydx_get_child(struct lyd_node *parent, const char *name); struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...); +struct lyd_node *lydx_find_by_name(struct lyd_node *from, const char *by, const char *name); const char *lydx_get_mattr(struct lyd_node *node, const char *name); const char *lydx_get_attr(struct lyd_node *sibling, const char *name);