^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * connector.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * 2004+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/connector.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) MODULE_DESCRIPTION("Generic userspace <-> kernelspace connector.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_CONNECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static struct cn_dev cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int cn_already_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Sends mult (multiple) cn_msg at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * msg->seq and msg->ack are used to determine message genealogy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * When someone sends message it puts there locally unique sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * and random acknowledge numbers. Sequence number may be copied into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * nlmsghdr->nlmsg_seq too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Sequence number is incremented with each message to be sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * If we expect a reply to our message then the sequence number in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * received message MUST be the same as in original message, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * acknowledge number MUST be the same + 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * If we receive a message and its sequence number is not equal to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * one we are expecting then it is a new message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * If we receive a message and its sequence number is the same as one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * we are expecting but it's acknowledgement number is not equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * the acknowledgement number in the original message + 1, then it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * a new message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * If msg->len != len, then additional cn_msg messages are expected following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * the first msg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * The message is sent to, the portid if given, the group if given, both if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * both, or if both are zero then the group is looked up and sent there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct cn_callback_entry *__cbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct cn_msg *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct cn_dev *dev = &cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u32 group = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (portid || __group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) group = __group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) spin_lock_bh(&dev->cbdev->queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) list_for_each_entry(__cbq, &dev->cbdev->queue_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) callback_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (cn_cb_equal(&__cbq->id.id, &msg->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) group = __cbq->group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spin_unlock_bh(&dev->cbdev->queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (!found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (!portid && !netlink_has_listeners(dev->nls, group))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) size = sizeof(*msg) + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) skb = nlmsg_new(size, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) nlh = nlmsg_put(skb, 0, msg->seq, NLMSG_DONE, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (!nlh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) data = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) memcpy(data, msg, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) NETLINK_CB(skb).dst_group = group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return netlink_broadcast(dev->nls, skb, portid, group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return netlink_unicast(dev->nls, skb, portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) !gfpflags_allow_blocking(gfp_mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) EXPORT_SYMBOL_GPL(cn_netlink_send_mult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* same as cn_netlink_send_mult except msg->len is used for len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return cn_netlink_send_mult(msg, msg->len, portid, __group, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) EXPORT_SYMBOL_GPL(cn_netlink_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * Callback helper - queues work and setup destructor for given data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int cn_call_callback(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct cn_callback_entry *i, *cbq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct cn_dev *dev = &cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct cn_msg *msg = nlmsg_data(nlmsg_hdr(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct netlink_skb_parms *nsp = &NETLINK_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* verify msg->len is within skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) nlh = nlmsg_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (nlh->nlmsg_len < NLMSG_HDRLEN + sizeof(struct cn_msg) + msg->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) spin_lock_bh(&dev->cbdev->queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) list_for_each_entry(i, &dev->cbdev->queue_list, callback_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (cn_cb_equal(&i->id.id, &msg->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) refcount_inc(&i->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) cbq = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) spin_unlock_bh(&dev->cbdev->queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (cbq != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) cbq->callback(msg, nsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) cn_queue_release_callback(cbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * Main netlink receiving function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * It checks skb, netlink header and msg sizes, and calls callback helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static void cn_rx_skb(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int len, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (skb->len >= NLMSG_HDRLEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) nlh = nlmsg_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) len = nlmsg_len(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (len < (int)sizeof(struct cn_msg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) skb->len < nlh->nlmsg_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) len > CONNECTOR_MAX_MSG_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) err = cn_call_callback(skb_get(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * Callback add routing - adds callback with given ID and name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * If there is registered callback with the same ID it will not be added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * May sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int cn_add_callback(struct cb_id *id, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void (*callback)(struct cn_msg *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct netlink_skb_parms *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct cn_dev *dev = &cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (!cn_already_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return cn_queue_add_callback(dev->cbdev, name, id, callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) EXPORT_SYMBOL_GPL(cn_add_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * Callback remove routing - removes callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * with given ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * If there is no registered callback with given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * ID nothing happens.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * May sleep while waiting for reference counter to become zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) void cn_del_callback(struct cb_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct cn_dev *dev = &cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) cn_queue_del_callback(dev->cbdev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) EXPORT_SYMBOL_GPL(cn_del_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int __maybe_unused cn_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct cn_queue_dev *dev = cdev.cbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct cn_callback_entry *cbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) seq_printf(m, "Name ID\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) spin_lock_bh(&dev->queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) list_for_each_entry(cbq, &dev->queue_list, callback_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) seq_printf(m, "%-15s %u:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) cbq->id.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) cbq->id.id.idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) cbq->id.id.val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) spin_unlock_bh(&dev->queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int cn_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct cn_dev *dev = &cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct netlink_kernel_cfg cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .groups = CN_NETLINK_USERS + 0xf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .input = cn_rx_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) dev->nls = netlink_kernel_create(&init_net, NETLINK_CONNECTOR, &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!dev->nls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dev->cbdev = cn_queue_alloc_dev("cqueue", dev->nls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!dev->cbdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) netlink_kernel_release(dev->nls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) cn_already_initialized = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) proc_create_single("connector", S_IRUGO, init_net.proc_net, cn_proc_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static void cn_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct cn_dev *dev = &cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) cn_already_initialized = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) remove_proc_entry("connector", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) cn_queue_free_dev(dev->cbdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) netlink_kernel_release(dev->nls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) subsys_initcall(cn_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) module_exit(cn_fini);