From nobody Thu Mar 30 09:57:22 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 4PnJkB6Xt7z42lvf; Thu, 30 Mar 2023 09:57:22 +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 4PnJkB5Zp7z4MFw; Thu, 30 Mar 2023 09:57:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680170242; 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=msaYeFpM0OL87nh2qXps+2dP8bw/GafmMfY0LDx0OG4=; b=CgqLvSUSd8KF1Fb0eQB3fw1H2DVypwf5D6c6SRb3mJiFB+eW5JIZpgVfHK9pYBd8RRYtTX 08MsAsQGX4+3TTgxlO8wXUcJWmTzduxCvFRwV5wxCH4cPzyO4rE924cM45P2ckT7b8e0Wc Hjzj/P0+M/vi67lkk0V/Uja2XXcLrtfwL6qre/3Aw2kZifs6ynrv/sdA/gbQMET7X8CedZ hWjVsDwx9AVB5GV9SHsrVnq2+smBySEEsKCvCc+Huq6mfx6ROlwT9xBqE4qMen4MA+fG9h sJs5qzPusEwSpyeoEOO97gBtFz1qsjpBYWS9+OzKbU1mLB9qp7L5sYV10wHNmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680170242; 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=msaYeFpM0OL87nh2qXps+2dP8bw/GafmMfY0LDx0OG4=; b=vfhk3ULTfeND0nRE/8e71S5h1IRY0SqKI2hKdsVYNL4ukUfieUoTMhsumGUibXwuVWYxTx 1Z7VSLZvgR3IJ92/7cZAlY1GMvtLYqgCaenklpjZwBSgNAlqwp+ZVYyhmqNaG7YS5Csq7E DZO4a16WeFbCZYY5Oe9vFQpJpQbZDU/bVA12ixWCuNdlqHdmANJ3LotTaFU5umc3f5XS+n XZ4ngd/cUjpZQLjIJ9H1yAylGzE0TXseaY+xefb8OXNG8J8iFsa9rMUT6xIJeNQ7X8R2Ko kfbqNgA9dratucX/LYpqO3+35ev/yMomFWoaOtcoXvM4uXd7NIZWKhPs7m7U+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1680170242; a=rsa-sha256; cv=none; b=rn8ZDXh89G8izM/u/6FfC5GtqBj4vhVYY8kv4Xjq4BUYHSM9CgqW6BIjgSKg7foeYj8IoH wDl72mf4ywqzdNcSu2GUG3Vd2e7V92576TBTZMJP6tzdfq0loRh++meAAn0U8RESK+ypoM 3YfR6AUe2h89sZo//u2307lNi5whGVyyq18QK3PniJK9Nr5QNNkCqTwsY2Tgh+v/CNm/Oa TxgJum6MlbIF61zfLSUhlJ+4q4GD1noaeEswU+LSgjlFYhexOzucVH7IizgoIYfVQZz1HS Eiv8qS7KrX4lmZJee7WsfRW5q17P+JnDAFUq6rsNRJu8/MfJOLMb6RlCLB25fQ== 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 4PnJkB4JWnz16lR; Thu, 30 Mar 2023 09:57:22 +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 32U9vMsG018898; Thu, 30 Mar 2023 09:57:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32U9vMCx018897; Thu, 30 Mar 2023 09:57:22 GMT (envelope-from git) Date: Thu, 30 Mar 2023 09:57:22 GMT Message-Id: <202303300957.32U9vMCx018897@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: 140ddeba0834 - main - route: try to autoload netlink(4) module if not present in the kernel. 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: 140ddeba0834509b9b8159c4d0c59cc7962dcc0e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=140ddeba0834509b9b8159c4d0c59cc7962dcc0e commit 140ddeba0834509b9b8159c4d0c59cc7962dcc0e Author: Alexander V. Chernikov AuthorDate: 2023-03-29 15:31:26 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-03-30 09:53:06 +0000 route: try to autoload netlink(4) module if not present in the kernel. Differential Revision: https://reviews.freebsd.org/D39324 --- sbin/route/route_netlink.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c index 0b9bb4ff5750..66b1920a58db 100644 --- a/sbin/route/route_netlink.c +++ b/sbin/route/route_netlink.c @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include #include @@ -90,6 +92,23 @@ get_netmask(struct snl_state *ss, int family, int plen) return (NULL); } +static void +nl_init_socket(struct snl_state *ss) +{ + if (snl_init(ss, NETLINK_ROUTE)) + return; + + if (modfind("netlink") == -1 && errno == ENOENT) { + /* Try to load */ + if (kldload("netlink") == -1) + err(1, "netlink is not loaded and load attempt failed"); + if (snl_init(ss, NETLINK_ROUTE)) + return; + } + + err(1, "unable to open netlink socket"); +} + struct nl_helper { struct snl_state ss_cmd; }; @@ -97,8 +116,7 @@ struct nl_helper { static void nl_helper_init(struct nl_helper *h) { - if (!snl_init(&h->ss_cmd, NETLINK_ROUTE)) - err(1, "unable to open netlink socket"); + nl_init_socket(&h->ss_cmd); } static void @@ -680,8 +698,7 @@ monitor_nl(int fib) struct snl_state ss_event = {}; struct nl_helper h; - if (!snl_init(&ss_event, NETLINK_ROUTE)) - err(1, "unable to open netlink socket"); + nl_init_socket(&ss_event); nl_helper_init(&h); int groups[] = { @@ -789,8 +806,7 @@ flushroutes_fib_nl(int fib, int af) struct snl_writer nw; struct nl_helper h = {}; - if (!snl_init(&ss, NETLINK_ROUTE)) - err(1, "unable to open netlink socket"); + nl_init_socket(&ss); snl_init_writer(&ss, &nw); struct nlmsghdr *hdr = snl_create_msg_request(&nw, NL_RTM_GETROUTE);