[PATCH 1/2] utils: add nl_get_capabilities() function

Thomas Graf tgraf at suug.ch
Fri Feb 21 10:17:04 EST 2014


On 02/20/14 at 06:12pm, Thomas Haller wrote:
> Signed-off-by: Thomas Haller <thaller at redhat.com>
> ---
>  include/netlink/utils.h |  8 ++++++++
>  lib/utils.c             | 22 ++++++++++++++++++++++
>  2 files changed, 30 insertions(+)
> 
> diff --git a/include/netlink/utils.h b/include/netlink/utils.h
> index 502341a..3c1c460 100644
> --- a/include/netlink/utils.h
> +++ b/include/netlink/utils.h
> @@ -79,6 +79,14 @@ extern void	nl_new_line(struct nl_dump_params *);
>  extern void	nl_dump(struct nl_dump_params *, const char *, ...);
>  extern void	nl_dump_line(struct nl_dump_params *, const char *, ...);
>  
> +enum {
> +	NL_CAPABILITY_NONE,
> +
> +	__NL_CAPABILITY_MAX
> +#define NL_CAPABILITY_MAX                               (__NL_CAPABILITY_MAX - 1)
> +};
> +const int *nl_get_capabilities (void);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/lib/utils.c b/lib/utils.c
> index 1267e87..3235f60 100644
> --- a/lib/utils.c
> +++ b/lib/utils.c
> @@ -1111,6 +1111,28 @@ void dump_from_ops(struct nl_object *obj, struct nl_dump_params *params)
>  		obj->ce_ops->oo_dump[type](obj, params);
>  }
>  
> +/**
> + * Returns a list of capabilities that this version of libnl
> + * supports. The capabilities are integer constants with
> + * name NL_CAPABILITY_*.
> + *
> + * This allows users to check at runtime whether the loaded
> + * libnl library supports a predefined set of capabilities.
> + * This is useful so that applications can workaround known issues of
> + * libnl that are fixed in newer library versions, without having a
> + * hard dependency on the new version.
> + *
> + * The array is terminated with 0 (NL_CAPABILITY_NONE) and the
> + * capabilities are sorted ascending.
> + **/
> +const int *nl_get_capabilities ()
> +{
> +	static const int caps[] = {
> +		NL_CAPABILITY_NONE
> +	};

use of a full 32 bit int for each cap will blow up the static
structure quickly depending on how many caps you are planning
to add. What about using a bitmap?



More information about the libnl mailing list