???????????????????????????????????????Netlink???????????????????nl_groups????????????潲??????????濴??????????????Netlink???
????4. ??? Netlink api
????4.1???? netlink socket
????struct sock *netlink_kernel_create(struct net *net??
????int unit??unsigned int groups??
????void (*input)(struct sk_buff *skb)??
????struct mutex *cb_mutex??struct module *module);
?????????????
????(1) net?????????????????namespace??????????????????????????????????????????????net_device?????????????????? init_net???????????
????(2) unit?????netlinkЭ?????????NETLINK_TEST??NETLINK_SELINUX??
????(3) groups?????????
????(4) input????????鶨???netlink?????????????????? ????????netlink socket?????input?????????????????д??????????????????sendmsg????????
????(5)  cb_mutex????????????????????????
????(6) module?? ????THIS_MODULE??
????4.2 ?????????? netlink_unicast
????int netlink_unicast(struct sock *ssk?? struct sk_buff *skb?? u32 pid?? int nonblock)
?????????????
????(1) ssk??????? netlink_kernel_create()?????socket??
????(2) skb??????????????data????????????netlink????????? skb?????鱣??????????????????NETLINK_CB(skb)???????????????顣
????(3) pid????????????????pid???????????????????????????????? 0??
????(4) nonblock??????ú???????????????????1???ú?????????н???????????????????????????0???ú???????н?????????????????
????4.3 ???????? netlink_broadcast
????int netlink_broadcast(struct sock *ssk?? struct sk_buff *skb?? u32 pid?? u32 group?? gfp_t allocation)
?????????????????? netlink_unicast?????????group????????????飬?ò?????????λ??????????飬?????????????????飬??ò?????????????????ID??λ??????allocation????????????????????GFP_ATOMIC??GFP_KERNEL??GFP_ATOMIC???????????????????????????????GFP_KERNEL???????????????
????4.4 ??? netlink socket
????int netlink_broadcast(struct sock *ssk?? struct sk_buff *skb?? u32 pid?? u32 group?? gfp_t allocation)
????5. ???????????
#include <linux/init.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/time.h>
#include <linux/types.h>
#include <net/sock.h>
#include <net/netlink.h>
#define NETLINK_TEST 25
#define MAX_MSGSIZE 1024
int stringlength(char *s);
int err;
struct sock *nl_sk = NULL;
int flag = 0;
//???????????????
void sendnlmsg(char *message?? int pid)
{
struct sk_buff *skb_1;
struct nlmsghdr *nlh;
int len = NLMSG_SPACE(MAX_MSGSIZE);
int slen = 0;
if(!message || !nl_sk)
{
return ;
}
printk(KERN_ERR "pid:%d "??pid);
skb_1 = alloc_skb(len??GFP_KERNEL);
if(!skb_1)
{
printk(KERN_ERR "my_net_link:alloc_skb error ");
}
slen = stringlength(message);
nlh = nlmsg_put(skb_1??0??0??0??MAX_MSGSIZE??0);
NETLINK_CB(skb_1).pid = 0;
NETLINK_CB(skb_1).dst_group = 0;
message[slen]= '