<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/sys/compat/linux/linux_netlink.c, branch releng/15.0</title>
<subtitle>FreeBSD source tree</subtitle>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/'/>
<entry>
<title>Revert "linux: fix reporting NL_RTM_DELLINK to Netlink sockets"</title>
<updated>2025-09-22T16:11:33+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2025-09-11T21:02:51+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=418bf338747ad470ad91fbfe4f2767ab820dc988'/>
<id>418bf338747ad470ad91fbfe4f2767ab820dc988</id>
<content type='text'>
I received a report that certain Linux application would crash on a
message of a departure of an interface with FreeBSD name.  Looks like
dropping NL_RTM_DELLINK is a lesser evil than relay them with FreeBSD
names.

This reverts commit 554907bac3b264863a051f75eedc35d180d3e18c.

(cherry picked from commit 1014003c538ccf8b258c9f0b11c0c131573a63cf)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
I received a report that certain Linux application would crash on a
message of a departure of an interface with FreeBSD name.  Looks like
dropping NL_RTM_DELLINK is a lesser evil than relay them with FreeBSD
names.

This reverts commit 554907bac3b264863a051f75eedc35d180d3e18c.

(cherry picked from commit 1014003c538ccf8b258c9f0b11c0c131573a63cf)
</pre>
</div>
</content>
</entry>
<entry>
<title>netlink: do not pass writer to the Linux translation layer</title>
<updated>2025-08-22T16:23:38+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2025-08-22T16:23:38+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=0d9ef08e099f6837de5a40fd582d9ffb01fd31a4'/>
<id>0d9ef08e099f6837de5a40fd582d9ffb01fd31a4</id>
<content type='text'>
Another flaw in the KPI between Netlink and Linuxulator is that we pass
the on-stack writer structure.  This structure belongs to someone, that we
can't even identify inside nl_send() and we shall not tamper it.  The
Linux translation layer needs a writer, because it actually composes a new
message.  Instead of reusing someone's writer and trying to repair it in
all possible cases where translation process tampers the writer, just let
Linuxulator use its own writer.  See also b977dd1ea5fb.

PR:			288892
Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D51928
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Another flaw in the KPI between Netlink and Linuxulator is that we pass
the on-stack writer structure.  This structure belongs to someone, that we
can't even identify inside nl_send() and we shall not tamper it.  The
Linux translation layer needs a writer, because it actually composes a new
message.  Instead of reusing someone's writer and trying to repair it in
all possible cases where translation process tampers the writer, just let
Linuxulator use its own writer.  See also b977dd1ea5fb.

PR:			288892
Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D51928
</pre>
</div>
</content>
</entry>
<entry>
<title>linux: fix reporting NL_RTM_DELLINK to Netlink sockets</title>
<updated>2025-08-22T16:23:28+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2025-08-22T16:23:28+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=554907bac3b264863a051f75eedc35d180d3e18c'/>
<id>554907bac3b264863a051f75eedc35d180d3e18c</id>
<content type='text'>
The problem is that ifname_bsd_to_linux_name() requires the interface to
exist.  But when we are in the context of ifnet_departure_event
EVENTHANDLER(9), it does not.  Instead of silently dropping the message,
let's send the FreeBSD name verbatim.  At the moment special translation
is done for IFT_LOOPBACK and IFT_ETHER only, and these two kinds of
interfaces usually don't depart.  So, this is not a final fix, but
definitely an improvement.  While here, simplify the associated code.

Differential Revision:	https://reviews.freebsd.org/D51927
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The problem is that ifname_bsd_to_linux_name() requires the interface to
exist.  But when we are in the context of ifnet_departure_event
EVENTHANDLER(9), it does not.  Instead of silently dropping the message,
let's send the FreeBSD name verbatim.  At the moment special translation
is done for IFT_LOOPBACK and IFT_ETHER only, and these two kinds of
interfaces usually don't depart.  So, this is not a final fix, but
definitely an improvement.  While here, simplify the associated code.

Differential Revision:	https://reviews.freebsd.org/D51927
</pre>
</div>
</content>
</entry>
<entry>
<title>linux: allow RTM_GETADDR without full ifaddrmsg argument</title>
<updated>2024-05-28T20:13:08+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2024-05-28T20:13:08+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=2780e5f43d5b0e8b155472300ee63816a660780e'/>
<id>2780e5f43d5b0e8b155472300ee63816a660780e</id>
<content type='text'>
Even modern glibc uses truncated argument for RTM_GETADDR when it wants to
list all addresses in a system.  See
sysdeps/unix/sysv/linux/ifaddrs.c:__netlink_sendreq().  It sends a one
char payload.  Linux kernel allows that as long as given socket is not
marked as a 'strict'.  We have a similar flag in the general netlink code
and it is checked in
sys/netlink/netlink_message_parser.h:nl_parse_header().  If the flag is
not present, parser will allocate a temporary zeroed buffer to make the
message correct.  The checks added in b977dd1ea5fb blocked such message
before the parser.  My reading of glibc says that there are two types of
messages that are sent with __netlink_sendreq() - RTM_GETLINK and
RTM_GETADDR.  The RTM_GETLINK is binary compatible between Linux and
FreeBSD and thus doesn't need any ABI handler.

