From nobody Fri Mar 29 20:36:12 2024 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 4V5scs0G3lz5Fgq5; Fri, 29 Mar 2024 20:36:13 +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 4V5scr6PbPz4DPJ; Fri, 29 Mar 2024 20:36:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711744572; 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=cD3BqIPajLmlpqydnIicYWOdG7a1+RL5cM6LUF5Wv1U=; b=JftFZqlzyXLZ3tO1kXmXUpHw8cNCLds8MZTJkdpxKfTeQau6PEJpPdIkM3Uq/XcMvcAFMw UEYVJ9DhTnVyJO26o0scussc1Wru70iAgeqsQtdqZXTTDns5jeJnb2BUEff2zQyLvU0JOT tH8HyCi6tZD5pJW/I6scqVYGiS4MsLmdemRS1OfZNaOubq2MDHT/6OE4NAJPipw8LZZV2D V98yw/Bbil3D2uqumNRspjAXGF4NsbZZl73O5UauB1zgsRKJgB1C2eX8s830WT6nwINVju Qwl5Fjl6wjs+1gh0XUkFF2AhNArg0jq+d0juWQUs/Y+98gwohLCb8Z9bZdSNIA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711744572; a=rsa-sha256; cv=none; b=MTVBGNs+bbmQm/HKcTN6bJukvwWUFvxvb3Fou+IqlDzvkUJXIsFJXNDugo8+G/9s7g4Rz4 2e1SvmFmY93FqbwG1cbj7fW0W9s0JqtgXlmXcMH25gKvxtJZSfnCPjENZ3kcHDcOeGGqJ+ JOmw57HLta7MyRw8MC5m9TIVjA/un67wKHuzoX7mrWUx1BqGVOnRecprKruRLIMN/KLSOo LabUaUjCFe0iZhfsfEVM8R50FuuRBZKBeyEgpnzGcjl2lVeYc9NUCtLZzo6Ek2P6UQFjIb YPRrvFNTgHutqEL8ScYtWy4FmZE2D1pmlo5brPUjfgTbswJNcbqLYRfWmjxpKw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711744572; 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=cD3BqIPajLmlpqydnIicYWOdG7a1+RL5cM6LUF5Wv1U=; b=tMqa4fDBulpCk/SRiaQhU7nkFBXiwVEW8DkIuvxhxo2kn/4xoBq9ymdeUw81t4bKwpc/r6 0XVV9J1pIN31JADOWZFoBtxbjB06GWkS1CbyvLgwzfoUgUrp5LPSwfD7+W8bV2gaAY9sJC J9bAdt2k6XkgMcIzFHtZDrmWVN/OA0lRkJLJUUTByPeXGlutwSCpBJcIpqAORvLPvcTdIu FGnLJ3xocwW84yWYZF4sRMzmOLYTT6sWAa82eMDeBgk68s3QPAgdbrkF9GcKeEQFMsv6AM 3W4ZY6bIfQ4M5l9/5q42xCAOKYUprBxWwFz8pIJ5m96HCuSG8SSA8FBkWZ1Fuw== 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 4V5scr619fzPZV; Fri, 29 Mar 2024 20:36:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42TKaCo0023246; Fri, 29 Mar 2024 20:36:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42TKaCTI023243; Fri, 29 Mar 2024 20:36:12 GMT (envelope-from git) Date: Fri, 29 Mar 2024 20:36:12 GMT Message-Id: <202403292036.42TKaCTI023243@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 9d4a08d162d8 - main - linux: use sa_family_t for address family conversions 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9d4a08d162d87ba120f418a1a71facd2c631b549 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9d4a08d162d87ba120f418a1a71facd2c631b549 commit 9d4a08d162d87ba120f418a1a71facd2c631b549 Author: Gleb Smirnoff AuthorDate: 2024-03-29 20:35:37 +0000 Commit: Gleb Smirnoff CommitDate: 2024-03-29 20:35:37 +0000 linux: use sa_family_t for address family conversions Express "conversion failed" with maximum possible value. This allows to reduce number of size/signedness conversion in the code that utilizes the functions. PR: 274536 Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D44375 --- sys/compat/linux/linux.c | 18 +++++++++--------- sys/compat/linux/linux_common.h | 5 +++-- sys/compat/linux/linux_socket.c | 9 +++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/sys/compat/linux/linux.c b/sys/compat/linux/linux.c index 69849b1d98ad..61b207070963 100644 --- a/sys/compat/linux/linux.c +++ b/sys/compat/linux/linux.c @@ -501,8 +501,8 @@ linux_ifhwaddr(struct ifnet *ifp, struct l_sockaddr *lsa) return (ENOENT); } -int -linux_to_bsd_domain(int domain) +sa_family_t +linux_to_bsd_domain(sa_family_t domain) { switch (domain) { @@ -523,11 +523,11 @@ linux_to_bsd_domain(int domain) case LINUX_AF_NETLINK: return (AF_NETLINK); } - return (-1); + return (AF_UNKNOWN); } -int -bsd_to_linux_domain(int domain) +sa_family_t +bsd_to_linux_domain(sa_family_t domain) { switch (domain) { @@ -548,7 +548,7 @@ bsd_to_linux_domain(int domain) case AF_NETLINK: return (LINUX_AF_NETLINK); } - return (-1); + return (AF_UNKNOWN); } /* @@ -562,13 +562,13 @@ bsd_to_linux_sockaddr(const struct sockaddr *sa, struct l_sockaddr **lsa, socklen_t len) { struct l_sockaddr *kosa; - int bdom; + sa_family_t bdom; *lsa = NULL; if (len < 2 || len > UCHAR_MAX) return (EINVAL); bdom = bsd_to_linux_domain(sa->sa_family); - if (bdom == -1) + if (bdom == AF_UNKNOWN) return (EAFNOSUPPORT); kosa = malloc(len, M_LINUX, M_WAITOK); @@ -615,7 +615,7 @@ linux_to_bsd_sockaddr(const struct l_sockaddr *osa, struct sockaddr **sap, goto out; bdom = linux_to_bsd_domain(kosa->sa_family); - if (bdom == -1) { + if (bdom == AF_UNKNOWN) { error = EAFNOSUPPORT; goto out; } diff --git a/sys/compat/linux/linux_common.h b/sys/compat/linux/linux_common.h index 485ebaab58f2..97f5a259f300 100644 --- a/sys/compat/linux/linux_common.h +++ b/sys/compat/linux/linux_common.h @@ -38,8 +38,9 @@ unsigned short linux_ifflags(struct ifnet *); int linux_ifhwaddr(struct ifnet *ifp, struct l_sockaddr *lsa); unsigned short bsd_to_linux_ifflags(int); -int linux_to_bsd_domain(int domain); -int bsd_to_linux_domain(int domain); +sa_family_t linux_to_bsd_domain(sa_family_t domain); +sa_family_t bsd_to_linux_domain(sa_family_t domain); +#define AF_UNKNOWN UINT8_MAX int bsd_to_linux_sockaddr(const struct sockaddr *sa, struct l_sockaddr **lsa, socklen_t len); int linux_to_bsd_sockaddr(const struct l_sockaddr *lsa, diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index ae22af90d443..1e578982fced 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -870,7 +870,8 @@ static const char *linux_netlink_names[] = { int linux_socket(struct thread *td, struct linux_socket_args *args) { - int domain, retval_socket, type; + int retval_socket, type; + sa_family_t domain; type = args->type & LINUX_SOCK_TYPE_MASK; if (type < 0 || type > LINUX_SOCK_MAX) @@ -880,7 +881,7 @@ linux_socket(struct thread *td, struct linux_socket_args *args) if (retval_socket != 0) return (retval_socket); domain = linux_to_bsd_domain(args->domain); - if (domain == -1) { + if (domain == AF_UNKNOWN) { /* Mask off SOCK_NONBLOCK / CLOEXEC for error messages. */ type = args->type & LINUX_SOCK_TYPE_MASK; if (args->domain == LINUX_AF_NETLINK && @@ -2309,8 +2310,8 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) name, &newval, UIO_SYSSPACE, &len); if (error != 0) return (error); - newval = bsd_to_linux_domain(newval); - if (newval == -1) + newval = bsd_to_linux_domain((sa_family_t)newval); + if (newval == AF_UNKNOWN) return (ENOPROTOOPT); return (linux_sockopt_copyout(td, &newval, len, args));