Commit Graph

40 Commits

Author SHA1 Message Date
Matteo Croce
8589eb4efd treewide: refactor help messages
Every tool in the iproute2 package have one or more function to show
an help message to the user. Some of these functions print the help
line by line with a series of printf call, e.g. ip/xfrm_state.c does
60 fprintf calls.
If we group all the calls to a single one and just concatenate strings,
we save a lot of libc calls and thus object size. The size difference
of the compiled binaries calculated with bloat-o-meter is:

        ip/ip:
        add/remove: 0/0 grow/shrink: 5/15 up/down: 103/-4796 (-4693)
        Total: Before=672591, After=667898, chg -0.70%
        ip/rtmon:
        add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-54 (-54)
        Total: Before=48879, After=48825, chg -0.11%
        tc/tc:
        add/remove: 0/2 grow/shrink: 31/10 up/down: 882/-6133 (-5251)
        Total: Before=351912, After=346661, chg -1.49%
        bridge/bridge:
        add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-459 (-459)
        Total: Before=70502, After=70043, chg -0.65%
        misc/lnstat:
        add/remove: 0/1 grow/shrink: 1/0 up/down: 48/-486 (-438)
        Total: Before=9960, After=9522, chg -4.40%
        tipc/tipc:
        add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-62 (-44)
        Total: Before=79182, After=79138, chg -0.06%

While at it, indent some strings which were starting at column 0,
and use tabs where possible, to have a consistent style across helps.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
2019-05-20 14:35:07 -07:00
Stephen Hemminger
a38fadf401 tc/police: make print_police static
print_police function only used by m_police.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2018-11-19 11:42:44 -08:00
David Ahern
e9625d6aea Merge branch 'iproute2-master' into iproute2-next
Conflicts:
	bridge/mdb.c

Updated bridge/bridge.c per removal of check_if_color_enabled by commit
1ca4341d2c ("color: disable color when json output is requested")

Signed-off-by: David Ahern <dsahern@gmail.com>
2018-03-13 17:48:10 -07:00
Davide Caratti
75ef7b18d2 tc: fix parsing of the control action
If the user didn't specify any control action, don't pop the command line
arguments: otherwise, parsing of the next argument (tipically the 'index'
keyword) results in an error, causing the following 'tc-testing' failures:

 Test a6d6: Add skbedit action with index
 Test 38f3: Delete skbedit action
 Test a568: Add action with ife type
 Test b983: Add action without ife type
 Test 7d50: Add skbmod action to set destination mac
 Test 9b29: Add skbmod action to set source mac
 Test e93a: Delete an skbmod action

Also, add missing parse for 'ok' control action to m_police, to fix the
following 'tc-testing' failure:

 Test 8dd5: Add police action with control ok

tested with:
 # ./tdc.py

test results:
 all tests ok using kernel 4.16-rc2, except 9aa8 "Get a single skbmod
 action from a list" (which is failing also before this commit)

Fixes: 3572e01a09 ("tc: util: Don't call NEXT_ARG_FWD() in __parse_action_control()")
Cc: Michal Privoznik <mprivozn@redhat.com>
Cc: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2018-03-04 09:01:38 -08:00
Serhey Popovych
c14f9d92ee treewide: Use addattr_nest()/addattr_nest_end() to handle nested attributes
We have helper routines to support nested attribute addition into
netlink buffer: use them instead of open coding.

Use addattr_nest_compat()/addattr_nest_compat_end() where appropriate.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
2018-02-02 15:01:09 -08:00
Stephen Hemminger
913352fe54 drop unneeded include of syslog.h
Only arpd uses syslog

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2017-11-12 16:22:36 -08:00
Jiri Pirko
d19f72f789 tc/actions: introduce support for goto chain action
Allow user to set control action "goto" with filter chain index as
a parameter.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
2017-05-22 13:31:51 -07:00
Jiri Pirko
e67aba5595 tc: actions: add helpers to parse and print control actions
Each tc action is terminated by a control action. Each action parses and
prints then intividually. Introduce set of helpers and allow to share
this code.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
2017-05-22 13:31:51 -07:00
Roman Mashak
3de88c4b47 police: improve usage message
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2016-08-29 10:54:40 -07:00
Roman Mashak
cef49e514a police: add extra space to improve police result printing
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2016-08-29 10:54:40 -07:00
Phil Sutter
7093200611 tc: util: No need for action_n2a() to be reentrant
This allows to remove some buffers here and there. While at it, make it
return a const value.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-07-25 08:10:43 -07:00
Phil Sutter
69f5aff63c tc: use action_a2n() everywhere
Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-07-25 08:10:43 -07:00
Phil Sutter
d17b136f7d Use C99 style initializers everywhere
This big patch was compiled by vimgrepping for memset calls and changing
to C99 initializer if applicable. One notable exception is the
initialization of union bpf_attr in tc/tc_bpf.c: changing it would break
for older gcc versions (at least <=3.4.6).