PR:		279012
Fixes:		b977dd1ea5fbc2df3f1279330be4d089322eb2cf
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Even modern glibc uses truncated argument for RTM_GETADDR when it wants to
list all addresses in a system.  See
sysdeps/unix/sysv/linux/ifaddrs.c:__netlink_sendreq().  It sends a one
char payload.  Linux kernel allows that as long as given socket is not
marked as a 'strict'.  We have a similar flag in the general netlink code
and it is checked in
sys/netlink/netlink_message_parser.h:nl_parse_header().  If the flag is
not present, parser will allocate a temporary zeroed buffer to make the
message correct.  The checks added in b977dd1ea5fb blocked such message
before the parser.  My reading of glibc says that there are two types of
messages that are sent with __netlink_sendreq() - RTM_GETLINK and
RTM_GETADDR.  The RTM_GETLINK is binary compatible between Linux and
FreeBSD and thus doesn't need any ABI handler.

PR:		279012
Fixes:		b977dd1ea5fbc2df3f1279330be4d089322eb2cf
</pre>
</div>
</content>
</entry>
<entry>
<title>linux: make linux_netlink_p-&gt;msg_from_linux be able to fail</title>
<updated>2024-03-29T20:35:51+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2024-03-29T20:35:51+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=b977dd1ea5fbc2df3f1279330be4d089322eb2cf'/>
<id>b977dd1ea5fbc2df3f1279330be4d089322eb2cf</id>
<content type='text'>
The KPI for this function was misleading.  From the NetLink perspective it
looked like a function that: a) allocates new hdr, b) can fail.  Neither
was true.  Let the function return a error code instead of returning the
same hdr it was passed to.  In case if future Linux NetLink compatibility
support calls for reallocating header, pass hdr as pointer to pointer.

With KPI that returns a error, propagate domain conversion errors all the
way up to NetLink module.  This fixes panic when unknown domain is
converted to 0xff and this invalid value is passed into NetLink
processing.

PR:			274536
Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D44392
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The KPI for this function was misleading.  From the NetLink perspective it
looked like a function that: a) allocates new hdr, b) can fail.  Neither
was true.  Let the function return a error code instead of returning the
same hdr it was passed to.  In case if future Linux NetLink compatibility
support calls for reallocating header, pass hdr as pointer to pointer.

With KPI that returns a error, propagate domain conversion errors all the
way up to NetLink module.  This fixes panic when unknown domain is
converted to 0xff and this invalid value is passed into NetLink
processing.

PR:			274536
Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D44392
</pre>
</div>
</content>
</entry>
<entry>
<title>netlink: restore original buffer if nlmsgs_to_linux() fails</title>
<updated>2024-02-27T20:45:54+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2024-02-27T20:45:54+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=41ce9c8b8891eee82b2824c733f103e6671b5731'/>
<id>41ce9c8b8891eee82b2824c733f103e6671b5731</id>
<content type='text'>
Caller is responsible to free it or reuse.

Fixes:	17083b94a91563aba15ba03d1c74796a35bb1c26
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Caller is responsible to free it or reuse.

Fixes:	17083b94a91563aba15ba03d1c74796a35bb1c26
</pre>
</div>
</content>
</entry>
<entry>
<title>netlink: use protocol specific receive buffer</title>
<updated>2024-01-02T21:04:01+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2024-01-02T21:04:01+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=17083b94a91563aba15ba03d1c74796a35bb1c26'/>
<id>17083b94a91563aba15ba03d1c74796a35bb1c26</id>
<content type='text'>
Implement Netlink socket receive buffer as a simple TAILQ of nl_buf's,
same part of struct sockbuf that is used for send buffer already.
This shaves a lot of code and a lot of extra processing.  The pcb rids
of the I/O queues as the socket buffer is exactly the queue.  The
message writer is simplified a lot, as we now always deal with linear
buf.  Notion of different buffer types goes away as way as different
kinds of writers.  The only things remaining are: a socket writer and
a group writer.
The impact on the network stack is that we no longer use mbufs, so
a workaround from d18715475071 disappears.

