[PATCH 0/2] add function nl_get_capabilities()

Thomas Haller thaller at redhat.com
Fri Feb 21 07:35:33 EST 2014


On Thu, 2014-02-20 at 18:12 +0100, Thomas Haller wrote:
> Thomas Haller (2):
>   utils: add nl_get_capabilities() function
>   utils: indicate capability ROUTE_BUILD_MSG_SET_SCOPE
> 
>  include/netlink/utils.h | 16 ++++++++++++++++
>  lib/utils.c             | 23 +++++++++++++++++++++++
>  2 files changed, 39 insertions(+)
> 


Maybe I should explain better, how I intend to use this.


Suppose, there is a bug in libnl. You know how to workaround it and
upstream there is already a patch that fixes it (which would conflict
with your workaround). So, you'd have to operate libnl differently,
depending on whether it has that particular fix or not.

The version number of libnl is not enough, because the patch could be
backported to an older library version too.

A compile time option is also quite inflexible, because you might not be
able to detect the patch with autoconf tests and you don't want to
recompile your application when libnl gets patched.

So, with nl_get_capabilities() you can query at runtime, whether libnl
has that particular patch.


I imagine something like the following (I did not test this yet):



#define NL_CAPABILITIES_SOMETHING    4711
typedef const int *(*t_nl_get_capabilities)();

int libnl_has_capability() {
    void *handle;
    int cap = 0;

    handle = dlopen("libnl-3.so", RTLD_NOLOAD);

    if (handle) {
        t_nl_get_capabilities get_c = dlsym(handle,"nl_get_capabilities");

        if (get_c) {
            const int *c = get_c();

            while (1) {
                switch (*c++) {
                    case NL_CAPABILITIES_SOMETHING:
                         cap = 1;
                    case 0:
                         break;
                }
            }
        }
        dlclose(handle);
    }
    return cap;
}



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20140221/94fdf05b/attachment.sig>


More information about the libnl mailing list