diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-03 14:16:52 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-03 14:16:52 +0200 |
commit | 45e3967c20b5020bf720b9497592e231104398f3 (patch) | |
tree | 364a53e80d1c2246e33fb00c4f6bb26e854912ae /libbb | |
parent | 498cec202adbf69a7a72af5e204260682d614183 (diff) | |
download | busybox-w32-45e3967c20b5020bf720b9497592e231104398f3.tar.gz busybox-w32-45e3967c20b5020bf720b9497592e231104398f3.tar.bz2 busybox-w32-45e3967c20b5020bf720b9497592e231104398f3.zip |
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 <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 @@ | |||
11 | #include <netinet/in.h> | 11 | #include <netinet/in.h> |
12 | #include <net/if.h> | 12 | #include <net/if.h> |
13 | #include <sys/un.h> | 13 | #include <sys/un.h> |
14 | #if ENABLE_IFPLUGD || ENABLE_FEATURE_MDEV_DAEMON || ENABLE_UEVENT | ||
15 | # include <linux/netlink.h> | ||
16 | #endif | ||
14 | #include "libbb.h" | 17 | #include "libbb.h" |
15 | 18 | ||
16 | int FAST_FUNC setsockopt_int(int fd, int level, int optname, int optval) | 19 | 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) | |||
412 | } | 415 | } |
413 | 416 | ||
414 | 417 | ||
418 | #if ENABLE_IFPLUGD || ENABLE_FEATURE_MDEV_DAEMON || ENABLE_UEVENT | ||
419 | int FAST_FUNC create_and_bind_to_netlink(int proto, int grp, unsigned rcvbuf) | ||
420 | { | ||
421 | struct sockaddr_nl sa; | ||
422 | int fd; | ||
423 | |||
424 | memset(&sa, 0, sizeof(sa)); | ||
425 | sa.nl_family = AF_NETLINK; | ||
426 | sa.nl_pid = getpid(); | ||
427 | sa.nl_groups = grp; | ||
428 | fd = xsocket(AF_NETLINK, SOCK_DGRAM, proto); | ||
429 | xbind(fd, (struct sockaddr *) &sa, sizeof(sa)); | ||
430 | close_on_exec_on(fd); | ||
431 | |||
432 | if (rcvbuf != 0) { | ||
433 | // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl | ||
434 | setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, rcvbuf); | ||
435 | setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, rcvbuf); | ||
436 | # if 0 | ||
437 | { | ||
438 | int z; | ||
439 | socklen_t zl = sizeof(z); | ||
440 | getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &z, &zl); | ||
441 | bb_error_msg("SO_RCVBUF:%d", z); | ||
442 | } | ||
443 | # endif | ||
444 | } | ||
445 | |||
446 | return fd; | ||
447 | } | ||
448 | #endif | ||
449 | |||
415 | int FAST_FUNC create_and_connect_stream_or_die(const char *peer, int port) | 450 | int FAST_FUNC create_and_connect_stream_or_die(const char *peer, int port) |
416 | { | 451 | { |
417 | int fd; | 452 | int fd; |