示例#1
0
int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
{
	struct sk_buff *msg;
	void *hdr;

	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
			  NFC_EVENT_TARGET_LOST);
	if (!hdr)
		goto free_msg;

	if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
	    nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
		goto nla_put_failure;

	genlmsg_end(msg, hdr);

	genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);

	return 0;

nla_put_failure:
	genlmsg_cancel(msg, hdr);
free_msg:
	nlmsg_free(msg);
	return -EMSGSIZE;
}
示例#2
0
int nfc_genl_targets_found(struct nfc_dev *dev)
{
	struct sk_buff *msg;
	void *hdr;

	dev->genl_data.poll_req_portid = 0;

	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
	if (!msg)
		return -ENOMEM;

	hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
			  NFC_EVENT_TARGETS_FOUND);
	if (!hdr)
		goto free_msg;

	if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
		goto nla_put_failure;

	genlmsg_end(msg, hdr);

	return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);

nla_put_failure:
	genlmsg_cancel(msg, hdr);
free_msg:
	nlmsg_free(msg);
	return -EMSGSIZE;
}
void br_ifinfo_notify(int event, struct net_bridge_port *port)
{
	struct net *net = dev_net(port->dev);
	struct sk_buff *skb;
	int err = -ENOBUFS;

	br_debug(port->br, "port %u(%s) event %d\n",
		 (unsigned)port->port_no, port->dev->name, event);

	skb = nlmsg_new(br_nlmsg_size(), GFP_ATOMIC);
	if (skb == NULL)
		goto errout;

	err = br_fill_ifinfo(skb, port, 0, 0, event, 0);
	if (err < 0) {
		
		WARN_ON(err == -EMSGSIZE);
		kfree_skb(skb);
		goto errout;
	}
	rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
	return;
errout:
	if (err < 0)
		rtnl_set_sk_err(net, RTNLGRP_LINK, err);
}
示例#4
0
static int deth_netlink_do_broadcast_addresses(struct sock* nl_sk, u32 index)
{
    struct sk_buff* skb = nlmsg_new(sizeof(u32), 0);
    struct nlmsghdr* nlh;

    if (!skb)
    {
        printk(KERN_ERR "Failed to allocate new skb\n");

        return -ENOBUFS;
    }

    nlh = nlmsg_put(skb, 0, 0, MULTICAST_ADDRESS_CHANGE, sizeof(u32), 0);

    if (nlh == NULL)
    {
        nlmsg_free(skb);
        
        return -EMSGSIZE;
    }

    memcpy(nlmsg_data(nlh), &index, sizeof(u32));

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
	NETLINK_CB(skb).portid = 0;
#else
    NETLINK_CB(skb).pid = 0;
#endif

    NETLINK_CB(skb).dst_group = NETLINK_DETH_GROUP;

    return netlink_broadcast(nl_sk, skb, 0, NETLINK_DETH_GROUP, GFP_KERNEL);
}
示例#5
0
a_status_t
acfg_net_indicate_event(struct net_device *dev, acfg_os_event_t    *event, 
							int send_iwevent)
{
    struct sk_buff *skb;
    int err;
    __acfg_event_t   fn;
#if LINUX_VERSION_CODE >= KERNEL_VERSION (2,6,24)
    if (!net_eq(dev_net(dev), &init_net))
        return A_STATUS_FAILED  ;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION (2,6,24)
    skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
#else
    skb = nlmsg_new(NLMSG_SPACE(ACFG_MAX_PAYLOAD));
#endif
    if (!skb)
        return A_STATUS_ENOMEM ;

    err = ev_fill_info(skb, dev, RTM_NEWLINK, event);
    if (err < 0) {
        kfree_skb(skb);
        return A_STATUS_FAILED ;
    }

    NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
    NETLINK_CB(skb).pid = 0;  /* from kernel */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)    
    NETLINK_CB(skb).dst_pid = 0;  /* multicast */
#endif


    /* Send event to acfg */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)   
  	err = nlmsg_multicast(acfg_ev_sock, skb, 0, RTNLGRP_NOTIFY);
#else
    rtnl_notify(skb, &init_net, 0, RTNLGRP_NOTIFY, NULL, GFP_ATOMIC);
