]> git.proxmox.com Git - mirror_iproute2.git/log
mirror_iproute2.git
6 years agoiprule: add json support
Stephen Hemminger [Tue, 6 Mar 2018 21:07:11 +0000 (13:07 -0800)]
iprule: add json support

More JSON and colorizing.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipaddrlabel: add json support
Stephen Hemminger [Tue, 6 Mar 2018 21:07:10 +0000 (13:07 -0800)]
ipaddrlabel: add json support

Add missing json and color support to addrlabel display

Example:
$ ip -j -p addrlabel
[ {
        "address": "::1",
        "prefixlen": 128,
        "label": 56
    },{
        "address": "::",
        "prefixlen": 96,
        "label": 56
    },{
...

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipneigh: add color and json support
Stephen Hemminger [Tue, 6 Mar 2018 21:07:09 +0000 (13:07 -0800)]
ipneigh: add color and json support

Use json_print to provide json (and color) support to
ip neigh command.

Example:
$ ip -j -p neigh
[ {
        "dst": "192.168.1.29",
        "dev": "enp12s0",
        "state": [ "FAILED" ]
    },{
        "dst": "192.168.1.130",
        "dev": "enp12s0",
        "state": [ "FAILED" ]
    },{
        "dst": "192.168.1.131",
        "dev": "enp12s0",
        "lladdr": "00:15:5d:2a:16:4f",
        "state": [ "STALE" ]
    }
...

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'ip-rule-proto' into iproute2-next
David Ahern [Thu, 1 Mar 2018 03:45:56 +0000 (19:45 -0800)]
Merge branch 'ip-rule-proto' into iproute2-next

Donald Sharp  says:

====================

Fix iprule.c to use the actual `struct fib_rule_hdr` and to
allow the end user to see and use the protocol keyword
for rule manipulation.

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: Allow rules to accept a specified protocol
Donald Sharp [Wed, 28 Feb 2018 23:44:00 +0000 (18:44 -0500)]
ip: Allow rules to accept a specified protocol

Allow the specification of a protocol when the user
adds/modifies/deletes a rule.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: Display ip rule protocol used
Donald Sharp [Wed, 28 Feb 2018 23:43:59 +0000 (18:43 -0500)]
ip: Display ip rule protocol used

Modify 'ip rule' command to notice when the kernel passes
to us the originating protocol.

Add code to allow the `ip rule flush protocol XXX`
command to be accepted and properly handled.

Modify the documentation to reflect these code changes.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: Use the `struct fib_rule_hdr` for rules
Donald Sharp [Wed, 28 Feb 2018 23:43:58 +0000 (18:43 -0500)]
ip: Use the `struct fib_rule_hdr` for rules

The iprule.c code was using `struct rtmsg` as the data
type to pass into the kernel for the netlink message.
While 'struct rtmsg' and `struct fib_rule_hdr` are
the same size and mostly the same, we should use
the correct data structure.  This commit translates
the data structures to have iprule.c use the correct
one.

Additionally copy over the modified fib_rules.h file

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'tc-ipt-ematch' into iproute2-next
David Ahern [Tue, 27 Feb 2018 17:44:33 +0000 (09:44 -0800)]
Merge branch 'tc-ipt-ematch' into iproute2-next

Eyal Birger  says:

====================

This patchset extends tc to support the ipt ematch.

The first patch adds the ability for ematch cmdline parsers
to receive argc,argv parameters.
The second patch adds the em_ipt module.

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agotc: add em_ipt ematch for calling xtables matches from tc matching context
Eyal Birger [Fri, 23 Feb 2018 11:12:25 +0000 (13:12 +0200)]
tc: add em_ipt ematch for calling xtables matches from tc matching context

The commit calls a new tc ematch for using netfilter xtable matches.

This allows early classification as well as mirroning/redirecting traffic
based on logic implemented in netfilter extensions.

Current supported use case is classification based on the incoming IPSec
state used during decpsulation using the 'policy' iptables extension
(xt_policy).

The matcher uses libxtables for parsing the input parameters.

Example use for matching an IPSec state with reqid 1:

tc qdisc add dev eth0 ingress
tc filter add dev eth0 protocol ip parent ffff: \
    basic match 'ipt(-m policy --dir in --pol ipsec --reqid 1)' \
    action drop

This is the user-space counter part of kernel commit ccc007e4a746
("net: sched: add em_ipt ematch for calling xtables matches")

Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agotc: ematch: add parse_eopt_argv() method for providing ematches with argv parameters
Eyal Birger [Fri, 23 Feb 2018 11:12:24 +0000 (13:12 +0200)]
tc: ematch: add parse_eopt_argv() method for providing ematches with argv parameters

ematche uses YACC to parse ematch arguments and places them in struct bstr
linked lists.

It is useful to be able to receive parameters as argc,argv in order to use
getopt (and alike) argument parsers.

Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoImport tc_em_ipt.h from kernel at commit 08009a760213
David Ahern [Tue, 27 Feb 2018 17:42:23 +0000 (09:42 -0800)]
Import tc_em_ipt.h from kernel at commit 08009a760213

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoUpdate kernel headers to 08009a760213
David Ahern [Mon, 26 Feb 2018 21:24:38 +0000 (13:24 -0800)]
Update kernel headers to 08009a760213

Update kernel headers to commit 08009a760213
("net: make kmem caches as __ro_after_init")

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip link: add json support for tun attributes
Sabrina Dubroca [Mon, 26 Feb 2018 10:36:15 +0000 (11:36 +0100)]
ip link: add json support for tun attributes

Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Fixes: 118eda77d660 ("ip link: add support to display extended tun attributes")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: link_gre6.c: Support IP6_TNL_F_ALLOW_LOCAL_REMOTE flag
Petr Machata [Wed, 21 Feb 2018 11:18:37 +0000 (12:18 +0100)]
ip: link_gre6.c: Support IP6_TNL_F_ALLOW_LOCAL_REMOTE flag

For IP-in-IP tunnels, one can specify the [no]allow-localremote command
when configuring a device. Under the hood, this flips the
IP6_TNL_F_ALLOW_LOCAL_REMOTE flag on the netdevice. However, ip6gretap
and ip6erspan devices, where the flag is also relevant, are not IP-in-IP
tunnels, and thus there's no way to configure the flag on these
netdevices. Therefore introduce the command to link_gre6 as well.

The original support was introduced in commit 21440d19d957
("ip: link_ip6tnl.c/ip6tunnel.c: Support IP6_TNL_F_ALLOW_LOCAL_REMOTE flag")

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoss: print skmeminfo for packet sockets
Roopa Prabhu [Thu, 22 Feb 2018 05:37:59 +0000 (21:37 -0800)]
ss: print skmeminfo for packet sockets

before:
$ss --packet -p -m
p_raw    0          0                            *:eth0
          users:(("lldpd",pid=2240,fd=11))

after:
$ss --packet -p -m
p_raw    0          0                            *:eth0
          users:(("lldpd",pid=2240,fd=11))
          skmem:(r0,rb266240,t0,tb266240,f0,w0,o320,bl0,d0)

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agordma: Add batch command support
Leon Romanovsky [Thu, 22 Feb 2018 07:28:23 +0000 (09:28 +0200)]
rdma: Add batch command support

Implement an option (-b) to execute RDMAtool commands
from supplied file. This follows the same model as
in use for ip and devlink tools, by expecting
every new command to be on new line.

These commands are expected to be without any -*
(e.g. -d, -j, e.t.c) global flags, which should be
called externally.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'iproute2-master' into iproute2-next
David Ahern [Thu, 22 Feb 2018 22:43:33 +0000 (14:43 -0800)]
Merge branch 'iproute2-master' into iproute2-next

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agotc: implement color output
Stephen Hemminger [Wed, 21 Feb 2018 00:39:34 +0000 (16:39 -0800)]
tc: implement color output

Implement the -color option; in this case -co is ambiguous
since it was already used for -conf.
For now this just means putting device name in color.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'bridge-color-json' into next
David Ahern [Wed, 21 Feb 2018 16:47:03 +0000 (08:47 -0800)]
Merge branch 'bridge-color-json' into next

Stephen Hemminger  says:

====================

From: Stephen Hemminger <sthemmin@microsoft.com>

This set of patches adds color and full JSON support to bridge command.

The output format for bridge link command changes so that
  $ bridge link show
and
  $ ip link show
use same basic format.

The "-c" flag to bridge changes from shortened form of "-compressvlan"
to shortened form of "-color".  Once again this is so that ip
and bridge command take similar options.

Lastly the JSON output format changes slightly but this
could not impact any real user, because in several cases
the current format was invalid JSON!

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: always print interface name in color
Stephen Hemminger [Tue, 20 Feb 2018 19:24:08 +0000 (11:24 -0800)]
ip: always print interface name in color

Even in brief mode the interface name should be printed
in color if desired. This makes output consistent across
regular and brief mode.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agobridge: update man page for new color and json changes
Stephen Hemminger [Tue, 20 Feb 2018 19:24:07 +0000 (11:24 -0800)]
bridge: update man page for new color and json changes

Document color option, and no longer have restriction on json

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agobridge: add json support for link command
Stephen Hemminger [Tue, 20 Feb 2018 19:24:06 +0000 (11:24 -0800)]
bridge: add json support for link command

Add json output for bridge link show command and reuse code
from ip command to display interface information.

This also changes the output format slightly for the non JSON case so
that it has same format as the ip link show command.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agobridge: colorize output and use JSON print library
Stephen Hemminger [Tue, 20 Feb 2018 19:24:05 +0000 (11:24 -0800)]
bridge: colorize output and use JSON print library

Use new functions from json_print to simplify code.
Provide standard flag for colorizing output.

The shortened -c flag is ambiguous it could mean color or
compressvlan; it is now changed to mean color for consistency
with other iproute2 commands.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agobridge: implement json pretty print flag
Stephen Hemminger [Tue, 20 Feb 2018 19:24:04 +0000 (11:24 -0800)]
bridge: implement json pretty print flag

Make bridge work like other iproute2 commands and accept
same json and pretty flags.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: remove dead code
Stephen Hemminger [Wed, 21 Feb 2018 00:01:46 +0000 (16:01 -0800)]
ip: remove dead code

Remove long dead code (in #if 0) from original iproute2
for numeric names.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoip: don't colorize the master device
Stephen Hemminger [Tue, 20 Feb 2018 19:08:46 +0000 (11:08 -0800)]
ip: don't colorize the master device

Putting whole string "master eth0" in the interface name color
is wrong and confusing. Let's just turn color off for all attributes
of device.

Fixes: d92cc2d087b0 ("ipaddress: ll_map: Replace ll_idx_n2a() with ll_index_to_name()")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agouapi: update if_ether compat headers
Stephen Hemminger [Tue, 20 Feb 2018 18:48:32 +0000 (10:48 -0800)]
uapi: update if_ether compat headers

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoip link: add support to display extended tun attributes
Sabrina Dubroca [Tue, 20 Feb 2018 12:43:22 +0000 (13:43 +0100)]
ip link: add support to display extended tun attributes

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoUpdate kernel headers to 4.16.0-rc2+
David Ahern [Tue, 20 Feb 2018 04:06:04 +0000 (20:06 -0800)]
Update kernel headers to 4.16.0-rc2+

Update kernel headers to commit f5c0c6f4299f
("Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net")

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'print_linkinfo_brief' into next
David Ahern [Fri, 16 Feb 2018 16:14:49 +0000 (08:14 -0800)]
Merge branch 'print_linkinfo_brief' into next

Serhey Popovych  says:

====================

With this series I propose to make print_linkinfo_brief() static in
favor of print_linkinfo() as single point for linkinfo printing.

Changes presented with this series tested using following script:

\#!/bin/bash

iproute2_dir="$1"
iface='eth0.2'

pushd "$iproute2_dir" &>/dev/null

for i in new old; do
DIR="/tmp/$i"
mkdir -p "$DIR"

ln -snf ip.$i ip/ip

# normal
ip/ip link show                  >"$DIR/ip-link-show"
ip/ip -4 addr show               >"$DIR/ip-4-addr-show"
ip/ip -6 addr show               >"$DIR/ip-6-addr-show"
ip/ip addr show dev "$iface"     >"$DIR/ip-addr-show-$iface"

# brief
ip/ip -br link show              >"$DIR/ip-br-link-show"
ip/ip -br -4 addr show           >"$DIR/ip-br-4-addr-show"
ip/ip -br -6 addr show           >"$DIR/ip-br-6-addr-show"
ip/ip -br addr show dev "$iface" >"$DIR/ip-br-addr-show-$iface"
done
rm -f ip/ip

diff -urN /tmp/{old,new} |sed -n -Ee'/^(-{3}|\+{3})[[:space:]]+/!p'
rc=$?

popd &>/dev/null
exit $rc

Expected results : <no output>
Actual results   : <no output>

Although test coverage is far from ideal in my opinion it covers most
important aspects of the changes presented by the series.

All this work is done in prepare of iplink_get() enhancements to support
attribute parse that finally will be used to simplify ip/tunnel
RTM_GETLINK code.

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipaddress: Make print_linkinfo_brief() static
Serhey Popovych [Thu, 15 Feb 2018 21:23:24 +0000 (23:23 +0200)]
ipaddress: Make print_linkinfo_brief() static

It shares lot of code with print_linkinfo(): drop duplicated part,
change parameters list, make it static and call from print_linkinfo()
after common path.

While there move SPRINT_BUF() to the function scope from blocks to
avoid duplication and use "%s" to print "\n" to help compiler optimize
exit for both print_linkinfo_brief() and normal paths.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoutils: Introduce and use print_name_and_link() to print name@link
Serhey Popovych [Thu, 15 Feb 2018 21:23:23 +0000 (23:23 +0200)]
utils: Introduce and use print_name_and_link() to print name@link

There is at least three places implementing same things: two in
ipaddress.c print_linkinfo() & print_linkinfo_brief() and one in
bridge/link.c.

They are diverge from each other very little: bridge/link.c does not
support JSON output at the moment and print_linkinfo_brief() does not
handle IFLA_LINK_NETNS case.

Introduce and use print_name_and_link() routine to handle name@link
output in all possible variations; respect IFLA_LINK_NETNS attribute to
handle case when link is in different namespace; use ll_idx_n2a() for
interface name instead of "<nil>" to share logic with other code (e.g.
ll_name_to_index() and ll_index_to_name()) supporting such template.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoutils: Introduce and use get_ifname_rta()
Serhey Popovych [Thu, 15 Feb 2018 21:23:22 +0000 (23:23 +0200)]
utils: Introduce and use get_ifname_rta()

Be consistent in handling of IFLA_IFNAME attribute in all places: if
there is no attribute report bug to stderr and use ll_idx_n2a() as
last measure to get name in "if%u" format instead of "<nil>".

Use check_ifname() to validate network device name: this catches both
unexpected return from kernel and ll_idx_n2a().

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agolib: Correct object file dependencies
Serhey Popovych [Thu, 15 Feb 2018 21:23:21 +0000 (23:23 +0200)]
lib: Correct object file dependencies

Neither internal libnetlink nor libgenl depends on ll_map.o: prepare for
upcoming changes that brings much more cleaner dependency between
utils.o and ll_map.o.

However ll_map.o depends on libnetlink.o functions so we need to provide
libnetlink.a after libutil.a in LIBNETLINK at global Makefile.

Tested using make clean && make -j4. No problems so far.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipaddress: Simplify print_linkinfo_brief() and it's usage
Serhey Popovych [Thu, 15 Feb 2018 21:23:20 +0000 (23:23 +0200)]
ipaddress: Simplify print_linkinfo_brief() and it's usage

Simplify calling code in ipaddr_list_flush_or_save() by introducing
intermediate variable of @struct nlmsghdr, drop duplicated code:
print_linkinfo_brief() never returns values other than <= 0 so we can
move print_selected_addrinfo() outside of each block.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipaddress: Improve print_linkinfo()
Serhey Popovych [Thu, 15 Feb 2018 21:23:19 +0000 (23:23 +0200)]
ipaddress: Improve print_linkinfo()

There are few places to improve:

  1) return -1 when entry is filtered instead of zero, which means
     accept entry: ipaddress_list_flush_or_save() the only user of this

  2) use ll_idx_n2a() as last resort to translate name to index for
     "should never happen" cases when cache shouldn't be considered

  3) replace open coded access to IFLA_IFNAME attribute data by
     RTA_DATA() with rta_getattr_str()

  4) simplify ifname printing since name is never NULL, thanks to (2).

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoutils: Reimplement ll_idx_n2a() and introduce ll_idx_a2n()
Serhey Popovych [Thu, 15 Feb 2018 21:23:18 +0000 (23:23 +0200)]
utils: Reimplement ll_idx_n2a() and introduce ll_idx_a2n()

