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