From f643b4f9dc7547c30eee923910739cb1bbf9ce56 Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Mon, 16 Oct 2023 10:16:59 +0200 Subject: [PATCH] statd: break out parent interface code (cosmetic) A non functional change to prepare for upcoming patches. Signed-off-by: Richard Alpe --- src/statd/iface-ip-link.c | 46 +++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/statd/iface-ip-link.c b/src/statd/iface-ip-link.c index d5786052..c1ebbd5b 100644 --- a/src/statd/iface-ip-link.c +++ b/src/statd/iface-ip-link.c @@ -226,6 +226,34 @@ static int ly_add_ip_link_br(const struct ly_ctx *ctx, struct lyd_node **parent, return SR_ERR_OK; } +static int ly_add_ip_link_parent(const struct ly_ctx *ctx, struct lyd_node **parent, + char *xpath, json_t *j_iface) +{ + json_t *j_val; + int err; + + j_val = json_object_get(j_iface, "link"); + if (!j_val) { + /* Interface has no parent */ + return SR_ERR_OK; + } + + if (!json_is_string(j_val)) { + ERROR("Expected a JSON string for 'link'"); + return SR_ERR_SYS; + } + + err = lydx_new_path(ctx, parent, xpath, + "ietf-if-extensions:parent-interface", "%s", + json_string_value(j_val)); + if (err) { + ERROR("Error, adding 'link' to data tree, libyang error %d", err); + return SR_ERR_LY; + } + + return SR_ERR_OK; +} + static int ly_add_ip_link_data(const struct ly_ctx *ctx, struct lyd_node **parent, char *xpath, json_t *j_iface) { @@ -291,20 +319,10 @@ static int ly_add_ip_link_data(const struct ly_ctx *ctx, struct lyd_node **paren return err; } - j_val = json_object_get(j_iface, "link"); - if (j_val) { - if (!json_is_string(j_val)) { - ERROR("Expected a JSON string for 'link'"); - return SR_ERR_SYS; - } - - err = lydx_new_path(ctx, parent, xpath, - "ietf-if-extensions:parent-interface", "%s", - json_string_value(j_val)); - if (err) { - ERROR("Error, adding 'link' to data tree, libyang error %d", err); - return SR_ERR_LY; - } + err = ly_add_ip_link_parent(ctx, parent, xpath, j_iface); + if (err) { + ERROR("Error, adding parent iface to data tree, libyang error %d", err); + return err; } return SR_ERR_OK;