]> git.proxmox.com Git - mirror_iproute2.git/log
mirror_iproute2.git
6 years agov4.13.0 v4.13.0
Stephen Hemminger [Tue, 5 Sep 2017 16:39:32 +0000 (09:39 -0700)]
v4.13.0

6 years agobpf: consolidate dumps to use bpf_dump_prog_info
Daniel Borkmann [Tue, 5 Sep 2017 00:24:32 +0000 (02:24 +0200)]
bpf: consolidate dumps to use bpf_dump_prog_info

Consolidate dump of prog info to use bpf_dump_prog_info() when possible.
Moving forward, we want to have a consistent output for BPF progs when
being dumped. E.g. in cls/act case we used to dump tag as a separate
netlink attribute before we had BPF_OBJ_GET_INFO_BY_FD bpf(2) command.

Move dumping tag into bpf_dump_prog_info() as well, and only dump the
netlink attribute for older kernels. Also, reuse bpf_dump_prog_info()
for XDP case, so we can dump tag and whether program was jited, which
we currently don't show.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agobpf: minor cleanups for bpf_trace_pipe
Daniel Borkmann [Tue, 5 Sep 2017 00:24:31 +0000 (02:24 +0200)]
bpf: minor cleanups for bpf_trace_pipe

Just minor nits, e.g. no need to fflush() and instead of returning
right away, just break and close the fd.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agotc actions: store and dump correct length of user cookies
Simon Horman [Tue, 5 Sep 2017 11:06:24 +0000 (13:06 +0200)]
tc actions: store and dump correct length of user cookies

Correct two errors which cancel each other out:
* Do not send twice the length of the actual provided by the user to the kernel
* Do not dump half the length of the cookie provided by the kernel

As the cookie is now stored in the kernel at its correct length rather
than double the that length cookies of up to the maximum size of 16 bytes
may now be stored rather than a maximum of half that length.

Output of dump is the same before and after this change,
but the data stored in the kernel is now exactly the cookie
rather than the cookie + as many trailing zeros.

Before:
 # tc filter add dev eth0 protocol ip parent ffff: \
       flower ip_proto udp action drop \
       cookie 0123456789abcdef0123456789abcdef
 RTNETLINK answers: Invalid argument

After:
 # tc filter add dev eth0 protocol ip parent ffff: \
       flower ip_proto udp action drop \
       cookie 0123456789abcdef0123456789abcdef
 # tc filter show dev eth0 ingress
   eth_type ipv4
   ip_proto udp
   not_in_hw
 action order 1: gact action drop
  random type none pass val 0
  index 1 ref 1 bind 1 installed 1 sec used 1 sec
 Action statistics:
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
 cookie len 16 0123456789abcdef0123456789abcdef

Fixes: fd8b3d2c1b9b ("actions: Add support for user cookies")
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
6 years agolib/bpf: Fix bytecode-file parsing
Phil Sutter [Tue, 29 Aug 2017 15:09:45 +0000 (17:09 +0200)]
lib/bpf: Fix bytecode-file parsing

The signedness of char type is implementation dependent, and there are
architectures on which it is unsigned by default. In that case, the
check whether fgetc() returned EOF failed because the return value was
assigned an (unsigned) char variable prior to comparison with EOF (which
is defined to -1). Fix this by using int as type for 'c' variable, which
also matches the declaration of fgetc().

While being at it, fix the parser logic to correctly handle multiple
empty lines and consecutive whitespace and tab characters to further
improve the parser's robustness. Note that this will still detect double
separator characters, so doesn't soften up the parser too much.

Fixes: 3da3ebfca85b8 ("bpf: Make bytecode-file reading a little more robust")
Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agoiplink: double the buffer size also in iplink_get()
Michal Kubecek [Fri, 1 Sep 2017 16:39:16 +0000 (18:39 +0200)]
iplink: double the buffer size also in iplink_get()

Commit 72b365e8e0fd ("libnetlink: Double the dump buffer size") increased
the buffer size for "ip link show" command to 32 KB to handle NICs with
large number of VFs. With "dev" filter, a different code path is taken and
iplink_get() still uses only 16 KB buffer.

The size of 32768 is not very future-proof as NICs supporting 120-128 VFs
are already in use so that single RTM_NEWLINK message in the dump can
exceed 30000 bytes. But it's what rtnl_talk() and rtnl_dump_filter_l() use
so let's be consistent. Once this proves insufficient, all three sizes
should be increased.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
6 years agoiplink: check for message truncation in iplink_get()
Michal Kubecek [Fri, 1 Sep 2017 16:39:11 +0000 (18:39 +0200)]
iplink: check for message truncation in iplink_get()

If message length exceeds maxlen argument of rtnl_talk(), it is truncated
to maxlen but unlike in the case of truncation to the length of local
buffer in rtnl_talk(), the caller doesn't get any indication of a problem.

In particular, iplink_get() passes the truncated message on and parsing it
results in various warnings and sometimes even a segfault (observed with
"ip link show dev ..." for a NIC with 125 VFs).

Handle message truncation in iplink_get() the same way as truncation in
rtnl_talk() would be handled: return an error.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
6 years agolnstat_util: Make sure buffer is NUL-terminated
Phil Sutter [Fri, 1 Sep 2017 16:52:56 +0000 (18:52 +0200)]
lnstat_util: Make sure buffer is NUL-terminated

