From patchwork Tue Nov 12 14:51:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193602 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hN6PmNz9sPK for ; Wed, 13 Nov 2019 01:52:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727722AbfKLOwd (ORCPT ); Tue, 12 Nov 2019 09:52:33 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44323 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727673AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKx6020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 1/8] tc_util: introduce a function to print JSON/non-JSON masked numbers Date: Tue, 12 Nov 2019 16:51:47 +0200 Message-Id: <20191112145154.145289-2-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Introduce a function to print masked number with a different output for JSON or non-JSON methods, as a pre-step towards printing numbers using this common function. Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- tc/tc_util.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tc/tc_util.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/tc/tc_util.c b/tc/tc_util.c index 0eb530408d05..2b391f182b96 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -915,6 +915,42 @@ compat_xstats: *xstats = tb[TCA_XSTATS]; } +static void print_masked_type(__u32 type_max, + __u32 (*rta_getattr_type)(const struct rtattr *), + const char *name, struct rtattr *attr, + struct rtattr *mask_attr) +{ + SPRINT_BUF(namefrm); + __u32 value, mask; + SPRINT_BUF(out); + size_t done; + + if (attr) { + value = rta_getattr_type(attr); + mask = mask_attr ? rta_getattr_type(mask_attr) : type_max; + + if (is_json_context()) { + sprintf(namefrm, "\n %s %%u", name); + print_hu(PRINT_ANY, name, namefrm, + rta_getattr_type(attr)); + if (mask != type_max) { + char mask_name[SPRINT_BSIZE-6]; + + sprintf(mask_name, "%s_mask", name); + sprintf(namefrm, "\n %s %%u", mask_name); + print_hu(PRINT_ANY, mask_name, namefrm, mask); + } + } else { + done = sprintf(out, "%u", value); + if (mask != type_max) + sprintf(out + done, "/0x%x", mask); + + sprintf(namefrm, "\n %s %%s", name); + print_string(PRINT_ANY, name, namefrm, out); + } + } +} + void print_masked_u32(const char *name, struct rtattr *attr, struct rtattr *mask_attr) { @@ -958,3 +994,15 @@ void print_masked_u16(const char *name, struct rtattr *attr, sprintf(namefrm, " %s %%s", name); print_string(PRINT_ANY, name, namefrm, out); } + +static __u32 __rta_getattr_u8_u32(const struct rtattr *attr) +{ + return rta_getattr_u8(attr); +} + +void print_masked_u8(const char *name, struct rtattr *attr, + struct rtattr *mask_attr) +{ + print_masked_type(UINT8_MAX, __rta_getattr_u8_u32, name, attr, + mask_attr); +} diff --git a/tc/tc_util.h b/tc/tc_util.h index 0c3425abc62f..7e5d93cbac66 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -131,4 +131,6 @@ void print_masked_u32(const char *name, struct rtattr *attr, struct rtattr *mask_attr); void print_masked_u16(const char *name, struct rtattr *attr, struct rtattr *mask_attr); +void print_masked_u8(const char *name, struct rtattr *attr, + struct rtattr *mask_attr); #endif From patchwork Tue Nov 12 14:51:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193598 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hJ1ns0z9sPK for ; Wed, 13 Nov 2019 01:52:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727715AbfKLOwa (ORCPT ); Tue, 12 Nov 2019 09:52:30 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44322 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727675AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKx7020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 2/8] tc_util: add an option to print masked numbers with/without a newline Date: Tue, 12 Nov 2019 16:51:48 +0200 Message-Id: <20191112145154.145289-3-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Add an option to print masked numbers with or without a newline, as a pre-step towards using a common function. Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- tc/f_flower.c | 4 ++-- tc/m_ct.c | 4 ++-- tc/tc_util.c | 17 +++++++++-------- tc/tc_util.h | 6 +++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tc/f_flower.c b/tc/f_flower.c index a2a230162f78..41b81217e47e 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -1847,13 +1847,13 @@ static void flower_print_ct_label(struct rtattr *attr, static void flower_print_ct_zone(struct rtattr *attr, struct rtattr *mask_attr) { - print_masked_u16("ct_zone", attr, mask_attr); + print_masked_u16("ct_zone", attr, mask_attr, false); } static void flower_print_ct_mark(struct rtattr *attr, struct rtattr *mask_attr) { - print_masked_u32("ct_mark", attr, mask_attr); + print_masked_u32("ct_mark", attr, mask_attr, false); } static void flower_print_key_id(const char *name, struct rtattr *attr) diff --git a/tc/m_ct.c b/tc/m_ct.c index d79eb5e361ac..8df2f6103601 100644 --- a/tc/m_ct.c +++ b/tc/m_ct.c @@ -466,8 +466,8 @@ static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg) print_string(PRINT_ANY, "action", " %s", "clear"); } - print_masked_u32("mark", tb[TCA_CT_MARK], tb[TCA_CT_MARK_MASK]); - print_masked_u16("zone", tb[TCA_CT_ZONE], NULL); + print_masked_u32("mark", tb[TCA_CT_MARK], tb[TCA_CT_MARK_MASK], false); + print_masked_u16("zone", tb[TCA_CT_ZONE], NULL, false); ct_print_labels(tb[TCA_CT_LABELS], tb[TCA_CT_LABELS_MASK]); ct_print_nat(ct_action, tb); diff --git a/tc/tc_util.c b/tc/tc_util.c index 2b391f182b96..d1ef4fac13f6 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -918,7 +918,7 @@ compat_xstats: static void print_masked_type(__u32 type_max, __u32 (*rta_getattr_type)(const struct rtattr *), const char *name, struct rtattr *attr, - struct rtattr *mask_attr) + struct rtattr *mask_attr, bool newline) { SPRINT_BUF(namefrm); __u32 value, mask; @@ -945,14 +945,15 @@ static void print_masked_type(__u32 type_max, if (mask != type_max) sprintf(out + done, "/0x%x", mask); - sprintf(namefrm, "\n %s %%s", name); + sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", + name); print_string(PRINT_ANY, name, namefrm, out); } } } void print_masked_u32(const char *name, struct rtattr *attr, - struct rtattr *mask_attr) + struct rtattr *mask_attr, bool newline) { __u32 value, mask; SPRINT_BUF(namefrm); @@ -969,12 +970,12 @@ void print_masked_u32(const char *name, struct rtattr *attr, if (mask != UINT32_MAX) sprintf(out + done, "/0x%x", mask); - sprintf(namefrm, " %s %%s", name); + sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name); print_string(PRINT_ANY, name, namefrm, out); } void print_masked_u16(const char *name, struct rtattr *attr, - struct rtattr *mask_attr) + struct rtattr *mask_attr, bool newline) { __u16 value, mask; SPRINT_BUF(namefrm); @@ -991,7 +992,7 @@ void print_masked_u16(const char *name, struct rtattr *attr, if (mask != UINT16_MAX) sprintf(out + done, "/0x%x", mask); - sprintf(namefrm, " %s %%s", name); + sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name); print_string(PRINT_ANY, name, namefrm, out); } @@ -1001,8 +1002,8 @@ static __u32 __rta_getattr_u8_u32(const struct rtattr *attr) } void print_masked_u8(const char *name, struct rtattr *attr, - struct rtattr *mask_attr) + struct rtattr *mask_attr, bool newline) { print_masked_type(UINT8_MAX, __rta_getattr_u8_u32, name, attr, - mask_attr); + mask_attr, newline); } diff --git a/tc/tc_util.h b/tc/tc_util.h index 7e5d93cbac66..9adf2ab42138 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -128,9 +128,9 @@ int action_a2n(char *arg, int *result, bool allow_num); bool tc_qdisc_block_exists(__u32 block_index); void print_masked_u32(const char *name, struct rtattr *attr, - struct rtattr *mask_attr); + struct rtattr *mask_attr, bool newline); void print_masked_u16(const char *name, struct rtattr *attr, - struct rtattr *mask_attr); + struct rtattr *mask_attr, bool newline); void print_masked_u8(const char *name, struct rtattr *attr, - struct rtattr *mask_attr); + struct rtattr *mask_attr, bool newline); #endif From patchwork Tue Nov 12 14:51:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193596 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hH1g06z9sPL for ; Wed, 13 Nov 2019 01:52:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727705AbfKLOw3 (ORCPT ); Tue, 12 Nov 2019 09:52:29 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44325 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727164AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKx8020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 3/8] tc: flower: fix newline prints for ct-mark and ct-zone Date: Tue, 12 Nov 2019 16:51:49 +0200 Message-Id: <20191112145154.145289-4-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Matches of ct-mark and ct-zone were printed all in the same line. Fix that so each ct match is printed in a separate line. Example: $ tc qdisc add dev eth0 ingress $ tc filter add dev eth0 protocol ip parent ffff: prio 1 flower skip_hw \ ct_zone 5 ct_mark 6/0xf action ct commit zone 7 mark 8/0xf drop Before: $ tc -s filter show dev eth0 parent ffff: filter protocol ip pref 1 flower chain 0 filter protocol ip pref 1 flower chain 0 handle 0x1 eth_type ipv4 ct_zone 5 ct_mark 6/0xf skip_hw not_in_hw action order 1: ct commit mark 8/0xf zone 7 drop index 1 ref 1 bind 1 installed 31 sec used 31 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 After: $ tc -s filter show dev eth0 parent ffff: filter protocol ip pref 1 flower chain 0 filter protocol ip pref 1 flower chain 0 handle 0x1 eth_type ipv4 ct_zone 5 ct_mark 6/0xf skip_hw not_in_hw action order 1: ct commit mark 8/0xf zone 7 drop index 1 ref 1 bind 1 installed 108 sec used 108 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 Fixes: c8a494314c40 ("tc: Introduce tc ct action") Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- tc/f_flower.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tc/f_flower.c b/tc/f_flower.c index 41b81217e47e..724577563c27 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -1847,13 +1847,13 @@ static void flower_print_ct_label(struct rtattr *attr, static void flower_print_ct_zone(struct rtattr *attr, struct rtattr *mask_attr) { - print_masked_u16("ct_zone", attr, mask_attr, false); + print_masked_u16("ct_zone", attr, mask_attr, true); } static void flower_print_ct_mark(struct rtattr *attr, struct rtattr *mask_attr) { - print_masked_u32("ct_mark", attr, mask_attr, false); + print_masked_u32("ct_mark", attr, mask_attr, true); } static void flower_print_key_id(const char *name, struct rtattr *attr) From patchwork Tue Nov 12 14:51:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193601 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hM5fPbz9sPL for ; Wed, 13 Nov 2019 01:52:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727730AbfKLOwe (ORCPT ); Tue, 12 Nov 2019 09:52:34 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44321 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727684AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKx9020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 4/8] tc_util: fix JSON prints for ct-mark and ct-zone Date: Tue, 12 Nov 2019 16:51:50 +0200 Message-Id: <20191112145154.145289-5-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Fix the output of ct-mark and ct-zone (both for matches and actions) to be different in JSON/non-JSON mode. Example: $ tc qdisc add dev eth0 ingress $ tc filter add dev eth0 protocol ip parent ffff: prio 1 flower skip_hw \ ct_zone 5 ct_mark 6/0xf action ct commit zone 7 mark 8/0xf drop Non JSON format remains the same: $ tc filter show dev eth0 parent ffff: $ tc -s filter show dev ens1f0_0 parent ffff: filter protocol ip pref 1 flower chain 0 filter protocol ip pref 1 flower chain 0 handle 0x1 eth_type ipv4 ct_zone 5 ct_mark 6/0xf skip_hw not_in_hw action order 1: ct commit mark 8/0xf zone 7 drop index 1 ref 1 bind 1 installed 108 sec used 108 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 JSON format is changed (partial output): $ tc -p -j filter show dev eth0 parent ffff: Before: "options": { "keys": { "ct_zone": "5", "ct_mark": "6/0xf" ... "actions": [ { "order": 1, "kind": "ct", "action": "commit", "mark": "8/0xf", "zone": "7", ... After: "options": { "keys": { "ct_zone": 5, "ct_mark": 6, "ct_mark_mask": 15 ... "actions": [ { "order": 1, "kind": "ct", "action": "commit", "mark": 8, "mark_mask": 15, "zone": 7, ... Fixes: c8a494314c40 ("tc: Introduce tc ct action") Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- tc/tc_util.c | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/tc/tc_util.c b/tc/tc_util.c index d1ef4fac13f6..13834234665f 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -955,45 +955,20 @@ static void print_masked_type(__u32 type_max, void print_masked_u32(const char *name, struct rtattr *attr, struct rtattr *mask_attr, bool newline) { - __u32 value, mask; - SPRINT_BUF(namefrm); - SPRINT_BUF(out); - size_t done; - - if (!attr) - return; - - value = rta_getattr_u32(attr); - mask = mask_attr ? rta_getattr_u32(mask_attr) : UINT32_MAX; - - done = sprintf(out, "%u", value); - if (mask != UINT32_MAX) - sprintf(out + done, "/0x%x", mask); + print_masked_type(UINT32_MAX, rta_getattr_u32, name, attr, mask_attr, + newline); +} - sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name); - print_string(PRINT_ANY, name, namefrm, out); +static __u32 __rta_getattr_u16_u32(const struct rtattr *attr) +{ + return rta_getattr_u16(attr); } void print_masked_u16(const char *name, struct rtattr *attr, struct rtattr *mask_attr, bool newline) { - __u16 value, mask; - SPRINT_BUF(namefrm); - SPRINT_BUF(out); - size_t done; - - if (!attr) - return; - - value = rta_getattr_u16(attr); - mask = mask_attr ? rta_getattr_u16(mask_attr) : UINT16_MAX; - - done = sprintf(out, "%u", value); - if (mask != UINT16_MAX) - sprintf(out + done, "/0x%x", mask); - - sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name); - print_string(PRINT_ANY, name, namefrm, out); + print_masked_type(UINT16_MAX, __rta_getattr_u16_u32, name, attr, + mask_attr, newline); } static __u32 __rta_getattr_u8_u32(const struct rtattr *attr) From patchwork Tue Nov 12 14:51:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193600 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hL4qldz9sPK for ; Wed, 13 Nov 2019 01:52:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727726AbfKLOwe (ORCPT ); Tue, 12 Nov 2019 09:52:34 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44331 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727680AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKxA020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 5/8] tc: flower: fix output for ip tos and ttl Date: Tue, 12 Nov 2019 16:51:51 +0200 Message-Id: <20191112145154.145289-6-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Fix the output for ip tos and ttl to be numbers in JSON format. Example: $ tc qdisc add dev eth0 ingress $ tc filter add dev eth0 protocol ip parent ffff: prio 1 flower skip_hw \ ip_tos 5/0xf action drop Non JSON format remains the same: $ tc filter show dev eth0 parent ffff: filter protocol ip pref 1 flower chain 0 filter protocol ip pref 1 flower chain 0 handle 0x1 eth_type ipv4 ip_tos 5/0xf skip_hw not_in_hw action order 1: gact action drop random type none pass val 0 index 1 ref 1 bind 1 JSON format is changed (partial output): $ tc -p -j filter show dev eth0 parent ffff: Before: "options": { "keys": { "ip_tos": "0x5/f", ... After: "options": { "keys": { "ip_tos": 5, "ip_tos_mask": 15, ... Fixes: 6ea2c2b1cff6 ("tc: flower: add support for matching on ip tos and ttl") Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- tc/f_flower.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/tc/f_flower.c b/tc/f_flower.c index 724577563c27..1b518ef30583 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -1617,20 +1617,7 @@ static void flower_print_ip_proto(__u8 *p_ip_proto, static void flower_print_ip_attr(const char *name, struct rtattr *key_attr, struct rtattr *mask_attr) { - SPRINT_BUF(namefrm); - SPRINT_BUF(out); - size_t done; - - if (!key_attr) - return; - - done = sprintf(out, "0x%x", rta_getattr_u8(key_attr)); - if (mask_attr) - sprintf(out + done, "/%x", rta_getattr_u8(mask_attr)); - - print_string(PRINT_FP, NULL, "%s ", _SL_); - sprintf(namefrm, "%s %%s", name); - print_string(PRINT_ANY, name, namefrm, out); + print_masked_u8(name, key_attr, mask_attr, true); } static void flower_print_matching_flags(char *name, From patchwork Tue Nov 12 14:51:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193595 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hG33tQz9sPK for ; Wed, 13 Nov 2019 01:52:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727699AbfKLOw3 (ORCPT ); Tue, 12 Nov 2019 09:52:29 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44332 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727678AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKxB020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 6/8] tc: flower: add u16 big endian parse option Date: Tue, 12 Nov 2019 16:51:52 +0200 Message-Id: <20191112145154.145289-7-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Add u16 big endian parse option as a pre-step towards TCP/UDP/SCTP ports usage. Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- tc/f_flower.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tc/f_flower.c b/tc/f_flower.c index 1b518ef30583..69de6a80735b 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -220,7 +220,7 @@ static int flower_parse_matching_flags(char *str, } static int flower_parse_u16(char *str, int value_type, int mask_type, - struct nlmsghdr *n) + struct nlmsghdr *n, bool be) { __u16 value, mask; char *slash; @@ -239,6 +239,10 @@ static int flower_parse_u16(char *str, int value_type, int mask_type, mask = UINT16_MAX; } + if (be) { + value = htons(value); + mask = htons(mask); + } addattr16(n, MAX_MSG, value_type, value); addattr16(n, MAX_MSG, mask_type, mask); @@ -284,7 +288,8 @@ static int flower_parse_ct_zone(char *str, struct nlmsghdr *n) return flower_parse_u16(str, TCA_FLOWER_KEY_CT_ZONE, TCA_FLOWER_KEY_CT_ZONE_MASK, - n); + n, + false); } static int flower_parse_ct_labels(char *str, struct nlmsghdr *n) From patchwork Tue Nov 12 14:51:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193604 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hY72ZZz9sPK for ; Wed, 13 Nov 2019 01:52:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727728AbfKLOwo (ORCPT ); Tue, 12 Nov 2019 09:52:44 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44340 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727674AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKxC020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 7/8] tc_util: add functions for big endian masked numbers Date: Tue, 12 Nov 2019 16:51:53 +0200 Message-Id: <20191112145154.145289-8-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Add functions for big endian masked numbers as a pre-step towards masked port numbers. Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- tc/tc_util.c | 12 ++++++++++++ tc/tc_util.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/tc/tc_util.c b/tc/tc_util.c index 13834234665f..b58e6cb8b32c 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -982,3 +982,15 @@ void print_masked_u8(const char *name, struct rtattr *attr, print_masked_type(UINT8_MAX, __rta_getattr_u8_u32, name, attr, mask_attr, newline); } + +static __u32 __rta_getattr_be16_u32(const struct rtattr *attr) +{ + return rta_getattr_be16(attr); +} + +void print_masked_be16(const char *name, struct rtattr *attr, + struct rtattr *mask_attr, bool newline) +{ + print_masked_type(UINT16_MAX, __rta_getattr_be16_u32, name, attr, + mask_attr, newline); +} diff --git a/tc/tc_util.h b/tc/tc_util.h index 9adf2ab42138..edc3913889b9 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -133,4 +133,6 @@ void print_masked_u16(const char *name, struct rtattr *attr, struct rtattr *mask_attr, bool newline); void print_masked_u8(const char *name, struct rtattr *attr, struct rtattr *mask_attr, bool newline); +void print_masked_be16(const char *name, struct rtattr *attr, + struct rtattr *mask_attr, bool newline); #endif From patchwork Tue Nov 12 14:51:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1193603 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47C9hT3STzz9sPK for ; Wed, 13 Nov 2019 01:52:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727691AbfKLOw2 (ORCPT ); Tue, 12 Nov 2019 09:52:28 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:44342 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727683AbfKLOw1 (ORCPT ); Tue, 12 Nov 2019 09:52:27 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2019 16:52:21 +0200 Received: from mtr-vdi-191.wap.labs.mlnx. (mtr-vdi-191.wap.labs.mlnx [10.209.100.28]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xACEqKxD020273; Tue, 12 Nov 2019 16:52:21 +0200 From: Roi Dayan To: netdev@vger.kernel.org Cc: David Ahern , Stephen Hemminger , Jiri Pirko , Eli Britstein , Roi Dayan Subject: [PATCH iproute2-next 8/8] tc: flower: support masked port destination and source match Date: Tue, 12 Nov 2019 16:51:54 +0200 Message-Id: <20191112145154.145289-9-roid@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20191112145154.145289-1-roid@mellanox.com> References: <20191112145154.145289-1-roid@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Britstein Extend destination and source port match to support masks, accepting both decimal and hexadecimal formats. Also add missing documentation to synopsis in manpage. $ tc qdisc add dev eth0 ingress $ tc filter add dev eth0 protocol ip parent ffff: prio 1 flower skip_hw \ ip_proto tcp dst_port 1234/0xff00 action drop $ tc -s filter show dev eth0 parent ffff: filter protocol ip pref 1 flower chain 0 filter protocol ip pref 1 flower chain 0 handle 0x1 eth_type ipv4 ip_proto tcp dst_port 1234/0xff00 skip_hw not_in_hw action order 1: gact action drop random type none pass val 0 index 1 ref 1 bind 1 installed 26 sec used 26 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 $ tc -p -j filter show dev eth0 parent ffff: "options": { "keys": { "dst_port": 1234, "dst_port_mask": 65280 ... Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- man/man8/tc-flower.8 | 13 ++++++----- tc/f_flower.c | 64 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8 index 04ee194764e1..eb9eb5f0b19c 100644 --- a/man/man8/tc-flower.8 +++ b/man/man8/tc-flower.8 @@ -57,7 +57,7 @@ flower \- flow based traffic control filter .BR dst_ip " | " src_ip " } " .IR PREFIX " | { " .BR dst_port " | " src_port " } { " -.IR port_number " | " +.IR MASKED_NUMBER " | " .IR min_port_number-max_port_number " } | " .B tcp_flags .IR MASKED_TCP_FLAGS " | " @@ -221,12 +221,13 @@ must be a valid IPv4 or IPv6 address, depending on the \fBprotocol\fR option to tc filter, optionally followed by a slash and the prefix length. If the prefix is missing, \fBtc\fR assumes a full-length host match. .TP -.IR \fBdst_port " { " NUMBER " | " " MIN_VALUE-MAX_VALUE " } +.IR \fBdst_port " { " MASKED_NUMBER " | " " MIN_VALUE-MAX_VALUE " } .TQ -.IR \fBsrc_port " { " NUMBER " | " " MIN_VALUE-MAX_VALUE " } -Match on layer 4 protocol source or destination port number. Alternatively, the -mininum and maximum values can be specified to match on a range of layer 4 -protocol source or destination port numbers. Only available for +.IR \fBsrc_port " { " MASKED_NUMBER " | " " MIN_VALUE-MAX_VALUE " } +Match on layer 4 protocol source or destination port number, with an +optional mask. Alternatively, the mininum and maximum values can be +specified to match on a range of layer 4 protocol source or destination +port numbers. Only available for .BR ip_proto " values " udp ", " tcp " and " sctp which have to be specified in beforehand. .TP diff --git a/tc/f_flower.c b/tc/f_flower.c index 69de6a80735b..a193c0eca22a 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -637,6 +637,27 @@ static int flower_port_attr_type(__u8 ip_proto, enum flower_endpoint endpoint) return -1; } +static int flower_port_attr_mask_type(__u8 ip_proto, + enum flower_endpoint endpoint) +{ + switch (ip_proto) { + case IPPROTO_TCP: + return endpoint == FLOWER_ENDPOINT_SRC ? + TCA_FLOWER_KEY_TCP_SRC_MASK : + TCA_FLOWER_KEY_TCP_DST_MASK; + case IPPROTO_UDP: + return endpoint == FLOWER_ENDPOINT_SRC ? + TCA_FLOWER_KEY_UDP_SRC_MASK : + TCA_FLOWER_KEY_UDP_DST_MASK; + case IPPROTO_SCTP: + return endpoint == FLOWER_ENDPOINT_SRC ? + TCA_FLOWER_KEY_SCTP_SRC_MASK : + TCA_FLOWER_KEY_SCTP_DST_MASK; + default: + return -1; + } +} + static int flower_port_range_attr_type(__u8 ip_proto, enum flower_endpoint type, __be16 *min_port_type, __be16 *max_port_type) @@ -681,13 +702,17 @@ static int flower_parse_port(char *str, __u8 ip_proto, enum flower_endpoint endpoint, struct nlmsghdr *n) { + char *slash = NULL; __be16 min = 0; __be16 max = 0; int ret; ret = parse_range(str, &min, &max); - if (ret) - return -1; + if (ret) { + slash = strchr(str, '/'); + if (!slash) + return -1; + } if (min && max) { __be16 min_port_type, max_port_type; @@ -702,13 +727,24 @@ static int flower_parse_port(char *str, __u8 ip_proto, addattr16(n, MAX_MSG, min_port_type, min); addattr16(n, MAX_MSG, max_port_type, max); - } else if (min && !max) { + } else if (slash || (min && !max)) { int type; type = flower_port_attr_type(ip_proto, endpoint); if (type < 0) return -1; - addattr16(n, MAX_MSG, type, min); + + if (!slash) { + addattr16(n, MAX_MSG, type, min); + } else { + int mask_type; + + mask_type = flower_port_attr_mask_type(ip_proto, + endpoint); + if (mask_type < 0) + return -1; + return flower_parse_u16(str, type, mask_type, n, true); + } } else { return -1; } @@ -1715,15 +1751,10 @@ static void flower_print_ip4_addr(char *name, struct rtattr *addr_attr, addr_attr, mask_attr, 0, 0); } -static void flower_print_port(char *name, struct rtattr *attr) +static void flower_print_port(char *name, struct rtattr *attr, + struct rtattr *mask_attr) { - SPRINT_BUF(namefrm); - - if (!attr) - return; - - sprintf(namefrm,"\n %s %%u", name); - print_hu(PRINT_ANY, name, namefrm, rta_getattr_be16(attr)); + print_masked_be16(name, attr, mask_attr, true); } static void flower_print_port_range(char *name, struct rtattr *min_attr, @@ -2129,11 +2160,13 @@ static int flower_print_opt(struct filter_util *qu, FILE *f, tb[TCA_FLOWER_KEY_IPV6_SRC_MASK]); nl_type = flower_port_attr_type(ip_proto, FLOWER_ENDPOINT_DST); + nl_mask_type = flower_port_attr_mask_type(ip_proto, FLOWER_ENDPOINT_DST); if (nl_type >= 0) - flower_print_port("dst_port", tb[nl_type]); + flower_print_port("dst_port", tb[nl_type], tb[nl_mask_type]); nl_type = flower_port_attr_type(ip_proto, FLOWER_ENDPOINT_SRC); + nl_mask_type = flower_port_attr_mask_type(ip_proto, FLOWER_ENDPOINT_SRC); if (nl_type >= 0) - flower_print_port("src_port", tb[nl_type]); + flower_print_port("src_port", tb[nl_type], tb[nl_mask_type]); if (!flower_port_range_attr_type(ip_proto, FLOWER_ENDPOINT_DST, &min_port_type, &max_port_type)) @@ -2193,7 +2226,8 @@ static int flower_print_opt(struct filter_util *qu, FILE *f, flower_print_key_id("enc_key_id", tb[TCA_FLOWER_KEY_ENC_KEY_ID]); - flower_print_port("enc_dst_port", tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]); + flower_print_port("enc_dst_port", tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT], + tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK]); flower_print_ip_attr("enc_tos", tb[TCA_FLOWER_KEY_ENC_IP_TOS], tb[TCA_FLOWER_KEY_ENC_IP_TOS_MASK]);