[PATCH 3/3] core: retry generate local port in nl_connect on ADDRINUSE

Thomas Graf tgraf at suug.ch
Wed Apr 9 00:07:23 PDT 2014


On 04/08/14 at 02:06pm, Thomas Haller wrote:
> It is a common error, 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
> themselfes, 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 only after the user calls
> nl_socket_get_local_port() the first time and thereby shows interest in
> the value.
> 
> If bind() fails due to ADDRINUSE, we check if the user ever cared about
> the local port, i.e. whether the local port is still unset. In that case
> we assume that libnl should choose a suitable port and we retry until we
> find a matching port.
> 
> Signed-off-by: Thomas Haller <thaller at redhat.com>

Very nice work

Acked-by: Thomas Graf <tgraf at suug.ch>



More information about the libnl mailing list