Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/nat: Support IPv6 Masquerading (NAT66) #12116

Merged
merged 4 commits into from Apr 11, 2024

Conversation

wengzhe
Copy link
Contributor

@wengzhe wengzhe commented Apr 10, 2024

Summary

Patches included:

  • net/nat: Make some IPv4 NAT functions as common
    • To prepare for IPv6 NAT functions.
      • Rename common ipv4_nat_xxx to nat_xxx
      • Move some common definitions into header
  • net/utils: Add net_ipv6_payload to get IPv6 L4 payload
  • net/nat: Support IPv6 Masquerading (NAT66)

Notes:

  1. This version of NAT66 is a stateful one like NAT44, corresponding to Linux's MASQUERADE target of ip6tables. We can support stateless NAT66 & NPTv6 later by slightly modify the address & port selection logic (maybe just match the rules and skip the entry find).
  2. We're using same flag IFF_NAT for both NAT44 & NAT66 to make control easier. Which means, if we enable NAT, both NAT44 & NAT66 will be enabled. If we don't want one of them, we can just disable that one in Kconfig.
  3. Maybe we can accelerate the checksum adjustment by pre-calculate a difference of checksum, and apply it to each packet, instead of calling net_chksum_adjust each time. Just a thought, maybe do it later.
  4. IP fragment segments on NAT66 connections are not supported yet.

Impact

NAT only, add IPv6-to-IPv6 NAT (NAT66) besides previous IPv4-to-IPv4 NAT (NAT44).
All logic under control of CONFIG_NET_NAT.

Testing

  • Described in nat.rst
  • CI

To prepare for future IPv6 NAT functions.
- Rename common ipv4_nat_xxx to nat_xxx
- Move some common definitions into header

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
net/nat/nat.c Outdated Show resolved Hide resolved
@acassis acassis self-requested a review April 10, 2024 14:06
net/nat/ipv6_nat.c Outdated Show resolved Hide resolved
net/nat/ipv6_nat_entry.c Show resolved Hide resolved
net/nat/ipv6_nat_entry.c Outdated Show resolved Hide resolved
Notes:
1. This version of NAT66 is a stateful one like NAT44, corresponding to Linux's MASQUERADE target of ip6tables.  We can support stateless NAT66 & NPTv6 later by slightly modify the address & port selection logic (maybe just match the rules and skip the entry find).
2. We're using same flag `IFF_NAT` for both NAT44 & NAT66 to make control easier.  Which means, if we enable NAT, both NAT44 & NAT66 will be enabled.  If we don't want one of them, we can just disable that one in Kconfig.
3. Maybe we can accelerate the checksum adjustment by pre-calculate a difference of checksum, and apply it to each packet, instead of calling `net_chksum_adjust` each time.  Just a thought, maybe do it later.
4. IP fragment segments on NAT66 connections are not supported yet.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
And fix possibly dead loop.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
net/nat/nat.c Show resolved Hide resolved
@xiaoxiang781216 xiaoxiang781216 merged commit 4eddf84 into apache:master Apr 11, 2024
26 checks passed
wengzhe added a commit to wengzhe/nuttx that referenced this pull request Apr 12, 2024
Finish apache#12116 (comment)

Change-Id: Ie4f1bce00d730f93a6f7484fd3f2203960c49528
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
wengzhe added a commit to wengzhe/nuttx that referenced this pull request Apr 12, 2024
Finish apache#12116 (comment)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
wengzhe added a commit to wengzhe/nuttx that referenced this pull request Apr 12, 2024
Optimize TCP/UDP port selection, and fix possibly dead loop.

Finish discussion in apache#12116 (comment)

Note:
Linux also uses EADDRINUSE for failing in finding a portno, according to https://man7.org/linux/man-pages/man2/bind.2.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
wengzhe added a commit to wengzhe/nuttx that referenced this pull request Apr 12, 2024
Finish apache#12116 (comment)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
wengzhe added a commit to wengzhe/nuttx that referenced this pull request Apr 12, 2024
Optimize TCP/UDP port selection, and fix possibly dead loop.

Finish discussion in apache#12116 (comment)

Note:
Linux also uses EADDRINUSE for failing in finding a portno, according to https://man7.org/linux/man-pages/man2/bind.2.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
anchao pushed a commit that referenced this pull request Apr 12, 2024
Optimize TCP/UDP port selection, and fix possibly dead loop.

Finish discussion in #12116 (comment)

Note:
Linux also uses EADDRINUSE for failing in finding a portno, according to https://man7.org/linux/man-pages/man2/bind.2.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
jerpelea pushed a commit that referenced this pull request Apr 12, 2024
Finish #12116 (comment)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants