1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * connector.h 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * 2004-2005 Copyright (c) Evgeniy Polyakov <zbr@ioremap.net> 6*4882a593Smuzhiyun * All rights reserved. 7*4882a593Smuzhiyun */ 8*4882a593Smuzhiyun #ifndef __CONNECTOR_H 9*4882a593Smuzhiyun #define __CONNECTOR_H 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun #include <linux/refcount.h> 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun #include <linux/list.h> 15*4882a593Smuzhiyun #include <linux/workqueue.h> 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun #include <net/sock.h> 18*4882a593Smuzhiyun #include <uapi/linux/connector.h> 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun #define CN_CBQ_NAMELEN 32 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun struct cn_queue_dev { 23*4882a593Smuzhiyun atomic_t refcnt; 24*4882a593Smuzhiyun unsigned char name[CN_CBQ_NAMELEN]; 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun struct list_head queue_list; 27*4882a593Smuzhiyun spinlock_t queue_lock; 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun struct sock *nls; 30*4882a593Smuzhiyun }; 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun struct cn_callback_id { 33*4882a593Smuzhiyun unsigned char name[CN_CBQ_NAMELEN]; 34*4882a593Smuzhiyun struct cb_id id; 35*4882a593Smuzhiyun }; 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun struct cn_callback_entry { 38*4882a593Smuzhiyun struct list_head callback_entry; 39*4882a593Smuzhiyun refcount_t refcnt; 40*4882a593Smuzhiyun struct cn_queue_dev *pdev; 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun struct cn_callback_id id; 43*4882a593Smuzhiyun void (*callback) (struct cn_msg *, struct netlink_skb_parms *); 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun u32 seq, group; 46*4882a593Smuzhiyun }; 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun struct cn_dev { 49*4882a593Smuzhiyun struct cb_id id; 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun u32 seq, groups; 52*4882a593Smuzhiyun struct sock *nls; 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun struct cn_queue_dev *cbdev; 55*4882a593Smuzhiyun }; 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun /** 58*4882a593Smuzhiyun * cn_add_callback() - Registers new callback with connector core. 59*4882a593Smuzhiyun * 60*4882a593Smuzhiyun * @id: unique connector's user identifier. 61*4882a593Smuzhiyun * It must be registered in connector.h for legal 62*4882a593Smuzhiyun * in-kernel users. 63*4882a593Smuzhiyun * @name: connector's callback symbolic name. 64*4882a593Smuzhiyun * @callback: connector's callback. 65*4882a593Smuzhiyun * parameters are %cn_msg and the sender's credentials 66*4882a593Smuzhiyun */ 67*4882a593Smuzhiyun int cn_add_callback(struct cb_id *id, const char *name, 68*4882a593Smuzhiyun void (*callback)(struct cn_msg *, struct netlink_skb_parms *)); 69*4882a593Smuzhiyun /** 70*4882a593Smuzhiyun * cn_del_callback() - Unregisters new callback with connector core. 71*4882a593Smuzhiyun * 72*4882a593Smuzhiyun * @id: unique connector's user identifier. 73*4882a593Smuzhiyun */ 74*4882a593Smuzhiyun void cn_del_callback(struct cb_id *id); 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun /** 78*4882a593Smuzhiyun * cn_netlink_send_mult - Sends message to the specified groups. 79*4882a593Smuzhiyun * 80*4882a593Smuzhiyun * @msg: message header(with attached data). 81*4882a593Smuzhiyun * @len: Number of @msg to be sent. 82*4882a593Smuzhiyun * @portid: destination port. 83*4882a593Smuzhiyun * If non-zero the message will be sent to the given port, 84*4882a593Smuzhiyun * which should be set to the original sender. 85*4882a593Smuzhiyun * @group: destination group. 86*4882a593Smuzhiyun * If @portid and @group is zero, then appropriate group will 87*4882a593Smuzhiyun * be searched through all registered connector users, and 88*4882a593Smuzhiyun * message will be delivered to the group which was created 89*4882a593Smuzhiyun * for user with the same ID as in @msg. 90*4882a593Smuzhiyun * If @group is not zero, then message will be delivered 91*4882a593Smuzhiyun * to the specified group. 92*4882a593Smuzhiyun * @gfp_mask: GFP mask. 93*4882a593Smuzhiyun * 94*4882a593Smuzhiyun * It can be safely called from softirq context, but may silently 95*4882a593Smuzhiyun * fail under strong memory pressure. 96*4882a593Smuzhiyun * 97*4882a593Smuzhiyun * If there are no listeners for given group %-ESRCH can be returned. 98*4882a593Smuzhiyun */ 99*4882a593Smuzhiyun int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 group, gfp_t gfp_mask); 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun /** 102*4882a593Smuzhiyun * cn_netlink_send_mult - Sends message to the specified groups. 103*4882a593Smuzhiyun * 104*4882a593Smuzhiyun * @msg: message header(with attached data). 105*4882a593Smuzhiyun * @portid: destination port. 106*4882a593Smuzhiyun * If non-zero the message will be sent to the given port, 107*4882a593Smuzhiyun * which should be set to the original sender. 108*4882a593Smuzhiyun * @group: destination group. 109*4882a593Smuzhiyun * If @portid and @group is zero, then appropriate group will 110*4882a593Smuzhiyun * be searched through all registered connector users, and 111*4882a593Smuzhiyun * message will be delivered to the group which was created 112*4882a593Smuzhiyun * for user with the same ID as in @msg. 113*4882a593Smuzhiyun * If @group is not zero, then message will be delivered 114*4882a593Smuzhiyun * to the specified group. 115*4882a593Smuzhiyun * @gfp_mask: GFP mask. 116*4882a593Smuzhiyun * 117*4882a593Smuzhiyun * It can be safely called from softirq context, but may silently 118*4882a593Smuzhiyun * fail under strong memory pressure. 119*4882a593Smuzhiyun * 120*4882a593Smuzhiyun * If there are no listeners for given group %-ESRCH can be returned. 121*4882a593Smuzhiyun */ 122*4882a593Smuzhiyun int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 group, gfp_t gfp_mask); 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name, 125*4882a593Smuzhiyun struct cb_id *id, 126*4882a593Smuzhiyun void (*callback)(struct cn_msg *, struct netlink_skb_parms *)); 127*4882a593Smuzhiyun void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id); 128*4882a593Smuzhiyun void cn_queue_release_callback(struct cn_callback_entry *); 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun struct cn_queue_dev *cn_queue_alloc_dev(const char *name, struct sock *); 131*4882a593Smuzhiyun void cn_queue_free_dev(struct cn_queue_dev *dev); 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun int cn_cb_equal(struct cb_id *, struct cb_id *); 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun #endif /* __CONNECTOR_H */ 136