fc2a0a48622d627ad29083b6183c0ab0cfbd36e2
[openwrt/openwrt.git] / target / linux / generic / hack-5.10 / 901-debloat_sock_diag.patch
1 From 3b6115d6b57a263bdc8c9b1df273bd4a7955eead Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Sat, 8 Jul 2017 08:16:31 +0200
4 Subject: debloat: add some debloat patches, strip down procfs and make O_DIRECT support optional, saves ~15K after lzma on MIPS
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8 net/Kconfig | 3 +++
9 net/core/Makefile | 3 ++-
10 net/core/sock.c | 2 ++
11 net/ipv4/Kconfig | 1 +
12 net/netlink/Kconfig | 1 +
13 net/packet/Kconfig | 1 +
14 net/unix/Kconfig | 1 +
15 7 files changed, 11 insertions(+), 1 deletion(-)
16
17 --- a/net/Kconfig
18 +++ b/net/Kconfig
19 @@ -98,6 +98,9 @@ source "net/mptcp/Kconfig"
20
21 endif # if INET
22
23 +config SOCK_DIAG
24 + bool
25 +
26 config NETWORK_SECMARK
27 bool "Security Marking"
28 help
29 --- a/net/core/Makefile
30 +++ b/net/core/Makefile
31 @@ -10,9 +10,10 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.
32
33 obj-y += dev.o dev_addr_lists.o dst.o netevent.o \
34 neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
35 - sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
36 + dev_ioctl.o tso.o sock_reuseport.o \
37 fib_notifier.o xdp.o flow_offload.o
38
39 +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o
40 obj-y += net-sysfs.o
41 obj-$(CONFIG_PAGE_POOL) += page_pool.o
42 obj-$(CONFIG_PROC_FS) += net-procfs.o
43 --- a/net/core/sock.c
44 +++ b/net/core/sock.c
45 @@ -114,6 +114,7 @@
46 #include <linux/memcontrol.h>
47 #include <linux/prefetch.h>
48 #include <linux/compat.h>
49 +#include <linux/cookie.h>
50
51 #include <linux/uaccess.h>
52
53 @@ -141,6 +142,7 @@
54
55 static DEFINE_MUTEX(proto_list_mutex);
56 static LIST_HEAD(proto_list);
57 +DEFINE_COOKIE(sock_cookie);
58
59 static void sock_inuse_add(struct net *net, int val);
60
61 @@ -526,6 +528,18 @@ discard_and_relse:
62 }
63 EXPORT_SYMBOL(__sk_receive_skb);
64
65 +u64 __sock_gen_cookie(struct sock *sk)
66 +{
67 + while (1) {
68 + u64 res = atomic64_read(&sk->sk_cookie);
69 +
70 + if (res)
71 + return res;
72 + res = gen_cookie_next(&sock_cookie);
73 + atomic64_cmpxchg(&sk->sk_cookie, 0, res);
74 + }
75 +}
76 +
77 struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie)
78 {
79 struct dst_entry *dst = __sk_dst_get(sk);
80 @@ -1808,9 +1822,11 @@ static void __sk_free(struct sock *sk)
81 if (likely(sk->sk_net_refcnt))
82 sock_inuse_add(sock_net(sk), -1);
83
84 +#ifdef CONFIG_SOCK_DIAG
85 if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
86 sock_diag_broadcast_destroy(sk);
87 else
88 +#endif
89 sk_destruct(sk);
90 }
91
92 --- a/net/core/sock_diag.c
93 +++ b/net/core/sock_diag.c
94 @@ -11,7 +11,6 @@
95 #include <linux/tcp.h>
96 #include <linux/workqueue.h>
97 #include <linux/nospec.h>
98 -#include <linux/cookie.h>
99 #include <linux/inet_diag.h>
100 #include <linux/sock_diag.h>
101
102 @@ -20,20 +19,6 @@ static int (*inet_rcv_compat)(struct sk_
103 static DEFINE_MUTEX(sock_diag_table_mutex);
104 static struct workqueue_struct *broadcast_wq;
105
106 -DEFINE_COOKIE(sock_cookie);
107 -
108 -u64 __sock_gen_cookie(struct sock *sk)
109 -{
110 - while (1) {
111 - u64 res = atomic64_read(&sk->sk_cookie);
112 -
113 - if (res)
114 - return res;
115 - res = gen_cookie_next(&sock_cookie);
116 - atomic64_cmpxchg(&sk->sk_cookie, 0, res);
117 - }
118 -}
119 -
120 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
121 {
122 u64 res;
123 --- a/net/ipv4/Kconfig
124 +++ b/net/ipv4/Kconfig
125 @@ -414,6 +414,7 @@ config INET_TUNNEL
126
127 config INET_DIAG
128 tristate "INET: socket monitoring interface"
129 + select SOCK_DIAG
130 default y
131 help
132 Support for INET (TCP, DCCP, etc) socket monitoring interface used by
133 --- a/net/netlink/Kconfig
134 +++ b/net/netlink/Kconfig
135 @@ -5,6 +5,7 @@
136
137 config NETLINK_DIAG
138 tristate "NETLINK: socket monitoring interface"
139 + select SOCK_DIAG
140 default n
141 help
142 Support for NETLINK socket monitoring interface used by the ss tool.
143 --- a/net/packet/Kconfig
144 +++ b/net/packet/Kconfig
145 @@ -19,6 +19,7 @@ config PACKET
146 config PACKET_DIAG
147 tristate "Packet: sockets monitoring interface"
148 depends on PACKET
149 + select SOCK_DIAG
150 default n
151 help
152 Support for PF_PACKET sockets monitoring interface used by the ss tool.
153 --- a/net/unix/Kconfig
154 +++ b/net/unix/Kconfig
155 @@ -28,6 +28,7 @@ config UNIX_SCM
156 config UNIX_DIAG
157 tristate "UNIX: socket monitoring interface"
158 depends on UNIX
159 + select SOCK_DIAG
160 default n
161 help
162 Support for UNIX socket monitoring interface used by the ss tool.