????Linux????????????????????????9???????????????????????????? sysfs??sysctl???????á?netlink??procfs??seq_file??debugfs??relayfs??Netlink??????????????????????????????2.6.14??????汾??Linux?????У??????????????????ü?????????????????????????????????????????API ???????netlink???????????????????????????? API ?????netlink??Netlink???????????????磬Linux?????????????????????netfilter????????iptables??netfilter??iptables??????????????Netlink????????ɡ?
???????????Netlink??????????????佻????????
????Netlink??????????á?ioctl???proc???????????????????????????????????????????????
????1????? netlink???????????? include/linux/netlink.h ???????????????? netlink Э?鶨?弴??? ?? #define NETLINK_MYTEST 17 ?????????????????????????????API???? netlink Э?????????????????????????????????μ????????ioctl ??????????豸??????? ????????????proc ???????????? /proc ??????μ??????????????????????? /proc ??????????
????2??netlink???????????????????????????????????????????socket????????У???????????????????????????socket???????У??????????????????????????????????? ioctl ???????????????????????????????????????????
????3????? netlink ??????????????????????????? netlink ????ò????????????б???????????????????????????????μ??????????????????????????У?????????????????????????????????????????????????
????4??netlink ??????????????????????????????netlink?飬?????neilink ????κ???????????????????????????????????????????????????????????κζ??????????????????????????????????????????
????5??????????? netlink ?????????????????ú? ioctl ??????????÷?????á?
????6??netlink ????????????API?????????????????????ú? ioctl??????????????????á?
????????Netlink????????÷??
??????????????????socket API?? socket()?? bind()?? sendmsg()?? recvmsg() ??recv()?? close() ??????????? netlink socket??????????????????Щ?????????????????????????? netlink ????????????????Щ???????????? netlink ???????????????linux/netlink.h????? socket ??????????????????sys/socket.h??
????????????? netlink socket??????????????2??????? socket():
view plaincopy to clipboardprint?
int ntSocket;
ntSocket = socket(AF_NETLINK?? SOCK_RAW?? NETLINK_KOBJECT_UEVENT);
??????????????????? AF_NETLINK ?? PF_NETLINK???? Linux ?У?????????????????????????????netlink?????????????????SOCK_RAW??SOCK_DGRAM???????????????netlinkЭ???????NETLINK_KOBJECT_UEVENT???“??????????????”??????Э?鴴????ntSocket?????????????????????????USB???Σ???
?????????????Э???????У?
#define NETLINK_ROUTE 0 //·?????????
#define NETLINK_W1 1 //1-wire ????
#define NETLINK_USERSOCK 2 //?????????Э??
#define NETLINK_FIREWALL 3 //?????
#define NETLINK_INET_DIAG 4 //????????
#define NETLINK_NFLOG 5 //??????????????
#define NETLINK_XFRM 6 //ipsec ???????
#define NETLINK_SELINUX 7 //SELinux ?????
#define NETLINK_ISCSI 8 //iSCSI????洢????
#define NETLINK_AUDIT 9 //???????
#define NETLINK_FIB_LOOKUP 10 //??????????
#define NETLINK_CONNECTOR 11 //netlink??????
#define NETLINK_NETFILTER 12 //?????????????
#define NETLINK_IP6_FW 13 //IPv6 ?????
#define NETLINK_DNRTMSG 14 //DECnet·?????
#define NETLINK_KOBJECT_UEVENT 15 //??????????????
#define NETLINK_GENERIC 16 //???netlink?????????幦???
????????????netlinkЭ????????????ж?? 32???飬?????????????λ?????netlink ?????????÷?????????????????????????????????????????????????????????????????????????