From patchwork Sun Feb 14 14:25:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivani Bhardwaj X-Patchwork-Id: 582499 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3B07914031F for ; Mon, 15 Feb 2016 01:25:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=jVWlDP2Z; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751420AbcBNOZI (ORCPT ); Sun, 14 Feb 2016 09:25:08 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34767 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751414AbcBNOZH (ORCPT ); Sun, 14 Feb 2016 09:25:07 -0500 Received: by mail-pa0-f49.google.com with SMTP id fy10so32323876pac.1 for ; Sun, 14 Feb 2016 06:25:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=eHKMfuArKraC/+A7OJOALeHOMxvZ5CpfEtT2tYATCmo=; b=jVWlDP2ZD5Y6VmCVv/M1LMp9/c6P9S988lRezDw+WGhHJ06NRHMQNJRl6+cfmrsv2Z myADT8Pb1kkGnDgL0ZJjpT128dNlxhZmcLphAqeoqwlAWjlyHunQvJSDBxza/ScuUt26 aal3yUgYdRApJTUKIdv4KYoUGL+6gI/vUPLK+ACKBhihzVhUFL62kCTbZFTzsxrMtiYl rrRNyfUhVixa+4tYrvP0rQ8u9jK3qGTJxSvzjP4ciX+jUFRzcZ6rnT8ofbOYfBFRrsSt RE4wSuGSdlFrdC9qi8o0myXRXlF2ZhxVbfc37To0s9xUOSixdCApK25wazGnGIl7Jwri xiIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=eHKMfuArKraC/+A7OJOALeHOMxvZ5CpfEtT2tYATCmo=; b=gjG19V5iiTaN2gvarrCIWZUopJJzGwbwp16I6sTRvKAwrA8OPrIjJXus0tRxj+G1JU ut4I20IWBuRlbkQf/UO7D1TzYwUUkqIUe2LeSQW6qb7kDIXO/J1PwwTtwzqeoHz/3ssE w2H8HXUjT8VDj1cns1UIsMP9EVWDnai/A8P0imfkcKEblEtsY6UftujpkrkFeygsHev+ CKm7SpDFIYtMpsCcJw4EQ28WMF61qlQ3uqTwOjr5F4hbN9dF3DMwa4W1EKYVr3taTb8O 5aw6eC71s8uopJuHOR/dxmEq4gIO+7D9uGtIpjoSKprgQcBqRhmyhpvo5aHBCksOZPsU xJ1g== X-Gm-Message-State: AG10YOSCnBcQH/7Gl9wJK7YW6hHTGRimFif2wmgVqmKDtaGYgPO/VaAZUqH9PEvUmXoLjA== X-Received: by 10.66.225.177 with SMTP id rl17mr16691348pac.46.1455459906822; Sun, 14 Feb 2016 06:25:06 -0800 (PST) Received: from gmail.com ([223.176.165.115]) by smtp.gmail.com with ESMTPSA id xg9sm15801079pac.9.2016.02.14.06.25.04 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 14 Feb 2016 06:25:06 -0800 (PST) Date: Sun, 14 Feb 2016 19:55:00 +0530 From: Shivani Bhardwaj To: netfilter-devel@vger.kernel.org Subject: [PATCH] extensions: libxt_tos: Add translation to nft Message-ID: <20160214142500.GA3397@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Add translation for match tos to nftables. Examples: $ sudo iptables-translate -A INPUT -m tos --tos 0x02 -j ACCEPT nft add rule ip filter INPUT ip tos 0x02 counter accept $ sudo iptables-translate -A INPUT -m tos --tos 0x02/0x04 -j ACCEPT nft add rule ip filter INPUT ip tos and 0x02 == 0x04 counter accept $ sudo iptables-translate -A INPUT -m tos ! --tos 0x02/0x04 -j ACCEPT nft add rule ip filter INPUT ip tos and 0x02 != 0x04 counter accept Details: This patch was sent by Ana, Shivani modified it as per the current nftables structure, applied it to the latest branch and tested it. Signed-off-by: Shivani Bhardwaj Signed-off-by: Ana Rey --- extensions/libxt_tos.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/extensions/libxt_tos.c b/extensions/libxt_tos.c index 81c096f..577e9cb 100644 --- a/extensions/libxt_tos.c +++ b/extensions/libxt_tos.c @@ -121,6 +121,23 @@ static void tos_mt_save(const void *ip, const struct xt_entry_match *match) printf(" --tos 0x%02x/0x%02x", info->tos_value, info->tos_mask); } +static int tos_mt_xlate(const struct xt_entry_match *match, + struct xt_xlate *xl, int numeric) +{ + const struct xt_tos_match_info *info = (const void *)match->data; + + xt_xlate_add(xl, "ip tos "); + + if (info->tos_mask == 0xff) + xt_xlate_add(xl, "%s0x%02x ", info->invert ? "!= " : "", + info->tos_value); + else + xt_xlate_add(xl, "and 0x%02x %s 0x%02x ", info->tos_value, + info->invert ? "!=" : "==", info->tos_mask); + + return 1; +} + static struct xtables_match tos_mt_reg[] = { { .version = XTABLES_VERSION, @@ -147,6 +164,7 @@ static struct xtables_match tos_mt_reg[] = { .save = tos_mt_save, .x6_parse = tos_mt_parse, .x6_options = tos_mt_opts, + .xlate = tos_mt_xlate, }, };