1276 Commits

Author SHA1 Message Date
Jonathan Lennox
d947f36560 tc: Fix rounding in tc_calc_xmittime and tc_calc_xmitsize.
Currently, tc_calc_xmittime and tc_calc_xmitsize round from double to
int three times — once when they call tc_core_time2tick /
tc_core_tick2time (whose argument is int), once when those functions
return (their return value is int), and then finally when the tc_calc_*
functions return.  This leads to extremely granular and inaccurate
conversions.

As a result, for example, on my test system (where tick_in_usec=15.625,
clock_factor=1, and hz=1000000000) for a bitrate of 1Gbps, all tc htb
burst values between 0 and 999 bytes get encoded as 0 ticks; all values
between 1000 and 1999 bytes get encoded as 15 ticks (equivalent to 960
bytes); all values between 2000 and 2999 bytes as 31 ticks (1984 bytes);
etc.

The patch changes the code so these calculations are done internally in
floating-point, and only rounded to integer values when the value is
returned. It also changes tc_calc_xmittime to round its calculated value
up, rather than down, to ensure that the calculated time is actually
sufficient for the requested size.

Signed-off-by: Jonathan Lennox <jonathan.lennox@8x8.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2025-02-28 15:47:23 +00:00
Ido Schimmel
e7638a027a tc_util: Add support for 64-bit hardware packets counter
The netlink nest that carriers tc action statistics looks as follows:

[TCA_ACT_STATS]
	[TCA_STATS_BASIC]
	[TCA_STATS_BASIC_HW]

Where 'TCA_STATS_BASIC' carries the combined software and hardware
packets (32-bits) and bytes (64-bit) counters and 'TCA_STATS_BASIC_HW'
carries the hardware statistics.

When the number of packets exceeds 0xffffffff, the kernel emits the
'TCA_STATS_PKT64' attribute:

[TCA_ACT_STATS]
	[TCA_STATS_BASIC]
	[TCA_STATS_PKT64]
	[TCA_STATS_BASIC_HW]
	[TCA_STATS_PKT64]

This layout is not ideal as the only way for user space to know what
each 'TCA_STATS_PKT64' attribute carries is to check which attribute
precedes it, which is exactly what some applications are doing [1].

Do the same in iproute2 so that users with existing kernels could read
the 64-bit hardware packets counter of tc actions instead of reading the
truncated 32-bit counter.

Before:

$ tc -s filter show dev swp2 ingress
filter protocol all pref 1 flower chain 0
filter protocol all pref 1 flower chain 0 handle 0x1
  skip_sw
  in_hw in_hw_count 1
        action order 1: mirred (Egress Redirect to device swp1) stolen
        index 1 ref 1 bind 1 installed 47 sec used 23 sec
        Action statistics:
        Sent 368689092544 bytes 5760767071 pkt (dropped 0, overlimits 0 requeues 0)
        Sent software 0 bytes 0 pkt
        Sent hardware 368689092544 bytes 1465799775 pkt
        backlog 0b 0p requeues 0
        used_hw_stats immediate

Where 5760767071 - 1465799775 = 0x100000000

After:

$ tc -s filter show dev swp2 ingress
filter protocol all pref 1 flower chain 0
filter protocol all pref 1 flower chain 0 handle 0x1
  skip_sw
  in_hw in_hw_count 1
        action order 1: mirred (Egress Redirect to device swp1) stolen
        index 1 ref 1 bind 1 installed 71 sec used 47 sec
        Action statistics:
        Sent 368689092544 bytes 5760767071 pkt (dropped 0, overlimits 0 requeues 0)
        Sent software 0 bytes 0 pkt
        Sent hardware 368689092544 bytes 5760767071 pkt
        backlog 0b 0p requeues 0
        used_hw_stats immediate

[1] 006e1c6dbf

Reported-by: Joe Botha <joe@atomic.ac>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2025-02-07 21:02:08 +00:00
Stephen Hemminger
7240e0e40f Merge ssh://gitolite.kernel.org/pub/scm/network/iproute2/iproute2-next 2025-01-21 07:03:48 -08:00
Eric Dumazet
3f8c7e7c8b tc: fq: add support for TCA_FQ_OFFLOAD_HORIZON attribute
In linux-6.13, we added the ability to offload pacing on
capable devices.

tc qdisc add ... fq ... offload_horizon 100ms

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2025-01-01 01:10:30 +00:00
Stephen Hemminger
ac547ad027 flower: replace XATTR_SIZE_MAX
The flower tc parser was using XATTR_SIZE_MAX from linux/limits.h,
but this constant is intended to before extended filesystem attributes
not for TC.  Replace it with a local define.

