2
* lib/route/tc.c Traffic Control
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation version 2.1
9
* Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
14
* @defgroup tc Traffic Control
18
#include <netlink-local.h>
19
#include <netlink-tc.h>
20
#include <netlink/netlink.h>
21
#include <netlink/utils.h>
22
#include <netlink/route/rtnl.h>
23
#include <netlink/route/link.h>
24
#include <netlink/route/tc.h>
25
#include <netlink/route/tc-api.h>
29
static struct nl_list_head tc_ops_list[__RTNL_TC_TYPE_MAX];
30
static struct rtnl_tc_type_ops *tc_type_ops[__RTNL_TC_TYPE_MAX];
32
static struct nla_policy tc_policy[TCA_MAX+1] = {
33
[TCA_KIND] = { .type = NLA_STRING,
34
.maxlen = TCKINDSIZ },
35
[TCA_STATS] = { .minlen = sizeof(struct tc_stats) },
36
[TCA_STATS2] = { .type = NLA_NESTED },
39
int tca_parse(struct nlattr **tb, int maxattr, struct rtnl_tc *g,
40
struct nla_policy *policy)
43
if (g->ce_mask & TCA_ATTR_OPTS)
44
return nla_parse(tb, maxattr,
45
(struct nlattr *) g->tc_opts->d_data,
46
g->tc_opts->d_size, policy);
48
/* Ugly but tb[] must be in a defined state even if no
49
* attributes can be found. */
50
memset(tb, 0, sizeof(struct nlattr *) * (maxattr + 1));
55
static struct nla_policy tc_stats2_policy[TCA_STATS_MAX+1] = {
56
[TCA_STATS_BASIC] = { .minlen = sizeof(struct gnet_stats_basic) },
57
[TCA_STATS_RATE_EST] = { .minlen = sizeof(struct gnet_stats_rate_est) },
58
[TCA_STATS_QUEUE] = { .minlen = sizeof(struct gnet_stats_queue) },
61
int rtnl_tc_msg_parse(struct nlmsghdr *n, struct rtnl_tc *tc)
63
struct rtnl_tc_ops *ops;
64
struct nlattr *tb[TCA_MAX + 1];
69
tc->ce_msgtype = n->nlmsg_type;
71
err = nlmsg_parse(n, sizeof(*tm), tb, TCA_MAX, tc_policy);
75
if (tb[TCA_KIND] == NULL)
76
return -NLE_MISSING_ATTR;
78
nla_strlcpy(kind, tb[TCA_KIND], sizeof(kind));
79
rtnl_tc_set_kind(tc, kind);
82
tc->tc_family = tm->tcm_family;
83
tc->tc_ifindex = tm->tcm_ifindex;
84
tc->tc_handle = tm->tcm_handle;
85
tc->tc_parent = tm->tcm_parent;
86
tc->tc_info = tm->tcm_info;
88
tc->ce_mask |= (TCA_ATTR_FAMILY | TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE|
89
TCA_ATTR_PARENT | TCA_ATTR_INFO);
91
if (tb[TCA_OPTIONS]) {
92
tc->tc_opts = nl_data_alloc_attr(tb[TCA_OPTIONS]);
95
tc->ce_mask |= TCA_ATTR_OPTS;
99
struct nlattr *tbs[TCA_STATS_MAX + 1];
101
err = nla_parse_nested(tbs, TCA_STATS_MAX, tb[TCA_STATS2],
106
if (tbs[TCA_STATS_BASIC]) {
107
struct gnet_stats_basic *bs;
109
bs = nla_data(tbs[TCA_STATS_BASIC]);
110
tc->tc_stats[RTNL_TC_BYTES] = bs->bytes;
111
tc->tc_stats[RTNL_TC_PACKETS] = bs->packets;
114
if (tbs[TCA_STATS_RATE_EST]) {
115
struct gnet_stats_rate_est *re;
117
re = nla_data(tbs[TCA_STATS_RATE_EST]);
118
tc->tc_stats[RTNL_TC_RATE_BPS] = re->bps;
119
tc->tc_stats[RTNL_TC_RATE_PPS] = re->pps;
122
if (tbs[TCA_STATS_QUEUE]) {
123
struct gnet_stats_queue *q;
125
q = nla_data(tbs[TCA_STATS_QUEUE]);
126
tc->tc_stats[RTNL_TC_QLEN] = q->qlen;
127
tc->tc_stats[RTNL_TC_BACKLOG] = q->backlog;
128
tc->tc_stats[RTNL_TC_DROPS] = q->drops;
129
tc->tc_stats[RTNL_TC_REQUEUES] = q->requeues;
130
tc->tc_stats[RTNL_TC_OVERLIMITS] = q->overlimits;
133
tc->ce_mask |= TCA_ATTR_STATS;
135
if (tbs[TCA_STATS_APP]) {
136
tc->tc_xstats = nl_data_alloc_attr(tbs[TCA_STATS_APP]);
137
if (tc->tc_xstats == NULL)
143
struct tc_stats *st = nla_data(tb[TCA_STATS]);
145
tc->tc_stats[RTNL_TC_BYTES] = st->bytes;
146
tc->tc_stats[RTNL_TC_PACKETS] = st->packets;
147
tc->tc_stats[RTNL_TC_RATE_BPS] = st->bps;
148
tc->tc_stats[RTNL_TC_RATE_PPS] = st->pps;
149
tc->tc_stats[RTNL_TC_QLEN] = st->qlen;
150
tc->tc_stats[RTNL_TC_BACKLOG] = st->backlog;
151
tc->tc_stats[RTNL_TC_DROPS] = st->drops;
152
tc->tc_stats[RTNL_TC_OVERLIMITS]= st->overlimits;
154
tc->ce_mask |= TCA_ATTR_STATS;
158
if (tb[TCA_XSTATS]) {
159
tc->tc_xstats = nl_data_alloc_attr(tb[TCA_XSTATS]);
160
if (tc->tc_xstats == NULL)
162
tc->ce_mask |= TCA_ATTR_XSTATS;
166
ops = rtnl_tc_get_ops(tc);
167
if (ops && ops->to_msg_parser) {
168
void *data = rtnl_tc_data(tc);
173
err = ops->to_msg_parser(tc, data);
181
int rtnl_tc_msg_build(struct rtnl_tc *tc, int type, int flags,
182
struct nl_msg **result)
185
struct rtnl_tc_ops *ops;
186
struct tcmsg tchdr = {
187
.tcm_family = AF_UNSPEC,
188
.tcm_ifindex = tc->tc_ifindex,
189
.tcm_handle = tc->tc_handle,
190
.tcm_parent = tc->tc_parent,
192
int err = -NLE_MSGSIZE;
194
msg = nlmsg_alloc_simple(type, flags);
198
if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0)
199
goto nla_put_failure;
201
if (tc->ce_mask & TCA_ATTR_KIND)
202
NLA_PUT_STRING(msg, TCA_KIND, tc->tc_kind);
204
ops = rtnl_tc_get_ops(tc);
205
if (ops && ops->to_msg_fill) {
207
void *data = rtnl_tc_data(tc);
209
if (!(opts = nla_nest_start(msg, TCA_OPTIONS)))
210
goto nla_put_failure;
212
if ((err = ops->to_msg_fill(tc, data, msg)) < 0)
213
goto nla_put_failure;
215
nla_nest_end(msg, opts);
226
void tca_set_kind(struct rtnl_tc *t, const char *kind)
228
strncpy(t->tc_kind, kind, sizeof(t->tc_kind) - 1);
229
t->ce_mask |= TCA_ATTR_KIND;
241
* Set interface index of traffic control object
242
* @arg tc traffic control object
243
* @arg ifindex interface index.
245
* Sets the interface index of a traffic control object. The interface
246
* index defines the network device which this tc object is attached to.
247
* This function will overwrite any network device assigned with previous
248
* calls to rtnl_tc_set_ifindex() or rtnl_tc_set_link().
250
void rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
252
/* Obsolete possible old link reference */
253
rtnl_link_put(tc->tc_link);
255
tc->ce_mask &= ~TCA_ATTR_LINK;
257
tc->tc_ifindex = ifindex;
258
tc->ce_mask |= TCA_ATTR_IFINDEX;
262
* Return interface index of traffic control object
263
* @arg tc traffic control object
265
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
267
return tc->tc_ifindex;
271
* Set link of traffic control object
272
* @arg tc traffic control object
273
* @arg link link object
275
* Sets the link of a traffic control object. This function serves
276
* the same purpose as rtnl_tc_set_ifindex() but due to the continued
277
* allowed access to the link object it gives it the possibility to
278
* retrieve sane default values for the the MTU and the linktype.
279
* Always prefer this function over rtnl_tc_set_ifindex() if you can
280
* spare to have an additional link object around.
282
void rtnl_tc_set_link(struct rtnl_tc *tc, struct rtnl_link *link)
284
rtnl_link_put(tc->tc_link);
289
nl_object_get(OBJ_CAST(link));
291
tc->tc_ifindex = link->l_index;
292
tc->ce_mask |= TCA_ATTR_LINK | TCA_ATTR_IFINDEX;
296
* Set the Maximum Transmission Unit (MTU) of traffic control object
297
* @arg tc traffic control object
298
* @arg mtu largest packet size expected
300
* Sets the MTU of a traffic control object. Not all traffic control
301
* objects will make use of this but it helps while calculating rate
302
* tables. This value is typically derived directly from the link
303
* the tc object is attached to if the link has been assigned via
304
* rtnl_tc_set_link(). It is usually not necessary to set the MTU
305
* manually, this function is provided to allow overwriting the derived
308
void rtnl_tc_set_mtu(struct rtnl_tc *tc, uint32_t mtu)
311
tc->ce_mask |= TCA_ATTR_MTU;
315
* Return the MTU of traffic control object
316
* @arg tc traffic control object
318
* Returns the MTU of a traffic control object which has been set via:
319
* -# User specified value set via rtnl_tc_set_mtu()
320
* -# Dervied from link set via rtnl_tc_set_link()
321
* -# Fall back to default: ethernet = 1600
323
uint32_t rtnl_tc_get_mtu(struct rtnl_tc *tc)
325
if (tc->ce_mask & TCA_ATTR_MTU)
327
else if (tc->ce_mask & TCA_ATTR_LINK)
328
return tc->tc_link->l_mtu;
330
return 1600; /* default to ethernet */
334
* Set the Minimum Packet Unit (MPU) of a traffic control object
335
* @arg tc traffic control object
336
* @arg mpu minimum packet size expected
338
* Sets the MPU of a traffic contorl object. It specifies the minimum
339
* packet size to ever hit this traffic control object. Not all traffic
340
* control objects will make use of this but it helps while calculating
343
void rtnl_tc_set_mpu(struct rtnl_tc *tc, uint32_t mpu)
346
tc->ce_mask |= TCA_ATTR_MPU;
350
* Return the Minimum Packet Unit (MPU) of a traffic control object
351
* @arg tc traffic control object
353
* @return The MPU previously set via rtnl_tc_set_mpu() or 0.
355
uint32_t rtnl_tc_get_mpu(struct rtnl_tc *tc)
361
* Set per packet overhead of a traffic control object
362
* @arg tc traffic control object
363
* @arg overhead overhead per packet in bytes
365
* Sets the per packet overhead in bytes occuring on the link not seen
366
* by the kernel. This value can be used to correct size calculations
367
* if the packet size on the wire does not match the packet sizes seen
368
* in the network stack. Not all traffic control objects will make use
369
* this but it helps while calculating accurate packet sizes in the
372
void rtnl_tc_set_overhead(struct rtnl_tc *tc, uint32_t overhead)
374
tc->tc_overhead = overhead;
375
tc->ce_mask |= TCA_ATTR_OVERHEAD;
379
* Return per packet overhead of a traffic control object
380
* @arg tc traffic control object
382
* @return The overhead previously set by rtnl_tc_set_overhead() or 0.
384
uint32_t rtnl_tc_get_overhead(struct rtnl_tc *tc)
386
return tc->tc_overhead;
390
* Set the linktype of a traffic control object
391
* @arg tc traffic control object
392
* @arg type type of link (e.g. ARPHRD_ATM, ARPHRD_ETHER)
394
* Overwrites the type of link this traffic control object is attached to.
395
* This value is typically derived from the link this tc object is attached
396
* if the link has been assigned via rtnl_tc_set_link(). It is usually not
397
* necessary to set the linktype manually. This function is provided to
398
* allow overwriting the linktype.
400
void rtnl_tc_set_linktype(struct rtnl_tc *tc, uint32_t type)
402
tc->tc_linktype = type;
403
tc->ce_mask |= TCA_ATTR_LINKTYPE;
407
* Return the linktype of a traffic control object
408
* @arg tc traffic control object
410
* Returns the linktype of the link the traffic control object is attached to:
411
* -# User specified value via rtnl_tc_set_linktype()
412
* -# Value derived from link set via rtnl_tc_set_link()
413
* -# Default fall-back: ARPHRD_ETHER
415
uint32_t rtnl_tc_get_linktype(struct rtnl_tc *tc)
417
if (tc->ce_mask & TCA_ATTR_LINKTYPE)
418
return tc->tc_linktype;
419
else if (tc->ce_mask & TCA_ATTR_LINK)
420
return tc->tc_link->l_arptype;
422
return ARPHRD_ETHER; /* default to ethernet */
426
* Set identifier of traffic control object
427
* @arg tc traffic control object
428
* @arg id unique identifier
430
void rtnl_tc_set_handle(struct rtnl_tc *tc, uint32_t id)
433
tc->ce_mask |= TCA_ATTR_HANDLE;
437
* Return identifier of a traffic control object
438
* @arg tc traffic control object
440
uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
442
return tc->tc_handle;
446
* Set the parent identifier of a traffic control object
447
* @arg tc traffic control object
448
* @arg parent identifier of parent traffif control object
451
void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
453
tc->tc_parent = parent;
454
tc->ce_mask |= TCA_ATTR_PARENT;
458
* Return parent identifier of a traffic control object
459
* @arg tc traffic control object
461
uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
463
return tc->tc_parent;
467
* Define the type of traffic control object
468
* @arg tc traffic control object
469
* @arg kind name of the tc object type
471
* @return 0 on success or a negative error code
473
int rtnl_tc_set_kind(struct rtnl_tc *tc, const char *kind)
475
if (tc->ce_mask & TCA_ATTR_KIND)
478
strncpy(tc->tc_kind, kind, sizeof(tc->tc_kind) - 1);
479
tc->ce_mask |= TCA_ATTR_KIND;
481
/* Force allocation of data */
488
* Return kind of traffic control object
489
* @arg tc traffic control object
491
* @return Kind of traffic control object or NULL if not set.
493
char *rtnl_tc_get_kind(struct rtnl_tc *tc)
495
if (tc->ce_mask & TCA_ATTR_KIND)
502
* Return value of a statistical counter of a traffic control object
503
* @arg tc traffic control object
504
* @arg id identifier of statistical counter
506
* @return Value of requested statistic counter or 0.
508
uint64_t rtnl_tc_get_stat(struct rtnl_tc *tc, enum rtnl_tc_stat id)
510
if (id < 0 || id > RTNL_TC_STATS_MAX)
513
return tc->tc_stats[id];
524
* Calculate time required to transmit buffer at a specific rate
525
* @arg bufsize Size of buffer to be transmited in bytes.
526
* @arg rate Transmit rate in bytes per second.
528
* Calculates the number of micro seconds required to transmit a
529
* specific buffer at a specific transmit rate.
532
* txtime=\frac{bufsize}{rate}10^6
535
* @return Required transmit time in micro seconds.
537
int rtnl_tc_calc_txtime(int bufsize, int rate)
541
tx_time_secs = (double) bufsize / (double) rate;
543
return tx_time_secs * 1000000.;
547
* Calculate buffer size able to transmit in a specific time and rate.
548
* @arg txtime Available transmit time in micro seconds.
549
* @arg rate Transmit rate in bytes per second.
551
* Calculates the size of the buffer that can be transmitted in a
552
* specific time period at a specific transmit rate.
555
* bufsize=\frac{{txtime} \times {rate}}{10^6}
558
* @return Size of buffer in bytes.
560
int rtnl_tc_calc_bufsize(int txtime, int rate)
564
bufsize = (double) txtime * (double) rate;
566
return bufsize / 1000000.;
570
* Calculate the binary logarithm for a specific cell size
571
* @arg cell_size Size of cell, must be a power of two.
572
* @return Binary logirhtm of cell size or a negative error code.
574
int rtnl_tc_calc_cell_log(int cell_size)
578
for (i = 0; i < 32; i++)
579
if ((1 << i) == cell_size)
595
* align_to_atm() and adjust_size() derived/coped from iproute2 source.
599
* The align to ATM cells is used for determining the (ATM) SAR
600
* alignment overhead at the ATM layer. (SAR = Segmentation And
601
* Reassembly). This is for example needed when scheduling packet on
602
* an ADSL connection. Note that the extra ATM-AAL overhead is _not_
603
* included in this calculation. This overhead is added in the kernel
604
* before doing the rate table lookup, as this gives better precision
605
* (as the table will always be aligned for 48 bytes).
606
* --Hawk, d.7/11-2004. <hawk@diku.dk>
608
static unsigned int align_to_atm(unsigned int size)
611
cells = size / ATM_CELL_PAYLOAD;
612
if ((size % ATM_CELL_PAYLOAD) > 0)
615
linksize = cells * ATM_CELL_SIZE; /* Use full cell size to add ATM tax */
619
static unsigned int adjust_size(unsigned int size, unsigned int mpu,
627
return align_to_atm(size);
636
* Compute a transmission time lookup table
637
* @arg tc traffic control object
638
* @arg spec Rate specification
639
* @arg dst Destination buffer of RTNL_TC_RTABLE_SIZE uint32_t[].
641
* Computes a table of RTNL_TC_RTABLE_SIZE entries specyfing the
642
* transmission times for various packet sizes, e.g. the transmission
643
* time for a packet of size \c pktsize could be looked up:
645
* txtime = table[pktsize >> log2(mtu)];
648
int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *spec,
651
uint32_t mtu = rtnl_tc_get_mtu(tc);
652
uint32_t linktype = rtnl_tc_get_linktype(tc);
653
uint8_t cell_log = spec->rs_cell_log;
654
unsigned int size, i;
656
spec->rs_mpu = rtnl_tc_get_mpu(tc);
657
spec->rs_overhead = rtnl_tc_get_overhead(tc);
662
if (cell_log == UINT8_MAX) {
664
* cell_log not specified, calculate it. It has to specify the
665
* minimum number of rshifts required to break the MTU to below
666
* RTNL_TC_RTABLE_SIZE.
669
while ((mtu >> cell_log) >= RTNL_TC_RTABLE_SIZE)
673
for (i = 0; i < RTNL_TC_RTABLE_SIZE; i++) {
674
size = adjust_size((i + 1) << cell_log, spec->rs_mpu, linktype);
675
dst[i] = rtnl_tc_calc_txtime(size, spec->rs_rate);
678
spec->rs_cell_align = -1;
679
spec->rs_cell_log = cell_log;
687
* @name TC implementation of cache functions
690
void rtnl_tc_free_data(struct nl_object *obj)
692
struct rtnl_tc *tc = TC_CAST(obj);
693
struct rtnl_tc_ops *ops;
695
rtnl_link_put(tc->tc_link);
696
nl_data_free(tc->tc_opts);
697
nl_data_free(tc->tc_xstats);
699
if (tc->tc_subdata) {
700
ops = rtnl_tc_get_ops(tc);
701
if (ops && ops->to_free_data)
702
ops->to_free_data(tc, nl_data_get(tc->tc_subdata));
704
nl_data_free(tc->tc_subdata);
708
int rtnl_tc_clone(struct nl_object *dstobj, struct nl_object *srcobj)
710
struct rtnl_tc *dst = TC_CAST(dstobj);
711
struct rtnl_tc *src = TC_CAST(srcobj);
712
struct rtnl_tc_ops *ops;
715
dst->tc_link = (struct rtnl_link *)
716
nl_object_clone(OBJ_CAST(src->tc_link));
722
dst->tc_opts = nl_data_clone(src->tc_opts);
727
if (src->tc_xstats) {
728
dst->tc_xstats = nl_data_clone(src->tc_xstats);
733
if (src->tc_subdata) {
734
if (!(dst->tc_subdata = nl_data_clone(src->tc_subdata))) {
739
ops = rtnl_tc_get_ops(src);
740
if (ops && ops->to_clone) {
741
void *a = rtnl_tc_data(dst), *b = rtnl_tc_data(src);
748
return ops->to_clone(a, b);
754
static int tc_dump(struct rtnl_tc *tc, enum nl_dump_type type,
755
struct nl_dump_params *p)
757
struct rtnl_tc_type_ops *type_ops;
758
struct rtnl_tc_ops *ops;
759
void *data = rtnl_tc_data(tc);
761
type_ops = tc_type_ops[tc->tc_type];
762
if (type_ops && type_ops->tt_dump[type])
763
type_ops->tt_dump[type](tc, p);
765
ops = rtnl_tc_get_ops(tc);
766
if (ops && ops->to_dump[type]) {
767
ops->to_dump[type](tc, data, p);
774
void rtnl_tc_dump_line(struct nl_object *obj, struct nl_dump_params *p)
776
struct rtnl_tc_type_ops *type_ops;
777
struct rtnl_tc *tc = TC_CAST(obj);
778
struct nl_cache *link_cache;
783
type_ops = tc_type_ops[tc->tc_type];
784
if (type_ops && type_ops->tt_dump_prefix)
785
nl_dump(p, "%s ", type_ops->tt_dump_prefix);
787
nl_dump(p, "%s ", tc->tc_kind);
789
if ((link_cache = nl_cache_mngt_require("route/link"))) {
790
nl_dump(p, "dev %s ",
791
rtnl_link_i2name(link_cache, tc->tc_ifindex,
794
nl_dump(p, "dev %u ", tc->tc_ifindex);
797
rtnl_tc_handle2str(tc->tc_handle, buf, sizeof(buf)));
799
nl_dump(p, "parent %s",
800
rtnl_tc_handle2str(tc->tc_parent, buf, sizeof(buf)));
802
tc_dump(tc, NL_DUMP_LINE, p);
806
void rtnl_tc_dump_details(struct nl_object *obj, struct nl_dump_params *p)
808
struct rtnl_tc *tc = TC_CAST(obj);
810
rtnl_tc_dump_line(OBJ_CAST(tc), p);
812
nl_dump_line(p, " ");
814
if (tc->ce_mask & TCA_ATTR_MTU)
815
nl_dump(p, " mtu %u", tc->tc_mtu);
817
if (tc->ce_mask & TCA_ATTR_MPU)
818
nl_dump(p, " mpu %u", tc->tc_mpu);
820
if (tc->ce_mask & TCA_ATTR_OVERHEAD)
821
nl_dump(p, " overhead %u", tc->tc_overhead);
823
if (!tc_dump(tc, NL_DUMP_DETAILS, p))
824
nl_dump(p, "no options");
828
void rtnl_tc_dump_stats(struct nl_object *obj, struct nl_dump_params *p)
830
struct rtnl_tc *tc = TC_CAST(obj);
834
rtnl_tc_dump_details(OBJ_CAST(tc), p);
836
strcpy(fmt, " %7.2f %s %10u %10u %10u %10u %10u\n");
839
" Stats: bytes packets drops overlimits" \
842
res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_BYTES], &unit);
846
nl_dump_line(p, fmt, res, unit,
847
tc->tc_stats[RTNL_TC_PACKETS],
848
tc->tc_stats[RTNL_TC_DROPS],
849
tc->tc_stats[RTNL_TC_OVERLIMITS],
850
tc->tc_stats[RTNL_TC_QLEN],
851
tc->tc_stats[RTNL_TC_BACKLOG]);
853
res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_RATE_BPS], &unit);
855
strcpy(fmt, " %7.2f %s/s%9u pps");
860
nl_dump_line(p, fmt, res, unit, tc->tc_stats[RTNL_TC_RATE_PPS]);
862
tc_dump(tc, NL_DUMP_LINE, p);
866
int rtnl_tc_compare(struct nl_object *aobj, struct nl_object *bobj,
867
uint32_t attrs, int flags)
869
struct rtnl_tc *a = TC_CAST(aobj);
870
struct rtnl_tc *b = TC_CAST(bobj);
873
#define TC_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, TCA_ATTR_##ATTR, a, b, EXPR)
875
diff |= TC_DIFF(HANDLE, a->tc_handle != b->tc_handle);
876
diff |= TC_DIFF(PARENT, a->tc_parent != b->tc_parent);
877
diff |= TC_DIFF(IFINDEX, a->tc_ifindex != b->tc_ifindex);
878
diff |= TC_DIFF(KIND, strcmp(a->tc_kind, b->tc_kind));
891
struct rtnl_tc_ops *rtnl_tc_lookup_ops(enum rtnl_tc_type type, const char *kind)
893
struct rtnl_tc_ops *ops;
895
nl_list_for_each_entry(ops, &tc_ops_list[type], to_list)
896
if (!strcmp(kind, ops->to_kind))
902
struct rtnl_tc_ops *rtnl_tc_get_ops(struct rtnl_tc *tc)
905
tc->tc_ops = rtnl_tc_lookup_ops(tc->tc_type, tc->tc_kind);
911
* Register a traffic control module
912
* @arg ops traffic control module operations
914
int rtnl_tc_register(struct rtnl_tc_ops *ops)
919
* Initialiation hack, make sure list is initialized when
920
* the first tc module registers. Putting this in a
921
* separate __init would required correct ordering of init
927
for (i = 0; i < __RTNL_TC_TYPE_MAX; i++)
928
nl_init_list_head(&tc_ops_list[i]);
933
if (!ops->to_kind || ops->to_type > RTNL_TC_TYPE_MAX)
936
if (rtnl_tc_lookup_ops(ops->to_type, ops->to_kind))
939
nl_list_add_tail(&ops->to_list, &tc_ops_list[ops->to_type]);
945
* Unregister a traffic control module
946
* @arg ops traffic control module operations
948
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
950
nl_list_del(&ops->to_list);
953
void *rtnl_tc_data(struct rtnl_tc *tc)
955
if (!tc->tc_subdata) {
962
if (!rtnl_tc_get_ops(tc))
966
if (!(size = tc->tc_ops->to_size))
969
if (!(tc->tc_subdata = nl_data_alloc(NULL, size)))
973
return nl_data_get(tc->tc_subdata);
976
void rtnl_tc_type_register(struct rtnl_tc_type_ops *ops)
978
if (ops->tt_type > RTNL_TC_TYPE_MAX)
981
tc_type_ops[ops->tt_type] = ops;
984
void rtnl_tc_type_unregister(struct rtnl_tc_type_ops *ops)
986
if (ops->tt_type > RTNL_TC_TYPE_MAX)
989
tc_type_ops[ops->tt_type] = NULL;