Can't use strlcpy() here since lnstat is not linked against libutil.

While being at it, fix coding style in that chunk as well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc_util: No need to terminate an snprintf'ed buffer
Phil Sutter [Fri, 1 Sep 2017 16:52:55 +0000 (18:52 +0200)]
tc_util: No need to terminate an snprintf'ed buffer

snprintf() won't leave the buffer unterminated, so manually terminating
is not necessary here.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoipxfrm: Replace STRBUF_CAT macro with strlcat()
Phil Sutter [Fri, 1 Sep 2017 16:52:54 +0000 (18:52 +0200)]
ipxfrm: Replace STRBUF_CAT macro with strlcat()

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoConvert harmful calls to strncpy() to strlcpy()
Phil Sutter [Fri, 1 Sep 2017 16:52:53 +0000 (18:52 +0200)]
Convert harmful calls to strncpy() to strlcpy()

This patch converts spots where manual buffer termination was missing to
strlcpy() since that does what is needed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoConvert the obvious cases to strlcpy()
Phil Sutter [Fri, 1 Sep 2017 16:52:52 +0000 (18:52 +0200)]
Convert the obvious cases to strlcpy()

This converts the typical idiom of manually terminating the buffer after
a call to strncpy().

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoutils: Implement strlcpy() and strlcat()
Phil Sutter [Fri, 1 Sep 2017 16:52:51 +0000 (18:52 +0200)]
utils: Implement strlcpy() and strlcat()

By making use of strncpy(), both implementations are really simple so
there is no need to add libbsd as additional dependency.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolink_gre6: Print the tunnel's tclass setting
Phil Sutter [Fri, 1 Sep 2017 14:08:09 +0000 (16:08 +0200)]
link_gre6: Print the tunnel's tclass setting

Print the value analogous to flowlabel. While being at it, also break
the overlong lines to not exceed 80 characters boundary.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolink_gre6: Fix for changing tclass/flowlabel
Phil Sutter [Fri, 1 Sep 2017 14:08:08 +0000 (16:08 +0200)]
link_gre6: Fix for changing tclass/flowlabel

When trying to change tclass or flowlabel of a GREv6 tunnel which has
the respective value set already, the code accidentally bitwise OR'ed
the old and the new value, leading to unexpected results. Fix this by
clearing the relevant bits of flowinfo variable prior to assigning the
new value.

Fixes: af89576d7a8c4 ("iproute2: GRE over IPv6 tunnel support.")
Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Fix for added diag support check
Phil Sutter [Mon, 28 Aug 2017 17:31:22 +0000 (19:31 +0200)]
ss: Fix for added diag support check

