xref: /linux/include/rdma/rdma_netlink.h (revision 38716732)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2b2cbae2cSRoland Dreier #ifndef _RDMA_NETLINK_H
3b2cbae2cSRoland Dreier #define _RDMA_NETLINK_H
4b2cbae2cSRoland Dreier 
5b2cbae2cSRoland Dreier 
6b2cbae2cSRoland Dreier #include <linux/netlink.h>
77235aa79SDavid Howells #include <uapi/rdma/rdma_netlink.h>
8b2cbae2cSRoland Dreier 
93250b4dbSLeon Romanovsky struct rdma_nl_cbs {
101830ba21SLeon Romanovsky 	int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
111830ba21SLeon Romanovsky 		    struct netlink_ext_ack *extack);
12b2cbae2cSRoland Dreier 	int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
13e3a2b93dSLeon Romanovsky 	u8 flags;
14e3a2b93dSLeon Romanovsky };
15e3a2b93dSLeon Romanovsky 
16e3a2b93dSLeon Romanovsky enum rdma_nl_flags {
17e3a2b93dSLeon Romanovsky 	/* Require CAP_NET_ADMIN */
18e3a2b93dSLeon Romanovsky 	RDMA_NL_ADMIN_PERM	= 1 << 0,
19b2cbae2cSRoland Dreier };
20b2cbae2cSRoland Dreier 
21e3bf14bdSJason Gunthorpe /* Define this module as providing netlink services for NETLINK_RDMA, with
22e3bf14bdSJason Gunthorpe  * index _index.  Since the client indexes were setup in a uapi header as an
23e3bf14bdSJason Gunthorpe  * enum and we do no want to change that, the user must supply the expanded
24e3bf14bdSJason Gunthorpe  * constant as well and the compiler checks they are the same.
25e3bf14bdSJason Gunthorpe  */
26e3bf14bdSJason Gunthorpe #define MODULE_ALIAS_RDMA_NETLINK(_index, _val)                                \
27e3bf14bdSJason Gunthorpe 	static inline void __chk_##_index(void)                                \
28e3bf14bdSJason Gunthorpe 	{                                                                      \
29e3bf14bdSJason Gunthorpe 		BUILD_BUG_ON(_index != _val);                                  \
30e3bf14bdSJason Gunthorpe 	}                                                                      \
31e3bf14bdSJason Gunthorpe 	MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
32e3bf14bdSJason Gunthorpe 
33b2cbae2cSRoland Dreier /**
34c9901724SLeon Romanovsky  * Register client in RDMA netlink.
35b2cbae2cSRoland Dreier  * @index: Index of the added client
36b2cbae2cSRoland Dreier  * @cb_table: A table for op->callback
37b2cbae2cSRoland Dreier  */
38c9901724SLeon Romanovsky void rdma_nl_register(unsigned int index,
393250b4dbSLeon Romanovsky 		      const struct rdma_nl_cbs cb_table[]);
40b2cbae2cSRoland Dreier 
41b2cbae2cSRoland Dreier /**
42b2cbae2cSRoland Dreier  * Remove a client from IB netlink.
43b2cbae2cSRoland Dreier  * @index: Index of the removed IB client.
44b2cbae2cSRoland Dreier  */
45c9901724SLeon Romanovsky void rdma_nl_unregister(unsigned int index);
46b2cbae2cSRoland Dreier 
47b2cbae2cSRoland Dreier /**
48b2cbae2cSRoland Dreier  * Put a new message in a supplied skb.
49b2cbae2cSRoland Dreier  * @skb: The netlink skb.
50b2cbae2cSRoland Dreier  * @nlh: Pointer to put the header of the new netlink message.
51b2cbae2cSRoland Dreier  * @seq: The message sequence number.
52b2cbae2cSRoland Dreier  * @len: The requested message length to allocate.
53b2cbae2cSRoland Dreier  * @client: Calling IB netlink client.
54b2cbae2cSRoland Dreier  * @op: message content op.
55b2cbae2cSRoland Dreier  * Returns the allocated buffer on success and NULL on failure.
56b2cbae2cSRoland Dreier  */
57b2cbae2cSRoland Dreier void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
5830dc5e63STatyana Nikolova 		   int len, int client, int op, int flags);
59b2cbae2cSRoland Dreier /**
60b2cbae2cSRoland Dreier  * Put a new attribute in a supplied skb.
61b2cbae2cSRoland Dreier  * @skb: The netlink skb.
62b2cbae2cSRoland Dreier  * @nlh: Header of the netlink message to append the attribute to.
63b2cbae2cSRoland Dreier  * @len: The length of the attribute data.
64b2cbae2cSRoland Dreier  * @data: The attribute data to put.
65b2cbae2cSRoland Dreier  * @type: The attribute type.
66b2cbae2cSRoland Dreier  * Returns the 0 and a negative error code on failure.
67b2cbae2cSRoland Dreier  */
68b2cbae2cSRoland Dreier int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
69b2cbae2cSRoland Dreier 		  int len, void *data, int type);
70b2cbae2cSRoland Dreier 
7130dc5e63STatyana Nikolova /**
7230dc5e63STatyana Nikolova  * Send the supplied skb to a specific userspace PID.
7330dc5e63STatyana Nikolova  * @skb: The netlink skb
7430dc5e63STatyana Nikolova  * @pid: Userspace netlink process ID
7530dc5e63STatyana Nikolova  * Returns 0 on success or a negative error code.
7630dc5e63STatyana Nikolova  */
77f00e6463SLeon Romanovsky int rdma_nl_unicast(struct sk_buff *skb, u32 pid);
7830dc5e63STatyana Nikolova 
7930dc5e63STatyana Nikolova /**
809047811bSIsmail, Mustafa  * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
819047811bSIsmail, Mustafa  * @skb: The netlink skb
829047811bSIsmail, Mustafa  * @pid: Userspace netlink process ID
839047811bSIsmail, Mustafa  * Returns 0 on success or a negative error code.
849047811bSIsmail, Mustafa  */
85f00e6463SLeon Romanovsky int rdma_nl_unicast_wait(struct sk_buff *skb, __u32 pid);
869047811bSIsmail, Mustafa 
879047811bSIsmail, Mustafa /**
8830dc5e63STatyana Nikolova  * Send the supplied skb to a netlink group.
8930dc5e63STatyana Nikolova  * @skb: The netlink skb
9030dc5e63STatyana Nikolova  * @group: Netlink group ID
9130dc5e63STatyana Nikolova  * @flags: allocation flags
9230dc5e63STatyana Nikolova  * Returns 0 on success or a negative error code.
9330dc5e63STatyana Nikolova  */
944d7f693aSLeon Romanovsky int rdma_nl_multicast(struct sk_buff *skb, unsigned int group, gfp_t flags);
9530dc5e63STatyana Nikolova 
96ff61c425SLeon Romanovsky /**
97ff61c425SLeon Romanovsky  * Check if there are any listeners to the netlink group
98ff61c425SLeon Romanovsky  * @group: the netlink group ID
99*38716732SLeon Romanovsky  * Returns true on success or false if no listeners.
100ff61c425SLeon Romanovsky  */
101*38716732SLeon Romanovsky bool rdma_nl_chk_listeners(unsigned int group);
102b2cbae2cSRoland Dreier #endif /* _RDMA_NETLINK_H */
103