From nobody Thu Feb 23 08:01:37 2023 X-Original-To: dev-commits-src-main@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 4PMlpp0WVtz3t97Q; Thu, 23 Feb 2023 08:01:38 +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 4PMlpn6zVhz3R6B; Thu, 23 Feb 2023 08:01:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677139298; 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=sC27idTw8P0kbb7MQLosgRMBAl/bhuuFTdAD4lycSg4=; b=EWI7nanHhRaPTy2QJszm/CaJbzr0cAPq6aZIJZEzMkUMnLARWWqSaVSVHIiZBdr+3H6e0L 6A0O5e3M/fij6hydUn4RZJNs/tbmGnE95IqUjV7M0uliaEVeZTBbDTSDqy5oJUqCV5pMSU ZYVHzcg9592Eb6foNc1jPLnQA8vIsGCuu6M0hOsruuMfBPw/SUqE8QYsZ1IaWj7ZoDViM5 0JtYp40HYUOzKB+Zuo7rrmk5/Sacl2ETlOEdxFAYCgGQE2+21lpyKyO3NWMTldPHZ65OK7 WkonEw1JIex22nrRHW2BftM9ySBnUik5jOYXzNl35oermBEfg9d75hYRpuxQhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677139298; 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=sC27idTw8P0kbb7MQLosgRMBAl/bhuuFTdAD4lycSg4=; b=jG5ilnYRzd111Sml2L19+Ia+ojwdbU3pZOjCSObb8Z64WYy6G08ji8hPVwYSA1pYvC5c8s +GNm9zspxCg8ny3/oM+BmyARz2+uUgmfuFdb+J+3fLdaOPpQizwQjVTj0mUrGWh1XYayr0 yQg3zHqkUqQei4ouqGv8c/SbK9IegS6dhiiQ35EMgHxwiIuTm0UsJL9+b2RoQHyKm2K57+ 87ofryl2kArGuCWV24McsdZpXTNop0XE7qclpeQDP/2ZnDSNP4JueRbzk9emY41h3zZpft LTfH2MmVWImoeu2ZVLmkVv2W/cqAK1+18lprBNo7wAF6W4/KkjEJE1Q8eSqPvQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677139298; a=rsa-sha256; cv=none; b=o/hgxkgylNeZSfgshp1XA5GhNTBWFdbQJ7wmn2Rlq+uSSnOQvW1zdv7B+UzUVJSh9JOybJ C7Rl2Of11/FnF/fOMW6b8Ei6L5gx6v9284WCYDHyrUJACq/LQjWbsM2sUrKiFIXpPRdU94 3ORgc8VLXGVvU+XdAnMiLmB1yNzBz43JC3nv7I43gG4LYP47Oo8CiJU3W/TGmFk5+sz9EA 3CRfiiJqs+4crw1NXqAnp02UEXMgRYR/Bw+9feWzTArQ8kYix+1ap0gXLocRgNBP318bNH fxHP87S4GzkC7kgXhl71+v60FvPhLyw9HlNgl3zgGTaqiQ3s8V2A7N+5aLJhNw== 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 4PMlpn65HPzZfc; Thu, 23 Feb 2023 08:01:37 +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 31N81bMt029628; Thu, 23 Feb 2023 08:01:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31N81bj7029627; Thu, 23 Feb 2023 08:01:37 GMT (envelope-from git) Date: Thu, 23 Feb 2023 08:01:37 GMT Message-Id: <202302230801.31N81bj7029627@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: e55e4a6ba3f4 - main - linux(4): Fixup the interface name translation in netlink List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: e55e4a6ba3f4cd31d47b74574ea7370d5ab14b48 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=e55e4a6ba3f4cd31d47b74574ea7370d5ab14b48 commit e55e4a6ba3f4cd31d47b74574ea7370d5ab14b48 Author: Dmitry Chagin AuthorDate: 2023-02-23 08:01:18 +0000 Commit: Dmitry Chagin CommitDate: 2023-02-23 08:01:18 +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 --- 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 69cd006ce4ef..9edfbfc2c031 100644 --- a/sys/compat/linux/linux_netlink.c +++ b/sys/compat/linux/linux_netlink.c @@ -224,10 +224,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; @@ -238,11 +280,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)