libceph: treat sockaddr_storage with uninitialized family as blank
diff mbox

Message ID 1436449754-34910-1-git-send-email-idryomov@gmail.com
State New
Headers show

Commit Message

Ilya Dryomov July 9, 2015, 1:49 p.m. UTC
addr_is_blank() should return true if family is neither AF_INET nor
AF_INET6.  This is what its counterpart entity_addr_t::is_blank_ip() is
doing and it is the right thing to do: in process_banner() we check if
our address is blank and if it is "learn" it from our peer.  As it is,
we never learn our address and always send out a blank one.  This goes
way back to ceph.git commit dd732cbfc1c9 ("use sockaddr_storage; and
some ipv6 support groundwork") from 2009.

While at at, do not open-code ipv6_addr_any() and use INADDR_ANY
constant instead of 0.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
 net/ceph/messenger.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Sage Weil July 9, 2015, 3:58 p.m. UTC | #1
On Thu, 9 Jul 2015, Ilya Dryomov wrote:
> addr_is_blank() should return true if family is neither AF_INET nor
> AF_INET6.  This is what its counterpart entity_addr_t::is_blank_ip() is
> doing and it is the right thing to do: in process_banner() we check if
> our address is blank and if it is "learn" it from our peer.  As it is,
> we never learn our address and always send out a blank one.  This goes
> way back to ceph.git commit dd732cbfc1c9 ("use sockaddr_storage; and
> some ipv6 support groundwork") from 2009.
> 
> While at at, do not open-code ipv6_addr_any() and use INADDR_ANY
> constant instead of 0.
> 
> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

Reviewed-by: Sage Weil <sage@redhat.com>



> ---
>  net/ceph/messenger.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
> index 726a57af760f..101ab6285fba 100644
> --- a/net/ceph/messenger.c
> +++ b/net/ceph/messenger.c
> @@ -1732,17 +1732,17 @@ static int verify_hello(struct ceph_connection *con)
>  
>  static bool addr_is_blank(struct sockaddr_storage *ss)
>  {
> +	struct in_addr *addr = &((struct sockaddr_in *)ss)->sin_addr;
> +	struct in6_addr *addr6 = &((struct sockaddr_in6 *)ss)->sin6_addr;
> +
>  	switch (ss->ss_family) {
>  	case AF_INET:
> -		return ((struct sockaddr_in *)ss)->sin_addr.s_addr == 0;
> +		return addr->s_addr == htonl(INADDR_ANY);
>  	case AF_INET6:
> -		return
> -		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[0] == 0 &&
> -		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[1] == 0 &&
> -		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[2] == 0 &&
> -		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[3] == 0;
> +		return ipv6_addr_any(addr6);
> +	default:
> +		return true;
>  	}
> -	return false;
>  }
>  
>  static int addr_port(struct sockaddr_storage *ss)
> -- 
> 1.9.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 726a57af760f..101ab6285fba 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1732,17 +1732,17 @@  static int verify_hello(struct ceph_connection *con)
 
 static bool addr_is_blank(struct sockaddr_storage *ss)
 {
+	struct in_addr *addr = &((struct sockaddr_in *)ss)->sin_addr;
+	struct in6_addr *addr6 = &((struct sockaddr_in6 *)ss)->sin6_addr;
+
 	switch (ss->ss_family) {
 	case AF_INET:
-		return ((struct sockaddr_in *)ss)->sin_addr.s_addr == 0;
+		return addr->s_addr == htonl(INADDR_ANY);
 	case AF_INET6:
-		return
-		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[0] == 0 &&
-		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[1] == 0 &&
-		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[2] == 0 &&
-		     ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[3] == 0;
+		return ipv6_addr_any(addr6);
+	default:
+		return true;
 	}
-	return false;
 }
 
 static int addr_port(struct sockaddr_storage *ss)