From nobody Mon Mar 27 16:09:15 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pld6g5WfTz41jxM; Mon, 27 Mar 2023 16:09:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pld6g4zQGz4Gsn; Mon, 27 Mar 2023 16:09:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679933355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=c43Jl0ImnUC7LR8Uctkvi6czIGvwglZb7SdHaF0OpOA=; b=RAz8RwmQ+9F9VCuwuFd7MVOVISBwwzPW3djz9Gs8WB5aAqTpgFGyZJN5/Dmez8heOTDSvA mYi2J07/fzBfpP/ZUt/KCUDbzRCCswFWVnKxVakCAWNIbLth0xQxOfslW9U8LMwOtvRpkE tpta+CrLyFk2gXYxOJ0HWbwi+B5EpaQ/04LuKp3ygy57rgjXalfBUcHDgKjekJnpTIGRT3 8juVh6dY8nrvuFB2AGc//34u2Bu5PExG/EnsUv2CQAg/vPyeuKHkBiOGq6l/aP+eG+Vc4j plDAyDf/Q10YR8gxRsF2QpIs+ozp4rm1AQkXFwxsGKtI10KTymfit0Ez2XhIPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679933355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=c43Jl0ImnUC7LR8Uctkvi6czIGvwglZb7SdHaF0OpOA=; b=AUVJz+Eb2hotZzZ4bRjZVYTob+ER1SAMVq1TFXLvoH8jdP6pZilK+kyc+DrFYjb8JFybN+ DIe8ugXpGXuO40on3Di8kM3/qSQhxoI0tpq8T03zZdGWPtkVt9pST/wuDG66lLdQuXSFye JOLL6GxhhisAE2xw5KvjhDwHrW0qaR/ZcJ9+qI+gCUrIAHWptB8YJC6N+kZKYfJNF8BGgt +gWYxS43zYA/Hfqh0IBYZ+1r6L/TG3D6HXZiMmQ9xEsKXwpAhGMEzkUdi5n41ZdvrncIes VQbJhnrJoPVJ4g8UBIJIiSdw54kJ6nnKP5OZtOSCeilUyUXcT0ROme7Hdc7gSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679933355; a=rsa-sha256; cv=none; b=UzadHwZp4dzrj62AfAsJM+7XOc9CizjY7hD00IAAzfXZSoBlCjtI8Djq29L0+x22J41+4W nIlB3mj2NROKCZyw5QawLbYO7ZnCaRnnozm9lU80QR4vNlbKGb3OU5edUpN5GvTEYlYKme R7aTdejvw4v/j/QIip4WsQ3K4/jd2yYZ5B6N2SqZMY8VByO8iCwxWeKh7XwTnJW+FKkyP+ itiuZV68lcuLpGBp6pV3yy+R77loycjaXnkEO2G/ma+y8/cKZUomYYWq1CoHyQ4Ua/DpZJ rFRvVU/OR/pMP89Gl6fOisTQQkpbVj+HKSxECgw78d9zePu0qPo49IOxAI0o2w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Pld6g427jzSZq; Mon, 27 Mar 2023 16:09:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32RG9Fxs022721; Mon, 27 Mar 2023 16:09:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32RG9Fn1022720; Mon, 27 Mar 2023 16:09:15 GMT (envelope-from git) Date: Mon, 27 Mar 2023 16:09:15 GMT Message-Id: <202303271609.32RG9Fn1022720@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: d3a49f62a284 - main - netlink: fix 19e43c163c64 by adding miseed netlinkg_glue.c List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d3a49f62a2848799a2e4cf205f44c4a0ca53b819 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=d3a49f62a2848799a2e4cf205f44c4a0ca53b819 commit d3a49f62a2848799a2e4cf205f44c4a0ca53b819 Author: Alexander V. Chernikov AuthorDate: 2023-03-27 16:08:24 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-03-27 16:09:02 +0000 netlink: fix 19e43c163c64 by adding miseed netlinkg_glue.c --- sys/netlink/netlink_glue.c | 266 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) diff --git a/sys/netlink/netlink_glue.c b/sys/netlink/netlink_glue.c new file mode 100644 index 000000000000..25b891036b5b --- /dev/null +++ b/sys/netlink/netlink_glue.c @@ -0,0 +1,266 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2023 Alexander V. Chernikov + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "opt_netlink.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* priv_check */ + +#include +#include + +#include +#include +#include + +/* Standard bits: built-in the kernel */ +SYSCTL_NODE(_net, OID_AUTO, netlink, CTLFLAG_RD, 0, ""); +SYSCTL_NODE(_net_netlink, OID_AUTO, debug, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); + +MALLOC_DEFINE(M_NETLINK, "netlink", "Memory used for netlink packets"); + +/* Netlink-related callbacks needed to glue rtsock, netlink and linuxolator */ +static void +ignore_route_event(uint32_t fibnum, const struct rib_cmd_info *rc) +{ +} + +static void +ignore_ifmsg_event(struct ifnet *ifp, int if_flags_mask) +{ +} + +static struct rtbridge ignore_cb = { + .route_f = ignore_route_event, + .ifmsg_f = ignore_ifmsg_event, +}; + +void *linux_netlink_p = NULL; /* Callback pointer for Linux translator functions */ +struct rtbridge *rtsock_callback_p = &ignore_cb; +struct rtbridge *netlink_callback_p = &ignore_cb; + + +/* + * nlp accessors. + * TODO: move to a separate file once the number grows. + */ +bool +nlp_has_priv(struct nlpcb *nlp, int priv) +{ + return (priv_check_cred(nlp->nl_cred, priv) == 0); +} + +struct ucred * +nlp_get_cred(struct nlpcb *nlp) +{ + return (nlp->nl_cred); +} + +uint32_t +nlp_get_pid(const struct nlpcb *nlp) +{ + return (nlp->nl_process_id); +} + +bool +nlp_unconstrained_vnet(const struct nlpcb *nlp) +{ + return (nlp->nl_unconstrained_vnet); +} + +#ifndef NETLINK +/* Stub implementations for the loadable functions */ + +static bool +get_stub_writer(struct nl_writer *nw) +{ + bzero(nw, sizeof(*nw)); + nw->writer_type = NS_WRITER_TYPE_STUB; + nw->enomem = true; + + return (false); +} + +static bool +nlmsg_get_unicast_writer_stub(struct nl_writer *nw, int size, struct nlpcb *nlp) +{ + return (get_stub_writer(nw)); +} + +static bool +nlmsg_get_group_writer_stub(struct nl_writer *nw, int size, int protocol, int group_id) +{ + return (get_stub_writer(nw)); +} + +static bool +nlmsg_get_chain_writer_stub(struct nl_writer *nw, int size, struct mbuf **pm) +{ + return (get_stub_writer(nw)); +} + +static bool +nlmsg_flush_stub(struct nl_writer *nw __unused) +{ + return (false); +} + +static void +nlmsg_ignore_limit_stub(struct nl_writer *nw __unused) +{ +} + +static bool +nlmsg_refill_buffer_stub(struct nl_writer *nw __unused, int required_len __unused) +{ + return (false); +} + +static bool +nlmsg_add_stub(struct nl_writer *nw, uint32_t portid, uint32_t seq, uint16_t type, + uint16_t flags, uint32_t len) +{ + return (false); +} + +static bool +nlmsg_end_stub(struct nl_writer *nw __unused) +{ + return (false); +} + +static void +nlmsg_abort_stub(struct nl_writer *nw __unused) +{ +} + +static bool +nlmsg_end_dump_stub(struct nl_writer *nw, int error, struct nlmsghdr *hdr) +{ + return (false); +} + +const static struct nl_function_wrapper nl_stub = { + .nlmsg_add = nlmsg_add_stub, + .nlmsg_refill_buffer = nlmsg_refill_buffer_stub, + .nlmsg_flush = nlmsg_flush_stub, + .nlmsg_end = nlmsg_end_stub, + .nlmsg_abort = nlmsg_abort_stub, + .nlmsg_ignore_limit = nlmsg_ignore_limit_stub, + .nlmsg_get_unicast_writer = nlmsg_get_unicast_writer_stub, + .nlmsg_get_group_writer = nlmsg_get_group_writer_stub, + .nlmsg_get_chain_writer = nlmsg_get_chain_writer_stub, + .nlmsg_end_dump = nlmsg_end_dump_stub, +}; + +/* + * If the kernel is compiled with netlink as a module, + * provide a way to introduce non-stub functioms + */ +static const struct nl_function_wrapper *_nl = &nl_stub; + +void +nl_set_functions(const struct nl_function_wrapper *nl) +{ + _nl = (nl != NULL) ? nl : &nl_stub; +} + +/* Function wrappers */ +bool +nlmsg_get_unicast_writer(struct nl_writer *nw, int size, struct nlpcb *nlp) +{ + return (_nl->nlmsg_get_unicast_writer(nw, size, nlp)); +} + +bool +nlmsg_get_group_writer(struct nl_writer *nw, int size, int protocol, int group_id) +{ + return (_nl->nlmsg_get_group_writer(nw, size, protocol, group_id)); +} + +bool +nlmsg_get_chain_writer(struct nl_writer *nw, int size, struct mbuf **pm) +{ + return (_nl->nlmsg_get_chain_writer(nw, size, pm)); +} + +bool +nlmsg_flush(struct nl_writer *nw) +{ + return (_nl->nlmsg_flush(nw)); +} + +void nlmsg_ignore_limit(struct nl_writer *nw) +{ + _nl->nlmsg_ignore_limit(nw); +} + +bool +nlmsg_refill_buffer(struct nl_writer *nw, int required_len) +{ + return (_nl->nlmsg_refill_buffer(nw, required_len)); +} + +bool +nlmsg_add(struct nl_writer *nw, uint32_t portid, uint32_t seq, uint16_t type, + uint16_t flags, uint32_t len) +{ + return (_nl->nlmsg_add(nw, portid, seq, type, flags, len)); +} + +bool +nlmsg_end(struct nl_writer *nw) +{ + return (_nl->nlmsg_end(nw)); +} + +void +nlmsg_abort(struct nl_writer *nw) +{ + _nl->nlmsg_abort(nw); +} + +bool +nlmsg_end_dump(struct nl_writer *nw, int error, struct nlmsghdr *hdr) +{ + return (_nl->nlmsg_end_dump(nw, error, hdr)); +} +#endif /* !NETLINK */ +