[PATCH] cls: add rtnl_u32_get_classid() API

Thomas Haller thaller at redhat.com
Wed Mar 4 06:03:30 PST 2015


On Tue, 2015-03-03 at 22:05 -0800, Cong Wang wrote:
> Cc:  Thomas Haller <thaller at redhat.com>
> Signed-off-by: Cong Wang <xiyou.wangcong at gmail.com>
> ---
>  include/netlink/route/cls/u32.h |  1 +
>  lib/route/cls/u32.c             | 14 ++++++++++++++
>  libnl-route-3.sym               |  1 +
>  3 files changed, 16 insertions(+)
> 
> diff --git a/include/netlink/route/cls/u32.h b/include/netlink/route/cls/u32.h
> index 4567e16..151c818 100644
> --- a/include/netlink/route/cls/u32.h
> +++ b/include/netlink/route/cls/u32.h
> @@ -23,6 +23,7 @@ extern "C" {
>  
>  extern void	rtnl_u32_set_handle(struct rtnl_cls *, int, int, int);
>  extern int	rtnl_u32_set_classid(struct rtnl_cls *, uint32_t);
> +extern int	rtnl_u32_get_classid(struct rtnl_cls *, uint32_t *);
>  extern int	rtnl_u32_set_divisor(struct rtnl_cls *, uint32_t);
>  extern int	rtnl_u32_set_link(struct rtnl_cls *, uint32_t);
>  extern int	rtnl_u32_set_hashtable(struct rtnl_cls *, uint32_t);
> diff --git a/lib/route/cls/u32.c b/lib/route/cls/u32.c
> index 1912533..2e8eee4 100644
> --- a/lib/route/cls/u32.c
> +++ b/lib/route/cls/u32.c
> @@ -415,6 +415,20 @@ int rtnl_u32_set_classid(struct rtnl_cls *cls, uint32_t classid)
>  	return 0;
>  }
>  
> +int rtnl_u32_get_classid(struct rtnl_cls *cls, uint32_t *classid)\
> +{
> +	struct rtnl_u32 *u;
> +
> +	if (!(u = rtnl_tc_data(TC_CAST(cls))))
> +		return -NLE_NOMEM;

I dislike that the getter tries to allocate memory. I know, other places
do that too...

I pushed a new function rtnl_tc_data_peek() to master. How is that?

+    if (!(u = rtnl_tc_data_peek(TC_CAST(cls))))
+         return -NLE_INVAL;


> +
> +	if (!(u->cu_mask & U32_ATTR_CLASSID))
> +		return -NLE_INVAL;
> +
> +	*classid = u->cu_classid;
> +	return 0;
> +}
> +
>  int rtnl_u32_set_divisor(struct rtnl_cls *cls, uint32_t divisor)
>  {
>  	struct rtnl_u32 *u;
> diff --git a/libnl-route-3.sym b/libnl-route-3.sym
> index 2768f05..7a5f26f 100644
> --- a/libnl-route-3.sym
> +++ b/libnl-route-3.sym
> @@ -815,6 +815,7 @@ global:
>  	rtnl_u32_del_action;
>  	rtnl_u32_get_key;
>  	rtnl_u32_set_classid;
> +	rtnl_u32_get_classid;

the new symobls should move down to the new libnl_3_2_26 section (at the
end of the file).

>  	rtnl_u32_set_cls_terminal;
>  	rtnl_u32_set_divisor;
>  	rtnl_u32_set_flags;




If you agree with me doing these two changes, no need to resend the
patch (unless you want).


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


More information about the libnl mailing list