From cuthbert.kao at gmail.com  Wed Jan 13 00:43:59 2010
From: cuthbert.kao at gmail.com (Cuthbert Kao)
Date: Wed, 13 Jan 2010 13:43:59 +0800
Subject: Couldn't link library libnl
Message-ID: <b81d071001122143g751b0685ncdf2991f34687e6d@mail.gmail.com>

Hi folks,

   I am newbie to linux application programming and got a problem of linking
standard library 'libnl.so'. Here my test code:

#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>

int main() {
    struct nl_handle *sock;
    int family;

    // Allocate a new netlink socket
    sock = nl_handle_alloc();
}

Then, compile and link my code with libnl:

$ gcc test.c
/tmp/ccJh2gSl.o: In function `main':
test.c:(.text+0x12): undefined reference to `nl_handle_alloc'
collect2: ld returned 1 exit status

However, the paths of header file and library were included already. still
don't know why couldn't compile it??
$ gcc -v test.c
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--enable-targets=all --with-tune=generic --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic'
 /usr/lib/gcc/i486-linux-gnu/4.3.3/cc1 -quiet -v test.c -D_FORTIFY_SOURCE=2
-quiet -dumpbase test.c -mtune=generic -auxbase test -version
-fstack-protector -o /tmp/ccMicv7a.s
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.3.3/include
 /usr/lib/gcc/i486-linux-gnu/4.3.3/include-fixed
 /usr/include
End of search list.
GNU C (Ubuntu 4.3.3-5ubuntu4) version 4.3.3 (i486-linux-gnu)
compiled by GNU C version 4.3.3, GMP version 4.2.4, MPFR version 2.4.0.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128351
Compiler executable checksum: 0bf5703b57e064ca90b48f4e2c186f4a
COLLECT_GCC_OPTIONS='-v' '-mtune=generic'
 as -V -Qy -o /tmp/cckXhlcm.o /tmp/ccMicv7a.s
GNU assembler version 2.19.1 (i486-linux-gnu) using BFD version (GNU
Binutils for Ubuntu) 2.19.1
COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic'
 /usr/lib/gcc/i486-linux-gnu/4.3.3/collect2 --eh-frame-hdr -m elf_i386
--hash-style=both -dynamic-linker /lib/ld-linux.so.2 -z relro
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.3.3/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.3.3 -L/usr/lib/gcc/i486-linux-gnu/4.3.3
-L/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib -L/lib/../lib
-L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.3.3/../../..
/tmp/cckXhlcm.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed
/usr/lib/gcc/i486-linux-gnu/4.3.3/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crtn.o
/tmp/cckXhlcm.o: In function `main':
test.c:(.text+0x12): undefined reference to `nl_handle_alloc'
collect2: ld returned 1 exit status

Search the header file and library:

