linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, tom.zanussi@linux.intel.com,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 07/24] net, diet: Make ping sockets optional
Date: Mon,  5 May 2014 15:25:56 -0700	[thread overview]
Message-ID: <1399328773-6531-8-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1399328773-6531-1-git-send-email-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

This saves about 6k text/data. ping still works fine using raw
sockets like it always did.

   text	   data	    bss	    dec	    hex	filename
 268128	  11555	   7872	 287555	  46343	net/ipv4/built-in.o-noping
 273610	  11843	   8176	 293629	  47afd	net/ipv4/built-in.o-ping

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 include/net/ping.h      | 15 +++++++++++----
 include/net/transp_v6.h |  2 --
 net/ipv4/Kconfig        |  5 +++++
 net/ipv4/Makefile       |  3 ++-
 net/ipv4/af_inet.c      |  9 ++++-----
 net/ipv4/icmp.c         |  1 +
 net/ipv4/ping.c         |  3 +++
 net/ipv6/Makefile       |  3 ++-
 net/ipv6/af_inet6.c     |  8 ++++++--
 9 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/include/net/ping.h b/include/net/ping.h
index 026479b..ca6b89d 100644
--- a/include/net/ping.h
+++ b/include/net/ping.h
@@ -71,7 +71,6 @@ void ping_unhash(struct sock *sk);
 int  ping_init_sock(struct sock *sk);
 void ping_close(struct sock *sk, long timeout);
 int  ping_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len);
-void ping_err(struct sk_buff *skb, int offset, u32 info);
 int  ping_getfrag(void *from, char *to, int offset, int fraglen, int odd,
 		  struct sk_buff *);
 
@@ -82,7 +81,6 @@ int  ping_common_sendmsg(int family, struct msghdr *msg, size_t len,
 int  ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 		     size_t len);
 int  ping_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
-void ping_rcv(struct sk_buff *skb);
 
 #ifdef CONFIG_PROC_FS
 struct ping_seq_afinfo {
@@ -100,12 +98,21 @@ void ping_seq_stop(struct seq_file *seq, void *v);
 int ping_proc_register(struct net *net, struct ping_seq_afinfo *afinfo);
 void ping_proc_unregister(struct net *net, struct ping_seq_afinfo *afinfo);
 
-int __init ping_proc_init(void);
-void ping_proc_exit(void);
 #endif
 
+#ifdef CONFIG_IP_PING
+void ping_rcv(struct sk_buff *skb);
+void ping_err(struct sk_buff *skb, int offset, u32 info);
 void __init ping_init(void);
 int  __init pingv6_init(void);
 void pingv6_exit(void);
+#else
+static inline void ping_init(void) {}
+static inline int pingv6_init(void) { return 0; }
+static inline void pingv6_exit(void) { }
+static inline void ping_err(struct sk_buff *skb, int offset, u32 info) {}
+static inline void ping_rcv(struct sk_buff *skb) {}
+#endif
+
 
 #endif /* _PING_H */
diff --git a/include/net/transp_v6.h b/include/net/transp_v6.h
index b927413..7a0e229 100644
--- a/include/net/transp_v6.h
+++ b/include/net/transp_v6.h
@@ -19,8 +19,6 @@ int ipv6_frag_init(void);
 void ipv6_frag_exit(void);
 
 /* transport protocols */
-int pingv6_init(void);
-void pingv6_exit(void);
 int rawv6_init(void);
 void rawv6_exit(void);
 int udpv6_init(void);
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig
index 05c57f0..6146b1b 100644
--- a/net/ipv4/Kconfig
+++ b/net/ipv4/Kconfig
@@ -52,6 +52,11 @@ config IP_ADVANCED_ROUTER
 
 	  If unsure, say N here.
 
+config IP_PING
+	bool "IP: ping sockets"
+	---help---
+	  Enable ping sockets to enable suid-less ping.
+
 config IP_FIB_TRIE_STATS
 	bool "FIB TRIE statistics"
 	depends on IP_ADVANCED_ROUTER
diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile
index f032688..756855c 100644
--- a/net/ipv4/Makefile
+++ b/net/ipv4/Makefile
@@ -11,9 +11,10 @@ obj-y     := route.o inetpeer.o protocol.o \
 	     tcp_offload.o datagram.o raw.o udp.o udplite.o \
 	     udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \
 	     fib_frontend.o fib_semantics.o fib_trie.o \
-	     inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o
+	     inet_fragment.o ip_tunnel_core.o gre_offload.o
 
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
+obj-$(CONFIG_IP_PING) += ping.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
 obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_IP_MULTIPLE_TABLES) += fib_rules.o
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 8c54870..c275ce5 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1015,7 +1015,7 @@ static struct inet_protosw inetsw_array[] =
 		.no_check =   UDP_CSUM_DEFAULT,
 		.flags =      INET_PROTOSW_PERMANENT,
        },
