From f2c9d6f5d7f04496f7d8b3a3f67cae7965c16146 Mon Sep 17 00:00:00 2001 From: Jeremie Leska Date: Wed, 10 Jun 2026 13:36:04 +0200 Subject: [PATCH] plugins types UPDATE pass ipv6 structure object Give the object instead of the two fields to the str2ip functions. Signed-off-by: Jeremie Leska --- src/plugins_types/ipv6_address.c | 13 ++++++------- src/plugins_types/ipv6_address_no_zone.c | 9 +++++---- src/plugins_types/ipv6_address_prefix.c | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/plugins_types/ipv6_address.c b/src/plugins_types/ipv6_address.c index 1822a3933..bb8a1289a 100644 --- a/src/plugins_types/ipv6_address.c +++ b/src/plugins_types/ipv6_address.c @@ -58,14 +58,13 @@ static void lyplg_type_free_ipv6_address(const struct ly_ctx *ctx, struct lyd_va * @param[in] value_len Length of @p value. * @param[in] options Type store callback options. * @param[in] ctx libyang context with dictionary. - * @param[in,out] addr Allocated value for the address. - * @param[out] zone Ipv6 address zone in dictionary. + * @param[in,out] val contains addr and zone to fill. * @param[out] err Error information on error. * @return LY_ERR value. */ static LY_ERR ipv6address_str2ip(const char *value, uint32_t value_len, uint32_t options, const struct ly_ctx *ctx, - struct in6_addr *addr, const char **zone, struct ly_err_item **err) + struct lyd_value_ipv6_address *val, struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; const char *addr_no_zone; @@ -76,7 +75,7 @@ ipv6address_str2ip(const char *value, uint32_t value_len, uint32_t options, cons if ((zone_ptr = ly_strnchr(value, '%', value_len))) { /* there is a zone index */ zone_len = value_len - (zone_ptr - value) - 1; - ret = lydict_insert(ctx, zone_ptr + 1, zone_len, zone); + ret = lydict_insert(ctx, zone_ptr + 1, zone_len, &val->zone); LY_CHECK_GOTO(ret, cleanup); /* get the IP without it */ @@ -89,7 +88,7 @@ ipv6address_str2ip(const char *value, uint32_t value_len, uint32_t options, cons } } else { /* no zone */ - *zone = NULL; + val->zone = NULL; /* get the IP terminated with zero */ if (options & LYPLG_TYPE_STORE_DYNAMIC) { @@ -102,7 +101,7 @@ ipv6address_str2ip(const char *value, uint32_t value_len, uint32_t options, cons } /* store the IPv6 address in network-byte order */ - if (!inet_pton(AF_INET6, addr_no_zone, addr)) { + if (!inet_pton(AF_INET6, addr_no_zone, &val->addr)) { ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to store IPv6 address \"%s\".", addr_no_zone); goto cleanup; } @@ -174,7 +173,7 @@ lyplg_type_store_ipv6_address(const struct ly_ctx *ctx, const struct lysc_type * LY_CHECK_GOTO(ret, cleanup); /* get the network-byte order address */ - ret = ipv6address_str2ip(value, value_size, options, ctx, &val->addr, &val->zone, err); + ret = ipv6address_str2ip(value, value_size, options, ctx, val, err); LY_CHECK_GOTO(ret, cleanup); if (format == LY_VALUE_CANON) { diff --git a/src/plugins_types/ipv6_address_no_zone.c b/src/plugins_types/ipv6_address_no_zone.c index d375ea59d..ca43db607 100644 --- a/src/plugins_types/ipv6_address_no_zone.c +++ b/src/plugins_types/ipv6_address_no_zone.c @@ -55,12 +55,13 @@ static void lyplg_type_free_ipv6_address_no_zone(const struct ly_ctx *ctx, struc * @param[in] value Value to convert. * @param[in] value_len Length of @p value. * @param[in] options Type store callback options. - * @param[in,out] addr Allocated value for the address. + * @param[in,out] val contains addr to fill. * @param[out] err Error information on error. * @return LY_ERR value. */ static LY_ERR -ipv6addressnozone_str2ip(const char *value, uint32_t value_len, uint32_t options, struct in6_addr *addr, struct ly_err_item **err) +ipv6addressnozone_str2ip(const char *value, uint32_t value_len, uint32_t options, + struct lyd_value_ipv6_address_no_zone *val, struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; const char *addr_str; @@ -76,7 +77,7 @@ ipv6addressnozone_str2ip(const char *value, uint32_t value_len, uint32_t options } /* store the IPv6 address in network-byte order */ - if (!inet_pton(AF_INET6, addr_str, addr)) { + if (!inet_pton(AF_INET6, addr_str, &val->addr)) { ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to store IPv6 address \"%s\".", addr_str); goto cleanup; } @@ -143,7 +144,7 @@ lyplg_type_store_ipv6_address_no_zone(const struct ly_ctx *ctx, const struct lys LY_CHECK_GOTO(ret, cleanup); /* get the network-byte order address, validates the value */ - ret = ipv6addressnozone_str2ip(value, value_size, options, &val->addr, err); + ret = ipv6addressnozone_str2ip(value, value_size, options, val, err); LY_CHECK_GOTO(ret, cleanup); if (format == LY_VALUE_CANON) { diff --git a/src/plugins_types/ipv6_address_prefix.c b/src/plugins_types/ipv6_address_prefix.c index 201a53469..d715d6378 100644 --- a/src/plugins_types/ipv6_address_prefix.c +++ b/src/plugins_types/ipv6_address_prefix.c @@ -56,13 +56,13 @@ static void lyplg_type_free_ipv6_address_prefix(const struct ly_ctx *ctx, struct * * @param[in] value String to convert. * @param[in] value_len Length of @p value. - * @param[in,out] addr Allocated address value to fill. - * @param[out] prefix Prefix length. + * @param[in,out] val contains addr and prefix to fill. * @param[out] err Error information on error. * @return LY_ERR value. */ static LY_ERR -ipv6prefix_str2ip(const char *value, uint32_t value_len, struct in6_addr *addr, uint8_t *prefix, struct ly_err_item **err) +ipv6prefix_str2ip(const char *value, uint32_t value_len, struct lyd_value_ipv6_prefix *val, + struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; const char *pref_str; @@ -70,14 +70,14 @@ ipv6prefix_str2ip(const char *value, uint32_t value_len, struct in6_addr *addr, /* it passed the pattern validation */ pref_str = ly_strnchr(value, '/', value_len); - ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix); + ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), &val->prefix); /* get just the network prefix */ mask_str = strndup(value, pref_str - value); LY_CHECK_ERR_GOTO(!mask_str, ret = LY_EMEM, cleanup); /* convert it to netword-byte order */ - if (inet_pton(AF_INET6, mask_str, addr) != 1) { + if (inet_pton(AF_INET6, mask_str, &val->addr) != 1) { ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to store IPv6 address \"%s\".", mask_str); goto cleanup; } @@ -194,7 +194,7 @@ lyplg_type_store_ipv6_address_prefix(const struct ly_ctx *ctx, const struct lysc } /* get the mask in network-byte order */ - ret = ipv6prefix_str2ip(value, value_size, &val->addr, &val->prefix, err); + ret = ipv6prefix_str2ip(value, value_size, val, err); LY_CHECK_GOTO(ret, cleanup); if (!strcmp(type->name, "ipv6-prefix")) {