|
|
81f82ab |
From Stefan Berger <stefanb@us.ibm.com>
|
|
|
81f82ab |
https://bugzilla.redhat.com/show_bug.cgi?id=677527
|
|
|
81f82ab |
|
|
|
81f82ab |
--- libnl-1.1/lib/socket.c
|
|
|
81f82ab |
+++ libnl-1.1/lib/socket.c
|
|
|
81f82ab |
@@ -89,6 +89,8 @@
|
|
|
81f82ab |
* @{
|
|
|
81f82ab |
*/
|
|
|
81f82ab |
|
|
|
81f82ab |
+#include <pthread.h>
|
|
|
81f82ab |
+
|
|
|
81f82ab |
#include <netlink-local.h>
|
|
|
81f82ab |
#include <netlink/netlink.h>
|
|
|
81f82ab |
#include <netlink/utils.h>
|
|
|
81f82ab |
@@ -117,12 +119,15 @@ static void __init init_default_cb(void)
|
|
|
81f82ab |
}
|
|
|
81f82ab |
|
|
|
81f82ab |
static uint32_t used_ports_map[32];
|
|
|
81f82ab |
+static pthread_mutex_t port_map_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
81f82ab |
|
|
|
81f82ab |
static uint32_t generate_local_port(void)
|
|
|
81f82ab |
{
|
|
|
81f82ab |
int i, n;
|
|
|
81f82ab |
uint32_t pid = getpid() & 0x3FFFFF;
|
|
|
81f82ab |
|
|
|
81f82ab |
+ pthread_mutex_lock(&port_map_mutex);
|
|
|
81f82ab |
+
|
|
|
81f82ab |
for (i = 0; i < 32; i++) {
|
|
|
81f82ab |
if (used_ports_map[i] == 0xFFFFFFFF)
|
|
|
81f82ab |
continue;
|
|
|
81f82ab |
@@ -136,11 +141,15 @@ static uint32_t generate_local_port(void
|
|
|
81f82ab |
|
|
|
81f82ab |
/* PID_MAX_LIMIT is currently at 2^22, leaving 10 bit
|
|
|
81f82ab |
* to, i.e. 1024 unique ports per application. */
|
|
|
81f82ab |
- return pid + (n << 22);
|
|
|
81f82ab |
|
|
|
81f82ab |
+ pthread_mutex_unlock(&port_map_mutex);
|
|
|
81f82ab |
+
|
|
|
81f82ab |
+ return pid + (n << 22);
|
|
|
81f82ab |
}
|
|
|
81f82ab |
}
|
|
|
81f82ab |
|
|
|
81f82ab |
+ pthread_mutex_unlock(&port_map_mutex);
|
|
|
81f82ab |
+
|
|
|
81f82ab |
/* Out of sockets in our own PID namespace, what to do? FIXME */
|
|
|
81f82ab |
return UINT_MAX;
|
|
|
81f82ab |
}
|
|
|
81f82ab |
@@ -153,7 +162,10 @@ static void release_local_port(uint32_t
|
|
|
81f82ab |
return;
|
|
|
81f82ab |
|
|
|
81f82ab |
nr = port >> 22;
|
|
|
81f82ab |
- used_ports_map[nr / 32] &= ~(1 << (nr % 32));
|
|
|
81f82ab |
+
|
|
|
81f82ab |
+ pthread_mutex_lock(&port_map_mutex);
|
|
|
81f82ab |
+ used_ports_map[nr / 32] &= ~(1 << (nr % 32));
|
|
|
81f82ab |
+ pthread_mutex_unlock(&port_map_mutex);
|
|
|
81f82ab |
}
|
|
|
81f82ab |
|
|
|
81f82ab |
/**
|
|
|
81f82ab |
--- libnl-1.1/lib/Makefile
|
|
|
81f82ab |
+++ libnl-1.1/lib/Makefile
|
|
|
81f82ab |
@@ -53,7 +53,7 @@ all:
|
|
|
81f82ab |
$(MAKE) $(targets)
|
|
|
81f82ab |
|
|
|
81f82ab |
$(OUT_SLIB): ../Makefile.opts $(OBJ)
|
|
|
81f82ab |
- $(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc
|
|
|
81f82ab |
+ $(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc -lpthread
|
|
|
81f82ab |
rm -f $(LN1_SLIB) ; $(LN) -s $(OUT_SLIB) $(LN1_SLIB)
|
|
|
81f82ab |
rm -f $(LN_SLIB) ; $(LN) -s $(LN1_SLIB) $(LN_SLIB)
|
|
|
81f82ab |
|
|
|
81f82ab |
|