summaryrefslogtreecommitdiffstats
path: root/include/netlink-private
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-04-09 10:08:52 (GMT)
committerThomas Haller <thaller@redhat.com>2014-05-06 12:34:58 (GMT)
commit4dd5fdd0af2c0b7ffe1dbc49313f263dbb2e906f (patch)
tree77e2bdc68404e664f27b0aded7512865b4e00493 /include/netlink-private
parent0271578987088210d7d2d68addbd5e8fe27d4383 (diff)
downloadlibnl-4dd5fdd0af2c0b7ffe1dbc49313f263dbb2e906f.zip
libnl-4dd5fdd0af2c0b7ffe1dbc49313f263dbb2e906f.tar.gz
libnl-4dd5fdd0af2c0b7ffe1dbc49313f263dbb2e906f.tar.bz2
lib/socket: retry generate local port in nl_connect on ADDRINUSE
It can easily happen that the generated local netlink port is alrady in use. In that case bind will fail with ADDRINUSE. Users of libnl3 could workaround this, by managing the local ports themselves, but sometimes these users are libraries too and they also don't know which ports might be used by other components. This patch changes that nl_socket_alloc() no longer initilizes the local port id immediately. Instead it will be initialized when the user calls nl_socket_get_local_port() the first time and thereby shows interest in the value. If bind() fails with ADDRINUSE, check if the user ever cared about the local port, i.e. whether the local port is still unset. If it is still unset, assume that libnl should choose a suitable port and retry until an unused port can be found. Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'include/netlink-private')
-rw-r--r--include/netlink-private/socket.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/netlink-private/socket.h b/include/netlink-private/socket.h
new file mode 100644
index 0000000..86a440c
--- /dev/null
+++ b/include/netlink-private/socket.h
@@ -0,0 +1,31 @@
+/*
+ * netlink-private/socket.h Private declarations for socket
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2014 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_SOCKET_PRIV_H_
+#define NETLINK_SOCKET_PRIV_H_
+
+#include <netlink-private/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _nl_socket_is_local_port_unspecified (struct nl_sock *sk);
+uint32_t _nl_socket_generate_local_port_no_release(struct nl_sock *sk);
+
+void _nl_socket_used_ports_release_all(const uint32_t *used_ports);
+void _nl_socket_used_ports_set(uint32_t *used_ports, uint32_t port);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif