tc: shared block support
Subsystems (2)
v12 cover tc: shared block support
From: Jiri Pirko <[email protected]>
Kernel allows to share all filters between qdiscs with use of shared block.
Example:
block number 22. "22" is just an identification:
$ tc qdisc add dev ens7 ingress_block 22 ingress
^^^^^^^^^^^^^^^^
$ tc qdisc add dev ens8 ingress_block 22 ingress
^^^^^^^^^^^^^^^^If we don't specify "block" command line option, no shared block would be created:
$ tc qdisc add dev ens9 ingress
Now if we list the qdiscs, we will see the block index in the output:
$ tc qdisc qdisc ingress ffff: dev ens7 parent ffff:fff1 ingress_block 22 qdisc ingress ffff: dev ens8 parent ffff:fff1 ingress_block 22 qdisc ingress ffff: dev ens9 parent ffff:fff1
To make is more visual, the situation looks like this:
ens7 ingress qdisc ens7 ingress qdisc
| |
| |
+----------> block 22 <----------+Unlimited number of qdiscs may share the same block.
Block sharing is also supported for clsact qdisc:
$ tc qdisc add dev ens10 ingress_block 23 egress_block 24 clsact $ tc qdisc show dev ens10 qdisc clsact ffff: dev ens10 parent ffff:fff1 ingress_block 23 egress_block 24
We can add filter using the block index:
$ tc filter add block 22 protocol ip pref 25 flower dst_ip 192.168.0.0/16 action drop
Note we cannot use the qdisc for filter manipulations of shared blocks:
$ tc filter add dev ens8 ingress protocol ip pref 1 flower dst_ip 192.168.100.2 action drop Error: This filter block is shared. Please use the block index to manipulate the filters.
We will see the same output if we list filters for ingress qdisc of ens7 and ens8, also for the block 22:
$ tc filter show block 22 filter protocol ip pref 25 flower chain 0 filter protocol ip pref 25 flower chain 0 handle 0x1 ...
$ tc filter show dev ens7 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
$ tc filter show dev ens8 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
---v11->v12:
- separate iproute2 patchset, kernel part is merged
- original patch 1 is removed as the header changes are already in iproute2 code
- patch 1:
- fixed return type of tc_qdisc_block_exists
- removed 0 checks for block in tc_qdisc_block_exists
- rever xmas tree variables in tc_qdisc_block_exists
- patch 2
- fixes error message when both dev and block are on the command line
---
Note that if you want me to change the ">=" vs "==" thing, I will do it. But I think that it is a global iproute2 thing and should be changed in a separate patch/patchset.
Jiri Pirko (3):
tc: introduce tc_qdisc_block_exists helper
tc: introduce support for block-handle for filter operations
tc: implement ingress/egress block index attributes for qdiscs
man/man8/tc.8 | 24 ++++++++++++- tc/tc_filter.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++---------- tc/tc_qdisc.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tc/tc_util.h | 2 ++ 4 files changed, 210 insertions(+), 18 deletions(-)
Signature · 1 line
2.14.3
PATCH v12 1/3 tc: introduce tc_qdisc_block_exists helper
From: Jiri Pirko <[email protected]>
This hepler used qdisc dump to list all qdisc and find if block index in question is used by any of them. That means the block with specified index exists.
---v11->v12:
- fixed return type of tc_qdisc_block_exists
- removed 0 checks for block in tc_qdisc_block_exists
- rever xmas tree variables in tc_qdisc_block_exists
--- tc/tc_qdisc.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tc/tc_util.h | 2 ++ 2 files changed, 63 insertions(+)
tc/tc_qdisc.c +61 -0
@@ -412,3 +412,64 @@ int do_qdisc(int argc, char **argv)fprintf (stderr,"Command \"%s\" is unknown, try \"tc qdisc help\".\n" , *argv);return -1 ; } + +struct tc_qdisc_block_exists_ctx { +__u32 block_index; +bool found; +}; + +static int tc_qdisc_block_exists_cb (const struct sockaddr_nl *who, +struct nlmsghdr *n,void *arg) +{ +struct tc_qdisc_block_exists_ctx *ctx = arg; +struct tcmsg *t =NLMSG_DATA (n); +struct rtattr *tb[TCA_MAX +1 ]; +int len = n->nlmsg_len; + +if (n->nlmsg_type !=RTM_NEWQDISC ) +return 0 ; + + len -=NLMSG_LENGTH (sizeof (*t)); +if (len <0 ) +return -1 ; + +parse_rtattr (tb,TCA_MAX ,TCA_RTA (t), len); + +if (tb[TCA_KIND ] ==NULL ) +return -1 ; + +if (tb[TCA_INGRESS_BLOCK ] && +RTA_PAYLOAD (tb[TCA_INGRESS_BLOCK ]) >=sizeof (__u32)) { +__u32 block =rta_getattr_u32 (tb[TCA_INGRESS_BLOCK ]); + +if (block == ctx->block_index) + ctx->found = true; + } + +if (tb[TCA_EGRESS_BLOCK ] && +RTA_PAYLOAD (tb[TCA_EGRESS_BLOCK ]) >=sizeof (__u32)) { +__u32 block =rta_getattr_u32 (tb[TCA_EGRESS_BLOCK ]); + +if (block == ctx->block_index) + ctx->found = true; + } +return 0 ; +} + +bool tc_qdisc_block_exists (__u32 block_index) +{ +struct tc_qdisc_block_exists_ctx ctx = { .block_index = block_index }; +struct tcmsg t = { .tcm_family =AF_UNSPEC }; + +if (rtnl_dump_request (&rth,RTM_GETQDISC , &t,sizeof (t)) <0 ) { +perror ("Cannot send dump request" ); +return false; + } + +if (rtnl_dump_filter (&rth, tc_qdisc_block_exists_cb, &ctx) <0 ) { +perror ("Dump terminated\n" ); +return false; + } + +return ctx.found; +}
tc/tc_util.h +2 -0
@@ -132,4 +132,6 @@ int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);int cls_names_init (char *path);void cls_names_uninit (void ); +bool tc_qdisc_block_exists (__u32 block_index); +#endif
Signature · 1 line
2.14.3
PATCH v12 2/3 tc: introduce support for block-handle for filter operations
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
So far, qdisc was the only handle that could be used to manipulate filters. Kernel added support for using block to manipulate it. So add the support to use block index to manipulate filters. The magic TCM_IFINDEX_MAGIC_BLOCK indicates the block index is in use.
---v11->v12:
- fixes error message when both dev and block are on the command line
--- man/man8/tc.8 | 18 ++++++++++ tc/tc_filter.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 106 insertions(+), 17 deletions(-)
man/man8/tc.8 +18 -0
@@ -41,6 +41,19 @@ tc \- show / manipulate traffic control settings .B flowid \fIflow-id\fR +.B tc +.RI "[ " OPTIONS " ]" +.B filter [ add | change | replace | delete | get ] block +\fIBLOCK_INDEX\fR +.B [ handle \fIfilter-id\fR ] +.B protocol +\fIprotocol\fR +.B prio +\fIpriority\fR filtertype +[ filtertype specific parameters ] +.B flowid +\fIflow-id\fR + .B tc .RI "[ " OPTIONS " ]" .RI "[ " FORMAT " ]"
@@ -58,6 +71,11 @@ tc \- show / manipulate traffic control settings .RI "[ " OPTIONS " ]" .B filter show dev \fIDEV\fR +.P +.B tc +.RI "[ " OPTIONS " ]" +.B filter show block +\fIBLOCK_INDEX\fR .P .ti 8
tc/tc_filter.c +88 -17
187 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v12 3/3 tc: implement ingress/egress block index attributes for qdiscs
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
During qdisc creation it is possible to specify shared block for bot ingress and egress. Pass this values to kernel according to the command line options.
--- man/man8/tc.8 | 6 +++++- tc/tc_qdisc.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-)
man/man8/tc.8 +5 -1
@@ -11,7 +11,11 @@ tc \- show / manipulate traffic control settings \fIqdisc-id\fR .B | root ] .B [ handle -\fIqdisc-id\fR ] qdisc +\fIqdisc-id\fR ] +.B [ ingress_block +\fIBLOCK_INDEX\fR ] +.B [ egress_block +\fIBLOCK_INDEX\fR ] qdisc [ qdisc specific parameters ] .P
tc/tc_qdisc.c +36 -0
@@ -31,6 +31,7 @@ static int usage(void)fprintf (stderr," [ handle QHANDLE ] [ root | ingress | clsact | parent CLASSID ]\n" );fprintf (stderr," [ estimator INTERVAL TIME_CONSTANT ]\n" );fprintf (stderr," [ stab [ help | STAB_OPTIONS] ]\n" ); +fprintf (stderr," [ ingress_block BLOCK_INDEX ] [ egress_block BLOCK_INDEX ]\n" );fprintf (stderr," [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n" );fprintf (stderr,"\n" );fprintf (stderr," tc qdisc show [ dev STRING ] [ ingress | clsact ] [ invisible ]\n" );
@@ -61,6 +62,8 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv) .n.nlmsg_type = cmd, .t.tcm_family = AF_UNSPEC, }; +__u32 ingress_block =0 ; +__u32 egress_block =0 ;while (argc >0 ) {if (strcmp (*argv,"dev" ) ==0 ) {
@@ -121,6 +124,14 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)if (parse_size_table (&argc, &argv, &stab.szopts) <0 )return -1 ;continue ; + }else if (matches (*argv,"ingress_block" ) ==0 ) { +NEXT_ARG (); +if (get_u32 (&ingress_block, *argv,0 ) || !ingress_block) +invarg ("invalid ingress block index value" , *argv); + }else if (matches (*argv,"egress_block" ) ==0 ) { +NEXT_ARG (); +if (get_u32 (&egress_block, *argv,0 ) || !egress_block) +invarg ("invalid egress block index value" , *argv); }else if (matches (*argv,"help" ) ==0 ) {usage (); }else {
@@ -138,6 +149,13 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)if (est.ewma_log)addattr_l (&req.n,sizeof (req),TCA_RATE , &est,sizeof (est)); +if (ingress_block) +addattr32 (&req.n,sizeof (req), +TCA_INGRESS_BLOCK , ingress_block); +if (egress_block) +addattr32 (&req.n,sizeof (req), +TCA_EGRESS_BLOCK , egress_block); +if (q) {if (q->parse_qopt) {if (q->parse_qopt (q, argc, argv, &req.n, d))
@@ -270,6 +288,24 @@ int print_qdisc(const struct sockaddr_nl *who, (rta_getattr_u8(tb[TCA_HW_OFFLOAD])))print_bool (PRINT_ANY ,"offloaded" ,"offloaded " , true); +if (tb[TCA_INGRESS_BLOCK ] && +RTA_PAYLOAD (tb[TCA_INGRESS_BLOCK ]) >=sizeof (__u32)) { +__u32 block =rta_getattr_u32 (tb[TCA_INGRESS_BLOCK ]); + +if (block) +print_uint (PRINT_ANY ,"ingress_block" , +"ingress_block %u " , block); + } + +if (tb[TCA_EGRESS_BLOCK ] && +RTA_PAYLOAD (tb[TCA_EGRESS_BLOCK ]) >=sizeof (__u32)) { +__u32 block =rta_getattr_u32 (tb[TCA_EGRESS_BLOCK ]); + +if (block) +print_uint (PRINT_ANY ,"egress_block" , +"egress_block %u " , block); + } +/* pfifo_fast is generic enough to warrant the hardcoding --JHS */ if (strcmp ("pfifo_fast" ,RTA_DATA (tb[TCA_KIND ])) ==0 ) q =get_qdisc_kind ("prio" );
Signature · 1 line
2.14.3
Quoted 81 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Kernel allows to share all filters between qdiscs with use of shared block.
Example:
block number 22. "22" is just an identification:
$ tc qdisc add dev ens7 ingress_block 22 ingress ^^^^^^^^^^^^^^^^ $ tc qdisc add dev ens8 ingress_block 22 ingress ^^^^^^^^^^^^^^^^If we don't specify "block" command line option, no shared block would be created:
$ tc qdisc add dev ens9 ingressNow if we list the qdiscs, we will see the block index in the output:
$ tc qdisc qdisc ingress ffff: dev ens7 parent ffff:fff1 ingress_block 22 qdisc ingress ffff: dev ens8 parent ffff:fff1 ingress_block 22 qdisc ingress ffff: dev ens9 parent ffff:fff1To make is more visual, the situation looks like this:
ens7 ingress qdisc ens7 ingress qdisc
| | | | +----------> block 22 <----------+Unlimited number of qdiscs may share the same block.
Block sharing is also supported for clsact qdisc:
$ tc qdisc add dev ens10 ingress_block 23 egress_block 24 clsact $ tc qdisc show dev ens10 qdisc clsact ffff: dev ens10 parent ffff:fff1 ingress_block 23 egress_block 24We can add filter using the block index:
$ tc filter add block 22 protocol ip pref 25 flower dst_ip 192.168.0.0/16 action dropNote we cannot use the qdisc for filter manipulations of shared blocks:
$ tc filter add dev ens8 ingress protocol ip pref 1 flower dst_ip 192.168.100.2 action drop Error: This filter block is shared. Please use the block index to manipulate the filters.We will see the same output if we list filters for ingress qdisc of ens7 and ens8, also for the block 22:
$ tc filter show block 22 filter protocol ip pref 25 flower chain 0 filter protocol ip pref 25 flower chain 0 handle 0x1 ...$ tc filter show dev ens7 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...$ tc filter show dev ens8 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...---
v11->v12:
- separate iproute2 patchset, kernel part is merged
- original patch 1 is removed as the header changes are already in iproute2 code
- patch 1:
- fixed return type oftc_qdisc_block_exists
- removed 0 checks for block intc_qdisc_block_exists
- rever xmas tree variables intc_qdisc_block_exists
- patch 2
- fixes error message when both dev and block are on the command line
Quoted 4 lines
---
Note that if you want me to change the ">=" vs "==" thing, I will do it. But I think that it is a global iproute2 thing and should be changed in a separate patch/patchset.
IMO, it should be checking for ==. If the payload is not of an expected length, then either the kernel and userspace differ on the API or the parsing has gone off the rails.
FWIW, all of the the 'RTA_PAYLOAD >=' checks are under tc/.
Series applied to iproute2-next. Thanks, Jiri.