18 #include <netlink-local.h> 19 #include <netlink-tc.h> 20 #include <netlink/netlink.h> 21 #include <netlink/utils.h> 22 #include <netlink/route/link.h> 23 #include <netlink/route/tc.h> 24 #include <netlink/route/qdisc.h> 25 #include <netlink/route/class.h> 26 #include <netlink/route/classifier.h> 27 #include <netlink/route/qdisc-modules.h> 29 static void qdisc_free_data(
struct nl_object *obj)
31 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) obj;
34 tca_free_data((
struct rtnl_tca *) qdisc);
36 qops = rtnl_qdisc_lookup_ops(qdisc);
41 static int qdisc_clone(
struct nl_object *_dst,
struct nl_object *_src)
43 struct rtnl_qdisc *dst = (
struct rtnl_qdisc *) _dst;
44 struct rtnl_qdisc *src = (
struct rtnl_qdisc *) _src;
48 err = tca_clone((
struct rtnl_tca *) dst, (
struct rtnl_tca *) src);
52 qops = rtnl_qdisc_lookup_ops(src);
59 static int qdisc_dump_brief(
struct nl_object *obj,
struct nl_dump_params *p)
61 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) obj;
64 int line = tca_dump_brief((
struct rtnl_tca *) qdisc,
"qdisc", p, 0);
66 qops = rtnl_qdisc_lookup_ops(qdisc);
75 static int qdisc_dump_full(
struct nl_object *arg,
struct nl_dump_params *p)
77 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) arg;
80 int line = qdisc_dump_brief(arg, p);
82 line = tca_dump_full((
struct rtnl_tca *) qdisc, p, line);
83 dp_dump(p,
"refcnt %u ", qdisc->q_info);
85 qops = rtnl_qdisc_lookup_ops(qdisc);
93 static int qdisc_dump_stats(
struct nl_object *arg,
struct nl_dump_params *p)
95 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) arg;
98 int line = qdisc_dump_full(arg, p);
99 line = tca_dump_stats((
struct rtnl_tca *) qdisc, p, line );
102 qops = rtnl_qdisc_lookup_ops(qdisc);
114 struct rtnl_qdisc *rtnl_qdisc_alloc(
void)
119 void rtnl_qdisc_put(
struct rtnl_qdisc *qdisc)
140 void (*cb)(
struct nl_object *,
void *),
void *arg)
142 struct rtnl_class *filter;
144 filter = rtnl_class_alloc();
148 rtnl_class_set_parent(filter, qdisc->q_handle);
149 rtnl_class_set_ifindex(filter, qdisc->q_ifindex);
150 rtnl_class_set_kind(filter, qdisc->q_kind);
154 rtnl_class_put(filter);
166 void (*cb)(
struct nl_object *,
void *),
void *arg)
168 struct rtnl_cls *filter;
170 filter = rtnl_cls_alloc();
174 rtnl_cls_set_ifindex(filter, qdisc->q_ifindex);
175 rtnl_cls_set_parent(filter, qdisc->q_parent);
178 rtnl_cls_put(filter);
188 void rtnl_qdisc_set_ifindex(
struct rtnl_qdisc *qdisc,
int ifindex)
190 tca_set_ifindex((
struct rtnl_tca *) qdisc, ifindex);
193 int rtnl_qdisc_get_ifindex(
struct rtnl_qdisc *qdisc)
195 return tca_get_ifindex((
struct rtnl_tca *) qdisc);
198 void rtnl_qdisc_set_handle(
struct rtnl_qdisc *qdisc, uint32_t handle)
200 tca_set_handle((
struct rtnl_tca *) qdisc, handle);
203 uint32_t rtnl_qdisc_get_handle(
struct rtnl_qdisc *qdisc)
205 return tca_get_handle((
struct rtnl_tca *) qdisc);
208 void rtnl_qdisc_set_parent(
struct rtnl_qdisc *qdisc, uint32_t parent)
210 tca_set_parent((
struct rtnl_tca *) qdisc, parent);
213 uint32_t rtnl_qdisc_get_parent(
struct rtnl_qdisc *qdisc)
215 return tca_get_parent((
struct rtnl_tca *) qdisc);
218 void rtnl_qdisc_set_kind(
struct rtnl_qdisc *qdisc,
const char *name)
220 tca_set_kind((
struct rtnl_tca *) qdisc, name);
221 qdisc->q_ops = __rtnl_qdisc_lookup_ops(name);
224 char *rtnl_qdisc_get_kind(
struct rtnl_qdisc *qdisc)
226 return tca_get_kind((
struct rtnl_tca *) qdisc);
229 uint64_t rtnl_qdisc_get_stat(
struct rtnl_qdisc *qdisc,
232 return tca_get_stat((
struct rtnl_tca *) qdisc,
id);
252 ops = rtnl_qdisc_lookup_ops(qdisc);
263 .oo_size =
sizeof(
struct rtnl_qdisc),
264 .oo_free_data = qdisc_free_data,
265 .oo_clone = qdisc_clone,
269 .oo_compare = tca_compare,
270 .oo_id_attrs = (TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE),
Dump object in a brief one-liner.
int(* qo_dump[NL_DUMP_MAX+1])(struct rtnl_qdisc *, struct nl_dump_params *, int)
Dump callbacks.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
void rtnl_qdisc_foreach_child(struct rtnl_qdisc *qdisc, struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback for each child class of a qdisc.
void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
rtnl_tc_stats_id
TC statistics identifiers.
struct nl_msg * rtnl_qdisc_get_opts(struct rtnl_qdisc *qdisc)
Return qdisc specific options for use in TCA_OPTIONS.
void rtnl_qdisc_foreach_cls(struct rtnl_qdisc *qdisc, struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback for each filter attached to the qdisc.
int(* qo_clone)(struct rtnl_qdisc *, struct rtnl_qdisc *)
Called whenever a qdisc object needs to be cloned.
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
void(* qo_free_data)(struct rtnl_qdisc *)
Called before a Qdisc object gets destroyed.
struct nl_msg *(* qo_get_opts)(struct rtnl_qdisc *)
Must return the contents supposed to be in TCA_OPTIONS.
char * oo_name
Unique name of object type.
Dump all attributes but no statistics.
Dump all attributes including statistics.