Example #1
0
int my_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
{
    int type;
     struct config_struct *cst;

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

	cst = NLMSG_DATA(nlh);
    pr_debug("NAT64:     netlink: got message.\n" );
    pr_debug("NAT64:     netlink: updating NAT64 configuration.\n" );

	if (update_nat_config(cst) != 0)
	{
		pr_debug("NAT64:     netlink: Error while updating NAT64 running configuration\n");
		return -EINVAL;
	}
	
	pr_debug("NAT64:     netlink: Running configuration successfully updated");

    return 0;
}
Example #2
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;
}