#endif
	if (send_iwevent) {
    /* Send iw event */
    fn = iw_events[event->id];
		if (fn != NULL) {
    fn(dev, &event->data);
		}
	}
    return A_STATUS_OK ;
}
示例#6
0
static void kr_nl_send(int pid, int seq, int cmd, void* data, size_t len)
{
    struct sk_buff* skb = nlmsg_new(len, GFP_KERNEL);
    struct nlmsghdr* nlh = nlmsg_put(skb, pid, seq, cmd, len, 0);
    char* dest = nlmsg_data(nlh);
    memcpy(dest, data, len);
    nlmsg_unicast(kr_nlsock, skb, pid);
}
static void nl_recv_msg_udp(struct sk_buff *skb)
{
        struct nlmsghdr *nlh;
        struct sk_buff *skb_out;
        int msg_size;
        char *msg="Hello from kernel";
        int res;
      printk(KERN_INFO "Entering: %s\n", __FUNCTION__);
       msg_size=strlen(msg);
       nlh=(struct nlmsghdr*)skb->data;
        if (!gotPid) {
                pid = nlh->nlmsg_pid; /*pid of sending process */
                gotPid=true;
                gotUserOrNotUdp(true);
                skb_out = nlmsg_new(msg_size,0);
                printk(KERN_INFO "Netlink received msg payload: %s\n",(char*)nlmsg_data(nlh));
            if(!skb_out)
                {
                        printk(KERN_ERR "Failed to allocate new skb\n");
                        return;
                }
                nlh = nlmsg_put(skb_out,0,0,NLMSG_DONE,msg_size,0);
                NETLINK_CB(skb_out).dst_group = 0;
                strncpy(nlmsg_data(nlh),msg,msg_size);
            res=nlmsg_unicast(nl_sk_udp,skb_out,pid);
            if (res<0){
                        printk(KERN_INFO "Error while sending back to user\n");
                        gotPid=false;
                        gotUserOrNotUdp(false);
                } else {
                }
        }else {
                printk(KERN_INFO "Netlink received msg payload: %s\n",(char*)nlmsg_data(nlh));
	   skb_out = nlmsg_new(msg_size,0);
            if(!skb_out)
                {
                        printk(KERN_ERR "Failed to allocate new skb\n");
                        return;
                } 
                if (((char*)nlmsg_data(nlh))[0] == 'y'){
                                letItResumeUdp(false);
                }else{
                        letItResumeUdp(true);
                }
        }
}
示例#8
0
static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
{
	struct ifinfomsg *ifm;
	struct nlattr *tb[IFLA_MAX+1];
	struct net_device *dev = NULL;
	struct sk_buff *nskb;
	char *iw_buf = NULL, *iw = NULL;
	int iw_buf_len = 0;
	int err;

	err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
	if (err < 0)
		return err;

	ifm = nlmsg_data(nlh);
	if (ifm->ifi_index >= 0) {
		dev = dev_get_by_index(ifm->ifi_index);
		if (dev == NULL)
			return -ENODEV;
	} else
		return -EINVAL;


#ifdef CONFIG_NET_WIRELESS_RTNETLINK
	if (tb[IFLA_WIRELESS]) {
		/* Call Wireless Extensions. We need to know the size before
		 * we can alloc. Various stuff checked in there... */
		err = wireless_rtnetlink_get(dev, nla_data(tb[IFLA_WIRELESS]),
					     nla_len(tb[IFLA_WIRELESS]),
					     &iw_buf, &iw_buf_len);
		if (err < 0)
			goto errout;

		iw += IW_EV_POINT_OFF;
	}
#endif	/* CONFIG_NET_WIRELESS_RTNETLINK */

	nskb = nlmsg_new(if_nlmsg_size(iw_buf_len), GFP_KERNEL);
	if (nskb == NULL) {
		err = -ENOBUFS;
		goto errout;
	}

	err = rtnl_fill_ifinfo(nskb, dev, iw, iw_buf_len, RTM_NEWLINK,
			       NETLINK_CB(skb).pid, nlh->nlmsg_seq, 0, 0);
	if (err < 0) {
		/* -EMSGSIZE implies BUG in if_nlmsg_size */
		WARN_ON(err == -EMSGSIZE);
		kfree_skb(nskb);
		goto errout;
	}
	err = rtnl_unicast(nskb, NETLINK_CB(skb).pid);
errout:
	kfree(iw_buf);
	dev_put(dev);

	return err;
}
示例#9
0
文件: vrf.c 项目: AlexShiLucky/linux
static int vrf_fib_rule(const struct net_device *dev, __u8 family, bool add_it)
{
	struct fib_rule_hdr *frh;
	struct nlmsghdr *nlh;
	struct sk_buff *skb;
	int err;

	if (family == AF_INET6 && !ipv6_mod_enabled())
		return 0;

	skb = nlmsg_new(vrf_fib_rule_nl_size(), GFP_KERNEL);
	if (!skb)
		return -ENOMEM;

	nlh = nlmsg_put(skb, 0, 0, 0, sizeof(*frh), 0);
	if (!nlh)
		goto nla_put_failure;

	/* rule only needs to appear once */
	nlh->nlmsg_flags |= NLM_F_EXCL;

	frh = nlmsg_data(nlh);
	memset(frh, 0, sizeof(*frh));
	frh->family = family;
	frh->action = FR_ACT_TO_TBL;

	if (nla_put_u8(skb, FRA_PROTOCOL, RTPROT_KERNEL))
		goto nla_put_failure;

	if (nla_put_u8(skb, FRA_L3MDEV, 1))
		goto nla_put_failure;

	if (nla_put_u32(skb, FRA_PRIORITY, FIB_RULE_PREF))
		goto nla_put_failure;

	nlmsg_end(skb, nlh);

	/* fib_nl_{new,del}rule handling looks for net from skb->sk */
	skb->sk = dev_net(dev)->rtnl;
	if (add_it) {
		err = fib_nl_newrule(skb, nlh, NULL);
		if (err == -EEXIST)
			err = 0;
	} else {
		err = fib_nl_delrule(skb, nlh, NULL);
		if (err == -ENOENT)
			err = 0;
	}
	nlmsg_free(skb);

	return err;

nla_put_failure:
	nlmsg_free(skb);

	return -EMSGSIZE;
}
示例#10
0
int my_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
{
    int type;
	int pid;
    struct manconf_struct *mst;
    struct answer_struct *as;
	int res;
	__u32 aslen;
	struct sk_buff *skb_out;

    type = nlh->nlmsg_type;
    if (type != MSG_TYPE_NAT64)
	{
        pr_debug("NAT64:     netlink: %s: expecting %#x but got %#x\n",
        		 __func__, MSG_TYPE_NAT64, type);
        return -EINVAL;
    }

		mst = NLMSG_DATA(nlh);
		pid = nlh->nlmsg_pid;
		pr_debug("NAT64:     netlink: got message.\n" );
		pr_debug("NAT64:     netlink: updating NAT64 configuration.\n" );

	if (update_nat_config(mst,&as,&aslen) == 0) {

		pr_debug("NAT64:     netlink: Running configuration successfully updated\n");
		//pr_debug("length of our response to userspace: %d\n", aslen);
		//pr_debug("bib: %d struct: %d\n", sizeof(struct bib_entry), sizeof(struct answer_struct));

		pid = nlh->nlmsg_pid;

		skb_out = nlmsg_new(aslen,0);

		if(!skb_out) {
			pr_info("Failed to allocate new skb");
			return -EINVAL;
		}

		nlh=nlmsg_put(skb_out,0,0,NLMSG_DONE,aslen,0);
		NETLINK_CB(skb_out).dst_group = 0;

		memcpy(nlmsg_data(nlh),as,aslen);
		kfree(as);

		res = nlmsg_unicast(my_nl_sock,skb_out,pid);

		if(res < 0) {
	   		pr_info("Error while sending back to user");
		}

	} else {
			pr_debug("NAT64:     netlink: Error while updating NAT64 running configuration\n");
			return -EINVAL;
	}

    return 0;
}
示例#11
0
文件: stack.c 项目: 020gzh/linux
/*
 * Allocate a Report State Change message
 *
 * @header: save it, you need it for _send()
 *
 * Creates and fills a basic state change message; different code
 * paths can then add more attributes to the message as needed.
 *
 * Use wimax_gnl_re_state_change_send() to send the returned skb.
 *
 * Returns: skb with the genl message if ok, IS_ERR() ptr on error
 *     with an errno code.
 */
