From e4b507e290475b59b08a022b1805f693d7867355 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Thu, 24 Mar 2011 22:50:11 +0100 Subject: Deprecate rtnl_qdisc_foreach_child() and rtnl_qdisc_foreach_cls() Their usage is not completely safe, it is not possible to handle the out of memory situation of the allocate filter. It is very unlikely for this to cause any problem though. The functions are still accessible but gcc will warn about their deprecation. --- include/netlink/route/qdisc.h | 5 +++-- lib/route/qdisc.c | 31 +++++++++++++------------------ src/nl-tctree-list.c | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/include/netlink/route/qdisc.h b/include/netlink/route/qdisc.h index a08fca1..fbff666 100644 --- a/include/netlink/route/qdisc.h +++ b/include/netlink/route/qdisc.h @@ -48,13 +48,14 @@ extern int rtnl_qdisc_build_delete_request(struct rtnl_qdisc *, struct nl_msg **); extern int rtnl_qdisc_delete(struct nl_sock *, struct rtnl_qdisc *); +/* Deprecated functions */ extern void rtnl_qdisc_foreach_child(struct rtnl_qdisc *, struct nl_cache *, void (*cb)(struct nl_object *, void *), - void *); + void *) __attribute__ ((deprecated)); extern void rtnl_qdisc_foreach_cls(struct rtnl_qdisc *, struct nl_cache *, void (*cb)(struct nl_object *, void *), - void *); + void *) __attribute__ ((deprecated)); #ifdef __cplusplus } diff --git a/lib/route/qdisc.c b/lib/route/qdisc.c index d0f2edc..5257b9d 100644 --- a/lib/route/qdisc.c +++ b/lib/route/qdisc.c @@ -429,17 +429,15 @@ void rtnl_qdisc_put(struct rtnl_qdisc *qdisc) /** @} */ /** - * @name Iterators + * @name Deprecated Functions * @{ */ /** - * Call a callback for each child class of a qdisc - * @arg qdisc the parent qdisc - * @arg cache a class cache including all classes of the interface - * the specified qdisc is attached to - * @arg cb callback function - * @arg arg argument to be passed to callback function + * Call a callback for each child class of a qdisc (deprecated) + * + * @deprecated Use of this function is deprecated, it does not allow + * to handle the out of memory situation that can occur. */ void rtnl_qdisc_foreach_child(struct rtnl_qdisc *qdisc, struct nl_cache *cache, void (*cb)(struct nl_object *, void *), void *arg) @@ -460,26 +458,23 @@ void rtnl_qdisc_foreach_child(struct rtnl_qdisc *qdisc, struct nl_cache *cache, } /** - * Call a callback for each filter attached to the qdisc - * @arg qdisc the parent qdisc - * @arg cache a filter cache including at least all the filters - * attached to the specified qdisc - * @arg cb callback function - * @arg arg argument to be passed to callback function + * Call a callback for each filter attached to the qdisc (deprecated) + * + * @deprecated Use of this function is deprecated, it does not allow + * to handle the out of memory situation that can occur. */ void rtnl_qdisc_foreach_cls(struct rtnl_qdisc *qdisc, struct nl_cache *cache, void (*cb)(struct nl_object *, void *), void *arg) { struct rtnl_cls *filter; - filter = rtnl_cls_alloc(); - if (!filter) + if (!(filter = rtnl_cls_alloc())) return; - rtnl_tc_set_ifindex((struct rtnl_tc *) filter, qdisc->q_ifindex); - rtnl_tc_set_parent((struct rtnl_tc *) filter, qdisc->q_parent); + rtnl_tc_set_ifindex(TC_CAST(filter), qdisc->q_ifindex); + rtnl_tc_set_parent(TC_CAST(filter), qdisc->q_parent); - nl_cache_foreach_filter(cache, (struct nl_object *) filter, cb, arg); + nl_cache_foreach_filter(cache, OBJ_CAST(filter), cb, arg); rtnl_cls_put(filter); } diff --git a/src/nl-tctree-list.c b/src/nl-tctree-list.c index 4cd5035..9407345 100644 --- a/src/nl-tctree-list.c +++ b/src/nl-tctree-list.c @@ -12,6 +12,7 @@ #include #include #include +#include #include static struct nl_sock *sock; @@ -60,6 +61,21 @@ static void print_class(struct nl_object *obj, void *arg) nl_cache_free(cls_cache); } +static void print_qdisc_childs(struct rtnl_qdisc *qdisc, void *arg) +{ + struct rtnl_tc *tc = TC_CAST(qdisc); + struct rtnl_class *filter; + + filter = nl_cli_class_alloc(); + + rtnl_tc_set_parent(TC_CAST(filter), rtnl_tc_get_handle(tc)); + rtnl_tc_set_ifindex(TC_CAST(filter), rtnl_tc_get_ifindex(tc)); + + nl_cache_foreach_filter(class_cache, OBJ_CAST(filter), &print_class, arg); + + rtnl_class_put(filter); +} + static void print_qdisc(struct nl_object *obj, void *arg) { struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj; @@ -69,7 +85,7 @@ static void print_qdisc(struct nl_object *obj, void *arg) params.dp_prefix = (int)(long) arg; nl_object_dump(obj, ¶ms); - rtnl_qdisc_foreach_child(qdisc, class_cache, &print_class, arg + 2); + print_qdisc_childs(qdisc, arg + 2); if (rtnl_cls_alloc_cache(sock, ifindex, parent, &cls_cache) < 0) return; -- cgit v1.2.1