1 // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
2 /* Do not edit directly, auto-generated from: */
3 /* Documentation/netlink/specs/fou.yaml */
4 /* YNL-GEN user source */
10 #include <linux/fou.h>
12 #include <libmnl/libmnl.h>
13 #include <linux/genetlink.h>
16 static const char * const fou_op_strmap
[] = {
17 [FOU_CMD_ADD
] = "add",
18 [FOU_CMD_DEL
] = "del",
19 [FOU_CMD_GET
] = "get",
22 const char *fou_op_str(int op
)
24 if (op
< 0 || op
>= (int)MNL_ARRAY_SIZE(fou_op_strmap
))
26 return fou_op_strmap
[op
];
29 static const char * const fou_encap_type_strmap
[] = {
35 const char *fou_encap_type_str(int value
)
37 if (value
< 0 || value
>= (int)MNL_ARRAY_SIZE(fou_encap_type_strmap
))
39 return fou_encap_type_strmap
[value
];
43 struct ynl_policy_attr fou_policy
[FOU_ATTR_MAX
+ 1] = {
44 [FOU_ATTR_UNSPEC
] = { .name
= "unspec", .type
= YNL_PT_REJECT
, },
45 [FOU_ATTR_PORT
] = { .name
= "port", .type
= YNL_PT_U16
, },
46 [FOU_ATTR_AF
] = { .name
= "af", .type
= YNL_PT_U8
, },
47 [FOU_ATTR_IPPROTO
] = { .name
= "ipproto", .type
= YNL_PT_U8
, },
48 [FOU_ATTR_TYPE
] = { .name
= "type", .type
= YNL_PT_U8
, },
49 [FOU_ATTR_REMCSUM_NOPARTIAL
] = { .name
= "remcsum_nopartial", .type
= YNL_PT_FLAG
, },
50 [FOU_ATTR_LOCAL_V4
] = { .name
= "local_v4", .type
= YNL_PT_U32
, },
51 [FOU_ATTR_LOCAL_V6
] = { .name
= "local_v6", .type
= YNL_PT_BINARY
,},
52 [FOU_ATTR_PEER_V4
] = { .name
= "peer_v4", .type
= YNL_PT_U32
, },
53 [FOU_ATTR_PEER_V6
] = { .name
= "peer_v6", .type
= YNL_PT_BINARY
,},
54 [FOU_ATTR_PEER_PORT
] = { .name
= "peer_port", .type
= YNL_PT_U16
, },
55 [FOU_ATTR_IFINDEX
] = { .name
= "ifindex", .type
= YNL_PT_U32
, },
58 struct ynl_policy_nest fou_nest
= {
59 .max_attr
= FOU_ATTR_MAX
,
63 /* Common nested types */
64 /* ============== FOU_CMD_ADD ============== */
65 /* FOU_CMD_ADD - do */
66 void fou_add_req_free(struct fou_add_req
*req
)
73 int fou_add(struct ynl_sock
*ys
, struct fou_add_req
*req
)
78 nlh
= ynl_gemsg_start_req(ys
, ys
->family_id
, FOU_CMD_ADD
, 1);
79 ys
->req_policy
= &fou_nest
;
81 if (req
->_present
.port
)
82 mnl_attr_put_u16(nlh
, FOU_ATTR_PORT
, req
->port
);
83 if (req
->_present
.ipproto
)
84 mnl_attr_put_u8(nlh
, FOU_ATTR_IPPROTO
, req
->ipproto
);
85 if (req
->_present
.type
)
86 mnl_attr_put_u8(nlh
, FOU_ATTR_TYPE
, req
->type
);
87 if (req
->_present
.remcsum_nopartial
)
88 mnl_attr_put(nlh
, FOU_ATTR_REMCSUM_NOPARTIAL
, 0, NULL
);
89 if (req
->_present
.local_v4
)
90 mnl_attr_put_u32(nlh
, FOU_ATTR_LOCAL_V4
, req
->local_v4
);
91 if (req
->_present
.peer_v4
)
92 mnl_attr_put_u32(nlh
, FOU_ATTR_PEER_V4
, req
->peer_v4
);
93 if (req
->_present
.local_v6_len
)
94 mnl_attr_put(nlh
, FOU_ATTR_LOCAL_V6
, req
->_present
.local_v6_len
, req
->local_v6
);
95 if (req
->_present
.peer_v6_len
)
96 mnl_attr_put(nlh
, FOU_ATTR_PEER_V6
, req
->_present
.peer_v6_len
, req
->peer_v6
);
97 if (req
->_present
.peer_port
)
98 mnl_attr_put_u16(nlh
, FOU_ATTR_PEER_PORT
, req
->peer_port
);
99 if (req
->_present
.ifindex
)
100 mnl_attr_put_u32(nlh
, FOU_ATTR_IFINDEX
, req
->ifindex
);
102 err
= ynl_exec(ys
, nlh
, NULL
);
109 /* ============== FOU_CMD_DEL ============== */
110 /* FOU_CMD_DEL - do */
111 void fou_del_req_free(struct fou_del_req
*req
)
118 int fou_del(struct ynl_sock
*ys
, struct fou_del_req
*req
)
120 struct nlmsghdr
*nlh
;
123 nlh
= ynl_gemsg_start_req(ys
, ys
->family_id
, FOU_CMD_DEL
, 1);
124 ys
->req_policy
= &fou_nest
;
126 if (req
->_present
.af
)
127 mnl_attr_put_u8(nlh
, FOU_ATTR_AF
, req
->af
);
128 if (req
->_present
.ifindex
)
129 mnl_attr_put_u32(nlh
, FOU_ATTR_IFINDEX
, req
->ifindex
);
130 if (req
->_present
.port
)
131 mnl_attr_put_u16(nlh
, FOU_ATTR_PORT
, req
->port
);
132 if (req
->_present
.peer_port
)
133 mnl_attr_put_u16(nlh
, FOU_ATTR_PEER_PORT
, req
->peer_port
);
134 if (req
->_present
.local_v4
)
135 mnl_attr_put_u32(nlh
, FOU_ATTR_LOCAL_V4
, req
->local_v4
);
136 if (req
->_present
.peer_v4
)
137 mnl_attr_put_u32(nlh
, FOU_ATTR_PEER_V4
, req
->peer_v4
);
138 if (req
->_present
.local_v6_len
)
139 mnl_attr_put(nlh
, FOU_ATTR_LOCAL_V6
, req
->_present
.local_v6_len
, req
->local_v6
);
140 if (req
->_present
.peer_v6_len
)
141 mnl_attr_put(nlh
, FOU_ATTR_PEER_V6
, req
->_present
.peer_v6_len
, req
->peer_v6
);
143 err
= ynl_exec(ys
, nlh
, NULL
);
150 /* ============== FOU_CMD_GET ============== */
151 /* FOU_CMD_GET - do */
152 void fou_get_req_free(struct fou_get_req
*req
)
159 void fou_get_rsp_free(struct fou_get_rsp
*rsp
)
166 int fou_get_rsp_parse(const struct nlmsghdr
*nlh
, void *data
)
168 struct ynl_parse_arg
*yarg
= data
;
169 const struct nlattr
*attr
;
170 struct fou_get_rsp
*dst
;
174 mnl_attr_for_each(attr
, nlh
, sizeof(struct genlmsghdr
)) {
175 unsigned int type
= mnl_attr_get_type(attr
);
177 if (type
== FOU_ATTR_PORT
) {
178 if (ynl_attr_validate(yarg
, attr
))
180 dst
->_present
.port
= 1;
181 dst
->port
= mnl_attr_get_u16(attr
);
182 } else if (type
== FOU_ATTR_IPPROTO
) {
183 if (ynl_attr_validate(yarg
, attr
))
185 dst
->_present
.ipproto
= 1;
186 dst
->ipproto
= mnl_attr_get_u8(attr
);
187 } else if (type
== FOU_ATTR_TYPE
) {
188 if (ynl_attr_validate(yarg
, attr
))
190 dst
->_present
.type
= 1;
191 dst
->type
= mnl_attr_get_u8(attr
);
192 } else if (type
== FOU_ATTR_REMCSUM_NOPARTIAL
) {
193 if (ynl_attr_validate(yarg
, attr
))
195 dst
->_present
.remcsum_nopartial
= 1;
196 } else if (type
== FOU_ATTR_LOCAL_V4
) {
197 if (ynl_attr_validate(yarg
, attr
))
199 dst
->_present
.local_v4
= 1;
200 dst
->local_v4
= mnl_attr_get_u32(attr
);
201 } else if (type
== FOU_ATTR_PEER_V4
) {
202 if (ynl_attr_validate(yarg
, attr
))
204 dst
->_present
.peer_v4
= 1;
205 dst
->peer_v4
= mnl_attr_get_u32(attr
);
206 } else if (type
== FOU_ATTR_LOCAL_V6
) {
209 if (ynl_attr_validate(yarg
, attr
))
212 len
= mnl_attr_get_payload_len(attr
);
213 dst
->_present
.local_v6_len
= len
;
214 dst
->local_v6
= malloc(len
);
215 memcpy(dst
->local_v6
, mnl_attr_get_payload(attr
), len
);
216 } else if (type
== FOU_ATTR_PEER_V6
) {
219 if (ynl_attr_validate(yarg
, attr
))
222 len
= mnl_attr_get_payload_len(attr
);
223 dst
->_present
.peer_v6_len
= len
;
224 dst
->peer_v6
= malloc(len
);
225 memcpy(dst
->peer_v6
, mnl_attr_get_payload(attr
), len
);
226 } else if (type
== FOU_ATTR_PEER_PORT
) {
227 if (ynl_attr_validate(yarg
, attr
))
229 dst
->_present
.peer_port
= 1;
230 dst
->peer_port
= mnl_attr_get_u16(attr
);
231 } else if (type
== FOU_ATTR_IFINDEX
) {
232 if (ynl_attr_validate(yarg
, attr
))
234 dst
->_present
.ifindex
= 1;
235 dst
->ifindex
= mnl_attr_get_u32(attr
);
242 struct fou_get_rsp
*fou_get(struct ynl_sock
*ys
, struct fou_get_req
*req
)
244 struct ynl_req_state yrs
= { .yarg
= { .ys
= ys
, }, };
245 struct fou_get_rsp
*rsp
;
246 struct nlmsghdr
*nlh
;
249 nlh
= ynl_gemsg_start_req(ys
, ys
->family_id
, FOU_CMD_GET
, 1);
250 ys
->req_policy
= &fou_nest
;
251 yrs
.yarg
.rsp_policy
= &fou_nest
;
253 if (req
->_present
.af
)
254 mnl_attr_put_u8(nlh
, FOU_ATTR_AF
, req
->af
);
255 if (req
->_present
.ifindex
)
256 mnl_attr_put_u32(nlh
, FOU_ATTR_IFINDEX
, req
->ifindex
);
257 if (req
->_present
.port
)
258 mnl_attr_put_u16(nlh
, FOU_ATTR_PORT
, req
->port
);
259 if (req
->_present
.peer_port
)
260 mnl_attr_put_u16(nlh
, FOU_ATTR_PEER_PORT
, req
->peer_port
);
261 if (req
->_present
.local_v4
)
262 mnl_attr_put_u32(nlh
, FOU_ATTR_LOCAL_V4
, req
->local_v4
);
263 if (req
->_present
.peer_v4
)
264 mnl_attr_put_u32(nlh
, FOU_ATTR_PEER_V4
, req
->peer_v4
);
265 if (req
->_present
.local_v6_len
)
266 mnl_attr_put(nlh
, FOU_ATTR_LOCAL_V6
, req
->_present
.local_v6_len
, req
->local_v6
);
267 if (req
->_present
.peer_v6_len
)
268 mnl_attr_put(nlh
, FOU_ATTR_PEER_V6
, req
->_present
.peer_v6_len
, req
->peer_v6
);
270 rsp
= calloc(1, sizeof(*rsp
));
272 yrs
.cb
= fou_get_rsp_parse
;
273 yrs
.rsp_cmd
= FOU_CMD_GET
;
275 err
= ynl_exec(ys
, nlh
, &yrs
);
282 fou_get_rsp_free(rsp
);
286 /* FOU_CMD_GET - dump */
287 void fou_get_list_free(struct fou_get_list
*rsp
)
289 struct fou_get_list
*next
= rsp
;
291 while ((void *)next
!= YNL_LIST_END
) {
295 free(rsp
->obj
.local_v6
);
296 free(rsp
->obj
.peer_v6
);
301 struct fou_get_list
*fou_get_dump(struct ynl_sock
*ys
)
303 struct ynl_dump_state yds
= {};
304 struct nlmsghdr
*nlh
;
308 yds
.alloc_sz
= sizeof(struct fou_get_list
);
309 yds
.cb
= fou_get_rsp_parse
;
310 yds
.rsp_cmd
= FOU_CMD_GET
;
311 yds
.rsp_policy
= &fou_nest
;
313 nlh
= ynl_gemsg_start_dump(ys
, ys
->family_id
, FOU_CMD_GET
, 1);
315 err
= ynl_exec_dump(ys
, nlh
, &yds
);
322 fou_get_list_free(yds
.first
);
326 const struct ynl_family ynl_fou_family
= {