nf_conntrack/ip_conntrack disrepencies
Subsystems (2)
in nf_conntrack_tuple.h we have:
static inline int nf_ct_tuple_src_equal(const struct nf_conntrack_tuple *t1,
const struct nf_conntrack_tuple *t2)
{
return (t1->src.u3.all[0] == t2->src.u3.all[0] &&
t1->src.u3.all[1] == t2->src.u3.all[1] &&
t1->src.u3.all[2] == t2->src.u3.all[2] &&
t1->src.u3.all[3] == t2->src.u3.all[3] &&
t1->src.u.all == t2->src.u.all &&
t1->src.l3num == t2->src.l3num &&
t1->dst.protonum == t2->dst.protonum);
}In ip_conntrack_tuple.h we have:
static inline int ip_ct_tuple_src_equal(const struct ip_conntrack_tuple *t1,
const struct ip_conntrack_tuple *t2)
{
return t1->src.ip == t2->src.ip
&& t1->src.u.all == t2->src.u.all;
}nf_conntrack compares the dst.protonum (makes sense) but the ip_conntrack doesn't. Is there the danger of ip_conntrack selecting wrong matching tuples sometimes? Perhaps only in the rare case where the hashes also match (unlikely) but I thought I would point this out.
Does protonum really belong in the dst member? Correspondingly, for nf_conntrack, does l3num really belong in src?
The final thing that troubles me is that the dst member seems to have things unrelated, like "dir" and "protonum", why are these part of nf_conntrack_tuple.dst and not the top level nf_conntrack_tuple struct?
Sam
Quoted 22 lines · Amin Azez
in
nf_conntrack_tuple.hwe have:
static inline int nf_ct_tuple_src_equal(const structnf_conntrack_tuple*t1,
const structnf_conntrack_tuple*t2){ return (t1->src.u3.all[0] == t2->src.u3.all[0] && t1->src.u3.all[1] == t2->src.u3.all[1] && t1->src.u3.all[2] == t2->src.u3.all[2] && t1->src.u3.all[3] == t2->src.u3.all[3] && t1->src.u.all == t2->src.u.all && t1->src.l3num == t2->src.l3num && t1->dst.protonum == t2->dst.protonum); }In
ip_conntrack_tuple.hwe have:
static inline int ip_ct_tuple_src_equal(const structip_conntrack_tuple*t1,
const structip_conntrack_tuple*t2){ return t1->src.ip == t2->src.ip && t1->src.u.all == t2->src.u.all; }
Quoted 4 lines
nf_conntrackcompares the dst.protonum (makes sense) but theip_conntrackdoesn't. Is there the danger ofip_conntrackselecting wrong matching tuples sometimes? Perhaps only in the rare case where the hashes also match (unlikely) but I thought I would point this out.
The only place where it is used in ip_conntrack is ip_ct_tuple_equal, which also compares the dst tuple. I guess its the same in nf_conntrack, so it could probably changed.
Quoted 2 lines
Does protonum really belong in the dst member? Correspondingly, for
nf_conntrack, does l3num really belong in src?
Not really, but it saves room. The compiler pads src and dst to a multiple of 32 bit, so there are two bytes room.
Quoted 3 lines
The final thing that troubles me is that the dst member seems to have things unrelated, like "dir" and "protonum", why are these part of nf_conntrack_tuple.dst and not the top level
nf_conntrack_tuplestruct?
See above.
more nf_conntrack/ip_conntrack questions
2 questions, part style, relating to nf_conntrack and ip_conntrack
In nf_conntrack_tuple.h in
#define NF_CT_TUPLE_U_BLANK(tuple) \
do { \
(tuple)->src.u.all = 0; \
(tuple)->dst.u.all = 0; \
memset((tuple)->src.u3.all, 0, \
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE); \
memset((tuple)->dst.u3.all, 0, \
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE); \
} while (0)
why do we have:
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE
as the size, instead of just:
sizeof((tuple)->dst.u3)
it seems to presume that:
1) .all will always be the biggest member
2) .all is always an array of NF_CT_TUPLE_L3SIZE of u_int32_t
I wonder why we need to duplicate this knowledge when a small definition appears to suffice.
Also; and I asked about somehting similar before, why is ip_conntrack_tuple.src almost exactly the same as ip_conntrack_tuple.dst, but .src is defined in terms of pre-declared structs and unions but dst is declared in terms of (nearly) identical structs and unions. With nf_conntrack as far as I can tell they are the same. The inline explanation of "manipulatable" doesn't seem to cover it.
Azez
Re: more nf_conntrack/ip_conntrack questions
Quoted 20 lines · Amin Azez
2 questions, part style, relating to
nf_conntrackandip_conntrackIn
nf_conntrack_tuple.hin#define
NF_CT_TUPLE_U_BLANK(tuple)\
do { \
(tuple)->src.u.all = 0; \
(tuple)->dst.u.all = 0; \
memset((tuple)->src.u3.all, 0, \
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE); \
memset((tuple)->dst.u3.all, 0, \
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE); \
} while (0)why do we have:
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZEas the size, instead of just:
sizeof((tuple)->dst.u3)
Quoted 6 lines
it seems to presume that:
1) .all will always be the biggest member
2) .all is always an array ofNF_CT_TUPLE_L3SIZEofu_int32_tI wonder why we need to duplicate this knowledge when a small definition appears to suffice.
I have no idea, but I agree that it looks confusing. You should ask Yasuyuki, he wrote this code.
Quoted 6 lines
Also; and I asked about somehting similar before, why is ip_conntrack_tuple.src almost exactly the same as ip_conntrack_tuple.dst, but .src is defined in terms of pre-declared structs and unions but dst is declared in terms of (nearly) identical structs and unions. With
nf_conntrackas far as I can tell they are the same. The inline explanation of "manipulatable" doesn't seem to cover it.
Well, for one dst is only nearly identical. The "maniputable" part is also used on its own for function arguments in the NAT code, the non-manipulable part isn't, so there's no need to put it in a seperate structure.
Re: more nf_conntrack/ip_conntrack questions
Hi,
From: Patrick McHardy <[email protected]>
Date: Mon, 12 Sep 2005 12:42:51 +0200
Quoted 18 lines
Quoted 17 lines · Amin Azez
2 questions, part style, relating to
nf_conntrackandip_conntrackIn
nf_conntrack_tuple.hin#define
NF_CT_TUPLE_U_BLANK(tuple)\
do { \
(tuple)->src.u.all = 0; \
(tuple)->dst.u.all = 0; \
memset((tuple)->src.u3.all, 0, \
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE); \
memset((tuple)->dst.u3.all, 0, \
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE); \
} while (0)why do we have:
sizeof(u_int32_t)*NF_CT_TUPLE_L3SIZE
Quoted 6 lines
Quoted 6 lines
as the size, instead of just:
sizeof((tuple)->dst.u3)it seems to presume that:
1) .all will always be the biggest member
2) .all is always an array ofNF_CT_TUPLE_L3SIZEofu_int32_t
Yes,
Quoted 5 lines
Quoted 2 lines
I wonder why we need to duplicate this knowledge when a small definition appears to suffice.
I have no idea, but I agree that it looks confusing. You should ask Yasuyuki, he wrote this code.
This is for nf_ct_tuple_mask_cmp(), which compares 2 tuples with mask. I didn't want to use 'switch - case' for each layer 3 protocol, then I tried to generalize it like ip_ct_tuple_mask_cmp() like layer 4 protocol part. Then I introduced the member 'all'.
And for efficiency, it applies mask to tuple per 32bits instead of 8bits.NF_CT_TUPLE_L3SIZE is used for checking loop limitation. I think it's easier to read than sizeof(tuple->dst.u3)/sizeof(u_int32_t). And explicit definition of array 'all' assures that sizeof(tuple->dst.u3) is divisible with sizeof(u_int32_t) independent on contents of 'u3'.
Of cause, smarter idea than this way is welcome.
-----------------------------------------------------------------
Yasuyuki Kozakai @ USAGI Project <[email protected]>
Re: more nf_conntrack/ip_conntrack questions
Sorry,
From: Yasuyuki KOZAKAI <[email protected]>
Date: Mon, 12 Sep 2005 20:29:07 +0900 (JST)
Quoted 3 lines
then I
tried to generalize it likeip_ct_tuple_mask_cmp()like layer 4 protocol part.
What I want to say is ...
I tried to generalize it like the handling of layer 4 protocol part in ip_ct_tuple_mask_cmp().
-----------------------------------------------------------------
Yasuyuki Kozakai @ USAGI Project <[email protected]>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: more nf_conntrack/ip_conntrack questions
Quoted 13 lines · Yasuyuki KOZAKAI
Sorry,
From: Yasuyuki KOZAKAI <[email protected]>
Date: Mon, 12 Sep 2005 20:29:07 +0900 (JST)Quoted 5 lines
then I
tried to generalize it likeip_ct_tuple_mask_cmp()like layer 4 protocol part.
Quoted 7 lines
What I want to say is ...
I tried to generalize it like the handling of layer 4 protocol part in
ip_ct_tuple_mask_cmp().
Sure, I don't have any fault with the structures, just the way the sizeof is measured for initial zero-ing.
Sam
Re: more nf_conntrack/ip_conntrack questions
From: Amin Azez <[email protected]>
Date: Mon, 12 Sep 2005 13:04:40 +0100
Quoted 2 lines
Sure, I don't have any fault with the structures, just the way the sizeof is measured for initial zero-ing.
Oh, it's reasonable. Thank you for notice.
Harald, please apply this patch.
-----------------------------------------------------------------
Yasuyuki Kozakai @ USAGI Project <[email protected]>
[NETFILTER] simplifies calculation of size of l3 part in tuple
---
commit 0a330af3412fbfaecd694acd572000f29f2a407c
tree 76e0dc454fa6723e98b1fc423fbb222985612960
parent b24ffb6730679e783e77eb3bc721ddd50fdf9ec7
author Yasuyuki Kozakai <[email protected]> Mon, 12 Sep 2005 21:49:32 +0900 committer Yasuyuki Kozakai <[email protected]> Mon, 12 Sep 2005 21:49:32 +0900
include/linux/netfilter/nf_conntrack_tuple.h | 6 ++---- net/netfilter/nf_conntrack_l3proto_generic.c | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-)
include/linux/netfilter/nf_conntrack_tuple.h +2 -4
@@ -104,10 +104,8 @@ struct nf_conntrack_tupledo { \ (tuple)->src.u.all =0 ; \ (tuple)->dst.u.all =0 ; \ -memset ((tuple)->src.u3.all,0 , \ -sizeof (u_int32_t)*NF_CT_TUPLE_L3SIZE ); \ -memset ((tuple)->dst.u3.all,0 , \ -sizeof (u_int32_t)*NF_CT_TUPLE_L3SIZE ); \ +memset (&(tuple)->src.u3,0 ,sizeof ((tuple)->src.u3)); \ +memset (&(tuple)->dst.u3,0 ,sizeof ((tuple)->dst.u3)); \ } while (0)#ifdef __KERNEL__
net/netfilter/nf_conntrack_l3proto_generic.c +4 -4
@@ -43,8 +43,8 @@ DECLARE_PER_CPU(struct nf_conntrack_statstatic int generic_pkt_to_tuple (const struct sk_buff *skb,unsigned int nhoff,struct nf_conntrack_tuple *tuple) { -memset (tuple->src.u3.all,0 ,NF_CT_TUPLE_L3SIZE ); -memset (tuple->dst.u3.all,0 ,NF_CT_TUPLE_L3SIZE ); +memset (&tuple->src.u3,0 ,sizeof (tuple->src.u3)); +memset (&tuple->dst.u3,0 ,sizeof (tuple->dst.u3));return 1 ; }
@@ -52,8 +52,8 @@ static int generic_pkt_to_tuple(const ststatic int generic_invert_tuple (struct nf_conntrack_tuple *tuple,const struct nf_conntrack_tuple *orig) { -memset (tuple->src.u3.all,0 ,NF_CT_TUPLE_L3SIZE ); -memset (tuple->dst.u3.all,0 ,NF_CT_TUPLE_L3SIZE ); +memset (&tuple->src.u3,0 ,sizeof (tuple->src.u3)); +memset (&tuple->dst.u3,0 ,sizeof (tuple->dst.u3));return 1 ; }
A message that is not in the archive (sent off-list or not yet received): [email protected]
Harald Welte
AppliedRe: more nf_conntrack/ip_conntrack questions
Quoted 9 lines · Yasuyuki KOZAKAI
From: Amin Azez <[email protected]>
Date: Mon, 12 Sep 2005 13:04:40 +0100Quoted 2 lines
Sure, I don't have any fault with the structures, just the way the sizeof is measured for initial zero-ing.
Oh, it's reasonable. Thank you for notice.
Harald, please apply this patch.
thanks, applied to netfilter-2.6.14#nf_conntrack
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie