网卡驱动学习之netlink
来源:互联网 发布:大数据的优点和缺点 编辑:程序博客网 时间:2024/06/04 19:51
Netlink is a socket family that for IPC between the kernel and user space processes, as well as between user processes (like e.g., UNIX sockets) or a mixture of both types. However, unlike INET sockets, it cannot traverse host boundaries, as it addresses processes by their (inherently local) PIDs.
Netlink was designed for and is used to transfer miscellaneous networking information between the Linux kernel space and user space processes. Networking utilities such as iproute2 use Netlink to communicate with the Linux kernel from user space. Netlink consists of a standard socket-based interface for user space processes and an internal kernel API for kernel modules. It is designed to be a more flexible successor to ioctl. Originally, Netlink used the AF_NETLINK socket family.
RFC 3549 describes this protocol in detail.
Contents [show]
[edit]History
Netlink was created as a more flexible alternative to the sophisticated and awkward ioctl communication method which was used for setting and getting external socket options. ioctl is still supported by the Linux kernel, for backward compatibility. It can be used as follows:
error = ioctl(ip_socket, ioctl_type, &value_result);
Netlink was first provided in Linux 2.0 as a character device. This interface is obsolete, but as an ioctl communication method, it can still be used. The Netlink socket interface appeared in the 2.2 Linux kernel.
[edit]Packet structure
Unlike the BSD socket access to Internet protocols such as TCP where the headers specifying flags and destination are autogenerated, the Netlink message header (available as struct nlmsghdr) must be prepared by the caller, as the socket generally works in a SOCK_RAW-like mode, even if SOCK_DGRAM was used to create it.
bit offset 0–1516-31
0 Message length
32 Type Flags
64 Sequence number
96 PID
128+
Data
The data portion then contains a subsystem-specific message that may be further nested.
[edit]Netlink Socket Families
The AF_NETLINK family offers multiple protocol subsets. Each interfaces to a different kernel component and has a different messaging subset. The following protocol is referenced in the field below:
int socket(AF_NETLINK, SOCK_DGRAM or SOCK_RAW, protocol)
Lacking a standard, SOCK_DGRAM and SOCK_RAW are not guaranteed to be implemented in a given Linux (or other OS) release. Some sources state that both options are legitimate, and the reference below from Red Hat states that SOCK_RAW is always the parameter, however iproute2 uses both interchangeably.
[edit]Netlink Protocols
A non-exhaustive list of the supported protocol entries follows:
NETLINK_ROUTE
NETLINK_ROUTE provides routing and link information. This information is used primarily for user-space routing daemons. Linux implements a large subset of messages:
Link Layer: RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK, RTM_SETLINK
Address Settings: RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
Routing Tables: RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
Neighbor Cache: RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
Routing Rules: RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
Queuing Discipline Settings: RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
Traffic Classes used with Queues: RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
Traffic filters: RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
Others: RTM_NEWACTION, RTM_DELACTION, RTM_GETACTION, RTM_NEWPREFIX, RTM_GETPREFIX, RTM_GETMULTICAST, RTM_GETANYCAST, RTM_NEWNEIGHTBL,RTM_GETNEIGHTBL, RTM_SETNEIGHTBL
NETLINK_FIREWALL
NETLINK_FIREWALL provides an interface for a user-space app to receive packets from the firewall.
NETLINK_NFLOG
NETLINK_NFLOG provides an interface used to communicate between used Netfilter and iptables.
NETLINK_ARPD
NETLINK_ARPD provides an interface to manage the ARP table from user space.
NETLINK_AUDIT
NETLINK_AUDIT provides an interface to the audit subsystem found in kernel versions 2.6.6 and later.
NETLINK_IPV6_FW
NETLINK_IPV6_FW provides an interface to transport packets from netfilter to userspace.
NETLINK_ROUTE6
NETLINK_TAPBASE
NETLINK_TCPDIAG
NETLINK_XFRM
NETLINK_XFRM provides an interface to manage the IPsec security association and security policy databases. It is mostly used by Key Manager daemons when they are used in Internet Key Exchange protocol.
[edit]User-defined Netlink protocol
The user can add a netlink handler in their own kernel routines. This allows additional Netlink protocols to be developed to address new kernel modules.[1]
Netlink was designed for and is used to transfer miscellaneous networking information between the Linux kernel space and user space processes. Networking utilities such as iproute2 use Netlink to communicate with the Linux kernel from user space. Netlink consists of a standard socket-based interface for user space processes and an internal kernel API for kernel modules. It is designed to be a more flexible successor to ioctl. Originally, Netlink used the AF_NETLINK socket family.
RFC 3549 describes this protocol in detail.
Contents [show]
[edit]History
Netlink was created as a more flexible alternative to the sophisticated and awkward ioctl communication method which was used for setting and getting external socket options. ioctl is still supported by the Linux kernel, for backward compatibility. It can be used as follows:
error = ioctl(ip_socket, ioctl_type, &value_result);
Netlink was first provided in Linux 2.0 as a character device. This interface is obsolete, but as an ioctl communication method, it can still be used. The Netlink socket interface appeared in the 2.2 Linux kernel.
[edit]Packet structure
Unlike the BSD socket access to Internet protocols such as TCP where the headers specifying flags and destination are autogenerated, the Netlink message header (available as struct nlmsghdr) must be prepared by the caller, as the socket generally works in a SOCK_RAW-like mode, even if SOCK_DGRAM was used to create it.
bit offset 0–1516-31
0 Message length
32 Type Flags
64 Sequence number
96 PID
128+
Data
The data portion then contains a subsystem-specific message that may be further nested.
[edit]Netlink Socket Families
The AF_NETLINK family offers multiple protocol subsets. Each interfaces to a different kernel component and has a different messaging subset. The following protocol is referenced in the field below:
int socket(AF_NETLINK, SOCK_DGRAM or SOCK_RAW, protocol)
Lacking a standard, SOCK_DGRAM and SOCK_RAW are not guaranteed to be implemented in a given Linux (or other OS) release. Some sources state that both options are legitimate, and the reference below from Red Hat states that SOCK_RAW is always the parameter, however iproute2 uses both interchangeably.
[edit]Netlink Protocols
A non-exhaustive list of the supported protocol entries follows:
NETLINK_ROUTE
NETLINK_ROUTE provides routing and link information. This information is used primarily for user-space routing daemons. Linux implements a large subset of messages:
Link Layer: RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK, RTM_SETLINK
Address Settings: RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
Routing Tables: RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
Neighbor Cache: RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
Routing Rules: RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
Queuing Discipline Settings: RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
Traffic Classes used with Queues: RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
Traffic filters: RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
Others: RTM_NEWACTION, RTM_DELACTION, RTM_GETACTION, RTM_NEWPREFIX, RTM_GETPREFIX, RTM_GETMULTICAST, RTM_GETANYCAST, RTM_NEWNEIGHTBL,RTM_GETNEIGHTBL, RTM_SETNEIGHTBL
NETLINK_FIREWALL
NETLINK_FIREWALL provides an interface for a user-space app to receive packets from the firewall.
NETLINK_NFLOG
NETLINK_NFLOG provides an interface used to communicate between used Netfilter and iptables.
NETLINK_ARPD
NETLINK_ARPD provides an interface to manage the ARP table from user space.
NETLINK_AUDIT
NETLINK_AUDIT provides an interface to the audit subsystem found in kernel versions 2.6.6 and later.
NETLINK_IPV6_FW
NETLINK_IPV6_FW provides an interface to transport packets from netfilter to userspace.
NETLINK_ROUTE6
NETLINK_TAPBASE
NETLINK_TCPDIAG
NETLINK_XFRM
NETLINK_XFRM provides an interface to manage the IPsec security association and security policy databases. It is mostly used by Key Manager daemons when they are used in Internet Key Exchange protocol.
[edit]User-defined Netlink protocol
The user can add a netlink handler in their own kernel routines. This allows additional Netlink protocols to be developed to address new kernel modules.[1]
- 网卡驱动学习之netlink
- 网卡驱动学习之DCA
- Linux之netlink学习
- 网卡驱动之虚拟网卡驱动编写
- 网卡驱动之虚拟网卡驱动编写
- Linux网卡驱动学习
- 网卡驱动学习笔记
- Linux内核学习笔记之网卡驱动的详细分析
- linux驱动之网卡驱动-虚拟网卡驱动编写
- 学习历程-linux网卡驱动
- Linux驱动之虚拟网卡
- tiny4412学习(三)之移植linux-4.x驱动(1)支持网卡驱动
- linux网卡驱动分析之驱动加载
- linux网卡驱动分析之驱动加载
- 网卡驱动之02驱动源码分析
- 网卡驱动之02驱动源码分析
- Netlink 获取网卡接口信息
- Linux内核学习笔记之网卡驱动的详细分析:RTL8139
- 【操作系统】linux--文件管理-secureCRT上传下载文件
- 计算广告学习笔记3.1 受众定向-受众定向概念
- 每秒100帧的行人检测方法 .
- namespace及use的用法
- iphone开发 Tab Bar应用程序中添加NavigationController
- 网卡驱动学习之netlink
- 基于jquery的滚动新闻列表
- c++ map
- setTimeout与setInterval区别
- 常用web.config公共配置
- JQuery中对option的添加、删除、取值
- mysql创建帐号
- Top 100 Software Testing Interview Questions
- linux下svn命令