$ ls /usr/include/netlink/*
/usr/include/netlink/addr.h       /usr/include/netlink/list.h
 /usr/include/netlink/object.h
/usr/include/netlink/attr.h       /usr/include/netlink/msg.h
/usr/include/netlink/socket.h
/usr/include/netlink/cache-api.h  /usr/include/netlink/netlink-compat.h
 /usr/include/netlink/types.h
/usr/include/netlink/cache.h      /usr/include/netlink/netlink.h
/usr/include/netlink/utils.h
/usr/include/netlink/data.h       /usr/include/netlink/netlink-kernel.h
/usr/include/netlink/handlers.h   /usr/include/netlink/object-api.h

/usr/include/netlink/fib_lookup:
lookup.h  request.h

/usr/include/netlink/genl:
ctrl.h  family.h  genl.h  mngt.h

/usr/include/netlink/route:
addr.h        classifier-modules.h  link.h       nexthop.h        route.h
 sch
class.h       class-modules.h       neighbour.h  qdisc.h          rtnl.h
tc.h
classifier.h  cls                   neightbl.h   qdisc-modules.h  rule.h
$ ls /usr/lib/libnl*
/usr/lib/libnl.so  /usr/lib/libnl.so.1  /usr/lib/libnl.so.1.1

$ gcc --version
gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3

libnl installation info:
libnl-1.1.so
libnl-dev
libnl-doc

OS: ubuntu 9.04

The header file and library seem to be in the right place but why I can not
link the library successfully??
Is there any one know where I was wrong or missed? Thanks in advance.

Cuthbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20100113/61edb4da/attachment.htm>

From heiko at sntech.de  Wed Jan 13 08:47:00 2010
From: heiko at sntech.de (Heiko =?iso-8859-1?q?St=FCbner?=)
Date: Wed, 13 Jan 2010 14:47:00 +0100
Subject: release plans for libnl 2.0?
Message-ID: <201001131447.00928.heiko@sntech.de>

Hi all,

do you have any release timeplan for the current development version of libnl?

Background:
I maintain part of the Debian packages of the freesmartphone.org software-
stack used for example on the Openmoko Neo Freerunner.
In coming versions they use the current development libnl (2.0). Therefore I 
have to get the Debian libnl-Maintainer to package it.
As libnl is used by some system-level components (e.g. wpasupplicant) it would 
be easier to handle "official released" software :-) .

Thanks
Heiko


From joseignacio.naranjo at gmail.com  Thu Jan 14 12:27:12 2010
From: joseignacio.naranjo at gmail.com (Jose Ignacio Naranjo)
Date: Thu, 14 Jan 2010 18:27:12 +0100
Subject: Bug when calculating ticks_per_usec
Message-ID: <4B4F53F0.3030708@gmail.com>

Hi list,

I've noticed a wrong behavior when setting up some delays in a netem
qdisc.  I will try to make the things easier for the reader describing
the calls path.

To set up a delay (or jitter...) I use 'rtnl_netem_set_delay' which
requires an int parameter that tells the delay in micro seconds. Inside
this func, the delay is set up with the help of 'nl_us2ticks', which is
just an arithmetic operation (us * ticks_per_usec), where us is the
input parameter and ticks_per_usec is a global variable initialized in
'get_psched_settings'. And here is the problem:

If this variable is going to be calculated using '/proc/net/psched', I
think the file scan is not done properly.

I don't understand what the meaning of the asterisk is here:

int r = fscanf(fd, "%08x%08x%08x%*08x", &tick, &us, &nom);
if (4 == r && nom == 1000000 && !got_tick)
	ticks_per_usec = (double)tick/(double)us;

The execution path never gets in the if statement, because r is always
3, and if the fourth parameter is read (avoiding the asterisk), there is
no variable to store it in, so it comes a segv. In my opinion we can get
rid of the if statement, because I think the proc psched file has always
a fixed format of 4 parameters, and 'nom' is always 1000000
(http://lxr.linux.no/#linux+v2.6.32/net/sched/sch_api.c#L1678).

Find attached a patch I did, if I am correct.

Regards,
JI
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-Fix-a-bug-when-calculating-ticks_per_usec.patch
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20100114/d0f3b791/attachment.el>

From joseignacio.naranjo at gmail.com  Thu Jan 14 12:10:10 2010
From: joseignacio.naranjo at gmail.com (=?UTF-8?q?Jose=20Ignacio=20Naranjo=20Hern=C3=A1ndez?=)
Date: Thu, 14 Jan 2010 18:10:10 +0100
Subject: [PATCH] Fix a bug when calculating ticks_per_usec
Message-ID: <mailman.151.1263490056.2170.libnl@lists.infradead.org>

---
 lib/utils.c |   35 ++++++++++++++++-------------------
 1 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/lib/utils.c b/lib/utils.c
index 263eb38..4007bee 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -285,7 +285,7 @@ static void __init get_psched_settings(void)
 {
 	char name[FILENAME_MAX];
 	FILE *fd;
-	int got_hz = 0, got_tick = 0;
+	int got_hz = 0;
 
 	if (getenv("HZ")) {
 		long hz = strtol(getenv("HZ"), NULL, 0);
@@ -301,28 +301,25 @@ static void __init get_psched_settings(void)
 
 	if (getenv("TICKS_PER_USEC")) {
 		double t = strtod(getenv("TICKS_PER_USEC"), NULL);
-
 		ticks_per_usec = t;
-		got_tick = 1;
 	}
+	else {
+		if (getenv("PROC_NET_PSCHED"))
+			snprintf(name, sizeof(name), "%s", getenv("PROC_NET_PSCHED"));
+		else if (getenv("PROC_ROOT"))
+			snprintf(name, sizeof(name), "%s/net/psched",
+				 getenv("PROC_ROOT"));
+		else
+			strncpy(name, "/proc/net/psched", sizeof(name) - 1);
 		
-
-	if (getenv("PROC_NET_PSCHED"))
-		snprintf(name, sizeof(name), "%s", getenv("PROC_NET_PSCHED"));
-	else if (getenv("PROC_ROOT"))
-		snprintf(name, sizeof(name), "%s/net/psched",
-			 getenv("PROC_ROOT"));
-	else
-		strncpy(name, "/proc/net/psched", sizeof(name) - 1);
-
-	if ((fd = fopen(name, "r"))) {
-		uint32_t tick, us, nom;
-		int r = fscanf(fd, "%08x%08x%08x%*08x", &tick, &us, &nom);
-
-		if (4 == r && nom == 1000000 && !got_tick)
+		if ((fd = fopen(name, "r"))) {
+			uint32_t tick, us;
+			/* the file contains 4 hexadecimals, but we just use
+			   the first two of them */
+			int r = fscanf(fd, "%08x %08x", &tick, &us);
 			ticks_per_usec = (double)tick/(double)us;
-			
-		fclose(fd);
+			fclose(fd);
+		}
 	}
 }
 
-- 
1.6.5.2


--------------030206090900000503070606--


