[libnl/f15/master] Fix various portmap issues

Daniel Williams dcbw at fedoraproject.org
Mon Mar 21 19:39:42 UTC 2011


commit 710a7803b5e9d4ad2d9a5b7ebf1ad6f34f51b7cf
Author: Dan Williams <dcbw at redhat.com>
Date:   Mon Mar 21 14:40:25 2011 -0500

    Fix various portmap issues

 libnl-1.1-fix-portmap-position.patch       |   25 ++++++++++
 libnl-1.1-threadsafe-port-allocation.patch |   71 ++++++++++++++++++++++++++++
 libnl.spec                                 |   10 ++++-
 3 files changed, 105 insertions(+), 1 deletions(-)
---
diff --git a/libnl-1.1-fix-portmap-position.patch b/libnl-1.1-fix-portmap-position.patch
new file mode 100644
index 0000000..d566289
--- /dev/null
+++ b/libnl-1.1-fix-portmap-position.patch
@@ -0,0 +1,25 @@
+commit ef8ba32e0ca7ac7bbbaf87f6fd7b197af18aed25
+Author: Inaky Perez-Gonzalez <inaky at linux.intel.com>
+Date:   Mon Apr 27 14:46:08 2009 -0700
+
+    release_local_port: properly compute the bitmap position
+    
+    Current calculation is always off, not reflecting the right position
+    in the bitmap, which results in failures due to conflicts (detected at
+    the kernel level) when trying to open a new handle.
+    
+    Signed-off-by: Inaky Perez-Gonzalez <inaky at linux.intel.com>
+
+diff --git a/lib/socket.c b/lib/socket.c
+index d1874f0..8083bbb 100644
+--- a/lib/socket.c
++++ b/lib/socket.c
+@@ -79,7 +79,7 @@ static void release_local_port(uint32_t port)
+ 		return;
+ 	
+ 	nr = port >> 22;
+-	used_ports_map[nr / 32] &= ~((nr % 32) + 1);
++	used_ports_map[nr / 32] &= ~(1 << (nr % 32));
+ }
+ 
+ /**
diff --git a/libnl-1.1-threadsafe-port-allocation.patch b/libnl-1.1-threadsafe-port-allocation.patch
new file mode 100644
index 0000000..e2f9459
--- /dev/null
+++ b/libnl-1.1-threadsafe-port-allocation.patch
@@ -0,0 +1,71 @@
+From Stefan Berger <stefanb at us.ibm.com>
+https://bugzilla.redhat.com/show_bug.cgi?id=677527
+
+--- libnl-1.1/lib/socket.c	
++++ libnl-1.1/lib/socket.c	
+@@ -89,6 +89,8 @@ 
+  * @{
+  */
+ 
++#include <pthread.h>
++
+ #include <netlink-local.h>
+ #include <netlink/netlink.h>
+ #include <netlink/utils.h>
+@@ -117,12 +119,15 @@ static void __init init_default_cb(void)
+ }
+ 
+ static uint32_t used_ports_map[32];
++static pthread_mutex_t port_map_mutex = PTHREAD_MUTEX_INITIALIZER;
+ 
+ static uint32_t generate_local_port(void)
+ {
+ 	int i, n;
+ 	uint32_t pid = getpid() & 0x3FFFFF;
+ 
++	pthread_mutex_lock(&port_map_mutex);
++
+ 	for (i = 0; i < 32; i++) {
+ 		if (used_ports_map[i] == 0xFFFFFFFF)
+ 			continue;
+@@ -136,11 +141,15 @@ static uint32_t generate_local_port(void
+ 
+ 			/* PID_MAX_LIMIT is currently at 2^22, leaving 10 bit
+ 			 * to, i.e. 1024 unique ports per application. */
+-			return pid + (n << 22);
+ 
++			pthread_mutex_unlock(&port_map_mutex);
++
++			return pid + (n << 22);
+ 		}
+ 	}
+ 
++	pthread_mutex_unlock(&port_map_mutex);
++
+ 	/* Out of sockets in our own PID namespace, what to do? FIXME */
+ 	return UINT_MAX;
+ }
+@@ -153,7 +162,10 @@ static void release_local_port(uint32_t 
+ 		return;
+ 	
+ 	nr = port >> 22;
+-	used_ports_map[nr / 32] &= ~(1 << (nr % 32));
++	
++	pthread_mutex_lock(&port_map_mutex);
++	used_ports_map[nr / 32] &= ~(1 << (nr % 32));
++	pthread_mutex_unlock(&port_map_mutex);
+ }
+ 
+ /**
+--- libnl-1.1/lib/Makefile	
++++ libnl-1.1/lib/Makefile	
+@@ -53,7 +53,7 @@ all:
+ 	$(MAKE) $(targets)
+ 
+ $(OUT_SLIB): ../Makefile.opts $(OBJ)
+-	$(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc
++	$(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc -lpthread
+ 	rm -f $(LN1_SLIB) ; $(LN) -s $(OUT_SLIB) $(LN1_SLIB)
+ 	rm -f $(LN_SLIB) ; $(LN) -s $(LN1_SLIB) $(LN_SLIB)
+ 
+
diff --git a/libnl.spec b/libnl.spec
index 19eb04f..5d42c60 100644
--- a/libnl.spec
+++ b/libnl.spec
@@ -3,7 +3,7 @@ Group: Development/Libraries
 License: LGPLv2
 Name: libnl
 Version: 1.1
-Release: 13%{?dist}
+Release: 14%{?dist}
 URL: http://www.infradead.org/~tgr/libnl/
 Source: http://www.infradead.org/~tgr/libnl/files/libnl-%{version}.tar.gz
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
@@ -17,6 +17,8 @@ Patch6: libnl-1.1-doc-inlinesrc.patch
 Patch7: libnl-1.1-no-extern-inline.patch
 Patch8: libnl-1.1-align.patch
 Patch9: libnl-1.1-disable-static-by-default.patch
+Patch10: libnl-1.1-fix-portmap-position.patch
+Patch11: libnl-1.1-threadsafe-port-allocation.patch
 
 %description
 This package contains a convenience library to simplify
@@ -44,6 +46,8 @@ This package contains various headers for using libnl
 %patch7 -p1 -b .no-extern-inline
 %patch8 -p1 -b .align
 %patch9 -p1 -b .disable-static-by-default
+%patch10 -p1 -b .fix-portmap-position
+%patch11 -p1 -b .threadsafe-port-allocation
 
 # a quick hack to make doxygen stripping builddir from html outputs.
 sed -i.org -e "s,^STRIP_FROM_PATH.*,STRIP_FROM_PATH = `pwd`," doc/Doxyfile.in
@@ -83,6 +87,10 @@ done
 %{_libdir}/pkgconfig/%{name}-1.pc
 
 %changelog
+* Mon Mar 21 2011 Dan Williams <dcbw at redhat.com> - 1.1-14
+- Fix portmap position calculation (rh #677526) (rh #677725)
+- Make port allocation threadsafe (rh #677527) (rh #677724)
+
 * Tue Feb 08 2011 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.1-13
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild
 


More information about the scm-commits mailing list