Status of IPv6 conn-tracking in 2.4.x series ?
Dear Netfilter-devel,
Could somebody tell to me, what is present status in IPv6 connection-tracking filters of netfilter codes ? Having browsed your CVS, there are some versions of such, and tantalizing glimpses of somebody doing development in some bitkeeper somewhere...
My present kernels are stock redhat things, but applying couple extra patches isn't out of question, if they give me things equal to IPv4 connection tracking.
I don't use NAT, but I do want to do statefull filtering.
If need be, I can freshen my kernel coding skills quite easily ;-)
Yours Sincerely,
Matti Aarnio -- <[email protected]>
Hi,
From: Matti Aarnio <[email protected]>
Date: Thu, 13 Nov 2003 03:01:59 +0200
Quoted 7 lines
Dear Netfilter-devel,
Could somebody tell to me, what is present status in IPv6 connection-tracking filters of netfilter codes ? Having browsed your CVS, there are some versions of such, and tantalizing glimpses of somebody doing development in some bitkeeper somewhere...
If you want to use ip6_conntrack ASAP, you can find the patch in archives of this list(24 Sep. 2003).
Or in USAGI kernel, too. http://www.linux-ipv6.org/
BTW, this patch works only with Linux 2.6. If you want to use it with Linux 2.4, some changes are needed. ex) replace synchronize_net() to br_write_{un}lock_bh(), fix the codes related to nf_reinject() in ip6_conntrack_reasm.c.
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------
nf_conntrack (l3 independent conntrack)
Quoted 9 lines · Yasuyuki Kozakai
If you want to use
ip6_conntrackASAP, you can find the patch in archives of this list(24 Sep. 2003).Or in USAGI kernel, too. http://www.linux-ipv6.org/
BTW, this patch works only with Linux 2.6. If you want to use it with Linux 2.4, some changes are needed. ex) replace
synchronize_net()to br_write_{un}lock_bh(), fix the codes related tonf_reinject()inip6_conntrack_reasm.c.
Hi again Yasuyuki. Sorry for not getting back to you earlier. I'm just busy with way too much work and don't really know where to start and when I'll be ever finished with all that stuff.
Please be assured that I didn't forget about the issue, but I just didn't find the time to finish the design paper on l3 independent conntrack.
However, I'll attach the current (icomplete) start of my paper to this email and also put it in CVS.
Maybe this is a start and somebody else will pick it up and express his idea about how the implementation / organization of data structures can look like.
Quoted 1 line
Yasuyuki KOZAKAI
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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
Design of a layer 3 independent netfilter connection tracking (nf_conntrack)
Harald Welte
$Revision$ - INCOMPLETE
Copyright © 2003 Harald Welte <[email protected]>
_________________________________________________________
Table of Contents
1. Rationale
2. Outline
3. Implementation
1. Rationale
The 2.4.x kernel series first introduced stateful packet filtering capabilities to Linux: The netfilter ip_conntrack module. While in itself modular and extensible, it is a strict IPv4 connection tracking implementation. There is a demand for stateful packet filtering of IPv6 (and potentially other layer 3 protocols). In fact, we now even have an IPv6 port of the ip_conntrack module.
However, this kind of port (by means of copying the existing IPv4 code and doing some IPv6 specific modifications) has proven to introduce a number of maintainance problems - apart from being bad programming practice. The netfilter core team has quite some experience with the ip_tables / ip6_tables port, which was done in a similar way and has become part of the 2.4.x kernel series.
Thus, a layer three independent connection tracking core is needed, together with plugins for the IPv4 and IPv6 specific part of connection tracking.
While the author of this paper doesn't have the ability to work on this project on his own (due to time constraints with other netfilter work like pkt_tables), this paper might give an idea about his view on how this layer3-generalization of conntrack could be achieved.
_________________________________________________________
2. Outline
At a first glance one might think that the differences between ipv4 and ipv6 connection tracking are quite small. Both protocols work in a similar way, both of them are most commonly used with TCP and UDP as layer 4. They just have a larger address space. So the overall notion of a connection within both protocols is exactly the same.
However, there are some areas where differences are leading to issues with regard to connection tracking:
* Fragmentation. While ip_conntrack does always defragment packets before connection tracking happens (and potentially re-fragment beofore the packets leave the machine again), IPv6 routers don't regularly perform fragmentation on their own.
* NAT. ip_conntrack provides the foundation for the stateful NAT implementation included with iptables. In IPv6, there is no need for stateful NAT.
* Extension Headers. In IPv6, there can be extension headers between the IPv6 packet header and the packet payload. Parsing of those extension headers is needed, before the layer4 header can be accessed by the l4 protocol helpers in conntrack (ip_conntrack_proto_{tcp,udp}.c).
* ICMPv6. Unlike TCP and UDP which are the same between IPv4 and IPv6, ICMPv6 is quite different to ICMPv4. One example is the stateless autoconfiguration / neighbour discovery mechanism employing multicast ICMPv6 packets, instead of the ARP protocol used with IPv4. Connection tracking should not interfere with the autoconfiguration messages
* Scope of addresses. There are for example link-local addresses that can never establish connections via a layer 3 routing device, because they are not allowed to leave a physical network link. It is questionable whether this should affect connection tracking or rather be left to the administrator to configure in ip6tables.
* Size of Addresses. ip_conntrack keeps two address tuples per connection (every tuple is 2*(sizeof(l3_addr)+sizeof(l4_addr)), thus adding up to 32 bytes. In IPv6 the size of a tuple would grow up to at least 80 bytes due to the large address size. If a union for struct nf_conntrack_tuple was used, every IPv4 conntrack entry would waste 48 bytes of memory, which is not acceptable considering the effect on wasting cachelines. Thus, a mechanism must be implemented to have differently sizes nf_conntrack structures, allocated from different slab caches, allocated from different slab caches. The dynamic part could be added to the end of a structure, so all l3 independent structure members can be transparently accessed by the core.
_________________________________________________________
3. Implementation
ip_conntrack needs to be split into two parts:net/core/netfilter/nf_conntrack_core.c
- init()
- initialize conntrack hash table and slab cache pools
- register sockopt for SO_ORIGINAL_DST
- register sysctl table
- nf_conntrack_in()
- expect a defragmented packet
- resolve the layer3 helper function (nf_ct_find_l3prot())
- reolve_normal_ct()
- l4prot->packet()
- call application helper
net/ipv4/netfilter/nf_conntrack_ipv4.c
- init()
- register with nf_conntrack core. tell it the size of the l4 specific part of struct nf_conntrack.
- register with ipv4 netfilter hooks (ip_conntrack_standalone.c
) and
attach nf_conntrack_in() or a local wrapper function for defrag, size checks, ...
- export l4 hash function
- export get_tuple() function
Re: nf_conntrack (l3 independent conntrack)
Hi, Harald,
From: Harald Welte <[email protected]>
Subject: nf_conntrack (l3 independent conntrack)
Date: Sat, 15 Nov 2003 11:50:20 +0100
Quoted 10 lines
Hi again Yasuyuki. Sorry for not getting back to you earlier. I'm just busy with way too much work and don't really know where to start and when I'll be ever finished with all that stuff.
Please be assured that I didn't forget about the issue, but I just didn't find the time to finish the design paper on l3 independent conntrack.
However, I'll attach the current (icomplete) start of my paper to this email and also put it in CVS.
I read. It's very usefull to implement nf_conntrack. Thank you.
Quoted 6 lines
* Size of Addresses.
ip_conntrackkeeps two address tuples per connection (every tuple is 2*(sizeof(l3_addr)+sizeof(l4_addr)), thus adding up to 32 bytes. In IPv6 the size of a tuple would grow up to at least 80 bytes due to the large address size. If a union for structnf_conntrack_tuplewas used, every IPv4
Quoted 8 lines
conntrack entry would waste 48 bytes of memory, which is not acceptable considering the effect on wasting cachelines. Thus, a mechanism must be implemented to have differently sizes
nf_conntrackstructures, allocated from different slab caches, allocated from different slab caches. The dynamic part could be added to the end of a structure, so all l3 independent structure members can be transparently accessed by the core.
OK, I understand this problem, but I don't perfectly understand the detail of your solution.
Is "The dynamic part" equal to tuple ? or does this part include the private structures for L3, protocol, and helper ?
Quoted 3 lines
net/ipv4/netfilter/nf_conntrack_ipv4.c
-init()
- register withnf_conntrackcore. tell it the size of the l4
I think it is not l4 but l3. Is this right ?
BTW,
Quoted 3 lines
Maybe this is a start and somebody else will pick it up and express his idea about how the implementation / organization of data structures can look like.
Actually, I already started implementing L3 independent conntrack....
At present, I have implemented ipv4, ipv6, tcp, udp, icmp[v6], generic, standard, and core except for the following items.
- separating "struct tuple" of IPv4 and IPv6
- hash function of tuple
- handling fragmented IPv6 packet
- DUMP_TUPLE()
- SO_ORIGINAL_DST
And I'm debugging now. I can see that it tracks the connections of ssh(TCP), iperf(UDP), and ping[6](ICMP[v6]), and output /proc/net/netfilter/nf_conntrack .
I'll send the patches as snapshot when I finish debugging. Or should I send them after I finish implementing above items ?
Regeards,
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------
Re: nf_conntrack (l3 independent conntrack)
Quoted 4 lines · Yasuyuki Kozakai
Quoted 2 lines
However, I'll attach the current (icomplete) start of my paper to this email and also put it in CVS.
I read. It's very usefull to implement
nf_conntrack. Thank you.
Well, I doubt it is, but anyway ;)
Quoted 6 lines
Quoted 1 line
* Size of Addresses.
ip_conntrackkeeps two address tuplesOK, I understand this problem, but I don't perfectly understand the detail of your solution.
Is "The dynamic part" equal to tuple ? or does this part include the private structures for L3, protocol, and helper ?
There is a static part. The static part would countain everything that exists for connections of any protocol. An (incomplete) list of static structure members would be:
- usage count
- list_head's for the hash table[s]
- pointer to the l4 helper (->proto)
- pointer to the l3 helper (new)
In the first step, the static part would also contain:
- list of expected connections
- union for conntrack helper
- union for nat helper
However, my real idea was some mechanism where the conntrack core can
deal with what I now call 'extensible conntracks'. The size of the
conntrack would be determined at 'NEW' time, i.e. when we receive the first packet. I.e. if it is an ipv4 packet, we only need ipv4-sized tupels. If there is no helper registered for that connection, there is no need to allocate the memory for expect_tuple_list and others.
In the 'perfect world', we would thus have several different sized kmem_cache's:
- struct ip_conntrack for ipv4, no helper
- struct ip_conntrack for ipv4, with helper
- struct ip_conntrack for ipv6, no helper
- struct ip_conntrack for ipv6, with helper
I think we can save a lot of memory, if we not only seperate the l3-specific part (tuple), but also the expectation-specific part. I guess in most installations, 99.9% of all connections don't have a helper - and thus no expectations.
And to reply to your question: The tuple is part of the 'dynamic' part, along with other fields.
Quoted 5 lines
Quoted 3 lines
net/ipv4/netfilter/nf_conntrack_ipv4.c
-init()
- register withnf_conntrackcore. tell it the size of the l4I think it is not l4 but l3. Is this right ?
yes, sorry.
Quoted 1 line
Actually, I already started implementing L3 independent conntrack....
that is good news. Your work is really appreciated.
Quoted 2 lines
I'll send the patches as snapshot when I finish debugging. Or should I send them after I finish implementing above items ?
If possible, I think it is good to have the development as open as possible. It's not important that the code runs (or even compiles). But if your current status of development was public, other netfilter developers could have a look at the code and comment.
If you are interested, we oould also put it in the netfilter.org CVS repository.
Quoted 2 lines
Regeards,
Yasuyuki KOZAKAI
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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
Re: nf_conntrack (l3 independent conntrack)
Hi, Harald,
From: Harald Welte <[email protected]>
Date: Tue, 18 Nov 2003 17:51:38 +0100
Quoted 5 lines · Yasuyuki Kozakai
Quoted 2 lines
I read. It's very usefull to implement
nf_conntrack. Thank you.Well, I doubt it is, but anyway ;)
Did I missread something enough to make you suspect that I read it...
Quoted 2 lines
And to reply to your question: The tuple is part of the 'dynamic' part, along with other fields.
Thank you for datail explanation. I try to rewrite the codes that processes nf_conntrack and tuple. At first, I'll move only tuple to the dynamic part of nf_conntrack. I may ask you about other question, I'm happy if you reply.
Quoted 7 lines
Quoted 2 lines
I'll send the patches as snapshot when I finish debugging. Or should I send them after I finish implementing above items ?
If possible, I think it is good to have the development as open as possible. It's not important that the code runs (or even compiles). But if your current status of development was public, other netfilter developers could have a look at the code and comment.
OK, I'll send it ASAP. But maybe I take a week to get permission.
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------
Re: nf_conntrack (l3 independent conntrack)
Quoted 5 lines · Yasuyuki Kozakai
Quoted 3 lines
Quoted 1 line
I read. It's very usefull to implement
nf_conntrack. Thank you.Well, I doubt it is, but anyway ;)
Did I missread something enough to make you suspect that I read it...
No, this was just self-ironic. I just don't think it is that much useful in it's current form.
Quoted 6 lines
Quoted 2 lines
And to reply to your question: The tuple is part of the 'dynamic' part, along with other fields.
Thank you for datail explanation. I try to rewrite the codes that processes
nf_conntrackand tuple. At first, I'll move only tuple to the dynamic part ofnf_conntrack. I may ask you about other question, I'm happy if you reply.
Sure, feel free to ask. It's probably best to Cc netfilter-devel, since I sometimes need a couple of days to respond all my email - and maybe somebody else also has an answer to your question.
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
I'll send the patches as snapshot when I finish debugging. Or should I send them after I finish implementing above items ?
If possible, I think it is good to have the development as open as possible. It's not important that the code runs (or even compiles). But if your current status of development was public, other netfilter developers could have a look at the code and comment.
OK, I'll send it ASAP. But maybe I take a week to get permission.
Would you need to get that permission every time you publish a certain version of the code? Isn't it possible to publish it once and get a general permission to publish changes to that already-published code?
Thanks again.
Quoted 5 lines
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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
Re: nf_conntrack (l3 independent conntrack)
Hi, Harald,
From: Harald Welte <[email protected]>
Subject: Re: nf_conntrack (l3 independent conntrack)
Date: Wed, 19 Nov 2003 14:24:44 +0100
Quoted 5 lines
Quoted 1 line
OK, I'll send it ASAP. But maybe I take a week to get permission.
Would you need to get that permission every time you publish a certain version of the code? Isn't it possible to publish it once and get a general permission to publish changes to that already-published code?
Well, I need to write some documents to get permission from my company this time. Probably I don't need anymore to send codes related l3 independent conntrack.
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------
Re: nf_conntrack (l3 independent conntrack)
In reply to Harald WelteHi, Harald and all,
I'm seeking the best structure of nf_conntrack and tuple in L3 independent conntrack, and I have some issues.
-----------------------------------------------------------------------------
1. I think one of benefits of L3 indepedent conntrack is that the various L3 connection can be represented with only one structure -- tuple.
For example, we can represent IPv4-IPv6 translated packet with
Original: ipv4_addr1, port1 -> ipv4_addr2, port2
Reply : ipv6_addr2, port2 -> ipv6_addr1, port1Probably, we need to reallocate tuple somewhere to create this tuple. Because when received initial packet in this connection, the core module create:
Original: ipv4_addr1, port1 -> ipv4_addr2, port2
Reply : ipv4_addr2, port2 -> ipv4_addr1, port1so the size of tuple "Reply" need to be changes. But if we adopt the way in white paper, this mean that we have to reallocate nf_conntrack. Moreover, the size of nf_conntrack is different from ip_conntracck and ip6_conntrack. So slab caches for all case of Original-Reply are needed.
Then I suggest that
- nf_conntrack has only static part and tuple_hash, and tuple_hash include the pointer to tuple
- tuple is allocated from different slab caches.
We can save memory spaces and utilize slab cache in this way. The disadvantages are that
- The management of nf_coonntrack become more complex.
- If L4 part in tuple should be handled as dynamic part, we can't adopt this approach.
... or, shouldn't we assume such a above connection ?
-----------------------------------------------------------------------------
2. Do you think which is better ? Or do you have other idea ?
a. define ip_conntrack_tuple and ip6_conntrack_tuple.
b. define only nf_conntrack which has "size" and "data[0]" in L3 part.
If we choose a., we have to make L3 module operate tuple, so have to search L3 module every operations.
And if we select b., we need to calculate to get the pointer to L3/L4 part in tuple. Please remember that the offset of members in "dst" aren't static because of "src" above "dst".
I like b. than a. . Because we can define L4 part in the header files for each protocol.
-----------------------------------------------------------------------------
These issue affect basic structure and codes in L3 independent conntrack. I want to carefully choose because I don't want to rewrite many time.
BTW, "flowi" in include/net/flow.h have union... I think this is one choise.
And BTW, the name "nf_conntrack" is already used in sk_buff.h . I use "nf_conn" in my code for now...
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------
Re: nf_conntrack (l3 independent conntrack)
Quoted 2 lines · Yasuyuki Kozakai
Hi, Harald and all,
Hi Yasuyki, sorry for my delayed reply.
Quoted 3 lines
-----------------------------------------------------------------------------
1. I think one of benefits of L3 indepedent conntrack is that the various L3 connection can be represented with only one structure -- tuple.
indeed.
Quoted 9 lines
For example, we can represent IPv4-IPv6 translated packet with
Original: ipv4_addr1, port1 -> ipv4_addr2, port2 Reply : ipv6_addr2, port2 -> ipv6_addr1, port1Probably, we need to reallocate tuple somewhere to create this tuple. Because when received initial packet in this connection, the core module create:
Quoted 7 lines
Original: ipv4_addr1, port1 -> ipv4_addr2, port2 Reply : ipv4_addr2, port2 -> ipv4_addr1, port1so the size of tuple "Reply" need to be changes. But if we adopt the way in white paper, this mean that we have to reallocate
nf_conntrack. Moreover, the size ofnf_conntrackis different fromip_conntracckandip6_conntrack. So slab caches for all case of Original-Reply are needed.
well, yes. But I don't think we should care too much about the corner cases. In a realistic setup, we would mainly have two sizes:
1) nf_conntrack + 2*tuple_ipv4
2) nf_conntrack + 2*tuple_ipv6
In case of an ipv4-ipv6 connection, I would just use tuple number two and represent the ipv4 end as ipv6-mapped-ipv4 address.
Quoted 10 lines
Then I suggest that
-nf_conntrackhas only static part andtuple_hash, andtuple_hashinclude the pointer to tuple
- tuple is allocated from different slab caches.We can save memory spaces and utilize slab cache in this way. The disadvantages are that
- The management ofnf_coonntrackbecome more complex.
- If L4 part in tuple should be handled as dynamic part, we can't adopt this approach.
one problem is also that we would have to allocate three items for every new connections, which is bad. I think we should have two slab caches, one with v4 tuples, one with v6 tuples. Depending on the type of connection, we chose either.
Quoted 1 line
... or, shouldn't we assume such a above connection ?
In that case, we might have to reallocate the connection. but ipv4-ipv6 nat should be the corner case, and in that case we can afford a second allocation. two allocations in that rare case is still less than three in every case.
Quoted 7 lines
2. Do you think which is better ? Or do you have other idea ?
a. define
ip_conntrack_tupleandip6_conntrack_tuple.
b. define onlynf_conntrackwhich has "size" and "data[0]" in L3 part.If we choose a., we have to make L3 module operate tuple, so have to search L3 module every operations.
I think we should have something like
struct nf_conntrack {
struct list_head;
int foo;
int bar;
union {
struct nf_conntrack_ipv4 ipv4[0];
struct nf_conntrack_ipv6 ipv6[0];
} l3;
};this way we can dereference all fields without any typacasting or manual pointer calculations..
Quoted 2 lines
And BTW, the name "
nf_conntrack" is already used insk_buff.h. I use "nf_conn" in my code for now...
mh. I'd rather rename nf_conntrack in sk_buff.h ;) but that's a minor case.
Quoted 1 line
Yasuyuki KOZAKAI
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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
Re: nf_conntrack (l3 independent conntrack)
Hi, Harald,
Thank you for replying.
[ short ]
I agree that we should not care too much about the corner cases, and translation of IPv4 (or IPv6) packets is the corner case, IN NOW.
And, I still seem to misunderstand your idea about tuple.
I tried to write structure of tuple like that in last week.
- all connection can be represented with nf_conntrack_tuple.
- l4 part and l3 protocol number in tuple can be accessed with l3 independently.
- operations of tuple are easy as possible.
- only one hash for conntrack is allocated in kernel.
I don't know these are what you want, or not.
And, I thought about some types of structure, but all of them have some complexity to operate tuple. I needed typecasting, manual calculation of pointer.
After all, I think that using "union" is simply and better even though wasting memory space.
[ detail ]
Quoted 6 lines
cases. In a realistic setup, we would mainly have two sizes:
1)nf_conntrack+ 2*tuple_ipv4
2)nf_conntrack+ 2*tuple_ipv6In case of an ipv4-ipv6 connection, I would just use tuple number two and represent the ipv4 end as ipv6-mapped-ipv4 address.
# ??? I assume 128 bit representation of IPv4 address in "2)".
I suspect this does not work well. We have to search nf_conntrack from hash 2 times every IPv4 packets -- by using tuple_ipv4 and tuple_ipv6. And I think we should not use tuple_ipv6 to represent ipv4 connection. I don't want to be confused that a tuple_ipv6 represents ipv4 or ipv6.
But I'll stop talking about this any more. This is the corner cases as you say, in now.
Quoted 11 lines
Quoted 10 lines
Then I suggest that
-nf_conntrackhas only static part andtuple_hash, andtuple_hashinclude the pointer to tuple
- tuple is allocated from different slab caches.We can save memory spaces and utilize slab cache in this way. The disadvantages are that
- The management ofnf_coonntrackbecome more complex.
- If L4 part in tuple should be handled as dynamic part, we can't adopt this approach.
Quoted 4 lines
one problem is also that we would have to allocate three items for every new connections, which is bad. I think we should have two slab caches, one with v4 tuples, one with v6 tuples. Depending on the type of connection, we chose either.
You're right about that problem.
Quoted 7 lines
Quoted 7 lines
2. Do you think which is better ? Or do you have other idea ?
a. define
ip_conntrack_tupleandip6_conntrack_tuple.
b. define onlynf_conntrackwhich has "size" and "data[0]" in L3 part.If we choose a., we have to make L3 module operate tuple, so have to search L3 module every operations.
Oh, sorry, I mistook in b. I wanted to ask about tuple.
b. define only nf_conntrack_tuple which has "size" and "data[0]"
in L3 part.
i.e.
struct nf_conntrack_tuple_elem {
u_int16_t pnum; /* l3 protocol number (in src) or
l4 protocol number (in dst) */
u_int16_t size;
union {
struct {
u_int16_t port;
} tcp;
...
} u;
u_int8_t data[0]; /* l3 part */
};struct nf_conntrack_tuple {
u_int32_t size; /* size of src(dst) part */
u_int8_t data[0]; /* followed by src and dst part */
};I think that the l3 & l4 protocol number and l4 part in tuple should be independent of l3 part. Then l4 modules can be implemented without thought of l3 protocol, and l3 module can be found from l3 protocol number in tuple. So I wanted to choice "b." if we compress tuple size. Of cause, typecasting and manual pointer calculations is needed.
And, if I'm allowed to change structure of tuple more, we can define tuple as following.
struct nf_conntrack_tuple {
u_int16_t l3num;
u_int16_t protonum;
/* l4 part */
union {
struct {
u_int16_t port;
} tcp[2];
...
} l4;
/* l3 part */
union {
struct nf_conntrack_tuple_ipv4 ipv4[0];
struct nf_conntrack_tuple_ipv6 ipv6[0];
} l3;
};In this case, typecasting and manual pointer calculations is not needed. But It's more difficult to rewrite IPv4 NAT modules.
Quoted 13 lines
I think we should have something like
struct nf_conntrack { struct list_head; int foo; int bar; union { struct nf_conntrack_ipv4 ipv4[0]; struct nf_conntrack_ipv6 ipv6[0]; } l3; };
Quoted 2 lines
this way we can dereference all fields without any typacasting or manual pointer calculations..
I agree. but, please don't forget that size of nf_conntrack_tuple is dynamic, so we have to define
struct nf_conntrack_ipv4 {
int foo;
int bar;
u_int8_t tuple[0];
}and, we need tuple_hash in nf_conntrack. I assume that
- nf_conntrack include tuple_hash
- tuple_hash include the pointer to tuple in nf_conntrack_ipv{4,6}
Then tuple and tuple_hash can be accessed with l3 independently.
You know this way is complex. and it is clear that
- the way to use "union" in l3 part in tuple is the most simple.
and I want to use it very much. But.. ok, I'll try rewrite my code with nf_conntrack_tuple and nf_conntrack I said.
- I'll not define tuple for ipv4 and ipv6 separately. I'll define just nf_conntrack_tuple.
- nf_conntrack include tuple_hash
- tuple_hash include the pointer to tuple in nf_conntrack_ipv{4,6}
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------
Re: nf_conntrack (l3 independent conntrack)
Hi, Harald,
Sorry, I forgot to say the important thing.
I want to use "union" very much. But.. I'll think of structure and try to rewrite my code for some time.
From: Yasuyuki Kozakai <[email protected]>
Date: Tue, 02 Dec 2003 09:34:40 +0900 (JST)
Quoted 21 lines
[ short ]
I agree that we should not care too much about the corner cases, and translation of IPv4 (or IPv6) packets is the corner case, IN NOW.
And, I still seem to misunderstand your idea about tuple.
I tried to write structure of tuple like that in last week.
- all connection can be represented withnf_conntrack_tuple.
- l4 part and l3 protocol number in tuple can be accessed with l3 independently.
- operations of tuple are easy as possible.
- only one hash for conntrack is allocated in kernel.I don't know these are what you want, or not.
And, I thought about some types of structure, but all of them have some complexity to operate tuple. I needed typecasting, manual calculation of pointer.
After all, I think that using "union" is simply and better even though wasting memory space.
Re: nf_conntrack (l3 independent conntrack)
In reply to Harald WelteHi, Harald and all,
I've got the permission to publish my nf_conntrack.
In this code, nf_conntrack_tuple use "union" in the l3 part. But anyway, I send it.
This is alpha version, please use on your responsibility.
And please don't forget that nf_conntrack.o don't work with ip_conntrack.o.
Regards,
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------
Re: nf_conntrack (l3 independent conntrack)
Sorry.... I forgot sending this patch.
From: Yasuyuki Kozakai <[email protected]>
Date: Wed, 03 Dec 2003 21:48:29 +0900 (JST)
Quoted 4 lines
Hi, Harald and all,
I've got the permission to publish my
nf_conntrack.
Quoted 8 lines
In this code,
nf_conntrack_tupleuse "union" in the l3 part. But anyway, I send it.This is alpha version, please use on your responsibility.
And please don't forget that nf_conntrack.o don't work with ip_conntrack.o.
Regards,
----------------------------------------
Yasuyuki KOZAKAI
Communication Platform Laboratory,
Corporate Research & Development Center,
Toshiba Corporation
[email protected]
----------------------------------------