Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/plugins_types/ipv6_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions src/plugins_types/ipv6_address_no_zone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/plugins_types/ipv6_address_prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ 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;
char *mask_str = NULL;

/* 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;
}
Expand Down Expand Up @@ -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")) {
Expand Down
Loading