This fixes issue on systems with musl and XATTR_SIZE_MAX is not
defined in limits.h there.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-12-12 15:22:22 -08:00
Choong Yong Liang
863c96cea4 tc: Add support for Hold/Release mechanism in TSN as per IEEE 802.1Q-2018
This commit enhances the q_taprio module by adding support for the
Hold/Release mechanism in Time-Sensitive Networking (TSN), as specified
in the IEEE 802.1Q-2018 standard.

Changes include:
- Addition of `TC_TAPRIO_CMD_SET_AND_HOLD` and `TC_TAPRIO_CMD_SET_AND_RELEASE`
cases in the `entry_cmd_to_str` function to return "H" and "R" respectively.
- Addition of corresponding string comparisons in the `str_to_entry_cmd`
function to map "H" and "R" to `TC_TAPRIO_CMD_SET_AND_HOLD` and
`TC_TAPRIO_CMD_SET_AND_RELEASE`.

The Hold/Release feature works as follows:
- Set-And-Hold-MAC (H): This command sets the gates and holds the current
configuration, preventing any further changes until a release command is
issued.
- Set-And-Release-MAC (R): This command releases the hold, allowing
subsequent gate configuration changes to take effect.

These changes ensure that the q_taprio module can correctly interpret and
handle the Hold/Release commands, aligning with the IEEE 802.1Q-2018 standard
for enhanced TSN configuration.

Signed-off-by: Choong Yong Liang <yong.liang.choong@linux.intel.com>
Signed-off-by: Jose Abreu <Jose.Abreu@synopsys.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-11-18 16:54:00 +00:00
David Ahern
2d35b775a4 Merge remote-tracking branch 'main/main' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-10-25 16:53:41 +00:00
Stephen Hemminger
95f4021b48 netem: swap transposed calloc args
Gcc with -Wextra complains about transposed args to calloc
in netem.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-10-07 09:37:24 -07:00
David Lamparter
031922c8a3 lib: utils: move over print_num from ip/
`print_num()` was born in `ip/ipaddress.c` but considering it has
nothing to do with IP addresses it should really live in `lib/utils.c`.

