All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Perevalov <a.perevalov@samsung.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: alexey.perevalov@hotmail.com, netfilter-devel@vger.kernel.org,
	kyungmin.park@samsung.com, hs81.go@samsung.com
Subject: Re: [PATCH v3 1/2] nfacct: check cmd line argument for singleness
Date: Fri, 12 Sep 2014 12:24:51 +0400	[thread overview]
Message-ID: <5412ADD3.4080203@samsung.com> (raw)
In-Reply-To: <20140911165537.GA6897@salvia>

On 09/11/2014 08:55 PM, Pablo Neira Ayuso wrote:
> On Thu, Sep 11, 2014 at 07:50:39PM +0400, Alexey Perevalov wrote:
>> It was possible to specify several equal options for list operation.
>>
>> Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
>> ---
>>   src/nfacct.c |   16 +++++++++++++++-
>>   1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/nfacct.c b/src/nfacct.c
>> index 091a5c9..d77a57e 100644
>> --- a/src/nfacct.c
>> +++ b/src/nfacct.c
>> @@ -25,6 +25,13 @@
>>   #include <linux/netfilter/nfnetlink_acct.h>
>>   #include <linux/netfilter/nfnetlink.h>
>>   
>> +#define CHECK_OPT_PLURARITY(opt_name, msg) \
>> +	opt_name += 1; \
>> +	if (opt_name > 1) { \
>> +		nfacct_perror(msg); \
>> +		return -1; \
>> +	}
>> +
>>   enum {
>>   	NFACCT_CMD_NONE = 0,
>>   	NFACCT_CMD_LIST,
>> @@ -166,6 +173,8 @@ err:
>>   	return MNL_CB_OK;
>>   }
>>   
>> +#define NFACCT_F_QUOTAS (NFACCT_F_QUOTA_BYTES | NFACCT_F_QUOTA_PKTS)
>> +
>>   static int nfacct_cmd_list(int argc, char *argv[])
>>   {
>>   	bool zeroctr = false, xml = false;
>> @@ -177,8 +186,14 @@ static int nfacct_cmd_list(int argc, char *argv[])
>>   
>>   	for (i=2; i<argc; i++) {
>>   		if (strncmp(argv[i], "reset", strlen(argv[i])) == 0) {
>> +			static int opt_reset;
>> +			CHECK_OPT_PLURARITY(opt_reset, "reset couldn't be "
>> +				            "defined more than once");
> I prefer if you add something similar to what iproute2 provides:
>
> void duparg2(const char *key, const char *arg)
> {
>          fprintf(stderr, "Error: either \"%s\" is duplicate, or \"%s\" is a garbage.\n", key, arg);
>          exit(-1);
> }
>
> You can probably check:
>
>                          if (zeroctr)
>                                  duparg2("reset", argv[i]);
>
>>   			zeroctr = true;
>>   		} else if (strncmp(argv[i], "xml", strlen(argv[i])) == 0) {
>> +			static int opt_xml;
>> +			CHECK_OPT_PLURARITY(opt_xml, "xml couldn't be defined "
>> +					    "more than once");
> Similar thing here.
>
> I always wanted to get this code more in line iproute2, but failed to
> find the time, later.
>
> So please, do it the way I'm proposing so we start looking into
> converging to iproute2.
ok, but now nfacct doesn't use iprout2, so suggested function should by 
copy-pasted, maybe with modification,
because "is a garbage" I think no necessary.
Do you want to make nfacct code more similar with iproute2 code, to 
merge it in future?

>
> Thanks.
>


-- 
Best regards,
Alexey Perevalov,
Tizen Developer,
phone: +7 (495) 797 25 00 ext 3969
e-mail: a.perevalov@samsung.com <mailto:a.perevalov@samsumng.com>

Mobile group, Samsung R&D Institute Rus
12 Dvintsev street, building 1
127018, Moscow, Russian Federation

  reply	other threads:[~2014-09-12  8:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11 15:50 [PATCH v3 0/2] nfacct: add filter in to the list operation Alexey Perevalov
2014-09-11 15:50 ` [PATCH v3 1/2] nfacct: check cmd line argument for singleness Alexey Perevalov
2014-09-11 16:55   ` Pablo Neira Ayuso
2014-09-12  8:24     ` Alexey Perevalov [this message]
2014-09-12  8:36       ` Pablo Neira Ayuso
2014-09-11 15:50 ` [PATCH v3 2/2] nfacct: add filter in to the list operation Alexey Perevalov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5412ADD3.4080203@samsung.com \
    --to=a.perevalov@samsung.com \
    --cc=alexey.perevalov@hotmail.com \
    --cc=hs81.go@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.