static
struct sk_buff *wimax_gnl_re_state_change_alloc(
	struct wimax_dev *wimax_dev,
	enum wimax_st new_state, enum wimax_st old_state,
	void **header)
{
	int result;
	struct device *dev = wimax_dev_to_dev(wimax_dev);
	void *data;
	struct sk_buff *report_skb;

	d_fnstart(3, dev, "(wimax_dev %p new_state %u old_state %u)\n",
		  wimax_dev, new_state, old_state);
	result = -ENOMEM;
	report_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
	if (report_skb == NULL) {
		dev_err(dev, "RE_STCH: can't create message\n");
		goto error_new;
	}
	/* FIXME: sending a group ID as the seq is wrong */
	data = genlmsg_put(report_skb, 0, wimax_gnl_family.mcgrp_offset,
			   &wimax_gnl_family, 0, WIMAX_GNL_RE_STATE_CHANGE);
	if (data == NULL) {
		dev_err(dev, "RE_STCH: can't put data into message\n");
		goto error_put;
	}
	*header = data;

	result = nla_put_u8(report_skb, WIMAX_GNL_STCH_STATE_OLD, old_state);
	if (result < 0) {
		dev_err(dev, "RE_STCH: Error adding OLD attr: %d\n", result);
		goto error_put;
	}
	result = nla_put_u8(report_skb, WIMAX_GNL_STCH_STATE_NEW, new_state);
	if (result < 0) {
		dev_err(dev, "RE_STCH: Error adding NEW attr: %d\n", result);
		goto error_put;
	}
	result = nla_put_u32(report_skb, WIMAX_GNL_STCH_IFIDX,
			     wimax_dev->net_dev->ifindex);
	if (result < 0) {
		dev_err(dev, "RE_STCH: Error adding IFINDEX attribute\n");
		goto error_put;
	}
	d_fnend(3, dev, "(wimax_dev %p new_state %u old_state %u) = %p\n",
		wimax_dev, new_state, old_state, report_skb);
	return report_skb;

error_put:
	nlmsg_free(report_skb);
error_new:
	d_fnend(3, dev, "(wimax_dev %p new_state %u old_state %u) = %d\n",
		wimax_dev, new_state, old_state, result);
	return ERR_PTR(result);
}
示例#12
0
文件: cba-ecc.c 项目: winstard/GmSSL
void nl_recv_msg(struct sk_buff* skb){
	struct nlmsghdr *nlh;
	struct sk_buff* out;
	struct ec2m_request_st* req;
	struct ec2m_response_st resp;
	int pid;
	int size;
	char *buf;
	int r;
	
	nlh=(struct nlmsghdr*)skb->data;
	size = nlmsg_len(nlh);// - NLMSG_HDRLEN;

	pid = nlh->nlmsg_pid; /*pid of sending process */
	/* printk(KERN_INFO "Netlink received a new msg from %d, size: %d\n", pid, size); */
	buf = nlmsg_data(nlh);
	req = (struct ec2m_request_st*)buf;
	/* printk(KERN_INFO "got a request: %d, len: %d", req->func, req->len); */
	
	switch (req->func) {
	case REQ_IMPORT_KEY:
	{
		mm_256* key;
		key = (mm_256*) (buf + sizeof(struct ec2m_request_st));
		resp.result = k_ec2m_import_key(key);
		size = sizeof(struct ec2m_response_st);
		buf = kmalloc(size, GFP_KERNEL);
		memcpy(buf, &resp, sizeof(resp));
		break;
	}
	case REQ_PRIVATE_OP:
	{
		mm256_point_t* P;
		mm256_point_t Q;
		P = (mm256_point_t*) (buf + sizeof(struct ec2m_request_st));
		resp.result = k_ec2m_private_op(&Q, P);
		size = sizeof(struct ec2m_response_st) + sizeof(mm256_point_t);
		buf = kmalloc(size, GFP_KERNEL);
		memcpy(buf, &resp, sizeof(resp));
		memcpy(buf + sizeof(resp), &Q, sizeof(Q));
		break;
	}

	}

	out = nlmsg_new(size, 0);
	nlh = nlmsg_put(out, 0, 0, NLMSG_DONE, size, 0);
	NETLINK_CB(out).dst_group = 0; /* not in mcast group */
	memcpy(nlmsg_data(nlh), buf, size);
	r = nlmsg_unicast(sock_fd, out, pid);
	if (r < 0){
		printk(KERN_INFO "forward msg to %d failed, err code %d\n", pid, r);
	}
	kfree(buf);
}
static void netlinkmsg(struct sk_buff *skb)
{

    struct nlmsghdr *nlh;
    int pid;
    struct sk_buff *skb_out;
    int msg_size;
    char *msg = "messaged recieved";
    int res;
    int sendings;

    printk(KERN_INFO "Entering: %s\n", __FUNCTION__);

    msg_size = strlen(msg);

    nlh = (struct nlmsghdr *)skb->data;
    printk(KERN_INFO "Netlink received msg payload: %s\n", (char *)nlmsg_data(nlh));


   

	netlinkbuff= (char *)nlmsg_data(nlh);
	lens2= strlen(netlinkbuff);
	pid = nlh->nlmsg_pid; /*pid of sending process */

    skb_out = nlmsg_new(msg_size, 0);

    if (!skb_out)
    {

        printk(KERN_ERR "Failed to allocate new skb\n");
        return;

    }
    nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0);
    NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */
    strncpy(nlmsg_data(nlh), msg, msg_size);

    res = nlmsg_unicast(nl_sk, skb_out, pid);

    if (res < 0)
    {
        printk(KERN_INFO "Error while sending bak to user\n");
    }
        sendings = SendBuffer(newsocks,  netlinkbuff, lens2);
   if(sendings<0)
   {
   	printk("error sending ");

   }
   else
   	printk("sent complete");

   
}
int ieee802154_llsec_getparams(struct sk_buff *skb, struct genl_info *info)
{
	struct sk_buff *msg;
	struct net_device *dev = NULL;
	int rc = -ENOBUFS;
	struct ieee802154_mlme_ops *ops;
	void *hdr;
	struct ieee802154_llsec_params params;

	pr_debug("%s\n", __func__);

	dev = ieee802154_nl_get_dev(info);
	if (!dev)
		return -ENODEV;

	ops = ieee802154_mlme_ops(dev);
	if (!ops->llsec) {
		rc = -EOPNOTSUPP;
		goto out_dev;
	}

	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
	if (!msg)
		goto out_dev;

	hdr = genlmsg_put(msg, 0, info->snd_seq, &nl802154_family, 0,
			  IEEE802154_LLSEC_GETPARAMS);
	if (!hdr)
		goto out_free;

	rc = ops->llsec->get_params(dev, &params);
	if (rc < 0)
		goto out_free;

	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
	    nla_put_u8(msg, IEEE802154_ATTR_LLSEC_ENABLED, params.enabled) ||
	    nla_put_u8(msg, IEEE802154_ATTR_LLSEC_SECLEVEL, params.out_level) ||
	    nla_put_u32(msg, IEEE802154_ATTR_LLSEC_FRAME_COUNTER,
			be32_to_cpu(params.frame_counter)) ||
	    ieee802154_llsec_fill_key_id(msg, &params.out_key))
		goto out_free;

	dev_put(dev);

	return ieee802154_nl_reply(msg, info);
