From: planck kernel size experiment Subject: net: remove socket diagnostics when no diagnostic family is built Both INET_DIAG and NETLINK_DIAG are disabled in the guarded configuration, and the logger never opens NETLINK_SOCK_DIAG. The unconditional sock_diag object therefore creates a netlink endpoint and retains cookie, memory-reporting and asynchronous socket-destruction notification code with no consumer. Remove the object, its unused SO_COOKIE query, and take the normal direct socket-destruction branch unconditionally. TCP close and UDP socket release retain their ordinary destructors; only cookie introspection and notification to nonexistent diagnostic listeners disappear. The acceptance run creates, receives on and closes all three socket types, so it exercises the lifetime path after this change. --- a/net/core/Makefile +++ b/net/core/Makefile @@ -13,7 +13,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o obj-y += dev.o dev_api.o dev_addr_lists.o dst.o netevent.o \ neighbour.o rtnetlink.o utils.o link_watch.o \ - sock_diag.o dev_ioctl.o tso.o \ + dev_ioctl.o tso.o \ fib_notifier.o xdp.o flow_offload.o gro.o \ gso.o --- a/net/core/sock.c +++ b/net/core/sock.c @@ -133,7 +133,6 @@ #include #include #include #include -#include #include @@ -2057,13 +2056,6 @@ int sk_getsockopt(struct sock *sk, int level, int optname, break; #endif - case SO_COOKIE: - lv = sizeof(u64); - if (len < lv) - return -EINVAL; - v.val64 = sock_gen_cookie(sk); - break; - case SO_ZEROCOPY: v.val = sock_flag(sk, SOCK_ZEROCOPY); break; @@ -2354,10 +2346,7 @@ static void __sk_free(struct sock *sk) if (likely(sk->sk_net_refcnt)) sock_inuse_add(sock_net(sk), -1); - if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk))) - sock_diag_broadcast_destroy(sk); - else - sk_destruct(sk); + sk_destruct(sk); } void sk_free(struct sock *sk)