1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Generic netlink handshake service 4 * 5 * Author: Chuck Lever <chuck.lever@oracle.com> 6 * 7 * Copyright (c) 2023, Oracle and/or its affiliates. 8 */ 9 10 #ifndef _INTERNAL_HANDSHAKE_H 11 #define _INTERNAL_HANDSHAKE_H 12 13 /* Per-net namespace context */ 14 struct handshake_net { 15 spinlock_t hn_lock; /* protects next 3 fields */ 16 int hn_pending; 17 int hn_pending_max; 18 struct list_head hn_requests; 19 20 unsigned long hn_flags; 21 }; 22 23 enum hn_flags_bits { 24 HANDSHAKE_F_NET_DRAINING, 25 }; 26 27 struct handshake_proto; 28 29 /* One handshake request */ 30 struct handshake_req { 31 struct list_head hr_list; 32 struct rhash_head hr_rhash; 33 unsigned long hr_flags; 34 struct file *hr_file; 35 const struct handshake_proto *hr_proto; 36 struct sock *hr_sk; 37 void (*hr_odestruct)(struct sock *sk); 38 39 /* Always the last field */ 40 char hr_priv[]; 41 }; 42 43 enum hr_flags_bits { 44 HANDSHAKE_F_REQ_COMPLETED, 45 }; 46 47 /* Invariants for all handshake requests for one transport layer 48 * security protocol 49 */ 50 struct handshake_proto { 51 int hp_handler_class; 52 size_t hp_privsize; 53 unsigned long hp_flags; 54 55 int (*hp_accept)(struct handshake_req *req, 56 struct genl_info *info, int fd); 57 void (*hp_done)(struct handshake_req *req, 58 unsigned int status, 59 struct genl_info *info); 60 void (*hp_destroy)(struct handshake_req *req); 61 }; 62 63 enum hp_flags_bits { 64 HANDSHAKE_F_PROTO_NOTIFY, 65 }; 66 67 /* netlink.c */ 68 int handshake_genl_notify(struct net *net, const struct handshake_proto *proto, 69 gfp_t flags); 70 struct nlmsghdr *handshake_genl_put(struct sk_buff *msg, 71 struct genl_info *info); 72 struct handshake_net *handshake_pernet(struct net *net); 73 74 /* request.c */ 75 struct handshake_req *handshake_req_alloc(const struct handshake_proto *proto, 76 gfp_t flags); 77 int handshake_req_hash_init(void); 78 void handshake_req_hash_destroy(void); 79 void *handshake_req_private(struct handshake_req *req); 80 struct handshake_req *handshake_req_hash_lookup(struct sock *sk); 81 struct handshake_req *handshake_req_next(struct handshake_net *hn, int class); 82 int handshake_req_submit(struct socket *sock, struct handshake_req *req, 83 gfp_t flags); 84 void handshake_complete(struct handshake_req *req, unsigned int status, 85 struct genl_info *info); 86 bool handshake_req_cancel(struct sock *sk); 87 88 #endif /* _INTERNAL_HANDSHAKE_H */ 89