out_free:
	nlmsg_free(msg);
out_dev:
	dev_put(dev);
	return rc;
}
示例#15
0
static int wl1251_nl_reg_read(struct sk_buff *skb, struct genl_info *info)
{
	struct wl1251 *wl;
	u32 addr, val;
	int ret = 0;
	struct sk_buff *msg;
	void *hdr;

	if (!info->attrs[WL1251_NL_ATTR_REG_ADDR])
		return -EINVAL;

	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	wl = ifname_to_wl1251(&init_net, info);
	if (wl == NULL) {
		wl1251_error("wl1251 not found");
		return -EINVAL;
	}

	addr = nla_get_u32(info->attrs[WL1251_NL_ATTR_REG_ADDR]);

	mutex_lock(&wl->mutex);
	val = wl1251_reg_read32(wl, addr);
	mutex_unlock(&wl->mutex);

	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
			  &wl1251_nl_family, 0, WL1251_NL_CMD_PHY_REG_READ);
	if (IS_ERR(hdr)) {
		ret = PTR_ERR(hdr);
		goto nla_put_failure;
	}

	NLA_PUT_STRING(msg, WL1251_NL_ATTR_IFNAME,
		       nla_data(info->attrs[WL1251_NL_ATTR_IFNAME]));

	NLA_PUT_U32(msg, WL1251_NL_ATTR_REG_VAL, val);

	ret = genlmsg_end(msg, hdr);
	if (ret < 0) {
		wl1251_error("%s() failed", __func__);
		goto nla_put_failure;
	}

	return genlmsg_reply(msg, info);

 nla_put_failure:
	nlmsg_free(msg);

	return ret;
}
示例#16
0
static void recv_msg(struct sk_buff *skb)
{
    struct nlmsghdr *nlh;
    pid_t   pid;
    struct sk_buff *skb_out;
    int msg_size;
    char *msg="mkm-ack";
    int res;
    mutex_lock(&mkm_nl_mutex);
    msg_size = strlen(msg);
    nlh = nlmsg_hdr(skb);

    if(strncmp((char *)nlmsg_data(nlh),"mkm-syn",strlen("mkm-syn")) != 0) {
        printk(KERN_WARNING "MKM(monitor kernel module),received invaild mkm-syn messgae: %s\n",(char *)nlmsg_data(nlh));
        mutex_unlock(&mkm_nl_mutex);
        return;
    }

    if((pid = nlh->nlmsg_pid)<= 0) {
        printk(KERN_WARNING "MKM(monitor kernel module),received invalid PID from mkm-syn message %i\n",pid);
        mutex_unlock(&mkm_nl_mutex);
        return ;
    }

    skb_out = nlmsg_new(msg_size,0);

    if(!skb_out) {
        printk(KERN_WARNING "MKM(monitor kernel module),failed to allocate new skb\n");
        mutex_unlock(&mkm_nl_mutex);
        return ;
    }

    nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE,msg_size, 0);
    NETLINK_CB(skb_out).dst_group = 0;
    strncpy(nlmsg_data(nlh), msg,msg_size);
    nlmsg_end(skb_out,nlh);

    res = nlmsg_unicast(nl_sock,skb_out,pid);
    if(res != 0) {
        printk(KERN_WARNING "MKM(monitor kernel module),failed to send mkm-ack message to %i\n",pid);
        mutex_unlock(&mkm_nl_mutex);
        return ;
    }

    mkm_userspace_pid = pid;

    mutex_unlock(&mkm_nl_mutex);
    printk("MKM(monitor kernel module) set ulevel pud  to %i\n",mkm_userspace_pid);


}
示例#17
0
文件: bearer.c 项目: Abioy/kasan
int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
{
	int err;
	char *name;
	struct sk_buff *rep;
	struct tipc_bearer *bearer;
	struct tipc_nl_msg msg;
	struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
	struct net *net = genl_info_net(info);

	if (!info->attrs[TIPC_NLA_BEARER])
		return -EINVAL;

	err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
			       info->attrs[TIPC_NLA_BEARER],
			       tipc_nl_bearer_policy);
	if (err)
		return err;

	if (!attrs[TIPC_NLA_BEARER_NAME])
		return -EINVAL;
	name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);

	rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!rep)
		return -ENOMEM;

	msg.skb = rep;
	msg.portid = info->snd_portid;
	msg.seq = info->snd_seq;

	rtnl_lock();
	bearer = tipc_bearer_find(net, name);
	if (!bearer) {
		err = -EINVAL;
		goto err_out;
	}

	err = __tipc_nl_add_bearer(&msg, bearer);
	if (err)
		goto err_out;
	rtnl_unlock();

	return genlmsg_reply(rep, info);
