From patchwork Tue Feb 6 09:44:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 10202573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CBF2C6020F for ; Tue, 6 Feb 2018 09:44:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C280428ABD for ; Tue, 6 Feb 2018 09:44:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6C4D28AC8; Tue, 6 Feb 2018 09:44:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23B7028ABD for ; Tue, 6 Feb 2018 09:44:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752256AbeBFJoq (ORCPT ); Tue, 6 Feb 2018 04:44:46 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:40029 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752183AbeBFJoo (ORCPT ); Tue, 6 Feb 2018 04:44:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HxDSqbS+38Uwaehhukuo/Y/CNIhgKsjI2Ra0HuTz1iM=; b=NXZFz0ssJrztnXmzMfbGEidbt s65Uyi/SpdnBNXDkHSCWLT4aAGQxzNoBl7q7qVOQgsC0lE4fBFEkSiW0iOMA1kLpU3unrbyNe/EAH flaFgtZpH6tpw4O5coUg/0dVaAbIY9vra37bU9Llp0t9Gg29+HX0JfShWxI00db2n9p9c4iz0U2Zr e+DN2y0dGH5AdMMhxE2RCikrpDkXxHDElrEAe9dKsPr1+I6G/Cg7BxihHlbKV9NdCa5aBe7hcPYzu fMOMuZP3y8R0K1rG3ggk1rBBLEsLQy2Gm1cLLsAmHcp5wWG+Eohx7stho6pBykHnXqTxi6gsc6FY3 5Fy8DBdvw==; Received: from bzq-219-42-90.isdn.bezeqint.net ([62.219.42.90] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1eiznu-0002nI-Gw; Tue, 06 Feb 2018 09:44:42 +0000 From: Sagi Grimberg To: linux-nvme@lists.infradead.org, target-devel@vger.kernel.org Cc: Christoph Hellwig , Johannes Thumshirn , "David S. Miller" , "Nicholas A. Bellinger" Subject: [PATCH 1/3] net/utils: Introduce inet_addr_is_any Date: Tue, 6 Feb 2018 11:44:30 +0200 Message-Id: <20180206094432.12761-2-sagi@grimberg.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180206094432.12761-1-sagi@grimberg.me> References: <20180206094432.12761-1-sagi@grimberg.me> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Can be useful to check INET_ANY address for both ipv4/ipv6 addresses. Signed-off-by: Sagi Grimberg Cc: "David S. Miller" Cc: netdev@vger.kernel.org --- include/linux/inet.h | 1 + net/core/utils.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/inet.h b/include/linux/inet.h index 636ebe87e6f8..97defc1139e9 100644 --- a/include/linux/inet.h +++ b/include/linux/inet.h @@ -59,5 +59,6 @@ extern int in6_pton(const char *src, int srclen, u8 *dst, int delim, const char extern int inet_pton_with_scope(struct net *net, unsigned short af, const char *src, const char *port, struct sockaddr_storage *addr); +extern bool inet_addr_is_any(struct sockaddr *addr); #endif /* _LINUX_INET_H */ diff --git a/net/core/utils.c b/net/core/utils.c index 93066bd0305a..a6e21111e523 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) +{ + bool ret = false; + + 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)) + ret = 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)) + ret = true; + } + + return ret; +} +EXPORT_SYMBOL(inet_addr_is_any); + void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb, __be32 from, __be32 to, bool pseudohdr) {