Commit 9f66764e308e9 ("libnetlink: Add test for error code returned from
netlink reply") changed rtnl_dump_filter_l() to return an error in case
NLMSG_DONE would contain one, even if it was ENOENT.

This in turn breaks ss when it tries to dump DCCP sockets on a system
without support for it: The function tcp_show(), which is shared between
TCP and DCCP, will start parsing /proc since inet_show_netlink() returns
an error - yet it parses /proc/net/tcp which doesn't make sense for DCCP
sockets at all.

On my system, a call to 'ss' without further arguments prints the list
of connected TCP sockets twice.

Fix this by introducing a dedicated function dccp_show() which does not
have a fallback to /proc, just like sctp_show(). And since tcp_show()
is no longer "multi-purpose", drop it's socktype parameter.

Fixes: 9f66764e308e9 ("libnetlink: Add test for error code returned from netlink reply")
Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc: use named initializer for default mqprio options
Stephen Hemminger [Thu, 24 Aug 2017 22:27:35 +0000 (15:27 -0700)]
tc: use named initializer for default mqprio options

Use C99 initializer

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agolib/libnetlink: Don't pass NULL parameter to memcpy()
Phil Sutter [Thu, 24 Aug 2017 09:41:31 +0000 (11:41 +0200)]
lib/libnetlink: Don't pass NULL parameter to memcpy()

Both addattr_l() and rta_addattr_l() may be called with NULL data
pointer and 0 alen parameters. Avoid calling memcpy() in that case.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolib/fs: Fix and simplify make_path()
Phil Sutter [Thu, 24 Aug 2017 09:41:30 +0000 (11:41 +0200)]
lib/fs: Fix and simplify make_path()

Calling stat() before mkdir() is racey: The entry might change in
between. Also, the call to stat() seems to exist only to check if the
directory exists already. So simply call mkdir() unconditionally and
catch only errors other than EEXIST.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolib/bpf: Check return value of write()
Phil Sutter [Thu, 24 Aug 2017 09:41:29 +0000 (11:41 +0200)]
lib/bpf: Check return value of write()

This is merely to silence the compiler warning. If write to stderr
failed, assume that printing an error message will fail as well so don't
even try.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agonetem/maketable: Check return value of fscanf()
Phil Sutter [Thu, 24 Aug 2017 09:41:28 +0000 (11:41 +0200)]
netem/maketable: Check return value of fscanf()

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Make sure scanned index value to unix_state_map is sane
Phil Sutter [Thu, 24 Aug 2017 09:41:27 +0000 (11:41 +0200)]
ss: Make sure scanned index value to unix_state_map is sane

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Make struct tcpstat fields 'timer' and 'timeout' unsigned
Phil Sutter [Thu, 24 Aug 2017 09:41:26 +0000 (11:41 +0200)]
ss: Make struct tcpstat fields 'timer' and 'timeout' unsigned

Both 'timer' and 'timeout' variables of struct tcpstat are either
scanned as unsigned values from /proc/net/tcp{,6} or copied from
'idiag_timer' and 'idiag_expries' fields of struct inet_diag_msg, which
itself are unsigned. Therefore they may be unsigned as well, which
eliminates the need to check for negative values.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agobpf: drop unused parameter to bpf_report_map_in_map
Stephen Hemminger [Thu, 24 Aug 2017 22:02:58 +0000 (15:02 -0700)]
bpf: drop unused parameter to bpf_report_map_in_map

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agolibnetlink: drop unused parameter to rtnl_dump_done
Stephen Hemminger [Thu, 24 Aug 2017 22:02:32 +0000 (15:02 -0700)]
libnetlink: drop unused parameter to rtnl_dump_done

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agordma: fix duplicate initialization in port_names
Stephen Hemminger [Thu, 24 Aug 2017 22:00:59 +0000 (15:00 -0700)]
rdma: fix duplicate initialization in port_names

Build with warnings enable spotted this.
link.c:51:58: note: (near initialization for ‘rdma_port_names[23]’)
   rdma_port_names[] = { RDMA_PORT_FLAGS(RDMA_BITMAP_NAMES) };

Assume that fields were in order and 25 is the missing value.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agolib/ll_map: Choose size of new cache items at run-time
Phil Sutter [Thu, 24 Aug 2017 09:51:50 +0000 (11:51 +0200)]
lib/ll_map: Choose size of new cache items at run-time

Instead of having a fixed buffer of 16 bytes for the interface name,
tailor size of new ll_cache entry using the interface name's actual
length. This also makes sure the following call to strcpy() is safe.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc/m_xt: Fix for potential string buffer overflows
Phil Sutter [Thu, 24 Aug 2017 09:51:49 +0000 (11:51 +0200)]
tc/m_xt: Fix for potential string buffer overflows

- Use strncpy() when writing to target->t->u.user.name and make sure the
  final byte remains untouched (xtables_calloc() set it to zero).
- 'tname' length sanitization was completely wrong: If it's length
  exceeded the 16 bytes available in 'k', passing a length value of 16
  to strncpy() would overwrite the previously NULL'ed 'k[15]'. Also, the
  sanitization has to happen if 'tname' is exactly 16 bytes long as
  well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolnstat_util: Simplify alloc_and_open() a bit
Phil Sutter [Thu, 24 Aug 2017 09:51:48 +0000 (11:51 +0200)]
lnstat_util: Simplify alloc_and_open() a bit

Relying upon callers and using unsafe strcpy() is probably not the best
idea. Aside from that, using snprintf() allows to format the string for
lf->path in one go.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolib/inet_proto: Review inet_proto_{a2n,n2a}()
Phil Sutter [Thu, 24 Aug 2017 09:51:47 +0000 (11:51 +0200)]
lib/inet_proto: Review inet_proto_{a2n,n2a}()

The original intent was to make sure strings written by those functions
are NUL-terminated at all times, though it was suggested to get rid of
the 15 char protocol name limit as well which this patch accomplishes.

In addition to that, simplify inet_proto_a2n() a bit: Use the error
checking in get_u8() to find out whether passed 'buf' contains a valid
decimal number instead of checking the first character's value manually.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolib/fs: Fix format string in find_fs_mount()
Phil Sutter [Thu, 24 Aug 2017 09:51:46 +0000 (11:51 +0200)]
lib/fs: Fix format string in find_fs_mount()

A field width of 4096 allows fscanf() to store that amount of characters
into the given buffer, though that doesn't include the terminating NULL
byte. Decrease the value by one to leave space for it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoipntable: Avoid memory allocation for filter.name
Phil Sutter [Thu, 24 Aug 2017 09:51:45 +0000 (11:51 +0200)]
ipntable: Avoid memory allocation for filter.name

The original issue was that filter.name might end up unterminated if
user provided string was too long. But in fact it is not necessary to
copy the commandline parameter at all: just make filter.name point to it
instead.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotipc/bearer: Prevent NULL pointer dereference
Phil Sutter [Thu, 24 Aug 2017 09:46:34 +0000 (11:46 +0200)]
tipc/bearer: Prevent NULL pointer dereference

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc/tc_filter: Make sure filter name is not empty
Phil Sutter [Thu, 24 Aug 2017 09:46:33 +0000 (11:46 +0200)]
tc/tc_filter: Make sure filter name is not empty

The later check for 'k[0] != 0' requires a non-empty filter name,
otherwise NULL pointer dereference in 'q' might happen.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc/q_netem: Don't dereference possibly NULL pointer
Phil Sutter [Thu, 24 Aug 2017 09:46:32 +0000 (11:46 +0200)]
tc/q_netem: Don't dereference possibly NULL pointer

Assuming 'opt' might be NULL, move the call to RTA_PAYLOAD to after the
check since it dereferences its parameter.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoifstat, nstat: Check fdopen() return value
Phil Sutter [Thu, 24 Aug 2017 09:46:31 +0000 (11:46 +0200)]
ifstat, nstat: Check fdopen() return value

Prevent passing NULL FILE pointer to fgets() later.

Fix both tools in a single patch since the code changes are basically
identical.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: fix help/man TCP-STATE description for listening
Andreas Henriksson [Wed, 23 Aug 2017 12:47:51 +0000 (14:47 +0200)]
ss: fix help/man TCP-STATE description for listening

There's some misleading information in --help and ss(8) manpage about
TCP-STATE named 'listen'.
ss doesn't know such a state, but it knows 'listening' state.

$ ss -tua state listen
ss: wrong state name: listen

$ ss -tua state listening
[...]

Addresses: https://bugs.debian.org/872990
Reported-by: Pavel Lyulchenko <p.lyulchenko@gmail.com>
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
6 years agolib/bpf: Don't leak fp in bpf_find_mntpt()
Phil Sutter [Mon, 21 Aug 2017 14:46:51 +0000 (16:46 +0200)]
lib/bpf: Don't leak fp in bpf_find_mntpt()

If fopen() succeeded but len != PATH_MAX, the function leaks the open
FILE pointer. Fix this by checking len value before calling fopen().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agodevlink: Check return code of strslashrsplit()
Phil Sutter [Mon, 21 Aug 2017 16:36:52 +0000 (18:36 +0200)]
devlink: Check return code of strslashrsplit()

This function shouldn't fail because all callers of
__dl_argv_handle_port() make sure the passed string contains enough
slashes already, but better make sure if this changes in future the
function won't access uninitialized data.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoiplink_vrf: Complain if main table is not found
Phil Sutter [Mon, 21 Aug 2017 16:36:51 +0000 (18:36 +0200)]
iplink_vrf: Complain if main table is not found

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: David Ahern <dsahern@gmail.com>
6 years agoiproute: Check mark value input
Phil Sutter [Mon, 21 Aug 2017 16:36:50 +0000 (18:36 +0200)]
iproute: Check mark value input

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc/q_multiq: Don't pass garbage in TCA_OPTIONS
Phil Sutter [Mon, 21 Aug 2017 09:27:04 +0000 (11:27 +0200)]
tc/q_multiq: Don't pass garbage in TCA_OPTIONS

multiq_parse_opt() doesn't change 'opt' at all. So at least make sure
it doesn't fill TCA_OPTIONS attribute with garbage from stack.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agonetem/maketable: Check return value of fstat()
Phil Sutter [Mon, 21 Aug 2017 09:27:03 +0000 (11:27 +0200)]
netem/maketable: Check return value of fstat()

Otherwise info.st_size may contain garbage.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Use C99 initializer in netlink_show_one()
Phil Sutter [Mon, 21 Aug 2017 09:27:02 +0000 (11:27 +0200)]
ss: Use C99 initializer in netlink_show_one()

This has the additional benefit of initializing st.ino to zero which is
used later in is_sctp_assoc() function.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoipmaddr: Avoid accessing uninitialized data
Phil Sutter [Mon, 21 Aug 2017 09:27:01 +0000 (11:27 +0200)]
ipmaddr: Avoid accessing uninitialized data

Looks like this can only happen if /proc/net/igmp is malformed, but
better be sure.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoiplink_can: Prevent overstepping array bounds
Phil Sutter [Mon, 21 Aug 2017 09:27:00 +0000 (11:27 +0200)]
iplink_can: Prevent overstepping array bounds

can_state_names array contains at most CAN_STATE_MAX fields, so allowing
an index to it to be equal to that number is wrong. While here, also
make sure the array is indeed that big so nothing bad happens if
CAN_STATE_MAX ever increases.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoipaddress: Avoid accessing uninitialized variable lcl
Phil Sutter [Mon, 21 Aug 2017 09:26:59 +0000 (11:26 +0200)]
ipaddress: Avoid accessing uninitialized variable lcl

If no address was given, ipaddr_modify() accesses uninitialized data
when assigning to req.ifa.ifa_prefixlen.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc/m_gact: Drop dead code
Phil Sutter [Thu, 17 Aug 2017 17:09:31 +0000 (19:09 +0200)]
tc/m_gact: Drop dead code

The use of 'ok' variable in parse_gact() is ineffective: The second
conditional increments it either if *argv is 'gact' or if
parse_action_control() doesn't fail (in which case exit() is called).
So this is effectively an unconditional increment and since no decrement
happens anywhere, all remaining checks for 'ok != 0' can be dropped.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Drop useless assignment
Phil Sutter [Thu, 17 Aug 2017 17:09:30 +0000 (19:09 +0200)]
ss: Drop useless assignment

After '*b = *a', 'b->next' already has the same value as 'a->next'.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Skip useless check in parse_hostcond()
Phil Sutter [Thu, 17 Aug 2017 17:09:29 +0000 (19:09 +0200)]
ss: Skip useless check in parse_hostcond()

The passed 'addr' parameter is dereferenced by caller before and in
parse_hostcond() multiple times before this check, so assume it is
always true.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolib/rt_names: Drop dead code in rtnl_rttable_n2a()
Phil Sutter [Thu, 17 Aug 2017 17:09:28 +0000 (19:09 +0200)]
lib/rt_names: Drop dead code in rtnl_rttable_n2a()

Since 'id' is 32bit unsigned, it can never exceed RT_TABLE_MAX (which is
defined to 0xFFFFFFFF). Therefore drop that never matching conditional.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoiproute: Fix for missing 'Oifs:' display
Phil Sutter [Thu, 17 Aug 2017 17:09:27 +0000 (19:09 +0200)]
iproute: Fix for missing 'Oifs:' display

Covscan complained about dead code but after reading it, I assume the
author's intention was to prefix the interface list with 'Oifs: '.
Initializing first to 1 and setting it to 0 after above prefix was
printed should fix it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoipntable: No need to check and assign to parms_rta
Phil Sutter [Thu, 17 Aug 2017 17:09:26 +0000 (19:09 +0200)]
ipntable: No need to check and assign to parms_rta

This variable is initialized at declaration and nowhere else does any
assignment to it happen, so just drop the check.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agodevlink: No need for this self-assignment
Phil Sutter [Thu, 17 Aug 2017 17:09:25 +0000 (19:09 +0200)]
devlink: No need for this self-assignment

dl_argv_handle_both() will either assign to handle_bit or error out in
which case the variable is not used by the caller.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Jiri Pirko <jiri@mellanox.com>
6 years agordma: Add initial manual for the tool
Leon Romanovsky [Sun, 20 Aug 2017 09:58:28 +0000 (12:58 +0300)]
rdma: Add initial manual for the tool

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agordma: Add json output to link object
Leon Romanovsky [Sun, 20 Aug 2017 09:58:27 +0000 (12:58 +0300)]
rdma: Add json output to link object

An example for the JSON output for two devices system.

root@mtr-leonro:~# rdma link -d -p -j
[{
        "ifindex": 1,
        "port": 1,
        "ifname": "mlx5_0/1",
        "subnet_prefix": "fe80:0000:0000:0000",
        "lid": 13399,
        "sm_lid": 49151,
        "lmc": 0,
        "state": "ACTIVE",
        "physical_state": "LINK_UP",
        "caps": ["AUTO_MIG"
        ]
    },{
        "ifindex": 2,
        "port": 1,
        "ifname": "mlx5_1/1",
        "subnet_prefix": "fe80:0000:0000:0000",
        "lid": 13400,
        "sm_lid": 49151,
        "lmc": 0,
        "state": "ACTIVE",
        "physical_state": "LINK_UP",
        "caps": ["AUTO_MIG"
        ]
    }
]

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agordma: Implement json output for dev object
Leon Romanovsky [Sun, 20 Aug 2017 09:58:26 +0000 (12:58 +0300)]
rdma: Implement json output for dev object

The example output for machine with two devices

root@mtr-leonro:~# rdma dev -j -p
[{
"ifindex": 1,
"ifname": "mlx5_0",
"node_type": "ca",
"fw": "2.8.9999",
"node_guid": "5254:00c0:fe12:3457",
"sys_image_guid": 5254:00c0:fe12:3457",
"caps": [ "BAD_PKEY_CNTR", "BAD_QKEY_CNTR", "CHANGE_PHY_POR",
  "PORT_ACTIVE_EVENT", "SYS_IMAGE_GUID", "RC_RNR_NAK_GEN",
  "MEM_WINDOW", "UD_IP_CSUM", "UD_TSO", "XRC",
  "MEM_MGT_EXTENSIONS", "BLOCK_MULTICAST_LOOPBACK",
  "MEM_WINDOW_TYPE_2B", "RAW_IP_CSUM",
  "MANAGED_FLOW_STEERING", "RESIZE_MAX_WR" ]
},{
"ifindex": 2,
"ifname": mlx5_1,
"node_type": "ca",
"fw": "2.8.9999",
"node_guid": "5254:00c0:fe12:3458",
"sys_image_guid": "5254:00c0:fe12:3458",
"caps": [ "BAD_PKEY_CNTR", "BAD_QKEY_CNTR", "CHANGE_PHY_POR",
  "PORT_ACTIVE_EVENT", "SYS_IMAGE_GUID", "RC_RNR_NAK_GEN",
  "MEM_WINDOW", "UD_IP_CSUM", "UD_TSO", "XRC",
  "MEM_MGT_EXTENSIONS", "BLOCK_MULTICAST_LOOPBACK",
  "MEM_WINDOW_TYPE_2B", "RAW_IP_CSUM",
  "MANAGED_FLOW_STEERING", "RESIZE_MAX_WR" ]
}
]

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agordma: Add json and pretty outputs
Leon Romanovsky [Sun, 20 Aug 2017 09:58:25 +0000 (12:58 +0300)]
rdma: Add json and pretty outputs

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agordma: Add link object
Leon Romanovsky [Sun, 20 Aug 2017 09:58:24 +0000 (12:58 +0300)]
rdma: Add link object

Link (port) object represent struct ib_port to the user space.

Link properties:
 * Port capabilities
 * IB subnet prefix
 * LID, SM_LID and LMC
 * Port state
 * Physical state

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agordma: Add dev object
Leon Romanovsky [Sun, 20 Aug 2017 09:58:23 +0000 (12:58 +0300)]
rdma: Add dev object

Device (dev) object represents struct ib_device to the user space.

Device properties:
 * Device capabilities
 * FW version to the device output
 * node_guid and sys_image_guid
 * node_type

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agordma: Add basic infrastructure for RDMA tool
Leon Romanovsky [Sun, 20 Aug 2017 09:58:22 +0000 (12:58 +0300)]
rdma: Add basic infrastructure for RDMA tool

RDMA devices are cross-functional devices from one side,
but very tailored for the specific markets from another.

Such diversity caused to spread of RDMA related configuration
across various tools, e.g. devlink, ip, ethtool, ib specific and
vendor specific solutions.

This patch adds ability to fill device and port information
by reading RDMA netlink.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agoutils: Move BIT macro to common header
Leon Romanovsky [Sun, 20 Aug 2017 09:58:21 +0000 (12:58 +0300)]
utils: Move BIT macro to common header

BIT() macro was implemented and used by devlink for now, but following
patches of rdmatool will reuse the same macro, so put it in common
header file.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
6 years agotipc/bearer: Fix resource leak in error path
Phil Sutter [Thu, 17 Aug 2017 17:09:31 +0000 (19:09 +0200)]
tipc/bearer: Fix resource leak in error path

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Fix potential memleak in unix_stats_print()
Phil Sutter [Thu, 17 Aug 2017 17:09:30 +0000 (19:09 +0200)]
ss: Fix potential memleak in unix_stats_print()

Fixes: 2d0e538f3e1cd ("ss: Drop list traversal from unix_stats_print()")
Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoifstat: Fix memleak in dump_kern_db() for json output
Phil Sutter [Thu, 17 Aug 2017 17:09:29 +0000 (19:09 +0200)]
ifstat: Fix memleak in dump_kern_db() for json output

Looks like this was forgotten when converting to common json output
formatter.

Fixes: fcc16c2287bf8 ("provide common json output formatter")
Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoifstat: Fix memleak in error case
Phil Sutter [Thu, 17 Aug 2017 17:09:28 +0000 (19:09 +0200)]
ifstat: Fix memleak in error case

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoipvrf: Fix error path of vrf_switch()
Phil Sutter [Thu, 17 Aug 2017 17:09:27 +0000 (19:09 +0200)]
ipvrf: Fix error path of vrf_switch()

Apart from trying to close(-1), this also leaked memory.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotc/em_ipset: Don't leak sockfd on error path
Phil Sutter [Thu, 17 Aug 2017 17:09:31 +0000 (19:09 +0200)]
tc/em_ipset: Don't leak sockfd on error path

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoss: Don't leak fd in tcp_show_netlink_file()
Phil Sutter [Thu, 17 Aug 2017 17:09:30 +0000 (19:09 +0200)]
ss: Don't leak fd in tcp_show_netlink_file()

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoiproute_lwtunnel: csum_mode value checking was ineffective
Phil Sutter [Thu, 17 Aug 2017 17:09:30 +0000 (19:09 +0200)]
iproute_lwtunnel: csum_mode value checking was ineffective

ila_csum_name2mode() returning -1 on error but being declared as
returning __u8 doesn't make much sense. Change the code to correctly
detect this issue. Checking for __u8 overruns shouldn't be necessary
though since ila_csum_name2mode() return values are well-defined.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoiproute_lwtunnel: Argument to strerror must be positive
Phil Sutter [Thu, 17 Aug 2017 17:09:31 +0000 (19:09 +0200)]
iproute_lwtunnel: Argument to strerror must be positive

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agotipc/node: Fix socket fd check in cmd_node_get_addr()
Phil Sutter [Thu, 17 Aug 2017 17:09:32 +0000 (19:09 +0200)]
tipc/node: Fix socket fd check in cmd_node_get_addr()

socket() returns -1 on error, not 0.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoifcfg: Quote left-hand side of [ ] expression
Phil Sutter [Thu, 17 Aug 2017 17:09:32 +0000 (19:09 +0200)]
ifcfg: Quote left-hand side of [ ] expression

This prevents word-splitting and therefore leads to more accurate error
message in case 'grep -c' prints something other than a number.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoexamples: Some shell fixes to cbq.init
Phil Sutter [Thu, 17 Aug 2017 17:09:31 +0000 (19:09 +0200)]
examples: Some shell fixes to cbq.init

This addresses the following issues:

- $@ is an array, so don't use it in quoted strings - use $* instead.

- Add missing quotes to components of [ ] expressions. These are not
  strictly necessary since the output of 'wc -l' should be a single word
  only, but in case of errors, bash prints "integer expression expected"
  instead of "too many arguments".

- Use -print0/-0 when piping from find to xargs to allow for filenames
  which contain whitespace.

- Quote arguments to 'eval' to prevent word-splitting.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agolibnetlink: Fix extack attribute parsing
David Ahern [Thu, 17 Aug 2017 20:43:00 +0000 (13:43 -0700)]
libnetlink: Fix extack attribute parsing

Initialize tb in nl_dump_ext_err since not all attributes will be
sent in the messages.

Add error checking on mnl_attr_parse and print messages on the off
chance the ext ack attributes fail to validate.

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agobpf: unbreak libelf linkage for bpf obj loader
Daniel Borkmann [Wed, 9 Aug 2017 22:15:41 +0000 (00:15 +0200)]
bpf: unbreak libelf linkage for bpf obj loader

Commit 69fed534a533 ("change how Config is used in Makefile's") moved
HAVE_MNL specific CFLAGS/LDLIBS for building with libmnl out of the
top level Makefile into sub-Makefiles. However, it also removed the
HAVE_ELF specific CFLAGS/LDLIBS entirely, which breaks the BPF object
loader for tc and ip with "No ELF library support compiled in." despite
having libelf detected in configure script. Fix it similarly as in
69fed534a533 for HAVE_ELF.

Fixes: 69fed534a533 ("change how Config is used in Makefile's")
Reported-by: Jeffrey Panneman <jeffrey.panneman@tno.nl>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agolib: Dump ext-ack string by default
David Ahern [Wed, 9 Aug 2017 15:43:27 +0000 (08:43 -0700)]
lib: Dump ext-ack string by default

In time, errfn can be implemented for link, route, etc commands to
give a much more detailed response (e.g., point to the attribute
that failed). Doing so is much more complicated to process the
message and convert attribute ids to names.

In any case the error string returned by the kernel should be dumped
to the user, so make that happen now.

Signed-off-by: David Ahern <dsahern@gmail.com>
6 years agovti: print keys in hex not dotted notation
Stephen Hemminger [Wed, 9 Aug 2017 15:50:25 +0000 (08:50 -0700)]
vti: print keys in hex not dotted notation

The ikey and okey value are normal u32 values. The input accepts
them in dotted, hex or decimal form. For output, hex seems like
the best form since they are not really addresses.

Suggested-by: Christian Langrock <christian.langrock@secunet.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agochange how Config is used in Makefile's
Stephen Hemminger [Wed, 9 Aug 2017 15:45:04 +0000 (08:45 -0700)]
change how Config is used in Makefile's

The recent LIBMNL changes was made more difficult to debug because
of how Config is handle in clean make. The Config file is generated
by top level make, but since it is not recursive, the values generated
would not be visible on a clean make.

The change is to not include Config in top level make, and move
all the conditionals down into sub makefiles. Not ideal, but beter
than going full autoconf route. Or forcing separate configure
step.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agovti6: fix local/remote any addr handling
Stephen Hemminger [Wed, 9 Aug 2017 15:39:27 +0000 (08:39 -0700)]
vti6: fix local/remote any addr handling

According to the IPv4 behavior of 'ip' it should be possible
to omit the arguments for local and remote address.
Without this patch omitting these parameters would lead to
uninitialized memory being interpreted as IPv6 addresses.

Reported-by: Christian Langrock <christian.langrock@secunet.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agotc, ip: more Makefile updates for LIBMNL
Stephen Hemminger [Wed, 9 Aug 2017 15:38:51 +0000 (08:38 -0700)]
tc, ip: more Makefile updates for LIBMNL

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoexamples/bpf: update list of examples
Alexander Alemayhu [Wed, 9 Aug 2017 03:39:07 +0000 (05:39 +0200)]
examples/bpf: update list of examples

Remove deleted examples and add the new map in map example.

Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agolib: need to pass LIBMNL flag
Stephen Hemminger [Wed, 9 Aug 2017 15:33:11 +0000 (08:33 -0700)]
lib: need to pass LIBMNL flag

Missed on earlier conversion.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agolib: fix extended ack with and without libmnl
Stephen Hemminger [Mon, 7 Aug 2017 18:43:21 +0000 (11:43 -0700)]
lib: fix extended ack with and without libmnl

The code was always building without libmnl support, so it was
doing nothing.

Fixes: b6432e68ac2f ("iproute: Add support for extended ack to rtnl_talk")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agonetns: make /var/run/netns bind-mount recursive
Casey Callendrello [Tue, 1 Aug 2017 15:46:09 +0000 (17:46 +0200)]
netns: make /var/run/netns bind-mount recursive

When ip netns {add|delete} is first run, it bind-mounts /var/run/netns
on top of itself, then marks it as shared. However, if there are already
bind-mounts in the directory from other tools, these would not be
propagated. Fix this by recursively bind-mounting.

Signed-off-by: Casey Callendrello <casey.callendrello@coreos.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
6 years agoss: enclose IPv6 address in brackets
Stephen Hemminger [Fri, 4 Aug 2017 19:02:41 +0000 (12:02 -0700)]
ss: enclose IPv6 address in brackets

Based on patch by Lehner Florian <dev@der-flo.net>

Adds support for RFC2732 IPv6 address format with brackets.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoiproute: Add support for extended ack to rtnl_talk
Stephen Hemminger [Fri, 4 Aug 2017 16:52:15 +0000 (09:52 -0700)]
iproute: Add support for extended ack to rtnl_talk

Add support for extended ack error reporting via libmnl.
Add a new function rtnl_talk_extack that takes a callback as an input
arg. If a netlink response contains extack attributes, the callback is
is invoked with the the err string, offset in the message and a pointer
to the message returned by the kernel.

If iproute2 is built without libmnl, it will still work but
extended error reports from kernel will not be available.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agotc: fix m_simple usage
Stephen Hemminger [Thu, 3 Aug 2017 23:10:18 +0000 (16:10 -0700)]
tc: fix m_simple usage

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agotc-simple: Fix documentation
Phil Sutter [Thu, 3 Aug 2017 15:00:51 +0000 (17:00 +0200)]
tc-simple: Fix documentation

- CONTROL has to come last, otherwise 'index' applies to gact and not
  simple itself.
- Man page wasn't updated to reflect syntax changes.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoReally fix get_addr() and get_prefix() error messages
Phil Sutter [Tue, 1 Aug 2017 16:36:11 +0000 (18:36 +0200)]
Really fix get_addr() and get_prefix() error messages

Both functions take the desired address family as a parameter. So using
that to notify the user what address family was expected is correct,
unlike using dst->family which will tell the user only what address
family was specified.

The situation which commit 334af76143368 tried to fix was when 'ip'
would accept addresses from multiple families. In that case, the family
parameter is set to AF_UNSPEC so that get_addr_1() may accept any valid
address.

This patch introduces a wrapper around family_name() which returns the
string "any valid" for AF_UNSPEC instead of the three question marks
unsuitable for use in error messages.

Tests for AF_UNSPEC:

| # ip a a 256.10.166.1/24 dev d0
| Error: any valid prefix is expected rather than "256.10.166.1/24".

| # ip neighbor add proxy 2001:db8::g dev d0
| Error: any valid address is expected rather than "2001:db8::g".

Tests for explicit address family:

| # ip -6 addrlabel add prefix 1.1.1.1/24 label 123
| Error: inet6 prefix is expected rather than "1.1.1.1/24".

| # ip -4 addrlabel add prefix dead:beef::1/24 label 123
| Error: inet prefix is expected rather than "dead:beef::1/24".

Reported-by: Jaroslav Aster <jaster@redhat.com>
Fixes: 334af76143368 ("fix get_addr() and get_prefix() error messages")
Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoupdate headers from 4.13-rc4
Stephen Hemminger [Thu, 3 Aug 2017 22:57:26 +0000 (15:57 -0700)]
update headers from 4.13-rc4

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agobpf: Make bytecode-file reading a little more robust
Phil Sutter [Wed, 2 Aug 2017 12:57:56 +0000 (14:57 +0200)]
bpf: Make bytecode-file reading a little more robust

bpf_parse_string() will now correctly handle:

- Extraneous whitespace,
- OPs on multiple lines and
- overlong file names.

The added feature of allowing to have OPs on multiple lines (like e.g.
tcpdump prints them) is rather a side effect of fixing detection of
malformed bytecode files having random content on a second line, like
e.g.:

| 4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0
| foobar

Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agoip: change flag names to an array
Stephen Hemminger [Fri, 7 Jul 2017 15:37:19 +0000 (08:37 -0700)]
ip: change flag names to an array

For the most of the address flags, use a table of values rather
than open coding every value.  This allows for easier inevitable
expansion of flags.

This also fixes the missing stable-privacy flag.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoUpdate headers from net-next
Stephen Hemminger [Tue, 1 Aug 2017 03:55:14 +0000 (20:55 -0700)]
Update headers from net-next

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
6 years agoutils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR
Hangbin Liu [Thu, 27 Jul 2017 09:44:15 +0000 (17:44 +0800)]
utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR

When we get a multicast route, the rtm_type is RTN_MULTICAST, but the
rtm_family may be AF_INET. If we only check the type with RTNL_FAMILY_IPMR,
we will get malformed address. e.g.

+ ip -4 route add multicast 172.111.1.1 dev em1 table main

Before fix:
+ ip route list type multicast table main
multicast ac6f:101:800:400:400:0:3c00:0 dev em1 scope link

After fix:
+ ip route list type multicast table main
multicast 172.111.1.1 dev em1 scope link

Fixes: 56e3eb4c3400 ("ip: route: fix multicast route dumps")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Acked-by: Phil Sutter <phil@nwl.cc>
6 years agonetns: more input validation
Matteo Croce [Tue, 25 Jul 2017 13:30:31 +0000 (15:30 +0200)]
netns: more input validation

ip netns accepts invalid input as namespace name like an empty string or a
string longer than the maximum file name length.
Check that the netns name is not empty and less than or equal to NAME_MAX.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
6 years agogeneve: support for modifying geneve device
Girish Moodalbail [Wed, 26 Jul 2017 02:11:43 +0000 (19:11 -0700)]
geneve: support for modifying geneve device

Ability to change geneve device attributes was added to kernel through
commit 5b861f6baa3a ("geneve: add rtnl changelink support"), however one
cannot do the same through ip-link(8) command.  Changing the allowed
geneve device attributes using 'ip link set <geneve_name> type geneve id
<geneve_id> <allowed_attributes>' currently fails with 'operation not
supported' error.  This patch adds support for it.

Signed-off-by: Girish Moodalbail <girish.moodalbail@oracle.com>
6 years agobpf: fix mnt path when from env
Daniel Borkmann [Sat, 22 Jul 2017 23:22:19 +0000 (01:22 +0200)]
bpf: fix mnt path when from env

When bpf fs mount path is from env, behavior is currently broken as
we continue to search in default paths, thus fix this up.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agobpf: improve error reporting around tail calls
Daniel Borkmann [Sat, 22 Jul 2017 23:22:18 +0000 (01:22 +0200)]
bpf: improve error reporting around tail calls

Currently, it's still quite hard to figure out if a prog passed the
verifier, but later gets rejected due to different tail call ownership.
Figure out whether that is the case and provide appropriate error
messages to the user.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
6 years agoip route: replace exits with returns
Élie Bouttier [Sat, 22 Jul 2017 22:42:02 +0000 (00:42 +0200)]
ip route: replace exits with returns

This patch replaces exits with returns in ip route
commands.

Allows to continue when invoked with ip -batch.

Signed-off-by: Élie Bouttier <elie@bouttier.eu>