Now all users of ll_idx_n2a() replaced with ll_index_to_name() we can
move it's functionality to ll_index_to_name() and implement index to
name conversion using snprintf() and "if%u".

Use %u specifier in "if%..." template consistently: network device
indexes are always greather than zero.

Also introduce ll_idx_n2a() conterpart: ll_idx_a2n() that is used
to translate name of the "if%u" form to index using sscanf().

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipaddress: ll_map: Replace ll_idx_n2a() with ll_index_to_name()
Serhey Popovych [Thu, 15 Feb 2018 21:23:17 +0000 (23:23 +0200)]
ipaddress: ll_map: Replace ll_idx_n2a() with ll_index_to_name()

There is no reentrancy as well as deferred result usage for all cases
where ll_idx_n2a() being used: it is safe to use ll_index_to_name() that
internally calls ll_idx_n2a() with static buffer to hold result.

While there print master network device name using correct color.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipaddress: Abstract IFA_LABEL matching code
Serhey Popovych [Thu, 15 Feb 2018 21:23:16 +0000 (23:23 +0200)]
ipaddress: Abstract IFA_LABEL matching code

There at least two places in ip/ipaddress.c where we match IFA_LABEL
against filter.label if that is given.

Get rid of "common" if () statement for inet_addr_match_rta() and
ifa_label_match_rta(): it is not common because first will check for
filter.pfx.family != AF_UNSPEC inside and second for filter.label being
non NULL.

