]> git.proxmox.com Git - mirror_frr.git/blob - yang/libyang_plugins/frr_user_types.c
Merge pull request #3320 from mjstapp/fix_dp_ecmp
[mirror_frr.git] / yang / libyang_plugins / frr_user_types.c
1 /*
2 * Copyright (C) 2018 NetDEF, Inc.
3 * Renato Westphal
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <zebra.h>
21
22 #include "prefix.h"
23
24 #include <libyang/user_types.h>
25
26 static int ipv4_address_store_clb(const char *type_name, const char *value_str,
27 lyd_val *value, char **err_msg)
28 {
29 value->ptr = malloc(sizeof(struct in_addr));
30 if (!value->ptr)
31 return 1;
32
33 if (inet_pton(AF_INET, value_str, value->ptr) != 1) {
34 free(value->ptr);
35 return 1;
36 }
37
38 return 0;
39 }
40
41 static int ipv6_address_store_clb(const char *type_name, const char *value_str,
42 lyd_val *value, char **err_msg)
43 {
44 value->ptr = malloc(INET6_ADDRSTRLEN);
45 if (!value->ptr)
46 return 1;
47
48 if (inet_pton(AF_INET6, value_str, value->ptr) != 1) {
49 free(value->ptr);
50 return 1;
51 }
52
53 return 0;
54 }
55
56 static int ipv4_prefix_store_clb(const char *type_name, const char *value_str,
57 lyd_val *value, char **err_msg)
58 {
59 value->ptr = malloc(sizeof(struct prefix_ipv4));
60 if (!value->ptr)
61 return 1;
62
63 if (str2prefix_ipv4(value_str, value->ptr) == 0) {
64 free(value->ptr);
65 return 1;
66 }
67
68 return 0;
69 }
70
71 static int ipv6_prefix_store_clb(const char *type_name, const char *value_str,
72 lyd_val *value, char **err_msg)
73 {
74 value->ptr = malloc(sizeof(struct prefix_ipv6));
75 if (!value->ptr)
76 return 1;
77
78 if (str2prefix_ipv6(value_str, value->ptr) == 0) {
79 free(value->ptr);
80 return 1;
81 }
82
83 return 0;
84 }
85
86 struct lytype_plugin_list frr_user_types[] = {
87 {"ietf-inet-types", "2013-07-15", "ipv4-address",
88 ipv4_address_store_clb, free},
89 {"ietf-inet-types", "2013-07-15", "ipv4-address-no-zone",
90 ipv4_address_store_clb, free},
91 {"ietf-inet-types", "2013-07-15", "ipv6-address",
92 ipv6_address_store_clb, free},
93 {"ietf-inet-types", "2013-07-15", "ipv6-address-no-zone",
94 ipv6_address_store_clb, free},
95 {"ietf-inet-types", "2013-07-15", "ipv4-prefix", ipv4_prefix_store_clb,
96 free},
97 {"ietf-inet-types", "2013-07-15", "ipv6-prefix", ipv6_prefix_store_clb,
98 free},
99 {NULL, NULL, NULL, NULL, NULL} /* terminating item */
100 };