From patchwork Tue Jun 8 15:33:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Danilov X-Patchwork-Id: 12307229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89BB3C47082 for ; Tue, 8 Jun 2021 15:33:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D01261002 for ; Tue, 8 Jun 2021 15:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbhFHPf0 (ORCPT ); Tue, 8 Jun 2021 11:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbhFHPfZ (ORCPT ); Tue, 8 Jun 2021 11:35:25 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9725C061574 for ; Tue, 8 Jun 2021 08:33:22 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id x14so13227419ljp.7 for ; Tue, 08 Jun 2021 08:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6MwjdJLeEpSC0apKdrMCy6GpFHPBUueYy/xEq2Hv4io=; b=fjmvSBle2rfmnqCOj9mYP9XZeXEC2K2bL6Ac2BJbfq+wMPy15Btaslyu1Fj0CL/M+b QEP8WiEaLBJQfjgEuLC+qOGTpTzYUpXCJpNh0O/hP0TN0caZvD9TkYnFKUt4xmuFmhBK f3/sdoTjyEUUD/0TWMajxgGAHNFKXiIq7tPgixgT01RxcTu+jrEKK+oDPsZ+1idZ4AE2 MIsnVrebooWXNh5jx9uog4VHWJYg7KB/QnGZWDvjDdb72B8hWOWCV+fTfnUo7D1PjeKT VwM44NkjmMchrkQGVuhWFUlcm9Y/0gkhveu1wcnTkHGHfbOIk8Q55AXjV6UvB3idhdwk 1cPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6MwjdJLeEpSC0apKdrMCy6GpFHPBUueYy/xEq2Hv4io=; b=djS/FxguyJPo1+jKke2RhDnuegMpR89amZ+09+UWL70G2I8L1o+kAh55mBZhzIL2KP RlYbGMITBHVcrD6wp8y3DYpgGGDheE9pdScN3ChQd7OQwb+3vN/CK8aRdqwHM4aoB/8n gW0AuVT2UYlMkMtH4z58wts/Vx9SAFprLVaTvBvsFRg2zK7pZXLLb/1Ligi8nsIdKmKu itLyzJorIUq6QZRT84lxCwaYCtRaexQeyPPPGDiqp5hvWy5+Jhfobcttmoes6F3a1Tyj dfxTmmQUYuC8fTZ0HrSOJbaLTKqes+8TiWFcQuNofYsgSVg6HdHyS621vACpoWyayB+J W4Jg== X-Gm-Message-State: AOAM530pWypeXdDf4kPlqfBW4HXyGQx1hIoDSErp8V+74dHJmdvTXPGY jtSl1l4K8t5VPBzxQnusvWMLipqm1QV6fixR X-Google-Smtp-Source: ABdhPJzM/08uzCGHyIYYMAmJjEX71m9k5C6l6ILgI4iH8eKn1CRyiGkFQaxmFYAnZISpNzeipd9LHA== X-Received: by 2002:a05:651c:157:: with SMTP id c23mr18218313ljd.393.1623166401124; Tue, 08 Jun 2021 08:33:21 -0700 (PDT) Received: from dau-work-pc.sunlink.ru ([87.244.6.228]) by smtp.googlemail.com with ESMTPSA id h4sm10483ljk.4.2021.06.08.08.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 08:33:20 -0700 (PDT) From: Anton Danilov To: Stephen Hemminger Cc: netdev@vger.kernel.org, Anton Danilov Subject: [RFC 1/3] [RFC iproute2-next] tc: f_u32: Rename commands and functions ip6 to ipv6 to unify naming Date: Tue, 8 Jun 2021 18:33:07 +0300 Message-Id: <20210608153309.4019-1-littlesmilingcloud@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Before patch: ~$ tc filter add dev dummy0 parent 1: protocol ipv6 prio 10 \ u32 match ip6 src aa:bb:cc:dd::/128 flowid 1:1 After patch: ~$ tc filter add dev dummy0 parent 1: protocol ipv6 prio 10 \ u32 match ipv6 src aa:bb:cc:dd::/128 flowid 1:1 Signed-off-by: Anton Danilov --- tc/f_u32.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tc/f_u32.c b/tc/f_u32.c index 2ed5254a..3fd3eb17 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -35,7 +35,7 @@ static void explain(void) "or u32 divisor DIVISOR\n" "\n" "Where: SELECTOR := SAMPLE SAMPLE ...\n" - " SAMPLE := { ip | ip6 | udp | tcp | icmp | u{32|16|8} | mark }\n" + " SAMPLE := { ip | ipv6 | udp | tcp | icmp | u{32|16|8} | mark }\n" " SAMPLE_ARGS [ divisor DIVISOR ]\n" " FILTERID := X:Y:Z\n" "\nNOTE: CLASSID is parsed at hexadecimal input.\n"); @@ -356,7 +356,7 @@ static int parse_ip_addr(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, return res; } -static int parse_ip6_addr(int *argc_p, char ***argv_p, +static int parse_ipv6_addr(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, int off) { int res = -1; @@ -403,7 +403,7 @@ static int parse_ip6_addr(int *argc_p, char ***argv_p, return res; } -static int parse_ip6_class(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) +static int parse_ipv6_class(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) { int res = -1; int argc = *argc_p; @@ -538,7 +538,7 @@ static int parse_ip(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) return res; } -static int parse_ip6(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) +static int parse_ipv6(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) { int res = -1; int argc = *argc_p; @@ -549,13 +549,13 @@ static int parse_ip6(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) if (strcmp(*argv, "src") == 0) { NEXT_ARG(); - res = parse_ip6_addr(&argc, &argv, sel, 8); + res = parse_ipv6_addr(&argc, &argv, sel, 8); } else if (strcmp(*argv, "dst") == 0) { NEXT_ARG(); - res = parse_ip6_addr(&argc, &argv, sel, 24); - } else if (strcmp(*argv, "priority") == 0) { + res = parse_ipv6_addr(&argc, &argv, sel, 24); + } else if (strcmp(*argv, "priority") == 0 || strcmp(*argv, "class") == 0) { NEXT_ARG(); - res = parse_ip6_class(&argc, &argv, sel); + res = parse_ipv6_class(&argc, &argv, sel); } else if (strcmp(*argv, "protocol") == 0) { NEXT_ARG(); res = parse_u8(&argc, &argv, sel, 6, 0); @@ -712,9 +712,9 @@ static int parse_selector(int *argc_p, char ***argv_p, } else if (matches(*argv, "ip") == 0) { NEXT_ARG(); res = parse_ip(&argc, &argv, sel); - } else if (matches(*argv, "ip6") == 0) { + } else if (matches(*argv, "ip6") == 0 || matches(*argv, "ipv6") == 0) { NEXT_ARG(); - res = parse_ip6(&argc, &argv, sel); + res = parse_ipv6(&argc, &argv, sel); } else if (matches(*argv, "udp") == 0) { NEXT_ARG(); res = parse_udp(&argc, &argv, sel); From patchwork Tue Jun 8 15:33:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Danilov X-Patchwork-Id: 12307231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 079FFC4743D for ; Tue, 8 Jun 2021 15:33:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B96AF61002 for ; Tue, 8 Jun 2021 15:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232164AbhFHPfa (ORCPT ); Tue, 8 Jun 2021 11:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbhFHPfa (ORCPT ); Tue, 8 Jun 2021 11:35:30 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 548B1C061787 for ; Tue, 8 Jun 2021 08:33:24 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id f30so32777795lfj.1 for ; Tue, 08 Jun 2021 08:33:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kKlzMs2lD1tYCQcR5b54DlEhQgqSRloMljB35g+LwsU=; b=nzbpfQ961FxGozO0rGt9iK0N5KxcIUQ5Z4bZq2maKz0pARKmYOBI4mMO23OS3nNq8j +P9zUJFAYD/z6tg4J/OWQNDgO8V1kU4LMgmGklANDdhqtATU20vo+Ur7nAyIvFd7KgQL iAk4ft13FaYmcxIQ/hvHkbVJ+7a61gdQLgV0Dfk8ZEk4OY604LqAAOUt9zPnuDmF0EB7 rEaGs172vS1aZev6+gvV1A7DWoZg8Ua/v/O6pJMeQGr29V3MfkDXmskw5CKTeLzUm3NV xC991Dnt7aD5pv+Rs1b/aozuQ41aIzzgPGMl6ZzQ5WFd2VqYoKdy0ekDQ6tfBqNu4t97 Nn9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kKlzMs2lD1tYCQcR5b54DlEhQgqSRloMljB35g+LwsU=; b=dEJphT7KxEN8kJMAPJVoT0AyuWng2jZ3VwDya3CvWEJbYTdZ4xZnjEQvmOM8ATAY5P jFKP2qymYH/0bY+OfsX+wO6u4algmAPjnF6P+xZsW81hFV/g9c3tcnOwYvSX+Ph1ZT/0 3yy4URzbbyj/HsO/R2GRQ52l2uyOsIgabECUQMgAgZXjqwTqCiQCcO5rRfqUHb8vT7xr WKfw2mE2iKfZlA9N65T6DofgcYhTQlJ3TDDwkq/ukH4TNc7SDfbWvsrBnfTxauWu28fS 2f6luo6XF+gks2kMMEfLzPX7Hob8CRxrafdBxgDX01K9D4XRxRpUADhX843wjzKHLJvX aitA== X-Gm-Message-State: AOAM533iZiP1RHy1A4vB+QgSPVaJHge0v9IZUgamO1dlRpnzD64Jd+xe +7TuFvxb8FYLE+f6t0LHgmS/JEfMi0CHDktr X-Google-Smtp-Source: ABdhPJyEOMX0K470E8cqr4msuGVVdWDfNN7nzDuhek4D8YvnjC4u5k6VzN0h5BKzbA41p5y9GAbujA== X-Received: by 2002:ac2:4a6b:: with SMTP id q11mr5750390lfp.321.1623166402626; Tue, 08 Jun 2021 08:33:22 -0700 (PDT) Received: from dau-work-pc.sunlink.ru ([87.244.6.228]) by smtp.googlemail.com with ESMTPSA id h4sm10483ljk.4.2021.06.08.08.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 08:33:22 -0700 (PDT) From: Anton Danilov To: Stephen Hemminger Cc: netdev@vger.kernel.org, Anton Danilov Subject: [RFC 2/3] [RFC iproute2-next] tc: f_u32: Fix the ipv6 pretty printing. Date: Tue, 8 Jun 2021 18:33:08 +0300 Message-Id: <20210608153309.4019-2-littlesmilingcloud@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210608153309.4019-1-littlesmilingcloud@gmail.com> References: <20210608153309.4019-1-littlesmilingcloud@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Unexpectedly the print_ipv6 function is the copy-paste version of the print_ipv4 function. Fixed. Before patch: $ sudo tc -p -s f ls dev dummy0 filter parent 1: protocol ipv6 pref 30 u32 chain 0 filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800: ht divisor 1 filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) match IP src 64.0.0.0/32 (success 0 ) match IP dst 0.0.0.0/32 (success 0 ) match sport 0, match dport 0 (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::801 order 2049 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) (success 0 ) (success 0 ) (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::802 order 2050 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) match IP src 0.204.0.221/32 (success 0 ) match IP dst 0.0.0.0/1 (success 0 ) (success 0 ) (success 0 ) (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::803 order 2051 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::804 order 2052 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::805 order 2053 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match IP ihl 1 (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::806 order 2054 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::807 order 2055 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) After patch: $ sudo tc -p -s f ls dev dummy0 filter parent 1: protocol ipv6 pref 30 u32 chain 0 filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800: ht divisor 1 filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 src 2a02:26e0:4000::/128 filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::801 order 2049 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 dst 2a02:26e0:4000::/128 filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::802 order 2050 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 src aa:bb:cc:dd::/65 match ipv6 dst aa:bb:cc:dd::/66 filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::803 order 2051 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 class 0xff 0xff (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::804 order 2052 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 class 0x10 0xff (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::805 order 2053 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 class 0x10 0xf0 (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::806 order 2054 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 flowlabel 0xbcde 0xffff (success 0 ) filter parent 1: protocol ipv6 pref 30 u32 chain 0 fh 800::807 order 2055 key ht 800 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ipv6 class 0x12 0xff match ipv6 flowlabel 0xbcde 0xffff (success 0 ) Signed-off-by: Anton Danilov --- tc/f_u32.c | 152 +++++++++++++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 70 deletions(-) diff --git a/tc/f_u32.c b/tc/f_u32.c index 3fd3eb17..d7beb586 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -820,28 +820,28 @@ static int parse_hashkey(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) return 0; } -static void print_ipv4(FILE *f, const struct tc_u32_key *key) +static int print_ipv4(FILE *f, const struct tc_u32_key *key) { char abuf[256]; + if (key == NULL) + return 0; + switch (key->off) { case 0: switch (ntohl(key->mask)) { case 0x0f000000: - fprintf(f, "\n match IP ihl %u", + return fprintf(f, "\n match IP ihl %u", ntohl(key->val) >> 24); - return; case 0x00ff0000: - fprintf(f, "\n match IP dsfield %#x", + return fprintf(f, "\n match IP dsfield %#x", ntohl(key->val) >> 16); - return; } break; case 8: if (ntohl(key->mask) == 0x00ff0000) { - fprintf(f, "\n match IP protocol %d", + return fprintf(f, "\n match IP protocol %d", ntohl(key->val) >> 16); - return; } break; case 12: @@ -849,12 +849,11 @@ static void print_ipv4(FILE *f, const struct tc_u32_key *key) int bits = mask2bits(key->mask); if (bits >= 0) { - fprintf(f, "\n %s %s/%d", + return fprintf(f, "\n %s %s/%d", key->off == 12 ? "match IP src" : "match IP dst", inet_ntop(AF_INET, &key->val, abuf, sizeof(abuf)), bits); - return; } } break; @@ -862,87 +861,100 @@ static void print_ipv4(FILE *f, const struct tc_u32_key *key) case 20: switch (ntohl(key->mask)) { case 0x0000ffff: - fprintf(f, "\n match dport %u", + return fprintf(f, "\n match dport %u", ntohl(key->val) & 0xffff); - return; case 0xffff0000: - fprintf(f, "\n match sport %u", + return fprintf(f, "\n match sport %u", ntohl(key->val) >> 16); - return; case 0xffffffff: - fprintf(f, "\n match dport %u, match sport %u", + return fprintf(f, "\n match dport %u, match sport %u", ntohl(key->val) & 0xffff, ntohl(key->val) >> 16); - return; } /* XXX: Default print_raw */ } + + return 0; } -static void print_ipv6(FILE *f, const struct tc_u32_key *key) +static int print_ipv6(FILE *f, const struct tc_u32_key *key) { char abuf[256]; + static __u32 ipv6_src_addr[4]; + static int ipv6_src_plen; + static __u32 ipv6_dst_addr[4]; + static int ipv6_dst_plen; + + int ret = 0; + + if ((key == NULL || key->off >= 24) && ipv6_src_plen > 0) { + ret = fprintf(f, "\n match ipv6 src %s/%d", + inet_ntop(AF_INET6, ipv6_src_addr, abuf, sizeof(abuf)), ipv6_src_plen); + memset(ipv6_src_addr, 0, 16); + ipv6_src_plen = 0; + } + + if (key == NULL && ipv6_dst_plen > 0) { + ret += fprintf(f, "\n match ipv6 dst %s/%d", + inet_ntop(AF_INET6, ipv6_dst_addr, abuf, sizeof(abuf)), ipv6_dst_plen); + memset(ipv6_dst_addr, 0, 16); + ipv6_dst_plen = 0; + } + + if (key == NULL) + return ret; + switch (key->off) { case 0: - switch (ntohl(key->mask)) { - case 0x0f000000: - fprintf(f, "\n match IP ihl %u", - ntohl(key->val) >> 24); - return; - case 0x00ff0000: - fprintf(f, "\n match IP dsfield %#x", - ntohl(key->val) >> 16); - return; + if (ntohl(key->mask) & 0x0ff00000) { + ret = fprintf(f, "\n match ipv6 class %#x %#x", + (ntohl(key->val) & 0x0ff00000) >> 20, + (ntohl(key->mask) & 0x0ff00000) >> 20); + } + if (ntohl(key->mask) & 0x000fffff) { + ret += fprintf(f, "\n match ipv6 flowlabel %#x %#x", + ntohl(key->val) & 0x000fffff, + ntohl(key->mask) & 0x000fffff); } + return ret; break; - case 8: - if (ntohl(key->mask) == 0x00ff0000) { - fprintf(f, "\n match IP protocol %d", - ntohl(key->val) >> 16); - return; + case 4: + if (ntohl(key->mask) == 0x0000ff00) { + return fprintf(f, "\n match ipv6 protocol %d", + ntohl(key->val) >> 8); } break; + case 8: case 12: - case 16: { - int bits = mask2bits(key->mask); - - if (bits >= 0) { - fprintf(f, "\n %s %s/%d", - key->off == 12 ? "match IP src" : "match IP dst", - inet_ntop(AF_INET, &key->val, - abuf, sizeof(abuf)), - bits); - return; - } + case 16: + case 20: { + ipv6_src_plen += mask2bits(key->mask); + ipv6_src_addr[(key->off - 8) / 4] = key->val; } break; - - case 20: - switch (ntohl(key->mask)) { - case 0x0000ffff: - fprintf(f, "\n match sport %u", - ntohl(key->val) & 0xffff); - return; - case 0xffff0000: - fprintf(f, "\n match dport %u", - ntohl(key->val) >> 16); - return; - case 0xffffffff: - fprintf(f, "\n match sport %u, match dport %u", - ntohl(key->val) & 0xffff, - ntohl(key->val) >> 16); - - return; + case 24: + case 28: + case 32: + case 36: { + ipv6_dst_plen += mask2bits(key->mask); + ipv6_dst_addr[(key->off - 24) / 4] = key->val; } + break; + /* XXX: Default print_raw */ } + + return 0; } -static void print_raw(FILE *f, const struct tc_u32_key *key) +static int print_raw(FILE *f, const struct tc_u32_key *key) { - fprintf(f, "\n match %08x/%08x at %s%d", + if (key == NULL) + return 0; + + return fprintf(f, "\n match %08x/%08x at %s%d", (unsigned int)ntohl(key->val), (unsigned int)ntohl(key->mask), key->offmask ? "nexthdr+" : "", @@ -952,14 +964,14 @@ static void print_raw(FILE *f, const struct tc_u32_key *key) static const struct { __u16 proto; __u16 pad; - void (*pprinter)(FILE *f, const struct tc_u32_key *key); + int (*pprinter)(FILE *f, const struct tc_u32_key *key); } u32_pprinters[] = { {0, 0, print_raw}, {ETH_P_IP, 0, print_ipv4}, {ETH_P_IPV6, 0, print_ipv6}, }; -static void show_keys(FILE *f, const struct tc_u32_key *key) +static int show_keys(FILE *f, const struct tc_u32_key *key) { int i = 0; @@ -969,8 +981,7 @@ static void show_keys(FILE *f, const struct tc_u32_key *key) for (i = 0; i < ARRAY_SIZE(u32_pprinters); i++) { if (u32_pprinters[i].proto == ntohs(f_proto)) { show_k: - u32_pprinters[i].pprinter(f, key); - return; + return u32_pprinters[i].pprinter(f, key); } } @@ -1289,12 +1300,13 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, if (sel) { if (sel->nkeys) { int i; - - for (i = 0; i < sel->nkeys; i++) { - show_keys(f, sel->keys + i); - if (show_stats && NULL != pf) - fprintf(f, " (success %llu ) ", - (unsigned long long) pf->kcnts[i]); + // The ipv6 pretty printing requires an additional call at the end. + // Call the show_keys with the NULL value after call with last key. + for (i = 0; i <= sel->nkeys; i++) { + if (show_keys(f, i < sel->nkeys ? sel->keys + i : NULL)) + if (i < sel->nkeys && show_stats && NULL != pf) + fprintf(f, " (success %llu ) ", + (unsigned long long) pf->kcnts[i]); } } From patchwork Tue Jun 8 15:33:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Danilov X-Patchwork-Id: 12307235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6840C47082 for ; Tue, 8 Jun 2021 15:34:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC52B6134F for ; Tue, 8 Jun 2021 15:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232934AbhFHPga (ORCPT ); Tue, 8 Jun 2021 11:36:30 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:39841 "EHLO mail-lf1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232887AbhFHPga (ORCPT ); Tue, 8 Jun 2021 11:36:30 -0400 Received: by mail-lf1-f42.google.com with SMTP id p17so31964346lfc.6 for ; Tue, 08 Jun 2021 08:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iP2f67S4SfR4Vp3wAXoqgs6iuDezCtUMH1C+HCeozgs=; b=INChxCdEoBf9zGWPXrJvtWXVNviSm/3xxzA/Bj7WHtIs7Q00w9kURqZmO90yLEku0Z VjNa/BH7fflKbE8IoyBmEmOgqWFTKltDJqExY5XbHWtQeRu7eMh0UFj1VKbVayQ6YW5f u/2JP+9yEmuUaJM/nZ+jVjQzZtWu4fhhdtUjRscEjPOkpr/4FMweiHWheyV+BU2wwCaq vi4oJYZwUgVwVmpRErjtuWxjkHVZWXEPBGiNFhL2hfCRFO56JuRdVaqxVVX6re4ZGgXa st6M+8iM/cV7tLX01TWjKlbSzM1zenYSd6OgjxGydvZJP+JSXcox7shujctiWM7bnuwj ds1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iP2f67S4SfR4Vp3wAXoqgs6iuDezCtUMH1C+HCeozgs=; b=JjV/AeRqZC0mnRWZXBJFf56Tak0/F2oR6epFBL13mcQLHZF/m9oIpmCxP97XHT2xY5 x2dwtfHvQj41aBT//UY1q3YtI9/fdmYdjl5stBigRT9+sPrVUCfr9XwCFQEdArAnawqP s+VKSG8eFQmLRFDIk9vmRhDm78xCRrUJUjB0jtiXAifPU9RXMThLYOyllRophCZyo7ni z9V0B5qSjH8opxbrVQucVg/bchCNNzrFA8jK+2bESsnKoWa8Q5WvvjtIvrsVoa43QqtK GjfvQbnboyiiV0Cw2v2xn7VQo3T46pyImeQcWWZ703nGhBNLgP3W8xolSsnriFa4TB61 7lcg== X-Gm-Message-State: AOAM533HRJJeX2l46XIP6OKryeIfUqwai+wnggucx8yNR3nFzj2XQod3 YneHbkb+aFLKpW11zFuyWBM4zThCCQUI5IjV X-Google-Smtp-Source: ABdhPJwQiMXF/7LETnyP+KekTKeBBuy7iRzWSs3CvFUENVKYgslXn3pfBwZ0Miw80MfDnXkxA9g8FQ== X-Received: by 2002:a05:6512:3da8:: with SMTP id k40mr5268516lfv.233.1623166404148; Tue, 08 Jun 2021 08:33:24 -0700 (PDT) Received: from dau-work-pc.sunlink.ru ([87.244.6.228]) by smtp.googlemail.com with ESMTPSA id h4sm10483ljk.4.2021.06.08.08.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 08:33:23 -0700 (PDT) From: Anton Danilov To: Stephen Hemminger Cc: netdev@vger.kernel.org, Anton Danilov Subject: [RFC 3/3] [RFC iproute2-next] tc: f_u32: fix the pretty print of ipv4 filters Date: Tue, 8 Jun 2021 18:33:09 +0300 Message-Id: <20210608153309.4019-3-littlesmilingcloud@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210608153309.4019-1-littlesmilingcloud@gmail.com> References: <20210608153309.4019-1-littlesmilingcloud@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC ~$: tc f add dev dummy0 parent 1: protocol ip prio 10 \ u32 match ip ihl 10 0xf match ip dsfield 0x0a 0xff flowid 1:1 Before patch: ~$ sudo tc -p -s f ls dev dummy0 filter parent 1: protocol ip pref 10 u32 chain 0 filter parent 1: protocol ip pref 10 u32 chain 0 fh 801: ht divisor 1 filter parent 1: protocol ip pref 10 u32 chain 0 fh 801::801 order 2049 key ht 801 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) (success 0 ) After patch: ~$ sudo tc -p -s f ls dev dummy0 filter parent 1: protocol ip pref 10 u32 chain 0 filter parent 1: protocol ip pref 10 u32 chain 0 fh 801: ht divisor 1 filter parent 1: protocol ip pref 10 u32 chain 0 fh 801::801 order 2049 key ht 801 bkt 0 flowid 1:1 not_in_hw (rule hit 0 success 0) match ip ihl 10 0xf match ip dsfield 0xa 0xff (success 0 ) Signed-off-by: Anton Danilov --- tc/f_u32.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tc/f_u32.c b/tc/f_u32.c index d7beb586..e60c787a 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -827,20 +827,25 @@ static int print_ipv4(FILE *f, const struct tc_u32_key *key) if (key == NULL) return 0; + int ret = 0; + switch (key->off) { case 0: - switch (ntohl(key->mask)) { - case 0x0f000000: - return fprintf(f, "\n match IP ihl %u", - ntohl(key->val) >> 24); - case 0x00ff0000: - return fprintf(f, "\n match IP dsfield %#x", - ntohl(key->val) >> 16); + if (ntohl(key->mask) & 0x0f000000) { + ret = fprintf(f, "\n match ip ihl %u %#x", + (ntohl(key->val) & 0x0f000000) >> 24, + (ntohl(key->mask) & 0x0f000000) >> 24); + } + if (ntohl(key->mask) & 0x00ff0000) { + ret += fprintf(f, "\n match ip dsfield %#x %#x", + (ntohl(key->val) & 0x00ff0000) >> 16, + (ntohl(key->mask) & 0x00ff0000) >> 16); } + return ret; break; case 8: if (ntohl(key->mask) == 0x00ff0000) { - return fprintf(f, "\n match IP protocol %d", + return fprintf(f, "\n match ip protocol %d", ntohl(key->val) >> 16); } break; @@ -850,7 +855,7 @@ static int print_ipv4(FILE *f, const struct tc_u32_key *key) if (bits >= 0) { return fprintf(f, "\n %s %s/%d", - key->off == 12 ? "match IP src" : "match IP dst", + key->off == 12 ? "match ip src" : "match ip dst", inet_ntop(AF_INET, &key->val, abuf, sizeof(abuf)), bits);