Calls to memset for struct rtattr pointer fields for parse_rtattr*()
were just dropped since they are not needed.

The changes here allowed the compiler to discover some unused variables,
so get rid of them, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
2016-07-20 12:05:24 -07:00
Jamal Hadi Salim
ead954cbd4 tc action policer: enable timestamp display
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2016-05-31 13:03:13 -07:00
Stephen Hemminger
e6263c8583 tc: action result is u32
In kernel action result is u32 not int in netlink messages.
2016-05-31 12:22:45 -07:00
Jamal Hadi Salim
45c6837911 tc action policer: Avoid nonsensical input
The user must at least specify a choice of the token bucket or
ewma policing or late binding index. TB policing requires at minimal
a rate and burst.

In addition fix formatting issues (80 chars etc).

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2016-05-31 12:16:45 -07:00
Stephen Hemminger
32a121cba2 tc: code cleanup
Use checkpatch to fix whitespace and other style issues.
2016-03-21 11:48:36 -07:00
Jamal Hadi Salim
cacba03b10 Remove unnecessary debug statement
Reported-by: Seann Herdejurgen <seann@herdejurgen.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2014-05-28 16:54:26 -07:00
Jamal Hadi Salim
4bfb21ca20 policer - retire old syntax
attached.

cheers,
jamal
commit b82057d9ec851a8aba8a295b959190ef5098f330
Author: Jamal Hadi Salim <jhs@mojatatu.com>
Date:   Sat Dec 21 17:00:11 2013 -0500

    After a decade of trying to deprecate the old policer syntax,
    I believe it is time to kill it. The kernel build option for old
    policer is gone for at least 5 years now (although backward
    compatibility is still there). Being backward compatible meant
    hijacking the keyword "action" and was obstructing policies like:

    tc filter add dev eth0 parent ffff: protocol ip pref 10 \
    u32 match ip protocol 1 0xff flowid 1:10 \
    action skbedit mark 1 \
    action police rate 10kbit burst 10k pipe \
    action skbedit mark 2 \
    action police rate 20kbit burst 20k pipe \
    action action mirred egress mirror dev dummy0

    Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2013-12-28 10:57:34 -08:00
Jesper Dangaard Brouer
3e92ff522a linklayer interface between kernel and tc/userspace
This iproute2 tc patch is connected to the kernel
 - commit 8a8e3d84b17 (net_sched: restore "linklayer atm" handling)

The rate table calculated by tc, have gotten replaced in the kernel
and is no-longer used for lookups.

This happened in kernel release v3.8 caused by kernel
 - commit 56b765b79 ("htb: improved accuracy at high rates").
This change unfortunately caused breakage of tc overhead and
linklayer parameters.

 Kernel overhead handling got fixed in kernel v3.10 by
 - commit 01cb71d2d47 (net_sched: restore "overhead xxx" handling)

 Kernel linklayer handling got fixed in kernel v3.11 by
 - commit 8a8e3d84b17 (net_sched: restore "linklayer atm" handling)

The linklayer fix introduced a struct change, that allow the linklayer
attribute to be transferred between tc and kernel. This patch make use
of this linklayer attribute.

The linklayer setting is transfer to the kernel.  And linklayer
setting received from the kernel is printed with a prefixed
"linklayer" when listing current configuration.  The default
TC_LINKLAYER_ETHERNET is only printed in detailed output mode.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2013-09-03 08:21:24 -07:00
Stephen Hemminger
d1f28cf181 ip: make local functions static 2013-02-12 11:38:35 -08:00
Stephen Hemminger
ff24746cca Convert to use rta_getattr_ functions
User new functions (inspired by libmnl) to do type safe access
of routeing attributes
2012-04-10 08:47:55 -07:00
Jesper Dangaard Brouer
292f29b42c ATM cell alignment.
Introducing the function that does the ATM cell alignment, and
modifying tc_calc_rtable() to use this based upon a linklayer
parameter.

Modified from original to use constants from atm.h and
fix all the usages of rtable in same patch.

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
2008-04-17 10:04:31 -07:00
Stephen Hemminger
1a5bd776a2 In police, fix uninitialized "overhead" variable.
Bug introduced by myself in an earlier patch series.

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
2008-04-17 09:12:38 -07:00
Jesper Dangaard Brouer
f71f75f39b police, implement overhead parameter parsing.
For police, implement overhead parameter parsing.

The change is ABI (Application Binary Interface) backward compatible
with older kernels, but will first have effect from kernel 2.6.24.

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com>
2008-04-01 11:27:42 -07:00
Stephen Hemminger
ef1d6f97ec Revert "TC action parsing bug fix"
This reverts commit 720a2e8d99.

