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/handshake.yaml */
4 /* YNL-GEN user source */
8 #include "handshake-user.h"
10 #include <linux/handshake.h>
12 #include <libmnl/libmnl.h>
13 #include <linux/genetlink.h>
16 static const char * const handshake_op_strmap
[] = {
17 [HANDSHAKE_CMD_READY
] = "ready",
18 [HANDSHAKE_CMD_ACCEPT
] = "accept",
19 [HANDSHAKE_CMD_DONE
] = "done",
22 const char *handshake_op_str(int op
)
24 if (op
< 0 || op
>= (int)MNL_ARRAY_SIZE(handshake_op_strmap
))
26 return handshake_op_strmap
[op
];
29 static const char * const handshake_handler_class_strmap
[] = {
35 const char *handshake_handler_class_str(enum handshake_handler_class value
)
37 if (value
< 0 || value
>= (int)MNL_ARRAY_SIZE(handshake_handler_class_strmap
))
39 return handshake_handler_class_strmap
[value
];
42 static const char * const handshake_msg_type_strmap
[] = {
48 const char *handshake_msg_type_str(enum handshake_msg_type value
)
50 if (value
< 0 || value
>= (int)MNL_ARRAY_SIZE(handshake_msg_type_strmap
))
52 return handshake_msg_type_strmap
[value
];
55 static const char * const handshake_auth_strmap
[] = {
62 const char *handshake_auth_str(enum handshake_auth value
)
64 if (value
< 0 || value
>= (int)MNL_ARRAY_SIZE(handshake_auth_strmap
))
66 return handshake_auth_strmap
[value
];
70 struct ynl_policy_attr handshake_x509_policy
[HANDSHAKE_A_X509_MAX
+ 1] = {
71 [HANDSHAKE_A_X509_CERT
] = { .name
= "cert", .type
= YNL_PT_U32
, },
72 [HANDSHAKE_A_X509_PRIVKEY
] = { .name
= "privkey", .type
= YNL_PT_U32
, },
75 struct ynl_policy_nest handshake_x509_nest
= {
76 .max_attr
= HANDSHAKE_A_X509_MAX
,
77 .table
= handshake_x509_policy
,
80 struct ynl_policy_attr handshake_accept_policy
[HANDSHAKE_A_ACCEPT_MAX
+ 1] = {
81 [HANDSHAKE_A_ACCEPT_SOCKFD
] = { .name
= "sockfd", .type
= YNL_PT_U32
, },
82 [HANDSHAKE_A_ACCEPT_HANDLER_CLASS
] = { .name
= "handler-class", .type
= YNL_PT_U32
, },
83 [HANDSHAKE_A_ACCEPT_MESSAGE_TYPE
] = { .name
= "message-type", .type
= YNL_PT_U32
, },
84 [HANDSHAKE_A_ACCEPT_TIMEOUT
] = { .name
= "timeout", .type
= YNL_PT_U32
, },
85 [HANDSHAKE_A_ACCEPT_AUTH_MODE
] = { .name
= "auth-mode", .type
= YNL_PT_U32
, },
86 [HANDSHAKE_A_ACCEPT_PEER_IDENTITY
] = { .name
= "peer-identity", .type
= YNL_PT_U32
, },
87 [HANDSHAKE_A_ACCEPT_CERTIFICATE
] = { .name
= "certificate", .type
= YNL_PT_NEST
, .nest
= &handshake_x509_nest
, },
88 [HANDSHAKE_A_ACCEPT_PEERNAME
] = { .name
= "peername", .type
= YNL_PT_NUL_STR
, },
91 struct ynl_policy_nest handshake_accept_nest
= {
92 .max_attr
= HANDSHAKE_A_ACCEPT_MAX
,
93 .table
= handshake_accept_policy
,
96 struct ynl_policy_attr handshake_done_policy
[HANDSHAKE_A_DONE_MAX
+ 1] = {
97 [HANDSHAKE_A_DONE_STATUS
] = { .name
= "status", .type
= YNL_PT_U32
, },
98 [HANDSHAKE_A_DONE_SOCKFD
] = { .name
= "sockfd", .type
= YNL_PT_U32
, },
99 [HANDSHAKE_A_DONE_REMOTE_AUTH
] = { .name
= "remote-auth", .type
= YNL_PT_U32
, },
102 struct ynl_policy_nest handshake_done_nest
= {
103 .max_attr
= HANDSHAKE_A_DONE_MAX
,
104 .table
= handshake_done_policy
,
107 /* Common nested types */
108 void handshake_x509_free(struct handshake_x509
*obj
)
112 int handshake_x509_parse(struct ynl_parse_arg
*yarg
,
113 const struct nlattr
*nested
)
115 struct handshake_x509
*dst
= yarg
->data
;
116 const struct nlattr
*attr
;
118 mnl_attr_for_each_nested(attr
, nested
) {
119 unsigned int type
= mnl_attr_get_type(attr
);
121 if (type
== HANDSHAKE_A_X509_CERT
) {
122 if (ynl_attr_validate(yarg
, attr
))
124 dst
->_present
.cert
= 1;
125 dst
->cert
= mnl_attr_get_u32(attr
);
126 } else if (type
== HANDSHAKE_A_X509_PRIVKEY
) {
127 if (ynl_attr_validate(yarg
, attr
))
129 dst
->_present
.privkey
= 1;
130 dst
->privkey
= mnl_attr_get_u32(attr
);
137 /* ============== HANDSHAKE_CMD_ACCEPT ============== */
138 /* HANDSHAKE_CMD_ACCEPT - do */
139 void handshake_accept_req_free(struct handshake_accept_req
*req
)
144 void handshake_accept_rsp_free(struct handshake_accept_rsp
*rsp
)
148 free(rsp
->peer_identity
);
149 for (i
= 0; i
< rsp
->n_certificate
; i
++)
150 handshake_x509_free(&rsp
->certificate
[i
]);
151 free(rsp
->certificate
);
156 int handshake_accept_rsp_parse(const struct nlmsghdr
*nlh
, void *data
)
158 struct ynl_parse_arg
*yarg
= data
;
159 struct handshake_accept_rsp
*dst
;
160 unsigned int n_peer_identity
= 0;
161 unsigned int n_certificate
= 0;
162 const struct nlattr
*attr
;
163 struct ynl_parse_arg parg
;
169 if (dst
->certificate
)
170 return ynl_error_parse(yarg
, "attribute already present (accept.certificate)");
171 if (dst
->peer_identity
)
172 return ynl_error_parse(yarg
, "attribute already present (accept.peer-identity)");
174 mnl_attr_for_each(attr
, nlh
, sizeof(struct genlmsghdr
)) {
175 unsigned int type
= mnl_attr_get_type(attr
);
177 if (type
== HANDSHAKE_A_ACCEPT_SOCKFD
) {
178 if (ynl_attr_validate(yarg
, attr
))
180 dst
->_present
.sockfd
= 1;
181 dst
->sockfd
= mnl_attr_get_u32(attr
);
182 } else if (type
== HANDSHAKE_A_ACCEPT_MESSAGE_TYPE
) {
183 if (ynl_attr_validate(yarg
, attr
))
185 dst
->_present
.message_type
= 1;
186 dst
->message_type
= mnl_attr_get_u32(attr
);
187 } else if (type
== HANDSHAKE_A_ACCEPT_TIMEOUT
) {
188 if (ynl_attr_validate(yarg
, attr
))
190 dst
->_present
.timeout
= 1;
191 dst
->timeout
= mnl_attr_get_u32(attr
);
192 } else if (type
== HANDSHAKE_A_ACCEPT_AUTH_MODE
) {
193 if (ynl_attr_validate(yarg
, attr
))
195 dst
->_present
.auth_mode
= 1;
196 dst
->auth_mode
= mnl_attr_get_u32(attr
);
197 } else if (type
== HANDSHAKE_A_ACCEPT_PEER_IDENTITY
) {
199 } else if (type
== HANDSHAKE_A_ACCEPT_CERTIFICATE
) {
201 } else if (type
== HANDSHAKE_A_ACCEPT_PEERNAME
) {
204 if (ynl_attr_validate(yarg
, attr
))
207 len
= strnlen(mnl_attr_get_str(attr
), mnl_attr_get_payload_len(attr
));
208 dst
->_present
.peername_len
= len
;
209 dst
->peername
= malloc(len
+ 1);
210 memcpy(dst
->peername
, mnl_attr_get_str(attr
), len
);
211 dst
->peername
[len
] = 0;
216 dst
->certificate
= calloc(n_certificate
, sizeof(*dst
->certificate
));
217 dst
->n_certificate
= n_certificate
;
219 parg
.rsp_policy
= &handshake_x509_nest
;
220 mnl_attr_for_each(attr
, nlh
, sizeof(struct genlmsghdr
)) {
221 if (mnl_attr_get_type(attr
) == HANDSHAKE_A_ACCEPT_CERTIFICATE
) {
222 parg
.data
= &dst
->certificate
[i
];
223 if (handshake_x509_parse(&parg
, attr
))
229 if (n_peer_identity
) {
230 dst
->peer_identity
= calloc(n_peer_identity
, sizeof(*dst
->peer_identity
));
231 dst
->n_peer_identity
= n_peer_identity
;
233 mnl_attr_for_each(attr
, nlh
, sizeof(struct genlmsghdr
)) {
234 if (mnl_attr_get_type(attr
) == HANDSHAKE_A_ACCEPT_PEER_IDENTITY
) {
235 dst
->peer_identity
[i
] = mnl_attr_get_u32(attr
);
244 struct handshake_accept_rsp
*
245 handshake_accept(struct ynl_sock
*ys
, struct handshake_accept_req
*req
)
247 struct ynl_req_state yrs
= { .yarg
= { .ys
= ys
, }, };
248 struct handshake_accept_rsp
*rsp
;
249 struct nlmsghdr
*nlh
;
252 nlh
= ynl_gemsg_start_req(ys
, ys
->family_id
, HANDSHAKE_CMD_ACCEPT
, 1);
253 ys
->req_policy
= &handshake_accept_nest
;
254 yrs
.yarg
.rsp_policy
= &handshake_accept_nest
;
256 if (req
->_present
.handler_class
)
257 mnl_attr_put_u32(nlh
, HANDSHAKE_A_ACCEPT_HANDLER_CLASS
, req
->handler_class
);
259 rsp
= calloc(1, sizeof(*rsp
));
261 yrs
.cb
= handshake_accept_rsp_parse
;
262 yrs
.rsp_cmd
= HANDSHAKE_CMD_ACCEPT
;
264 err
= ynl_exec(ys
, nlh
, &yrs
);
271 handshake_accept_rsp_free(rsp
);
275 /* HANDSHAKE_CMD_ACCEPT - notify */
276 void handshake_accept_ntf_free(struct handshake_accept_ntf
*rsp
)
280 free(rsp
->obj
.peer_identity
);
281 for (i
= 0; i
< rsp
->obj
.n_certificate
; i
++)
282 handshake_x509_free(&rsp
->obj
.certificate
[i
]);
283 free(rsp
->obj
.certificate
);
284 free(rsp
->obj
.peername
);
288 /* ============== HANDSHAKE_CMD_DONE ============== */
289 /* HANDSHAKE_CMD_DONE - do */
290 void handshake_done_req_free(struct handshake_done_req
*req
)
292 free(req
->remote_auth
);
296 int handshake_done(struct ynl_sock
*ys
, struct handshake_done_req
*req
)
298 struct nlmsghdr
*nlh
;
301 nlh
= ynl_gemsg_start_req(ys
, ys
->family_id
, HANDSHAKE_CMD_DONE
, 1);
302 ys
->req_policy
= &handshake_done_nest
;
304 if (req
->_present
.status
)
305 mnl_attr_put_u32(nlh
, HANDSHAKE_A_DONE_STATUS
, req
->status
);
306 if (req
->_present
.sockfd
)
307 mnl_attr_put_u32(nlh
, HANDSHAKE_A_DONE_SOCKFD
, req
->sockfd
);
308 for (unsigned int i
= 0; i
< req
->n_remote_auth
; i
++)
309 mnl_attr_put_u32(nlh
, HANDSHAKE_A_DONE_REMOTE_AUTH
, req
->remote_auth
[i
]);
311 err
= ynl_exec(ys
, nlh
, NULL
);
318 static const struct ynl_ntf_info handshake_ntf_info
[] = {
319 [HANDSHAKE_CMD_READY
] = {
320 .alloc_sz
= sizeof(struct handshake_accept_ntf
),
321 .cb
= handshake_accept_rsp_parse
,
322 .policy
= &handshake_accept_nest
,
323 .free
= (void *)handshake_accept_ntf_free
,
327 const struct ynl_family ynl_handshake_family
= {
329 .ntf_info
= handshake_ntf_info
,
330 .ntf_info_size
= MNL_ARRAY_SIZE(handshake_ntf_info
),