diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2017-12-07 20:31:48 +0100 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2018-10-27 20:16:12 +0200 |
commit | 1c2facd12df7bc27758d7ea674b1e57e401fc234 (patch) | |
tree | b82aeb06586c2c7b380420ddd484964af915aee1 /yang | |
parent | Merge pull request #3235 from opensourcerouting/buildfoo-20181024 (diff) | |
download | frr-1c2facd12df7bc27758d7ea674b1e57e401fc234.tar.xz frr-1c2facd12df7bc27758d7ea674b1e57e401fc234.zip |
lib: introduce new northbound API
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to '')
-rw-r--r-- | yang/frr-module-translator.yang | 68 | ||||
-rw-r--r-- | yang/libyang_plugins/frr_user_types.c | 100 | ||||
-rw-r--r-- | yang/libyang_plugins/subdir.am | 9 | ||||
-rw-r--r-- | yang/subdir.am | 1 |
4 files changed, 178 insertions, 0 deletions
diff --git a/yang/frr-module-translator.yang b/yang/frr-module-translator.yang new file mode 100644 index 000000000..3d64ec539 --- /dev/null +++ b/yang/frr-module-translator.yang @@ -0,0 +1,68 @@ +module frr-module-translator { + yang-version 1.1; + namespace "http://frrouting.org/yang/frr-module-translator"; + prefix frr-module-translator; + + organization + "Free Range Routing"; + contact + "FRR Users List: <mailto:frog@lists.frrouting.org> + FRR Development List: <mailto:dev@lists.frrouting.org>"; + description + "A model for FRR YANG module translators."; + + revision 2018-07-31 { + description + "Initial revision."; + } + + container frr-module-translator { + leaf family { + type string { + length "0 .. 32"; + } + mandatory true; + description + "Family of YANG models."; + } + list module { + key "name"; + ordered-by user; + description + "YANG module."; + + leaf name { + type string; + description + "Module name."; + } + leaf deviations { + type string; + mandatory true; + description + "Module containing the YANG deviations."; + } + list mappings { + key "custom"; + description + "YANG mappings between the custom module and FRR native modules."; + + leaf custom { + type string { + length "0 .. 256"; + } + description + "YANG path of the custom module."; + } + leaf native { + type string { + length "0 .. 256"; + } + mandatory true; + description + "Corresponding path of the native YANG modules"; + } + } + } + } +} diff --git a/yang/libyang_plugins/frr_user_types.c b/yang/libyang_plugins/frr_user_types.c new file mode 100644 index 000000000..4814f5bc1 --- /dev/null +++ b/yang/libyang_plugins/frr_user_types.c @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2018 NetDEF, Inc. + * Renato Westphal + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> + +#include "prefix.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 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; +} + +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", "ipv4-prefix", ipv4_prefix_store_clb, + free}, + {"ietf-inet-types", "2013-07-15", "ipv6-prefix", ipv6_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 000000000..956d22587 --- /dev/null +++ b/yang/libyang_plugins/subdir.am @@ -0,0 +1,9 @@ +# +# libyang user types +# +libyang_plugins_LTLIBRARIES += yang/libyang_plugins/frr_user_types.la + +yang_libyang_plugins_frr_user_types_la_CFLAGS = $(WERROR) +yang_libyang_plugins_frr_user_types_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +yang_libyang_plugins_frr_user_types_la_LIBADD = +yang_libyang_plugins_frr_user_types_la_SOURCES = yang/libyang_plugins/frr_user_types.c diff --git a/yang/subdir.am b/yang/subdir.am new file mode 100644 index 000000000..b290f9b27 --- /dev/null +++ b/yang/subdir.am @@ -0,0 +1 @@ +dist_yangmodels_DATA += yang/frr-module-translator.yang |