netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: Probably wrong code in nf_nat_snmp_basic.c
@ 2011-11-17 21:14 Thomas Jarosch
  2011-11-18  0:34 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Jarosch @ 2011-11-17 21:14 UTC (permalink / raw)
  To: netfilter-devel

Hi,

consider this piece of code from
net/ipv4/netfilter/nf_nat_snmp_basic.c:1198

---------------------------------------------
/*
    * Determine mappping for application layer addresses based
    * on NAT manipulations for the packet.
    */
if (dir == IP_CT_DIR_ORIGINAL) {
    /* SNAT traps */
    map.from = NOCT1(&ct->tuplehash[dir].tuple.src.u3.ip);
    map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip);
} else {
    /* DNAT replies */
    map.from = NOCT1(&ct->tuplehash[dir].tuple.src.u3.ip);
    map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip);
}
---------------------------------------------

cppcheck reported: (style) Found duplicate branches for if and else.


Either I need glasses or the code is exactly the same :)

Cheers,
Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: Probably wrong code in nf_nat_snmp_basic.c
  2011-11-17 21:14 RFC: Probably wrong code in nf_nat_snmp_basic.c Thomas Jarosch
@ 2011-11-18  0:34 ` Pablo Neira Ayuso
  2011-11-18  8:43   ` Thomas Jarosch
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2011-11-18  0:34 UTC (permalink / raw)
  To: Thomas Jarosch; +Cc: netfilter-devel

On Thu, Nov 17, 2011 at 10:14:02PM +0100, Thomas Jarosch wrote:
> Hi,
> 
> consider this piece of code from
> net/ipv4/netfilter/nf_nat_snmp_basic.c:1198
> 
> ---------------------------------------------
> /*
>     * Determine mappping for application layer addresses based
>     * on NAT manipulations for the packet.
>     */
> if (dir == IP_CT_DIR_ORIGINAL) {
>     /* SNAT traps */
>     map.from = NOCT1(&ct->tuplehash[dir].tuple.src.u3.ip);
>     map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip);
> } else {
>     /* DNAT replies */
>     map.from = NOCT1(&ct->tuplehash[dir].tuple.src.u3.ip);
>     map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip);
> }
> ---------------------------------------------
> 
> cppcheck reported: (style) Found duplicate branches for if and else.
> 
> 
> Either I need glasses or the code is exactly the same :)

Indeed. I'll be happy to take a patch for this. If you don't make it
in the following days, no problem, I'll take of this myself. Thanks
for the report.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: Probably wrong code in nf_nat_snmp_basic.c
  2011-11-18  0:34 ` Pablo Neira Ayuso
@ 2011-11-18  8:43   ` Thomas Jarosch
  2011-11-28 15:46     ` Thomas Jarosch
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Jarosch @ 2011-11-18  8:43 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, James Morris

On Friday, 18. November 2011 01:34:29 Pablo Neira Ayuso wrote:
> > if (dir == IP_CT_DIR_ORIGINAL) {
> > 
> >     /* SNAT traps */
> >     map.from = NOCT1(&ct->tuplehash[dir].tuple.src.u3.ip);
> >     map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip);
> > 
> > } else {
> > 
> >     /* DNAT replies */
> >     map.from = NOCT1(&ct->tuplehash[dir].tuple.src.u3.ip);
> >     map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip);
> > 
> > }
> > ---------------------------------------------
> > 
> > cppcheck reported: (style) Found duplicate branches for if and else.
> > 
> > 
> > Either I need glasses or the code is exactly the same :)
> 
> Indeed. I'll be happy to take a patch for this. If you don't make it
> in the following days, no problem, I'll take of this myself. Thanks
> for the report.

The if() statement is probably in there for a reason. I'm not familiar with 
the internal details of the ct stuff, perhaps map.from/map.to
should be swapped or something like that.

James, any idea what's going on?

Cheers,
Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: Probably wrong code in nf_nat_snmp_basic.c
  2011-11-18  8:43   ` Thomas Jarosch
@ 2011-11-28 15:46     ` Thomas Jarosch
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Jarosch @ 2011-11-28 15:46 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, James Morris

Hi Pablo,

On Friday, 18. November 2011 09:43:29 Thomas Jarosch wrote:
> > Indeed. I'll be happy to take a patch for this. If you don't make it
> > in the following days, no problem, I'll take of this myself. Thanks
> > for the report.
> 
> The if() statement is probably in there for a reason. I'm not familiar
> with the internal details of the ct stuff, perhaps map.from/map.to
> should be swapped or something like that.
> 
> James, any idea what's going on?

Hmm, James is probably busy.

Would be nice if you could take over this, Pablo.

Thanks,
Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-28 15:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-17 21:14 RFC: Probably wrong code in nf_nat_snmp_basic.c Thomas Jarosch
2011-11-18  0:34 ` Pablo Neira Ayuso
2011-11-18  8:43   ` Thomas Jarosch
2011-11-28 15:46     ` Thomas Jarosch

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).