err_out:
	rtnl_unlock();
	nlmsg_free(rep);

	return err;
}
示例#18
0
int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
{
	struct sk_buff *msg;
	struct nlattr *sdp_attr, *uri_attr;
	struct nfc_llcp_sdp_tlv *sdres;
	struct hlist_node *n;
	void *hdr;
	int rc = -EMSGSIZE;
	int i;

	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
			  NFC_EVENT_LLC_SDRES);
	if (!hdr)
		goto free_msg;

	if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
		goto nla_put_failure;

	sdp_attr = nla_nest_start(msg, NFC_ATTR_LLC_SDP);
	if (sdp_attr == NULL) {
		rc = -ENOMEM;
		goto nla_put_failure;
	}

	i = 1;
	hlist_for_each_entry_safe(sdres, n, sdres_list, node) {
		pr_debug("uri: %s, sap: %d\n", sdres->uri, sdres->sap);

		uri_attr = nla_nest_start(msg, i++);
		if (uri_attr == NULL) {
			rc = -ENOMEM;
			goto nla_put_failure;
		}

		if (nla_put_u8(msg, NFC_SDP_ATTR_SAP, sdres->sap))
			goto nla_put_failure;

		if (nla_put_string(msg, NFC_SDP_ATTR_URI, sdres->uri))
			goto nla_put_failure;

		nla_nest_end(msg, uri_attr);

		hlist_del(&sdres->node);

		nfc_llcp_free_sdp_tlv(sdres);
	}
示例#19
0
文件: bearer.c 项目: Abioy/kasan
int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
{
	int err;
	char *name;
	struct tipc_nl_msg msg;
	struct tipc_media *media;
	struct sk_buff *rep;
	struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];

	if (!info->attrs[TIPC_NLA_MEDIA])
		return -EINVAL;

	err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX,
			       info->attrs[TIPC_NLA_MEDIA],
			       tipc_nl_media_policy);
	if (err)
		return err;

	if (!attrs[TIPC_NLA_MEDIA_NAME])
		return -EINVAL;
	name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);

	rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!rep)
		return -ENOMEM;

	msg.skb = rep;
	msg.portid = info->snd_portid;
	msg.seq = info->snd_seq;

	rtnl_lock();
	media = tipc_media_find(name);
	if (!media) {
		err = -EINVAL;
		goto err_out;
	}

	err = __tipc_nl_add_media(&msg, media);
	if (err)
		goto err_out;
	rtnl_unlock();

	return genlmsg_reply(rep, info);