After further investigation it seems clear to me that reverting the
commit 720a2e8d990707749b2... is the correct thing to do, since the real
fix for the problem this commit was supposed to fix was instead fixed in
commit c29391c7c68f031e246c...

Whatever you specify after a u32 police you will now get a syntax error,
and according to "tc filter add u32 help" there are several things that
you are supposed to be able to specify after a police.

So, Steven, please revert 720a2e8d990707749b2...
2008-01-02 16:34:58 -08:00
Jesper Dangaard Brouer
d5f46f9cc3 Cleanup: tc_calc_rtable().
Change tc_calc_rtable() to take a tc_ratespec struct as an
argument. (cell_log still needs to be passed on as a parameter,
because -1 indicate that the cell_log needs to be computed by the
function.).

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com>
2007-12-31 11:08:04 -08:00
Patrick McHardy
c29391c7c6 Bug fix tc action drop
>>That command is from a script that used to work with iproute2-ss020116
>>(2002!), which had the following in tc/m_police.c:
>>
>>210     } else if (strcmp(*argv, "action") == 0) {
>>211             NEXT_ARG();
>>212             if (get_police_result(&p.action, &presult, *argv)) {
>>
>>I don't know when that bit was dropped, but it used to be there. :-)
>
>
>
> Indeed, I missed that. I'll fix up the patch ..

OK this patch fixes parsing of "action ...". I've removed
the erroring on unknown arguments again since in that case
the caller should continue parsing.
2007-08-22 10:01:10 -07:00
Patrick McHardy
720a2e8d99 TC action parsing bug fix
>
> Is it a bug that:
>
>   # tc filter add dev eth0 parent 1: protocol ip prio 0 handle 0xfffffff
>     fw police rate 1 burst 1 mpu 0 mtu 1 action drop
>                                          ^^^^^^^^^^^
> creates a filter that looks like:
>
>   # tc filter ls dev eth0
>   filter parent 1: protocol ip pref 49152 fw
>   filter parent 1: protocol ip pref 49152 fw handle 0xfffffff police 0x1
>   rate 0bit burst 0b mtu 1b action reclassify
>                             ^^^^^^^^^^^^^^^^^
>   ref -543190236 bind 4
>
> (which reclassifies and thus lets 0xfffffff-marked packets through).
>
> I'm pretty sure this used to work under 2.4.x (though I no longer have a
> 2.4 box to test with), but it hasn't worked on any of the 2.6.x kernels
> I've tried (with both iproute2-ss060323 and 070710).

Good catch. It seems this is merely a parsing error, iproute doesn't
have an "action" parameter and aborts parsing, so it uses the default
value of "RECLASSIFY". It never had this parameter, so this patch
removes it from the help text and makes it return an error.
2007-08-22 10:00:41 -07:00
Patrick McHardy
76dc0aa28f Introduce tc_calc_xmitsize and use where appropriate
[IPROUTE]: Introduce tc_calc_xmitsize and use where appropriate

Add tc_calc_xmitsize() as complement to tc_calc_xmittime(), which calculates
the size that can be transmitted at a given rate during a given time.

Replace all expressions of the form "size = rate*tc_core_tick2usec(time))/1000000"
by tc_calc_xmitsize() calls.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-03-13 14:42:15 -07:00
Stephen Hemminger
ae665a522b Remove trailing whitespace
Go through source files and remove all trailing whitespace

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-12-05 10:10:22 -08:00
Jamal Hadi Salim
ebf32083e0 First part of cleaning up the help output of actions.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-08-08 12:10:08 -07:00
6!tgraf
14ee9e6159 Use parse_rtattr_nested
(Logical change 1.129)
2005-01-18 22:11:58 +00:00
6!tgraf
1b52a7622e Use NLMSG_TAIL
(Logical change 1.127)
2005-01-18 01:24:18 +00:00
net[shemminger]!shemminger
0284dcde32 Import patch iproute2-typo-fixes-1.diff
(Logical change 1.94)
2004-10-07 18:56:07 +00:00
net[shemminger]!kaber
95812b56a5 : prevent tc crashes
(Logical change 1.81)
2004-09-28 18:35:49 +00:00
osdl.net!shemminger
f2f99e2eef no longer need xstats stub
(Logical change 1.77)
2004-08-31 17:45:21 +00:00
osdl.net!shemminger
2373fde9b0 new stuff from jamal.
(Logical change 1.66)
2004-08-13 23:54:55 +00:00
osdl.org!shemminger
aba5acdfdb (Logical change 1.3) 2004-04-15 20:56:59 +00:00
osdl.org!shemminger
86fdf0e47b Initial revision 2004-04-15 20:56:59 +00:00