This allows us to further simplify down code and prepare for
ll_idx_n2a() replacement with ll_index_to_name() without 80 columns
checkpatch notice.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: Use single variable to represent -pretty
Serhey Popovych [Thu, 15 Feb 2018 18:31:33 +0000 (20:31 +0200)]
ip: Use single variable to represent -pretty

After commit a233caa0aaee ("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 44dcfe820185 ("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: a233caa0aaee ("json: make pretty printing optional")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'unify-tunnel-endpoint-parsing' into next
David Ahern [Wed, 14 Feb 2018 17:02:12 +0000 (09:02 -0800)]
Merge branch 'unify-tunnel-endpoint-parsing' into next

Serhey Popovych  says:

====================

Use get_addr_rta() helper to unify address retriveal from netlink
message when configuring tunnel and get_addr() to parse endpoint
address into @inet_prefix.

This is next step towards ip and ipv6 tunnel module merge: endpoint
address parsing code will differ only in @family constant being
passed to get_addr_rta() and get_addr().

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiptnl/ip6tnl: Unify local/remote endpoint and 6rd address parsing
Serhey Popovych [Mon, 12 Feb 2018 20:17:59 +0000 (22:17 +0200)]
iptnl/ip6tnl: Unify local/remote endpoint and 6rd address parsing

We are going to merge link_iptnl.c and link_ip6tnl.c and this is final
step to make their diffs clear and show what needs to be changed during
merge.

Note that it is safe to omit endpoint address(es) from netlink create
request as kernel is aware of such case and will use zero for that
endpoint(s).

Make sure we initialize ip6rdprefix and ip6rdrelayprefix bitlen in
link_iptnl.c only when configuring existing tunnel: if kernel does not
submit prefixlen in corresponding attributes preceeding get_addr_rta()
will set bitlen to -1 which is incorrect value.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agogre/gre6: Unify local/remote endpoint address parsing
Serhey Popovych [Mon, 12 Feb 2018 20:17:58 +0000 (22:17 +0200)]
gre/gre6: Unify local/remote endpoint address parsing

We are going to merge link_gre.c and link_gre6.c and this is final step
to make their diffs clear and show what needs to be changed during merge.

Note that it is safe to omit endpoint address(es) from netlink create
request as kernel is aware of such case and will use zero for that
endpoint(s).

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agovti/vti6: Unify local/remote endpoint address parsing
Serhey Popovych [Mon, 12 Feb 2018 20:17:57 +0000 (22:17 +0200)]
vti/vti6: Unify local/remote endpoint address parsing

We are going to merge link_vti.c and link_vti6.c and this is final step
to make their diffs clear and show what needs to be changed during merge.

Note that it is safe to omit endpoint address(es) from netlink create
request as kernel is aware of such case and will use zero for that
endpoint(s).

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoutils: Introduce and use inet_prefix_reset()
Serhey Popovych [Mon, 12 Feb 2018 20:17:56 +0000 (22:17 +0200)]
utils: Introduce and use inet_prefix_reset()

Initializing @inet_prefix using C initializers or memset() seems
inefficient and unnecessary: only small part of ->data[] field will be
used to store address corresponding to ->family.

Instead initialize ->flags with zero and assume no other fields accessed
before checking corresponding bits in ->flags. For example special
helpers (e.g. is_addrtype_*()) can be used to ensure that @inet_prefix
contains valid ip or ipv6 address.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoRemove leftovers from removed Latex documentation
Phil Sutter [Fri, 9 Feb 2018 17:49:38 +0000 (18:49 +0100)]
Remove leftovers from removed Latex documentation

Since there is no documentation in Latex format left, there is no need
to check for commands to build it. Also there is no need to ignore any
of the temporary files which were created by them.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoREADME: update location of git repositories, remove broken info link
Quentin Monnet [Fri, 9 Feb 2018 17:11:09 +0000 (09:11 -0800)]
README: update location of git repositories, remove broken info link

Reflect the recent change of location for the git repositories, and the
creation of the -next development repo, in README and README.devel.

Also remove the link to the Linux Foundation wiki that contained
information about iproute2. The link is now broken, I did not find any
alternative page to point to.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: David Ahern <dsahern@gmail.com>
6 years agoinclude: update rdma header from 4.16-rc1
Stephen Hemminger [Wed, 14 Feb 2018 00:42:00 +0000 (16:42 -0800)]
include: update rdma header from 4.16-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoMerge branch 'iproute-json-color' into next
David Ahern [Sat, 10 Feb 2018 16:24:57 +0000 (08:24 -0800)]
Merge branch 'iproute-json-color' into next

Stephen Hemminger  says:

====================

From: Stephen Hemminger <stephen@networkplumber.org>

This set of patches adds JSON output to route printing.
Tested for the simple cases, but there are many variations and there
such as lw tunnels which have not be tested.

The color formatting may need some additional tweaks. It looks
like for some tags the tag is also showing up in color.
This should be fixed in print_color_string rather than having
to do special case handling in so many places.

This patchset also changes the default JSON output to be compressed
(since the purpose of JSON is to make output machine readable);
but do optional pretty print formatting with -p flag.

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: implement JSON and color output
Stephen Hemminger [Thu, 8 Feb 2018 16:26:25 +0000 (08:26 -0800)]
iproute: implement JSON and color output

Add JSON and color output formatting to ip route command.
Similar to existing address and link output.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agojson: fix newline at end of array
Stephen Hemminger [Thu, 8 Feb 2018 16:26:24 +0000 (08:26 -0800)]
json: fix newline at end of array

The json print library was toggling pretty print at the end of
an array to workaround a bug in underlying json_writer.
Instead, just fix json_writer to pretty print array correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoman: add documentation for json and pretty flags
Stephen Hemminger [Thu, 8 Feb 2018 16:26:23 +0000 (08:26 -0800)]
man: add documentation for json and pretty flags

Add description for -json and -pretty options.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agojson: make pretty printing optional
Stephen Hemminger [Thu, 8 Feb 2018 16:26:22 +0000 (08:26 -0800)]
json: make pretty printing optional

Since JSON is intended for programmatic consumption, it makes
sense for the default output format to be concise as possible.

For programmer and other uses, it is helpful to keep the pretty
whitespace format; therefore enable it with -p flag.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: Use print_0xhex() where appropriate
Serhey Popovych [Thu, 8 Feb 2018 16:04:05 +0000 (18:04 +0200)]
ip: Use print_0xhex() where appropriate

In gre/gre6 for non-JSON output 0x%x format is used: use print_0xhex()
to get the same value for JSON.

Get rid of custom _print_hex() in bridge slave code: print_0xhex() can
be used perfectly.

Break long print_uint() with long argument list to fit into 80 columns.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip/tunnel: Minor cleanups
Serhey Popovych [Thu, 8 Feb 2018 10:57:02 +0000 (12:57 +0200)]
ip/tunnel: Minor cleanups

Few minor changes to reduce diffs between ip and ipv6 tunnel code:

  1) reduce intendation by one level when adding attributes in gre and
     gre6; reorder addattr*() calls to simplify diff

  2) reorder local variables definition; change their type (e.g. for
     IFLA_LINK) to match ones returned by rta_getattr_*()

  3) move "mode" parameter parsing in link_iptnl.c to the similar
     position as in link_ip6tnl.c

  4) handle "tc" as shortcut for "tclass"/"tos" in link_iptnl.c

  5) add whitespace where required

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'unify_tunnel_help' into next
David Ahern [Fri, 9 Feb 2018 16:04:39 +0000 (08:04 -0800)]
Merge branch 'unify_tunnel_help' into next

