tasklwIP - A Lightweight TCP/IP stack - Tasks: task #7506, NAT support for lwIP

 
 

You are not allowed to post comments on this tracker with your current authentication level.

task #7506: NAT support for lwIP

Submitter:  Frédéric Bernon <fbernon>
Submitted:  Tue 04 Dec 2007 10:40:48 PM UTC
   
 
Category:  None Should Start On:  Mon 03 Dec 2007 11:00:00 PM UTC
Should be Finished on:  Wed 28 Jan 2015 12:00:00 AM UTC Priority:  1 - Later
Status:  Cancelled Privacy:  Public
Percent Complete:  0% Assigned to:  None
Open/Closed:  Closed Planned Release:  None
Effort:  0.00

Jump to the original submission

Wed 12 May 2010 10:12:15 PM UTC, comment #12: 

Cancelled as christian didn't have the (full?) copyright on the code he uploaded. Which is also the reason I deleted the files. I have already posted this here but it seems that that post is lost...

I think the general idea of lwIP NAT'ing is cool, but I'm done with it. If anyone wants to continue, I'll leave this open as cancelled/later.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 05 May 2010 07:36:09 PM UTC, comment #11: 

Finally, I've come round to lwIP'ing the source code and reviewing it a bit. Unfortunately, I couldn't test it yet, since I only have one netif.

As to the license: I've put this under the lwIP license since I regard posting this here as a task as a silent agreement to that. If you disagree, Walter, please let me know so I'll delete it from CVS again!!!

Simon Goldschmidt <goldsimon>
Group administrator
Wed 26 Aug 2009 09:21:21 AM UTC, comment #10: 

I didn't have the time to look at the nat.c implementation, yet, but wouldn't be the source- and dest-netif be enough for the struct passed to ip_nat_init()? That way, we wouldn't need to wait with the call until the interfaces are initialized. Oh, and _init() is a bad name, too, since in lwIP, it is used to initialize modules that need initialization (return type void, no arguments). Given the _remove() function, _add() would be better.

As to TODO 3 in nat.c: I'd use a linked list approach and sort it (recently used entry to the front) for speed. That would require a new memp pool (one for the 3 protocols - can be a union struct).

There is some room for code size improvement for the 3 protocols, and I'd love to get the code commented (see the rest of the stack) before checking it in.

Other than that, I'll try to check it in these days to get a starter on this: since it is mostly new code, the effect on existing code is minimal.

BTW: Do you agree to put this under the same license as the rest of the stack? (Your copyright line will be added - see other files for examples).

Simon Goldschmidt <goldsimon>
Group administrator
Tue 25 Aug 2009 10:10:21 PM UTC, comment #9: 

I have added an updated version of the NAT support which already works pretty well. Still it is somewhat inefficient but this is will be worked out next.

New file: lwip-nat-090826.diff, Applies to v1.3.0


