From patchwork Thu Apr 4 13:09:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 1077275 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) 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=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44ZjwF6yYjz9sP9 for ; Fri, 5 Apr 2019 00:09:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728872AbfDDNJs (ORCPT ); Thu, 4 Apr 2019 09:09:48 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:40168 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726952AbfDDNJr (ORCPT ); Thu, 4 Apr 2019 09:09:47 -0400 Received: by mail-ed1-f66.google.com with SMTP id h22so2144337edw.7 for ; Thu, 04 Apr 2019 06:09:46 -0700 (PDT) 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=cawTo6H0tOQvXi5JwcBUqzALkJkO9j9d8bfD/LY9RuI=; b=U/4l6lINtIsUDTv39FnJCHEFGj2QXJAaGeAPVOp2CXf74vuj9X9zOUJ1WaOQRilpdW eexvHa4mEZTLkWiYmmRJCDlAOLoIMtIfh518kTSIHE0H2ofTZxWIX28uGJwrdxgmjagE vuZBQjL/c2iAcrsTw3dhorYTBcH5U1BRfbk3tXXcXAsmTxIyCErwlFbt3yMk7kgAne+N LA+bbx/g8iMaBJNqowfcqJDK2cEG5cLjRhpg9u/30wJTTJZ5IFaZHzE179K3EzH+2wCj 1IC4XhBRpdvvsPkzTixB7sw+Q31+Pz/1m1rBAUpHpOs/Ds6Y+cpXBD4P/ifnHOAtlZzN 0eOA== X-Gm-Message-State: APjAAAUIQ5MlQJgqIIL0f834eSafi0b6hOJzSMd9Ed4UwaZ73jjsIwQa vtRy9PmbNP2tbmtUxKMNgsR/cRQ/gTA= X-Google-Smtp-Source: APXvYqyz5hIysohZT8twYTR6FaRfeCjS2z51jAxl2k38L9S0iPxxUsyPV7640ULRp4AqbcjpvXIbvA== X-Received: by 2002:a17:906:e5a:: with SMTP id q26mr3611804eji.50.1554383385981; Thu, 04 Apr 2019 06:09:45 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk (borgediget.toke.dk. [85.204.121.218]) by smtp.gmail.com with ESMTPSA id m18sm4722075edc.86.2019.04.04.06.09.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Apr 2019 06:09:45 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id B49091804A5; Thu, 4 Apr 2019 15:09:44 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: netdev@vger.kernel.org Cc: cake@lists.bufferbloat.net, =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= Subject: [PATCH iproute2] q_cake: Add support for setting the fwmark option Date: Thu, 4 Apr 2019 15:09:10 +0200 Message-Id: <20190404130910.19948-1-toke@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This adds support for the newly added fwmark option to CAKE, which allows overriding the tin selection from the per-packet firewall marks. The fwmark field is a bitmask that is applied to the fwmark to select the tin. Signed-off-by: Toke Høiland-Jørgensen --- man/man8/tc-cake.8 | 16 ++++++++++++++++ tc/q_cake.c | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/man/man8/tc-cake.8 b/man/man8/tc-cake.8 index eda436e1..8c57eadd 100644 --- a/man/man8/tc-cake.8 +++ b/man/man8/tc-cake.8 @@ -91,6 +91,10 @@ TIME | LIMIT ] .br [ +.BR fwmark +MASK ] +.br +[ .BR ptm | .BR atm @@ -524,6 +528,18 @@ preset on the modern Internet is firmly discouraged. .br Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval. +.PP +.B fwmark +MASK +.br + This options turns on fwmark-based overriding of CAKE's tin selection. +If set, the option specifies a bitmask that will be applied to the fwmark +associated with each packet. If the result of this masking is non-zero, the +result will be right-shifted by the number of least-significant unset bits in +the mask value, and the result will be used as a the tin number for that packet. +This can be used to set policies in a firewall script that will override CAKE's +built-in tin selection. + .SH OTHER PARAMETERS .B memlimit LIMIT diff --git a/tc/q_cake.c b/tc/q_cake.c index e827e3f1..307a12c0 100644 --- a/tc/q_cake.c +++ b/tc/q_cake.c @@ -82,6 +82,7 @@ static void explain(void) " [ split-gso* | no-split-gso ]\n" " [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n" " [ memlimit LIMIT ]\n" +" [ fwmark MASK ]\n" " [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n" " [ mpu N ] [ ingress | egress* ]\n" " (* marks defaults)\n"); @@ -106,6 +107,7 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, int autorate = -1; int ingress = -1; int overhead = 0; + int fwmark = -1; int wash = -1; int nat = -1; int atm = -1; @@ -332,6 +334,16 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, "Illegal value for \"memlimit\": \"%s\"\n", *argv); return -1; } + } else if (strcmp(*argv, "fwmark") == 0) { + unsigned int fwm; + + NEXT_ARG(); + if (get_u32(&fwm, *argv, 0)) { + fprintf(stderr, + "Illegal value for \"fwmark\": \"%s\"\n", *argv); + return -1; + } + fwmark = fwm; } else if (strcmp(*argv, "help") == 0) { explain(); return -1; @@ -376,6 +388,9 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (memlimit) addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit)); + if (fwmark != -1) + addattr_l(n, 1024, TCA_CAKE_FWMARK, &fwmark, + sizeof(fwmark)); if (nat != -1) addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat)); if (wash != -1) @@ -409,6 +424,7 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) struct rtattr *tb[TCA_CAKE_MAX + 1]; unsigned int interval = 0; unsigned int memlimit = 0; + unsigned int fwmark = 0; __u64 bandwidth = 0; int ack_filter = 0; int split_gso = 0; @@ -507,6 +523,10 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) { interval = rta_getattr_u32(tb[TCA_CAKE_RTT]); } + if (tb[TCA_CAKE_FWMARK] && + RTA_PAYLOAD(tb[TCA_CAKE_FWMARK]) >= sizeof(__u32)) { + fwmark = rta_getattr_u32(tb[TCA_CAKE_FWMARK]); + } if (wash) print_string(PRINT_FP, NULL, "wash ", NULL); @@ -559,6 +579,10 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) sprint_size(memlimit, b1)); } + if (fwmark) + print_uint(PRINT_FP, NULL, "fwmark 0x%x ", fwmark); + print_0xhex(PRINT_JSON, "fwmark", NULL, fwmark); + return 0; }