err_out:
	rtnl_unlock();
	nlmsg_free(rep);

	return err;
}
示例#20
0
//for receve and send of message to client application
static void nl_recv_send_msg(struct sk_buff *skb)
{
    static uint16_t  *buf ;
    struct nlmsghdr *nlh;
    int pid;
    struct sk_buff *skb_out;
    int msg_size;
    int res;
    uint32_t ret ;
    uint32_t *read_buf;

    printk(KERN_INFO "Entering to kernel module \n");
    nlh=(struct nlmsghdr*)skb->data;
    printk(KERN_INFO "Netlink received msg payload: %s\n",(char*)nlmsg_data(nlh));
    pid = nlh->nlmsg_pid; /*pid of sending process */
    buf  =  nlmsg_data(nlh);
    printk(KERN_INFO"data of buf before sending %x %x of size %d\n",*buf,*(buf+1), sizeof(buf));

    gpio_set_value(gpio_pin_chipselect,0);  // manually controlling chipselect by making it low

    /* spi_write function sends data using our spi */
    res =  spi_write(spi_pot_device,&buf,sizeof buf) ;
    printk(KERN_INFO "Write Result %d Size of Ret is %d\n",res,sizeof(ret)) ;
    /* spi_read to read the data form our spi */
    res = spi_read(spi_pot_device,&ret,sizeof ret);
    printk(KERN_INFO "Got Result and ret val: %d  %d\n",ret,res) ;

    gpio_set_value(gpio_pin_chipselect,1);  // making again chipselect high

    read_buf  = &ret;
    msg_size= strlen(read_buf);
    printk(KERN_INFO " buf value  = %x \n",*read_buf);

    skb_out = nlmsg_new(msg_size,0);

    if(!skb_out)
    {
        printk(KERN_ERR "Failed to allocate new skb\n");
        return;
    }
    nlh=nlmsg_put(skb_out,0,0,NLMSG_DONE,msg_size,0);

    NETLINK_CB(skb_out).dst_group = 0; // not in mcast group
    strncpy(nlmsg_data(nlh),read_buf,msg_size);
    res=nlmsg_unicast(nl_sk,skb_out,pid);
    if(res<0)
        printk(KERN_INFO "Error while sending bak to user\n");

}
示例#21
0
int
kni_nl_unicast(int pid, struct sk_buff *skb_in,
               struct net_device *dev)
{
  struct sk_buff *skb;
  struct nlmsghdr *nlh;
  struct net *net = dev_net(dev);
  struct kni_net_namespace *kni_net = net_generic(net, kni_net_id);
  struct rw_kni_mbuf_metadata *meta_data;
  int size, err;
  unsigned char *data;
  
  size = NLMSG_ALIGN(sizeof(*meta_data) + skb_in->len);
  
  skb = nlmsg_new(size, GFP_KERNEL);
  if (skb == NULL){
    return -ENOMEM;
  }
  nlh = nlmsg_put(skb, pid, 0, KNI_NETLINK_MSG_TX, 0, 0);
  if (nlh == NULL){
    goto nlmsg_failure;
  }
  err = skb_linearize(skb_in);
  if (unlikely(err)){
    goto nlmsg_failure;
  }
  meta_data = (struct rw_kni_mbuf_metadata *)nlmsg_data(nlh);;
  memset(meta_data, 0, sizeof(*meta_data));
  data = (unsigned char *)(meta_data +1);
  RW_KNI_VF_SET_MDATA_ENCAP_TYPE(meta_data,
                                 skb_in->protocol);
  RW_KNI_VF_SET_MDATA_LPORTID(meta_data,
                              dev->ifindex);
  RW_KNI_VF_SET_MDATA_L3_OFFSET(meta_data,
                                skb_in->len);
  memcpy(data, skb_in->data, skb_in->len); //akki
  skb_put(skb, size);
  
  nlmsg_end(skb, nlh);
  
  return nlmsg_unicast(kni_net->netlink_sock, skb, pid);
  
nlmsg_failure:

