version 1, including all changes.
.
| Rev |
Author |
# |
Line |
| 1 |
perry |
1 |
NETLINK |
| |
|
2 |
!!!NETLINK |
| |
|
3 |
NAME |
| |
|
4 |
SYNOPSIS |
| |
|
5 |
DESCRIPTION |
| |
|
6 |
ADDRESS FORMATS |
| |
|
7 |
BUGS |
| |
|
8 |
NOTES |
| |
|
9 |
VERSIONS |
| |
|
10 |
SEE ALSO |
| |
|
11 |
---- |
| |
|
12 |
!!NAME |
| |
|
13 |
|
| |
|
14 |
|
| |
|
15 |
netlink, PF_NETLINK - Communication between kernel and user. |
| |
|
16 |
!!SYNOPSIS |
| |
|
17 |
|
| |
|
18 |
|
| |
|
19 |
__#include |
| |
|
20 |
__ ''socket_type''__,__ ''netlink_family''__); |
| |
|
21 |
__ |
| |
|
22 |
!!DESCRIPTION |
| |
|
23 |
|
| |
|
24 |
|
| |
|
25 |
Netlink is used to transfer information between kernel |
| |
|
26 |
modules and user space processes. It consists of a standard |
| |
|
27 |
sockets based interface for user processes and an internal |
| |
|
28 |
kernel API for kernel modules. The internal kernel interface |
| |
|
29 |
is not documented in this man page. Also there is an |
| |
|
30 |
obsolete netlink interface via netlink character devices, |
| |
|
31 |
this interface is not documented here and is only provided |
| |
|
32 |
for backwards compatibility. |
| |
|
33 |
|
| |
|
34 |
|
| |
|
35 |
Netlink is a datagram oriented service. Both __SOCK_RAW__ |
| |
|
36 |
and __SOCK_DGRAM__ are valid values for |
| |
|
37 |
''socket_type''; however the netlink protocol does not |
| |
|
38 |
distinguish between datagram and raw sockets. |
| |
|
39 |
|
| |
|
40 |
|
| |
|
41 |
''netlink_family'' selects the kernel module or netlink |
| |
|
42 |
group to communicate with. The currently assigned netlink |
| |
|
43 |
families are: |
| |
|
44 |
|
| |
|
45 |
|
| |
|
46 |
__NETLINK_ROUTE__ |
| |
|
47 |
|
| |
|
48 |
|
| |
|
49 |
Receives routing updates and may be used to modify the IPv4 |
| |
|
50 |
routing table (see rtnetlink(7)). |
| |
|
51 |
|
| |
|
52 |
|
| |
|
53 |
__NETLINK_FIREWALL__ |
| |
|
54 |
|
| |
|
55 |
|
| |
|
56 |
Receives packets sent by the IPv4 firewall |
| |
|
57 |
code. |
| |
|
58 |
|
| |
|
59 |
|
| |
|
60 |
__NETLINK_ARPD__ |
| |
|
61 |
|
| |
|
62 |
|
| |
|
63 |
For managing the arp table in user space. |
| |
|
64 |
|
| |
|
65 |
|
| |
|
66 |
__NETLINK_ROUTE6__ |
| |
|
67 |
|
| |
|
68 |
|
| |
|
69 |
Receives and sends IPv6 routing table updates. |
| |
|
70 |
|
| |
|
71 |
|
| |
|
72 |
__NETLINK_IP6_FW__ |
| |
|
73 |
|
| |
|
74 |
|
| |
|
75 |
to receive packets that failed the IPv6 firewall checks |
| |
|
76 |
(currently not implemented). |
| |
|
77 |
|
| |
|
78 |
|
| |
|
79 |
__NETLINK_TAPBASE__...__NETLINK_TAPBASE+15__ |
| |
|
80 |
|
| |
|
81 |
|
| |
|
82 |
are the instances of the __ethertap__ device. Ethertap is |
| |
|
83 |
a pseudo network tunnel device that allows an ethernet |
| |
|
84 |
driver to be simulated from user space. |
| |
|
85 |
|
| |
|
86 |
|
| |
|
87 |
__NETLINK_SKIP__ |
| |
|
88 |
|
| |
|
89 |
|
| |
|
90 |
Reserved for ENskip. |
| |
|
91 |
|
| |
|
92 |
|
| |
|
93 |
__NETLINK_USERSOCK__ |
| |
|
94 |
|
| |
|
95 |
|
| |
|
96 |
is reserved for future user space protocols. |
| |
|
97 |
|
| |
|
98 |
|
| |
|
99 |
Netlink messages consist of a byte stream with one or |
| |
|
100 |
multiple __nlmsghdr__ headers and associated payload. For |
| |
|
101 |
multipart messages the first and all following headers have |
| |
|
102 |
the __NLM_F_MULTI__ flag set, except for the last header |
| |
|
103 |
which has the type __NLMSG_DONE__. The byte stream should |
| |
|
104 |
only be accessed with the standard __NLMSG_*__ macros, |
| |
|
105 |
see netlink(3). |
| |
|
106 |
|
| |
|
107 |
|
| |
|
108 |
Netlink is not a reliable protocol. It tries its best to |
| |
|
109 |
deliver a message to its destination(s), but may drop |
| |
|
110 |
messages when an out of memory condition or other error |
| |
|
111 |
occurs. For reliable transfer the sender can request an |
| |
|
112 |
acknowledgement from the receiver by setting the |
| |
|
113 |
__NLM_F_ACK__ flag. An acknowledgment is an |
| |
|
114 |
__NLMSG_ERROR__ packet with the error field set to 0. The |
| |
|
115 |
application must generate acks for received messages itself. |
| |
|
116 |
The kernel tries to send an __NLMSG_ERROR__ message for |
| |
|
117 |
every failed packet. A user process should follow this |
| |
|
118 |
convention too. |
| |
|
119 |
|
| |
|
120 |
|
| |
|
121 |
Each netlink family has a set of 32 multicast groups. When |
| |
|
122 |
bind(2) is called on the socket, the __nl_groups__ |
| |
|
123 |
field in the __sockaddr_nl__ should be set to a bitmask |
| |
|
124 |
of the groups which it wishes to listen to. The default |
| |
|
125 |
value for this field is zero which means that no multicasts |
| |
|
126 |
will be received. A socket may multicast messages to any of |
| |
|
127 |
the multicast groups by setting __nl_groups__ to a |
| |
|
128 |
bitmask of the groups it wishes to send to when it calls |
| |
|
129 |
sendmsg(2) or does a connect(2). Only users |
| |
|
130 |
with an effective uid of 0 or the __CAP_NET_ADMIN__ |
| |
|
131 |
capability may send or listen to a netlink multicast group. |
| |
|
132 |
Any replies to a message received for a multicast group |
| |
|
133 |
should be sent back to the sending pid and the multicast |
| |
|
134 |
group. |
| |
|
135 |
|
| |
|
136 |
|
| |
|
137 |
struct nlmsghdr |
| |
|
138 |
{ |
| |
|
139 |
__u32 nlmsg_len; /* Length of message including header */ |
| |
|
140 |
__u16 nlmsg_type; /* Message content */ |
| |
|
141 |
__u16 nlmsg_flags;/* Additional flags */ |
| |
|
142 |
__u32 nlmsg_seq; /* Sequence number */ |
| |
|
143 |
__u32 nlmsg_pid; /* PID of the process that opened the socket */ |
| |
|
144 |
}; |
| |
|
145 |
struct nlmsgerr |
| |
|
146 |
{ |
| |
|
147 |
int error; /* negative errno or 0 for acks. */ |
| |
|
148 |
struct nlmsghdr msg; /* message header that caused the error */ |
| |
|
149 |
}; |
| |
|
150 |
|
| |
|
151 |
|
| |
|
152 |
After each __nlmsghdr__ the payload follows. |
| |
|
153 |
__nlmsg_type__ can be one of the standard message types: |
| |
|
154 |
__NLMSG_NOOP__ message is to be ignored, |
| |
|
155 |
__NLMSG_ERROR__ the message signals an error and the |
| |
|
156 |
payload contains a ''nlmsgerr'' structure, |
| |
|
157 |
__NLMSG_DONE__ message terminates a multipart |
| |
|
158 |
message, |
| |
|
159 |
|
| |
|
160 |
|
| |
|
161 |
A netlink family usually specifies more message types, see |
| |
|
162 |
the appropriate man pages for that, e.g. rtnetlink(7) |
| |
|
163 |
for ''NETLINK_ROUTE''. |
| |
|
164 |
|
| |
|
165 |
|
| |
|
166 |
Note that NLM_F_ATOMIC requires CAP_NET_ADMIN or super user rights. |
| |
|
167 |
!!ADDRESS FORMATS |
| |
|
168 |
|
| |
|
169 |
|
| |
|
170 |
The __sockaddr_nl__ structure describes a netlink client |
| |
|
171 |
in user space or in the kernel. A sockaddr_nl can be either |
| |
|
172 |
unicast (only send to one peer) or send to netlink groups |
| |
|
173 |
(nl_groups not equal 0). |
| |
|
174 |
|
| |
|
175 |
|
| |
|
176 |
struct sockaddr_nl |
| |
|
177 |
{ |
| |
|
178 |
sa_family_t nl_family; /* AF_NETLINK */ |
| |
|
179 |
unsigned short nl_pad; /* zero */ |
| |
|
180 |
pid_t nl_pid; /* process pid */ |
| |
|
181 |
__u32 nl_groups; /* multicast groups mask */ |
| |
|
182 |
}; |
| |
|
183 |
|
| |
|
184 |
|
| |
|
185 |
__nl_pid__ is the pid of the process owning the |
| |
|
186 |
destination socket, or 0 if the destination is in the |
| |
|
187 |
kernel. __nl_groups__ is a bitmask with every bit |
| |
|
188 |
representing a netlink group number. |
| |
|
189 |
!!BUGS |
| |
|
190 |
|
| |
|
191 |
|
| |
|
192 |
This man page is not complete. |
| |
|
193 |
!!NOTES |
| |
|
194 |
|
| |
|
195 |
|
| |
|
196 |
It is often better to use netlink via __libnetlink__ than |
| |
|
197 |
via the low level kernel interface. |
| |
|
198 |
!!VERSIONS |
| |
|
199 |
|
| |
|
200 |
|
| |
|
201 |
The socket interface to netlink is a new feature of Linux |
| |
|
202 |
2.2 |
| |
|
203 |
|
| |
|
204 |
|
| |
|
205 |
Linux 2.0 supported a more primitive device based netlink |
| |
|
206 |
interface (which is still available as a compatibility |
| |
|
207 |
option). This obsolete interface is not described |
| |
|
208 |
here. |
| |
|
209 |
!!SEE ALSO |
| |
|
210 |
|
| |
|
211 |
|
| |
|
212 |
cmsg(3), rtnetlink(7), |
| |
|
213 |
netlink(3) |
| |
|
214 |
|
| |
|
215 |
|
| |
|
216 |
ftp://ftp.inr.ac.ru/ip-routing/iproute2* for |
| |
|
217 |
libnetlink |
| |
|
218 |
---- |