connector.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * connector.h
  4. *
  5. * 2004-2005 Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
  6. * All rights reserved.
  7. */
  8. #ifndef __CONNECTOR_H
  9. #define __CONNECTOR_H
  10. #include <linux/refcount.h>
  11. #include <linux/list.h>
  12. #include <linux/workqueue.h>
  13. #include <net/sock.h>
  14. #include <uapi/linux/connector.h>
  15. #define CN_CBQ_NAMELEN 32
  16. struct cn_queue_dev {
  17. atomic_t refcnt;
  18. unsigned char name[CN_CBQ_NAMELEN];
  19. struct list_head queue_list;
  20. spinlock_t queue_lock;
  21. struct sock *nls;
  22. };
  23. struct cn_callback_id {
  24. unsigned char name[CN_CBQ_NAMELEN];
  25. struct cb_id id;
  26. };
  27. struct cn_callback_entry {
  28. struct list_head callback_entry;
  29. refcount_t refcnt;
  30. struct cn_queue_dev *pdev;
  31. struct cn_callback_id id;
  32. void (*callback) (struct cn_msg *, struct netlink_skb_parms *);
  33. u32 seq, group;
  34. };
  35. struct cn_dev {
  36. struct cb_id id;
  37. u32 seq, groups;
  38. struct sock *nls;
  39. struct cn_queue_dev *cbdev;
  40. };
  41. /**
  42. * cn_add_callback() - Registers new callback with connector core.
  43. *
  44. * @id: unique connector's user identifier.
  45. * It must be registered in connector.h for legal
  46. * in-kernel users.
  47. * @name: connector's callback symbolic name.
  48. * @callback: connector's callback.
  49. * parameters are %cn_msg and the sender's credentials
  50. */
  51. int cn_add_callback(struct cb_id *id, const char *name,
  52. void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
  53. /**
  54. * cn_del_callback() - Unregisters new callback with connector core.
  55. *
  56. * @id: unique connector's user identifier.
  57. */
  58. void cn_del_callback(struct cb_id *id);
  59. /**
  60. * cn_netlink_send_mult - Sends message to the specified groups.
  61. *
  62. * @msg: message header(with attached data).
  63. * @len: Number of @msg to be sent.
  64. * @portid: destination port.
  65. * If non-zero the message will be sent to the given port,
  66. * which should be set to the original sender.
  67. * @group: destination group.
  68. * If @portid and @group is zero, then appropriate group will
  69. * be searched through all registered connector users, and
  70. * message will be delivered to the group which was created
  71. * for user with the same ID as in @msg.
  72. * If @group is not zero, then message will be delivered
  73. * to the specified group.
  74. * @gfp_mask: GFP mask.
  75. *
  76. * It can be safely called from softirq context, but may silently
  77. * fail under strong memory pressure.
  78. *
  79. * If there are no listeners for given group %-ESRCH can be returned.
  80. */
  81. int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 group, gfp_t gfp_mask);
  82. /**
  83. * cn_netlink_send_mult - Sends message to the specified groups.
  84. *
  85. * @msg: message header(with attached data).
  86. * @portid: destination port.
  87. * If non-zero the message will be sent to the given port,
  88. * which should be set to the original sender.
  89. * @group: destination group.
  90. * If @portid and @group is zero, then appropriate group will
  91. * be searched through all registered connector users, and
  92. * message will be delivered to the group which was created
  93. * for user with the same ID as in @msg.
  94. * If @group is not zero, then message will be delivered
  95. * to the specified group.
  96. * @gfp_mask: GFP mask.
  97. *
  98. * It can be safely called from softirq context, but may silently
  99. * fail under strong memory pressure.
  100. *
  101. * If there are no listeners for given group %-ESRCH can be returned.
  102. */
  103. int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 group, gfp_t gfp_mask);
  104. int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name,
  105. struct cb_id *id,
  106. void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
  107. void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id);
  108. void cn_queue_release_callback(struct cn_callback_entry *);
  109. struct cn_queue_dev *cn_queue_alloc_dev(const char *name, struct sock *);
  110. void cn_queue_free_dev(struct cn_queue_dev *dev);
  111. int cn_cb_equal(struct cb_id *, struct cb_id *);
  112. #endif /* __CONNECTOR_H */