kernel: add support for kernel 5.4
[oweals/openwrt.git] / target / linux / generic / hack-5.4 / 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 @@ -100,6 +100,9 @@ source "net/netlabel/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 ethtool.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 @@ -140,6 +140,7 @@
46  
47  static DEFINE_MUTEX(proto_list_mutex);
48  static LIST_HEAD(proto_list);
49 +static atomic64_t cookie_gen;
50  
51  static void sock_inuse_add(struct net *net, int val);
52  
53 @@ -539,6 +540,18 @@ discard_and_relse:
54  }
55  EXPORT_SYMBOL(__sk_receive_skb);
56  
57 +u64 sock_gen_cookie(struct sock *sk)
58 +{
59 +       while (1) {
60 +               u64 res = atomic64_read(&sk->sk_cookie);
61 +
62 +               if (res)
63 +                       return res;
64 +               res = atomic64_inc_return(&cookie_gen);
65 +               atomic64_cmpxchg(&sk->sk_cookie, 0, res);
66 +       }
67 +}
68 +
69  struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie)
70  {
71         struct dst_entry *dst = __sk_dst_get(sk);
72 @@ -1746,9 +1759,11 @@ static void __sk_free(struct sock *sk)
73         if (likely(sk->sk_net_refcnt))
74                 sock_inuse_add(sock_net(sk), -1);
75  
76 +#ifdef CONFIG_SOCK_DIAG
77         if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
78                 sock_diag_broadcast_destroy(sk);
79         else
80 +#endif
81                 sk_destruct(sk);
82  }
83  
84 --- a/net/core/sock_diag.c
85 +++ b/net/core/sock_diag.c
86 @@ -19,19 +19,6 @@ static const struct sock_diag_handler *s
87  static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
88  static DEFINE_MUTEX(sock_diag_table_mutex);
89  static struct workqueue_struct *broadcast_wq;
90 -static atomic64_t cookie_gen;
91 -
92 -u64 sock_gen_cookie(struct sock *sk)
93 -{
94 -       while (1) {
95 -               u64 res = atomic64_read(&sk->sk_cookie);
96 -
97 -               if (res)
98 -                       return res;
99 -               res = atomic64_inc_return(&cookie_gen);
100 -               atomic64_cmpxchg(&sk->sk_cookie, 0, res);
101 -       }
102 -}
103  
104  int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
105  {
106 --- a/net/ipv4/Kconfig
107 +++ b/net/ipv4/Kconfig
108 @@ -399,6 +399,7 @@ config INET_TUNNEL
109  
110  config INET_DIAG
111         tristate "INET: socket monitoring interface"
112 +       select SOCK_DIAG
113         default y
114         ---help---
115           Support for INET (TCP, DCCP, etc) socket monitoring interface used by
116 --- a/net/netlink/Kconfig
117 +++ b/net/netlink/Kconfig
118 @@ -5,6 +5,7 @@
119  
120  config NETLINK_DIAG
121         tristate "NETLINK: socket monitoring interface"
122 +       select SOCK_DIAG
123         default n
124         ---help---
125           Support for NETLINK socket monitoring interface used by the ss tool.
126 --- a/net/packet/Kconfig
127 +++ b/net/packet/Kconfig
128 @@ -19,6 +19,7 @@ config PACKET
129  config PACKET_DIAG
130         tristate "Packet: sockets monitoring interface"
131         depends on PACKET
132 +       select SOCK_DIAG
133         default n
134         ---help---
135           Support for PF_PACKET sockets monitoring interface used by the ss tool.
136 --- a/net/unix/Kconfig
137 +++ b/net/unix/Kconfig
138 @@ -28,6 +28,7 @@ config UNIX_SCM
139  config UNIX_DIAG
140         tristate "UNIX: socket monitoring interface"
141         depends on UNIX
142 +       select SOCK_DIAG
143         default n
144         ---help---
145           Support for UNIX socket monitoring interface used by the ss tool.