Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 247445
b: refs/heads/master
c: c319b4d
h: refs/heads/master
i:
  247443: 2cfa8ec
v: v3
  • Loading branch information
Vasiliy Kulikov authored and David S. Miller committed May 13, 2011
1 parent ddefb5a commit cf78cd5
Show file tree
Hide file tree
Showing 8 changed files with 1,111 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f20190302e3e697a166cc28ebef43058749dedda
refs/heads/master: c319b4d76b9e583a5d88d6bf190e079c4e43213d
2 changes: 2 additions & 0 deletions trunk/include/net/netns/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct netns_ipv4 {
int sysctl_rt_cache_rebuild_count;
int current_rt_cache_rebuild_count;

unsigned int sysctl_ping_group_range[2];

atomic_t rt_genid;
atomic_t dev_addr_genid;

Expand Down
57 changes: 57 additions & 0 deletions trunk/include/net/ping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* INET An implementation of the TCP/IP protocol suite for the LINUX
* operating system. INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* Definitions for the "ping" module.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _PING_H
#define _PING_H

#include <net/netns/hash.h>

/* PING_HTABLE_SIZE must be power of 2 */
#define PING_HTABLE_SIZE 64
#define PING_HTABLE_MASK (PING_HTABLE_SIZE-1)

#define ping_portaddr_for_each_entry(__sk, node, list) \
hlist_nulls_for_each_entry(__sk, node, list, sk_nulls_node)

/*
* gid_t is either uint or ushort. We want to pass it to
* proc_dointvec_minmax(), so it must not be larger than MAX_INT
*/
#define GID_T_MAX (((gid_t)~0U) >> 1)

struct ping_table {
struct hlist_nulls_head hash[PING_HTABLE_SIZE];
rwlock_t lock;
};

struct ping_iter_state {
struct seq_net_private p;
int bucket;
};

extern struct proto ping_prot;


extern void ping_rcv(struct sk_buff *);
extern void ping_err(struct sk_buff *, u32 info);

extern void inet_get_ping_group_range_net(struct net *net, unsigned int *low, unsigned int *high);

#ifdef CONFIG_PROC_FS
extern int __init ping_proc_init(void);
extern void ping_proc_exit(void);
#endif

void __init ping_init(void);


#endif /* _PING_H */
2 changes: 1 addition & 1 deletion trunk/net/ipv4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ obj-y := route.o inetpeer.o protocol.o \
datagram.o raw.o udp.o udplite.o \
arp.o icmp.o devinet.o af_inet.o igmp.o \
fib_frontend.o fib_semantics.o fib_trie.o \
inet_fragment.o
inet_fragment.o ping.o

obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
obj-$(CONFIG_PROC_FS) += proc.o
Expand Down
22 changes: 22 additions & 0 deletions trunk/net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
#include <net/tcp.h>
#include <net/udp.h>
#include <net/udplite.h>
#include <net/ping.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <net/raw.h>
Expand Down Expand Up @@ -1008,6 +1009,14 @@ static struct inet_protosw inetsw_array[] =
.flags = INET_PROTOSW_PERMANENT,
},

{
.type = SOCK_DGRAM,
.protocol = IPPROTO_ICMP,
.prot = &ping_prot,
.ops = &inet_dgram_ops,
.no_check = UDP_CSUM_DEFAULT,
.flags = INET_PROTOSW_REUSE,
},

{
.type = SOCK_RAW,
Expand Down Expand Up @@ -1527,6 +1536,7 @@ static const struct net_protocol udp_protocol = {

static const struct net_protocol icmp_protocol = {
.handler = icmp_rcv,
.err_handler = ping_err,
.no_policy = 1,
.netns_ok = 1,
};
Expand Down Expand Up @@ -1642,6 +1652,10 @@ static int __init inet_init(void)
if (rc)
goto out_unregister_udp_proto;

rc = proto_register(&ping_prot, 1);
if (rc)
goto out_unregister_raw_proto;

/*
* Tell SOCKET that we are alive...
*/
Expand Down Expand Up @@ -1697,6 +1711,8 @@ static int __init inet_init(void)
/* Add UDP-Lite (RFC 3828) */
udplite4_register();

ping_init();

/*
* Set the ICMP layer up
*/
Expand Down Expand Up @@ -1727,6 +1743,8 @@ static int __init inet_init(void)
rc = 0;
out:
return rc;
out_unregister_raw_proto:
proto_unregister(&raw_prot);
out_unregister_udp_proto:
proto_unregister(&udp_prot);
out_unregister_tcp_proto:
Expand All @@ -1751,11 +1769,15 @@ static int __init ipv4_proc_init(void)
goto out_tcp;
if (udp4_proc_init())
goto out_udp;
if (ping_proc_init())
goto out_ping;
if (ip_misc_proc_init())
goto out_misc;
out:
return rc;
out_misc:
ping_proc_exit();
out_ping:
udp4_proc_exit();
out_udp:
tcp4_proc_exit();
Expand Down
12 changes: 11 additions & 1 deletion trunk/net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#include <net/tcp.h>
#include <net/udp.h>
#include <net/raw.h>
#include <net/ping.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <linux/errno.h>
Expand Down Expand Up @@ -781,6 +782,15 @@ static void icmp_redirect(struct sk_buff *skb)
iph->saddr, skb->dev);
break;
}

/* Ping wants to see redirects.
* Let's pretend they are errors of sorts... */
if (iph->protocol == IPPROTO_ICMP &&
iph->ihl >= 5 &&
pskb_may_pull(skb, (iph->ihl<<2)+8)) {
ping_err(skb, icmp_hdr(skb)->un.gateway);
}

out:
return;
out_err:
Expand Down Expand Up @@ -1041,7 +1051,7 @@ int icmp_rcv(struct sk_buff *skb)
*/
static const struct icmp_control icmp_pointers[NR_ICMP_TYPES + 1] = {
[ICMP_ECHOREPLY] = {
.handler = icmp_discard,
.handler = ping_rcv,
},
[1] = {
.handler = icmp_discard,
Expand Down
Loading

0 comments on commit cf78cd5

Please sign in to comment.