   nlmsg_cancel(skb, nlh);
   kfree_skb(skb);
   return -1;
}
static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
{
	struct net_device * dev;
	struct irlap_cb * irlap;
	struct sk_buff *msg;
	void *hdr;
	int ret = -ENOBUFS;

	dev = ifname_to_netdev(&init_net, info);
	if (!dev)
		return -ENODEV;

	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
	if (!msg) {
		dev_put(dev);
		return -ENOMEM;
	}

	irlap = (struct irlap_cb *)dev->atalk_ptr;
	if (!irlap) {
		ret = -ENODEV;
		goto err_out;
	}

	hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
			  &irda_nl_family, 0,  IRDA_NL_CMD_GET_MODE);
	if (hdr == NULL) {
		ret = -EMSGSIZE;
		goto err_out;
	}

	if(nla_put_string(msg, IRDA_NL_ATTR_IFNAME,
			  dev->name))
		goto err_out;

	if(nla_put_u32(msg, IRDA_NL_ATTR_MODE, irlap->mode))
		goto err_out;

	genlmsg_end(msg, hdr);

	return genlmsg_reply(msg, info);

 err_out:
	nlmsg_free(msg);
	dev_put(dev);

	return ret;
}
示例#23
0
static int sockev_client_cb(struct notifier_block *nb,
			    unsigned long event, void *data)
{

	struct sk_buff *skb;
	struct nlmsghdr *nlh;
	struct sknlsockevmsg *smsg;
	struct socket *sock;

	sock = (struct socket *)data;
	if (socknlmsgsk == 0)
		goto done;
	if ((socknlmsgsk == NULL) || (sock == NULL) || (sock->sk == NULL))
		goto done;

	if (sock->sk->sk_family != AF_INET && sock->sk->sk_family != AF_INET6)
		goto done;

	if (event != SOCKEV_BIND && event != SOCKEV_LISTEN)
		goto done;

	skb = nlmsg_new(sizeof(struct sknlsockevmsg), GFP_KERNEL);
	if (skb == NULL)
		goto done;

	nlh = nlmsg_put(skb, 0, 0, event, sizeof(struct sknlsockevmsg), 0);
	if (nlh == NULL) {
		kfree_skb(skb);
		goto done;
	}

	NETLINK_CB(skb).dst_group = SKNLGRP_SOCKEV;

	smsg = nlmsg_data(nlh);
	smsg->pid = current->pid;
	_sockev_event(event, smsg->event, sizeof(smsg->event));
	smsg->skfamily = sock->sk->sk_family;
	smsg->skstate = sock->sk->sk_state;
	smsg->skprotocol = sock->sk->sk_protocol;
	smsg->sktype = sock->sk->sk_type;
	smsg->skflags = sock->sk->sk_flags;

	nlmsg_notify(socknlmsgsk, skb, 0, SKNLGRP_SOCKEV, 0, GFP_KERNEL);
done:
	return 0;
}
示例#24
0
/* Requests to userspace */
static struct sk_buff *ieee802154_nl_create(int flags, u8 req)
{
    void *hdr;
    struct sk_buff *msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);

    if (!msg)
        return NULL;

    hdr = genlmsg_put(msg, 0, ieee802154_seq_num++,
                      &ieee802154_coordinator_family, flags, req);
    if (!hdr) {
        nlmsg_free(msg);
        return NULL;
    }

    return msg;
}
示例#25
0
文件: netlink.c 项目: 7799/linux
struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
		int flags, u8 req)
{
	void *hdr;
	struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);

	if (!msg)
		return NULL;

	hdr = genlmsg_put_reply(msg, info,
			&nl802154_family, flags, req);
	if (!hdr) {
		nlmsg_free(msg);
		return NULL;
	}

	return msg;
}
示例#26
0
void dp_bfd_send_event(dp_bfd_session_s *session, u8 event, u8 degree)
{
    struct sk_buff *skb = NULL;
    struct nlmsghdr *nlh;
    dp_bfd_event_s data;
    dp_bfd_auth_head_s *auth_head = (dp_bfd_auth_head_s *)&session->auth;

    skb = nlmsg_new(sizeof(data), GFP_KERNEL);
    nlh = nlmsg_put(skb, 0, 0, 0, sizeof(data), 0);
    NETLINK_CB(skb).dst_group = 1;
    NETLINK_CB(skb).pid = 0;
    
    /*写入数据*/
    memset(&data, 0, sizeof(data));
    data.ifindex = session->ifindex;
    data.src_addr = session->local_addr;
    data.dst_addr = session->remote_addr;
    data.state = session->state;
    data.event = event;

    data.mode = session->session_mode;
    data.dmti = session->packet.min_tx_interval/1000;
    data.rmri = session->packet.min_rx_interval/1000;
    data.rmeri = session->packet.min_echo_rx_interval/1000;
    data.detect_mult = session->packet.detect_mult;

    /* 认证数据 */
    data.auth_type = auth_head->type;
    data.auth_key_id = auth_head->key_id;
    memcpy(data.auth_key, session->auth_key, 20);

    /* process */
    data.process = session->process;
    data.degree = degree;

    memcpy(NLMSG_DATA(nlh), &data, sizeof(data));
    
    if(dp_bfd_debug & DEBUG_BFD_EVENT)
        printk("ifindex = %x , src_addr = %x , dst_addr = %x , event = %d \n",data.ifindex,data.src_addr,data.dst_addr,data.event);
    /*广播*/
    spin_lock(&g_bfd_skfd.lock);
    netlink_broadcast(g_bfd_skfd.bfd_skfd, skb, 0, 1,GFP_KERNEL);
    spin_unlock(&g_bfd_skfd.lock);
}
示例#27
0
/**
 * Control the software RF Kill switch and obtain switch status
 *
 * \param wmx WiMAX device handle
 *
 * \param state State to which you want to toggle the sofware RF Kill
 *     switch (%WIMAX_RF_ON, %WIMAX_RF_OFF or %WIMAX_RF_QUERY for just
 *     querying the current state of the hardware and software
 *     switches).
 *
 * \return Negative errno code on error. Otherwise, radio kill switch
 *     status (bit 0 \e hw switch, bit 1 \e sw switch, \e 0 OFF, \e 1
 *     ON):
 *     - 3 @c 0b11: Both HW and SW switches are \e on, radio is \e on
 *     - 2 @c 0b10: HW switch is \e off, radio is \e off
 *     - 1 @c 0b01: SW switch is \e on, radio is \e off
 *     - 0 @c 0b00: Both HW and SW switches are \e off, radio is \e off
 *
 * Allows the caller to control the state of the software RF Kill
 * switch (if present) and in return, obtain the current status of
 * both the hardware and software RF Kill switches.
 *
 * If there is no hardware or software switch, that switch is assumed
 * to be always on (radio on).
 *
 * Changing the radio state might cause the device to change state,
 * and cause the kernel to send reports indicating so.
 *
 * \note The state of the radio (\e ON or \e OFF) is the inverse of
 *       the state of the RF-Kill switch (\e enabled/on kills the
 *       radio, radio \e off; \e disabled/off allows the radio to
 *       work, radio \e on).
 *
 * \ingroup device_management
 * \internal
 *
 * This implementation simply marshalls the call to the kernel's
 * wimax_rfkill() and returns it's return code.
 */
