net: add helpers checking if socket can be bound to nonlocal address
The construction "net->ipv4.sysctl_ip_nonlocal_bind || inet->freebind || inet->transparent" is present three times and its IPv6 counterpart is also present three times. We introduce two small helpers to characterize these tests uniformly. Signed-off-by: Vincent Bernat <vincent@bernat.im> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
d39db3b4d6
commit
83ba464515
@@ -322,8 +322,7 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
|
||||
/* Reproduce AF_INET checks to make the bindings consistent */
|
||||
v4addr = addr->sin6_addr.s6_addr32[3];
|
||||
chk_addr_ret = inet_addr_type(net, v4addr);
|
||||
if (!net->ipv4.sysctl_ip_nonlocal_bind &&
|
||||
!(inet->freebind || inet->transparent) &&
|
||||
if (!inet_can_nonlocal_bind(net, inet) &&
|
||||
v4addr != htonl(INADDR_ANY) &&
|
||||
chk_addr_ret != RTN_LOCAL &&
|
||||
chk_addr_ret != RTN_MULTICAST &&
|
||||
@@ -362,8 +361,7 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
|
||||
*/
|
||||
v4addr = LOOPBACK4_IPV6;
|
||||
if (!(addr_type & IPV6_ADDR_MULTICAST)) {
|
||||
if (!net->ipv6.sysctl.ip_nonlocal_bind &&
|
||||
!(inet->freebind || inet->transparent) &&
|
||||
if (!ipv6_can_nonlocal_bind(net, inet) &&
|
||||
!ipv6_chk_addr(net, &addr->sin6_addr,
|
||||
dev, 0)) {
|
||||
err = -EADDRNOTAVAIL;
|
||||
|
Reference in New Issue
Block a user