History log of /freebsd-current/sys/netlink/netlink_snl.h
Revision Date Author Comments
# ff92493a 17-May-2024 cnbatch <cnbatch@gmail.com>

netlink: Fix C++ compile errors

Allow these files to be included in C++ programs with careful casting to
the proper type, like C++ wants (and in a way that also works for C).

MFC After: 1 week
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1245


# 5824df8d 23-Mar-2024 Kristof Provost <kp@FreeBSD.org>

pf: convert DIOCGETSTATUS to netlink

Introduce pfctl_get_status_h() because we need the pfctl_handle. In this variant
use netlink to obtain the information.

Sponsored by: Rubicon Communications, LLC ("Netgate")


# dfed87b5 26-Feb-2024 Kristof Provost <kp@FreeBSD.org>

netlink: add bool type support

Reviewed by: melifaro
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D44089


# 69945c49 27-Feb-2024 John Baldwin <jhb@FreeBSD.org>

netlink: Don't use a zero-length array

Define SNL_DECLARE_FIELD_PARSER* macros to create a parser that has
no output attributes only input fields and use this to define the
snl_donemsg_parser.

This removes the need for the zero-length nla_p_donemsg[] variable.
Zero length arrays are not valid in ISO C.

Reviewed by: jrtc27, melifaro
Differential Revision: https://reviews.freebsd.org/D43918


# 777a4702 12-Jan-2024 Kristof Provost <kp@FreeBSD.org>

pf: implement addrule via netlink

Sponsored by: Rubicon Communications, LLC ("Netgate")


# 0c511baf 12-Dec-2023 Igor Ostapenko <pm@igoro.pro>

netlink: fix snl_writer and linear_buffer re-allocation logic

- Use the correct base pointer after re-allocation to avoid buffer
overflows.

- Maintain correct snl_writer.size, which avoids redundant memory
allocation, e.g. a need for ~1k bytes may end up with ~32k
linear_buffer actually allocated.

This fixes a pfctl regression at least for armv7 after the addrule logic
migration to netlink:
ffbf25951e7b ("pf: convert rule addition to netlink")

The add rule command creates a bigger than default size netlink requests
which triggers the re-allocation logic.

Reviewed by: kp
MFC after: 2 weeks
Differnetial Revision: https://reviews.freebsd.org/D43003


# 9795f14e 10-Aug-2023 John Baldwin <jhb@FreeBSD.org>

netlink: Align allocations on __max_align_t, not uint64_t.

uint64_t is not sufficient alignment for allocators on all platforms.
On a CHERI platform pointers require 16 byte alignment, but also if a
type contained a uint128_t or long double it would not be aligned
correctly either. C11 added max_align_t precisely to provide a
portable type for allocators to use.

Reviewed by: melifaro
Obtained from: CheriBSD
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D41301


# c344eff9 16-Jun-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: dump interface capabilities with other interface data.

This change exports interface capabilities using the standard
Netlink attribute type, bitset, and switches `ifconfig(8)` to use
it when displaying interface data.
Bitset comes in two representations. The first one is "compact",
where the bits are exported via two arrays - "mask" listing the
"valid" bits and "values, providing the values for those bits.
The second one is more verbose, listing each bit as a separate item,
with its name, id and value. The latter option is handy when submitting
update requests.

The support for setting capabilities will be added in the upcoming diffs.

Differential Revision: https://reviews.freebsd.org/D40331


# 5f19f790 27-May-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: add snl(3) support for parsing unknown-size arrays

Reviewed by: bapt
Differential Review: https://reviews.freebsd.org/D40282
MFC after: 2 weeks


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 88bd9ef6 09-May-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: automatically fill sin6_scope_id in the default snl(3) parsers.

Add the optional post-parse hook to the snl(3) parser declaration.
Use this hook to automatically add the interface indexes to the
link-local sockaddrs.

MFC after: 2 weeks


# ba9c815d 09-May-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: use consistent variable lifetime in the default snl(3) parsers.

Currently, parsers use original strings/nla pointers instead of
duplicating them. These pointers refer to the temporary packet buffer,
which can be silently rewritten when the next message is read.
Instead, duplicate all string/nla attributes using snl_allocz(3) to
give control over variable lifetime to the user.

MFC after: 2 weeks


# 6a23843a 28-Apr-2023 Kristof Provost <kp@FreeBSD.org>

libifconfig: fix carp key configuration

There were two issues with the carp key configuration in the new netlink
code.

The first is that userspace failed to actually pass the CARP_NL_KEY
attribute to the kernel, so a key was never set.

