af_qmsgq.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __AF_QMSGQ_H_
  6. #define __AF_QMSGQ_H_
  7. #include <net/af_vsock.h>
  8. struct qmsgq_endpoint;
  9. struct qmsgq_sock {
  10. /* sk must be the first member. */
  11. struct sock sk;
  12. const struct qmsgq_endpoint *ep;
  13. struct sockaddr_vm local_addr;
  14. struct sockaddr_vm remote_addr;
  15. /* Links for the global tables of bound and connected sockets. */
  16. struct list_head bound_table;
  17. struct list_head connected_table;
  18. /* Accessed without the socket lock held. This means it can never be
  19. * modified outsided of socket create or destruct.
  20. */
  21. bool trusted;
  22. bool cached_peer_allow_dgram; /* Dgram communication allowed to
  23. * cached peer?
  24. */
  25. u32 cached_peer; /* Context ID of last dgram destination check. */
  26. const struct cred *owner;
  27. /* Rest are SOCK_STREAM only. */
  28. long connect_timeout;
  29. /* Listening socket that this came from. */
  30. struct sock *listener;
  31. /* Used for pending list and accept queue during connection handshake.
  32. * The listening socket is the head for both lists. Sockets created
  33. * for connection requests are placed in the pending list until they
  34. * are connected, at which point they are put in the accept queue list
  35. * so they can be accepted in accept(). If accept() cannot accept the
  36. * connection, it is marked as rejected so the cleanup function knows
  37. * to clean up the socket.
  38. */
  39. struct list_head pending_links;
  40. struct list_head accept_queue;
  41. bool rejected;
  42. struct delayed_work connect_work;
  43. struct delayed_work pending_work;
  44. struct delayed_work close_work;
  45. bool close_work_scheduled;
  46. u32 peer_shutdown;
  47. bool sent_request;
  48. bool ignore_connecting_rst;
  49. /* Protected by lock_sock(sk) */
  50. u64 buffer_size;
  51. u64 buffer_min_size;
  52. u64 buffer_max_size;
  53. };
  54. #define qsk_sk(__qsk) (&(__qsk)->sk)
  55. #define sk_qsk(__sk) ((struct qmsgq_sock *)__sk)
  56. struct qmsgq_endpoint {
  57. struct module *module;
  58. /* Initialize/tear-down socket. */
  59. int (*init)(struct qmsgq_sock *qsk, struct qmsgq_sock *psk);
  60. void (*destruct)(struct qmsgq_sock *qsk);
  61. void (*release)(struct qmsgq_sock *qsk);
  62. /* DGRAM. */
  63. int (*dgram_enqueue)(struct qmsgq_sock *qsk, struct sockaddr_vm *addr,
  64. struct msghdr *msg, size_t len);
  65. bool (*dgram_allow)(u32 cid, u32 port);
  66. /* Shutdown. */
  67. int (*shutdown)(struct qmsgq_sock *qsk, int mode);
  68. /* Addressing. */
  69. u32 (*get_local_cid)(void);
  70. };
  71. int qmsgq_post(const struct qmsgq_endpoint *ep, struct sockaddr_vm *src, struct sockaddr_vm *dst,
  72. void *data, int len);
  73. int qmsgq_endpoint_register(const struct qmsgq_endpoint *ep);
  74. void qmsgq_endpoint_unregister(const struct qmsgq_endpoint *ep);
  75. #endif