static int send_data(struct sk_buff *skb) { struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); void *data = genlmsg_data(genlhdr); genlmsg_end(skb, data); return genlmsg_unicast(&init_net, skb, listener_nlportid); }
int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info) { struct nlmsghdr *nlh = nlmsg_hdr(msg); void *hdr = genlmsg_data(nlmsg_data(nlh)); if (genlmsg_end(msg, hdr) < 0) goto out; return genlmsg_reply(msg, info); out: nlmsg_free(msg); return -ENOBUFS; }
int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group) { struct nlmsghdr *nlh = nlmsg_hdr(msg); void *hdr = genlmsg_data(nlmsg_data(nlh)); if (genlmsg_end(msg, hdr) < 0) goto out; return genlmsg_multicast(&nl802154_family, msg, 0, group, GFP_ATOMIC); out: nlmsg_free(msg); return -ENOBUFS; }
int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info) { /* XXX: nlh is right at the start of msg */ void *hdr = genlmsg_data(NLMSG_DATA(msg->data)); if (genlmsg_end(msg, hdr) < 0) goto out; return genlmsg_reply(msg, info); out: nlmsg_free(msg); return -ENOBUFS; }
int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group) { /* XXX: nlh is right at the start of msg */ void *hdr = genlmsg_data(NLMSG_DATA(msg->data)); if (genlmsg_end(msg, hdr) < 0) goto out; return genlmsg_multicast(msg, 0, group, GFP_ATOMIC); out: nlmsg_free(msg); return -ENOBUFS; }
/* * @pid:用户进行id @data:发送数据缓冲区 @data_len:缓冲区长度 */ static int genlnet_msg_send(int pid, char *data, uint32_t data_len) { char buf[MAX_STR_LEN]; void *msg; int ret; size_t size; struct sk_buff *skb; struct genlmsghdr *genlhdr; void *reply; memcpy(buf, data, data_len); size = nla_total_size(data_len) + nla_total_size(0); skb = genlmsg_new(size, GFP_KERNEL); if (skb == NULL) { printk("%s %d\n", __func__, __LINE__); return -1; } msg = genlmsg_put(skb, 0, 0, &genlnet_family, 0, MSG_CMD_NOTIFY); if (msg == NULL) { printk("%s %d\n", __func__, __LINE__); goto err; } ret = nla_put(skb, MSG_CMD, data_len, data); if (ret < 0) { printk("%s %d, ret = %d\n", __func__, __LINE__, ret); goto err; } genlhdr = nlmsg_data(nlmsg_hdr(skb)); reply = genlmsg_data(genlhdr); ret = genlmsg_end(skb, reply); if (ret < 0) { printk("%s %d, ret = %d\n", __func__, __LINE__, ret); goto err; } ret = genlmsg_unicast(&init_net, skb, pid); if (ret < 0) { printk("%s %d, ret = %d\n", __func__, __LINE__, ret); goto err; } return 0; err: //nlmsg_free(skb); return -1; }
static int send_data(struct sk_buff *skb) { struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); void *data = genlmsg_data(genlhdr); int rv; rv = genlmsg_end(skb, data); if (rv < 0) { nlmsg_free(skb); return rv; } return genlmsg_unicast(&init_net, skb, listener_nlpid); }
static int ieee802154_nl_finish(struct sk_buff *msg) { /* XXX: nlh is right at the start of msg */ void *hdr = genlmsg_data(NLMSG_DATA(msg->data)); if (!genlmsg_end(msg, hdr)) goto out; return genlmsg_multicast(msg, 0, ieee802154_coord_mcgrp.id, GFP_ATOMIC); out: nlmsg_free(msg); return -ENOBUFS; }
/** * Return pointer to user header * @arg gnlh Generic Netlink message header * * Calculates the pointer to the user header based on the pointer to * the Generic Netlink message header. * * @return Pointer to the user header */ void *genlmsg_user_hdr(const struct genlmsghdr *gnlh) { return genlmsg_data(gnlh); }
/** * Get head of attribute data * @arg gnlh generic netlink message header * @arg hdrlen length of family specific header */ struct nlattr *genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen) { return genlmsg_data(gnlh) + NLMSG_ALIGN(hdrlen); }