summaryrefslogtreecommitdiffstats
path: root/yang/libyang_plugins
diff options
context:
space:
mode:
Diffstat (limited to 'yang/libyang_plugins')
-rw-r--r--yang/libyang_plugins/frr_user_types.c122
-rw-r--r--yang/libyang_plugins/subdir.am7
2 files changed, 129 insertions, 0 deletions
diff --git a/yang/libyang_plugins/frr_user_types.c b/yang/libyang_plugins/frr_user_types.c
new file mode 100644
index 0000000..70a8da3
--- /dev/null
+++ b/yang/libyang_plugins/frr_user_types.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2018 NetDEF, Inc.
+ * Renato Westphal
+ */
+
+#include <zebra.h>
+
+#include "prefix.h"
+#include "ipaddr.h"
+
+#include <libyang/user_types.h>
+
+static int ipv4_address_store_clb(const char *type_name, const char *value_str,
+ lyd_val *value, char **err_msg)
+{
+ value->ptr = malloc(sizeof(struct in_addr));
+ if (!value->ptr)
+ return 1;
+
+ if (inet_pton(AF_INET, value_str, value->ptr) != 1) {
+ free(value->ptr);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int ipv6_address_store_clb(const char *type_name, const char *value_str,
+ lyd_val *value, char **err_msg)
+{
+ value->ptr = malloc(INET6_ADDRSTRLEN);
+ if (!value->ptr)
+ return 1;
+
+ if (inet_pton(AF_INET6, value_str, value->ptr) != 1) {
+ free(value->ptr);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int ip_address_store_clb(const char *type_name, const char *value_str,
+ lyd_val *value, char **err_msg)
+{
+ value->ptr = malloc(sizeof(struct ipaddr));
+ if (!value->ptr)
+ return 1;
+
+ if (str2ipaddr(value_str, value->ptr)) {
+ free(value->ptr);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int ipv4_prefix_store_clb(const char *type_name, const char *value_str,
+ lyd_val *value, char **err_msg)
+{
+ value->ptr = malloc(sizeof(struct prefix_ipv4));
+ if (!value->ptr)
+ return 1;
+
+ if (str2prefix_ipv4(value_str, value->ptr) == 0) {
+ free(value->ptr);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int ipv6_prefix_store_clb(const char *type_name, const char *value_str,
+ lyd_val *value, char **err_msg)
+{
+ value->ptr = malloc(sizeof(struct prefix_ipv6));
+ if (!value->ptr)
+ return 1;
+
+ if (str2prefix_ipv6(value_str, value->ptr) == 0) {
+ free(value->ptr);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int ip_prefix_store_clb(const char *type_name, const char *value_str,
+ lyd_val *value, char **err_msg)
+{
+ value->ptr = malloc(sizeof(struct prefix));
+ if (!value->ptr)
+ return 1;
+
+ if (str2prefix(value_str, value->ptr) == 0) {
+ free(value->ptr);
+ return 1;
+ }
+
+ return 0;
+}
+
+struct lytype_plugin_list frr_user_types[] = {
+ {"ietf-inet-types", "2013-07-15", "ipv4-address",
+ ipv4_address_store_clb, free},
+ {"ietf-inet-types", "2013-07-15", "ipv4-address-no-zone",
+ ipv4_address_store_clb, free},
+ {"ietf-inet-types", "2013-07-15", "ipv6-address",
+ ipv6_address_store_clb, free},
+ {"ietf-inet-types", "2013-07-15", "ipv6-address-no-zone",
+ ipv6_address_store_clb, free},
+ {"ietf-inet-types", "2013-07-15", "ip-address", ip_address_store_clb,
+ free},
+ {"ietf-inet-types", "2013-07-15", "ipv4-prefix", ipv4_prefix_store_clb,
+ free},
+ {"ietf-inet-types", "2013-07-15", "ipv6-prefix", ipv6_prefix_store_clb,
+ free},
+ {"ietf-inet-types", "2013-07-15", "ip-prefix", ip_prefix_store_clb,
+ free},
+ {NULL, NULL, NULL, NULL, NULL} /* terminating item */
+};
diff --git a/yang/libyang_plugins/subdir.am b/yang/libyang_plugins/subdir.am
new file mode 100644
index 0000000..837908a
--- /dev/null
+++ b/yang/libyang_plugins/subdir.am
@@ -0,0 +1,7 @@
+#
+# libyang user types
+#
+
+# XXX: disable support for libyang custom user types temporarily to facilitate
+# the transition from libyang 0.x to libyang 1.x.
+#lib_libfrr_la_SOURCES += yang/libyang_plugins/frr_user_types.c