mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-22 18:56:38 +00:00
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
This commit is contained in:
parent
fa93ba4097
commit
9d4a08d162
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue