From patchwork Mon Mar 11 22:39:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Suryaputra X-Patchwork-Id: 1055037 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uba/PTwJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44JK183Dc8z9sBr for ; Tue, 12 Mar 2019 13:39:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726887AbfCLCjG (ORCPT ); Mon, 11 Mar 2019 22:39:06 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:33606 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbfCLCjF (ORCPT ); Mon, 11 Mar 2019 22:39:05 -0400 Received: by mail-yw1-f66.google.com with SMTP id a199so894206ywa.0 for ; Mon, 11 Mar 2019 19:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Jk/Rw3BXlAwPX7S8bUgInyqsqaePbG3ZF3kd7KHPS0E=; b=uba/PTwJ1moYyY48851NgZXIi14MUUX/TE/8zr86dv5oaiXbN/+Ddm0iNRt5d7pwAM VujgxGQ9EmVf9vTIfnhkO7dFRWoroaYfdaNVsHq1OjeP6FehVm9bXfMi2CqYNObS0OOT ALXWDnh5Z6u7RMgpVstyumIyn29YnqfYXqONUqFLWe/kQ7T13ctg1Qy4jkOyfLvk5lSz pmurw15nu2Kqa8hhQpGfJSFDahDxcgvjVOQM6CVnlXuhQhKC4iHyYmgFEjedFvsy2LqR w4gl7BHWEzw8ql4xYmeXc+CQ09UNYc9CLbwFwt3eeJ1ChCKwpV4EC2ALNbjeLVm0+DMY fh0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Jk/Rw3BXlAwPX7S8bUgInyqsqaePbG3ZF3kd7KHPS0E=; b=OZTWqrfZ93NA09UumP7RiHLtBl2+47x39x4amMvksGdgLhPjVtWGihx9Gg+UrWGuOD CcSggDTkMcwOizVx/drhx83zhox6qxQRzX62eNrYVUkWXD7g0mjfxYsgsf4P4jb0MpP2 p1SIDk21Zt8sEru4p0YdYUYt+QMluCccwX2qmAqkb9Bl8i+7bJ6bT3e5/CCEyNoTMS1L NK+x+SpgHq5BOnlfvPybGRl+LxdOQ1XvSIEuvntL+gUJWUBLEqksSG+N/qJ9uEh6bf1J h/syP8ehI/jZYmten7DoJ+DE+UnYXQLKSGGm4jSUnzc2xyE4LpezzBsfr3bqFbR6ONv4 LdUA== X-Gm-Message-State: APjAAAWp5QtHLHflLH6/56zkfJuAlAWtXw1j0ilE6TMM+64dMU9LjPb8 a9+qv+IChCxUy/In9rXnTVopKE0= X-Google-Smtp-Source: APXvYqyy3EC06jzKj7nRa13O75jF4DxUkdtTa1mkdA2dMw4rVNjg3oQO2PmJWhcImNkstK3fOLFa4g== X-Received: by 2002:a81:1017:: with SMTP id 23mr27326491ywq.72.1552358343764; Mon, 11 Mar 2019 19:39:03 -0700 (PDT) Received: from localhost.localdomain (99-149-127-125.lightspeed.rlghnc.sbcglobal.net. [99.149.127.125]) by smtp.gmail.com with ESMTPSA id y134sm2796416ywg.8.2019.03.11.19.39.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 19:39:03 -0700 (PDT) From: Stephen Suryaputra To: netdev@vger.kernel.org Cc: Stephen Suryaputra Subject: [PATCH net-next] ipv6: Add icmp_echo_ignore_multicast support for ICMPv6 Date: Mon, 11 Mar 2019 18:39:38 -0400 Message-Id: <20190311223938.2241-1-ssuryaextr@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org IPv4 has icmp_echo_ignore_broadcast to prevent responding to broadcast pings. IPv6 needs a similar mechanism. Signed-off-by: Stephen Suryaputra --- Documentation/networking/ip-sysctl.txt | 5 +++++ include/net/netns/ipv6.h | 1 + include/uapi/linux/sysctl.h | 3 ++- net/ipv6/af_inet6.c | 1 + net/ipv6/icmp.c | 12 ++++++++++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt index acdfb5d2bcaa..55ea7def46be 100644 --- a/Documentation/networking/ip-sysctl.txt +++ b/Documentation/networking/ip-sysctl.txt @@ -1918,6 +1918,11 @@ echo_ignore_all - BOOLEAN requests sent to it over the IPv6 protocol. Default: 0 +echo_ignore_multicast - BOOLEAN + If set non-zero, then the kernel will ignore all ICMP ECHO + requests sent to it over the IPv6 protocol via multicast. + Default: 0 + xfrm6_gc_thresh - INTEGER The threshold at which we will start garbage collecting for IPv6 destination cache entries. At twice this value the system will diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index b028a1dc150d..e29aff15acc9 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -33,6 +33,7 @@ struct netns_sysctl_ipv6 { int auto_flowlabels; int icmpv6_time; int icmpv6_echo_ignore_all; + int icmpv6_echo_ignore_multicast; int anycast_src_echo_reply; int ip_nonlocal_bind; int fwmark_reflect; diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h index 87aa2a6d9125..bd83ddedc014 100644 --- a/include/uapi/linux/sysctl.h +++ b/include/uapi/linux/sysctl.h @@ -577,7 +577,8 @@ enum { /* /proc/sys/net/ipv6/icmp */ enum { NET_IPV6_ICMP_RATELIMIT = 1, - NET_IPV6_ICMP_ECHO_IGNORE_ALL = 2 + NET_IPV6_ICMP_ECHO_IGNORE_ALL = 2, + NET_IPV6_ICMP_ECHO_IGNORE_MULTICAST = 3 }; /* /proc/sys/net//neigh/ */ diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 2f45d2a3e3a3..fdc117de849c 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -847,6 +847,7 @@ static int __net_init inet6_net_init(struct net *net) net->ipv6.sysctl.bindv6only = 0; net->ipv6.sysctl.icmpv6_time = 1*HZ; net->ipv6.sysctl.icmpv6_echo_ignore_all = 0; + net->ipv6.sysctl.icmpv6_echo_ignore_multicast = 0; net->ipv6.sysctl.flowlabel_consistency = 1; net->ipv6.sysctl.auto_flowlabels = IP6_DEFAULT_AUTO_FLOW_LABELS; net->ipv6.sysctl.idgen_retries = 3; diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index 802faa2fcc0e..0907bcede5e5 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -684,6 +684,10 @@ static void icmpv6_echo_reply(struct sk_buff *skb) struct ipcm6_cookie ipc6; u32 mark = IP6_REPLY_MARK(net, skb->mark); + if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) && + net->ipv6.sysctl.icmpv6_echo_ignore_multicast) + return; + saddr = &ipv6_hdr(skb)->daddr; if (!ipv6_unicast_destination(skb) && @@ -1115,6 +1119,13 @@ static struct ctl_table ipv6_icmp_table_template[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "echo_ignore_multicast", + .data = &init_net.ipv6.sysctl.icmpv6_echo_ignore_multicast, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, { }, }; @@ -1129,6 +1140,7 @@ struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net) if (table) { table[0].data = &net->ipv6.sysctl.icmpv6_time; table[1].data = &net->ipv6.sysctl.icmpv6_echo_ignore_all; + table[2].data = &net->ipv6.sysctl.icmpv6_echo_ignore_multicast; } return table; }