summaryrefslogtreecommitdiffstats
path: root/lib/utils.c
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 /lib/utils.c
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 'lib/utils.c')
-rw-r--r--lib/utils.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/utils.c b/lib/utils.c
index e2294e6..5cc9e94 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1147,7 +1147,7 @@ int nl_has_capability (int capability)
NL_CAPABILITY_ROUTE_BUILD_MSG_SET_SCOPE,
NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE,
NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE,
- 0,
+ NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE,
0,
0,
0,