plugin ipv4/6_prefix BUGFIX value_len in print clb
diff --git a/src/plugins_types/ipv4_prefix.c b/src/plugins_types/ipv4_prefix.c
index 697e904..a4738f5 100644
--- a/src/plugins_types/ipv4_prefix.c
+++ b/src/plugins_types/ipv4_prefix.c
@@ -40,6 +40,8 @@
* | 1 | yes | `uint8_t *` | prefix length up to 32 |
*/
+#define LYB_VALUE_LEN 5
+
static void lyplg_type_free_ipv4_prefix(const struct ly_ctx *ctx, struct lyd_value *value);
/**
@@ -122,9 +124,9 @@
if (format == LY_VALUE_LYB) {
/* validation */
- if (value_len != 5) {
- ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB ipv4-prefix value size %zu (expected 5).",
- value_len);
+ if (value_len != LYB_VALUE_LEN) {
+ ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB ipv4-prefix value size %zu (expected %d).",
+ value_len, LYB_VALUE_LEN);
goto cleanup;
}
if (((uint8_t *)value)[4] > 32) {
@@ -224,7 +226,7 @@
if (format == LY_VALUE_LYB) {
*dynamic = 0;
if (value_len) {
- *value_len = sizeof *val;
+ *value_len = LYB_VALUE_LEN;
}
return val;
}
diff --git a/src/plugins_types/ipv6_prefix.c b/src/plugins_types/ipv6_prefix.c
index 4a4701f..e864c74 100644
--- a/src/plugins_types/ipv6_prefix.c
+++ b/src/plugins_types/ipv6_prefix.c
@@ -40,6 +40,8 @@
* | 1 | yes | `uint8_t *` | prefix length up to 128 |
*/
+#define LYB_VALUE_LEN 17
+
static void lyplg_type_free_ipv6_prefix(const struct ly_ctx *ctx, struct lyd_value *value);
/**
@@ -122,9 +124,9 @@
if (format == LY_VALUE_LYB) {
/* validation */
- if (value_len != 17) {
- ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB ipv6-prefix value size %zu (expected 17).",
- value_len);
+ if (value_len != LYB_VALUE_LEN) {
+ ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB ipv6-prefix value size %zu (expected %d).",
+ value_len, LYB_VALUE_LEN);
goto cleanup;
}
if (((uint8_t *)value)[16] > 128) {
@@ -238,7 +240,7 @@
if (format == LY_VALUE_LYB) {
*dynamic = 0;
if (value_len) {
- *value_len = sizeof *val;
+ *value_len = LYB_VALUE_LEN;
}
return val;
}
diff --git a/tests/utests/types/inet_types.c b/tests/utests/types/inet_types.c
index 1b140e0..2d746ac 100644
--- a/tests/utests/types/inet_types.c
+++ b/tests/utests/types/inet_types.c
@@ -50,6 +50,22 @@
lyd_free_all(tree); \
}
+#define TEST_SUCCESS_LYB(MOD_NAME, NODE_NAME, DATA) \
+ { \
+ struct lyd_node *tree_1; \
+ struct lyd_node *tree_2; \
+ char *xml_out, *data; \
+ data = "<" NODE_NAME " xmlns=\"urn:tests:" MOD_NAME "\">" DATA "</" NODE_NAME ">"; \
+ CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, LY_SUCCESS, tree_1); \
+ assert_int_equal(lyd_print_mem(&xml_out, tree_1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0); \
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, xml_out, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &tree_2)); \
+ assert_non_null(tree_2); \
+ CHECK_LYD(tree_1, tree_2); \
+ free(xml_out); \
+ lyd_free_all(tree_1); \
+ lyd_free_all(tree_2); \
+ }
+
static void
test_data_xml(void **state)
{
@@ -97,11 +113,28 @@
TEST_SUCCESS_XML("a", "l7", "::C:D:E:f:a/55", STRING, "::/55");
}
+static void
+test_data_lyb(void **UNUSED(state))
+{
+#if 0
+ const char *schema;
+
+ schema = MODULE_CREATE_YANG("lyb",
+ "leaf l6 {type inet:ipv4-prefix;}"
+ "leaf l7 {type inet:ipv6-prefix;}");
+ UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+
+ TEST_SUCCESS_LYB("lyb", "l6", "12.1.58.4/8");
+ TEST_SUCCESS_LYB("lyb", "l7", "::C:D:E:f:a/112");
+#endif
+}
+
int
main(void)
{
const struct CMUnitTest tests[] = {
UTEST(test_data_xml),
+ UTEST(test_data_lyb),
};
return cmocka_run_group_tests(tests, NULL, NULL);