Serhey Popovych  says:

====================

To show only relevant diffs of ip and ipv6 variants help message print
routines needs to be unified and improved.

Get rid of print_usage() and usage() wrappers: use single function to
output help message. As side effect we return -1 from parse function
instead of calling exit(2) in case of "... tunnel <help|garbage>" is
found.

Additionally we get pointer to @struct link_util and can directly access
->id information to prepare customized help message.

Split calls to fprintf() two group: one that contains format string with
specifiers (thus requiring parameters) and another one that does not.
This helps compiler to optimize calls to fprintf() with fputs() when no
format specifiers in string. Do not use fputs() directly to keep code
formatting nice.

After this series applied following diffs:

  # diff -urN ip/link_gre{,6}.c
  # diff -urN ip/link_vti{,6}.c
  # diff -urN ip/link_ip{,6}tnl.c

in scope of help print routines reduced to necessary minimum.

Tested minimally by compiling and executing "ip link help <kind>" and
"ip link add type help" commands. Looks correct.

See individual patch description for more information.

Reviews, commands and suggestions are welcome.

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiptnl/ip6tnl: Unify iptunnel_print_help()
Serhey Popovych [Fri, 9 Feb 2018 06:58:42 +0000 (08:58 +0200)]
iptnl/ip6tnl: Unify iptunnel_print_help()

