summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* treewide: Use addattr_nest()/addattr_nest_end() to handle nested attributesSerhey Popovych2018-02-0251-193/+132
| | | | | | | | | | 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>
* ip: Minor cleanupsSerhey Popovych2018-02-029-38/+38
| | | | | | | | | | | 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>
* ip: Consolidate ip, xdp and lwtunnel parse/dump prototypes in ip_common.hSerhey Popovych2018-02-029-37/+25
| | | | | | | | | | | | 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>
* Revert "ip address: Change print_linkinfo_brief to take filter as an input"Serhey Popovych2018-02-013-22/+17
| | | | | | | | | | | | | | | | | 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>
* Merge branch 'iproute2-master' into iproute2-nextDavid Ahern2018-01-293-3/+3
|\ | | | | | | Signed-off-by: David Ahern <dsahern@gmail.com>
| * v4.15.0v4.15.0Stephen Hemminger2018-01-291-1/+1
| |
| * tc: fix second printing of requeuesJakub Kicinski2018-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Non-JSON tc qdisc output used to print the "requeues" statistic twice. Commit 4fcec7f3665b ("tc: jsonify stats2") tried to preserve this behaviour for both standard output and JSON, but used the wrong statistic (q.qlen). Also duplicating keys in JSON is not allowed, so the second occurrence should be completely skipped with JSON. Fixes: 4fcec7f3665b ("tc: jsonify stats2") Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * ip: address: fix stats64 JSON object nameJakub Kicinski2018-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The JSON object name for statistics in ip link show is "stats644". Looks like a typo, commit d0e720111aad ("ip: ipaddress.c: add support for json output") contains an example with the expected "stats64" name. The fact that no one has noticed until now is probably an indication that no one is using this object. Hopefully it's not too late to fix this, although IIUC this has already been in 4.13 and 4.14 releases :S Fixes: d0e720111aad ("ip: ipaddress.c: add support for json output") Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* | tc: prio: JSON-ify prio outputJakub Kicinski2018-01-261-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | Make JSON output work with prio Qdiscs. This will also make other qdiscs which reuse the print_qopt work, like mqprio or pfifo_fast. Note that there is a double space between "priomap" and first prio number. Keep this original behaviour. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* | tc: red: JSON-ify RED outputJakub Kicinski2018-01-264-19/+28
| | | | | | | | | | | | | | | | | | | | Make JSON output work with RED Qdiscs. Float/double printing helpers have to be added/uncommented to print the probability. Since TC stats in general are not split out to a separate object the xstats printed by this patch are not separated either. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* | Merge branch 'get_addr_rta' into iproute2-nextDavid Ahern2018-01-2516-246/+206
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Serhey Popovych says: ==================== Now we enhance get_addr() to return additional information about address (e.g. if it unspecified or multicast) we want to have same functionality for attributes in netlink message. Introduce and use get_addr_rta() that parses given netlink attribute into @inet_prefix data structure in the same way similar get_addr() parses address from it's string representation. Use attribute length to guess address family: force it by giving non AF_UNSPEC @family to get_addr_rta() to ensure address is of expected family. Introduce and use inet_addr_match_rta() to further simplify and unify code where get_addr_rta() intended to be used together with inet_addr_match(). This is next step in ipv4 and ipv6 modules unification to prepare for merge in the future. ==================== Signed-off-by: David Ahern <dsahern@gmail.com>
| * | ip/tunnel: Unify local/remote endpoint address printingSerhey Popovych2018-01-258-113/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce and use tnl_print_endpoint() helper to print of tunnel endpoint address. Note that for AF_INET and AF_INET6 inet_ntop(3) is used that may return NULL in case of failure and while unlikely format_host_rta() might return NULL too. Handle this case when passing local/remote to print_string(). Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | tcp_metric: Use get_addr_rta()Serhey Popovych2018-01-251-30/+30
| | | | | | | | | | | | | | | | | | | | | While there remove & from inet_prefix.data when since it is array. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | ipl2tp: Use get_addr_rta()Serhey Popovych2018-01-251-21/+16
| | | | | | | | | | | | | | | Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | ipneigh: Use inet_addr_match_rta()Serhey Popovych2018-01-251-9/+4
| | | | | | | | | | | | | | | | | | | | | While there check return from get_prefix() for filter address. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | ipmroute: Use inet_addr_match_rta()Serhey Popovych2018-01-251-16/+10
| | | | | | | | | | | | | | | | | | | | | While there check return from get_prefix() for filter address. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | iprule: Use inet_addr_match_rta()Serhey Popovych2018-01-251-18/+18
| | | | | | | | | | | | | | | | | | | | | While there check return from get_prefix() for filter address. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | ipaddress: Use inet_addr_match_rta()Serhey Popovych2018-01-251-20/+9
| | | | | | | | | | | | | | | | | | | | | While there check return from get_prefix() for filter address. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | utils: Introduce get_addr_rta() and inet_addr_match_rta()Serhey Popovych2018-01-252-19/+78
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First is used to get address from netlink attribute to inet_prefix data structure. Use memcpy() with constant value to let complier optimize by replacing a call by inlining load/store instructions. Second is used to match address in given netlink attribute with one given as reference. It matches successfully if no attribute is given (@rta is NULL), reference address family is AF_UNSPEC or it's length isn't given; fails if get_attr_rta() can't get attribute or it's family does not match reference; calls inet_addr_match() to get final verdict. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* | Merge branch 'unify_external' into iproute2-nextDavid Ahern2018-01-246-43/+52
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Serhey Popovych says: ==================== With this series I want to unify collect metadata handling in tunnels: 1) Use "external" name for JSON and non-JSON output. Do not *print* any options when tunnel in collect metadata mode: gre6 already do this, so just apply to others. 2) Do not *add* any attributes when configuring gre tunnel in collect metadata mode. Other tunnels (e.g. gre6, iptnl, ip6tnl) alredy do that. This is next step in ipv4 and ipv6 modules unification to prepare for merge in the future. Any comments, suggestions and criticism as always welcome. v2 For all tunnels implementing collect metadata use "external" keyword for both JSON. Thanks to Jiri Benc for detailed explanation. ==================== Signed-off-by: David Ahern <dsahern@gmail.com>
| * | gre/gre6: Unify attribute addition to netlink bufferSerhey Popovych2018-01-242-16/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are couple of minor improvements: 1) Check erspan_ver == 2 in gre6. It still could be 1 if erspan_idx is 0. 2) Add tunnel encapsulation attributes only when collect metadata not in effect in gre. 3) Trivial: address checkpatch issues. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | ip/tunnel: Be consistent when printing tunnel collect metadataSerhey Popovych2018-01-246-27/+32
|/ / | | | | | | | | | | | | | | | | | | | | | | Print only "external" if collect meta data attribute is given: rest of parameters are irrelevant. This is to follow gre6. For both JSON and non-JSON output use "external" for all tunnels including vxlan and geneve. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* | Merge branch 'iproute2-master' into iproute2-nextDavid Ahern2018-01-2415-43/+43
|\| | | | | | | Signed-off-by: David Ahern <dsahern@gmail.com>
| * tc/lexer: let quotes actually start stringsWolfgang Bumiller2018-01-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | The lexer will go with the longest match, so previously the starting double quotes of a string would be swallowed by the [^ \t\r\n()]+ pattern leaving the user no way to actually use strings with escape sequences. Fix this by not allowing this case to start with double quotes. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
| * iplink: Use ll_name_to_index() instead of if_nametoindex()Serhey Popovych2018-01-2313-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While benefit from using ll_name_to_index() with populated cache can potentially be exploited only in few places (e.g. bridge fdb/mdb/vlan show routines) there is another advantage of ll_name_to_index() over plain if_nametoindex(): in case of if_nametoindex() failure ll_name_to_index() will attempt to get index from common name in form "if%d" that may be returned from ll_index_to_name(). This makes output from ip(8) coherent with it's input. Note that most of the code already switched from plain if_nametoindex() to ll_name_to_index() to cached variant. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * vti/vti6: Minor improvementsSerhey Popovych2018-01-232-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In prepare of link_vti.c and link_vti6.c merge: 1) Make @fwmark of __u32 type instead of unsigned int in vti to match with rest tunneling code. 2) Report when unable to translate @link network device name to index instead of silently exiting in vti6. 3) Remove newline separating local/remote attributes from the ikey/okey in vti6 to match vti module. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * iptnl/ip6tnl: Unify ttl/hoplimit parsing routinesSerhey Popovych2018-01-234-21/+19
| | | | | | | | | | | | | | | | | | | | | | | | Handle "inherit" case properly for gre6 and ip6tnl. Use get_u8() in gre to parse ttl/hoplimit. Be consistent about "hlim" alias to ttl/hoplimit support. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * tunnel: Add space between encap-dport and encap-sport in non-JSON outputSerhey Popovych2018-01-231-2/+2
| | | | | | | | | | | | | | Fixes: bad76e6b1f44 ("ip/tunnel: Abstract tunnel encapsulation options printing") Fixes: e2d4588331fc ("ip: link_gre.c: add json output support") Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* | gre/gre6: Post merge fixesSerhey Popovych2018-01-222-45/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Few minor changes after merge of 'master' into 'net-next' branch: 1) Follow 80 line length for printing erspan_index parameter as we did in master with commit 2a8d0f6e9c3f ("gre/tunnel: Print erspan_index using print_uint()"). 2) Remove remnants of encapsulation option printing: now it is done using tnl_print_encap() helper in commit bad76e6b1f44 ("ip/tunnel: Abstract tunnel encapsulation options printing"). Fixes: 8c75f69411bc ("Merge branch 'master' into net-next") Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
* | Merge branch 'shared_block' into net-nextDavid Ahern2018-01-214-18/+210
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Jiri Pirko says: ==================== From: Jiri Pirko <jiri@mellanox.com> Kernel allows to share all filters between qdiscs with use of shared block. Example: block number 22. "22" is just an identification: $ tc qdisc add dev ens7 ingress_block 22 ingress ^^^^^^^^^^^^^^^^ $ tc qdisc add dev ens8 ingress_block 22 ingress ^^^^^^^^^^^^^^^^ If we don't specify "block" command line option, no shared block would be created: $ tc qdisc add dev ens9 ingress Now if we list the qdiscs, we will see the block index in the output: $ tc qdisc qdisc ingress ffff: dev ens7 parent ffff:fff1 ingress_block 22 qdisc ingress ffff: dev ens8 parent ffff:fff1 ingress_block 22 qdisc ingress ffff: dev ens9 parent ffff:fff1 To make is more visual, the situation looks like this: ens7 ingress qdisc ens7 ingress qdisc | | | | +----------> block 22 <----------+ Unlimited number of qdiscs may share the same block. Block sharing is also supported for clsact qdisc: $ tc qdisc add dev ens10 ingress_block 23 egress_block 24 clsact $ tc qdisc show dev ens10 qdisc clsact ffff: dev ens10 parent ffff:fff1 ingress_block 23 egress_block 24 We can add filter using the block index: $ tc filter add block 22 protocol ip pref 25 flower dst_ip 192.168.0.0/16 action drop Note we cannot use the qdisc for filter manipulations of shared blocks: $ tc filter add dev ens8 ingress protocol ip pref 1 flower dst_ip 192.168.100.2 action drop Error: This filter block is shared. Please use the block index to manipulate the filters. We will see the same output if we list filters for ingress qdisc of ens7 and ens8, also for the block 22: $ tc filter show block 22 filter protocol ip pref 25 flower chain 0 filter protocol ip pref 25 flower chain 0 handle 0x1 ... $ tc filter show dev ens7 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ... $ tc filter show dev ens8 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ... ==================== Signed-off-by: David Ahern <dsahern@gmail.com>
| * | tc: implement ingress/egress block index attributes for qdiscsJiri Pirko2018-01-212-1/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | During qdisc creation it is possible to specify shared block for bot ingress and egress. Pass this values to kernel according to the command line options. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | tc: introduce support for block-handle for filter operationsJiri Pirko2018-01-212-17/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So far, qdisc was the only handle that could be used to manipulate filters. Kernel added support for using block to manipulate it. So add the support to use block index to manipulate filters. The magic TCM_IFINDEX_MAGIC_BLOCK indicates the block index is in use. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | tc: introduce tc_qdisc_block_exists helperJiri Pirko2018-01-212-0/+63
|/ / | | | | | | | | | | | | | | | | This hepler used qdisc dump to list all qdisc and find if block index in question is used by any of them. That means the block with specified index exists. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* | Merge branch 'inet_get_addr' into net-nextDavid Ahern2018-01-216-110/+142
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Serhey Popovych says: ==================== It looks confusing to have multiple independent routines to get internet address from it's string representation: get_addr() and inet_get_addr(). Most complicated users of inet_get_addr() is iplink_geneve.c and iplink_vxlan.c because they required to handle both AF_INET and AF_INET6 for their local/remote endpoints. On the other hand get_addr() does not provide additional information like address type: need to address this. to get rid of current and possible future code duplications. Note that this functionality is first step to make proto independent handling of local/remote endpoints in ip/tunnel code (there will be additional series based on this one). Also fix get_addr_1() and get_prefix() to make sure it always provide correct ->family and ->bitlen. As always comments, suggestions and criticism are welcome. ==================== Signed-off-by: David Ahern <dsahern@gmail.com>
| * | ip: Get rid of inet_get_addr()Serhey Popovych2018-01-214-15/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Both geneve and vxlan modules are converted to use get_addr() we can replace inet_get_addr() in less problematic places and finally get rid of inet_get_addr(). Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | iplink_vxlan: Get rid of inet_get_addr()Serhey Popovych2018-01-211-46/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | Now we have additional information about address class from get_addr() we can use it in place of inet_get_addr(). Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | iplink_geneve: Get rid of inet_get_addr()Serhey Popovych2018-01-211-13/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | Now we have additional information about address class from get_addr() we can use it in place of inet_get_addr(). Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | utils: Fast inet address classification after get_addr()Serhey Popovych2018-01-212-2/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It looks very useful to receive additional information from get_addr_1() and get_addr() about address to simplify caller and get rid of code duplications. For now following information can be returned: 1) address is unspecified (zero) 2) address is multicast 3) address is internet: family is either AF_INET or AF_INET6. More information can be added in the future. Introduce inline helpers to make code using this new address classification interface more self explaining: bool is_addrtype_inet(inet_prefix *addr) true if @addr is inet address bool is_addrtype_inet_unspec(inet_prefix *addr) true if @addr is unspecified inet address bool is_addrtype_inet_multi(inet_prefix *addr) true if @addr is multicast inet address bool is_addrtype_inet_not_unspec(inet_prefix *addr) true if @addr is not unspecified inet address false if @addr is not inet or unspecified inet bool is_addrtype_inet_not_multi(inet_prefix *addr) true if @addr is not multicast inet address false if @addr is not inet or multicast inet Last two are useful for case when we need inet address that is not unspecified or multicast. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | utils: Always specify family and ->bytelen in get_prefix_1()Serhey Popovych2018-01-211-32/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle default/all/any special case in get_addr_1() to setup ->family and ->bytelen correctly. Make get_addr_1() return ->bitlen == -2 instead of -1 to distinguish default/all/any special case from the rest: it is safe because all callers check ->bitlen < 0, not explicit value -1. Reduce intendation by one level and get rid of goto/label to make code more readable. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
| * | utils: Always specify family for address in get_addr_1()Serhey Popovych2018-01-211-2/+2
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | Set ->family correctly when string representing address is "default", "all" or "any": get_addr_1() might be called with AF_UNSPEC (e.g. get_addr() -> get_addr_1()). Extend support for zero address to all address families, not only AF_INET and AF_INET6 when one explicitly given as @family: use af_byte_len() to correctly set address length. Still assume AF_INET when @family is AF_UNSPEC. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* | Merge branch 'master' into net-nextDavid Ahern2018-01-2133-629/+440
|\| | | | | | | | | | | | | | | Conflicts: ip/link_gre.c ip/link_gre6.c Signed-off-by: David Ahern <dsahern@gmail.com>
| * tunnel: Return constant string without copying itSerhey Popovych2018-01-181-18/+7
| | | | | | | | | | | | | | | | | | We return constant string from tnl_strproto(), no need to copy it to temporary buffer and then return such buffer as const: return constant string instead. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * vti6/tunnel: Unify and simplify link type help functionsSerhey Popovych2018-01-181-10/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | Both of these two changes are missing for link_vti6.c: commit 8b47135474cd ("ip: link: Unify link type help functions a bit") commit 561e650eff67 ("ip link: Shortify printing the usage of link type") Replay them on link_vti6.c to bring link type help functions inline with other tunneling code. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * vti/tunnel: Unify ikey/okey printingSerhey Popovych2018-01-182-12/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For vti6 tunnel we print [io]key in dotted-quad notation (ipv4 address) while in vti we do that in hex format. For vti tunnel we print [io]key only if value is not zero while for vti6 we miss such check. Unify vti and vti6 tunnel [io]key output. While here enlarge s2 buffer to the same size as in rest of tunnel support code (64 bytes) and check return from inet_ntop(). Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * gre/tunnel: Print erspan_index using print_uint()Serhey Popovych2018-01-182-2/+5
| | | | | | | | | | | | | | | | One is missing in JSON output because fprintf() is used instead of print_uint(). Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * ip/tunnel: Abstract tunnel encapsulation options printingSerhey Popovych2018-01-186-251/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Get rid of code duplications and consolidate encapsulation options printing in single function - tnl_print_encap(). Introduce and use tnl_encap_str() to format encapsulation option string according to tempate and given values to avoid code duplication and simplify it. Use print_string() instead of fputs() and fprintf() to print encapsulation for !is_json_context(). Print "unknown" parameter for "encap" type in PRINT_FP context using "%s " format specifier and benefit from complite time string merge. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * ip/tunnel: Use print_0xhex() instead of print_string()Serhey Popovych2018-01-186-37/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No need for custom SPRINT_BUF() and snprintf() 0x%x value to this buffer: we can use print_0xhex() instead of print_string(). In link_iptnl.c use s2 instead of s1 buffer and remove s1. While there adjust fwmark option print order in iptnl and ip6tnl to get it match each other. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * ip/tunnel: Simplify and unify tos printingSerhey Popovych2018-01-184-55/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | For ip tunnels tos can be 0 when not configured, 1 when inherited from encapsulated packet and rest specifying diffserv (rfc2474) or tos (rfc1349) bits. It is stored in packet tos/diffserv field and returned in tos netlink attribute to userspace. Simplify and unify tos printing by using print_0xhex() and print_string() instead of fprintf() to output values. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * ip/tunnel: Correct and unify ttl/hoplimit printingSerhey Popovych2018-01-189-50/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Both ttl/hoplimit is from 1 to 255. Zero has special meaning: use encapsulated packet value. In ip-link(8) -d output this looks like "ttl/hoplimit inherit". In JSON we have "int" type for ttl and therefore values from 0 (inherit) to 255. To do the best in handling ttl/hoplimit we need to accept both cases: missing attribute in netlink dump and zero value for "inherit"ed case. Last one is broken since JSON output introduction for gre/iptnl versions and was never true for gre6/ip6tnl. For all tunnels, except ip6tnl change JSON type from "int" to "uint" to reflect true nature of the ttl. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
| * iplink: Use ll_index_to_name() instead of if_indextoname()Serhey Popovych2018-01-1811-92/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two reasons for switching to cached variant: 1) ll_index_to_name() may return result from cache, eliminating expensive ioctl() to the kernel. Note that most of the code already switched from plain if_indextoname() to ll_index_to_name() to cached variant in print path because in most cases cache populated. 2) It always return name in the form "if%d", even if entry is not in cache and ioctl() fails. This drops "link_index" from JSON output. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>