From patchwork Sun Apr 23 12:53:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Vadai X-Patchwork-Id: 753913 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3w9qFN2qxdz9ryk for ; Sun, 23 Apr 2017 22:55:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1045445AbdDWMyu (ORCPT ); Sun, 23 Apr 2017 08:54:50 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34826 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1045427AbdDWMyn (ORCPT ); Sun, 23 Apr 2017 08:54:43 -0400 Received: by mail-wr0-f193.google.com with SMTP id l44so17772594wrc.2 for ; Sun, 23 Apr 2017 05:54:43 -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:in-reply-to :references; bh=2O5BYGhBcMZ1l7GLklSahIouQHAi+RcLbrC5PZrtcvY=; b=TuhAZacKxAG1XLexTmn1zrduLz6z05pwZz51bExjW8oK6rFi+dVYInpBFOzR5A4YC8 3hiHyUmqct3ZwrRf9jp0rxTEIlBmQmoDoyb9vQLw1QmvKIQBKACtqWaTpWS2YveFxGh6 P5uyevQ9/Bx3ss4dq6IHaHcyxYhX+Dk0hpLjiRnFX0H3om5/gDm1jfCX1TwpLkb69z8e XN3WEzPCykTHKbQN5xvvGZkr3tofJBIRYg3/4tOuXnIHgX6W+ZgNxM5915fUzYLdwhVa 8Dg19FOu/k8XcLWpBVlELILo9ZuOFG275tMduYbYk14iwr5lpk/FWdUr1b6pI6mlrs7A xo6w== X-Gm-Message-State: AN3rC/6CqPatyR7SQpYLruh+AirO4BEOtL6fBArHm7cphODtsar3UPP+ bXw2rE54UWjcYw== X-Received: by 10.223.135.130 with SMTP id b2mr1854891wrb.48.1492952082148; Sun, 23 Apr 2017 05:54:42 -0700 (PDT) Received: from office.vadai.me ([192.116.94.213]) by smtp.gmail.com with ESMTPSA id t16sm9339522wme.16.2017.04.23.05.54.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Apr 2017 05:54:41 -0700 (PDT) From: Amir Vadai To: Stephen Hemminger Cc: netdev@vger.kernel.org, Or Gerlitz , Jamal Hadi Salim , Amir Vadai Subject: [PATCH iproute2 net 4/8] tc/pedit: p_ip: introduce editing ttl header Date: Sun, 23 Apr 2017 15:53:52 +0300 Message-Id: <20170423125356.1298-5-amir@vadai.me> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170423125356.1298-1-amir@vadai.me> References: <20170423125356.1298-1-amir@vadai.me> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Enable user to edit IP header ttl field. For example, to forward any TCP packet and decrease its TTL by one: $ tc filter add dev enp0s9 protocol ip parent ffff: \ flower \ ip_proto tcp \ action pedit ex munge \ ip ttl add 0xff pipe \ action mirred egress \ redirect dev veth0 Signed-off-by: Amir Vadai --- man/man8/tc-pedit.8 | 17 +++++++++++++++++ tc/p_ip.c | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/man/man8/tc-pedit.8 b/man/man8/tc-pedit.8 index 6bba741956f1..c98d95cb0021 100644 --- a/man/man8/tc-pedit.8 +++ b/man/man8/tc-pedit.8 @@ -28,6 +28,8 @@ pedit - generic packet editor action .ti -8 .IR EXTENDED_LAYERED_OP " := { " .BI ip " IPHDR_FIELD" +| +.BI ip " EX_IPHDR_FIELD" .RI } " CMD_SPEC" .ti -8 @@ -40,6 +42,10 @@ pedit - generic packet editor action .BR dport " | " sport " | " icmp_type " | " icmp_code " }" .ti -8 +.IR EX_IPHDR_FIELD " := { " +.BR ttl " }" + +.ti -8 .IR CMD_SPEC " := {" .BR clear " | " invert " | " set .IR VAL " | " @@ -161,6 +167,17 @@ If it is not or the latter is bigger than the minimum of 20 bytes, this will do unexpected things. These fields are eight-bit values. .RE .TP +.BI ip " EX_IPHDR_FIELD" +Supported only when +.I ex +is used. The supported keywords for +.I EX_IPHDR_FIELD +are: +.RS +.TP +.B ttl +.RE +.TP .B clear Clear the addressed data (i.e., set it to zero). .TP diff --git a/tc/p_ip.c b/tc/p_ip.c index e56eb39317ba..22fe6505e427 100644 --- a/tc/p_ip.c +++ b/tc/p_ip.c @@ -66,6 +66,12 @@ parse_ip(int *argc_p, char ***argv_p, res = parse_cmd(&argc, &argv, 1, TU32, 0x0f, sel, tkey); goto done; } + if (strcmp(*argv, "ttl") == 0) { + NEXT_ARG(); + tkey->off = 8; + res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey); + goto done; + } if (strcmp(*argv, "protocol") == 0) { NEXT_ARG(); tkey->off = 9;