17 #include "plugins_internal.h"
21 # include <winsock2.h>
22 # include <ws2tcpip.h>
24 # include <arpa/inet.h>
25 # if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__)
26 # include <netinet/in.h>
27 # include <sys/socket.h>
39 #include "ly_common.h"
50 static void lyplg_type_free_ipv6_address_no_zone(
const struct ly_ctx *ctx,
struct lyd_value *value);
63 ipv6addressnozone_str2ip(
const char *value,
size_t value_len, uint32_t options,
struct in6_addr *addr,
struct ly_err_item **err)
67 char *addr_dyn = NULL;
74 addr_dyn = strndup(value, value_len);
79 if (!inet_pton(AF_INET6, addr_str, addr)) {
93 lyplg_type_store_ipv6_address_no_zone(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value,
94 size_t value_len, uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
95 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
102 memset(storage, 0,
sizeof *storage);
107 if (value_len != 16) {
109 "(expected 16).", value_len);
115 storage->dyn_mem = (
void *)value;
116 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
120 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
123 memcpy(&val->
addr, value,
sizeof val->
addr);
132 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
136 LY_CHECK_GOTO(ret, cleanup);
139 ret = ipv6addressnozone_str2ip(value, value_len, options, &val->
addr, err);
140 LY_CHECK_GOTO(ret, cleanup);
144 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
146 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
147 LY_CHECK_GOTO(ret, cleanup);
150 LY_CHECK_GOTO(ret, cleanup);
155 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
160 lyplg_type_free_ipv6_address_no_zone(ctx, storage);
169 lyplg_type_compare_ipv6_address_no_zone(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
187 lyplg_type_sort_ipv6_address_no_zone(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
203 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
213 *value_len =
sizeof val->
addr;
221 ret = malloc(INET6_ADDRSTRLEN);
222 LY_CHECK_RET(!ret, NULL);
225 if (!inet_ntop(AF_INET6, &val->
addr, ret, INET6_ADDRSTRLEN)) {
227 LOGERR(ctx,
LY_ESYS,
"Failed to get IPv6 address in string (%s).", strerror(errno));
252 lyplg_type_dup_ipv6_address_no_zone(
const struct ly_ctx *ctx,
const struct lyd_value *original,
struct lyd_value *dup)
257 memset(dup, 0,
sizeof *dup);
260 LY_CHECK_GOTO(ret, error);
263 LY_CHECK_ERR_GOTO(!dup_val, ret =
LY_EMEM, error);
266 memcpy(&dup_val->
addr, &orig_val->
addr,
sizeof orig_val->
addr);
272 lyplg_type_free_ipv6_address_no_zone(ctx, dup);
280 lyplg_type_free_ipv6_address_no_zone(
const struct ly_ctx *ctx,
struct lyd_value *value)
299 .
module =
"ietf-inet-types",
300 .revision =
"2013-07-15",
301 .name =
"ipv6-address-no-zone",
303 .plugin.id =
"libyang 2 - ipv6-address-no-zone, version 1",
304 .plugin.store = lyplg_type_store_ipv6_address_no_zone,
305 .plugin.validate = NULL,
306 .plugin.compare = lyplg_type_compare_ipv6_address_no_zone,
307 .plugin.sort = lyplg_type_sort_ipv6_address_no_zone,
308 .plugin.print = lyplg_type_print_ipv6_address_no_zone,
309 .plugin.duplicate = lyplg_type_dup_ipv6_address_no_zone,
310 .plugin.free = lyplg_type_free_ipv6_address_no_zone,
311 .plugin.lyb_data_len = 16,
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
uint8_t ly_bool
Type to indicate boolean value.
#define LYPLG_TYPE_STORE_DYNAMIC
Special lyd_value structure for ietf-inet-types ipv6-address-no-zone values.
LYPLG_TYPE_VAL_INLINE_DESTROY(val)
The main libyang public header.
YANG data representation.
Libyang full error structure.
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
LIBYANG_API_DECL LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *data_path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
Create and fill error structure.
LIBYANG_API_DECL LY_ERR lydict_remove(const struct ly_ctx *ctx, const char *value)
Remove specified string from the dictionary. It decrement reference counter for the string and if it ...
LIBYANG_API_DECL LY_ERR lydict_insert(const struct ly_ctx *ctx, const char *value, size_t len, const char **str_p)
Insert string into dictionary. If the string is already present, only a reference counter is incremen...
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, size_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
Check that the type is suitable for the parser's hints (if any) in the specified format.
#define LYPLG_TYPE_VAL_IS_DYN(type_val)
Check whether specific type value needs to be allocated dynamically.
LIBYANG_API_DECL LY_ERR lydict_insert_zc(const struct ly_ctx *ctx, char *value, const char **str_p)
Insert string into dictionary - zerocopy version. If the string is already present, only a reference counter is incremented and no memory allocation is performed. This insert function variant avoids duplication of specified value - it is inserted into the dictionary directly.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
struct lyplg_type_record plugins_ipv6_address_no_zone[]
Plugin information for ipv6-address-no-zone type implementation.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
API for (user) types plugins.
LY_ERR
libyang's error codes returned by the libyang functions.