From 52d767aff8632e098891479d16de204a9ec0464b Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 11 Aug 2020 13:18:41 -0700 Subject: [PATCH 1/9] uapi: update kernel headers pre-rc1 version of Linux kernel headers. Signed-off-by: Stephen Hemminger --- include/uapi/linux/bpf.h | 24 ++++++++++++++++++++++-- include/uapi/linux/seg6_iptunnel.h | 1 - 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 378eda20..eeb98d35 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -117,6 +117,7 @@ enum bpf_cmd { BPF_LINK_GET_NEXT_ID, BPF_ENABLE_STATS, BPF_ITER_CREATE, + BPF_LINK_DETACH, }; enum bpf_map_type { @@ -230,6 +231,7 @@ enum bpf_attach_type { BPF_CGROUP_INET_SOCK_RELEASE, BPF_XDP_CPUMAP, BPF_SK_LOOKUP, + BPF_XDP, __MAX_BPF_ATTACH_TYPE }; @@ -242,10 +244,18 @@ enum bpf_link_type { BPF_LINK_TYPE_CGROUP = 3, BPF_LINK_TYPE_ITER = 4, BPF_LINK_TYPE_NETNS = 5, + BPF_LINK_TYPE_XDP = 6, MAX_BPF_LINK_TYPE, }; +enum bpf_iter_link_info { + BPF_ITER_LINK_UNSPEC = 0, + BPF_ITER_LINK_MAP_FD = 1, + + MAX_BPF_ITER_LINK_INFO, +}; + /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command * * NONE(default): No further bpf programs allowed in the subtree. @@ -607,7 +617,10 @@ union bpf_attr { struct { /* struct used by BPF_LINK_CREATE command */ __u32 prog_fd; /* eBPF program to attach */ - __u32 target_fd; /* object to attach to */ + union { + __u32 target_fd; /* object to attach to */ + __u32 target_ifindex; /* target ifindex */ + }; __u32 attach_type; /* attach type */ __u32 flags; /* extra flags */ } link_create; @@ -622,6 +635,10 @@ union bpf_attr { __u32 old_prog_fd; } link_update; + struct { + __u32 link_fd; + } link_detach; + struct { /* struct used by BPF_ENABLE_STATS command */ __u32 type; } enable_stats; @@ -3229,7 +3246,7 @@ union bpf_attr { * Return * The id is returned or 0 in case the id could not be retrieved. * - * int bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags) + * long bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags) * Description * Copy *size* bytes from *data* into a ring buffer *ringbuf*. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification @@ -4057,6 +4074,9 @@ struct bpf_link_info { __u32 netns_ino; __u32 attach_type; } netns; + struct { + __u32 ifindex; + } xdp; }; } __attribute__((aligned(8))); diff --git a/include/uapi/linux/seg6_iptunnel.h b/include/uapi/linux/seg6_iptunnel.h index 3004e982..ee6d1dd5 100644 --- a/include/uapi/linux/seg6_iptunnel.h +++ b/include/uapi/linux/seg6_iptunnel.h @@ -37,5 +37,4 @@ enum { SEG6_IPTUN_MODE_L2ENCAP, }; - #endif From 7ded3c97b9836f2ae0bf21fc79d8559357acb190 Mon Sep 17 00:00:00 2001 From: Leon Romanovsky Date: Tue, 11 Aug 2020 10:32:00 +0300 Subject: [PATCH 2/9] rdma: Fix owner name for the kernel resources Owner of kernel resources is printed in different format than user resources to easy with the reader by simply looking on the name. The kernel owner will have "[ ]" around the name. Before this change: [leonro@vm ~]$ rdma res show qp link rocep0s9/1 lqpn 1 type GSI state RTS sq-psn 58 comm ib_core After this change: [leonro@vm ~]$ rdma res show qp link rocep0s9/1 lqpn 1 type GSI state RTS sq-psn 58 comm [ib_core] Fixes: b0a688a542cd ("rdma: Rewrite custom JSON and prints logic to use common API") Signed-off-by: Leon Romanovsky Signed-off-by: Stephen Hemminger --- rdma/res.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rdma/res.c b/rdma/res.c index c99a1fcb..b7a703f8 100644 --- a/rdma/res.c +++ b/rdma/res.c @@ -157,11 +157,11 @@ void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line) if (!str) return; - if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) + if (nla_line[RDMA_NLDEV_ATTR_RES_PID] || rd->json_output) snprintf(tmp, sizeof(tmp), "%s", str); else snprintf(tmp, sizeof(tmp), "[%s]", str); - print_color_string(PRINT_ANY, COLOR_NONE, "comm", "comm %s ", str); + print_color_string(PRINT_ANY, COLOR_NONE, "comm", "comm %s ", tmp); } void print_dev(struct rd *rd, uint32_t idx, const char *name) From db6d6becb0b39c49a1491a88f965ad188b88e9ee Mon Sep 17 00:00:00 2001 From: Leon Romanovsky Date: Tue, 11 Aug 2020 10:32:01 +0300 Subject: [PATCH 3/9] rdma: Properly print device and link names in CLI output The citied commit broke the CLI output and printed ifindex/ifname instead of dev/link. Before: [leonro@vm ~]$ rdma res show qp link mlx5_0/lqpn 1 type GSI state RTS sq-psn 0 comm ib_core [leonro@vm ~]$ rdma res show cq ifindex 0 ifname rocep0s9 cqn 0 cqe 1023 users 2 poll-ctx WORKQUEUE adaptive-moderation on comm ib_core After: [leonro@vm ~]$ rdma res show qp link mlx5_0/- lqpn 1 type GSI state RTS sq-psn 0 comm [ib_core] [leonro@vm ~]$ rdma res show cq dev rocep0s9 cqn 0 cqe 1023 users 2 poll-ctx WORKQUEUE adaptive-moderation on comm [ib_core] It was missed because rdmatool mostly used in JSON mode. Fixes: b0a688a542cd ("rdma: Rewrite custom JSON and prints logic to use common API") Signed-off-by: Leon Romanovsky Signed-off-by: Stephen Hemminger --- rdma/res.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/rdma/res.c b/rdma/res.c index b7a703f8..dc12bbe4 100644 --- a/rdma/res.c +++ b/rdma/res.c @@ -166,17 +166,27 @@ void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line) void print_dev(struct rd *rd, uint32_t idx, const char *name) { - print_color_int(PRINT_ANY, COLOR_NONE, "ifindex", "ifindex %d ", idx); - print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "ifname %s ", name); + print_color_int(PRINT_ANY, COLOR_NONE, "ifindex", NULL, idx); + print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "dev %s ", name); } void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port, struct nlattr **nla_line) { + char tmp[64] = {}; + print_color_uint(PRINT_JSON, COLOR_NONE, "ifindex", NULL, idx); - print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "link %s/", name); - if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]) - print_color_uint(PRINT_ANY, COLOR_NONE, "port", "%u ", port); + print_color_string(PRINT_ANY, COLOR_NONE, "ifname", NULL, name); + if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]) { + print_color_uint(PRINT_ANY, COLOR_NONE, "port", NULL, port); + snprintf(tmp, sizeof(tmp), "%s/%d", name, port); + } else { + snprintf(tmp, sizeof(tmp), "%s/-", name); + } + + if (!rd->json_output) + print_color_string(PRINT_ANY, COLOR_NONE, NULL, "link %s ", + tmp); } void print_qp_type(struct rd *rd, uint32_t val) From bf538de59d0813861fbad086d64a390002739447 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 16 Aug 2020 16:09:52 -0700 Subject: [PATCH 4/9] uapi: update bpf.h Signed-off-by: Stephen Hemminger --- include/uapi/linux/bpf.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index eeb98d35..faf7df1d 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -81,6 +81,12 @@ struct bpf_cgroup_storage_key { __u32 attach_type; /* program attach type */ }; +union bpf_iter_link_info { + struct { + __u32 map_fd; + } map; +}; + /* BPF syscall commands, see bpf(2) man-page for details. */ enum bpf_cmd { BPF_MAP_CREATE, @@ -249,13 +255,6 @@ enum bpf_link_type { MAX_BPF_LINK_TYPE, }; -enum bpf_iter_link_info { - BPF_ITER_LINK_UNSPEC = 0, - BPF_ITER_LINK_MAP_FD = 1, - - MAX_BPF_ITER_LINK_INFO, -}; - /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command * * NONE(default): No further bpf programs allowed in the subtree. @@ -623,6 +622,8 @@ union bpf_attr { }; __u32 attach_type; /* attach type */ __u32 flags; /* extra flags */ + __aligned_u64 iter_info; /* extra bpf_iter_link_info */ + __u32 iter_info_len; /* iter_info length */ } link_create; struct { /* struct used by BPF_LINK_UPDATE command */ From 7e7a1d107b7f2bb729836de25c4983f9615a2aa1 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 17 Aug 2020 13:25:19 +0200 Subject: [PATCH 5/9] iproute2: ip maddress: Check multiaddr length ip maddress add|del takes a MAC address as argument, so insist on getting a length of ETH_ALEN bytes. This makes sure the passed argument is actually a MAC address and especially not an IPv4 address which was previously accepted and silently taken as a MAC address. While at it, do not print *argv in the error path as this has been modified by ll_addr_a2n() and doesn't contain the full string anymore, which can lead to misleading error messages. Also while at it, replace the hardcoded buffer size with the actual buffer size using sizeof(). Signed-off-by: Sascha Hauer Signed-off-by: Stephen Hemminger --- ip/ipmaddr.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c index 3400e055..d41ac63a 100644 --- a/ip/ipmaddr.c +++ b/ip/ipmaddr.c @@ -291,7 +291,7 @@ static int multiaddr_modify(int cmd, int argc, char **argv) { struct ifreq ifr = {}; int family; - int fd; + int fd, len; if (cmd == RTM_NEWADDR) cmd = SIOCADDMULTI; @@ -313,9 +313,14 @@ static int multiaddr_modify(int cmd, int argc, char **argv) usage(); if (ifr.ifr_hwaddr.sa_data[0]) duparg("address", *argv); - if (ll_addr_a2n(ifr.ifr_hwaddr.sa_data, - 14, *argv) < 0) { - fprintf(stderr, "Error: \"%s\" is not a legal ll address.\n", *argv); + len = ll_addr_a2n(ifr.ifr_hwaddr.sa_data, + sizeof(ifr.ifr_hwaddr.sa_data), + *argv); + if (len < 0) + exit(1); + + if (len != ETH_ALEN) { + fprintf(stderr, "Error: Invalid address length %d - must be %d bytes\n", len, ETH_ALEN); exit(1); } } From 8e6bce735a132150c23503a55ea0aef55a01425f Mon Sep 17 00:00:00 2001 From: Amit Cohen Date: Thu, 20 Aug 2020 16:51:13 +0300 Subject: [PATCH 6/9] devlink: Add fflush() in cmd_mon_show_cb() Similar to other print functions we need to flush buffered data in order to work with pipes and output redirects. Without it, stdout output is buffered and not written to the disk. This is useful when writing scripts that rely on devlink-monitor output. Signed-off-by: Amit Cohen Reviewed-by: Ido Schimmel Reviewed-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index 8ec96c01..007677a5 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -4654,6 +4654,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) pr_out_trap_policer(dl, tb, false); break; } + fflush(stdout); return MNL_CB_OK; } From 68f027724b5fa0854b63d3346a38cb9c62fe1493 Mon Sep 17 00:00:00 2001 From: Murali Karicheri Date: Mon, 17 Aug 2020 17:17:36 -0400 Subject: [PATCH 7/9] iplink: hsr: add support for creating PRP device similar to HSR This patch enhances the iplink command to add a proto parameters to create PRP device/interface similar to HSR. Both protocols are quite similar and requires a pair of Ethernet interfaces. So re-use the existing HSR iplink command to create PRP device/interface as well. Use proto parameter to differentiate the two protocols. Signed-off-by: Murali Karicheri Signed-off-by: Stephen Hemminger --- ip/iplink_hsr.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c index 7d9167d4..da2d03d4 100644 --- a/ip/iplink_hsr.c +++ b/ip/iplink_hsr.c @@ -25,7 +25,7 @@ static void print_usage(FILE *f) { fprintf(f, "Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n" - "\t[ supervision ADDR-BYTE ] [version VERSION]\n" + "\t[ supervision ADDR-BYTE ] [version VERSION] [proto PROTOCOL]\n" "\n" "NAME\n" " name of new hsr device (e.g. hsr0)\n" @@ -35,7 +35,9 @@ static void print_usage(FILE *f) " 0-255; the last byte of the multicast address used for HSR supervision\n" " frames (default = 0)\n" "VERSION\n" - " 0,1; the protocol version to be used. (default = 0)\n"); + " 0,1; the protocol version to be used. (default = 0)\n" + "PROTOCOL\n" + " 0 - HSR, 1 - PRP. (default = 0 - HSR)\n"); } static void usage(void) @@ -49,6 +51,7 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv, int ifindex; unsigned char multicast_spec; unsigned char protocol_version; + unsigned char protocol = HSR_PROTOCOL_HSR; while (argc > 0) { if (matches(*argv, "supervision") == 0) { @@ -64,6 +67,13 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv, invarg("version is invalid", *argv); addattr_l(n, 1024, IFLA_HSR_VERSION, &protocol_version, 1); + } else if (matches(*argv, "proto") == 0) { + NEXT_ARG(); + if (!(get_u8(&protocol, *argv, 0) == HSR_PROTOCOL_HSR || + get_u8(&protocol, *argv, 0) == HSR_PROTOCOL_PRP)) + invarg("protocol is invalid", *argv); + addattr_l(n, 1024, IFLA_HSR_PROTOCOL, + &protocol, 1); } else if (matches(*argv, "slave1") == 0) { NEXT_ARG(); ifindex = ll_name_to_index(*argv); @@ -140,6 +150,9 @@ static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]), ARPHRD_VOID, b1, sizeof(b1))); + if (tb[IFLA_HSR_PROTOCOL]) + print_hhu(PRINT_ANY, "proto", "proto %hhu ", + rta_getattr_u8(tb[IFLA_HSR_PROTOCOL])); } static void hsr_print_help(struct link_util *lu, int argc, char **argv, From ea6aeeb90cdbabe0ddf9e30b183ba9ffbf0dbbba Mon Sep 17 00:00:00 2001 From: Murali Karicheri Date: Mon, 17 Aug 2020 17:17:37 -0400 Subject: [PATCH 8/9] ip: iplink: prp: update man page for new parameter PRP support requires a proto parameter which is 0 for hsr and 1 for prp. Default is hsr and is backward compatible. Signed-off-by: Murali Karicheri Signed-off-by: Stephen Hemminger --- man/man8/ip-link.8.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index c6bd2c53..367105b7 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -1404,7 +1404,8 @@ the following additional arguments are supported: .BI slave1 " SLAVE1-IF " slave2 " SLAVE2-IF " .RB [ " supervision" .IR ADDR-BYTE " ] [" -.BR version " { " 0 " | " 1 " } ]" +.BR version " { " 0 " | " 1 " } [" +.BR proto " { " 0 " | " 1 " } ]" .in +8 .sp @@ -1425,6 +1426,12 @@ Default option is "0", possible values 0-255. - Selects the protocol version of the interface. Default option is "0", which corresponds to the 2010 version of the HSR standard. Option "1" activates the 2012 version. + +.BR proto " { " 0 " | " 1 " }" +- Selects the protocol at the interface. Default option is "0", which +corresponds to the HSR standard. Option "1" activates the Parallel +Redundancy Protocol (PRP). +. .in -8 .TP From 23203b750e2dee3cee5d5360504b08d090b61bcf Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sat, 29 Aug 2020 12:18:35 +0200 Subject: [PATCH 9/9] ip link: Fix indenting in help text Indenting of 'ip link set' options below 'link-netns' was wrong, they should be on the same level as the above. While being at it, fix closing brackets in vf-specific options. Also write node/port_guid parameters in upper-case without curly braces: They are supposed to be replaced by values, not put literally. Fixes: 8589eb4efdf2a ("treewide: refactor help messages") Fixes: 5a3ec4ba64783 ("iplink: Update usage in help message") Signed-off-by: Phil Sutter Signed-off-by: Stephen Hemminger --- ip/iplink.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ip/iplink.c b/ip/iplink.c index 7d4b244d..5ec33a98 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -86,26 +86,26 @@ void iplink_usage(void) " [ mtu MTU ]\n" " [ netns { PID | NAME } ]\n" " [ link-netns NAME | link-netnsid ID ]\n" - " [ alias NAME ]\n" - " [ vf NUM [ mac LLADDR ]\n" - " [ vlan VLANID [ qos VLAN-QOS ] [ proto VLAN-PROTO ] ]\n" - " [ rate TXRATE ]\n" - " [ max_tx_rate TXRATE ]\n" - " [ min_tx_rate TXRATE ]\n" - " [ spoofchk { on | off} ]\n" - " [ query_rss { on | off} ]\n" - " [ state { auto | enable | disable} ] ]\n" - " [ trust { on | off} ] ]\n" - " [ node_guid { eui64 } ]\n" - " [ port_guid { eui64 } ]\n" - " [ { xdp | xdpgeneric | xdpdrv | xdpoffload } { off |\n" - " object FILE [ section NAME ] [ verbose ] |\n" - " pinned FILE } ]\n" - " [ master DEVICE ][ vrf NAME ]\n" - " [ nomaster ]\n" - " [ addrgenmode { eui64 | none | stable_secret | random } ]\n" - " [ protodown { on | off } ]\n" - " [ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]\n" + " [ alias NAME ]\n" + " [ vf NUM [ mac LLADDR ]\n" + " [ vlan VLANID [ qos VLAN-QOS ] [ proto VLAN-PROTO ] ]\n" + " [ rate TXRATE ]\n" + " [ max_tx_rate TXRATE ]\n" + " [ min_tx_rate TXRATE ]\n" + " [ spoofchk { on | off} ]\n" + " [ query_rss { on | off} ]\n" + " [ state { auto | enable | disable} ]\n" + " [ trust { on | off} ]\n" + " [ node_guid EUI64 ]\n" + " [ port_guid EUI64 ] ]\n" + " [ { xdp | xdpgeneric | xdpdrv | xdpoffload } { off |\n" + " object FILE [ section NAME ] [ verbose ] |\n" + " pinned FILE } ]\n" + " [ master DEVICE ][ vrf NAME ]\n" + " [ nomaster ]\n" + " [ addrgenmode { eui64 | none | stable_secret | random } ]\n" + " [ protodown { on | off } ]\n" + " [ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]\n" "\n" " ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]\n" "\n"