1
0

901-debloat_sock_diag.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  6. ---
  7. net/Kconfig | 3 +++
  8. net/core/Makefile | 3 ++-
  9. net/core/sock.c | 2 ++
  10. net/ipv4/Kconfig | 1 +
  11. net/netlink/Kconfig | 1 +
  12. net/packet/Kconfig | 1 +
  13. net/unix/Kconfig | 1 +
  14. 7 files changed, 11 insertions(+), 1 deletion(-)
  15. --- a/net/Kconfig
  16. +++ b/net/Kconfig
  17. @@ -97,6 +97,9 @@ source "net/netlabel/Kconfig"
  18. endif # if INET
  19. +config SOCK_DIAG
  20. + bool
  21. +
  22. config NETWORK_SECMARK
  23. bool "Security Marking"
  24. help
  25. --- a/net/core/Makefile
  26. +++ b/net/core/Makefile
  27. @@ -10,9 +10,10 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.
  28. obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \
  29. neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
  30. - sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
  31. + dev_ioctl.o tso.o sock_reuseport.o \
  32. fib_notifier.o
  33. +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o
  34. obj-y += net-sysfs.o
  35. obj-$(CONFIG_PROC_FS) += net-procfs.o
  36. obj-$(CONFIG_NET_PKTGEN) += pktgen.o
  37. --- a/net/core/sock.c
  38. +++ b/net/core/sock.c
  39. @@ -528,6 +528,18 @@ discard_and_relse:
  40. }
  41. EXPORT_SYMBOL(__sk_receive_skb);
  42. +u64 sock_gen_cookie(struct sock *sk)
  43. +{
  44. + while (1) {
  45. + u64 res = atomic64_read(&sk->sk_cookie);
  46. +
  47. + if (res)
  48. + return res;
  49. + res = atomic64_inc_return(&sock_net(sk)->cookie_gen);
  50. + atomic64_cmpxchg(&sk->sk_cookie, 0, res);
  51. + }
  52. +}
  53. +
  54. struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie)
  55. {
  56. struct dst_entry *dst = __sk_dst_get(sk);
  57. @@ -1618,9 +1630,11 @@ void sk_destruct(struct sock *sk)
  58. static void __sk_free(struct sock *sk)
  59. {
  60. +#ifdef CONFIG_SOCK_DIAG
  61. if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
  62. sock_diag_broadcast_destroy(sk);
  63. else
  64. +#endif
  65. sk_destruct(sk);
  66. }
  67. --- a/net/core/sock_diag.c
  68. +++ b/net/core/sock_diag.c
  69. @@ -19,18 +19,6 @@ static int (*inet_rcv_compat)(struct sk_
  70. static DEFINE_MUTEX(sock_diag_table_mutex);
  71. static struct workqueue_struct *broadcast_wq;
  72. -u64 sock_gen_cookie(struct sock *sk)
  73. -{
  74. - while (1) {
  75. - u64 res = atomic64_read(&sk->sk_cookie);
  76. -
  77. - if (res)
  78. - return res;
  79. - res = atomic64_inc_return(&sock_net(sk)->cookie_gen);
  80. - atomic64_cmpxchg(&sk->sk_cookie, 0, res);
  81. - }
  82. -}
  83. -
  84. int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
  85. {
  86. u64 res;
  87. --- a/net/ipv4/Kconfig
  88. +++ b/net/ipv4/Kconfig
  89. @@ -431,6 +431,7 @@ config INET_XFRM_MODE_BEET
  90. config INET_DIAG
  91. tristate "INET: socket monitoring interface"
  92. + select SOCK_DIAG
  93. default y
  94. ---help---
  95. Support for INET (TCP, DCCP, etc) socket monitoring interface used by
  96. --- a/net/netlink/Kconfig
  97. +++ b/net/netlink/Kconfig
  98. @@ -4,6 +4,7 @@
  99. config NETLINK_DIAG
  100. tristate "NETLINK: socket monitoring interface"
  101. + select SOCK_DIAG
  102. default n
  103. ---help---
  104. Support for NETLINK socket monitoring interface used by the ss tool.
  105. --- a/net/packet/Kconfig
  106. +++ b/net/packet/Kconfig
  107. @@ -18,6 +18,7 @@ config PACKET
  108. config PACKET_DIAG
  109. tristate "Packet: sockets monitoring interface"
  110. depends on PACKET
  111. + select SOCK_DIAG
  112. default n
  113. ---help---
  114. Support for PF_PACKET sockets monitoring interface used by the ss tool.
  115. --- a/net/unix/Kconfig
  116. +++ b/net/unix/Kconfig
  117. @@ -27,6 +27,7 @@ config UNIX_SCM
  118. config UNIX_DIAG
  119. tristate "UNIX: socket monitoring interface"
  120. depends on UNIX
  121. + select SOCK_DIAG
  122. default n
  123. ---help---
  124. Support for UNIX socket monitoring interface used by the ss tool.