The second issue is that snl_attr_get_string() returns a pointer to the
string inside the netlink message. It does not copy the string to the
target buffer. That's somewhat inconvenient to work with in libifconfig
where we have a static buffer for the key.
Introduce snl_attr_copy_string() which can copy a string to a target
buffer and uses the 'arg' parameter to pass the buffer size, so it
doesn't accidentally exceed the available space.

Reviewed by: melifaro
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D39874


# 30d7e724 27-Apr-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

route: show originator PID in netlink monitor

Replacing rtsock with netlink also means providing similar tracing facilities,
rtsock provides `route -n monitor` interface, where each message can be traced
to the originating PID.
This diff closes the feature gap between rtsock and netlink in that regard.

Netlink works slightly differently from rtsock, as it is a generic message
"broker". It calls some kernel KPIs and returns the result to the caller.
Other Netlink consumers gets notified on the changed kernel state using the
relevant subsystem callbacks. Typically, it is close to impossible to pass
some data through these KPIs to enhance the notification.

This diff approaches the problem by using osd(9) to assign the relevant
socket pointer (`'nlp`) to the per-socket taskqueue execution thread.
This change allows to recover the pointer in the aforementioned notification
callbacks and extract some additional data.
Using `osd(9)` (and adding additional metadata) to the notification receiver
comes with some additional cost attached, so this interface needs to be
enabled explicitly by using a newly-created `NETLINK_MSG_INFO` `SOL_NETLINK`
socket option.

The actual medatadata (which includes the originator PID) is provided via
control messages. To enable extensibility, the control message data is
encoded in the standard netlink(TLV-based) fashion. The list of the
currently-provided properties can be found in `nlmsginfo_attrs`.
snl(3) is extended to enable decoding of netlink messages with metadata
(`snl_read_message_dbg()` stores the parsed structure in the provided buffer).

Differential Revision: https://reviews.freebsd.org/D39391


# e83f23eb 25-Apr-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: enable extended error reporting in snl(3).

MFC after: 2 weeks


# fab828b4 25-Apr-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: fix parameters in snl_attr_get_flag()

MFC after: 2 weeks


# 27cbc1a7 01-Apr-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: fix snl_read_reply_multi().

CID: 1506956
MFC after: 2 weeks


# 13781800 15-Mar-2023 Kristof Provost <kp@FreeBSD.org>

carp: support unicast

Allow users to configure the address to send carp messages to. This
allows carp to be used in unicast mode, which is useful in certain
virtual configurations (e.g. AWS, VMWare ESXi, ...)

Reviewed by: melifaro
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D38940


# 568a645b 17-Mar-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: fix capped uncapped ack handling in snl(3).

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D39144
MFC after: 2 weeks


# 73ae25c1 15-Mar-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: improve snl(3)

Summary:
* add snl_send_message() as a convenient send wrapper
* add signed integer parsers
* add snl_read_reply_code() to simplify operation result checks
* add snl_read_reply_multi() to simplify reading multipart messages
* add snl_create_genl_msg_request()
* add snl_get_genl_family() to simplify family name->id resolution
* add tests for some of the functionality

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D39092
MFC after: 2 weeks


# da4047d3 09-Mar-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

fix buildworld after 595d23f777dc.

Reported by: se


# 595d23f7 09-Mar-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: add snl(3) default parsers for routes and links.

This change adds the "default" parsers of _all_ route/link attributes
exported by the kernel.
It removes the need to declare similar parsers in the userland applications,
simplifying their logic.

Differential Revision: https://reviews.freebsd.org/D38979
MFC after: 2 weeks


# 76f6d391 09-Mar-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: add basic message writing support to snl(3).

Differential Revision: https://reviews.freebsd.org/D38947
MFC after: 2 weeks


# 0679eb1f 08-Mar-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: make snl(3) scratch buffer growable

Differential Revision: https://reviews.freebsd.org/D38946
MFC after: 2 weeks


# 61507ae3 03-Mar-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: add u8/u64 attribute fetcher accessors to snl(3).

MFC after: 2 weeks


# 6d7da7c8 11-Feb-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

Revert "netlink: make netlink_snl(3) c++ friendly."

Was pushed accidentally.

This reverts commit 629d9219d931e63dc49ef046332b2a360e42a5f6.


# 629d9219 10-Feb-2023 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: make netlink_snl(3) c++ friendly.


# c89209c6 23-Dec-2022 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: fix test-includes broken by f2c8381fce9b

Reported by: many


# 3e387541 23-Dec-2022 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: make snl(3) headers self-contained.


# f2c8381f 18-Dec-2022 Alexander V. Chernikov <melifaro@FreeBSD.org>

netlink: add snl(3) - simple netlink library

Reviewed by: bapt, pauamma
Differential Revision: https://reviews.freebsd.org/D37736