From patchwork Wed Feb 7 13:05:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 10205147 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 0067F60247 for ; Wed, 7 Feb 2018 13:05:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFB0E28F75 for ; Wed, 7 Feb 2018 13:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D48C028F78; Wed, 7 Feb 2018 13:05:49 +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 2CA8028F75 for ; Wed, 7 Feb 2018 13:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754114AbeBGNFs (ORCPT ); Wed, 7 Feb 2018 08:05:48 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:45069 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753539AbeBGNFs (ORCPT ); Wed, 7 Feb 2018 08:05:48 -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=vR4isarJFxc3Bmm8HVB7XGXa6Y4sESNxObdK7r80si4=; b=nHcjxZQNrFqm6cf8lcH0LWs11 ajKdCYkxN2wnOCQJ5UBtyW4OQpoSdFSsMzV4NENXggWjpw+t5gzzEZOGlb4hgs5BGBdMVmTGm3lL2 meCt5ga0xXb5SfANv691id23i5U0euadYT3Lzecyu6BjshONX3tn4lHV6Uw+F4BoKeVE3HpyKkQAz ANIEWzA2X9Iyws9l0LJC+ghRWIoDgNDFaEqqVxxlER6adQI8QnF6fmSCbuGOl3dbEU8NIIYg5bGO4 FRME/tkQo6G/k/deHqkP4/M5qSV6Ks41yc3vTuKEHJPnLo5TzF68D3MS1xVrs2a2QvjLvXUEhqtHP sjQUA7mpA==; 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 1ejPQ2-0006Lv-0o; Wed, 07 Feb 2018 13:05:46 +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 v2 1/3] net/utils: Introduce inet_addr_is_any Date: Wed, 7 Feb 2018 15:05:16 +0200 Message-Id: <20180207130518.22803-2-sagi@grimberg.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180207130518.22803-1-sagi@grimberg.me> References: <20180207130518.22803-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..6e331a7904e7 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; + static 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) {