Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  connector.h
0004  * 
0005  * 2004-2005 Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
0006  * All rights reserved.
0007  */
0008 #ifndef __CONNECTOR_H
0009 #define __CONNECTOR_H
0010 
0011 
0012 #include <linux/refcount.h>
0013 
0014 #include <linux/list.h>
0015 #include <linux/workqueue.h>
0016 
0017 #include <net/sock.h>
0018 #include <uapi/linux/connector.h>
0019 
0020 #define CN_CBQ_NAMELEN      32
0021 
0022 struct cn_queue_dev {
0023     atomic_t refcnt;
0024     unsigned char name[CN_CBQ_NAMELEN];
0025 
0026     struct list_head queue_list;
0027     spinlock_t queue_lock;
0028 
0029     struct sock *nls;
0030 };
0031 
0032 struct cn_callback_id {
0033     unsigned char name[CN_CBQ_NAMELEN];
0034     struct cb_id id;
0035 };
0036 
0037 struct cn_callback_entry {
0038     struct list_head callback_entry;
0039     refcount_t refcnt;
0040     struct cn_queue_dev *pdev;
0041 
0042     struct cn_callback_id id;
0043     void (*callback) (struct cn_msg *, struct netlink_skb_parms *);
0044 
0045     u32 seq, group;
0046 };
0047 
0048 struct cn_dev {
0049     struct cb_id id;
0050 
0051     u32 seq, groups;
0052     struct sock *nls;
0053 
0054     struct cn_queue_dev *cbdev;
0055 };
0056 
0057 /**
0058  * cn_add_callback() - Registers new callback with connector core.
0059  *
0060  * @id:     unique connector's user identifier.
0061  *      It must be registered in connector.h for legal
0062  *      in-kernel users.
0063  * @name:   connector's callback symbolic name.
0064  * @callback:   connector's callback.
0065  *      parameters are %cn_msg and the sender's credentials
0066  */
0067 int cn_add_callback(const struct cb_id *id, const char *name,
0068             void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
0069 /**
0070  * cn_del_callback() - Unregisters new callback with connector core.
0071  *
0072  * @id:     unique connector's user identifier.
0073  */
0074 void cn_del_callback(const struct cb_id *id);
0075 
0076 
0077 /**
0078  * cn_netlink_send_mult - Sends message to the specified groups.
0079  *
0080  * @msg:    message header(with attached data).
0081  * @len:    Number of @msg to be sent.
0082  * @portid: destination port.
0083  *      If non-zero the message will be sent to the given port,
0084  *      which should be set to the original sender.
0085  * @group:  destination group.
0086  *      If @portid and @group is zero, then appropriate group will
0087  *      be searched through all registered connector users, and
0088  *      message will be delivered to the group which was created
0089  *      for user with the same ID as in @msg.
0090  *      If @group is not zero, then message will be delivered
0091  *      to the specified group.
0092  * @gfp_mask:   GFP mask.
0093  *
0094  * It can be safely called from softirq context, but may silently
0095  * fail under strong memory pressure.
0096  *
0097  * If there are no listeners for given group %-ESRCH can be returned.
0098  */
0099 int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 group, gfp_t gfp_mask);
0100 
0101 /**
0102  * cn_netlink_send - Sends message to the specified groups.
0103  *
0104  * @msg:    message header(with attached data).
0105  * @portid: destination port.
0106  *      If non-zero the message will be sent to the given port,
0107  *      which should be set to the original sender.
0108  * @group:  destination group.
0109  *      If @portid and @group is zero, then appropriate group will
0110  *      be searched through all registered connector users, and
0111  *      message will be delivered to the group which was created
0112  *      for user with the same ID as in @msg.
0113  *      If @group is not zero, then message will be delivered
0114  *      to the specified group.
0115  * @gfp_mask:   GFP mask.
0116  *
0117  * It can be safely called from softirq context, but may silently
0118  * fail under strong memory pressure.
0119  *
0120  * If there are no listeners for given group %-ESRCH can be returned.
0121  */
0122 int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 group, gfp_t gfp_mask);
0123 
0124 int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name,
0125               const struct cb_id *id,
0126               void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
0127 void cn_queue_del_callback(struct cn_queue_dev *dev, const struct cb_id *id);
0128 void cn_queue_release_callback(struct cn_callback_entry *);
0129 
0130 struct cn_queue_dev *cn_queue_alloc_dev(const char *name, struct sock *);
0131 void cn_queue_free_dev(struct cn_queue_dev *dev);
0132 
0133 int cn_cb_equal(const struct cb_id *, const struct cb_id *);
0134 
0135 #endif              /* __CONNECTOR_H */