-
+#ifdef CONFIG_IP_PING
        {
 		.type =       SOCK_DGRAM,
 		.protocol =   IPPROTO_ICMP,
@@ -1024,6 +1024,7 @@ static struct inet_protosw inetsw_array[] =
 		.no_check =   UDP_CSUM_DEFAULT,
 		.flags =      INET_PROTOSW_REUSE,
        },
+#endif
 
        {
 	       .type =       SOCK_RAW,
@@ -1719,7 +1720,9 @@ static int __init inet_init(void)
 	if (rc)
 		goto out_unregister_udp_proto;
 
+#ifdef CONFIG_IP_PING
 	rc = proto_register(&ping_prot, 1);
+#endif
 	if (rc)
 		goto out_unregister_raw_proto;
 
@@ -1836,15 +1839,11 @@ 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();
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 0134663..df3872b 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -989,6 +989,7 @@ void icmp_err(struct sk_buff *skb, u32 info)
 		return;
 	}
 
+	/* RED-PEN dead code? the if above will eat all. */
 	if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
 		ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ICMP, 0);
 	else if (type == ICMP_REDIRECT)
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 8210964..3f79243 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -1206,6 +1206,9 @@ void ping_proc_exit(void)
 	unregister_pernet_subsys(&ping_v4_net_ops);
 }
 
+module_init(ping_proc_init);
+module_exit(ping_proc_init);
+
 #endif
 
 void __init ping_init(void)
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile
index 2fe6836..6ff7cfd 100644
--- a/net/ipv6/Makefile
+++ b/net/ipv6/Makefile
@@ -7,13 +7,14 @@ obj-$(CONFIG_IPV6) += ipv6.o
 ipv6-objs :=	af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \
 		addrlabel.o \
 		route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o udplite.o \
-		raw.o icmp.o mcast.o reassembly.o tcp_ipv6.o ping.o \
+		raw.o icmp.o mcast.o reassembly.o tcp_ipv6.o \
 		exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o
 
 ipv6-offload :=	ip6_offload.o tcpv6_offload.o udp_offload.o exthdrs_offload.o
 
 ipv6-$(CONFIG_SYSCTL) = sysctl_net_ipv6.o
 ipv6-$(CONFIG_IPV6_MROUTE) += ip6mr.o
+ipv6-$(CONFIG_IP_PING) += ping.o
 
 ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \
 	xfrm6_output.o xfrm6_protocol.o
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index d935889..68ac214 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -861,16 +861,18 @@ static int __init inet6_init(void)
 	if (err)
 		goto out_unregister_udplite_proto;
 
+#ifdef CONFIG_IP_PING
 	err = proto_register(&pingv6_prot, 1);
 	if (err)
-		goto out_unregister_ping_proto;
+		goto out_unregister_raw_proto;
+#endif
 
 	/* We MUST register RAW sockets before we create the ICMP6,
 	 * IGMP6, or NDISC control sockets.
 	 */
 	err = rawv6_init();
 	if (err)
