Add a new function, ifa_ifwithaddr_check(), which rather than returning
a pointer to an ifaddr matching the passed socket address, returns a boolean indicating whether one was present. In the (near) future, ifa_ifwithaddr() will return a referenced ifaddr rather than a raw ifaddr pointer, and the new wrapper will allow callers that care only about the boolean condition to avoid having to free that reference. MFC after: 3 weeks
This commit is contained in:
parent
f863f9cbd9
commit
8896f83a58
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=194622
@ -1337,12 +1337,13 @@ static int
|
||||
is_loopback_dst(struct iw_cm_id *cm_id)
|
||||
{
|
||||
uint16_t port = cm_id->remote_addr.sin_port;
|
||||
struct ifaddr *ifa;
|
||||
int ifa_present;
|
||||
|
||||
cm_id->remote_addr.sin_port = 0;
|
||||
ifa = ifa_ifwithaddr((struct sockaddr *)&cm_id->remote_addr);
|
||||
ifa_present = ifa_ifwithaddr_check(
|
||||
(struct sockaddr *)&cm_id->remote_addr);
|
||||
cm_id->remote_addr.sin_port = port;
|
||||
return (ifa != NULL);
|
||||
return (ifa_present);
|
||||
}
|
||||
|
||||
int
|
||||
|
18
sys/net/if.c
18
sys/net/if.c
@ -1466,8 +1466,8 @@ ifa_free(struct ifaddr *ifa)
|
||||
* Locate an interface based on a complete address.
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
struct ifaddr *
|
||||
ifa_ifwithaddr(struct sockaddr *addr)
|
||||
static struct ifaddr *
|
||||
ifa_ifwithaddr_internal(struct sockaddr *addr)
|
||||
{
|
||||
INIT_VNET_NET(curvnet);
|
||||
struct ifnet *ifp;
|
||||
@ -1500,6 +1500,20 @@ ifa_ifwithaddr(struct sockaddr *addr)
|
||||
return (ifa);
|
||||
}
|
||||
|
||||
struct ifaddr *
|
||||
ifa_ifwithaddr(struct sockaddr *addr)
|
||||
{
|
||||
|
||||
return (ifa_ifwithaddr_internal(addr));
|
||||
}
|
||||
|
||||
int
|
||||
ifa_ifwithaddr_check(struct sockaddr *addr)
|
||||
{
|
||||
|
||||
return (ifa_ifwithaddr_internal(addr) != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate an interface based on the broadcast address.
|
||||
*/
|
||||
|
@ -820,6 +820,7 @@ void ifq_init(struct ifaltq *, struct ifnet *ifp);
|
||||
void ifq_delete(struct ifaltq *);
|
||||
|
||||
struct ifaddr *ifa_ifwithaddr(struct sockaddr *);
|
||||
int ifa_ifwithaddr_check(struct sockaddr *);
|
||||
struct ifaddr *ifa_ifwithbroadaddr(struct sockaddr *);
|
||||
struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
|
||||
struct ifaddr *ifa_ifwithnet(struct sockaddr *);
|
||||
|
@ -547,7 +547,7 @@ rtredirect_fib(struct sockaddr *dst,
|
||||
if (!(flags & RTF_DONE) && rt &&
|
||||
(!sa_equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
|
||||
error = EINVAL;
|
||||
else if (ifa_ifwithaddr(gateway))
|
||||
else if (ifa_ifwithaddr_check(gateway))
|
||||
error = EHOSTUNREACH;
|
||||
if (error)
|
||||
goto done;
|
||||
|
@ -357,7 +357,7 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
|
||||
* to any endpoint address, local or not.
|
||||
*/
|
||||
if ((inp->inp_flags & INP_BINDANY) == 0 &&
|
||||
ifa_ifwithaddr((struct sockaddr *)sin) == NULL)
|
||||
ifa_ifwithaddr_check((struct sockaddr *)sin) == 0)
|
||||
return (EADDRNOTAVAIL);
|
||||
}
|
||||
laddr = sin->sin_addr;
|
||||
|
@ -875,7 +875,7 @@ rip_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
|
||||
(addr->sin_family != AF_INET && addr->sin_family != AF_IMPLINK) ||
|
||||
(addr->sin_addr.s_addr &&
|
||||
(inp->inp_flags & INP_BINDANY) == 0 &&
|
||||
ifa_ifwithaddr((struct sockaddr *)addr) == NULL))
|
||||
ifa_ifwithaddr_check((struct sockaddr *)addr) == 0))
|
||||
return (EADDRNOTAVAIL);
|
||||
|
||||
INP_INFO_WLOCK(&V_ripcbinfo);
|
||||
|
@ -121,7 +121,7 @@ ipx_pcbbind(struct ipxpcb *ipxp, struct sockaddr *nam, struct thread *td)
|
||||
int tport = sipx->sipx_port;
|
||||
|
||||
sipx->sipx_port = 0; /* yech... */
|
||||
if (ifa_ifwithaddr((struct sockaddr *)sipx) == NULL)
|
||||
if (ifa_ifwithaddr_check((struct sockaddr *)sipx) == 0)
|
||||
return (EADDRNOTAVAIL);
|
||||
sipx->sipx_port = tport;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user