Skip to content

Commit e6f86b0

Browse files
Virgile Jarrydavem330
authored andcommitted
ipv6: Add icmp_echo_ignore_all support for ICMPv6
Preventing the kernel from responding to ICMP Echo Requests messages can be useful in several ways. The sysctl parameter 'icmp_echo_ignore_all' can be used to prevent the kernel from responding to IPv4 ICMP echo requests. For IPv6 pings, such a sysctl kernel parameter did not exist. Add the ability to prevent the kernel from responding to IPv6 ICMP echo requests through the use of the following sysctl parameter : /proc/sys/net/ipv6/icmp/echo_ignore_all. Update the documentation to reflect this change. Signed-off-by: Virgile Jarry <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8f78004 commit e6f86b0

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

Documentation/networking/ip-sysctl.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,11 @@ ratelimit - INTEGER
18821882
otherwise the minimal space between responses in milliseconds.
18831883
Default: 1000
18841884

1885+
echo_ignore_all - BOOLEAN
1886+
If set non-zero, then the kernel will ignore all ICMP ECHO
1887+
requests sent to it over the IPv6 protocol.
1888+
Default: 0
1889+
18851890
xfrm6_gc_thresh - INTEGER
18861891
The threshold at which we will start garbage collecting for IPv6
18871892
destination cache entries. At twice this value the system will

include/net/netns/ipv6.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct netns_sysctl_ipv6 {
3232
int flowlabel_consistency;
3333
int auto_flowlabels;
3434
int icmpv6_time;
35+
int icmpv6_echo_ignore_all;
3536
int anycast_src_echo_reply;
3637
int ip_nonlocal_bind;
3738
int fwmark_reflect;

include/uapi/linux/sysctl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ enum {
575575

576576
/* /proc/sys/net/ipv6/icmp */
577577
enum {
578-
NET_IPV6_ICMP_RATELIMIT=1
578+
NET_IPV6_ICMP_RATELIMIT = 1,
579+
NET_IPV6_ICMP_ECHO_IGNORE_ALL = 2
579580
};
580581

581582
/* /proc/sys/net/<protocol>/neigh/<dev> */

net/ipv6/af_inet6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ static int __net_init inet6_net_init(struct net *net)
832832

833833
net->ipv6.sysctl.bindv6only = 0;
834834
net->ipv6.sysctl.icmpv6_time = 1*HZ;
835+
net->ipv6.sysctl.icmpv6_echo_ignore_all = 0;
835836
net->ipv6.sysctl.flowlabel_consistency = 1;
836837
net->ipv6.sysctl.auto_flowlabels = IP6_DEFAULT_AUTO_FLOW_LABELS;
837838
net->ipv6.sysctl.idgen_retries = 3;

net/ipv6/icmp.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
794794

795795
static int icmpv6_rcv(struct sk_buff *skb)
796796
{
797+
struct net *net = dev_net(skb->dev);
797798
struct net_device *dev = skb->dev;
798799
struct inet6_dev *idev = __in6_dev_get(dev);
799800
const struct in6_addr *saddr, *daddr;
@@ -843,7 +844,8 @@ static int icmpv6_rcv(struct sk_buff *skb)
843844

844845
switch (type) {
845846
case ICMPV6_ECHO_REQUEST:
846-
icmpv6_echo_reply(skb);
847+
if (!net->ipv6.sysctl.icmpv6_echo_ignore_all)
848+
icmpv6_echo_reply(skb);
847849
break;
848850

849851
case ICMPV6_ECHO_REPLY:
@@ -1104,6 +1106,13 @@ static struct ctl_table ipv6_icmp_table_template[] = {
11041106
.mode = 0644,
11051107
.proc_handler = proc_dointvec_ms_jiffies,
11061108
},
1109+
{
1110+
.procname = "echo_ignore_all",
1111+
.data = &init_net.ipv6.sysctl.icmpv6_echo_ignore_all,
1112+
.maxlen = sizeof(int),
1113+
.mode = 0644,
1114+
.proc_handler = proc_dointvec,
1115+
},
11071116
{ },
11081117
};
11091118

@@ -1115,9 +1124,10 @@ struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
11151124
sizeof(ipv6_icmp_table_template),
11161125
GFP_KERNEL);
11171126

1118-
if (table)
1127+
if (table) {
11191128
table[0].data = &net->ipv6.sysctl.icmpv6_time;
1120-
1129+
table[1].data = &net->ipv6.sysctl.icmpv6_echo_ignore_all;
1130+
}
11211131
return table;
11221132
}
11231133
#endif

0 commit comments

Comments
 (0)