handshake.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef _INTERNAL_HANDSHAKE_H
  10. #define _INTERNAL_HANDSHAKE_H
  11. /* Per-net namespace context */
  12. struct handshake_net {
  13. spinlock_t hn_lock; /* protects next 3 fields */
  14. int hn_pending;
  15. int hn_pending_max;
  16. struct list_head hn_requests;
  17. unsigned long hn_flags;
  18. };
  19. enum hn_flags_bits {
  20. HANDSHAKE_F_NET_DRAINING,
  21. };
  22. struct handshake_proto;
  23. /* One handshake request */
  24. struct handshake_req {
  25. struct list_head hr_list;
  26. struct rhash_head hr_rhash;
  27. unsigned long hr_flags;
  28. const struct handshake_proto *hr_proto;
  29. struct sock *hr_sk;
  30. void (*hr_odestruct)(struct sock *sk);
  31. /* Always the last field */
  32. char hr_priv[];
  33. };
  34. enum hr_flags_bits {
  35. HANDSHAKE_F_REQ_COMPLETED,
  36. HANDSHAKE_F_REQ_SESSION,
  37. };
  38. struct genl_info;
  39. /* Invariants for all handshake requests for one transport layer
  40. * security protocol
  41. */
  42. struct handshake_proto {
  43. int hp_handler_class;
  44. size_t hp_privsize;
  45. unsigned long hp_flags;
  46. int (*hp_accept)(struct handshake_req *req,
  47. struct genl_info *info, int fd);
  48. void (*hp_done)(struct handshake_req *req,
  49. unsigned int status,
  50. struct genl_info *info);
  51. void (*hp_destroy)(struct handshake_req *req);
  52. };
  53. enum hp_flags_bits {
  54. HANDSHAKE_F_PROTO_NOTIFY,
  55. };
  56. /* alert.c */
  57. int tls_alert_send(struct socket *sock, u8 level, u8 description);
  58. /* netlink.c */
  59. int handshake_genl_notify(struct net *net, const struct handshake_proto *proto,
  60. gfp_t flags);
  61. struct nlmsghdr *handshake_genl_put(struct sk_buff *msg,
  62. struct genl_info *info);
  63. struct handshake_net *handshake_pernet(struct net *net);
  64. /* request.c */
  65. struct handshake_req *handshake_req_alloc(const struct handshake_proto *proto,
  66. gfp_t flags);
  67. int handshake_req_hash_init(void);
  68. void handshake_req_hash_destroy(void);
  69. void *handshake_req_private(struct handshake_req *req);
  70. struct handshake_req *handshake_req_hash_lookup(struct sock *sk);
  71. struct handshake_req *handshake_req_next(struct handshake_net *hn, int class);
  72. int handshake_req_submit(struct socket *sock, struct handshake_req *req,
  73. gfp_t flags);
  74. void handshake_complete(struct handshake_req *req, unsigned int status,
  75. struct genl_info *info);
  76. bool handshake_req_cancel(struct sock *sk);
  77. #endif /* _INTERNAL_HANDSHAKE_H */