1 From 0448f4e7b9daf6d126b8ea920d871cd4a03a7806 Mon Sep 17 00:00:00 2001
2 From: Carsten Emde <C.Emde@osadl.org>
3 Date: Tue, 19 Jul 2011 13:51:17 +0100
4 Subject: [PATCH 195/366] net: sysrq via icmp
6 There are (probably rare) situations when a system crashed and the system
7 console becomes unresponsive but the network icmp layer still is alive.
8 Wouldn't it be wonderful, if we then could submit a sysreq command via ping?
10 This patch provides this facility. Please consult the updated documentation
11 Documentation/sysrq.txt for details.
13 Signed-off-by: Carsten Emde <C.Emde@osadl.org>
15 Documentation/sysrq.txt | 11 +++++++++--
16 include/net/netns/ipv4.h | 1 +
17 net/ipv4/icmp.c | 30 ++++++++++++++++++++++++++++++
18 net/ipv4/sysctl_net_ipv4.c | 7 +++++++
19 4 files changed, 47 insertions(+), 2 deletions(-)
21 diff --git a/Documentation/sysrq.txt b/Documentation/sysrq.txt
22 index 13f5619..f64d075 100644
23 --- a/Documentation/sysrq.txt
24 +++ b/Documentation/sysrq.txt
25 @@ -59,10 +59,17 @@ On PowerPC - Press 'ALT - Print Screen (or F13) - <command key>,
26 On other - If you know of the key combos for other architectures, please
27 let me know so I can add them to this section.
29 -On all - write a character to /proc/sysrq-trigger. e.g.:
31 +On all - write a character to /proc/sysrq-trigger, e.g.:
32 echo t > /proc/sysrq-trigger
34 +On all - Enable network SysRq by writing a cookie to icmp_echo_sysrq, e.g.
35 + echo 0x01020304 >/proc/sys/net/ipv4/icmp_echo_sysrq
36 + Send an ICMP echo request with this pattern plus the particular
37 + SysRq command key. Example:
38 + # ping -c1 -s57 -p0102030468
39 + will trigger the SysRq-H (help) command.
42 * What are the 'command' keys?
43 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44 'b' - Will immediately reboot the system without syncing or unmounting
45 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
46 index c68926b..dd0751e 100644
47 --- a/include/net/netns/ipv4.h
48 +++ b/include/net/netns/ipv4.h
49 @@ -70,6 +70,7 @@ struct netns_ipv4 {
51 int sysctl_icmp_echo_ignore_all;
52 int sysctl_icmp_echo_ignore_broadcasts;
53 + int sysctl_icmp_echo_sysrq;
54 int sysctl_icmp_ignore_bogus_error_responses;
55 int sysctl_icmp_ratelimit;
56 int sysctl_icmp_ratemask;
57 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
58 index ef2d432..288d20f 100644
62 #include <linux/jiffies.h>
63 #include <linux/kernel.h>
64 #include <linux/fcntl.h>
65 +#include <linux/sysrq.h>
66 #include <linux/socket.h>
68 #include <linux/inet.h>
69 @@ -893,6 +894,30 @@ static bool icmp_redirect(struct sk_buff *skb)
73 + * 32bit and 64bit have different timestamp length, so we check for
74 + * the cookie at offset 20 and verify it is repeated at offset 50
78 +#define CO_SIZE sizeof(int)
79 +#define ICMP_SYSRQ_SIZE 57
82 + * We got a ICMP_SYSRQ_SIZE sized ping request. Check for the cookie
83 + * pattern and if it matches send the next byte as a trigger to sysrq.
85 +static void icmp_check_sysrq(struct net *net, struct sk_buff *skb)
87 + int cookie = htonl(net->ipv4.sysctl_icmp_echo_sysrq);
88 + char *p = skb->data;
90 + if (!memcmp(&cookie, p + CO_POS0, CO_SIZE) &&
91 + !memcmp(&cookie, p + CO_POS1, CO_SIZE) &&
92 + p[CO_POS0 + CO_SIZE] == p[CO_POS1 + CO_SIZE])
93 + handle_sysrq(p[CO_POS0 + CO_SIZE]);
97 * Handle ICMP_ECHO ("ping") requests.
99 * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
100 @@ -919,6 +944,11 @@ static bool icmp_echo(struct sk_buff *skb)
101 icmp_param.data_len = skb->len;
102 icmp_param.head_len = sizeof(struct icmphdr);
103 icmp_reply(&icmp_param, skb);
105 + if (skb->len == ICMP_SYSRQ_SIZE &&
106 + net->ipv4.sysctl_icmp_echo_sysrq) {
107 + icmp_check_sysrq(net, skb);
110 /* should there be an ICMP stat for ignored echos? */
112 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
113 index 4612336..123ffd6 100644
114 --- a/net/ipv4/sysctl_net_ipv4.c
115 +++ b/net/ipv4/sysctl_net_ipv4.c
116 @@ -840,6 +840,13 @@ static struct ctl_table ipv4_net_table[] = {
117 .proc_handler = proc_dointvec
120 + .procname = "icmp_echo_sysrq",
121 + .data = &init_net.ipv4.sysctl_icmp_echo_sysrq,
122 + .maxlen = sizeof(int),
124 + .proc_handler = proc_dointvec
127 .procname = "icmp_ignore_bogus_error_responses",
128 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
129 .maxlen = sizeof(int),