2 .\" Copyright (C) 2022 Alexander Chernikov <melifaro@FreeBSD.org>.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .Nd Network configuration-specific Netlink family
33 .In netlink/netlink_route.h
35 .Fn socket AF_NETLINK SOCK_RAW NETLINK_ROUTE
39 family aims to be the primary configuration mechanism for all
40 network-related tasks.
41 Currently it supports configuring interfaces, interface addresses, routes,
42 nexthops and arp/ndp neighbors.
44 All route configuration messages share the common header:
47 unsigned char rtm_family; /* address family */
48 unsigned char rtm_dst_len; /* Prefix length */
49 unsigned char rtm_src_len; /* Deprecated, set to 0 */
50 unsigned char rtm_tos; /* Type of service (not used) */
51 unsigned char rtm_table; /* deprecated, set to 0 */
52 unsigned char rtm_protocol; /* Routing protocol id (RTPROT_) */
53 unsigned char rtm_scope; /* Route distance (RT_SCOPE_) */
54 unsigned char rtm_type; /* Route type (RTN_) */
55 unsigned rtm_flags; /* Route flags (not supported) */
61 specifies the route family to be operated on.
66 are the only supported families.
67 The route prefix length is stored in
70 The caller should set the originator identity (one of the
75 It is useful for users and for the application itself, allowing for easy
76 identification of self-originated routes.
77 The route scope has to be set via
80 The supported values are:
81 .Bd -literal -offset indent -compact
82 RT_SCOPE_UNIVERSE Global scope
83 RT_SCOPE_LINK Link scope
86 Route type needs to be set.
87 The defined values are:
88 .Bd -literal -offset indent -compact
89 RTN_UNICAST Unicast route
90 RTN_MULTICAST Multicast route
91 RTN_BLACKHOLE Drops traffic towards destination
92 RTN_PROHIBIT Drops traffic and sends reject
95 The following messages are supported:
98 All NL flags are supported.
99 Extending a multipath route requires NLM_F_APPEND flag.
101 Tries to delete a route.
102 The route is specified using a combination of
107 Fetches a single route or all routes in the current VNET, depending on the
110 Each route is reported as
113 The following filters are recognised by the kernel:
115 .Bd -literal -offset indent -compact
116 rtm_family required family or AF_UNSPEC
117 RTA_TABLE fib number or RT_TABLE_UNSPEC to return all fibs
120 .Bl -tag -width indent
122 (binary) IPv4/IPv6 address, depending on the
125 (uint32_t) transmit interface index.
127 (binary) IPv4/IPv6 gateway address, depending on the
130 (nested) Container attribute, listing route properties.
131 The only supported sub-attribute is
132 .Dv RTAX_MTU , which stores path MTU as uint32_t.
134 This attribute contains multipath route nexthops with their weights.
135 These nexthops are represented as a sequence of
137 structures, each followed by
144 unsigned short rtnh_len;
145 unsigned char rtnh_flags;
146 unsigned char rtnh_hops; /* nexthop weight */
153 field specifies the total nexthop info length, including both
155 and the following TLVs.
158 field stores relative nexthop weight, used for load balancing between group
162 field contains the index of the transmit interface.
164 The following TLVs can follow the structure:
165 .Bd -literal -offset indent -compact
166 RTA_GATEWAY IPv4/IPv6 nexthop address of the gateway
167 RTA_VIA IPv6 nexthop address for IPv4 route
168 RTA_KNH_ID Kernel-specific index of the nexthop
171 (uint32_t) (FreeBSD-specific) Auto-allocated kernel index of the nexthop.
173 (uint32_t) (FreeBSD-specific) rtsock route flags.
175 (uint32_t) Fib number of the route.
176 Default route table is
178 To explicitely specify "all tables" one needs to set the value to
179 .Dv RT_TABLE_UNSPEC .
181 (uint32_t) seconds till path expiration.
183 (uint32_t) useland nexthop or nexthop group index.
186 The following groups are defined:
187 .Bd -literal -offset indent -compact
188 RTNLGRP_IPV4_ROUTE Notifies on IPv4 route arrival/removal/change
189 RTNLGRP_IPV6_ROUTE Notifies on IPv6 route arrival/removal/change
192 All nexthop/nexthop group configuration messages share the common header:
195 unsigned char nh_family; /* transport family */
196 unsigned char nh_scope; /* ignored on RX, filled by kernel */
197 unsigned char nh_protocol; /* Routing protocol that installed nh */
199 unsigned int nh_flags; /* RTNH_F_* flags from route.h */
204 specificies the gateway address family.
205 It can be different from route address family for IPv4 routes with IPv6
211 field, which designates originator application identity.
213 The following messages are supported:
215 Creates a new nexthop or nexthop group.
217 Deletes nexthop or nexthhop group.
218 The required object is specified by the
222 Fetches a single nexthop or all nexthops/nexthop groups, depending on the
225 The following filters are recognised by the kernel:
227 .Bd -literal -offset indent -compact
228 RTA_NH_ID nexthop or nexthtop group id
229 NHA_GROUPS match only nexthtop groups
232 .Bl -tag -width indent
234 (uint32_t) Nexthhop index used to identify particular nexthop or nexthop group.
235 Should be provided by userland at the nexthtop creation time.
237 This attribute designates the nexthtop group and contains all of its nexthtops
238 and their relative weights.
239 The attribute constists of a list of
244 uint32_t id; /* nexhop userland index */
245 uint8_t weight; /* weight of this nexthop */
250 .It Dv NHA_GROUP_TYPE
251 (uint16_t) Nexthtop group type, set to one of the following types:
252 .Bd -literal -offset indent -compact
253 NEXTHOP_GRP_TYPE_MPATH default multipath group
256 (flag) Marks the nexthtop as blackhole.
258 (uint32_t) Transmit interface index of the nexthtop.
260 (binary) IPv4/IPv6 gateway address
262 (flag) Matches nexthtop groups during dump.
265 The following groups are defined:
266 .Bd -literal -offset indent -compact
267 RTNLGRP_NEXTHOP Notifies on nexthop/groups arrival/removal/change
270 All interface configuration messages share the common header:
273 unsigned char ifi_family; /* not used, set to 0 */
274 unsigned char __ifi_pad;
275 unsigned short ifi_type; /* ARPHRD_* */
276 int ifi_index; /* Inteface index */
277 unsigned ifi_flags; /* IFF_* flags */
278 unsigned ifi_change; /* IFF_* change mask */
282 Creates a new interface.
283 The only mandatory TLV is
285 The following attributes are returned inside the nested
286 .Dv NLMSGERR_ATTR_COOKIE :
288 .Bd -literal -offset indent -compact
289 IFLA_NEW_IFINDEX (uint32) created interface index
290 IFLA_IFNAME (string) created interface name
293 Deletes the interface specified by
296 Fetches a single interface or all interfaces in the current VNET, depending on the
299 Each interface is reported as a
302 The following filters are recognised by the kernel:
304 .Bd -literal -offset indent -compact
305 ifi_index interface index
306 IFLA_IFNAME interface name
307 IFLA_ALT_IFNAME interface name
310 .Bl -tag -width indent
312 (binary) Llink-level interface address (MAC).
313 .It Dv IFLA_BROADCAST
314 (binary) (readonly) Link-level broadcast address.
316 (string) New interface name.
318 (string) Interface description.
320 (uint32_t) (readonly) Interface index.
322 (uint32_t) Parent interface index.
324 (nested) Interface type-specific attributes:
325 .Bd -literal -offset indent -compact
326 IFLA_INFO_KIND (string) interface type ("vlan")
327 IFLA_INFO_DATA (nested) custom attributes
329 The following types and attributes are supported:
330 .Bl -tag -width indent
332 .Bd -literal -offset indent -compact
333 IFLA_VLAN_ID (uint16_t) 802.1Q vlan id
334 IFLA_VLAN_PROTOCOL (uint16_t) Protocol: ETHERTYPE_VLAN or ETHERTYPE_QINQ
337 .It Dv IFLA_OPERSTATE
338 (uint8_t) Interface operational state per RFC 2863.
339 Can be one of the following:
340 .Bd -literal -offset indent -compact
341 IF_OPER_UNKNOWN status can not be determined
342 IF_OPER_NOTPRESENT some (hardware) component not present
344 IF_OPER_LOWERLAYERDOWN some lower-level interface is down
345 IF_OPER_TESTING in some test mode
346 IF_OPER_DORMANT "up" but waiting for some condition (802.1X)
347 IF_OPER_UP ready to pass packets
350 (readonly) Consists of the following 64-bit counters structure:
352 struct rtnl_link_stats64 {
353 uint64_t rx_packets; /* total RX packets (IFCOUNTER_IPACKETS) */
354 uint64_t tx_packets; /* total TX packets (IFCOUNTER_OPACKETS) */
355 uint64_t rx_bytes; /* total RX bytes (IFCOUNTER_IBYTES) */
356 uint64_t tx_bytes; /* total TX bytes (IFCOUNTER_OBYTES) */
357 uint64_t rx_errors; /* RX errors (IFCOUNTER_IERRORS) */
358 uint64_t tx_errors; /* RX errors (IFCOUNTER_OERRORS) */
359 uint64_t rx_dropped; /* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
360 uint64_t tx_dropped; /* TX drop (IFCOUNTER_OQDROPS) */
361 uint64_t multicast; /* RX multicast packets (IFCOUNTER_IMCASTS) */
362 uint64_t collisions; /* not supported */
363 uint64_t rx_length_errors; /* not supported */
364 uint64_t rx_over_errors; /* not supported */
365 uint64_t rx_crc_errors; /* not supported */
366 uint64_t rx_frame_errors; /* not supported */
367 uint64_t rx_fifo_errors; /* not supported */
368 uint64_t rx_missed_errors; /* not supported */
369 uint64_t tx_aborted_errors; /* not supported */
370 uint64_t tx_carrier_errors; /* not supported */
371 uint64_t tx_fifo_errors; /* not supported */
372 uint64_t tx_heartbeat_errors; /* not supported */
373 uint64_t tx_window_errors; /* not supported */
374 uint64_t rx_compressed; /* not supported */
375 uint64_t tx_compressed; /* not supported */
376 uint64_t rx_nohandler; /* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
381 The following groups are defined:
382 .Bd -literal -offset indent -compact
383 RTNLGRP_LINK Notifies on interface arrival/removal/change
385 .Sh INTERFACE ADDRESSES
386 All interface address configuration messages share the common header:
389 uint8_t ifa_family; /* Address family */
390 uint8_t ifa_prefixlen; /* Prefix length */
391 uint8_t ifa_flags; /* Address-specific flags */
392 uint8_t ifa_scope; /* Address scope */
393 uint32_t ifa_index; /* Link ifindex */
399 specifies the address family of the interface address.
402 specifies the prefix length if applicable for the address family.
405 specifies the interface index of the target interface.
411 Fetches interface addresses in the current VNET matching conditions.
412 Each address is reported as a
415 The following filters are recognised by the kernel:
417 .Bd -literal -offset indent -compact
418 ifa_family required family or AF_UNSPEC
419 ifa_index matching interface index or 0
422 .Bl -tag -width indent
424 (binary) masked interface address or destination address for p2p interfaces.
426 (binary) local interface address.
427 Set for IPv4 and p2p addresses.
429 (string) interface name.
431 (binary) broacast interface address.
434 The following groups are defined:
435 .Bd -literal -offset indent -compact
436 RTNLGRP_IPV4_IFADDR Notifies on IPv4 ifaddr arrival/removal/change
437 RTNLGRP_IPV6_IFADDR Notifies on IPv6 ifaddr arrival/removal/change
440 All neighbor configuration messages share the common header:
455 field specifies the address family (IPv4 or IPv6) of the neighbor.
458 specifies the interface to operate on.
461 represents the entry state according to the neighbor model.
462 The state can be one of the following:
463 .Bd -literal -offset indent -compact
464 NUD_INCOMPLETE No lladdr, address resolution in progress
465 NUD_REACHABLE reachable & recently resolved
466 NUD_STALE has lladdr but it's stale
467 NUD_DELAY has lladdr, is stale, probes delayed
468 NUD_PROBE has lladdr, is stale, probes sent
474 field stores the options specific to this entry.
476 .Bd -literal -offset indent -compact
477 NTF_SELF local station (LLE_IFADDR)
478 NTF_PROXY proxy entry (LLE_PUB)
479 NTF_STICKY permament entry (LLE_STATIC)
480 NTF_ROUTER dst indicated itself as a router
483 Creates new neighbor entry.
484 The mandatory options are
490 Deletes the neighbor entry.
491 The entry is specified by the combination of
496 Fetches a single neighbor or all neighbors in the current VNET, depending on the
499 Each entry is reported as
502 The following filters are recognised by the kernel:
504 .Bd -literal -offset indent -compact
505 ndm_family required family or AF_UNSPEC
506 ndm_ifindex target ifindex
507 NDA_IFINDEX target ifindex
510 .Bl -tag -width indent
512 (binary) neighbor IPv4/IPv6 address.
514 (binary) neighbor link-level address.
516 (uint32_t) interface index.
518 (uint32_t) extended version of
522 The following groups are defined:
523 .Bd -literal -offset indent -compact
524 RTNLGRP_NEIGH Notifies on ARP/NDP neighbor arrival/removal/change
532 protocol family appeared in
535 The netlink was implementated by
537 .An Alexander Chernikov Aq Mt melifaro@FreeBSD.org .
538 It was derived from the Google Summer of Code 2021 project by
539 .An Ng Peng Nam Sean .