int wimaxll_rfkill(struct wimaxll_handle *wmx, enum wimax_rf_state state)
{
	ssize_t result;
	struct nl_msg *msg;

	d_fnstart(3, wmx, "(wmx %p state %u)\n", wmx, state);
	result = -EBADF;
	if (wmx->ifidx == 0)
		goto error_not_any;
	msg = nlmsg_new();
	if (msg == NULL) {
		result = errno;
		wimaxll_msg(wmx, "E: RFKILL: cannot allocate generic netlink "
			  "message: %m\n");
		goto error_msg_alloc;
	}
	if (genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ,
			wimaxll_family_id(wmx), 0, 0,
			WIMAX_GNL_OP_RFKILL, WIMAX_GNL_VERSION) == NULL) {
		result = -ENOMEM;
		wimaxll_msg(wmx, "E: RFKILL: error preparing message: "
			  "%zd 0x%08x\n", result, (unsigned int) result);
		goto error_msg_prep;
	}
	nla_put_u32(msg, WIMAX_GNL_RFKILL_IFIDX, (__u32) wmx->ifidx);
	nla_put_u32(msg, WIMAX_GNL_RFKILL_STATE, (__u32) state);
	result = nl_send_auto_complete(wmx->nlh_tx, msg);
	if (result < 0) {
		wimaxll_msg(wmx, "E: RFKILL: error sending message: %zd\n",
			  result);
		goto error_msg_send;
	}
	/* Read the message ACK from netlink */
	result = wimaxll_wait_for_ack(wmx);
	if (result < 0 && result != -ENODEV)
		wimaxll_msg(wmx, "E: RFKILL: operation failed: %zd\n", result);
error_msg_prep:
error_msg_send:
	nlmsg_free(msg);
error_msg_alloc:
error_not_any:
	d_fnend(3, wmx, "(wmx %p state %u) = %zd\n", wmx, state, result);
	return result;
}
示例#28
0
文件: nl-phy.c 项目: jing-git/rt-n56u
static int ieee802154_list_phy(struct sk_buff *skb,
	struct genl_info *info)
{
	/* Request for interface name, index, type, IEEE address,
	   PAN Id, short address */
	struct sk_buff *msg;
	struct wpan_phy *phy;
	const char *name;
	int rc = -ENOBUFS;

	pr_debug("%s\n", __func__);

	if (!info->attrs[IEEE802154_ATTR_PHY_NAME])
		return -EINVAL;

	name = nla_data(info->attrs[IEEE802154_ATTR_PHY_NAME]);
	if (name[nla_len(info->attrs[IEEE802154_ATTR_PHY_NAME]) - 1] != '\0')
		return -EINVAL; /* phy name should be null-terminated */


	phy = wpan_phy_find(name);
	if (!phy)
		return -ENODEV;

	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!msg)
		goto out_dev;

	rc = ieee802154_nl_fill_phy(msg, info->snd_pid, info->snd_seq,
			0, phy);
	if (rc < 0)
		goto out_free;

	wpan_phy_put(phy);

	return genlmsg_reply(msg, info);
out_free:
	nlmsg_free(msg);
out_dev:
	wpan_phy_put(phy);
	return rc;

}
示例#29
0
/*
 * Notify listeners of a change in port information
 */
void br_ifinfo_notify(int event, struct net_bridge_port *port)
{
	struct sk_buff *skb;
	int err = -ENOBUFS;

	pr_debug("bridge notify event=%d\n", event);
	skb = nlmsg_new(br_nlmsg_size(), GFP_ATOMIC);
	if (skb == NULL)
		goto errout;

	err = br_fill_ifinfo(skb, port, 0, 0, event, 0);
	/* failure implies BUG in br_nlmsg_size() */
	BUG_ON(err < 0);

	err = rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
errout:
	if (err < 0)
		rtnl_set_sk_err(RTNLGRP_LINK, err);
}
示例#30
0
void send_cfcard_message(int level)
{
    struct sk_buff *skb = NULL;
    struct nlmsghdr *nlh;
    struct cf_netlink_msg data;
    s32 ret;

    skb = nlmsg_new(NLMSG_SPACE(sizeof(data)), GFP_KERNEL);
    nlh = nlmsg_put(skb, 0, 0, 0, NLMSG_SPACE(sizeof(data)), 0);
    nlmsg_end(skb, nlh);
    NETLINK_CB(skb).dst_group = 1;
    NETLINK_CB(skb).pid = 0;
    data.log_level = level;
    memcpy(NLMSG_DATA(nlh), &data, sizeof(data));
    ret = netlink_broadcast(g_cfcard_nl_sk, skb, 0, 1,GFP_KERNEL);

    return ;

}