2 * Copyright (C) 2018 NetDEF, Inc.
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)
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
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
25 #include <libyang/user_types.h>
27 static int ipv4_address_store_clb(const char *type_name
, const char *value_str
,
28 lyd_val
*value
, char **err_msg
)
30 value
->ptr
= malloc(sizeof(struct in_addr
));
34 if (inet_pton(AF_INET
, value_str
, value
->ptr
) != 1) {
42 static int ipv6_address_store_clb(const char *type_name
, const char *value_str
,
43 lyd_val
*value
, char **err_msg
)
45 value
->ptr
= malloc(INET6_ADDRSTRLEN
);
49 if (inet_pton(AF_INET6
, value_str
, value
->ptr
) != 1) {
57 static int ip_address_store_clb(const char *type_name
, const char *value_str
,
58 lyd_val
*value
, char **err_msg
)
60 value
->ptr
= malloc(sizeof(struct ipaddr
));
64 if (str2ipaddr(value_str
, value
->ptr
)) {
72 static int ipv4_prefix_store_clb(const char *type_name
, const char *value_str
,
73 lyd_val
*value
, char **err_msg
)
75 value
->ptr
= malloc(sizeof(struct prefix_ipv4
));
79 if (str2prefix_ipv4(value_str
, value
->ptr
) == 0) {
87 static int ipv6_prefix_store_clb(const char *type_name
, const char *value_str
,
88 lyd_val
*value
, char **err_msg
)
90 value
->ptr
= malloc(sizeof(struct prefix_ipv6
));
94 if (str2prefix_ipv6(value_str
, value
->ptr
) == 0) {
102 static int ip_prefix_store_clb(const char *type_name
, const char *value_str
,
103 lyd_val
*value
, char **err_msg
)
105 value
->ptr
= malloc(sizeof(struct prefix
));
109 if (str2prefix(value_str
, value
->ptr
) == 0) {
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
,
128 {"ietf-inet-types", "2013-07-15", "ipv4-prefix", ipv4_prefix_store_clb
,
130 {"ietf-inet-types", "2013-07-15", "ipv6-prefix", ipv6_prefix_store_clb
,
132 {"ietf-inet-types", "2013-07-15", "ip-prefix", ip_prefix_store_clb
,
134 {NULL
, NULL
, NULL
, NULL
, NULL
} /* terminating item */