Date: Sun, 26 Feb 2023 08:11:27 GMT From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 123ca9ab1189 - stable/13 - linux(4): Fixup the interface name translation in netlink Message-ID: <202302260811.31Q8BRlZ082536@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=123ca9ab11896f356245537ee41207fb6943fccd commit 123ca9ab11896f356245537ee41207fb6943fccd Author: Dmitry Chagin <dchagin@FreeBSD.org> AuthorDate: 2023-02-23 08:01:18 +0000 Commit: Dmitry Chagin <dchagin@FreeBSD.org> 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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302260811.31Q8BRlZ082536>