Reduce diff lines between iptnl and ip6tnl help printing code.

Use @struct link_util ->id field to print correct link help: all callers
now pass this data structure to iptunnel_print_help().

Get rid of custom print_usage() and usage() functions and use
iptunnel_print_help() directly, return from function on "... type
<help|garbage>" instead of exit(2).

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agogre/gre6: Unify gre_print_help()
Serhey Popovych [Fri, 9 Feb 2018 06:58:41 +0000 (08:58 +0200)]
gre/gre6: Unify gre_print_help()

Reduce diff lines between gre and gre6 help printing code.

Use @struct link_util ->id field to print correct link help: all callers
now pass this data structure to gre_print_help().

Get rid of custom print_usage() and usage() functions and use
gre_print_help() directly, return from function on "... type
<help|garbage>" instead of exit(2).

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agovti/vti6: Unify vti_print_help()
Serhey Popovych [Fri, 9 Feb 2018 06:58:40 +0000 (08:58 +0200)]
vti/vti6: Unify vti_print_help()

Reduce diff lines between vti and vti6 help printing code.

Use @struct link_util ->id field to print correct link help: all callers
now pass this data structure to vti_print_help().

Get rid of custom print_usage() and usage() functions and use
vti_print_help() directly, return from function on "... type
<help|garbage>" instead of exit(2).

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agonetns: allow negative nsid
Christian Brauner [Tue, 6 Feb 2018 18:39:31 +0000 (19:39 +0100)]
netns: allow negative nsid

If the kernel receives a negative nsid it will automatically assign
the next available nsid. In this case alloc_netid() will set min and
max to 0 for ird_alloc(). And when max == 0 idr_alloc() will interpret
this as the maximum range, i.e. specific to nsids it will try to find
an id in the range [0,INT_MAX). This is intentionally supported in the
kernel for nsids.

Commit acbe9118ce80 ("ip netns: use strtol() instead of atoi()")
regressed ip netns in that respect although previously the use-case
was either accidentally supported or opaquely supported such that it
triggered the original commit. From what I can gather it went as
follows before: atoi() was called with a string indicating a negative
value which caused it to return -1 which was passed to the
kernel. Let's make it less opaque by introducing the keyword "auto":

ip netns set <netns-name> auto

will cause nsid to be set to -1 and the kernel will select an available
nsid.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoiproute: make flush a separate function
Stephen Hemminger [Thu, 8 Feb 2018 00:25:06 +0000 (16:25 -0800)]
iproute: make flush a separate function

Minor refactoring to move flush into separate function to improve
readability and reduce depth of nesting.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: don't do assignment in condition
Stephen Hemminger [Thu, 8 Feb 2018 00:25:05 +0000 (16:25 -0800)]
iproute: don't do assignment in condition

Fix checkpatch complaints about assignment in conditions.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: whitespace fixes
Stephen Hemminger [Thu, 8 Feb 2018 00:25:04 +0000 (16:25 -0800)]
iproute: whitespace fixes

