]> git.proxmox.com Git - mirror_iproute2.git/commit
lib: Move print_rate() from tc here; modernize
authorPetr Machata <me@pmachata.org>
Sat, 5 Dec 2020 21:13:30 +0000 (22:13 +0100)
committerDavid Ahern <dsahern@gmail.com>
Wed, 9 Dec 2020 02:30:15 +0000 (02:30 +0000)
commit60265cc2264109ce832f17d502dce5965ed670d8
treedeab02e22d5c3927b194eeca7467d86ef45c2adc
parentcdd94253154a4797cb9349dff02556b1c56069f5
lib: Move print_rate() from tc here; modernize

The functions print_rate() and sprint_rate() are useful for formatting
rate-like values. The DCB tool would find these useful in the maxrate
subtool. However, the current interface to these functions uses a global
variable use_iec as a flag indicating whether 1024- or 1000-based powers
should be used when formatting the rate value. For general use, a global
variable is not a great way of passing arguments to a function. Besides, it
is unlike most other printing functions in that it deals in buffers and
ignores JSON.

Therefore make the interface to print_rate() explicit by converting use_iec
to an ordinary parameter. Since the interface changes anyway, convert it to
follow the pattern of other json_print functions (except for the
now-explicit use_iec parameter). Move to json_print.c.

Add a wrapper to tc, so that all the call sites do not need to repeat the
use_iec global variable argument, and convert all call sites.

In q_cake.c, the conversion is not straightforward due to usage of a macro
that is shared across numerous data types. Simply hand-roll the
corresponding code, which seems better than making an extra helper for one
call site.

Drop sprint_rate() now that everybody just uses print_rate().

Signed-off-by: Petr Machata <me@pmachata.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
13 files changed:
include/json_print.h
lib/json_print.c
tc/m_police.c
tc/q_cake.c
tc/q_cbq.c
tc/q_fq.c
tc/q_hfsc.c
tc/q_htb.c
tc/q_mqprio.c
tc/q_netem.c
tc/q_tbf.c
tc/tc_util.c
tc/tc_util.h