rdma_netlink.h 3.2 KB

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