xref: /openbmc/linux/tools/net/ynl/generated/fou-user.c (revision 2612e3bbc0386368a850140a6c9b990cd496a5ec)
1d75fdfbcSJakub Kicinski // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
2d75fdfbcSJakub Kicinski /* Do not edit directly, auto-generated from: */
3d75fdfbcSJakub Kicinski /*	Documentation/netlink/specs/fou.yaml */
4d75fdfbcSJakub Kicinski /* YNL-GEN user source */
5d75fdfbcSJakub Kicinski 
6d75fdfbcSJakub Kicinski #include <stdlib.h>
79b52fd4bSJakub Kicinski #include <string.h>
8d75fdfbcSJakub Kicinski #include "fou-user.h"
9d75fdfbcSJakub Kicinski #include "ynl.h"
10d75fdfbcSJakub Kicinski #include <linux/fou.h>
11d75fdfbcSJakub Kicinski 
12d75fdfbcSJakub Kicinski #include <libmnl/libmnl.h>
13d75fdfbcSJakub Kicinski #include <linux/genetlink.h>
14d75fdfbcSJakub Kicinski 
15d75fdfbcSJakub Kicinski /* Enums */
16d75fdfbcSJakub Kicinski static const char * const fou_op_strmap[] = {
17d75fdfbcSJakub Kicinski 	[FOU_CMD_ADD] = "add",
18d75fdfbcSJakub Kicinski 	[FOU_CMD_DEL] = "del",
19d75fdfbcSJakub Kicinski 	[FOU_CMD_GET] = "get",
20d75fdfbcSJakub Kicinski };
21d75fdfbcSJakub Kicinski 
fou_op_str(int op)22d75fdfbcSJakub Kicinski const char *fou_op_str(int op)
23d75fdfbcSJakub Kicinski {
24d75fdfbcSJakub Kicinski 	if (op < 0 || op >= (int)MNL_ARRAY_SIZE(fou_op_strmap))
25d75fdfbcSJakub Kicinski 		return NULL;
26d75fdfbcSJakub Kicinski 	return fou_op_strmap[op];
27d75fdfbcSJakub Kicinski }
28d75fdfbcSJakub Kicinski 
29d75fdfbcSJakub Kicinski static const char * const fou_encap_type_strmap[] = {
30d75fdfbcSJakub Kicinski 	[0] = "unspec",
31d75fdfbcSJakub Kicinski 	[1] = "direct",
32d75fdfbcSJakub Kicinski 	[2] = "gue",
33d75fdfbcSJakub Kicinski };
34d75fdfbcSJakub Kicinski 
fou_encap_type_str(int value)35d75fdfbcSJakub Kicinski const char *fou_encap_type_str(int value)
36d75fdfbcSJakub Kicinski {
37d75fdfbcSJakub Kicinski 	if (value < 0 || value >= (int)MNL_ARRAY_SIZE(fou_encap_type_strmap))
38d75fdfbcSJakub Kicinski 		return NULL;
39d75fdfbcSJakub Kicinski 	return fou_encap_type_strmap[value];
40d75fdfbcSJakub Kicinski }
41d75fdfbcSJakub Kicinski 
42d75fdfbcSJakub Kicinski /* Policies */
43d75fdfbcSJakub Kicinski struct ynl_policy_attr fou_policy[FOU_ATTR_MAX + 1] = {
44d75fdfbcSJakub Kicinski 	[FOU_ATTR_UNSPEC] = { .name = "unspec", .type = YNL_PT_REJECT, },
45d75fdfbcSJakub Kicinski 	[FOU_ATTR_PORT] = { .name = "port", .type = YNL_PT_U16, },
46d75fdfbcSJakub Kicinski 	[FOU_ATTR_AF] = { .name = "af", .type = YNL_PT_U8, },
47d75fdfbcSJakub Kicinski 	[FOU_ATTR_IPPROTO] = { .name = "ipproto", .type = YNL_PT_U8, },
48d75fdfbcSJakub Kicinski 	[FOU_ATTR_TYPE] = { .name = "type", .type = YNL_PT_U8, },
49d75fdfbcSJakub Kicinski 	[FOU_ATTR_REMCSUM_NOPARTIAL] = { .name = "remcsum_nopartial", .type = YNL_PT_FLAG, },
50d75fdfbcSJakub Kicinski 	[FOU_ATTR_LOCAL_V4] = { .name = "local_v4", .type = YNL_PT_U32, },
51d75fdfbcSJakub Kicinski 	[FOU_ATTR_LOCAL_V6] = { .name = "local_v6", .type = YNL_PT_BINARY,},
52d75fdfbcSJakub Kicinski 	[FOU_ATTR_PEER_V4] = { .name = "peer_v4", .type = YNL_PT_U32, },
53d75fdfbcSJakub Kicinski 	[FOU_ATTR_PEER_V6] = { .name = "peer_v6", .type = YNL_PT_BINARY,},
54d75fdfbcSJakub Kicinski 	[FOU_ATTR_PEER_PORT] = { .name = "peer_port", .type = YNL_PT_U16, },
55d75fdfbcSJakub Kicinski 	[FOU_ATTR_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, },
56d75fdfbcSJakub Kicinski };
57d75fdfbcSJakub Kicinski 
58d75fdfbcSJakub Kicinski struct ynl_policy_nest fou_nest = {
59d75fdfbcSJakub Kicinski 	.max_attr = FOU_ATTR_MAX,
60d75fdfbcSJakub Kicinski 	.table = fou_policy,
61d75fdfbcSJakub Kicinski };
62d75fdfbcSJakub Kicinski 
63d75fdfbcSJakub Kicinski /* Common nested types */
64d75fdfbcSJakub Kicinski /* ============== FOU_CMD_ADD ============== */
65d75fdfbcSJakub Kicinski /* FOU_CMD_ADD - do */
fou_add_req_free(struct fou_add_req * req)66d75fdfbcSJakub Kicinski void fou_add_req_free(struct fou_add_req *req)
67d75fdfbcSJakub Kicinski {
68d75fdfbcSJakub Kicinski 	free(req->local_v6);
69d75fdfbcSJakub Kicinski 	free(req->peer_v6);
70d75fdfbcSJakub Kicinski 	free(req);
71d75fdfbcSJakub Kicinski }
72d75fdfbcSJakub Kicinski 
fou_add(struct ynl_sock * ys,struct fou_add_req * req)73d75fdfbcSJakub Kicinski int fou_add(struct ynl_sock *ys, struct fou_add_req *req)
74d75fdfbcSJakub Kicinski {
75d75fdfbcSJakub Kicinski 	struct nlmsghdr *nlh;
76d75fdfbcSJakub Kicinski 	int err;
77d75fdfbcSJakub Kicinski 
78d75fdfbcSJakub Kicinski 	nlh = ynl_gemsg_start_req(ys, ys->family_id, FOU_CMD_ADD, 1);
79d75fdfbcSJakub Kicinski 	ys->req_policy = &fou_nest;
80d75fdfbcSJakub Kicinski 
81d75fdfbcSJakub Kicinski 	if (req->_present.port)
82d75fdfbcSJakub Kicinski 		mnl_attr_put_u16(nlh, FOU_ATTR_PORT, req->port);
83d75fdfbcSJakub Kicinski 	if (req->_present.ipproto)
84d75fdfbcSJakub Kicinski 		mnl_attr_put_u8(nlh, FOU_ATTR_IPPROTO, req->ipproto);
85d75fdfbcSJakub Kicinski 	if (req->_present.type)
86d75fdfbcSJakub Kicinski 		mnl_attr_put_u8(nlh, FOU_ATTR_TYPE, req->type);
87d75fdfbcSJakub Kicinski 	if (req->_present.remcsum_nopartial)
88d75fdfbcSJakub Kicinski 		mnl_attr_put(nlh, FOU_ATTR_REMCSUM_NOPARTIAL, 0, NULL);
89d75fdfbcSJakub Kicinski 	if (req->_present.local_v4)
90d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_LOCAL_V4, req->local_v4);
91d75fdfbcSJakub Kicinski 	if (req->_present.peer_v4)
92d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_PEER_V4, req->peer_v4);
93d75fdfbcSJakub Kicinski 	if (req->_present.local_v6_len)
94d75fdfbcSJakub Kicinski 		mnl_attr_put(nlh, FOU_ATTR_LOCAL_V6, req->_present.local_v6_len, req->local_v6);
95d75fdfbcSJakub Kicinski 	if (req->_present.peer_v6_len)
96d75fdfbcSJakub Kicinski 		mnl_attr_put(nlh, FOU_ATTR_PEER_V6, req->_present.peer_v6_len, req->peer_v6);
97d75fdfbcSJakub Kicinski 	if (req->_present.peer_port)
98d75fdfbcSJakub Kicinski 		mnl_attr_put_u16(nlh, FOU_ATTR_PEER_PORT, req->peer_port);
99d75fdfbcSJakub Kicinski 	if (req->_present.ifindex)
100d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_IFINDEX, req->ifindex);
101d75fdfbcSJakub Kicinski 
102d75fdfbcSJakub Kicinski 	err = ynl_exec(ys, nlh, NULL);
103d75fdfbcSJakub Kicinski 	if (err < 0)
104d75fdfbcSJakub Kicinski 		return -1;
105d75fdfbcSJakub Kicinski 
106d75fdfbcSJakub Kicinski 	return 0;
107d75fdfbcSJakub Kicinski }
108d75fdfbcSJakub Kicinski 
109d75fdfbcSJakub Kicinski /* ============== FOU_CMD_DEL ============== */
110d75fdfbcSJakub Kicinski /* FOU_CMD_DEL - do */
fou_del_req_free(struct fou_del_req * req)111d75fdfbcSJakub Kicinski void fou_del_req_free(struct fou_del_req *req)
112d75fdfbcSJakub Kicinski {
113d75fdfbcSJakub Kicinski 	free(req->local_v6);
114d75fdfbcSJakub Kicinski 	free(req->peer_v6);
115d75fdfbcSJakub Kicinski 	free(req);
116d75fdfbcSJakub Kicinski }
117d75fdfbcSJakub Kicinski 
fou_del(struct ynl_sock * ys,struct fou_del_req * req)118d75fdfbcSJakub Kicinski int fou_del(struct ynl_sock *ys, struct fou_del_req *req)
119d75fdfbcSJakub Kicinski {
120d75fdfbcSJakub Kicinski 	struct nlmsghdr *nlh;
121d75fdfbcSJakub Kicinski 	int err;
122d75fdfbcSJakub Kicinski 
123d75fdfbcSJakub Kicinski 	nlh = ynl_gemsg_start_req(ys, ys->family_id, FOU_CMD_DEL, 1);
124d75fdfbcSJakub Kicinski 	ys->req_policy = &fou_nest;
125d75fdfbcSJakub Kicinski 
126d75fdfbcSJakub Kicinski 	if (req->_present.af)
127d75fdfbcSJakub Kicinski 		mnl_attr_put_u8(nlh, FOU_ATTR_AF, req->af);
128d75fdfbcSJakub Kicinski 	if (req->_present.ifindex)
129d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_IFINDEX, req->ifindex);
130d75fdfbcSJakub Kicinski 	if (req->_present.port)
131d75fdfbcSJakub Kicinski 		mnl_attr_put_u16(nlh, FOU_ATTR_PORT, req->port);
132d75fdfbcSJakub Kicinski 	if (req->_present.peer_port)
133d75fdfbcSJakub Kicinski 		mnl_attr_put_u16(nlh, FOU_ATTR_PEER_PORT, req->peer_port);
134d75fdfbcSJakub Kicinski 	if (req->_present.local_v4)
135d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_LOCAL_V4, req->local_v4);
136d75fdfbcSJakub Kicinski 	if (req->_present.peer_v4)
137d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_PEER_V4, req->peer_v4);
138d75fdfbcSJakub Kicinski 	if (req->_present.local_v6_len)
139d75fdfbcSJakub Kicinski 		mnl_attr_put(nlh, FOU_ATTR_LOCAL_V6, req->_present.local_v6_len, req->local_v6);
140d75fdfbcSJakub Kicinski 	if (req->_present.peer_v6_len)
141d75fdfbcSJakub Kicinski 		mnl_attr_put(nlh, FOU_ATTR_PEER_V6, req->_present.peer_v6_len, req->peer_v6);
142d75fdfbcSJakub Kicinski 
143d75fdfbcSJakub Kicinski 	err = ynl_exec(ys, nlh, NULL);
144d75fdfbcSJakub Kicinski 	if (err < 0)
145d75fdfbcSJakub Kicinski 		return -1;
146d75fdfbcSJakub Kicinski 
147d75fdfbcSJakub Kicinski 	return 0;
148d75fdfbcSJakub Kicinski }
149d75fdfbcSJakub Kicinski 
150d75fdfbcSJakub Kicinski /* ============== FOU_CMD_GET ============== */
151d75fdfbcSJakub Kicinski /* FOU_CMD_GET - do */
fou_get_req_free(struct fou_get_req * req)152d75fdfbcSJakub Kicinski void fou_get_req_free(struct fou_get_req *req)
153d75fdfbcSJakub Kicinski {
154d75fdfbcSJakub Kicinski 	free(req->local_v6);
155d75fdfbcSJakub Kicinski 	free(req->peer_v6);
156d75fdfbcSJakub Kicinski 	free(req);
157d75fdfbcSJakub Kicinski }
158d75fdfbcSJakub Kicinski 
fou_get_rsp_free(struct fou_get_rsp * rsp)159d75fdfbcSJakub Kicinski void fou_get_rsp_free(struct fou_get_rsp *rsp)
160d75fdfbcSJakub Kicinski {
161d75fdfbcSJakub Kicinski 	free(rsp->local_v6);
162d75fdfbcSJakub Kicinski 	free(rsp->peer_v6);
163d75fdfbcSJakub Kicinski 	free(rsp);
164d75fdfbcSJakub Kicinski }
165d75fdfbcSJakub Kicinski 
fou_get_rsp_parse(const struct nlmsghdr * nlh,void * data)166d75fdfbcSJakub Kicinski int fou_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
167d75fdfbcSJakub Kicinski {
168d75fdfbcSJakub Kicinski 	struct ynl_parse_arg *yarg = data;
169d75fdfbcSJakub Kicinski 	const struct nlattr *attr;
170d75fdfbcSJakub Kicinski 	struct fou_get_rsp *dst;
171d75fdfbcSJakub Kicinski 
172d75fdfbcSJakub Kicinski 	dst = yarg->data;
173d75fdfbcSJakub Kicinski 
174d75fdfbcSJakub Kicinski 	mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
175*7234415bSJakub Kicinski 		unsigned int type = mnl_attr_get_type(attr);
176*7234415bSJakub Kicinski 
177*7234415bSJakub Kicinski 		if (type == FOU_ATTR_PORT) {
178d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
179d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
180d75fdfbcSJakub Kicinski 			dst->_present.port = 1;
181d75fdfbcSJakub Kicinski 			dst->port = mnl_attr_get_u16(attr);
182*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_IPPROTO) {
183d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
184d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
185d75fdfbcSJakub Kicinski 			dst->_present.ipproto = 1;
186d75fdfbcSJakub Kicinski 			dst->ipproto = mnl_attr_get_u8(attr);
187*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_TYPE) {
188d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
189d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
190d75fdfbcSJakub Kicinski 			dst->_present.type = 1;
191d75fdfbcSJakub Kicinski 			dst->type = mnl_attr_get_u8(attr);
192*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_REMCSUM_NOPARTIAL) {
193d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
194d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
195d75fdfbcSJakub Kicinski 			dst->_present.remcsum_nopartial = 1;
196*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_LOCAL_V4) {
197d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
198d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
199d75fdfbcSJakub Kicinski 			dst->_present.local_v4 = 1;
200d75fdfbcSJakub Kicinski 			dst->local_v4 = mnl_attr_get_u32(attr);
201*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_PEER_V4) {
202d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
203d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
204d75fdfbcSJakub Kicinski 			dst->_present.peer_v4 = 1;
205d75fdfbcSJakub Kicinski 			dst->peer_v4 = mnl_attr_get_u32(attr);
206*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_LOCAL_V6) {
207d75fdfbcSJakub Kicinski 			unsigned int len;
208d75fdfbcSJakub Kicinski 
209d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
210d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
211d75fdfbcSJakub Kicinski 
212d75fdfbcSJakub Kicinski 			len = mnl_attr_get_payload_len(attr);
213d75fdfbcSJakub Kicinski 			dst->_present.local_v6_len = len;
214d75fdfbcSJakub Kicinski 			dst->local_v6 = malloc(len);
215d75fdfbcSJakub Kicinski 			memcpy(dst->local_v6, mnl_attr_get_payload(attr), len);
216*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_PEER_V6) {
217d75fdfbcSJakub Kicinski 			unsigned int len;
218d75fdfbcSJakub Kicinski 
219d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
220d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
221d75fdfbcSJakub Kicinski 
222d75fdfbcSJakub Kicinski 			len = mnl_attr_get_payload_len(attr);
223d75fdfbcSJakub Kicinski 			dst->_present.peer_v6_len = len;
224d75fdfbcSJakub Kicinski 			dst->peer_v6 = malloc(len);
225d75fdfbcSJakub Kicinski 			memcpy(dst->peer_v6, mnl_attr_get_payload(attr), len);
226*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_PEER_PORT) {
227d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
228d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
229d75fdfbcSJakub Kicinski 			dst->_present.peer_port = 1;
230d75fdfbcSJakub Kicinski 			dst->peer_port = mnl_attr_get_u16(attr);
231*7234415bSJakub Kicinski 		} else if (type == FOU_ATTR_IFINDEX) {
232d75fdfbcSJakub Kicinski 			if (ynl_attr_validate(yarg, attr))
233d75fdfbcSJakub Kicinski 				return MNL_CB_ERROR;
234d75fdfbcSJakub Kicinski 			dst->_present.ifindex = 1;
235d75fdfbcSJakub Kicinski 			dst->ifindex = mnl_attr_get_u32(attr);
236d75fdfbcSJakub Kicinski 		}
237d75fdfbcSJakub Kicinski 	}
238d75fdfbcSJakub Kicinski 
239d75fdfbcSJakub Kicinski 	return MNL_CB_OK;
240d75fdfbcSJakub Kicinski }
241d75fdfbcSJakub Kicinski 
fou_get(struct ynl_sock * ys,struct fou_get_req * req)242d75fdfbcSJakub Kicinski struct fou_get_rsp *fou_get(struct ynl_sock *ys, struct fou_get_req *req)
243d75fdfbcSJakub Kicinski {
244d75fdfbcSJakub Kicinski 	struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
245d75fdfbcSJakub Kicinski 	struct fou_get_rsp *rsp;
246d75fdfbcSJakub Kicinski 	struct nlmsghdr *nlh;
247d75fdfbcSJakub Kicinski 	int err;
248d75fdfbcSJakub Kicinski 
249d75fdfbcSJakub Kicinski 	nlh = ynl_gemsg_start_req(ys, ys->family_id, FOU_CMD_GET, 1);
250d75fdfbcSJakub Kicinski 	ys->req_policy = &fou_nest;
251d75fdfbcSJakub Kicinski 	yrs.yarg.rsp_policy = &fou_nest;
252d75fdfbcSJakub Kicinski 
253d75fdfbcSJakub Kicinski 	if (req->_present.af)
254d75fdfbcSJakub Kicinski 		mnl_attr_put_u8(nlh, FOU_ATTR_AF, req->af);
255d75fdfbcSJakub Kicinski 	if (req->_present.ifindex)
256d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_IFINDEX, req->ifindex);
257d75fdfbcSJakub Kicinski 	if (req->_present.port)
258d75fdfbcSJakub Kicinski 		mnl_attr_put_u16(nlh, FOU_ATTR_PORT, req->port);
259d75fdfbcSJakub Kicinski 	if (req->_present.peer_port)
260d75fdfbcSJakub Kicinski 		mnl_attr_put_u16(nlh, FOU_ATTR_PEER_PORT, req->peer_port);
261d75fdfbcSJakub Kicinski 	if (req->_present.local_v4)
262d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_LOCAL_V4, req->local_v4);
263d75fdfbcSJakub Kicinski 	if (req->_present.peer_v4)
264d75fdfbcSJakub Kicinski 		mnl_attr_put_u32(nlh, FOU_ATTR_PEER_V4, req->peer_v4);
265d75fdfbcSJakub Kicinski 	if (req->_present.local_v6_len)
266d75fdfbcSJakub Kicinski 		mnl_attr_put(nlh, FOU_ATTR_LOCAL_V6, req->_present.local_v6_len, req->local_v6);
267d75fdfbcSJakub Kicinski 	if (req->_present.peer_v6_len)
268d75fdfbcSJakub Kicinski 		mnl_attr_put(nlh, FOU_ATTR_PEER_V6, req->_present.peer_v6_len, req->peer_v6);
269d75fdfbcSJakub Kicinski 
270d75fdfbcSJakub Kicinski 	rsp = calloc(1, sizeof(*rsp));
271d75fdfbcSJakub Kicinski 	yrs.yarg.data = rsp;
272d75fdfbcSJakub Kicinski 	yrs.cb = fou_get_rsp_parse;
273d75fdfbcSJakub Kicinski 	yrs.rsp_cmd = FOU_CMD_GET;
274d75fdfbcSJakub Kicinski 
275d75fdfbcSJakub Kicinski 	err = ynl_exec(ys, nlh, &yrs);
276d75fdfbcSJakub Kicinski 	if (err < 0)
277d75fdfbcSJakub Kicinski 		goto err_free;
278d75fdfbcSJakub Kicinski 
279d75fdfbcSJakub Kicinski 	return rsp;
280d75fdfbcSJakub Kicinski 
281d75fdfbcSJakub Kicinski err_free:
282d75fdfbcSJakub Kicinski 	fou_get_rsp_free(rsp);
283d75fdfbcSJakub Kicinski 	return NULL;
284d75fdfbcSJakub Kicinski }
285d75fdfbcSJakub Kicinski 
286d75fdfbcSJakub Kicinski /* FOU_CMD_GET - dump */
fou_get_list_free(struct fou_get_list * rsp)287d75fdfbcSJakub Kicinski void fou_get_list_free(struct fou_get_list *rsp)
288d75fdfbcSJakub Kicinski {
289d75fdfbcSJakub Kicinski 	struct fou_get_list *next = rsp;
290d75fdfbcSJakub Kicinski 
291d75fdfbcSJakub Kicinski 	while ((void *)next != YNL_LIST_END) {
292d75fdfbcSJakub Kicinski 		rsp = next;
293d75fdfbcSJakub Kicinski 		next = rsp->next;
294d75fdfbcSJakub Kicinski 
295d75fdfbcSJakub Kicinski 		free(rsp->obj.local_v6);
296d75fdfbcSJakub Kicinski 		free(rsp->obj.peer_v6);
297d75fdfbcSJakub Kicinski 		free(rsp);
298d75fdfbcSJakub Kicinski 	}
299d75fdfbcSJakub Kicinski }
300d75fdfbcSJakub Kicinski 
fou_get_dump(struct ynl_sock * ys)301d75fdfbcSJakub Kicinski struct fou_get_list *fou_get_dump(struct ynl_sock *ys)
302d75fdfbcSJakub Kicinski {
303d75fdfbcSJakub Kicinski 	struct ynl_dump_state yds = {};
304d75fdfbcSJakub Kicinski 	struct nlmsghdr *nlh;
305d75fdfbcSJakub Kicinski 	int err;
306d75fdfbcSJakub Kicinski 
307d75fdfbcSJakub Kicinski 	yds.ys = ys;
308d75fdfbcSJakub Kicinski 	yds.alloc_sz = sizeof(struct fou_get_list);
309d75fdfbcSJakub Kicinski 	yds.cb = fou_get_rsp_parse;
310d75fdfbcSJakub Kicinski 	yds.rsp_cmd = FOU_CMD_GET;
311d75fdfbcSJakub Kicinski 	yds.rsp_policy = &fou_nest;
312d75fdfbcSJakub Kicinski 
313d75fdfbcSJakub Kicinski 	nlh = ynl_gemsg_start_dump(ys, ys->family_id, FOU_CMD_GET, 1);
314d75fdfbcSJakub Kicinski 
315d75fdfbcSJakub Kicinski 	err = ynl_exec_dump(ys, nlh, &yds);
316d75fdfbcSJakub Kicinski 	if (err < 0)
317d75fdfbcSJakub Kicinski 		goto free_list;
318d75fdfbcSJakub Kicinski 
319d75fdfbcSJakub Kicinski 	return yds.first;
320d75fdfbcSJakub Kicinski 
321d75fdfbcSJakub Kicinski free_list:
322d75fdfbcSJakub Kicinski 	fou_get_list_free(yds.first);
323d75fdfbcSJakub Kicinski 	return NULL;
324d75fdfbcSJakub Kicinski }
325d75fdfbcSJakub Kicinski 
326d75fdfbcSJakub Kicinski const struct ynl_family ynl_fou_family =  {
327d75fdfbcSJakub Kicinski 	.name		= "fou",
328d75fdfbcSJakub Kicinski };
329