Commit 8f2d6ec
committed
Support for tc-actions
# Summary of feature
This is easiest to explain by way of iproute2.
`tc` allows actions to be created independently of filters.
Once created, these actions may then
1. be associated with _zero or more_ filters,
2. live updated (and updates will be seen by all filters using that action),
3. be deleted (only after all filters using that action have been deleted).
For example, consider the following :
```bash
for i in x y z; do
ip link add dev "$i" type dummy
tc qdisc add dev "$i" clsact
done
tc actions add action mirred egress redirect dev y
tc actions add action gact drop
```
At this point, we could
1. list the `mirred` actions
```bash
$ tc actions list action mirred
total acts 1
action order 0: mirred (Egress Redirect to device y) stolen
index 1 ref 1 bind 0
not_in_hw
used_hw_stats disabled
```
2. list the `gact` actions
```bash
$ tc actions list action gact
total acts 1
action order 0: gact action drop
random type none pass val 0
index 1 ref 1 bind 0
not_in_hw
used_hw_stats disabled
```
3. create any number of filters using either or both of these actions by index
```bash
tc filter add dev x ingress pref 1000 proto ip flower dst_ip 8.8.8.8 action mirred index 1
tc filter add dev z ingress pref 1000 proto ip flower dst_ip 8.8.8.8 action mirred index 1 action gact index 1
```
4. display those filters as normal (with per-action statistics)
```bash
$ tc -s filter show dev z ingress
filter protocol ip pref 1000 flower chain 0
filter protocol ip pref 1000 flower chain 0 handle 0x1
eth_type ipv4
dst_ip 8.8.8.8
not_in_hw
action order 1: mirred (Egress Redirect to device y) stolen
index 1 ref 3 bind 2 installed 599 sec used 599 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
action order 2: gact action drop
random type none pass val 0
index 1 ref 2 bind 1 installed 599 sec used 599 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
```
5. centrally update those actions (e.g., change `drop` to `pass`)
```bash
$ tc actions change action gact pass index 1
$ tc -s filter show dev z ingress
filter protocol ip pref 1000 flower chain 0
filter protocol ip pref 1000 flower chain 0 handle 0x1
eth_type ipv4
dst_ip 8.8.8.8
not_in_hw
action order 1: mirred (Egress Redirect to device y) stolen
index 1 ref 3 bind 2 installed 838 sec used 838 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
action order 2: gact action pass
random type none pass val 0
index 1 ref 2 bind 1 installed 838 sec used 838 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
```
6. attempts to delete those actions while in use will be rejected (albeit with a buggy error message from `iproute2`/`tc`)
```bash
$ tc actions delete action gact index 1
Error: Failed to delete TC action.
We have an error talking to the kernel
Command "action" is unknown, try "tc actions help"
```
7. Removing all filters that use an action will allow the action to be deleted
```bash
$ tc filter del dev z ingress pref 1000
$ tc actions delete action gact index 1
$ tc filter del dev x ingress pref 1000
$ tc actions delete action mirred index 1
```1 parent 186747e commit 8f2d6ec
File tree
16 files changed
+1611
-242
lines changed- src
- tc
- actions
- tests
- tests
16 files changed
+1611
-242
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | 4 | | |
9 | 5 | | |
10 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
11 | 10 | | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
294 | 309 | | |
295 | 310 | | |
296 | 311 | | |
| |||
348 | 363 | | |
349 | 364 | | |
350 | 365 | | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
351 | 369 | | |
352 | 370 | | |
353 | 371 | | |
| |||
460 | 478 | | |
461 | 479 | | |
462 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
463 | 493 | | |
464 | 494 | | |
465 | 495 | | |
| |||
528 | 558 | | |
529 | 559 | | |
530 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
531 | 564 | | |
532 | 565 | | |
533 | 566 | | |
| |||
598 | 631 | | |
599 | 632 | | |
600 | 633 | | |
601 | | - | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
602 | 640 | | |
603 | 641 | | |
604 | 642 | | |
| |||
658 | 696 | | |
659 | 697 | | |
660 | 698 | | |
661 | | - | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
662 | 705 | | |
663 | 706 | | |
664 | 707 | | |
| |||
0 commit comments