Forums » Software Development »
Netlink
Added by Mary Frantz about 9 years ago
Does this distro support the Netlink interface between a kernel module and user space?
I can't get past the initialization. Below is the kernel module code:
#include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/sched.h> #include <net/sock.h> #include <linux/netlink.h> #include <linux/skbuff.h> #include <net/net_namespace.h> #define NETLINK_USER 17 #define MAX_PAYLOAD 1024 struct sock *nl_sk = NULL; static void nl_recv_msg(struct sk_buff *skb) { struct nlmsghdr *nlh = NULL; int pid; printk("Entering: %s\n", __FUNCTION__); if (skb == NULL) { printk("skb is NULL \n"); return; } nlh = (struct nlmsghdr *)skb->data; printk("Netlink received msg payload: %s\n", (char *)nlmsg_data(nlh)); pid = nlh->nlmsg_pid; /*pid of sending process */ } int netlink_init(void) { printk("Entering: %s\n", __FUNCTION__); nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, 0, nl_recv_msg, NULL, THIS_MODULE); if (!nl_sk) { printk("Error creating socket.\n"); return -10; } return 0; }
I defined NETLINK_USER in netlink.h, and recompiled and reloaded the kernel. There are no other modifications. netlink_kernel_create() returns NULL. I have found many examples for creating the socket in the kernel, and this version is supposed to work with the 3.2 kernel.
What's wrong?
Mary
Replies (3)
RE: Netlink - Added by Jonathan Cormier about 9 years ago
Mary,
I don't believe any one here has any experience with using Netlink, so I'm not sure how much help I can be. From what I've read NETLINK has been in the kernel since 2.6 so it should be supported.
Doing a grep on the kernel .config file shows that by default no netlink specific configs are enabled. Perhaps your missing one of these?
$ grep -i netlink .config # CONFIG_NETFILTER_NETLINK_QUEUE is not set # CONFIG_NETFILTER_NETLINK_LOG is not set # CONFIG_NF_CT_NETLINK is not set # CONFIG_SCSI_NETLINK is not set # CONFIG_QUOTA_NETLINK_INTERFACE is not set
There appears to be some documentation located at Documentation/connector/connector.txt which mentions NETLINK.
Sorry I couldn't be of more help.
-Jonathan
RE: Netlink - Added by Mary Frantz about 9 years ago
I modified .config to enable "Netfilter NFQUEUE over NFNETLINK interface"
Networking support -> Networking options -> Network packet filtering framework (Netfilter) -> Core Netfilter Configuration -> Netfilter NFQUEUE over NFNETLINK interface <Y>
The changes to NETLINK show up like this:
$ grep -i netlink .config CONFIG_NETFILTER_NETLINK=y CONFIG_NETFILTER_NETLINK_QUEUE=y # CONFIG_NETFILTER_NETLINK_LOG is not set # CONFIG_NF_CT_NETLINK is not set # CONFIG_SCSI_NETLINK is not set # CONFIG_QUOTA_NETLINK_INTERFACE is not set
I can now successfully send messages from the kernel to user space.
Mary