Merge tag 'v3.10.106' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / ipv4 / ping.c
CommitLineData
c319b4d7
VK
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * "Ping" sockets
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 *
13 * Based on ipv4/udp.c code.
14 *
15 * Authors: Vasiliy Kulikov / Openwall (for Linux 2.6),
16 * Pavel Kankovsky (for Linux 2.4.32)
17 *
18 * Pavel gave all rights to bugs to Vasiliy,
19 * none of the bugs are Pavel's now.
20 *
21 */
22
c319b4d7 23#include <linux/uaccess.h>
c319b4d7
VK
24#include <linux/types.h>
25#include <linux/fcntl.h>
26#include <linux/socket.h>
27#include <linux/sockios.h>
28#include <linux/in.h>
29#include <linux/errno.h>
30#include <linux/timer.h>
31#include <linux/mm.h>
32#include <linux/inet.h>
33#include <linux/netdevice.h>
34#include <net/snmp.h>
35#include <net/ip.h>
c319b4d7
VK
36#include <net/icmp.h>
37#include <net/protocol.h>
38#include <linux/skbuff.h>
39#include <linux/proc_fs.h>
bc3b2d7f 40#include <linux/export.h>
c319b4d7
VK
41#include <net/sock.h>
42#include <net/ping.h>
c319b4d7
VK
43#include <net/udp.h>
44#include <net/route.h>
45#include <net/inet_common.h>
46#include <net/checksum.h>
47
6fa3eb70
S
48#if IS_ENABLED(CONFIG_IPV6)
49#include <linux/in6.h>
50#include <linux/icmpv6.h>
51#include <net/addrconf.h>
52#include <net/ipv6.h>
53#include <net/transp_v6.h>
54#endif
c319b4d7 55
6fa3eb70
S
56
57struct ping_table ping_table;
58struct pingv6_ops pingv6_ops;
59EXPORT_SYMBOL_GPL(pingv6_ops);
c319b4d7 60
1b1cb1f7 61static u16 ping_port_rover;
c319b4d7 62
95c96174 63static inline int ping_hashfn(struct net *net, unsigned int num, unsigned int mask)
c319b4d7
VK
64{
65 int res = (num + net_hash_mix(net)) & mask;
95c96174 66
c319b4d7
VK
67 pr_debug("hash(%d) = %d\n", num, res);
68 return res;
69}
6fa3eb70 70EXPORT_SYMBOL_GPL(ping_hash);
c319b4d7
VK
71
72static inline struct hlist_nulls_head *ping_hashslot(struct ping_table *table,
95c96174 73 struct net *net, unsigned int num)
c319b4d7
VK
74{
75 return &table->hash[ping_hashfn(net, num, PING_HTABLE_MASK)];
76}
77
6fa3eb70 78int ping_get_port(struct sock *sk, unsigned short ident)
c319b4d7
VK
79{
80 struct hlist_nulls_node *node;
81 struct hlist_nulls_head *hlist;
82 struct inet_sock *isk, *isk2;
83 struct sock *sk2 = NULL;
84
85 isk = inet_sk(sk);
86 write_lock_bh(&ping_table.lock);
87 if (ident == 0) {
88 u32 i;
89 u16 result = ping_port_rover + 1;
90
91 for (i = 0; i < (1L << 16); i++, result++) {
92 if (!result)
93 result++; /* avoid zero */
94 hlist = ping_hashslot(&ping_table, sock_net(sk),
95 result);
96 ping_portaddr_for_each_entry(sk2, node, hlist) {
97 isk2 = inet_sk(sk2);
98
99 if (isk2->inet_num == result)
100 goto next_port;
101 }
102
103 /* found */
104 ping_port_rover = ident = result;
105 break;
106next_port:
107 ;
108 }
109 if (i >= (1L << 16))
110 goto fail;
111 } else {
112 hlist = ping_hashslot(&ping_table, sock_net(sk), ident);
113 ping_portaddr_for_each_entry(sk2, node, hlist) {
114 isk2 = inet_sk(sk2);
115
6fa3eb70
S
116 /* BUG? Why is this reuse and not reuseaddr? ping.c
117 * doesn't turn off SO_REUSEADDR, and it doesn't expect
118 * that other ping processes can steal its packets.
119 */
c319b4d7
VK
120 if ((isk2->inet_num == ident) &&
121 (sk2 != sk) &&
122 (!sk2->sk_reuse || !sk->sk_reuse))
123 goto fail;
124 }
125 }
126
127 pr_debug("found port/ident = %d\n", ident);
128 isk->inet_num = ident;
129 if (sk_unhashed(sk)) {
130 pr_debug("was not hashed\n");
131 sock_hold(sk);
132 hlist_nulls_add_head(&sk->sk_nulls_node, hlist);
133 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
134 }
135 write_unlock_bh(&ping_table.lock);
136 return 0;
137
138fail:
139 write_unlock_bh(&ping_table.lock);
140 return 1;
141}
6fa3eb70 142EXPORT_SYMBOL_GPL(ping_get_port);
c319b4d7 143
6fa3eb70 144void ping_hash(struct sock *sk)
c319b4d7 145{
6fa3eb70 146 pr_debug("ping_hash(sk->port=%u)\n", inet_sk(sk)->inet_num);
c319b4d7
VK
147 BUG(); /* "Please do not press this button again." */
148}
149
6fa3eb70 150void ping_unhash(struct sock *sk)
c319b4d7
VK
151{
152 struct inet_sock *isk = inet_sk(sk);
153 pr_debug("ping_v4_unhash(isk=%p,isk->num=%u)\n", isk, isk->inet_num);
60f704bd 154 write_lock_bh(&ping_table.lock);
c319b4d7 155 if (sk_hashed(sk)) {
c319b4d7 156 hlist_nulls_del(&sk->sk_nulls_node);
4b9e9796 157 sk_nulls_node_init(&sk->sk_nulls_node);
c319b4d7 158 sock_put(sk);
747465ef
ED
159 isk->inet_num = 0;
160 isk->inet_sport = 0;
c319b4d7 161 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
c319b4d7 162 }
60f704bd 163 write_unlock_bh(&ping_table.lock);
c319b4d7 164}
6fa3eb70 165EXPORT_SYMBOL_GPL(ping_unhash);
c319b4d7 166
6fa3eb70 167static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
c319b4d7
VK
168{
169 struct hlist_nulls_head *hslot = ping_hashslot(&ping_table, net, ident);
170 struct sock *sk = NULL;
171 struct inet_sock *isk;
172 struct hlist_nulls_node *hnode;
6fa3eb70
S
173 int dif = skb->dev->ifindex;
174
175 if (skb->protocol == htons(ETH_P_IP)) {
176 pr_debug("try to find: num = %d, daddr = %pI4, dif = %d\n",
177 (int)ident, &ip_hdr(skb)->daddr, dif);
178#if IS_ENABLED(CONFIG_IPV6)
179 } else if (skb->protocol == htons(ETH_P_IPV6)) {
180 pr_debug("try to find: num = %d, daddr = %pI6c, dif = %d\n",
181 (int)ident, &ipv6_hdr(skb)->daddr, dif);
182#endif
183 }
c319b4d7 184
c319b4d7
VK
185 read_lock_bh(&ping_table.lock);
186
187 ping_portaddr_for_each_entry(sk, hnode, hslot) {
188 isk = inet_sk(sk);
189
c319b4d7
VK
190 pr_debug("iterate\n");
191 if (isk->inet_num != ident)
192 continue;
6fa3eb70
S
193
194 if (skb->protocol == htons(ETH_P_IP) &&
195 sk->sk_family == AF_INET) {
196 pr_debug("found: %p: num=%d, daddr=%pI4, dif=%d\n", sk,
197 (int) isk->inet_num, &isk->inet_rcv_saddr,
198 sk->sk_bound_dev_if);
199
200 if (isk->inet_rcv_saddr &&
201 isk->inet_rcv_saddr != ip_hdr(skb)->daddr)
202 continue;
203#if IS_ENABLED(CONFIG_IPV6)
204 } else if (skb->protocol == htons(ETH_P_IPV6) &&
205 sk->sk_family == AF_INET6) {
206 struct ipv6_pinfo *np = inet6_sk(sk);
207
208 pr_debug("found: %p: num=%d, daddr=%pI6c, dif=%d\n", sk,
209 (int) isk->inet_num,
210 &inet6_sk(sk)->rcv_saddr,
211 sk->sk_bound_dev_if);
212
213 if (!ipv6_addr_any(&np->rcv_saddr) &&
214 !ipv6_addr_equal(&np->rcv_saddr,
215 &ipv6_hdr(skb)->daddr))
216 continue;
217#endif
218 }
219
c319b4d7
VK
220 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)
221 continue;
222
223 sock_hold(sk);
224 goto exit;
225 }
226
227 sk = NULL;
228exit:
229 read_unlock_bh(&ping_table.lock);
230
231 return sk;
232}
233
7064d16e
EB
234static void inet_get_ping_group_range_net(struct net *net, kgid_t *low,
235 kgid_t *high)
f56e03e8 236{
7064d16e 237 kgid_t *data = net->ipv4.sysctl_ping_group_range;
95c96174
ED
238 unsigned int seq;
239
f56e03e8
VK
240 do {
241 seq = read_seqbegin(&sysctl_local_ports.lock);
242
243 *low = data[0];
244 *high = data[1];
245 } while (read_seqretry(&sysctl_local_ports.lock, seq));
246}
247
248
6fa3eb70 249int ping_init_sock(struct sock *sk)
c319b4d7
VK
250{
251 struct net *net = sock_net(sk);
7064d16e 252 kgid_t group = current_egid();
8dbc8dc8
WX
253 struct group_info *group_info;
254 int i, j, count;
ae2975bc 255 kgid_t low, high;
8dbc8dc8 256 int ret = 0;
6fa3eb70 257
7064d16e
EB
258 inet_get_ping_group_range_net(net, &low, &high);
259 if (gid_lte(low, group) && gid_lte(group, high))
c319b4d7
VK
260 return 0;
261
8dbc8dc8
WX
262 group_info = get_current_groups();
263 count = group_info->ngroups;
c319b4d7
VK
264 for (i = 0; i < group_info->nblocks; i++) {
265 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
c319b4d7 266 for (j = 0; j < cp_count; j++) {
ae2975bc
EB
267 kgid_t gid = group_info->blocks[i][j];
268 if (gid_lte(low, gid) && gid_lte(gid, high))
8dbc8dc8 269 goto out_release_group;
c319b4d7
VK
270 }
271
272 count -= cp_count;
273 }
274
8dbc8dc8
WX
275 ret = -EACCES;
276
277out_release_group:
278 put_group_info(group_info);
279 return ret;
c319b4d7 280}
6fa3eb70 281EXPORT_SYMBOL_GPL(ping_init_sock);
c319b4d7 282
6fa3eb70 283void ping_close(struct sock *sk, long timeout)
c319b4d7
VK
284{
285 pr_debug("ping_close(sk=%p,sk->num=%u)\n",
058bd4d2 286 inet_sk(sk), inet_sk(sk)->inet_num);
c319b4d7
VK
287 pr_debug("isk->refcnt = %d\n", sk->sk_refcnt.counter);
288
289 sk_common_release(sk);
6fa3eb70 290 pr_info("ping_close done\n");
c319b4d7 291}
6fa3eb70
S
292EXPORT_SYMBOL_GPL(ping_close);
293
294/* Checks the bind address and possibly modifies sk->sk_bound_dev_if. */
295int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
296 struct sockaddr *uaddr, int addr_len) {
297 struct net *net = sock_net(sk);
298 if (sk->sk_family == AF_INET) {
299 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
300 int chk_addr_ret;
301
302 if (addr_len < sizeof(*addr))
303 return -EINVAL;
304
305 pr_debug("ping_check_bind_addr(sk=%p,addr=%pI4,port=%d)\n",
306 sk, &addr->sin_addr.s_addr, ntohs(addr->sin_port));
307
308 chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
c319b4d7 309
6fa3eb70
S
310 if (addr->sin_addr.s_addr == htonl(INADDR_ANY))
311 chk_addr_ret = RTN_LOCAL;
312
313 if ((sysctl_ip_nonlocal_bind == 0 &&
314 isk->freebind == 0 && isk->transparent == 0 &&
315 chk_addr_ret != RTN_LOCAL) ||
316 chk_addr_ret == RTN_MULTICAST ||
317 chk_addr_ret == RTN_BROADCAST)
318 return -EADDRNOTAVAIL;
319
320#if IS_ENABLED(CONFIG_IPV6)
321 } else if (sk->sk_family == AF_INET6) {
322 struct sockaddr_in6 *addr = (struct sockaddr_in6 *) uaddr;
323 int addr_type, scoped, has_addr;
324 struct net_device *dev = NULL;
325
326 if (addr_len < sizeof(*addr))
327 return -EINVAL;
328
329 pr_debug("ping_check_bind_addr(sk=%p,addr=%pI6c,port=%d)\n",
330 sk, addr->sin6_addr.s6_addr, ntohs(addr->sin6_port));
331
332 addr_type = ipv6_addr_type(&addr->sin6_addr);
333 scoped = __ipv6_addr_needs_scope_id(addr_type);
334 if ((addr_type != IPV6_ADDR_ANY &&
335 !(addr_type & IPV6_ADDR_UNICAST)) ||
336 (scoped && !addr->sin6_scope_id))
337 return -EINVAL;
338
339 rcu_read_lock();
340 if (addr->sin6_scope_id) {
341 dev = dev_get_by_index_rcu(net, addr->sin6_scope_id);
342 if (!dev) {
343 rcu_read_unlock();
344 return -ENODEV;
345 }
346 }
347 has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
348 scoped);
349 rcu_read_unlock();
350
351 if (!(isk->freebind || isk->transparent || has_addr ||
352 addr_type == IPV6_ADDR_ANY))
353 return -EADDRNOTAVAIL;
354
355 if (scoped)
356 sk->sk_bound_dev_if = addr->sin6_scope_id;
357#endif
358 } else {
359 return -EAFNOSUPPORT;
360 }
361 return 0;
362}
363
364void ping_set_saddr(struct sock *sk, struct sockaddr *saddr)
365{
366 if (saddr->sa_family == AF_INET) {
367 struct inet_sock *isk = inet_sk(sk);
368 struct sockaddr_in *addr = (struct sockaddr_in *) saddr;
369 isk->inet_rcv_saddr = isk->inet_saddr = addr->sin_addr.s_addr;
370#if IS_ENABLED(CONFIG_IPV6)
371 } else if (saddr->sa_family == AF_INET6) {
372 struct sockaddr_in6 *addr = (struct sockaddr_in6 *) saddr;
373 struct ipv6_pinfo *np = inet6_sk(sk);
374 np->rcv_saddr = np->saddr = addr->sin6_addr;
375#endif
376 }
377}
378
379void ping_clear_saddr(struct sock *sk, int dif)
380{
381 sk->sk_bound_dev_if = dif;
382 if (sk->sk_family == AF_INET) {
383 struct inet_sock *isk = inet_sk(sk);
384 isk->inet_rcv_saddr = isk->inet_saddr = 0;
385#if IS_ENABLED(CONFIG_IPV6)
386 } else if (sk->sk_family == AF_INET6) {
387 struct ipv6_pinfo *np = inet6_sk(sk);
388 memset(&np->rcv_saddr, 0, sizeof(np->rcv_saddr));
389 memset(&np->saddr, 0, sizeof(np->saddr));
390#endif
391 }
392}
c319b4d7
VK
393/*
394 * We need our own bind because there are no privileged id's == local ports.
395 * Moreover, we don't allow binding to multi- and broadcast addresses.
396 */
397
6fa3eb70 398int ping_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
c319b4d7 399{
c319b4d7
VK
400 struct inet_sock *isk = inet_sk(sk);
401 unsigned short snum;
c319b4d7 402 int err;
6fa3eb70 403 int dif = sk->sk_bound_dev_if;
c319b4d7 404
6fa3eb70
S
405 err = ping_check_bind_addr(sk, isk, uaddr, addr_len);
406 if (err)
407 return err;
c319b4d7
VK
408
409 lock_sock(sk);
410
411 err = -EINVAL;
412 if (isk->inet_num != 0)
413 goto out;
414
415 err = -EADDRINUSE;
6fa3eb70
S
416 ping_set_saddr(sk, uaddr);
417 snum = ntohs(((struct sockaddr_in *)uaddr)->sin_port);
418 if (ping_get_port(sk, snum) != 0) {
419 ping_clear_saddr(sk, dif);
c319b4d7
VK
420 goto out;
421 }
422
6fa3eb70 423 pr_debug("after bind(): num = %d, dif = %d\n",
058bd4d2 424 (int)isk->inet_num,
058bd4d2 425 (int)sk->sk_bound_dev_if);
c319b4d7
VK
426
427 err = 0;
6fa3eb70
S
428 if ((sk->sk_family == AF_INET && isk->inet_rcv_saddr) ||
429 (sk->sk_family == AF_INET6 &&
430 !ipv6_addr_any(&inet6_sk(sk)->rcv_saddr)))
c319b4d7 431 sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
6fa3eb70 432
c319b4d7
VK
433 if (snum)
434 sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
435 isk->inet_sport = htons(isk->inet_num);
436 isk->inet_daddr = 0;
437 isk->inet_dport = 0;
6fa3eb70
S
438
439#if IS_ENABLED(CONFIG_IPV6)
440 if (sk->sk_family == AF_INET6)
441 memset(&inet6_sk(sk)->daddr, 0, sizeof(inet6_sk(sk)->daddr));
442#endif
443
c319b4d7
VK
444 sk_dst_reset(sk);
445out:
446 release_sock(sk);
447 pr_debug("ping_v4_bind -> %d\n", err);
448 return err;
449}
6fa3eb70 450EXPORT_SYMBOL_GPL(ping_bind);
c319b4d7
VK
451
452/*
453 * Is this a supported type of ICMP message?
454 */
455
6fa3eb70 456static inline int ping_supported(int family, int type, int code)
c319b4d7 457{
6fa3eb70
S
458 return (family == AF_INET && type == ICMP_ECHO && code == 0) ||
459 (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0);
c319b4d7
VK
460}
461
462/*
463 * This routine is called by the ICMP module when it gets some
464 * sort of error condition.
465 */
466
6fa3eb70 467void ping_err(struct sk_buff *skb, int offset, u32 info)
c319b4d7 468{
6fa3eb70
S
469 int family;
470 struct icmphdr *icmph;
c319b4d7 471 struct inet_sock *inet_sock;
6fa3eb70
S
472 int type;
473 int code;
c319b4d7
VK
474 struct net *net = dev_net(skb->dev);
475 struct sock *sk;
476 int harderr;
477 int err;
478
6fa3eb70
S
479 if (skb->protocol == htons(ETH_P_IP)) {
480 family = AF_INET;
481 type = icmp_hdr(skb)->type;
482 code = icmp_hdr(skb)->code;
483 icmph = (struct icmphdr *)(skb->data + offset);
484 } else if (skb->protocol == htons(ETH_P_IPV6)) {
485 family = AF_INET6;
486 type = icmp6_hdr(skb)->icmp6_type;
487 code = icmp6_hdr(skb)->icmp6_code;
488 icmph = (struct icmphdr *) (skb->data + offset);
489 } else {
490 BUG();
491 }
492
c319b4d7
VK
493 /* We assume the packet has already been checked by icmp_unreach */
494
6fa3eb70 495 if (!ping_supported(family, icmph->type, icmph->code))
c319b4d7
VK
496 return;
497
6fa3eb70
S
498 pr_debug("ping_err(proto=0x%x,type=%d,code=%d,id=%04x,seq=%04x)\n",
499 skb->protocol, type, code, ntohs(icmph->un.echo.id),
500 ntohs(icmph->un.echo.sequence));
c319b4d7 501
6fa3eb70 502 sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id));
c319b4d7 503 if (sk == NULL) {
c319b4d7
VK
504 pr_debug("no socket, dropping\n");
505 return; /* No socket for error */
506 }
507 pr_debug("err on socket %p\n", sk);
508
509 err = 0;
510 harderr = 0;
511 inet_sock = inet_sk(sk);
512
6fa3eb70
S
513 if (skb->protocol == htons(ETH_P_IP)) {
514 switch (type) {
515 default:
516 case ICMP_TIME_EXCEEDED:
517 err = EHOSTUNREACH;
518 break;
519 case ICMP_SOURCE_QUENCH:
520 /* This is not a real error but ping wants to see it.
521 * Report it with some fake errno.
522 */
523 err = EREMOTEIO;
524 break;
525 case ICMP_PARAMETERPROB:
526 err = EPROTO;
527 harderr = 1;
528 break;
529 case ICMP_DEST_UNREACH:
530 if (code == ICMP_FRAG_NEEDED) { /* Path MTU discovery */
531 ipv4_sk_update_pmtu(skb, sk, info);
532 if (inet_sock->pmtudisc != IP_PMTUDISC_DONT) {
533 err = EMSGSIZE;
534 harderr = 1;
535 break;
536 }
537 goto out;
c319b4d7 538 }
6fa3eb70
S
539 err = EHOSTUNREACH;
540 if (code <= NR_ICMP_UNREACH) {
541 harderr = icmp_err_convert[code].fatal;
542 err = icmp_err_convert[code].errno;
543 }
544 break;
545 case ICMP_REDIRECT:
546 /* See ICMP_SOURCE_QUENCH */
547 ipv4_sk_redirect(skb, sk);
548 err = EREMOTEIO;
549 break;
c319b4d7 550 }
6fa3eb70
S
551#if IS_ENABLED(CONFIG_IPV6)
552 } else if (skb->protocol == htons(ETH_P_IPV6)) {
553 harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
554#endif
c319b4d7
VK
555 }
556
557 /*
558 * RFC1122: OK. Passes ICMP errors back to application, as per
559 * 4.1.3.3.
560 */
6fa3eb70
S
561 if ((family == AF_INET && !inet_sock->recverr) ||
562 (family == AF_INET6 && !inet6_sk(sk)->recverr)) {
c319b4d7
VK
563 if (!harderr || sk->sk_state != TCP_ESTABLISHED)
564 goto out;
565 } else {
6fa3eb70
S
566 if (family == AF_INET) {
567 ip_icmp_error(sk, skb, err, 0 /* no remote port */,
568 info, (u8 *)icmph);
569#if IS_ENABLED(CONFIG_IPV6)
570 } else if (family == AF_INET6) {
571 pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
572 info, (u8 *)icmph);
573#endif
574 }
c319b4d7
VK
575 }
576 sk->sk_err = err;
577 sk->sk_error_report(sk);
578out:
579 sock_put(sk);
580}
6fa3eb70 581EXPORT_SYMBOL_GPL(ping_err);
c319b4d7
VK
582
583/*
6fa3eb70
S
584 * Copy and checksum an ICMP Echo packet from user space into a buffer
585 * starting from the payload.
c319b4d7
VK
586 */
587
6fa3eb70
S
588int ping_getfrag(void *from, char *to,
589 int offset, int fraglen, int odd, struct sk_buff *skb)
c319b4d7
VK
590{
591 struct pingfakehdr *pfh = (struct pingfakehdr *)from;
592
593 if (offset == 0) {
594 if (fraglen < sizeof(struct icmphdr))
595 BUG();
596 if (csum_partial_copy_fromiovecend(to + sizeof(struct icmphdr),
597 pfh->iov, 0, fraglen - sizeof(struct icmphdr),
598 &pfh->wcheck))
599 return -EFAULT;
6fa3eb70
S
600 } else if (offset < sizeof(struct icmphdr)) {
601 BUG();
602 } else {
603 if (csum_partial_copy_fromiovecend
604 (to, pfh->iov, offset - sizeof(struct icmphdr),
605 fraglen, &pfh->wcheck))
606 return -EFAULT;
607 }
c319b4d7 608
6fa3eb70
S
609#if IS_ENABLED(CONFIG_IPV6)
610 /* For IPv6, checksum each skb as we go along, as expected by
611 * icmpv6_push_pending_frames. For IPv4, accumulate the checksum in
612 * wcheck, it will be finalized in ping_v4_push_pending_frames.
613 */
614 if (pfh->family == AF_INET6) {
615 skb->csum = pfh->wcheck;
616 skb->ip_summed = CHECKSUM_NONE;
617 pfh->wcheck = 0;
c319b4d7 618 }
6fa3eb70
S
619#endif
620
c319b4d7
VK
621 return 0;
622}
6fa3eb70 623EXPORT_SYMBOL_GPL(ping_getfrag);
c319b4d7 624
6fa3eb70
S
625static int ping_v4_push_pending_frames(struct sock *sk, struct pingfakehdr *pfh,
626 struct flowi4 *fl4)
c319b4d7
VK
627{
628 struct sk_buff *skb = skb_peek(&sk->sk_write_queue);
629
c6dfb877
WC
630 if (!skb)
631 return 0;
c319b4d7
VK
632 pfh->wcheck = csum_partial((char *)&pfh->icmph,
633 sizeof(struct icmphdr), pfh->wcheck);
634 pfh->icmph.checksum = csum_fold(pfh->wcheck);
635 memcpy(icmp_hdr(skb), &pfh->icmph, sizeof(struct icmphdr));
636 skb->ip_summed = CHECKSUM_NONE;
637 return ip_push_pending_frames(sk, fl4);
638}
639
6fa3eb70
S
640int ping_common_sendmsg(int family, struct msghdr *msg, size_t len,
641 void *user_icmph, size_t icmph_len) {
642 u8 type, code;
c319b4d7 643
4b9e9796 644 if (len > 0xFFFF || len < icmph_len)
c319b4d7
VK
645 return -EMSGSIZE;
646
647 /*
648 * Check the flags.
649 */
650
651 /* Mirror BSD error message compatibility */
652 if (msg->msg_flags & MSG_OOB)
653 return -EOPNOTSUPP;
654
655 /*
656 * Fetch the ICMP header provided by the userland.
6fa3eb70 657 * iovec is modified! The ICMP header is consumed.
c319b4d7 658 */
6fa3eb70 659 if (memcpy_fromiovec(user_icmph, msg->msg_iov, icmph_len))
c319b4d7 660 return -EFAULT;
6fa3eb70
S
661
662 if (family == AF_INET) {
663 type = ((struct icmphdr *) user_icmph)->type;
664 code = ((struct icmphdr *) user_icmph)->code;
665#if IS_ENABLED(CONFIG_IPV6)
666 } else if (family == AF_INET6) {
667 type = ((struct icmp6hdr *) user_icmph)->icmp6_type;
668 code = ((struct icmp6hdr *) user_icmph)->icmp6_code;
669#endif
670 } else {
671 BUG();
672 }
673
674 if (!ping_supported(family, type, code))
c319b4d7
VK
675 return -EINVAL;
676
6fa3eb70
S
677 return 0;
678}
679EXPORT_SYMBOL_GPL(ping_common_sendmsg);
680
681int ping_v4_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
682 size_t len)
683{
684 struct net *net = sock_net(sk);
685 struct flowi4 fl4;
686 struct inet_sock *inet = inet_sk(sk);
687 struct ipcm_cookie ipc;
688 struct icmphdr user_icmph;
689 struct pingfakehdr pfh;
690 struct rtable *rt = NULL;
691 struct ip_options_data opt_copy;
692 int free = 0;
693 __be32 saddr, daddr, faddr;
694 u8 tos;
695 int err;
696
697 pr_debug("ping_v4_sendmsg(sk=%p,sk->num=%u)\n", inet, inet->inet_num);
698
699 err = ping_common_sendmsg(AF_INET, msg, len, &user_icmph,
700 sizeof(user_icmph));
701 if (err)
702 return err;
703
c319b4d7
VK
704 /*
705 * Get and verify the address.
706 */
707
708 if (msg->msg_name) {
709 struct sockaddr_in *usin = (struct sockaddr_in *)msg->msg_name;
710 if (msg->msg_namelen < sizeof(*usin))
711 return -EINVAL;
712 if (usin->sin_family != AF_INET)
713 return -EINVAL;
714 daddr = usin->sin_addr.s_addr;
715 /* no remote port */
716 } else {
717 if (sk->sk_state != TCP_ESTABLISHED)
718 return -EDESTADDRREQ;
719 daddr = inet->inet_daddr;
720 /* no remote port */
721 }
722
723 ipc.addr = inet->inet_saddr;
724 ipc.opt = NULL;
725 ipc.oif = sk->sk_bound_dev_if;
726 ipc.tx_flags = 0;
bf84a010
DB
727
728 sock_tx_timestamp(sk, &ipc.tx_flags);
c319b4d7
VK
729
730 if (msg->msg_controllen) {
731 err = ip_cmsg_send(sock_net(sk), msg, &ipc);
732 if (err)
733 return err;
734 if (ipc.opt)
735 free = 1;
736 }
737 if (!ipc.opt) {
738 struct ip_options_rcu *inet_opt;
739
740 rcu_read_lock();
741 inet_opt = rcu_dereference(inet->inet_opt);
742 if (inet_opt) {
743 memcpy(&opt_copy, inet_opt,
744 sizeof(*inet_opt) + inet_opt->opt.optlen);
745 ipc.opt = &opt_copy.opt;
746 }
747 rcu_read_unlock();
748 }
749
750 saddr = ipc.addr;
751 ipc.addr = faddr = daddr;
752
753 if (ipc.opt && ipc.opt->opt.srr) {
754 if (!daddr)
755 return -EINVAL;
756 faddr = ipc.opt->opt.faddr;
757 }
758 tos = RT_TOS(inet->tos);
759 if (sock_flag(sk, SOCK_LOCALROUTE) ||
760 (msg->msg_flags & MSG_DONTROUTE) ||
761 (ipc.opt && ipc.opt->opt.is_strictroute)) {
762 tos |= RTO_ONLINK;
763 }
764
765 if (ipv4_is_multicast(daddr)) {
766 if (!ipc.oif)
767 ipc.oif = inet->mc_index;
768 if (!saddr)
769 saddr = inet->mc_addr;
76e21053
EH
770 } else if (!ipc.oif)
771 ipc.oif = inet->uc_index;
c319b4d7
VK
772
773 flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos,
774 RT_SCOPE_UNIVERSE, sk->sk_protocol,
6fa3eb70
S
775 inet_sk_flowi_flags(sk), faddr, saddr, 0, 0,
776 sock_i_uid(sk));
c319b4d7
VK
777
778 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
779 rt = ip_route_output_flow(net, &fl4, sk);
780 if (IS_ERR(rt)) {
781 err = PTR_ERR(rt);
782 rt = NULL;
783 if (err == -ENETUNREACH)
6fa3eb70 784 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES);
c319b4d7
VK
785 goto out;
786 }
787
788 err = -EACCES;
789 if ((rt->rt_flags & RTCF_BROADCAST) &&
790 !sock_flag(sk, SOCK_BROADCAST))
791 goto out;
792
793 if (msg->msg_flags & MSG_CONFIRM)
794 goto do_confirm;
795back_from_confirm:
796
797 if (!ipc.addr)
798 ipc.addr = fl4.daddr;
799
800 lock_sock(sk);
801
802 pfh.icmph.type = user_icmph.type; /* already checked */
803 pfh.icmph.code = user_icmph.code; /* ditto */
804 pfh.icmph.checksum = 0;
805 pfh.icmph.un.echo.id = inet->inet_sport;
806 pfh.icmph.un.echo.sequence = user_icmph.un.echo.sequence;
807 pfh.iov = msg->msg_iov;
808 pfh.wcheck = 0;
6fa3eb70 809 pfh.family = AF_INET;
c319b4d7
VK
810
811 err = ip_append_data(sk, &fl4, ping_getfrag, &pfh, len,
812 0, &ipc, &rt, msg->msg_flags);
813 if (err)
814 ip_flush_pending_frames(sk);
815 else
6fa3eb70 816 err = ping_v4_push_pending_frames(sk, &pfh, &fl4);
c319b4d7
VK
817 release_sock(sk);
818
819out:
820 ip_rt_put(rt);
821 if (free)
822 kfree(ipc.opt);
823 if (!err) {
824 icmp_out_count(sock_net(sk), user_icmph.type);
825 return len;
826 }
827 return err;
828
829do_confirm:
830 dst_confirm(&rt->dst);
831 if (!(msg->msg_flags & MSG_PROBE) || len)
832 goto back_from_confirm;
833 err = 0;
834 goto out;
835}
836
6fa3eb70
S
837int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
838 size_t len, int noblock, int flags, int *addr_len)
c319b4d7
VK
839{
840 struct inet_sock *isk = inet_sk(sk);
6fa3eb70
S
841 int family = sk->sk_family;
842 struct sockaddr_in *sin;
843 struct sockaddr_in6 *sin6;
c319b4d7
VK
844 struct sk_buff *skb;
845 int copied, err;
846
847 pr_debug("ping_recvmsg(sk=%p,sk->num=%u)\n", isk, isk->inet_num);
848
a5e7424d 849 err = -EOPNOTSUPP;
c319b4d7
VK
850 if (flags & MSG_OOB)
851 goto out;
852
6fa3eb70
S
853 if (addr_len) {
854 if (family == AF_INET)
855 *addr_len = sizeof(*sin);
856 else if (family == AF_INET6 && addr_len)
857 *addr_len = sizeof(*sin6);
858 }
859
860 if (flags & MSG_ERRQUEUE) {
861 if (family == AF_INET) {
862 return ip_recv_error(sk, msg, len, addr_len);
863#if IS_ENABLED(CONFIG_IPV6)
864 } else if (family == AF_INET6) {
865 return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
866#endif
867 }
868 }
c319b4d7
VK
869
870 skb = skb_recv_datagram(sk, flags, noblock, &err);
871 if (!skb)
872 goto out;
873
874 copied = skb->len;
875 if (copied > len) {
876 msg->msg_flags |= MSG_TRUNC;
877 copied = len;
878 }
879
880 /* Don't bother checking the checksum */
881 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
882 if (err)
883 goto done;
884
885 sock_recv_timestamp(msg, sk, skb);
886
6fa3eb70
S
887 /* Copy the address and add cmsg data. */
888 if (family == AF_INET) {
889 sin = (struct sockaddr_in *) msg->msg_name;
890 if (sin) {
891 sin->sin_family = AF_INET;
892 sin->sin_port = 0 /* skb->h.uh->source */;
893 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
894 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
895 }
896 if (isk->cmsg_flags)
897 ip_cmsg_recv(msg, skb);
898
899#if IS_ENABLED(CONFIG_IPV6)
900 } else if (family == AF_INET6) {
901 struct ipv6_pinfo *np = inet6_sk(sk);
902 struct ipv6hdr *ip6 = ipv6_hdr(skb);
903 sin6 = (struct sockaddr_in6 *) msg->msg_name;
904
905 if (sin6) {
906 sin6->sin6_family = AF_INET6;
907 sin6->sin6_port = 0;
908 sin6->sin6_addr = ip6->saddr;
909 sin6->sin6_flowinfo = 0;
910 if (np->sndflow)
911 sin6->sin6_flowinfo = ip6_flowinfo(ip6);
912 sin6->sin6_scope_id =
913 ipv6_iface_scope_id(&sin6->sin6_addr,
914 IP6CB(skb)->iif);
915 }
a2214488 916
6fa3eb70
S
917 if (inet6_sk(sk)->rxopt.all)
918 pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
919#endif
920 } else {
921 BUG();
c319b4d7 922 }
6fa3eb70 923
c319b4d7
VK
924 err = copied;
925
926done:
927 skb_free_datagram(sk, skb);
928out:
929 pr_debug("ping_recvmsg -> %d\n", err);
930 return err;
931}
6fa3eb70 932EXPORT_SYMBOL_GPL(ping_recvmsg);
c319b4d7 933
6fa3eb70 934int ping_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
c319b4d7
VK
935{
936 pr_debug("ping_queue_rcv_skb(sk=%p,sk->num=%d,skb=%p)\n",
058bd4d2 937 inet_sk(sk), inet_sk(sk)->inet_num, skb);
c319b4d7 938 if (sock_queue_rcv_skb(sk, skb) < 0) {
c319b4d7
VK
939 kfree_skb(skb);
940 pr_debug("ping_queue_rcv_skb -> failed\n");
941 return -1;
942 }
943 return 0;
944}
6fa3eb70 945EXPORT_SYMBOL_GPL(ping_queue_rcv_skb);
c319b4d7
VK
946
947
948/*
949 * All we need to do is get the socket.
950 */
951
952void ping_rcv(struct sk_buff *skb)
953{
954 struct sock *sk;
955 struct net *net = dev_net(skb->dev);
c319b4d7 956 struct icmphdr *icmph = icmp_hdr(skb);
c319b4d7
VK
957
958 /* We assume the packet has already been checked by icmp_rcv */
959
960 pr_debug("ping_rcv(skb=%p,id=%04x,seq=%04x)\n",
058bd4d2 961 skb, ntohs(icmph->un.echo.id), ntohs(icmph->un.echo.sequence));
c319b4d7
VK
962
963 /* Push ICMP header back */
964 skb_push(skb, skb->data - (u8 *)icmph);
965
6fa3eb70 966 sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id));
c319b4d7 967 if (sk != NULL) {
6fa3eb70
S
968#ifdef CONFIG_MTK_NET_LOGGING
969 printk(KERN_INFO "[mtk_net][ping_debug]rcv on sk %p\n", sk);
970#endif
c319b4d7 971 ping_queue_rcv_skb(sk, skb_get(skb));
6fa3eb70
S
972 /*mtk_net: don't put sock here, do sock_put after free skb*/
973 /* sock_put(sk); */
c319b4d7
VK
974 return;
975 }
6fa3eb70 976 pr_info("[mtk_net][ping_debug]no socket, dropping\n");
c319b4d7
VK
977
978 /* We're called from icmp_rcv(). kfree_skb() is done there. */
979}
6fa3eb70 980EXPORT_SYMBOL_GPL(ping_rcv);
c319b4d7
VK
981
982struct proto ping_prot = {
983 .name = "PING",
984 .owner = THIS_MODULE,
985 .init = ping_init_sock,
986 .close = ping_close,
987 .connect = ip4_datagram_connect,
988 .disconnect = udp_disconnect,
c319b4d7
VK
989 .setsockopt = ip_setsockopt,
990 .getsockopt = ip_getsockopt,
6fa3eb70 991 .sendmsg = ping_v4_sendmsg,
c319b4d7
VK
992 .recvmsg = ping_recvmsg,
993 .bind = ping_bind,
994 .backlog_rcv = ping_queue_rcv_skb,
8141ed9f 995 .release_cb = ip4_datagram_release_cb,
6fa3eb70
S
996 .hash = ping_hash,
997 .unhash = ping_unhash,
998 .get_port = ping_get_port,
c319b4d7
VK
999 .obj_size = sizeof(struct inet_sock),
1000};
1001EXPORT_SYMBOL(ping_prot);
1002
1003#ifdef CONFIG_PROC_FS
1004
1005static struct sock *ping_get_first(struct seq_file *seq, int start)
1006{
1007 struct sock *sk;
1008 struct ping_iter_state *state = seq->private;
1009 struct net *net = seq_file_net(seq);
1010
1011 for (state->bucket = start; state->bucket < PING_HTABLE_SIZE;
1012 ++state->bucket) {
1013 struct hlist_nulls_node *node;
75e308c8
CG
1014 struct hlist_nulls_head *hslot;
1015
1016 hslot = &ping_table.hash[state->bucket];
c319b4d7
VK
1017
1018 if (hlist_nulls_empty(hslot))
1019 continue;
1020
1021 sk_nulls_for_each(sk, node, hslot) {
6fa3eb70
S
1022 if (net_eq(sock_net(sk), net) &&
1023 sk->sk_family == state->family)
c319b4d7
VK
1024 goto found;
1025 }
1026 }
1027 sk = NULL;
1028found:
1029 return sk;
1030}
1031
1032static struct sock *ping_get_next(struct seq_file *seq, struct sock *sk)
1033{
1034 struct ping_iter_state *state = seq->private;
1035 struct net *net = seq_file_net(seq);
1036
1037 do {
1038 sk = sk_nulls_next(sk);
1039 } while (sk && (!net_eq(sock_net(sk), net)));
1040
1041 if (!sk)
1042 return ping_get_first(seq, state->bucket + 1);
1043 return sk;
1044}
1045
1046static struct sock *ping_get_idx(struct seq_file *seq, loff_t pos)
1047{
1048 struct sock *sk = ping_get_first(seq, 0);
1049
1050 if (sk)
1051 while (pos && (sk = ping_get_next(seq, sk)) != NULL)
1052 --pos;
1053 return pos ? NULL : sk;
1054}
1055
6fa3eb70 1056void *ping_seq_start(struct seq_file *seq, loff_t *pos, sa_family_t family)
c319b4d7
VK
1057{
1058 struct ping_iter_state *state = seq->private;
1059 state->bucket = 0;
6fa3eb70 1060 state->family = family;
c319b4d7
VK
1061
1062 read_lock_bh(&ping_table.lock);
1063
1064 return *pos ? ping_get_idx(seq, *pos-1) : SEQ_START_TOKEN;
1065}
6fa3eb70
S
1066EXPORT_SYMBOL_GPL(ping_seq_start);
1067
1068static void *ping_v4_seq_start(struct seq_file *seq, loff_t *pos)
1069{
1070 return ping_seq_start(seq, pos, AF_INET);
1071}
c319b4d7 1072
6fa3eb70 1073void *ping_seq_next(struct seq_file *seq, void *v, loff_t *pos)
c319b4d7
VK
1074{
1075 struct sock *sk;
1076
1077 if (v == SEQ_START_TOKEN)
1078 sk = ping_get_idx(seq, 0);
1079 else
1080 sk = ping_get_next(seq, v);
1081
1082 ++*pos;
1083 return sk;
1084}
6fa3eb70 1085EXPORT_SYMBOL_GPL(ping_seq_next);
c319b4d7 1086
6fa3eb70 1087void ping_seq_stop(struct seq_file *seq, void *v)
c319b4d7
VK
1088{
1089 read_unlock_bh(&ping_table.lock);
1090}
6fa3eb70 1091EXPORT_SYMBOL_GPL(ping_seq_stop);
c319b4d7 1092
6fa3eb70 1093static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
c319b4d7
VK
1094 int bucket, int *len)
1095{
1096 struct inet_sock *inet = inet_sk(sp);
1097 __be32 dest = inet->inet_daddr;
1098 __be32 src = inet->inet_rcv_saddr;
1099 __u16 destp = ntohs(inet->inet_dport);
1100 __u16 srcp = ntohs(inet->inet_sport);
1101
1102 seq_printf(f, "%5d: %08X:%04X %08X:%04X"
1103 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %pK %d%n",
1104 bucket, src, srcp, dest, destp, sp->sk_state,
1105 sk_wmem_alloc_get(sp),
1106 sk_rmem_alloc_get(sp),
a7cb5a49
EB
1107 0, 0L, 0,
1108 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
1109 0, sock_i_ino(sp),
c319b4d7
VK
1110 atomic_read(&sp->sk_refcnt), sp,
1111 atomic_read(&sp->sk_drops), len);
1112}
1113
6fa3eb70 1114static int ping_v4_seq_show(struct seq_file *seq, void *v)
c319b4d7
VK
1115{
1116 if (v == SEQ_START_TOKEN)
1117 seq_printf(seq, "%-127s\n",
1118 " sl local_address rem_address st tx_queue "
1119 "rx_queue tr tm->when retrnsmt uid timeout "
1120 "inode ref pointer drops");
1121 else {
1122 struct ping_iter_state *state = seq->private;
1123 int len;
1124
6fa3eb70 1125 ping_v4_format_sock(v, seq, state->bucket, &len);
c319b4d7
VK
1126 seq_printf(seq, "%*s\n", 127 - len, "");
1127 }
1128 return 0;
1129}
1130
6fa3eb70
S
1131static const struct seq_operations ping_v4_seq_ops = {
1132 .show = ping_v4_seq_show,
1133 .start = ping_v4_seq_start,
c319b4d7
VK
1134 .next = ping_seq_next,
1135 .stop = ping_seq_stop,
1136};
1137
1138static int ping_seq_open(struct inode *inode, struct file *file)
1139{
6fa3eb70
S
1140 struct ping_seq_afinfo *afinfo = PDE_DATA(inode);
1141 return seq_open_net(inode, file, &afinfo->seq_ops,
c319b4d7
VK
1142 sizeof(struct ping_iter_state));
1143}
1144
6fa3eb70 1145const struct file_operations ping_seq_fops = {
c319b4d7
VK
1146 .open = ping_seq_open,
1147 .read = seq_read,
1148 .llseek = seq_lseek,
1149 .release = seq_release_net,
1150};
6fa3eb70
S
1151EXPORT_SYMBOL_GPL(ping_seq_fops);
1152
1153static struct ping_seq_afinfo ping_v4_seq_afinfo = {
1154 .name = "icmp",
1155 .family = AF_INET,
1156 .seq_fops = &ping_seq_fops,
1157 .seq_ops = {
1158 .start = ping_v4_seq_start,
1159 .show = ping_v4_seq_show,
1160 .next = ping_seq_next,
1161 .stop = ping_seq_stop,
1162 },
1163};
c319b4d7 1164
6fa3eb70 1165int ping_proc_register(struct net *net, struct ping_seq_afinfo *afinfo)
c319b4d7
VK
1166{
1167 struct proc_dir_entry *p;
6fa3eb70
S
1168 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
1169 afinfo->seq_fops, afinfo);
c319b4d7 1170 if (!p)
6fa3eb70
S
1171 return -ENOMEM;
1172 return 0;
c319b4d7 1173}
6fa3eb70 1174EXPORT_SYMBOL_GPL(ping_proc_register);
c319b4d7 1175
6fa3eb70 1176void ping_proc_unregister(struct net *net, struct ping_seq_afinfo *afinfo)
c319b4d7 1177{
6fa3eb70 1178 remove_proc_entry(afinfo->name, net->proc_net);
c319b4d7 1179}
6fa3eb70 1180EXPORT_SYMBOL_GPL(ping_proc_unregister);
c319b4d7 1181
6fa3eb70 1182static int __net_init ping_v4_proc_init_net(struct net *net)
c319b4d7 1183{
6fa3eb70 1184 return ping_proc_register(net, &ping_v4_seq_afinfo);
c319b4d7
VK
1185}
1186
6fa3eb70 1187static void __net_exit ping_v4_proc_exit_net(struct net *net)
c319b4d7 1188{
6fa3eb70 1189 ping_proc_unregister(net, &ping_v4_seq_afinfo);
c319b4d7
VK
1190}
1191
6fa3eb70
S
1192static struct pernet_operations ping_v4_net_ops = {
1193 .init = ping_v4_proc_init_net,
1194 .exit = ping_v4_proc_exit_net,
c319b4d7
VK
1195};
1196
1197int __init ping_proc_init(void)
1198{
6fa3eb70 1199 return register_pernet_subsys(&ping_v4_net_ops);
c319b4d7
VK
1200}
1201
1202void ping_proc_exit(void)
1203{
6fa3eb70 1204 unregister_pernet_subsys(&ping_v4_net_ops);
c319b4d7
VK
1205}
1206
1207#endif
1208
1209void __init ping_init(void)
1210{
1211 int i;
1212
1213 for (i = 0; i < PING_HTABLE_SIZE; i++)
1214 INIT_HLIST_NULLS_HEAD(&ping_table.hash[i], i);
1215 rwlock_init(&ping_table.lock);
1216}