]> git.proxmox.com Git - mirror_frr.git/blob - yang/libyang_plugins/frr_user_types.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / yang / libyang_plugins / frr_user_types.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2018 NetDEF, Inc.
4 * Renato Westphal
5 */
6
7 #include <zebra.h>
8
9 #include "prefix.h"
10 #include "ipaddr.h"
11
12 #include <libyang/user_types.h>
13
14 static int ipv4_address_store_clb(const char *type_name, const char *value_str,
15 lyd_val *value, char **err_msg)
16 {
17 value->ptr = malloc(sizeof(struct in_addr));
18 if (!value->ptr)
19 return 1;
20
21 if (inet_pton(AF_INET, value_str, value->ptr) != 1) {
22 free(value->ptr);
23 return 1;
24 }
25
26 return 0;
27 }
28
29 static int ipv6_address_store_clb(const char *type_name, const char *value_str,
30 lyd_val *value, char **err_msg)
31 {
32 value->ptr = malloc(INET6_ADDRSTRLEN);
33 if (!value->ptr)
34 return 1;
35
36 if (inet_pton(AF_INET6, value_str, value->ptr) != 1) {
37 free(value->ptr);
38 return 1;
39 }
40
41 return 0;
42 }
43
44 static int ip_address_store_clb(const char *type_name, const char *value_str,
45 lyd_val *value, char **err_msg)
46 {
47 value->ptr = malloc(sizeof(struct ipaddr));
48 if (!value->ptr)
49 return 1;
50
51 if (str2ipaddr(value_str, value->ptr)) {
52 free(value->ptr);
53 return 1;
54 }
55
56 return 0;
57 }
58
59 static int ipv4_prefix_store_clb(const char *type_name, const char *value_str,
60 lyd_val *value, char **err_msg)
61 {
62 value->ptr = malloc(sizeof(struct prefix_ipv4));
63 if (!value->ptr)
64 return 1;
65
66 if (str2prefix_ipv4(value_str, value->ptr) == 0) {
67 free(value->ptr);
68 return 1;
69 }
70
71 return 0;
72 }
73
74 static int ipv6_prefix_store_clb(const char *type_name, const char *value_str,
75 lyd_val *value, char **err_msg)
76 {
77 value->ptr = malloc(sizeof(struct prefix_ipv6));
78 if (!value->ptr)
79 return 1;
80
81 if (str2prefix_ipv6(value_str, value->ptr) == 0) {
82 free(value->ptr);
83 return 1;
84 }
85
86 return 0;
87 }
88
89 static int ip_prefix_store_clb(const char *type_name, const char *value_str,
90 lyd_val *value, char **err_msg)
91 {
92 value->ptr = malloc(sizeof(struct prefix));
93 if (!value->ptr)
94 return 1;
95
96 if (str2prefix(value_str, value->ptr) == 0) {
97 free(value->ptr);
98 return 1;
99 }
100
101 return 0;
102 }
103
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,
114 free},
115 {"ietf-inet-types", "2013-07-15", "ipv4-prefix", ipv4_prefix_store_clb,
116 free},
117 {"ietf-inet-types", "2013-07-15", "ipv6-prefix", ipv6_prefix_store_clb,
118 free},
119 {"ietf-inet-types", "2013-07-15", "ip-prefix", ip_prefix_store_clb,
120 free},
121 {NULL, NULL, NULL, NULL, NULL} /* terminating item */
122 };