git: edf966085e44 - stable/13 - netlink: allow creating sockets with SOCK_DGRAM.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 Jan 2023 22:12:26 UTC
The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=edf966085e44b0aefcc8cd4f74d22b1bd09d3d60 commit edf966085e44b0aefcc8cd4f74d22b1bd09d3d60 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-01-21 14:36:23 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-01-23 22:10:01 +0000 netlink: allow creating sockets with SOCK_DGRAM. Some existing applications setup Netlink socket with SOCK_DGRAM instead of SOCK_RAW. Update the manpage to clarify that the default way of creating the socket should be with SOCK_RAW. Update the code to support both SOCK_RAW and SOCK_DGRAM. Reviewed By: pauamma Differential Revision: https://reviews.freebsd.org/D38075 (cherry picked from commit 0079d177ab69168df5e103128a2b15bd8e74d4eb) --- share/man/man4/netlink.4 | 4 ++-- share/man/man4/rtnetlink.4 | 2 +- sys/netlink/netlink_domain.c | 16 +++++++++++++--- tests/sys/netlink/test_nl_core.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/share/man/man4/netlink.4 b/share/man/man4/netlink.4 index 2aa4903a4594..1894de5841fe 100644 --- a/share/man/man4/netlink.4 +++ b/share/man/man4/netlink.4 @@ -34,7 +34,7 @@ .In netlink/netlink.h .In netlink/netlink_route.h .Ft int -.Fn socket AF_NETLINK SOCK_DGRAM int family +.Fn socket AF_NETLINK SOCK_RAW "int family" .Sh DESCRIPTION Netlink is a user-kernel message-based communication protocol primarily used for network stack configuration. @@ -293,7 +293,7 @@ This is the default level, not impacting production performance. Socket events such as groups memberships, privilege checks, commands and dumps are logged. This level does not incur significant performance overhead. -.It Dv LOG_DEBUG9(9) +.It Dv LOG_DEBUG3(9) All socket events, each dumped or modified entities are logged. Turning it on may result in significant performance overhead. .El diff --git a/share/man/man4/rtnetlink.4 b/share/man/man4/rtnetlink.4 index dc40b277d934..5849508b74c2 100644 --- a/share/man/man4/rtnetlink.4 +++ b/share/man/man4/rtnetlink.4 @@ -34,7 +34,7 @@ .In netlink/netlink.h .In netlink/netlink_route.h .Ft int -.Fn socket AF_NETLINK SOCK_DGRAM NETLINK_ROUTE +.Fn socket AF_NETLINK SOCK_RAW NETLINK_ROUTE .Sh DESCRIPTION The .Dv NETLINK_ROUTE diff --git a/sys/netlink/netlink_domain.c b/sys/netlink/netlink_domain.c index 3b5e897164f8..de96818d5e35 100644 --- a/sys/netlink/netlink_domain.c +++ b/sys/netlink/netlink_domain.c @@ -721,13 +721,23 @@ struct pr_usrreqs nl_usrreqs = { static struct domain netlinkdomain; -static struct protosw netlinksw = { +static struct protosw netlinksw[] = { +{ .pr_type = SOCK_RAW, .pr_domain = &netlinkdomain, .pr_protocol = 0, // IPPROTO_UDP .pr_flags = PR_ATOMIC | PR_ADDR | PR_WANTRCVD, .pr_ctloutput = nl_ctloutput, .pr_usrreqs = &nl_usrreqs, +}, +{ + .pr_type = SOCK_DGRAM, + .pr_domain = &netlinkdomain, + .pr_protocol = 0, // IPPROTO_UDP + .pr_flags = PR_ATOMIC | PR_ADDR | PR_WANTRCVD, + .pr_ctloutput = nl_ctloutput, + .pr_usrreqs = &nl_usrreqs, +} }; static struct domain netlinkdomain = { @@ -736,8 +746,8 @@ static struct domain netlinkdomain = { #ifdef DOMF_UNLOADABLE .dom_flags = DOMF_UNLOADABLE, #endif - .dom_protosw = &netlinksw, - .dom_protoswNPROTOSW = (&netlinksw + 1), + .dom_protosw = &netlinksw[0], + .dom_protoswNPROTOSW = (&netlinksw[0] + 2), }; DOMAIN_SET(netlink); diff --git a/tests/sys/netlink/test_nl_core.py b/tests/sys/netlink/test_nl_core.py new file mode 100644 index 000000000000..7af421a929dc --- /dev/null +++ b/tests/sys/netlink/test_nl_core.py @@ -0,0 +1,33 @@ +import errno +import socket + +import pytest +from atf_python.sys.net.netlink import NetlinkTestTemplate +from atf_python.sys.net.netlink import NlConst +from atf_python.sys.net.vnet import SingleVnetTestTemplate + + +class TestNlCore(NetlinkTestTemplate, SingleVnetTestTemplate): + @pytest.mark.parametrize( + "params", + [ + pytest.param({"type": socket.SOCK_RAW}, id="SOCK_RAW"), + pytest.param({"type": socket.SOCK_DGRAM}, id="SOCK_DGRAM"), + ], + ) + def test_socket_type(self, params): + s = socket.socket(NlConst.AF_NETLINK, params["type"], NlConst.NETLINK_ROUTE) + s.close() + + @pytest.mark.parametrize( + "params", + [ + pytest.param({"type": socket.SOCK_STREAM}, id="SOCK_STREAM"), + pytest.param({"type": socket.SOCK_RDM}, id="SOCK_RDM"), + pytest.param({"type": socket.SOCK_SEQPACKET}, id="SOCK_SEQPACKET"), + ], + ) + def test_socket_type_unsup(self, params): + with pytest.raises(OSError) as exc_info: + socket.socket(NlConst.AF_NETLINK, params["type"], NlConst.NETLINK_ROUTE) + assert exc_info.value.errno == errno.EPROTOTYPE