From nobody Sun Feb 26 08:11:27 2023 X-Original-To: dev-commits-src-branches@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 4PPbtm0kcYz3s3ld; Sun, 26 Feb 2023 08:11:28 +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 4PPbtl6fswz4FgM; Sun, 26 Feb 2023 08:11:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677399088; 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=CzPIxFwV/oS9zlPteiciOrqY6or4uIxfcE6RBMeYzH4=; b=hOZR7i8VrlTVTL2qYOASvRHVU5c0Pqx6JjGHng6PcB859WZBcT0XnJQdFnUoeBUzvHzbLT u3LJpIfm9t3QH2mD3Zc8fVkWfovs3cOjI1Eqmb29vylm1hZuc5L4bMvJ93MBBYU7yc822u JN6/HyFF8PAKiaH+UDLVzsvLoE0RfoUP6FndsmZLKmTFrmTElBDm28c9qCmBcuQ13Jk/64 quk6Un0ua9uNQ0RyS8Vyp3QPEMUqJYRGsskDLjn7nFU/+Q6tDf8ILFULb/0tT6r2QRM/Qj rpaGchau0mpH2Rs3WuRtwGD54svxsLZ/z0MCOBRG4RluD1QxZbQIxQhJcbOjag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677399088; 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=CzPIxFwV/oS9zlPteiciOrqY6or4uIxfcE6RBMeYzH4=; b=R/xqsyTeEwNWU8hBCPKq7WdZOkklD67xv6rkFCBByzesALRaPWhNMr2ZpIveF/XYrYrxUa hf33RBArMiGqm+F7FEwoUg4C3nmjK2Deg2tHY311BZalSBfTjnIHPUOayUwIIO/jSSRqHj PuRhbAD20IEuxxHduIvANzpM725RkMgsLKjAXHYzxOJKeFwSz+ww2KwgE1+38QOL6GWDQu Kzw9IQ29XSDVnDwAKaQ94ql/DjPmgkWUBfGi8U1HdktokQ0KPSOd88Ow45/HeNNcH3Obnw vMymIzeDBXTNbGLRsH/wEwkjGapKHeU+CGc2283gGkwNVZ81OmVRUApmV8TOhg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677399088; a=rsa-sha256; cv=none; b=O6C2WZnKO15hFUuNBB5NxZS0LjghYH9DFlm7047bvvtplWzqbwkdX2bI55MUIKpk9WFUF8 J1iY2cjjAW9hjB2yr31KayvBPIZ2o/T7gEvDB5DzRt25ZcEskuHAEcKlSXxoxYpx9HCbob sYCkzE8Eeq7COVb5NxZtzlfv69JmTLi+PwNxlKsnSbyHYirUr4K3kJQSQscQ39RL5jpn90 WHw+vmP3thwzo+egmYqVOFSy4ZncM5LqzfW3xFCv6q4snhZrgYYKPx+pi6dkc62qe8ajFN uxQ7AgOsjd4QlT6gTRXCumM6umoCJV6gVetcngbSzlpV2R+a4vfBEUdPNhMuEg== 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 4PPbtl5mY4zd39; Sun, 26 Feb 2023 08:11:27 +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 31Q8BRWg082537; Sun, 26 Feb 2023 08:11:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31Q8BRlZ082536; Sun, 26 Feb 2023 08:11:27 GMT (envelope-from git) Date: Sun, 26 Feb 2023 08:11:27 GMT Message-Id: <202302260811.31Q8BRlZ082536@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 123ca9ab1189 - stable/13 - linux(4): Fixup the interface name translation in netlink List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 123ca9ab11896f356245537ee41207fb6943fccd Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=123ca9ab11896f356245537ee41207fb6943fccd commit 123ca9ab11896f356245537ee41207fb6943fccd Author: Dmitry Chagin AuthorDate: 2023-02-23 08:01:18 +0000 Commit: Dmitry Chagin CommitDate: 2023-02-26 08:10:44 +0000 linux(4): Fixup the interface name translation in netlink Netlink should translate a FreeBSD interface name to a Linux interface name. Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D38715 MFC after: 3 days (cherry picked from commit e55e4a6ba3f4cd31d47b74574ea7370d5ab14b48) --- sys/compat/linux/linux_netlink.c | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/sys/compat/linux/linux_netlink.c b/sys/compat/linux/linux_netlink.c index bcbf39cdcb85..4fc962c7ea0b 100644 --- a/sys/compat/linux/linux_netlink.c +++ b/sys/compat/linux/linux_netlink.c @@ -220,10 +220,52 @@ nlmsg_copy_nla(const struct nlattr *nla_orig, struct nl_writer *nw) return (false); } +/* + * Translate a FreeBSD interface name to a Linux interface name. + */ +static bool +nlmsg_translate_ifname_nla(struct nlattr *nla, struct nl_writer *nw) +{ + char ifname[LINUX_IFNAMSIZ]; + + if (ifname_bsd_to_linux_name((char *)(nla + 1), ifname, + sizeof(ifname)) <= 0) + return (false); + return (nlattr_add_string(nw, IFLA_IFNAME, ifname)); +} + +#define LINUX_NLA_UNHANDLED -1 +/* + * Translate a FreeBSD attribute to a Linux attribute. + * Returns LINUX_NLA_UNHANDLED when the attribute is not processed + * and the caller must take care of it, otherwise the result is returned. + */ +static int +nlmsg_translate_all_nla(struct nlmsghdr *hdr, struct nlattr *nla, + struct nl_writer *nw) +{ + + switch (hdr->nlmsg_type) { + case NL_RTM_NEWLINK: + case NL_RTM_DELLINK: + case NL_RTM_GETLINK: + switch (nla->nla_type) { + case IFLA_IFNAME: + return (nlmsg_translate_ifname_nla(nla, nw)); + default: + break; + } + default: + break; + } + return (LINUX_NLA_UNHANDLED); +} + static bool nlmsg_copy_all_nla(struct nlmsghdr *hdr, int raw_hdrlen, struct nl_writer *nw) { struct nlattr *nla; + int ret; int hdrlen = NETLINK_ALIGN(raw_hdrlen); int attrs_len = hdr->nlmsg_len - sizeof(struct nlmsghdr) - hdrlen; @@ -234,11 +276,15 @@ nlmsg_copy_all_nla(struct nlmsghdr *hdr, int raw_hdrlen, struct nl_writer *nw) if (nla->nla_len < sizeof(struct nlattr)) { return (false); } - if (!nlmsg_copy_nla(nla, nw)) + ret = nlmsg_translate_all_nla(hdr, nla, nw); + if (ret == LINUX_NLA_UNHANDLED) + ret = nlmsg_copy_nla(nla, nw); + if (!ret) return (false); } return (true); } +#undef LINUX_NLA_UNHANDLED static unsigned int rtnl_if_flags_to_linux(unsigned int if_flags)