-		goto out_unregister_raw_proto;
+		goto out_unregister_ping_proto;
 
 	/* Register the family here so that the init calls below will
 	 * be able to create sockets. (?? is this dangerous ??)
@@ -1022,8 +1024,10 @@ register_pernet_fail:
 out_sock_register_fail:
 	rawv6_exit();
 out_unregister_ping_proto:
+#ifdef CONFIG_IP_PING
 	proto_unregister(&pingv6_prot);
 out_unregister_raw_proto:
+#endif
 	proto_unregister(&rawv6_prot);
 out_unregister_udplite_proto:
 	proto_unregister(&udplitev6_prot);
-- 
1.9.0


  parent reply	other threads:[~2014-05-05 22:28 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-05 22:25 RFC: A reduced Linux network stack for small systems Andi Kleen
2014-05-05 22:25 ` [PATCH 01/24] net, diet: Reduce netdev name hash table for CONFIG_BASE_SMALL Andi Kleen
2014-05-06  3:03   ` David Miller
2014-05-05 22:25 ` [PATCH 02/24] net, diet: Reduce NAPI " Andi Kleen
2014-05-05 22:25 ` [PATCH 03/24] net, diet: Decrease ip defrag hash tables and max length with BASE_SMALL Andi Kleen
2014-05-05 22:25 ` [PATCH 04/24] net, diet: Make FIB hash tables smaller with CONFIG_BASE_SMALL Andi Kleen
2014-05-06  3:10   ` David Miller
2014-05-05 22:25 ` [PATCH 05/24] net, diet: Default to small TCP hash tables on small kernels Andi Kleen
2014-05-06  3:12   ` David Miller
2014-05-05 22:25 ` [PATCH 06/24] net, diet: Use small UDP " Andi Kleen
2014-05-06  3:11   ` David Miller
2014-05-06 14:26   ` Eric Dumazet
2014-05-06 18:23     ` Andi Kleen
2014-05-06 19:25       ` Eric Dumazet
2014-05-05 22:25 ` Andi Kleen [this message]
2014-05-06  3:04   ` [PATCH 07/24] net, diet: Make ping sockets optional David Miller
2014-05-05 22:25 ` [PATCH 08/24] net, diet: Make TCP metrics optional Andi Kleen
2014-05-05 23:18   ` Yuchung Cheng
2014-05-05 23:28     ` Andi Kleen
2014-05-06  3:12   ` David Miller
2014-05-06  3:21     ` Andi Kleen
2014-05-06  3:23       ` David Miller
2014-05-06  4:39         ` Tom Zanussi
2014-05-07 13:59           ` One Thousand Gnomes
2014-05-07 17:20             ` David Miller
2014-05-07 22:19               ` Tim Bird
2014-05-07 22:52                 ` David Miller
2014-05-06 15:57         ` josh
2014-05-06 15:59           ` David Miller
2014-05-06 16:41             ` josh
2014-05-06 17:12               ` Rick Jones
2014-05-06 18:09                 ` josh
2014-05-06 17:16               ` David Miller
2014-05-06 17:55                 ` josh
2014-05-06 18:33                   ` Cong Wang
2014-05-06 18:48                     ` Andi Kleen
2014-05-06 19:19                     ` Richard Cochran
2014-05-06 20:44                     ` David Miller
2014-05-06 21:08                       ` josh
2014-05-06 21:11                         ` David Miller
2014-05-06 22:50                           ` josh
2014-05-06 23:27                             ` Eric Dumazet
2014-06-14 20:33                     ` Pavel Machek
2014-06-23 10:17                     ` zhuyj
2014-05-06 19:14               ` Richard Cochran
2014-05-06 19:50                 ` Andi Kleen
2014-05-06 20:07                   ` Richard Cochran
2014-05-06 21:05                     ` Andi Kleen
2014-05-06 23:29                       ` Eric Dumazet
2014-05-07  4:33                         ` Andi Kleen
2014-05-06 20:46                   ` David Miller
2014-05-07  8:39               ` David Laight
2014-05-09  9:48             ` Pavel Machek
2014-05-06 16:39           ` Eric Dumazet
2014-05-06 16:45             ` josh
2014-05-06 17:03               ` Eric Dumazet
2014-05-06 17:30                 ` josh
2014-05-06 17:17               ` David Miller
2014-05-06 17:21                 ` josh
2014-05-06 17:25                   ` David Miller
2014-05-06 20:06                     ` Andi Kleen
2014-05-06 20:47                       ` David Miller
2014-05-06 20:11                     ` josh
2014-05-06 20:44                       ` Andi Kleen
2014-05-06 17:14             ` David Miller
2014-05-06 18:32             ` Andi Kleen
2014-05-06 18:58               ` Tom Herbert
2014-05-06 19:37                 ` josh
2014-05-06 19:57                 ` Andi Kleen
2014-05-06 20:17               ` Eric Dumazet
2014-05-06 20:27                 ` josh
2014-05-06 20:37                 ` Andi Kleen
2014-05-06 20:48                 ` David Miller
2014-05-07 13:35                 ` One Thousand Gnomes
2014-05-13 16:22                   ` Christer Weinigel
2014-05-09  7:38     ` Pavel Machek
2014-05-05 22:25 ` [PATCH 09/24] net, diet: Make ethtool optional Andi Kleen
2014-05-06  3:11   ` David Miller
2014-05-06  3:14     ` Andi Kleen
2014-05-06  3:22       ` David Miller
2014-05-05 22:25 ` [PATCH 10/24] net, diet: Make LPF filter optional Andi Kleen
2014-05-06  3:10   ` David Miller
2014-05-05 22:26 ` [PATCH 11/24] net, diet: Move rtnl_lock to separate file Andi Kleen
2014-05-05 22:26 ` [PATCH 12/24] net, diet: Make rtnetlink optional Andi Kleen
2014-05-06  3:08   ` David Miller
2014-05-06  3:11     ` Andi Kleen
2014-05-05 22:26 ` [PATCH 13/24] net, diet: Make GRO offload optional Andi Kleen
2014-05-06  3:01   ` David Miller
2014-05-06  3:03     ` Andi Kleen
2014-05-05 22:26 ` [PATCH 14/24] net, diet: Make MIB statistics collections depend on PROC_FS Andi Kleen
2014-05-06  3:05   ` David Miller
2014-05-05 22:26 ` [PATCH 15/24] net, diet: Make igmp and mcast ioctls depend on IP_MULTICAST Andi Kleen
2014-05-05 22:26 ` [PATCH 16/24] net, diet: Make TCP fastopen optional Andi Kleen
2014-05-06  3:06   ` David Miller
2014-05-05 22:26 ` [PATCH 17/24] net, diet: Make internal control sockets use UDP Andi Kleen
2014-05-05 22:26 ` [PATCH 18/24] net, diet: Make raw sockets optional Andi Kleen
2014-05-06  3:12   ` David Miller
2014-05-05 22:26 ` [PATCH 19/24] net, diet: Make RPS configurable Andi Kleen
2014-05-06  3:14   ` David Miller
2014-05-06  3:16     ` Andi Kleen
2014-05-06  8:32   ` Bjørn Mork
2014-05-05 22:26 ` [PATCH 20/24] net, diet: Make XPS configurable Andi Kleen
2014-05-05 22:26 ` [PATCH 21/24] net, diet: Make packet tpacket/mmap/fanout/rings optional Andi Kleen
2014-05-06  3:09   ` David Miller
2014-05-05 22:26 ` [PATCH 22/24] net, diet: Support simpler routing table Andi Kleen
2014-05-06  3:02   ` David Miller
2014-05-06  3:08     ` Andi Kleen
2014-05-06  3:21       ` David Miller
2014-05-05 22:26 ` [PATCH 23/24] net, diet: Add coccinelle script to convert drivers to ETHTOOL_OPS Andi Kleen
2014-05-06  9:27   ` Nicolas Palix
2014-05-06 15:05     ` David Miller
2014-05-07  0:18       ` Wilfried Klaebe
2014-05-05 22:26 ` [PATCH 24/24] net, diet: Convert all drivers to use SET_ETHTOOL_OPS Andi Kleen
2014-05-06  7:25 ` RFC: A reduced Linux network stack for small systems Richard Weinberger
2014-05-06 13:34   ` Tom Zanussi
2014-05-06 15:20     ` Alexei Starovoitov
2014-05-06 15:34       ` Tom Zanussi
2014-05-06 17:20         ` Alexei Starovoitov
2014-05-06 20:00           ` Andi Kleen
2014-05-06 21:05             ` Alexei Starovoitov
2014-05-09  7:39           ` Pavel Machek
2014-05-09  7:38       ` Pavel Machek
2014-05-06  9:18 ` David Laight
2014-05-07 13:20   ` One Thousand Gnomes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399328773-6531-8-git-send-email-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tom.zanussi@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).