2012-02-28 66 views
2

我有一些問題使用netlink套接字與新的netlink系列...特別是與組。我在內核空間中使用netlink_broadcastnlmsg_multicast方法將消息發送到用戶空間。我有一個頭,例如,與DEFS:如何使用套接字netlink與新的netlink系列

#define NETLINK_MYFAMILY 20 
#define NL_MYGRP   2 

,並打開一個套接字並綁定到網絡鏈路地址的過程:

int sock = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_MYFAMILY); 
... 
struct sockaddr_nl nl_addr; 
memset(&nl_addr, 0, sizeof(struct sockaddr_nl)); 
nl_addr.nl_family = AF_NETLINK; 
nl_addr.nl_pid = getpid(); 
nl_addr.nl_groups = NL_MYGRP; 

int r = bind(sock, (struct sockaddr *)&nl_addr, sizeof(struct sockaddr_nl)); 
... 

obsiously在內核空間我打電話:

struct sock *s = netlink_kernel_create(&init_net, 
             NETLINK_MYFAMILY, 
             NL_MYGRP, 
             recv_cb, 
             NULL, THIS_MODULE); 

其中recv_cb是進程從用戶空間發送消息時調用的回調。

現在我試圖發送消息到用戶空間:

netlink_broadcast(s, skb, 0, NL_MYGRP, GFP_ATOMIC); 

我可以正確讀取過程中的消息僅在NL_MYGRP爲1。我不能找出問題...所有netlink系列在linux/netlink.h中指定,數字20不存在,所以我認爲它可以用來指定我的新家庭。哪裏不對?謝謝你們。

+0

也許你可以接受的一些 – Coren 2012-02-28 22:23:36

+1

謝謝科倫你過去的問題的答案,但我認爲「有用和清晰」和「接受」是不一樣的。 – MirkoBanchi 2012-02-28 22:52:49

回答

1

20已被NETLINK_RDMA使用。你爲什麼不使用NETLINK_USERSOCK作爲你的netlink系列?

#define NETLINK_ROUTE  0 /* Routing/device hook    */ 
#define NETLINK_UNUSED  1 /* Unused number    */ 
#define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */ 
#define NETLINK_FIREWALL 3 /* Unused number, formerly ip_queue  */ 
#define NETLINK_SOCK_DIAG 4 /* socket monitoring    */ 
#define NETLINK_NFLOG  5 /* netfilter/iptables ULOG */ 
#define NETLINK_XFRM  6 /* ipsec */ 
#define NETLINK_SELINUX  7 /* SELinux event notifications */ 

#define NETLINK_ISCSI  8 /* Open-iSCSI */ 
#define NETLINK_AUDIT  9 /* auditing */ 
#define NETLINK_FIB_LOOKUP 10 
#define NETLINK_CONNECTOR 11 
#define NETLINK_NETFILTER 12 /* netfilter subsystem */ 
#define NETLINK_IP6_FW  13 
#define NETLINK_DNRTMSG  14 /* DECnet routing messages */ 
#define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */ 
#define NETLINK_GENERIC  16 

/* leave room for NETLINK_DM (DM Events) */ 
#define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */ 
#define NETLINK_ECRYPTFS 19 
#define NETLINK_RDMA  20 
#define NETLINK_CRYPTO  21 /* Crypto layer */ 

#define NETLINK_INET_DIAG NETLINK_SOCK_DIAG 

#define MAX_LINKS 32  
+0

請看這裏:[include/uapi/linux/netllink.h](https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/include/uapi/linux/ netlink.h) – Oliver 2016-02-17 21:45:37

相關問題