Commit Graph

55 Commits

Author SHA1 Message Date
Serhey Popovych
5433656705 ip: Use single variable to represent -pretty
After commit a233caa0aa ("json: make pretty printing optional") I get
following build failure:

    LINK     rtmon
    ../lib/libutil.a(json_print.o): In function `new_json_obj':
    json_print.c:(.text+0x35): undefined reference to `show_pretty'
    collect2: error: ld returned 1 exit status
    make[1]: *** [rtmon] Error 1
    make: *** [all] Error 2

It is caused by missing show_pretty variable in rtmon.

On the other hand tc/tc.c there are two distinct variables and single
matches() call that handles -pretty option thus setting show_pretty
will never happen. Note that since commit 44dcfe8201 ("Change
formatting of u32 back to default") show_pretty is used in tc/f_u32.c
so this is first place where -pretty introduced.

Furthermore other utilities like misc/ifstat.c and misc/nstat.c define
pretty variable, however only for their own purposes. They both support
JSON output and thus depend show_pretty in new_json_obj().

Assuming above use common variable to represent -pretty option, define
it in utils.c and declare in utils.h that is commonly used. Replace
show_pretty with pretty.

Fixes: a233caa0aa ("json: make pretty printing optional")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
2018-02-16 08:13:36 -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
Yulia Kartseva
73451259da tc: fix ipv6 filter selector attribute for some prefix lengths
Wrong TCA_U32_SEL attribute packing if prefixLen AND 0x1f equals 0x1f.
These are  /31, /63, /95 and /127 prefix lengths.

Example:
ip6 dst face:b00f::/31
filter parent b: protocol ipv6 pref 2307 u32
filter parent b: protocol ipv6 pref 2307 u32 fh 800: ht divisor 1
filter parent b: protocol ipv6 pref 2307 u32 fh 800::800 order 2048
key ht 800 bkt 0
  match faceb00f/ffffffff at 24

v2: previous patch was made with a wrong repo

Signed-off-by: Yulia Kartseva <hex@fb.com>
2017-10-01 13:41:29 -07:00
Jamal Hadi Salim
9e71352581 tc actions: Improved batching and time filtered dumping
dump more than TCA_ACT_MAX_PRIO actions per batch when the kernel
supports it.

Introduced keyword "since" for time based filtering of actions.
Some example (we have 400 actions bound to 400 filters); at
installation time. Using updated when tc setting the time of
interest to 120 seconds earlier (we see 400 actions):
prompt$ hackedtc actions ls action gact since 120000| grep index | wc -l
400

go get some coffee and wait for > 120 seconds and try again:

prompt$ hackedtc actions ls action gact since 120000 | grep index | wc -l
0

Lets see a filter bound to one of these actions:
....
filter pref 10 u32
filter pref 10 u32 fh 800: ht divisor 1
filter pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:10  (rule hit 2 success 1)
  match 7f000002/ffffffff at 12 (success 1 )
    action order 1: gact action pass
     random type none pass val 0
     index 23 ref 2 bind 1 installed 1145 sec used 802 sec
    Action statistics:
    Sent 84 bytes 1 pkt (dropped 0, overlimits 0 requeues 0)
    backlog 0b 0p requeues 0
...

that coffee took long, no? It was good.

Now lets ping -c 1 127.0.0.2, then run the actions again:
prompt$ hackedtc actions ls action gact since 120 | grep index | wc -l
1

More details please:
prompt$ hackedtc -s actions ls action gact since 120000

    action order 0: gact action pass
     random type none pass val 0
     index 23 ref 2 bind 1 installed 1270 sec used 30 sec
    Action statistics:
    Sent 168 bytes 2 pkt (dropped 0, overlimits 0 requeues 0)
    backlog 0b 0p requeues 0

And the filter?
filter pref 10 u32
filter pref 10 u32 fh 800: ht divisor 1
filter pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:10  (rule hit 4 success 2)
  match 7f000002/ffffffff at 12 (success 2 )
    action order 1: gact action pass
     random type none pass val 0
     index 23 ref 2 bind 1 installed 1324 sec used 84 sec
    Action statistics:
    Sent 168 bytes 2 pkt (dropped 0, overlimits 0 requeues 0)
    backlog 0b 0p requeues 0

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2017-08-04 13:16:51 -07:00
Roman Mashak
fb12cea8d9 tc: fixed typo in usage text.
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
2017-06-21 08:34:28 -07:00
Or Gerlitz
e57285b81a tc: Reflect HW offload status
Currently there is no way of querying whether a filter is
offloaded to HW or not when using "both" policy (where none
of skip_sw or skip_hw flags are set by user-space).

Add two new flags, "in hw" and "not in hw" such that user
space can determine if a filter is actually offloaded to
hw or not. The "in hw" UAPI semantics was chosen so it's
similar to the "skip hw" flag logic.

If none of these two flags are set, this signals running
over older kernel.

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
2017-05-05 09:49:25 -07:00
Sushma Sitaram
58d93d0030 tc: f_u32: Fill in 'linkid' provided by user
Currently, 'linkid' input by the user is parsed but 'handle' is appended to the netlink message.

# tc filter add dev enp1s0f1 protocol ip parent ffff: prio 99 u32 ht 800: \
	order 1 link 1: offset at 0 mask 0f00 shift 6 plus 0 eat match ip \
	protocol 6 ff

resulted in:
filter protocol ip pref 99 u32 fh 800::1 order 1 key ht 800 bkt 0
  match 00060000/00ff0000 at 8
    offset 0f00>>6 at 0  eat

This patch results in:
filter protocol ip pref 99 u32 fh 800::1 order 1 key ht 800 bkt 0 link 1:
  match 00060000/00ff0000 at 8
    offset 0f00>>6 at 0  eat

Signed-off-by Sushma Sitaram: Sushma Sitaram <sushma.sitaram@intel.com>
2016-10-09 18:51:00 -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
Stephen Hemminger
622812052a tc: f_u32 cleanup indentation and long lines
Several long lines and too long messages here.
2016-06-08 16:45:26 -07:00
Samudrala, Sridhar
5e5b3008d1 tc: f_u32: Add support for skip_hw and skip_sw flags
On devices that support TC U32 offloads, these flags enable a filter to be
added only to HW or only to SW. skip_sw and skip_hw are mutually exclusive
flags. By default without any flags, the filter is added to both HW and SW,
but no error checks are done in case of failure to add to HW.
With skip-sw, failure to add to HW is treated as an error.

Here is a sample script that adds 2 filters, one with skip_sw and the other
with skip_hw flag.

   # add ingress qdisc
   tc qdisc add dev p4p1 ingress

   # enable hw tc offload.
   ethtool -K p4p1 hw-tc-offload on

   # add u32 filter with skip-sw flag.
   tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
      handle 800:0:1 u32 ht 800: flowid 800:1 \
      skip-sw \
      match ip src 192.168.1.0/24 \
      action drop

   # add u32 filter with skip-hw flag.
   tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
      handle 800:0:2 u32 ht 800: flowid 800:2 \
      skip-hw \
      match ip src 192.168.2.0/24 \
      action drop

Signed-off-by: Sridhar Samudrala <sridhar.samudrala@intel.com>
2016-06-08 16:39:30 -07:00
Sabrina Dubroca
9f7401fa49 utils: add get_be{16, 32, 64}, use them where possible
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Acked-by: Phil Sutter <phil@nwl.cc>
2016-06-08 09:30:37 -07:00
Jamal Hadi Salim
82e6efe2e3 tc filter u32: Coding style fixes
"handle" was being used several times for different things.
Fix the 80 character limit abuse and other little issues while at it.

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2016-05-31 12:33:48 -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
Luca Lemmo
725f2a872d tc: f_u32: trivial coding style cleanups
Signed-off-by: Luca Lemmo <luca@linux.com>
2016-03-21 11:42:12 -07:00
Luca Lemmo
dd0c8d193f tc: f_u32: add missing spaces around operators
Signed-off-by: Luca Lemmo <luca@linux.com>
2016-03-21 11:42:12 -07:00
Phil Sutter
40eb737ebb tc: u32 filter coding style cleanup
Add missing spaces around operators to increase readability. Aside from
that, make "preference" match a real synonym for "tos" and "dsfield" as
it's effect was identical to them.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-10-23 15:37:26 -07:00
Stephen Hemminger
3d0b7439df whitespace cleanup
Remove all trailing whitespace and space before tabs.
2014-12-20 15:47:17 -08:00
Jamal Hadi Salim
863ecb04b4 discourage use of direct policer interface
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2014-10-09 08:26:57 -07:00
Stephen Hemminger
d1f28cf181 ip: make local functions static 2013-02-12 11:38:35 -08:00
Hiroaki SHIMODA
690b11f4a6 tc: u32: Fix firstfrag filter.
On current firstfrag filter, all non fragmented packets are matched.
firstfrag should check MF bit.

Signed-off-by: Hiroaki SHIMODA <shimoda.hiroaki@gmail.com>
2012-07-10 15:39:02 -07:00
Hiroaki SHIMODA
1d62f99fe2 tc: u32: Fix icmp_code off.
The off of icmp_code is not 20 but 21. Also offmask should be 0 unless
nexthdr+ is specified.

Signed-off-by: Hiroaki SHIMODA <shimoda.hiroaki@gmail.com>
2012-07-10 15:39:02 -07: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
Stephen Hemminger
bcd7abddd4 tc filter: fix dport/sport in pretty print output
Problem reported by Peter Lebbing on Debian.
The decode of source and destination port filters in pretty print
mode was backwards.
2011-05-19 09:19:17 -07:00
Stephen Hemminger
d7ac9ad4f4 Fix warning in u32 from assignment in conditional 2011-04-12 14:23:39 -07:00
Stephen Hemminger
e3d153c1fb Fix byte order of ether address match for u32
The u32 key match was incorrect byte order when using ether source
or destination address matching.
2010-08-02 11:55:30 -07:00
Petr Lautrbach
0156412215 iproute: fix tc generating ipv6 priority filter
This patch adds ipv6 filter priority/traffic class function
static int parse_ip6_class(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
shifting filter value to 5th bit and ignoring "at" as header position
is exactly given.

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2010-07-23 12:29:35 -07:00
Florian Westphal
8d8de1139c tc: remove stale code
remove unused #define and "ok" statements.

Signed-off-by: Florian Westphal <fwestphal@astaro.com>
2010-01-21 10:13:01 -08:00
Stephen Hemminger
d13cee6d59 Add IPV6 match pretty print 2009-05-26 15:14:29 -07:00
Stephen Hemminger
b4d41f41b6 Add u32 extension to match on ether source/destination
Use existing u32 mechanism to match based on Ethernet header.
No need for protocol that already exists.
2009-04-15 15:39:34 -07:00
Stephen Hemminger
9fce67dd46 Remove goto chain
The selector logic is clearer with if / else if
2009-04-03 09:44:04 -07:00
jamal
1750abe2ba Infrastructure for pretty printing
And last for now ..

cheers,
jamal

[PATCH 3/3] [TC/U32] Infrastructure for pretty printing

This patch makes it easy to add pretty printers of different protocols.
For starters it makes use of ipv4 and raw printers.
Add more later ...

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
2008-05-09 15:50:12 -07:00
Stephen Hemminger
44dcfe8201 Change formatting of u32 back to default
Don't break scripts that depend on previous offset/value format.
Introduce a new -pretty flag for decoding, and (*gasp*) document
the formatting arguments.
2008-05-09 15:42:34 -07:00
Stephen Hemminger
cfa440b0da missing dport in f_u32 output
Small typo from last change to decode filters. Should print dport
not port.
2008-02-22 11:51:35 -08:00
Stephen Hemminger
4c9ffc2f8c decode the output of u32 matches
reverse the match offset/mask values into ip header matches.
2008-02-18 11:35:29 -08:00
Stephen Hemminger
e62077d0b6 break excessively long lines
Cleanup code (slightly).
2008-02-18 10:51:42 -08:00
PJ Waskiewicz
e9acc2420c Update various classifiers' help output for expected CLASSID syntax
update: Fix the spelling of "hexidecimal"

This updates the help output to specify that CLASSID should be hexidecimal.
This makes sure that a user entering "flowid 1:10" gets his flow put into
band 15 (0x10) and knows why.

Signed-off-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com>
2008-02-13 12:36:38 -08:00
Stephen Hemminger
6b1ac654e9 add decode of match rules
Show ip address etc when decoding output of tc filter show

Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com>
2007-12-31 10:29:52 -08:00
Stephen Hemminger
81c61790d5 Eliminate trailing whitespace
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-12-13 17:05:50 -08:00
jamal
dcf1349722 Fix missing class/flowid oddity
[U32] Fix missing class/flowid oddity
When an action or policer is specified but not a classid/flowid, the
syntax accepts it but the kernel never really hits it.
This has been a long standing problem, but thanks to the persistence
of Marco Berizzi <pupilla@hotmail.com> I broke down and fixed it.

Signed-off-by: J Hadi Salim <hadi@cyberus.ca>
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-12-13 17:00:46 -08: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
shemminger
267480f553 Backout the 2.4 utsname hash patch. 2006-03-22 00:07:49 +00:00
shemminger
46b67dab26 Fix build errors from last patch 2006-03-14 19:38:34 +00:00
shemminger
3925ad8119 Fixes for tc hash sample. 2006-03-14 19:36:31 +00:00
shemminger
f3b1006c73 Missing memset in tc sample 2006-03-10 23:27:13 +00:00
shemminger
d8a45819b2 Fix u32 filter for ipv6 priority 2006-01-10 18:45:42 +00:00
8!tgraf
ac2fc2df5e Use parse_rtattr_nested
(Logical change 1.129)
2005-01-18 22:11:58 +00:00
8!tgraf
4a86fe19bc Use NLMSG_TAIL
(Logical change 1.127)
2005-01-18 01:24:18 +00:00
net[shemminger]!shemminger
b906243b62 Import patch iproute2.116
(Logical change 1.118)
2005-01-17 23:28:16 +00:00
net[shemminger]!shemminger
6f0ba88be0 Import patch iproute2.115
(Logical change 1.117)
2005-01-17 23:27:56 +00:00