* [PATCH nft] main: misleading error reporting in chain definitions
@ 2019-10-21 15:38 Pablo Neira Ayuso
2019-10-21 15:47 ` Phil Sutter
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-21 15:38 UTC (permalink / raw)
To: netfilter-devel
# nft add chain x y { type filter hook input priority -30\; }
nft: invalid option -- '3'
Fix this by restricting getopt_long() to the first curly brace.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/main.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/main.c b/src/main.c
index f77d8a820a02..0d4a45b30d20 100644
--- a/src/main.c
+++ b/src/main.c
@@ -192,19 +192,38 @@ static const struct {
},
};
+static int argc_getopt(int argc, char * const *argv)
+{
+ int i;
+
+ /* Restrict getopt_long() parsing to the first curly brace, so users
+ * do not need to invoke nft with an upfront -- to specify chain
+ * priority.
+ */
+ for (i = 0; i < argc; i++) {
+ if (argv[i][0] == '{') {
+ return i;
+ }
+ }
+
+ return argc;
+}
+
int main(int argc, char * const *argv)
{
char *buf = NULL, *filename = NULL;
unsigned int output_flags = 0;
+ int i, val, rc, __argc;
bool interactive = false;
unsigned int debug_mask;
unsigned int len;
- int i, val, rc;
+
+ __argc = argc_getopt(argc, argv);
nft = nft_ctx_new(NFT_CTX_DEFAULT);
while (1) {
- val = getopt_long(argc, argv, OPTSTRING, options, NULL);
+ val = getopt_long(__argc, argv, OPTSTRING, options, NULL);
if (val == -1)
break;
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH nft] main: misleading error reporting in chain definitions
2019-10-21 15:38 [PATCH nft] main: misleading error reporting in chain definitions Pablo Neira Ayuso
@ 2019-10-21 15:47 ` Phil Sutter
2019-10-21 16:00 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Phil Sutter @ 2019-10-21 15:47 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
Hi Pablo,
On Mon, Oct 21, 2019 at 05:38:35PM +0200, Pablo Neira Ayuso wrote:
> # nft add chain x y { type filter hook input priority -30\; }
> nft: invalid option -- '3'
>
> Fix this by restricting getopt_long() to the first curly brace.
Wouldn't it suffice to set the first char of OPTSTRING to '+'? Exporting
POSIXLY_CORRECT=1 prior to calling the above command works at least.
Cheers, Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH nft] main: misleading error reporting in chain definitions
2019-10-21 15:47 ` Phil Sutter
@ 2019-10-21 16:00 ` Pablo Neira Ayuso
0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-21 16:00 UTC (permalink / raw)
To: Phil Sutter, netfilter-devel
On Mon, Oct 21, 2019 at 05:47:13PM +0200, Phil Sutter wrote:
> Hi Pablo,
>
> On Mon, Oct 21, 2019 at 05:38:35PM +0200, Pablo Neira Ayuso wrote:
> > # nft add chain x y { type filter hook input priority -30\; }
> > nft: invalid option -- '3'
> >
> > Fix this by restricting getopt_long() to the first curly brace.
>
> Wouldn't it suffice to set the first char of OPTSTRING to '+'? Exporting
> POSIXLY_CORRECT=1 prior to calling the above command works at least.
Would you post a patch? :-)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-21 16:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 15:38 [PATCH nft] main: misleading error reporting in chain definitions Pablo Neira Ayuso
2019-10-21 15:47 ` Phil Sutter
2019-10-21 16:00 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).