diff options
author | Sagi Grimberg <sagi@grimberg.me> | 2018-01-24 20:24:24 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-03-26 08:53:43 -0600 |
commit | a470143fc83924251647143ff042bd2843e296cf (patch) | |
tree | 35ac2abc2bd810d95dcabb4797ce4eea5df9c2fb /net/core | |
parent | 57678e5a3d5145e5f08aa1d307ba219b27b1765a (diff) | |
download | op-kernel-dev-a470143fc83924251647143ff042bd2843e296cf.zip op-kernel-dev-a470143fc83924251647143ff042bd2843e296cf.tar.gz |
net/utils: Introduce inet_addr_is_any
Can be useful to check INET_ANY address for both ipv4/ipv6 addresses.
Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/utils.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/net/core/utils.c b/net/core/utils.c index 93066bd..d47863b 100644 --- a/net/core/utils.c +++ b/net/core/utils.c @@ -403,6 +403,29 @@ int inet_pton_with_scope(struct net *net, __kernel_sa_family_t af, } EXPORT_SYMBOL(inet_pton_with_scope); +bool inet_addr_is_any(struct sockaddr *addr) +{ + if (addr->sa_family == AF_INET6) { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; + const struct sockaddr_in6 in6_any = + { .sin6_addr = IN6ADDR_ANY_INIT }; + + if (!memcmp(in6->sin6_addr.s6_addr, + in6_any.sin6_addr.s6_addr, 16)) + return true; + } else if (addr->sa_family == AF_INET) { + struct sockaddr_in *in = (struct sockaddr_in *)addr; + + if (in->sin_addr.s_addr == htonl(INADDR_ANY)) + return true; + } else { + pr_warn("unexpected address family %u\n", addr->sa_family); + } + + return false; +} +EXPORT_SYMBOL(inet_addr_is_any); + void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb, __be32 from, __be32 to, bool pseudohdr) { |