Add whitespace around operators for consistency.
Use tabs for indentation.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'dev_walk' into iproute2-next
David Ahern [Thu, 8 Feb 2018 00:19:12 +0000 (16:19 -0800)]
Merge branch 'dev_walk' into iproute2-next

Serhey Popovych  says:

====================

In this seris I replace /proc/net/dev and /sys/class/net usage for walk
through network device list in iptunnel/ip6tunnel and iptuntap with
netlink dump.

Following changed since RFC was sent:

  1) Treat @struct rtnl_link_stats and @struct rtnl_link_stats64 as
     array with __u32 and __u64 elements respectively in
     copy_rtnl_link_stats64() as suggested by Stephen Hemminger.

  2) Remove @name and @size parameters from @struct tnl_print_nlmsg_info
     since we can get them easily from other data.

Testing.
========

Following script is used to ensure I didn't broke things too much:

\#!/bin/bash

iproute2_dir="$1"
iface='gre1'

pushd "$iproute2_dir" &>/dev/null

for i in new old; do
DIR="/tmp/$i"
mkdir -p "$DIR"

ln -snf ip.$i ip/ip

for o in '' -s -d; do
ip/ip $o tunnel show           >"$DIR/ip${o}-tunnel-show"
ip/ip -4 $o tunnel show        >"$DIR/ip-4${o}-tunnel-show"
ip/ip -6 $o tunnel show        >"$DIR/ip-6${o}-tunnel-show"
ip/ip $o tunnel show dev "$iface" \
>"$DIR/ip${o}-tunnel-show-$iface"
ip/ip $o tuntap show           >"$DIR/ip${o}-tuntap-show"
done
done
rm -f ip/ip

diff -urN /tmp/{old,new} |sed -n -Ee'/^(-{3}|\+{3})[[:space:]]+/!p'
rc=$?

popd &>/dev/null
exit $rc

Results:
========

...
fopen /sys/class/net/ipip1/tun_flags: No such file or directory
fopen /sys/class/net/ipip2/tun_flags: No such file or directory
fopen /sys/class/net/gre10/tun_flags: No such file or directory
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note that this comes from ip.old
...
diff -urN /tmp/old/ip-d-tuntap-show /tmp/new/ip-d-tuntap-show
@@ -1,4 +1,4 @@
-tun1: tap user 1004 group 27
- Attached to processes:
 tun0: tun user 1000 group 27
  Attached to processes:
+tun1: tap user 1004 group 27
+ Attached to processes:
diff -urN /tmp/old/ip-s-tuntap-show /tmp/new/ip-s-tuntap-show
@@ -1,2 +1,2 @@
-tun1: tap user 1004 group 27
 tun0: tun user 1000 group 27
+tun1: tap user 1004 group 27
diff -urN /tmp/old/ip-tuntap-show /tmp/new/ip-tuntap-show
@@ -1,2 +1,2 @@
-tun1: tap user 1004 group 27
 tun0: tun user 1000 group 27
+tun1: tap user 1004 group 27

So basically only print order for ip tuntap get changes. Rest is intact.

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agotuntap: Use netlink to walk through tuntap list
Serhey Popovych [Wed, 7 Feb 2018 06:30:56 +0000 (08:30 +0200)]
tuntap: Use netlink to walk through tuntap list

It seems bad idea to depend on sysfs being mounted and reflected to the
current network namespace. Same applies to procfs.

Instead netlink should be used to talk to the kernel and get list of
specific network devices among with their parameters.

Support for kernel netlink message filtering by passing IFLA_INFO_KIND
in RTM_GETLINK request: if kernel does not support filtering by the kind
we will check it in reply anyway. Check for ifi->ifi_type to be either
ARPHRD_NONE or ARPHRD_ETHER to seed up things a bit without kernel level
filtering.

Unfortunately tun driver does not implement dumping it's configuration
via netlink and we still need to use read_prop() which depends on sysfs
to get additional tun device information.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiptunnel/ip6tunnel: Use netlink to walk through tunnels list
Serhey Popovych [Wed, 7 Feb 2018 06:30:55 +0000 (08:30 +0200)]
iptunnel/ip6tunnel: Use netlink to walk through tunnels list

Both tunnels use legacy /proc/net/dev interface to get tunnel device and
it's statistics. This may cause problems for cases when procfs either
not mounted or not unshare(2)d for given network namespace.

Use netlink to walk through list of tunnel devices which is network
namespace aware and provides additional information such as statistics
in the dump message.

Since both address family specific variants of do_tunnels_list() nearly
the same, except for tunnel parameters structure initialization,
matching and printing we can introduce common one in tunnel.c.

To implement address family specific parts introduce new data structure
@struct tnl_print_nlmsg_info what contains all necessary information as
well as pointers to ->init(), ->match() and ->print() callbacks.

Annotate data structures by const where appropriate.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiptunnel/ip6tunnel: Code cleanups
Serhey Popovych [Wed, 7 Feb 2018 06:30:54 +0000 (08:30 +0200)]
iptunnel/ip6tunnel: Code cleanups

Use switch () instead of if () to compare tunnel type to fit into 80
columns and make code more readable. Print "\n" using fputc().

In iptunnel.c abstract tunnel parameters matching code in iptunnel.c
into ip_tunnel_parm_match() helper to conform with ip6tunnel.c. Use
memset() to initialize @p1.

In ip6tunnel.c no need to call ll_name_to_index() with name twice: just
use found previously index. Do not initialize @p1: this is done in
ip6_tnl_parm_init().

This is to show real differences between ip and ipv6 do_tunnels_list()
implementations and prepare for upcoming unification of them.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agotunnel: Split statistic getting and printing
Serhey Popovych [Wed, 7 Feb 2018 06:30:53 +0000 (08:30 +0200)]
tunnel: Split statistic getting and printing

This is first step to move tunnel code to use rtnl dump interface
instead of /proc/net/dev read.

