]> git.proxmox.com Git - mirror_frr.git/blob - yang/libyang_plugins/frr_user_types.c
Merge pull request #7787 from deastoe/fpm-work-ready-fixes
[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 #include "ipaddr.h"
24
25 #include <libyang/user_types.h>
26
27 static int ipv4_address_store_clb(const char *type_name, const char *value_str,
28 lyd_val *value, char **err_msg)
29 {
30 value->ptr = malloc(sizeof(struct in_addr));
31 if (!value->ptr)
32 return 1;
33
34 if (inet_pton(AF_INET, value_str, value->ptr) != 1) {
35 free(value->ptr);
36 return 1;
37 }
38
39 return 0;
40 }
41
42 static int ipv6_address_store_clb(const char *type_name, const char *value_str,
43 lyd_val *value, char **err_msg)
44 {
45 value->ptr = malloc(INET6_ADDRSTRLEN);
46 if (!value->ptr)
47 return 1;
48
49 if (inet_pton(AF_INET6, value_str, value->ptr) != 1) {
50 free(value->ptr);
51 return 1;
52 }
53
54 return 0;
55 }
56
57 static int ip_address_store_clb(const char *type_name, const char *value_str,
58 lyd_val *value, char **err_msg)
59 {
60 value->ptr = malloc(sizeof(struct ipaddr));
61 if (!value->ptr)
62 return 1;
63
64 if (str2ipaddr(value_str, value->ptr)) {
65 free(value->ptr);
66 return 1;
67 }
68
69 return 0;
70 }
71
72 static int ipv4_prefix_store_clb(const char *type_name, const char *value_str,
73 lyd_val *value, char **err_msg)
74 {
75 value->ptr = malloc(sizeof(struct prefix_ipv4));
76 if (!value->ptr)
77 return 1;
78
79 if (str2prefix_ipv4(value_str, value->ptr) == 0) {
80 free(value->ptr);
81 return 1;
82 }
83
84 return 0;
85 }
86
87 static int ipv6_prefix_store_clb(const char *type_name, const char *value_str,
88 lyd_val *value, char **err_msg)
89 {
90 value->ptr = malloc(sizeof(struct prefix_ipv6));
91 if (!value->ptr)
92 return 1;
93
94 if (str2prefix_ipv6(value_str, value->ptr) == 0) {
95 free(value->ptr);
96 return 1;
97 }
98
99 return 0;
100 }
101
102 static int ip_prefix_store_clb(const char *type_name, const char *value_str,
103 lyd_val *value, char **err_msg)
104 {
105 value->ptr = malloc(sizeof(struct prefix));
106 if (!value->ptr)
107 return 1;
108
109 if (str2prefix(value_str, value->ptr) == 0) {
110 free(value->ptr);
111 return 1;
112 }
113
114 return 0;
115 }
116
117 struct lytype_plugin_list frr_user_types[] = {
118 {"ietf-inet-types", "2013-07-15", "ipv4-address",
119 ipv4_address_store_clb, free},
120 {"ietf-inet-types", "2013-07-15", "ipv4-address-no-zone",
121 ipv4_address_store_clb, free},
122 {"ietf-inet-types", "2013-07-15", "ipv6-address",
123 ipv6_address_store_clb, free},
124 {"ietf-inet-types", "2013-07-15", "ipv6-address-no-zone",
125 ipv6_address_store_clb, free},
126 {"ietf-inet-types", "2013-07-15", "ip-address", ip_address_store_clb,
127 free},
128 {"ietf-inet-types", "2013-07-15", "ipv4-prefix", ipv4_prefix_store_clb,
129 free},
130 {"ietf-inet-types", "2013-07-15", "ipv6-prefix", ipv6_prefix_store_clb,
131 free},
132 {"ietf-inet-types", "2013-07-15", "ip-prefix", ip_prefix_store_clb,
133 free},
134 {NULL, NULL, NULL, NULL, NULL} /* terminating item */
135 };