/* * Sends mult (multiple) cn_msg at a time. * * msg->seq and msg->ack are used to determine message genealogy. * When someone sends message it puts there locally unique sequence * and random acknowledge numbers. Sequence number may be copied into * nlmsghdr->nlmsg_seq too. * * Sequence number is incremented with each message to be sent. * * If we expect a reply to our message then the sequence number in * received message MUST be the same as in original message, and * acknowledge number MUST be the same + 1. * * If we receive a message and its sequence number is not equal to the * one we are expecting then it is a new message. * * If we receive a message and its sequence number is the same as one * we are expecting but it's acknowledgement number is not equal to * the acknowledgement number in the original message + 1, then it is * a new message. * * If msg->len != len, then additional cn_msg messages are expected following * the first msg. * * The message is sent to, the portid if given, the group if given, both if * both, or if both are zero then the group is looked up and sent there.
*/ int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
gfp_t gfp_mask, netlink_filter_fn filter, void *filter_data)
{ struct cn_callback_entry *__cbq; unsignedint size; struct sk_buff *skb; struct nlmsghdr *nlh; struct cn_msg *data; struct cn_dev *dev = &cdev;
u32 group = 0; int found = 0;
if (portid || __group) {
group = __group;
} else {
spin_lock_bh(&dev->cbdev->queue_lock);
list_for_each_entry(__cbq, &dev->cbdev->queue_list,
callback_entry) { if (cn_cb_equal(&__cbq->id.id, &msg->id)) {
found = 1;
group = __cbq->group; break;
}
}
spin_unlock_bh(&dev->cbdev->queue_lock);
if (!found) return -ENODEV;
}
if (!portid && !netlink_has_listeners(dev->nls, group)) return -ESRCH;
size = sizeof(*msg) + len;
skb = nlmsg_new(size, gfp_mask); if (!skb) return -ENOMEM;
/* same as cn_netlink_send_mult except msg->len is used for len */ int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
gfp_t gfp_mask)
{ return cn_netlink_send_mult(msg, msg->len, portid, __group, gfp_mask,
NULL, NULL);
}
EXPORT_SYMBOL_GPL(cn_netlink_send);
/* * Callback helper - queues work and setup destructor for given data.
*/ staticint cn_call_callback(struct sk_buff *skb)
{ struct nlmsghdr *nlh; struct cn_callback_entry *i, *cbq = NULL; struct cn_dev *dev = &cdev; struct cn_msg *msg = nlmsg_data(nlmsg_hdr(skb)); struct netlink_skb_parms *nsp = &NETLINK_CB(skb); int err = -ENODEV;
/* verify msg->len is within skb */
nlh = nlmsg_hdr(skb); if (nlh->nlmsg_len < NLMSG_HDRLEN + sizeof(struct cn_msg) + msg->len) return -EINVAL;
/* * Allow non-root access for NETLINK_CONNECTOR family having CN_IDX_PROC * multicast group.
*/ staticint cn_bind(struct net *net, int group)
{ unsignedlong groups = (unsignedlong) group;
if (ns_capable(net->user_ns, CAP_NET_ADMIN)) return 0;
/* * Main netlink receiving function. * * It checks skb, netlink header and msg sizes, and calls callback helper.
*/ staticvoid cn_rx_skb(struct sk_buff *skb)
{ struct nlmsghdr *nlh; int len, err;
if (skb->len >= NLMSG_HDRLEN) {
nlh = nlmsg_hdr(skb);
len = nlmsg_len(nlh);
if (len < (int)sizeof(struct cn_msg) ||
skb->len < nlh->nlmsg_len ||
len > CONNECTOR_MAX_MSG_SIZE) return;
err = cn_call_callback(skb_get(skb)); if (err < 0)
kfree_skb(skb);
}
}
/* * Callback add routing - adds callback with given ID and name. * If there is registered callback with the same ID it will not be added. * * May sleep.
*/ int cn_add_callback(conststruct cb_id *id, constchar *name, void (*callback)(struct cn_msg *, struct netlink_skb_parms *))
{ struct cn_dev *dev = &cdev;
/* * Callback remove routing - removes callback * with given ID. * If there is no registered callback with given * ID nothing happens. * * May sleep while waiting for reference counter to become zero.
*/ void cn_del_callback(conststruct cb_id *id)
{ struct cn_dev *dev = &cdev;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.