rdma_netlink.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _RDMA_NETLINK_H
  3. #define _RDMA_NETLINK_H
  4. #include <linux/netlink.h>
  5. #include <uapi/rdma/rdma_netlink.h>
  6. struct rdma_nl_cbs {
  7. int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
  8. struct netlink_ext_ack *extack);
  9. int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
  10. u8 flags;
  11. };
  12. enum rdma_nl_flags {
  13. /* Require CAP_NET_ADMIN */
  14. RDMA_NL_ADMIN_PERM = 1 << 0,
  15. };
  16. /* Define this module as providing netlink services for NETLINK_RDMA, with
  17. * index _index. Since the client indexes were setup in a uapi header as an
  18. * enum and we do no want to change that, the user must supply the expanded
  19. * constant as well and the compiler checks they are the same.
  20. */
  21. #define MODULE_ALIAS_RDMA_NETLINK(_index, _val) \
  22. static inline void __chk_##_index(void) \
  23. { \
  24. BUILD_BUG_ON(_index != _val); \
  25. } \
  26. MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
  27. /**
  28. * Register client in RDMA netlink.
  29. * @index: Index of the added client
  30. * @cb_table: A table for op->callback
  31. */
  32. void rdma_nl_register(unsigned int index,
  33. const struct rdma_nl_cbs cb_table[]);
  34. /**
  35. * Remove a client from IB netlink.
  36. * @index: Index of the removed IB client.
  37. */
  38. void rdma_nl_unregister(unsigned int index);
  39. /**
  40. * Put a new message in a supplied skb.
  41. * @skb: The netlink skb.
  42. * @nlh: Pointer to put the header of the new netlink message.
  43. * @seq: The message sequence number.
  44. * @len: The requested message length to allocate.
  45. * @client: Calling IB netlink client.
  46. * @op: message content op.
  47. * Returns the allocated buffer on success and NULL on failure.
  48. */
  49. void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
  50. int len, int client, int op, int flags);
  51. /**
  52. * Put a new attribute in a supplied skb.
  53. * @skb: The netlink skb.
  54. * @nlh: Header of the netlink message to append the attribute to.
  55. * @len: The length of the attribute data.
  56. * @data: The attribute data to put.
  57. * @type: The attribute type.
  58. * Returns the 0 and a negative error code on failure.
  59. */
  60. int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
  61. int len, void *data, int type);
  62. /**
  63. * Send the supplied skb to a specific userspace PID.
  64. * @skb: The netlink skb
  65. * @pid: Userspace netlink process ID
  66. * Returns 0 on success or a negative error code.
  67. */
  68. int rdma_nl_unicast(struct sk_buff *skb, u32 pid);
  69. /**
  70. * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
  71. * @skb: The netlink skb
  72. * @pid: Userspace netlink process ID
  73. * Returns 0 on success or a negative error code.
  74. */
  75. int rdma_nl_unicast_wait(struct sk_buff *skb, __u32 pid);
  76. /**
  77. * Send the supplied skb to a netlink group.
  78. * @skb: The netlink skb
  79. * @group: Netlink group ID
  80. * @flags: allocation flags
  81. * Returns 0 on success or a negative error code.
  82. */
  83. int rdma_nl_multicast(struct sk_buff *skb, unsigned int group, gfp_t flags);
  84. /**
  85. * Check if there are any listeners to the netlink group
  86. * @group: the netlink group ID
  87. * Returns 0 on success or a negative for no listeners.
  88. */
  89. int rdma_nl_chk_listeners(unsigned int group);
  90. #endif /* _RDMA_NETLINK_H */