(I've had reason to call it from bridge/* on some random hackery.)

Signed-off-by: David Lamparter <equinox@diac24.net>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-10-05 17:48:11 +00:00
Davide Caratti
0941975dc8 tc: f_flower: add support for matching on tunnel metadata
extend TC flower for matching on tunnel metadata.

Changes since v2:
 - split uAPI changes and TC code in separate patches, as per David's request [2]

Changes since v1:
 - fix incostintent naming in explain() and in tc-flower.8 (Asbjørn)

Changes since RFC:
 - update uAPI bits to Asbjørn's most recent code [1]
 - add 'tun' prefix to all flag names (Asbjørn)
 - allow parsing 'enc_flags' multiple times, without clearing the match
   mask every time, like happens for 'ip_flags' (Asbjørn)
 - don't use "matches()" for parsing argv[]  (Stephen)
 - (hopefully) improve usage() printout (Asbjørn)
 - update man page

[1] https://lore.kernel.org/netdev/20240709163825.1210046-1-ast@fiberby.net/
[2] https://lore.kernel.org/netdev/cc73004c-9aa8-9cd3-b46e-443c0727c34d@kernel.org/

Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-08-04 15:20:32 +00:00
Maks Mishin
b06341a252 f_flower: Remove always zero checks
Expression 'ttl & ~(255 >> 0)' is always zero, because right operand
has 8 trailing zero bits, which is greater or equal than the size
of the left operand == 8 bits.

Found by RASU JSC.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
Reviewed-by: Guillaume Nault <gnault@redhat.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-07-17 16:47:57 -07:00
David Ahern
977d51cfec Merge remote-tracking branch 'main/main' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-05-03 15:40:02 +00:00
Stephen Hemminger
911c62bf9d use missing argument helper
There is a helper in utilities to handle missing argument,
but it was not being used consistently.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-04-23 09:01:46 -07:00
Michal Swiatkowski
976dca372e f_flower: implement pfcp opts
Allow adding tc filter for PFCP header.

Add support for parsing TCA_FLOWER_KEY_ENC_OPTS_PFCP.
Options are as follows: TYPE:SEID.

TYPE is a 8-bit value represented in hex and can be  1
for session header and 0 for node header. In PFCP packet
this is S flag in header.

SEID is a 64-bit session id value represented in hex.

This patch enables adding hardware filters using PFCP fields, see [1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=d823265dd45bbf14bd67aa476057108feb4143ce

Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Signed-off-by: Wojciech Drewek <wojciech.drewek@intel.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-04-23 15:34:19 +00:00
Stephen Hemminger
95c886b8e8 tc/util: remove unused argument from print_tcstats2_attr
The function doesn't use the FILE handle.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-04-21 01:45:48 +00:00
Stephen Hemminger
6879d2046b tc/police: remove unused argument to tc_print_police
FILE handle no longer used.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-04-21 01:45:38 +00:00
Stephen Hemminger
2c42df8689 tc/util: remove unused argument from print_action_control
The FILE handle is no longer used.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-04-21 01:43:52 +00:00
Stephen Hemminger
bf4022ebe6 tc/util: remove unused argument from print_tm
File argument no longer used.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-04-21 01:41:56 +00:00
Stephen Hemminger
98b7262c12 tc/u32: remove FILE argument
The pretty printing routines no longer use the file handle.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-04-21 01:12:51 +00:00
Stephen Hemminger
69d55c213d simple: support json output
Last action that never got JSON support.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-13 10:07:33 -07:00
Stephen Hemminger
af0ddbfa51 skbmod: support json in print
This tc action never got jsonized.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-13 10:07:33 -07:00
Stephen Hemminger
ba52b3d4dd pedit: log errors to stderr
The errors should bo to stderr, not to stdout.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-13 10:07:33 -07:00
Stephen Hemminger
fc4226d247 tc: support JSON for legacy stats
The extended stats already supported JSON output, add to the
legacy stats as well.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-13 10:07:33 -07:00
Stephen Hemminger
38656eeb35 tc: remove no longer used helpers
The removal of tick usage in netem, means that some of the
helper functions in tc are no longer used and can be safely removed.
Other functions can be made static.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-13 09:56:29 -07:00
Stephen Hemminger
9a6b231ea1 netem: use 64 bit value for latency and jitter
The current version of netem in iproute2 has a maximum of 4.3 seconds
because of scaled 32 bit clock values. Some users would like to be
able to use larger delays to emulate things like storage delays.

Since kernel version 4.15, netem qdisc had netlink parameters
to express wider range of delays in nanoseconds. But the iproute2
side was never updated to use them.

This does break compatibility with older kernels (4.14 and earlier).
With these out of support kernels, the latency/delay parameter
will end up being ignored.

Reported-by: Marc Blanchet <marc.blanchet@viagenie.ca>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-13 09:54:44 -07:00
Stephen Hemminger
9fb634deec tc: make exec_util arg const
The callbacks in exec_util should not be modifying underlying
qdisc operations structure.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-12 15:11:43 -07:00
Stephen Hemminger
38b0e6c120 tc: make action_util arg const
The callbacks in action_util should not be modifying underlying
qdisc operations structure.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-12 15:11:43 -07:00
Stephen Hemminger
fa740c21b4 tc: make filter_util args const
The callbacks in filter_util should not be modifying underlying
qdisc operations structure.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-12 15:11:43 -07:00
Stephen Hemminger
8576afbb89 tc: make qdisc_util arg const
The callbacks in qdisc_util should not be modifying underlying
qdisc operations structure.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-12 15:11:43 -07:00
Stephen Hemminger
ade05d59c3 Merge branch 'main' of git://git.kernel.org/pub/scm/network/iproute2/iproute2-next 2024-03-11 16:39:39 -07:00
Stephen Hemminger
88f0b157e9 tc/action: remove trailing whitespace
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-11 10:32:05 -07:00
Takanori Hirano
b8daf861a4 tc: Fix json output for f_u32
Signed-off-by: Takanori Hirano <me@hrntknr.net>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-03-04 08:20:46 -08:00
David Ahern
4306b28650 Merge remote-tracking branch 'main/main' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-02-27 04:09:35 +00:00
Takanori Hirano
4b6e97b5f3 tc: Support json option in tc-cgroup, tc-flow and tc-route
Fix json corruption when using the "-json" option in some cases

Signed-off-by: Takanori Hirano <me@hrntknr.net>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-19 10:08:56 -08:00
Takanori Hirano
bc5468c5eb tc: Change of json format in tc-fw
In the case of a process such as mapping a json to a structure,
it can be difficult if the keys have the same name but different types.
Since handle is used in hex string, change it to fw.

Signed-off-by: Takanori Hirano <me@hrntknr.net>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-19 10:08:49 -08:00
David Ahern
f900302f32 Merge remote-tracking branch 'main/main' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-02-18 17:41:39 +00:00
Stephen Hemminger
d06f6a3d17 tc: u32: check return value from snprintf
Add assertion to check for case of snprintf failing (bad format?)
or buffer getting full.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-10 16:47:25 -08:00
Stephen Hemminger
e91dfaaaea tc: drop no longer used prototype from tc_util.h
Part of the ipt removal missed this.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-10 09:48:55 -08:00
Stephen Hemminger
b958d3c25d tc: print unknown action on stderr
This is an error, and should not go to stdout.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-10 09:48:55 -08:00
Stephen Hemminger
46031294e3 tc: bpf: fix extra newline in JSON output
Don't print newline at end of bpf if in JSON mode.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-10 09:48:55 -08:00
Takanori Hirano
49a8b895ad tc: Support json option in tc-fw.
Fix json corruption when using the "-json" option in cases where tc-fw is set.

Signed-off-by: Takanori Hirano <me@hrntknr.net>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-10 09:48:55 -08:00
Stephen Hemminger
e449400508 tc: u32: errors should be printed on stderr
Don't corrupt stdout with error messages, matters if JSON is used.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-10 09:48:49 -08:00
Andrea Claudi
9cf6493cab treewide: fix typos in various comments
Fix various typos and spelling errors in some iproute2 comments.

Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-02-09 08:45:10 -08:00
Victor Nogueira
cf0eae9a9f tc: Add NLM_F_ECHO support for filters
If the user specifies this flag for a filter command the kernel will
return the command's result back to user space.
For example:

  tc -echo filter add dev lo parent ffff: protocol ip matchall action ok

  added filter dev lo parent ffff: protocol ip pref 49152 matchall chain 0

As illustrated above, the kernel will give us a pref of 491252

The same can be done for other filter commands (replace, delete, and
change). For example:

  tc -echo filter del dev lo parent ffff: pref 49152 protocol ip matchall

  deleted filter dev lo parent ffff: protocol ip pref 49152 matchall chain 0

Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-01-30 15:49:13 +00:00
Victor Nogueira
071144c0bb tc: add NLM_F_ECHO support for actions
This patch adds the -echo flag to tc command line and support for it in
tc actions. If the user specifies this flag for an action command, the
kernel will return the command's result back to user space.
For example:

  tc -echo actions add action mirred egress mirror dev lo

  total acts 0
  Added action
        action order 1: mirred (Egress Mirror to device lo) pipe
        index 10 ref 1 bind 0
        not_in_hw

As illustrated above, the kernel will give us an index of 10

The same can be done for other action commands (replace, change, and
delete). For example:

  tc -echo actions delete action mirred index 10

  total acts 0
  Deleted action
        action order 1: mirred (Egress Mirror to device lo) pipe
        index 10 ref 0 bind 0
        not_in_hw

Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-01-30 15:49:12 +00:00
Stephen Hemminger
0c3400cc8f spelling fixes
Use codespell and ispell to fix some spelling errors
in comments and README's.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-25 16:49:10 -08:00
Victor Nogueira
139a74134c m_mirred: Allow mirred to block
So far the mirred action has dealt with syntax that handles
mirror/redirection for netdev. A matching packet is redirected or mirrored
to a target netdev.

In this patch we enable mirred to mirror to a tc block as well.
IOW, the new syntax looks as follows:
... mirred <ingress | egress> <mirror | redirect> [index INDEX] < <blockid BLOCKID> | <dev <devname>> >

Examples of mirroring or redirecting to a tc block:
$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress mirror blockid 22

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 10.10.10.10/32 action mirred egress redirect blockid 22

Co-developed-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Co-developed-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-01-25 18:15:50 +00:00
Stephen Hemminger
3062aaf770 tc: better clockid handling
All clockid values not available on some older glibc versions.
Also, add some comments.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-21 09:19:19 -08:00
Stephen Hemminger
91cca2aee7 tc: unify clockid handling
There are three places in tc which all have same code for
handling clockid (copy/paste). Move it into tc_util.c.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-19 08:38:58 -08:00
Stephen Hemminger
45dc10463d remove support for iptables action
There is an open upstream kernel patch to remove ipt action from
kernel. This is corresponding iproute2 change.

 - Remove support fot ipt and xt in tc.
 - Remove no longer used header files.
 - Update man pages.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-01-08 01:44:50 +00:00