Home | History | Annotate | Download | only in route

Lines Matching refs:tc

2  * lib/route/tc.c		Traffic Control
14 * @defgroup tc Traffic Control
19 #include <netlink-private/tc.h>
24 #include <netlink/route/tc.h>
25 #include <netlink-private/route/tc-api.h>
61 int rtnl_tc_msg_parse(struct nlmsghdr *n, struct rtnl_tc *tc)
70 tc->ce_msgtype = n->nlmsg_type;
80 rtnl_tc_set_kind(tc, kind);
83 tc->tc_family = tm->tcm_family;
84 tc->tc_ifindex = tm->tcm_ifindex;
85 tc->tc_handle = tm->tcm_handle;
86 tc->tc_parent = tm->tcm_parent;
87 tc->tc_info = tm->tcm_info;
89 tc->ce_mask |= (TCA_ATTR_FAMILY | TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE|
93 tc->tc_opts = nl_data_alloc_attr(tb[TCA_OPTIONS]);
94 if (!tc->tc_opts)
96 tc->ce_mask |= TCA_ATTR_OPTS;
111 tc->tc_stats[RTNL_TC_BYTES] = bs->bytes;
112 tc->tc_stats[RTNL_TC_PACKETS] = bs->packets;
119 tc->tc_stats[RTNL_TC_RATE_BPS] = re->bps;
120 tc->tc_stats[RTNL_TC_RATE_PPS] = re->pps;
127 tc->tc_stats[RTNL_TC_QLEN] = q->qlen;
128 tc->tc_stats[RTNL_TC_BACKLOG] = q->backlog;
129 tc->tc_stats[RTNL_TC_DROPS] = q->drops;
130 tc->tc_stats[RTNL_TC_REQUEUES] = q->requeues;
131 tc->tc_stats[RTNL_TC_OVERLIMITS] = q->overlimits;
134 tc->ce_mask |= TCA_ATTR_STATS;
137 tc->tc_xstats = nl_data_alloc_attr(tbs[TCA_STATS_APP]);
138 if (tc->tc_xstats == NULL)
146 tc->tc_stats[RTNL_TC_BYTES] = st->bytes;
147 tc->tc_stats[RTNL_TC_PACKETS] = st->packets;
148 tc->tc_stats[RTNL_TC_RATE_BPS] = st->bps;
149 tc->tc_stats[RTNL_TC_RATE_PPS] = st->pps;
150 tc->tc_stats[RTNL_TC_QLEN] = st->qlen;
151 tc->tc_stats[RTNL_TC_BACKLOG] = st->backlog;
152 tc->tc_stats[RTNL_TC_DROPS] = st->drops;
153 tc->tc_stats[RTNL_TC_OVERLIMITS]= st->overlimits;
155 tc->ce_mask |= TCA_ATTR_STATS;
160 tc->tc_xstats = nl_data_alloc_attr(tb[TCA_XSTATS]);
161 if (tc->tc_xstats == NULL)
163 tc->ce_mask |= TCA_ATTR_XSTATS;
167 ops = rtnl_tc_get_ops(tc);
169 void *data = rtnl_tc_data(tc);
174 err = ops->to_msg_parser(tc, data);
182 if ((link = rtnl_link_get(link_cache, tc->tc_ifindex))) {
183 rtnl_tc_set_link(tc, link);
193 int rtnl_tc_msg_build(struct rtnl_tc *tc, int type, int flags,
200 .tcm_ifindex = tc->tc_ifindex,
201 .tcm_handle = tc->tc_handle,
202 .tcm_parent = tc->tc_parent,
213 if (tc->ce_mask & TCA_ATTR_KIND)
214 NLA_PUT_STRING(msg, TCA_KIND, tc->tc_kind);
216 ops = rtnl_tc_get_ops(tc);
219 void *data = rtnl_tc_data(tc);
225 if ((err = ops->to_msg_fill(tc, data, msg)) < 0)
229 } else if ((err = ops->to_msg_fill_raw(tc, data, msg)) < 0)
257 * @arg tc traffic control object
261 * index defines the network device which this tc object is attached to.
265 void rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
268 rtnl_link_put(tc->tc_link);
269 tc->tc_link = NULL;
270 tc->ce_mask &= ~TCA_ATTR_LINK;
272 tc->tc_ifindex = ifindex;
273 tc->ce_mask |= TCA_ATTR_IFINDEX;
278 * @arg tc traffic control object
280 int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
282 return tc->tc_ifindex;
287 * @arg tc traffic control object
297 void rtnl_tc_set_link(struct rtnl_tc *tc, struct rtnl_link *link)
299 rtnl_link_put(tc->tc_link);
307 tc->tc_link = link;
308 tc->tc_ifindex = link->l_index;
309 tc->ce_mask |= TCA_ATTR_LINK | TCA_ATTR_IFINDEX;
314 * @arg tc traffic control object
318 * if a link cache was available while parsing the tc object. This
320 * the tc object. It will _not_ look up the link by itself.
328 struct rtnl_link *rtnl_tc_get_link(struct rtnl_tc *tc)
330 if (tc->tc_link) {
331 nl_object_get(OBJ_CAST(tc->tc_link));
332 return tc->tc_link;
340 * @arg tc traffic control object
346 * the tc object is attached to if the link has been assigned via
351 void rtnl_tc_set_mtu(struct rtnl_tc *tc, uint32_t mtu)
353 tc->tc_mtu = mtu;
354 tc->ce_mask |= TCA_ATTR_MTU;
359 * @arg tc traffic control object
366 uint32_t rtnl_tc_get_mtu(struct rtnl_tc *tc)
368 if (tc->ce_mask & TCA_ATTR_MTU)
369 return tc->tc_mtu;
370 else if (tc->ce_mask & TCA_ATTR_LINK)
371 return tc->tc_link->l_mtu;
378 * @arg tc traffic control object
386 void rtnl_tc_set_mpu(struct rtnl_tc *tc, uint32_t mpu)
388 tc->tc_mpu = mpu;
389 tc->ce_mask |= TCA_ATTR_MPU;
394 * @arg tc traffic control object
398 uint32_t rtnl_tc_get_mpu(struct rtnl_tc *tc)
400 return tc->tc_mpu;
405 * @arg tc traffic control object
415 void rtnl_tc_set_overhead(struct rtnl_tc *tc, uint32_t overhead)
417 tc->tc_overhead = overhead;
418 tc->ce_mask |= TCA_ATTR_OVERHEAD;
423 * @arg tc traffic control object
427 uint32_t rtnl_tc_get_overhead(struct rtnl_tc *tc)
429 return tc->tc_overhead;
434 * @arg tc traffic control object
438 * This value is typically derived from the link this tc object is attached
443 void rtnl_tc_set_linktype(struct rtnl_tc *tc, uint32_t type)
445 tc->tc_linktype = type;
446 tc->ce_mask |= TCA_ATTR_LINKTYPE;
451 * @arg tc traffic control object
458 uint32_t rtnl_tc_get_linktype(struct rtnl_tc *tc)
460 if (tc->ce_mask & TCA_ATTR_LINKTYPE)
461 return tc->tc_linktype;
462 else if (tc->ce_mask & TCA_ATTR_LINK)
463 return tc->tc_link->l_arptype;
470 * @arg tc traffic control object
473 void rtnl_tc_set_handle(struct rtnl_tc *tc, uint32_t id)
475 tc->tc_handle = id;
476 tc->ce_mask |= TCA_ATTR_HANDLE;
481 * @arg tc traffic control object
483 uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
485 return tc->tc_handle;
490 * @arg tc traffic control object
494 void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
496 tc->tc_parent = parent;
497 tc->ce_mask |= TCA_ATTR_PARENT;
502 * @arg tc traffic control object
504 uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
506 return tc->tc_parent;
511 * @arg tc traffic control object
512 * @arg kind name of the tc object type
516 int rtnl_tc_set_kind(struct rtnl_tc *tc, const char *kind)
518 if (tc->ce_mask & TCA_ATTR_KIND)
521 strncpy(tc->tc_kind, kind, sizeof(tc->tc_kind) - 1);
522 tc->ce_mask |= TCA_ATTR_KIND;
525 rtnl_tc_data(tc);
532 * @arg tc traffic control object
536 char *rtnl_tc_get_kind(struct rtnl_tc *tc)
538 if (tc->ce_mask & TCA_ATTR_KIND)
539 return tc->tc_kind;
546 * @arg tc traffic control object
551 uint64_t rtnl_tc_get_stat(struct rtnl_tc *tc, enum rtnl_tc_stat id)
556 return tc->tc_stats[id];
680 * @arg tc traffic control object
691 int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *spec,
694 uint32_t mtu = rtnl_tc_get_mtu(tc);
695 uint32_t linktype = rtnl_tc_get_linktype(tc);
699 spec->rs_mpu = rtnl_tc_get_mpu(tc);
700 spec->rs_overhead = rtnl_tc_get_overhead(tc);
730 * @name TC implementation of cache functions
735 struct rtnl_tc *tc = TC_CAST(obj);
738 rtnl_link_put(tc->tc_link);
739 nl_data_free(tc->tc_opts);
740 nl_data_free(tc->tc_xstats);
742 if (tc->tc_subdata) {
743 ops = rtnl_tc_get_ops(tc);
745 ops->to_free_data(tc, nl_data_get(tc->tc_subdata));
747 nl_data_free(tc->tc_subdata);
795 static int tc_dump(struct rtnl_tc *tc, enum nl_dump_type type,
800 void *data = rtnl_tc_data(tc);
802 type_ops = tc_type_ops[tc->tc_type];
804 type_ops->tt_dump[type](tc, p);
806 ops = rtnl_tc_get_ops(tc);
808 ops->to_dump[type](tc, data, p);
818 struct rtnl_tc *tc = TC_CAST(obj);
824 type_ops = tc_type_ops[tc->tc_type];
828 nl_dump(p, "%s ", tc->tc_kind);
832 rtnl_link_i2name(link_cache, tc->tc_ifindex,
835 nl_dump(p, "dev %u ", tc->tc_ifindex);
838 rtnl_tc_handle2str(tc->tc_handle, buf, sizeof(buf)));
841 rtnl_tc_handle2str(tc->tc_parent, buf, sizeof(buf)));
843 tc_dump(tc, NL_DUMP_LINE, p);
852 struct rtnl_tc *tc = TC_CAST(obj);
854 rtnl_tc_dump_line(OBJ_CAST(tc), p);
858 if (tc->ce_mask & TCA_ATTR_MTU)
859 nl_dump(p, " mtu %u", tc->tc_mtu);
861 if (tc->ce_mask & TCA_ATTR_MPU)
862 nl_dump(p, " mpu %u", tc->tc_mpu);
864 if (tc->ce_mask & TCA_ATTR_OVERHEAD)
865 nl_dump(p, " overhead %u", tc->tc_overhead);
867 if (!tc_dump(tc, NL_DUMP_DETAILS, p))
874 struct rtnl_tc *tc = TC_CAST(obj);
878 rtnl_tc_dump_details(OBJ_CAST(tc), p);
886 res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_BYTES], &unit);
891 tc->tc_stats[RTNL_TC_PACKETS],
892 tc->tc_stats[RTNL_TC_DROPS],
893 tc->tc_stats[RTNL_TC_OVERLIMITS],
894 tc->tc_stats[RTNL_TC_QLEN],
895 tc->tc_stats[RTNL_TC_BACKLOG]);
897 res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_RATE_BPS], &unit);
904 nl_dump_line(p, fmt, res, unit, tc->tc_stats[RTNL_TC_RATE_PPS]);
906 tc_dump(tc, NL_DUMP_LINE, p);
946 struct rtnl_tc_ops *rtnl_tc_get_ops(struct rtnl_tc *tc)
948 if (!tc->tc_ops)
949 tc->tc_ops = rtnl_tc_lookup_ops(tc->tc_type, tc->tc_kind);
951 return tc->tc_ops;
964 * the first tc module registers. Putting this in a
999 * @arg tc traffic control object
1004 * @return Pointer to private tc data or NULL if allocation failed.
1006 void *rtnl_tc_data(struct rtnl_tc *tc)
1008 if (!tc->tc_subdata) {
1011 if (!tc->tc_ops) {
1012 if (!tc->tc_kind)
1015 if (!rtnl_tc_get_ops(tc))
1019 if (!(size = tc->tc_ops->to_size))
1022 if (!(tc->tc_subdata = nl_data_alloc(NULL, size)))
1026 return nl_data_get(tc->tc_subdata);
1031 * @arg tc traffic control object
1036 * type matches, the private tc object data is returned. If type
1041 * @return Pointer to private tc data or NULL if type mismatches.
1043 void *rtnl_tc_data_check(struct rtnl_tc *tc, struct rtnl_tc_ops *ops)
1045 if (tc->tc_ops != ops) {
1049 "tc object %p used in %s context but is of type %s",
1050 tc, ops->to_kind, tc->tc_ops->to_kind);
1056 return rtnl_tc_data(tc);