Make tnl_print_stats() to accept @struct rtnl_link_stats64 parameter,
introduce tnl_get_stats() that will parse line from /proc/net/dev into
@struct rtnl_link_stats64.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: Introduce get_rtnl_link_stats_rta() to get link statistics
Serhey Popovych [Wed, 7 Feb 2018 06:30:52 +0000 (08:30 +0200)]
ip: Introduce get_rtnl_link_stats_rta() to get link statistics

Assume all statistics in ip(8) represented either by IFLA_STATS64 or
IFLA_STATS is 64 bit. It is clean that we can store __u32 counters of
@struct rtnl_link_stats in __u64 counters in @struct rtnl_link_stats64.

New get_rtnl_link_stats_rta() follows __print_link_stats() behaviour on
handling of stats attribute: copy no more than size of data structure
and no less than attribute length zeroing rest.

Drop print_link_stats32() as it's functionality can be handled by 64bit
variant. Move code from __print_link_stats() to print_link_stats64() and
finally rename print_link_stats64() to __print_link_stats().

More users of introduced function will come in future.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoipaddress: Unify print_link_stats() and print_link_stats64()
Serhey Popovych [Wed, 7 Feb 2018 06:30:51 +0000 (08:30 +0200)]
ipaddress: Unify print_link_stats() and print_link_stats64()

To show real differences between these two variants adjust whitespace
intendation and use print_uint() instead of print_int() as all members
in both @struct rtnl_link_stats and @struct rtnl_link_stats64 are
unsigned.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'route_print_refactor' into iproute2-next
David Ahern [Thu, 8 Feb 2018 00:12:52 +0000 (16:12 -0800)]
Merge branch 'route_print_refactor' into iproute2-next

Stephen Hemminger  says:

====================

This patch set breaks up the big print_route function into
smaller pieces for readability and to make later changes
to support JSON and color output easier.

====================

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: refactor printing of interface
Stephen Hemminger [Wed, 7 Feb 2018 17:10:17 +0000 (09:10 -0800)]
iproute: refactor printing of interface

For JSON and colorization, make common code a function.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: refactor multipath print
Stephen Hemminger [Wed, 7 Feb 2018 17:10:16 +0000 (09:10 -0800)]
iproute: refactor multipath print

Make printing of multipath attributes a function to improve
readability.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: refactor newdst, gateway and via printing
Stephen Hemminger [Wed, 7 Feb 2018 17:10:15 +0000 (09:10 -0800)]
iproute: refactor newdst, gateway and via printing

Since these fields are printed in both route and multipath case;
avoid duplicating code.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: refactor printing flow info
Stephen Hemminger [Wed, 7 Feb 2018 17:10:14 +0000 (09:10 -0800)]
iproute: refactor printing flow info

Use common code for printing flow info.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: refactor metrics print
Stephen Hemminger [Wed, 7 Feb 2018 17:10:13 +0000 (09:10 -0800)]
iproute: refactor metrics print

Make a separate function to improve readability and enable
easier JSON conversion.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: refactor cacheinfo printing
Stephen Hemminger [Wed, 7 Feb 2018 17:10:12 +0000 (09:10 -0800)]
iproute: refactor cacheinfo printing

Make common function for decoding cacheinfo.
This code may print more info than old version in some cases.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: make printing IPv4 cache flags a function
Stephen Hemminger [Wed, 7 Feb 2018 17:10:11 +0000 (09:10 -0800)]
iproute: make printing IPv4 cache flags a function

More refactoring prior to JSON support.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: make printing icmpv6 a function
Stephen Hemminger [Wed, 7 Feb 2018 17:10:10 +0000 (09:10 -0800)]
iproute: make printing icmpv6 a function

Refactor to reduce size of print_route and improve
readability.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: refactor printing flags
Stephen Hemminger [Wed, 7 Feb 2018 17:10:09 +0000 (09:10 -0800)]
iproute: refactor printing flags

Both next hop and route need to decode flags.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agordma: Check return value of strdup call
Leon Romanovsky [Wed, 31 Jan 2018 08:11:56 +0000 (10:11 +0200)]
rdma: Check return value of strdup call

Fixes: 74bd75c2b68d ("rdma: Add basic infrastructure for RDMA tool")
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Document resource tracking
Leon Romanovsky [Wed, 31 Jan 2018 08:11:55 +0000 (10:11 +0200)]
rdma: Document resource tracking

Spartan version of resource tracking documentation.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Add QP resource tracking information
Leon Romanovsky [Wed, 31 Jan 2018 08:11:54 +0000 (10:11 +0200)]
rdma: Add QP resource tracking information

This patch adds ss-similar interface to view various resource
tracked objects. At this stage, only QP is presented.

1. Get all QPs for the specific device:
$ rdma res show qp link mlx5_4
link mlx5_4/- lqpn 8 type UD state RESET sq-psn 0 pid 0 comm [ib_ipoib]
link mlx5_4/1 lqpn 7 type UD state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 1 type GSI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 0 type SMI state RTS sq-psn 0 pid 0 comm [ib_core]

$ rdma res show qp link mlx5_4/
link mlx5_4/- lqpn 8 type UD state RESET sq-psn 0 pid 0 comm [ib_ipoib]
link mlx5_4/1 lqpn 7 type UD state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 1 type GSI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 0 type SMI state RTS sq-psn 0 pid 0 comm [ib_core]

2. Provide illegal port number (0 is illegal):
$ rdma res show qp link mlx5_4/0
Wrong device name

3. Get QPs of specific port:
$ rdma res show qp link mlx5_4/1
link mlx5_4/1 lqpn 7 type UD state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 1 type GSI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 0 type SMI state RTS sq-psn 0 pid 0 comm [ib_core]

4. Get QPs which have not assigned port yet:
link mlx5_4/- lqpn 8 type UD state RESET sq-psn 0 pid 0 comm [ib_ipoib]

5. Limit to specific Local QPNs:
$ rdma res show qp link mlx5_4/1 lqpn 1-3,7
link mlx5_4/1 lqpn 7 type UD state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 1 type GSI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 0 type SMI state RTS sq-psn 0 pid 0 comm [ib_core]

