Add new function for setting ifindex and parent of a classifier cache.

It is not good to give classifier cache users only one chance to
set interface index and parent handle when allocte new cache.
Sometimes we want to reuse classifier cache to reduce the overhead
of allocating new memory everytime a new cache is created.
This commit is contained in:
d0u9 2018-01-15 16:35:50 +08:00 committed by Thomas Haller
parent 2b11ab02ce
commit ca02edd101
3 changed files with 21 additions and 0 deletions

View File

@ -27,6 +27,8 @@ extern void rtnl_cls_put(struct rtnl_cls *);
extern int rtnl_cls_alloc_cache(struct nl_sock *, int, uint32_t,
struct nl_cache **);
extern void rtnl_cls_cache_set_tcm_params(struct nl_cache *, int, uint32_t);
extern int rtnl_cls_build_add_request(struct rtnl_cls *, int,
struct nl_msg **);
extern int rtnl_cls_add(struct nl_sock *, struct rtnl_cls *, int);

View File

@ -345,6 +345,24 @@ int rtnl_cls_alloc_cache(struct nl_sock *sk, int ifindex, uint32_t parent,
return 0;
}
/**
* Set interface index and parent handle for classifier cache.
* @arg cache Pointer to cache
* @arg parent Parent qdisc/traffic class class
*
* Set the interface index and parent handle of a classifier cache.
* This is useful for reusing some existed classifier cache to reduce
* the overhead introduced by memory allocation.
*
* @return void.
*/
void rtnl_cls_cache_set_tcm_params(struct nl_cache *cache,
int ifindex, uint32_t parent)
{
cache->c_iarg1 = ifindex;
cache->c_iarg2 = parent;
}
/** @} */
static void cls_dump_line(struct rtnl_tc *tc, struct nl_dump_params *p)

View File

@ -151,6 +151,7 @@ global:
rtnl_cls_add;
rtnl_cls_alloc;
rtnl_cls_alloc_cache;
rtnl_cls_cache_set_tcm_params;
rtnl_cls_build_add_request;
rtnl_cls_build_change_request;
rtnl_cls_build_delete_request;