From 45e3967c20b5020bf720b9497592e231104398f3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 3 Jun 2019 14:16:52 +0200 Subject: libbb: move netlink socket binding to the utility function function old new delta create_and_bind_to_netlink - 134 +134 ifplugd_main 1117 1052 -65 uevent_main 399 306 -93 mdev_main 314 215 -99 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 134/-257) Total: -123 bytes Signed-off-by: Denys Vlasenko --- libbb/xconnect.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'libbb') diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 39e56b223..ea5fe173f 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -11,6 +11,9 @@ #include #include #include +#if ENABLE_IFPLUGD || ENABLE_FEATURE_MDEV_DAEMON || ENABLE_UEVENT +# include +#endif #include "libbb.h" int FAST_FUNC setsockopt_int(int fd, int level, int optname, int optval) @@ -412,6 +415,38 @@ int FAST_FUNC create_and_bind_dgram_or_die(const char *bindaddr, int port) } +#if ENABLE_IFPLUGD || ENABLE_FEATURE_MDEV_DAEMON || ENABLE_UEVENT +int FAST_FUNC create_and_bind_to_netlink(int proto, int grp, unsigned rcvbuf) +{ + struct sockaddr_nl sa; + int fd; + + memset(&sa, 0, sizeof(sa)); + sa.nl_family = AF_NETLINK; + sa.nl_pid = getpid(); + sa.nl_groups = grp; + fd = xsocket(AF_NETLINK, SOCK_DGRAM, proto); + xbind(fd, (struct sockaddr *) &sa, sizeof(sa)); + close_on_exec_on(fd); + + if (rcvbuf != 0) { + // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl + setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, rcvbuf); + setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, rcvbuf); +# if 0 + { + int z; + socklen_t zl = sizeof(z); + getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &z, &zl); + bb_error_msg("SO_RCVBUF:%d", z); + } +# endif + } + + return fd; +} +#endif + int FAST_FUNC create_and_connect_stream_or_die(const char *peer, int port) { int fd; -- cgit v1.2.3