. Filter types (strings):
$ rdma res show qp link mlx5_4/1 type UD,gSi
link mlx5_4/1 lqpn 7 type UD state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_4/1 lqpn 1 type GSI state RTS sq-psn 0 pid 0 comm [ib_core]

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Add resource tracking summary
Leon Romanovsky [Wed, 31 Jan 2018 08:11:53 +0000 (10:11 +0200)]
rdma: Add resource tracking summary

The global resource summary information. The object names, current utilization
and maximum numbers are received as is from the kernel.

$ rdma res
1: mlx5_0: pd 3 cq 5 qp 4
2: mlx5_1: pd 3 cq 5 qp 4
3: mlx5_2: pd 3 cq 5 qp 4
4: mlx5_3: pd 2 cq 3 qp 2
5: mlx5_4: pd 3 cq 5 qp 4

$ rdma res show mlx5_4
5: mlx5_4: pd 3 cq 5 qp 44

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Allow external usage of compare string routine
Leon Romanovsky [Wed, 31 Jan 2018 08:11:51 +0000 (10:11 +0200)]
rdma: Allow external usage of compare string routine

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Set pointer to device name position
Leon Romanovsky [Wed, 31 Jan 2018 08:11:50 +0000 (10:11 +0200)]
rdma: Set pointer to device name position

The dev and link execution callbacks expects that next
command line argument is device or port name.

Set pointer to device or port name position prior calls to
rd_exec_dev()/rd_exec_link().

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Add filtering infrastructure
Leon Romanovsky [Wed, 31 Jan 2018 08:11:49 +0000 (10:11 +0200)]
rdma: Add filtering infrastructure

This patch adds general infrastructure to RDMAtool to handle various
filtering options needed for the downstream resource tracking patches.

The infrastructure is generic and stores filters in list of key<->value
entries. There are three types of filters:

1. Numeric - the values are intended to be digits combined with '-' to
mark range and ',' to mark multiple entries, e.g. pid 1-100,234,400-401
is perfectly legit filter to limit process ids.

2. String - the values are consist from strings and "," as a denominator.

3. Link - special case to allow '/' in string to provide link name, e.g.
link mlx4_1/2.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Make visible the number of arguments
Leon Romanovsky [Wed, 31 Jan 2018 08:11:48 +0000 (10:11 +0200)]
rdma: Make visible the number of arguments

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: Add option to provide "-" sign for the port number
Leon Romanovsky [Wed, 31 Jan 2018 08:11:47 +0000 (10:11 +0200)]
rdma: Add option to provide "-" sign for the port number

According to the IBTA spec [1], the physical connected port is provided
for the QP in RTR-to-INIT stage performed by modify_qp(). It causes
to do not have port number for newly created QPs.

The following patch adds "-" sign to present absence of port, because
QPs are going to be associated with rdmatool link object, which needs
port number as an index.

[1] InfiniBand Architecture Release 1.3 -
"Table 96 QP State Transition Properties"

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoinclude: update UAPI types.h
Stephen Hemminger [Tue, 6 Feb 2018 01:21:27 +0000 (17:21 -0800)]
include: update UAPI types.h

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoinclude: update interface UAPI from 4.15-rc1
Stephen Hemminger [Tue, 6 Feb 2018 01:21:01 +0000 (17:21 -0800)]
include: update interface UAPI from 4.15-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoinclude: update rdma uapi from 4.15-rc1
Stephen Hemminger [Tue, 6 Feb 2018 01:20:14 +0000 (17:20 -0800)]
include: update rdma uapi from 4.15-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoinclude: update netfilter headers from 4.15-rc1
Stephen Hemminger [Tue, 6 Feb 2018 01:19:32 +0000 (17:19 -0800)]
include: update netfilter headers from 4.15-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoinclude: update uapi with BPF from 4.15-rc1
Stephen Hemminger [Tue, 6 Feb 2018 01:18:53 +0000 (17:18 -0800)]
include: update uapi with BPF from 4.15-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agotreewide: Use addattr_nest()/addattr_nest_end() to handle nested attributes
Serhey Popovych [Wed, 31 Jan 2018 08:15:08 +0000 (10:15 +0200)]
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>
6 years agoip: Minor cleanups
Serhey Popovych [Wed, 31 Jan 2018 08:15:07 +0000 (10:15 +0200)]
ip: Minor cleanups

  1) Rename @hdr parameter to @n to be coherent with rest of the parsing
     code.

  2) Use NLMSG_DATA() to get pointer to the data after nlmsghdr instead
     of calculating it directly in ip/tunnel code.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoip: Consolidate ip, xdp and lwtunnel parse/dump prototypes in ip_common.h
Serhey Popovych [Wed, 31 Jan 2018 08:15:06 +0000 (10:15 +0200)]
ip: Consolidate ip, xdp and lwtunnel parse/dump prototypes in ip_common.h

Having iplink_parse() and @struct iplink_req in include/utils.h does not
reflect it's IP nature: move to ip/ip_common.h.

Move contents of ip/iplink_xdp.h and ip/iproute_lwtunnel.h to
ip/ip_common.h since they are small (i.e. only two function prototypes):
ip/iplink_bridge.c and ip/iplink_vrf.c prototypes already there.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoRevert "ip address: Change print_linkinfo_brief to take filter as an input"
Serhey Popovych [Thu, 1 Feb 2018 11:25:52 +0000 (13:25 +0200)]
Revert "ip address: Change print_linkinfo_brief to take filter as an input"

This reverts commit 63891c70137f200105c539c92eb73abade2c05d5.

It seems print_linkinfo_brief() never accepts filter different than
default one and David Ahern suggests to revert it instead of making
new change that actually do revert.

Conflicts:
ip/ipaddress.c
ip/iplink.c

These are caused by JSON support addition after commit we reverting.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agoMerge branch 'iproute2-master' into iproute2-next
David Ahern [Mon, 29 Jan 2018 16:24:57 +0000 (08:24 -0800)]
Merge branch 'iproute2-master' into iproute2-next

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agov4.15.0 v4.15.0
Stephen Hemminger [Mon, 29 Jan 2018 16:08:52 +0000 (08:08 -0800)]
v4.15.0