1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2018 NetDEF, Inc.
12 #include <libyang/user_types.h>
14 static int ipv4_address_store_clb(const char *type_name
, const char *value_str
,
15 lyd_val
*value
, char **err_msg
)
17 value
->ptr
= malloc(sizeof(struct in_addr
));
21 if (inet_pton(AF_INET
, value_str
, value
->ptr
) != 1) {
29 static int ipv6_address_store_clb(const char *type_name
, const char *value_str
,
30 lyd_val
*value
, char **err_msg
)
32 value
->ptr
= malloc(INET6_ADDRSTRLEN
);
36 if (inet_pton(AF_INET6
, value_str
, value
->ptr
) != 1) {
44 static int ip_address_store_clb(const char *type_name
, const char *value_str
,
45 lyd_val
*value
, char **err_msg
)
47 value
->ptr
= malloc(sizeof(struct ipaddr
));
51 if (str2ipaddr(value_str
, value
->ptr
)) {
59 static int ipv4_prefix_store_clb(const char *type_name
, const char *value_str
,
60 lyd_val
*value
, char **err_msg
)
62 value
->ptr
= malloc(sizeof(struct prefix_ipv4
));
66 if (str2prefix_ipv4(value_str
, value
->ptr
) == 0) {
74 static int ipv6_prefix_store_clb(const char *type_name
, const char *value_str
,
75 lyd_val
*value
, char **err_msg
)
77 value
->ptr
= malloc(sizeof(struct prefix_ipv6
));
81 if (str2prefix_ipv6(value_str
, value
->ptr
) == 0) {
89 static int ip_prefix_store_clb(const char *type_name
, const char *value_str
,
90 lyd_val
*value
, char **err_msg
)
92 value
->ptr
= malloc(sizeof(struct prefix
));
96 if (str2prefix(value_str
, value
->ptr
) == 0) {
104 struct lytype_plugin_list frr_user_types
[] = {
105 {"ietf-inet-types", "2013-07-15", "ipv4-address",
106 ipv4_address_store_clb
, free
},
107 {"ietf-inet-types", "2013-07-15", "ipv4-address-no-zone",
108 ipv4_address_store_clb
, free
},
109 {"ietf-inet-types", "2013-07-15", "ipv6-address",
110 ipv6_address_store_clb
, free
},
111 {"ietf-inet-types", "2013-07-15", "ipv6-address-no-zone",
112 ipv6_address_store_clb
, free
},
113 {"ietf-inet-types", "2013-07-15", "ip-address", ip_address_store_clb
,
115 {"ietf-inet-types", "2013-07-15", "ipv4-prefix", ipv4_prefix_store_clb
,
117 {"ietf-inet-types", "2013-07-15", "ipv6-prefix", ipv6_prefix_store_clb
,
119 {"ietf-inet-types", "2013-07-15", "ip-prefix", ip_prefix_store_clb
,
121 {NULL
, NULL
, NULL
, NULL
, NULL
} /* terminating item */