blob: 6b6c7396a584521aba86bcf2dd1ed0344f98ed76 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -07002/*
3 * connector.h
4 *
Evgeniy Polyakova8018762011-08-25 15:59:06 -07005 * 2004-2005 Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -07006 * All rights reserved.
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -07007 */
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -07008#ifndef __CONNECTOR_H
9#define __CONNECTOR_H
10
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070011
Elena Reshetovae65f7ee2017-10-20 10:23:49 +030012#include <linux/refcount.h>
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070013
14#include <linux/list.h>
15#include <linux/workqueue.h>
16
17#include <net/sock.h>
David Howells607ca462012-10-13 10:46:48 +010018#include <uapi/linux/connector.h>
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070019
20#define CN_CBQ_NAMELEN 32
21
22struct cn_queue_dev {
23 atomic_t refcnt;
24 unsigned char name[CN_CBQ_NAMELEN];
25
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070026 struct list_head queue_list;
27 spinlock_t queue_lock;
28
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070029 struct sock *nls;
30};
31
Evgeniy Polyakovacd042b2005-09-26 15:06:50 -070032struct cn_callback_id {
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070033 unsigned char name[CN_CBQ_NAMELEN];
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070034 struct cb_id id;
Evgeniy Polyakovacd042b2005-09-26 15:06:50 -070035};
36
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070037struct cn_callback_entry {
38 struct list_head callback_entry;
Elena Reshetovae65f7ee2017-10-20 10:23:49 +030039 refcount_t refcnt;
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070040 struct cn_queue_dev *pdev;
41
Evgeniy Polyakovacd042b2005-09-26 15:06:50 -070042 struct cn_callback_id id;
Patrick McHardy04f482f2011-03-28 08:39:36 +000043 void (*callback) (struct cn_msg *, struct netlink_skb_parms *);
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070044
Li Zefan6e328142008-01-04 01:59:42 -080045 u32 seq, group;
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070046};
47
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070048struct cn_dev {
49 struct cb_id id;
50
51 u32 seq, groups;
52 struct sock *nls;
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -070053 void (*input) (struct sk_buff *skb);
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -070054
55 struct cn_queue_dev *cbdev;
56};
57
Mauro Carvalho Chehab720594f2019-04-13 22:54:53 -030058/**
59 * cn_add_callback() - Registers new callback with connector core.
60 *
61 * @id: unique connector's user identifier.
62 * It must be registered in connector.h for legal
63 * in-kernel users.
64 * @name: connector's callback symbolic name.
65 * @callback: connector's callback.
66 * parameters are %cn_msg and the sender's credentials
67 */
Joe Perches008536e2011-02-19 15:45:29 -080068int cn_add_callback(struct cb_id *id, const char *name,
69 void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
Mauro Carvalho Chehab720594f2019-04-13 22:54:53 -030070/**
71 * cn_del_callback() - Unregisters new callback with connector core.
72 *
73 * @id: unique connector's user identifier.
74 */
75void cn_del_callback(struct cb_id *id);
76
77
78/**
79 * cn_netlink_send_mult - Sends message to the specified groups.
80 *
81 * @msg: message header(with attached data).
82 * @len: Number of @msg to be sent.
83 * @portid: destination port.
84 * If non-zero the message will be sent to the given port,
85 * which should be set to the original sender.
86 * @group: destination group.
87 * If @portid and @group is zero, then appropriate group will
88 * be searched through all registered connector users, and
89 * message will be delivered to the group which was created
90 * for user with the same ID as in @msg.
91 * If @group is not zero, then message will be delivered
92 * to the specified group.
93 * @gfp_mask: GFP mask.
94 *
95 * It can be safely called from softirq context, but may silently
96 * fail under strong memory pressure.
97 *
98 * If there are no listeners for given group %-ESRCH can be returned.
99 */
David Fries34470e02014-04-08 22:37:08 -0500100int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 group, gfp_t gfp_mask);
Mauro Carvalho Chehab720594f2019-04-13 22:54:53 -0300101
102/**
103 * cn_netlink_send_mult - Sends message to the specified groups.
104 *
105 * @msg: message header(with attached data).
106 * @portid: destination port.
107 * If non-zero the message will be sent to the given port,
108 * which should be set to the original sender.
109 * @group: destination group.
110 * If @portid and @group is zero, then appropriate group will
111 * be searched through all registered connector users, and
112 * message will be delivered to the group which was created
113 * for user with the same ID as in @msg.
114 * If @group is not zero, then message will be delivered
115 * to the specified group.
116 * @gfp_mask: GFP mask.
117 *
118 * It can be safely called from softirq context, but may silently
119 * fail under strong memory pressure.
120 *
121 * If there are no listeners for given group %-ESRCH can be returned.
122 */
David Friesac8f7332014-01-15 22:29:19 -0600123int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 group, gfp_t gfp_mask);
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -0700124
Joe Perches008536e2011-02-19 15:45:29 -0800125int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name,
126 struct cb_id *id,
127 void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -0700128void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id);
Patrick McHardy04f482f2011-03-28 08:39:36 +0000129void cn_queue_release_callback(struct cn_callback_entry *);
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -0700130
Joe Perches008536e2011-02-19 15:45:29 -0800131struct cn_queue_dev *cn_queue_alloc_dev(const char *name, struct sock *);
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -0700132void cn_queue_free_dev(struct cn_queue_dev *dev);
133
134int cn_cb_equal(struct cb_id *, struct cb_id *);
135
Evgeniy Polyakov7672d0b2005-09-11 19:15:07 -0700136#endif /* __CONNECTOR_H */