From patchwork Wed Dec 11 16:10:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 1207747 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.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=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nwl.cc Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47Y22x5Rv1z9sTx for ; Thu, 12 Dec 2019 03:10:33 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388975AbfLKQKc (ORCPT ); Wed, 11 Dec 2019 11:10:32 -0500 Received: from orbyte.nwl.cc ([151.80.46.58]:47028 "EHLO orbyte.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730822AbfLKQKa (ORCPT ); Wed, 11 Dec 2019 11:10:30 -0500 Received: from localhost ([::1]:60118 helo=tatos) by orbyte.nwl.cc with esmtp (Exim 4.91) (envelope-from ) id 1if4ZI-0000lM-3Y; Wed, 11 Dec 2019 17:10:28 +0100 From: Phil Sutter To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org Subject: [nft PATCH] doc: nft.8: Add BUGS section about command line parsing Date: Wed, 11 Dec 2019 17:10:20 +0100 Message-Id: <20191211161020.1327-1-phil@nwl.cc> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Illustrate potential pitfalls when entering nft commands on command line and list possible counter-measures. Signed-off-by: Phil Sutter --- doc/nft.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/nft.txt b/doc/nft.txt index abb9260d3f2f6..d69c2283f52db 100644 --- a/doc/nft.txt +++ b/doc/nft.txt @@ -802,6 +802,32 @@ On success, nft exits with a status of 0. Unspecified errors cause it to exit with a status of 1, memory allocation errors with a status of 2, unable to open Netlink socket with 3. +BUGS +----- +COMMAND LINE PARSING +~~~~~~~~~~~~~~~~~~~~ +The syntax used in nftables is prone to cause problems when given on command +line. For instance, *semi-colon* is used in all relevant shells to delimit +commands. + +In some places, *quoted strings* are expected. If not escaped, the shell will +silently eat them away. + +There is also an internal problem regarding *negative priority values* (e.g., +when defining base-chains or flowtables): The leading dash catches getopt's +attention which in turn assumes user specified an unknown option flag. Getopt +allows to ignore any option-like parameter after the first non-option, but +that would prevent typical commands like *nft list ruleset -a*. + +There are multiple ways to mitigate these issues: Shells can be prevented from +interpreting special characters by prefixing them with the escape character +(typically *backslash*), getopt won't recognize options following a parameter +consisting of *two dashes* alone (which in turn is ignored as well). Probably +the easiest way to avoid even unforseen issues is to enclose the whole +nftables syntax in *single quotes*. This turns the multiple non-option words +on command line into a single argument which is passed to the parser just like +before but the shell as well as getopt will leave it alone. + SEE ALSO -------- [verse]