Note on message throttling.  Now the taskqueue throttling mechanism
needs to look at both socket buffers protected by their respective
locks and on flags in the pcb that are protected by the pcb lock.
There is definitely some room for optimization, but this changes tries
to preserve as much as possible.

Note on new nl_soreceive().  It emulates soreceive_generic().  It
must undergo further optimization, see large comment put in there.

Note on tests/sys/netlink/test_netlink_message_writer.py. This test
boiled down almost to nothing with mbufs removed.  However, I left
it with minimal functionality (it basically checks that allocating N
bytes we get N bytes) as it is one of not so many examples of ktest
framework that allows to test KPIs with python.

Note on Linux support. It got much simplier: Netlink message writer
loses notion of Linux support lifetime, it is same regardless of
process ABI.  On socket write from Linux process we perform
conversion immediately in nl_receive_message() and on an output
conversion to Linux happens in in nl_send_one(). XXX: both
conversions use M_NOWAIT allocation, which used to be the case
before this change, too.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D42524
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Implement Netlink socket receive buffer as a simple TAILQ of nl_buf's,
same part of struct sockbuf that is used for send buffer already.
This shaves a lot of code and a lot of extra processing.  The pcb rids
of the I/O queues as the socket buffer is exactly the queue.  The
message writer is simplified a lot, as we now always deal with linear
buf.  Notion of different buffer types goes away as way as different
kinds of writers.  The only things remaining are: a socket writer and
a group writer.
The impact on the network stack is that we no longer use mbufs, so
a workaround from d18715475071 disappears.

Note on message throttling.  Now the taskqueue throttling mechanism
needs to look at both socket buffers protected by their respective
locks and on flags in the pcb that are protected by the pcb lock.
There is definitely some room for optimization, but this changes tries
to preserve as much as possible.

Note on new nl_soreceive().  It emulates soreceive_generic().  It
must undergo further optimization, see large comment put in there.

Note on tests/sys/netlink/test_netlink_message_writer.py. This test
boiled down almost to nothing with mbufs removed.  However, I left
it with minimal functionality (it basically checks that allocating N
bytes we get N bytes) as it is one of not so many examples of ktest
framework that allows to test KPIs with python.

Note on Linux support. It got much simplier: Netlink message writer
loses notion of Linux support lifetime, it is same regardless of
process ABI.  On socket write from Linux process we perform
conversion immediately in nl_receive_message() and on an output
conversion to Linux happens in in nl_send_one(). XXX: both
conversions use M_NOWAIT allocation, which used to be the case
before this change, too.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D42524
</pre>
</div>
</content>
</entry>
<entry>
<title>netlink: move NETLINK define to opt_global.h</title>
<updated>2023-10-13T07:23:47+00:00</updated>
<author>
<name>Kristof Provost</name>
<email>kp@FreeBSD.org</email>
</author>
<published>2023-10-12T19:55:57+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=ab393e9548f8cc0ee28499c411963b798ebb38a5'/>
<id>ab393e9548f8cc0ee28499c411963b798ebb38a5</id>
<content type='text'>
Move the NETLINK define into opt_global.h so we can rely on it being
set correctly, without having to remember to include opt_netlink.h.
This ensures that the NETLINK define is correctly set. If not we
may end up with unloadable modules, due to missing symbols (such as
nlmsg_get_group_writer).

PR:		274306
Reviewed by:	imp, markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42179
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Move the NETLINK define into opt_global.h so we can rely on it being
set correctly, without having to remember to include opt_netlink.h.
This ensures that the NETLINK define is correctly set. If not we
may end up with unloadable modules, due to missing symbols (such as
nlmsg_get_group_writer).

PR:		274306
Reviewed by:	imp, markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42179
</pre>
</div>
</content>
</entry>
<entry>
<title>linux(4): Remove sys/cdefs.h inclusion where it's not needed due to 685dc743</title>
<updated>2023-08-18T10:12:02+00:00</updated>
<author>
<name>Dmitry Chagin</name>
<email>dchagin@FreeBSD.org</email>
</author>
<published>2023-08-18T10:12:02+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=3460fab5fced39c7ea597cc7de0ebc3e4c88989a'/>
<id>3460fab5fced39c7ea597cc7de0ebc3e4c88989a</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>sys: Remove $FreeBSD$: one-line .c pattern</title>
<updated>2023-08-16T17:54:36+00:00</updated>
<author>
<name>Warner Losh</name>
<email>imp@FreeBSD.org</email>
</author>
<published>2023-08-16T17:54:36+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=685dc743dc3b5645e34836464128e1c0558b404b'/>
<id>685dc743dc3b5645e34836464128e1c0558b404b</id>
<content type='text'>
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
</pre>
</div>
</content>
</entry>
</feed>