(file #18642)

Christian Walter <cwalter_at>
Thu 20 Aug 2009 02:55:55 PM UTC, comment #8: 

Hello,

Since I would like to continue working I would like to discuss the design questions a bit more.

 - I am planning to use a hash algorithm to avoid searching the linked lists for NAT entries. Are there some existing hash maps in lwIP I have not seen or in contrib? Would the additional code for a hash map be okay?

 - If we have the has map we could create the hash from the source, dest, port, dest and protocol. We could then use a single hash table for all nat entries similar to the already existing ones. I did not like the old version which tried to put everything into one struct since it was not extensible.

 - We have not talked about the ip fragmentation issues and I am not aware of the problems. I think basically using the existing code in some form would be okay. And a soon as the paket has been reassembled we would then pass it to the NAT.

 - Is there any ip fragmentation code available? We would need this if we route pakets between interfaces with different MTUs. n this case lwIP would need to fragment.

 - What about the configuration interface? Is something I used in this example code okay - See ip_nat_init. The final version will of course allow multiple nat sources.

 - I will change the license of the code as soon as we are finished because we want to get this into the core since we will be using this code in a product.

Thanks for feedback,
  Christian

Christian Walter <cwalter_at>
Tue 18 Aug 2009 10:01:53 PM UTC, comment #7: 

Hello,

I have created an intial version for NAT tested on lwIP 1.3.0. It integrates much cleaner than the old one because it is fully integrated in ip.c. The old version was a hook directly between the network interface and the ip stack which gives rise to a lot of problems (unknown header sizes, no checking, processing within the context of the netif driver).

Still there are a lot of things to improve in my version and I am grateful for any feedback. Some TODOs can be found on to of the nat.c

(file #18601, file #18602)

Christian Walter <cwalter_at>
Thu 07 May 2009 03:35:01 PM UTC, comment #6: 

SH*T, I just deleted the wrong nat.c file (#14563), there is no safety-question, and now it seems to be lost. Does someone have it and can re-add it???

Simon Goldschmidt <goldsimon>
Group administrator
Wed 05 Dec 2007 08:12:39 AM UTC, comment #5: 

Good, it's good you have already update it.

>You may delete (file #14561, file #14562) in Comment 3


I'm not sure we can, but it's not a problem

>BTW: I'm not sure where you plan to put this to(core, netif or contrib), well I prefer core, for it contains the modification of IP/UDP/TCP header.


Yes, I thought to use an option to integrate it in the "core", mainly to integrate the memp module. Of course, if there is no objections to add it (in post-1.3.0)

But first, I will take a look to your updates.

Thank you

Frédéric Bernon <fbernon>
Group Member
Wed 05 Dec 2007 05:57:19 AM UTC, comment #4: 

You may delete (file #14561, file #14562) in Comment 3
It's wrong

Bockham Zhao <bockham>
Wed 05 Dec 2007 03:21:19 AM UTC, comment #3: 

Modified log:

Integrate nat_memp.c, nat_memp.h and natopts.h to nat.c.
Split nat_input to two functions nat_local_input and nat_global_input.
Add two api funcions nat_start and nat_stop.
...


(file #14561, file #14562)

Bockham Zhao <bockham>
Wed 05 Dec 2007 03:19:06 AM UTC, comment #2: 

I have modified this old nat implementation to my 1.1.1 release, and it works well. I will upload them later.

BTW: I'm not sure where you plan to put this to(core, netif or contrib), well I prefer core, for it contains the modification of IP/UDP/TCP header.

Bockham Zhao <bockham>
Tue 04 Dec 2007 10:44:11 PM UTC, comment #1: 

(from http://www.sm.luth.se/~conny/nat/ )

NAT for lwIP is a simple open source implementation that allows small lwIP enabled devices to create a private network which share a single connection to an external network such as the Internet.

Since the local IP addresses used in the private network are invalid in the external network, NAT multiplex the traffic from the private network and present it to the external network as if it was coming from a single device having only one IP address.

NAT can be useful when the external network can not provide valid addresses to all devices or because the internal addressing must be kept private from the external network.

NAT features:

    * Implements traditional NAT which makes use of both IP addresses and port numbers to uniquely identify each connection between two devices/machines.
    * Transparent to lwIP network interfaces after setup which includes assigning the interface an internal IP address from a configurable address space.
    * Makes use of lwIPs IP packet forwarding mechanism to route packets between interfaces.
    * Implements three (to each other) independent mechanisms that can be configured to close down a session.
    * Can optionally assign private IP addresses to lwIP interfaces that registers with the private network

The source code is available under a BSD license.


Frédéric Bernon <fbernon>
Group Member
Tue 04 Dec 2007 10:40:48 PM UTC, original submission:  

There is some months, I have found this contribution from Conny Öhult (at EISLAB). The code could be useful for anyone which want to design a simple router with lwIP, or to implement a simple SLIP server. The link is :

http://www.sm.luth.se/~conny/nat/

The code is pretty small, and I think it could be integrated without any difficulties (even if it's pretty old).



Frédéric Bernon <fbernon>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #14564:  nat.h added by bockham (4KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by kieranm (Updated the item)
  • -email is unavailable- added by cwalter_at (Updated the item)
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by bockham (Posted a comment)
  • -email is unavailable- added by fbernon (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 25 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-01-28 goldsimon Should be Finished on- 2015-01-28
        Open/ClosedOpen Closed
    2010-05-12 goldsimon Should be Finished on2007-12-03 -
        Priority5 - Normal 1 - Later
        StatusReady For Test Cancelled
        Percent Complete90% 0%
        Assigned togoldsimon None
        Planned Release1.4.0 None
    2010-05-05 goldsimon Attached File#18601 Removed
    2010-05-05 goldsimon Attached File#18602 Removed
    2010-05-05 goldsimon Attached File#18603 Removed
    2010-05-05 goldsimon Attached File#18604 Removed
    2010-05-05 goldsimon Attached File#18642 Removed
    2010-05-05 goldsimon StatusNone Ready For Test
        Percent Complete0% 90%
        Assigned toNone goldsimon
    2009-08-25 cwalter_at Attached File- Added lwip-nat-090826.diff, #18642
    2009-08-20 kieranm Planned ReleaseNone 1.4.0
    2009-08-18 cwalter_at Attached File- Added nat.c, #18604
    2009-08-18 cwalter_at Attached File- Added ipv4-nat.patch, #18603
    2009-08-18 cwalter_at Attached File- Added nat.h, #18601
        Attached File- Added nat.c, #18602
    2009-05-07 goldsimon Attached File#14561 Removed
    2009-05-07 goldsimon Attached File#14562 Removed
    2009-05-07 goldsimon Attached File#14563 Removed

    Back to the top

    Powered by Savane 3.12