summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-06-21 20:45:20 +0200
committerThomas Haller <thaller@redhat.com>2022-06-23 20:36:52 +0200
commit260d693ec48e7b01714f70aa3b467a56e58d42f9 (patch)
tree12416c872b3a019c232f7d1017eedb6c239a9cc0
parent6b0f67b7368d361cee2cfbfe3866264714556a5b (diff)
downloadNetworkManager-260d693ec48e7b01714f70aa3b467a56e58d42f9.tar.gz
platform/netlink: add "blocking" argument to nl_socket_new()
Whether we use a socket blockingly or non-blocking is usually determined upfront and does not change. Make it a parameter of nl_socket_new(). Also, it saves an additional syscall.
-rw-r--r--src/libnm-platform/nm-linux-platform.c7
-rw-r--r--src/libnm-platform/nm-netlink.c4
-rw-r--r--src/libnm-platform/nm-netlink.h2
3 files changed, 5 insertions, 8 deletions
diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c
index b997ca2e0a..9a629a8194 100644
--- a/src/libnm-platform/nm-linux-platform.c
+++ b/src/libnm-platform/nm-linux-platform.c
@@ -9747,7 +9747,7 @@ constructed(GObject *_object)
/*************************************************************************/
- nle = nl_socket_new(&priv->sk_genl_sync, NETLINK_GENERIC);
+ nle = nl_socket_new(&priv->sk_genl_sync, NETLINK_GENERIC, TRUE);
g_assert(!nle);
_LOGD("genl: generic netlink socket for sync operations created: port=%u, fd=%d",
@@ -9756,15 +9756,12 @@ constructed(GObject *_object)
/*************************************************************************/
- nle = nl_socket_new(&priv->sk_rtnl, NETLINK_ROUTE);
+ nle = nl_socket_new(&priv->sk_rtnl, NETLINK_ROUTE, FALSE);
g_assert(!nle);
nle = nl_socket_set_passcred(priv->sk_rtnl, 1);
g_assert(!nle);
- nle = nl_socket_set_nonblocking(priv->sk_rtnl);
- g_assert(!nle);
-
nle = nl_socket_set_buffer_size(priv->sk_rtnl, 8 * 1024 * 1024, 0);
g_assert(!nle);
diff --git a/src/libnm-platform/nm-netlink.c b/src/libnm-platform/nm-netlink.c
index 05790cb054..f1918df63b 100644
--- a/src/libnm-platform/nm-netlink.c
+++ b/src/libnm-platform/nm-netlink.c
@@ -1051,7 +1051,7 @@ nl_socket_disable_msg_peek(struct nl_sock *sk)
/*****************************************************************************/
int
-nl_socket_new(struct nl_sock **out_sk, int protocol)
+nl_socket_new(struct nl_sock **out_sk, int protocol, bool blocking)
{
nm_auto_nlsock struct nl_sock *sk = NULL;
nm_auto_close int fd = -1;
@@ -1063,7 +1063,7 @@ nl_socket_new(struct nl_sock **out_sk, int protocol)
nm_assert(out_sk && !*out_sk);
- fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, protocol);
+ fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | (blocking ? 0 : SOCK_NONBLOCK), protocol);
if (fd < 0)
return -nm_errno_from_native(errno);
diff --git a/src/libnm-platform/nm-netlink.h b/src/libnm-platform/nm-netlink.h
index 11dd559766..f9082c99f1 100644
--- a/src/libnm-platform/nm-netlink.h
+++ b/src/libnm-platform/nm-netlink.h
@@ -489,7 +489,7 @@ nlmsg_put(struct nl_msg *n, uint32_t pid, uint32_t seq, int type, int payload, i
struct nl_sock;
-int nl_socket_new(struct nl_sock **out_sk, int protocol);
+int nl_socket_new(struct nl_sock **out_sk, int protocol, bool blocking);
void nl_socket_free(struct nl_sock *sk);