-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[client] Add dual-stack nftables manager with IPv6 table support #5707
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e4857b4
Add dual-stack nftables manager with IPv6 table support
lixmal c13f1af
Fix ip6tables-save compat: skip ip6tables-managed tables in external …
lixmal 571527c
Add iptablesProto helper, filter table fallback, DNAT compat tests
lixmal 44d16e8
Merge branch 'client-ipv6-routing' into client-ipv6-nftables
lixmal 443d072
Fix CodeRabbit findings: rollback on init failure, accumulate Close e…
lixmal 546140a
Extract rollbackInit helper to deduplicate Init cleanup
lixmal 024cc6c
Split Init to reduce cognitive complexity
lixmal ea451df
Merge remote-tracking branch 'origin/client-ipv6-routing' into client…
lixmal 935ca81
Merge remote-tracking branch 'origin/client-ipv6-routing' into client…
lixmal 6793950
Merge branch 'client-ipv6-routing' into client-ipv6-nftables
lixmal dcc9657
Merge remote-tracking branch 'origin/client-ipv6-routing' into client…
lixmal 212ab63
Fix AddOutputDNAT using removed standalone functions after merge from…
lixmal 8b51b79
Merge branch 'client-ipv6-routing' into client-ipv6-nftables
lixmal 62fd61f
Address review feedback for nftables IPv6 firewall
lixmal cd9e90a
[client] Add dual-stack iptables manager with ip6tables support (#5708)
lixmal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package nftables | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
|
|
||
| "github.com/google/nftables" | ||
| "golang.org/x/sys/unix" | ||
|
|
||
| firewall "github.com/netbirdio/netbird/client/firewall/manager" | ||
| ) | ||
|
|
||
| // addrFamily holds protocol-specific constants for nftables expression building. | ||
| type addrFamily struct { | ||
| // protoOffset is the IP header offset for the protocol/next-header field (9 for v4, 6 for v6) | ||
| protoOffset uint32 | ||
| // srcAddrOffset is the IP header offset for the source address (12 for v4, 8 for v6) | ||
| srcAddrOffset uint32 | ||
| // dstAddrOffset is the IP header offset for the destination address (16 for v4, 24 for v6) | ||
| dstAddrOffset uint32 | ||
| // addrLen is the byte length of addresses (4 for v4, 16 for v6) | ||
| addrLen uint32 | ||
| // totalBits is the address size in bits (32 for v4, 128 for v6) | ||
| totalBits int | ||
| // setKeyType is the nftables set data type for addresses | ||
| setKeyType nftables.SetDatatype | ||
| // tableFamily is the nftables table family | ||
| tableFamily nftables.TableFamily | ||
| // icmpProto is the ICMP protocol number for this family (1 for v4, 58 for v6) | ||
| icmpProto uint8 | ||
| } | ||
|
|
||
| var ( | ||
| // afIPv4 defines IPv4 header layout and nftables types. | ||
| afIPv4 = addrFamily{ | ||
| protoOffset: 9, | ||
| srcAddrOffset: 12, | ||
| dstAddrOffset: 16, | ||
| addrLen: net.IPv4len, | ||
| totalBits: 8 * net.IPv4len, | ||
| setKeyType: nftables.TypeIPAddr, | ||
| tableFamily: nftables.TableFamilyIPv4, | ||
| icmpProto: unix.IPPROTO_ICMP, | ||
| } | ||
| // afIPv6 defines IPv6 header layout and nftables types. | ||
| afIPv6 = addrFamily{ | ||
| protoOffset: 6, | ||
| srcAddrOffset: 8, | ||
| dstAddrOffset: 24, | ||
| addrLen: net.IPv6len, | ||
| totalBits: 8 * net.IPv6len, | ||
| setKeyType: nftables.TypeIP6Addr, | ||
| tableFamily: nftables.TableFamilyIPv6, | ||
| icmpProto: unix.IPPROTO_ICMPV6, | ||
| } | ||
| ) | ||
|
|
||
| // familyForAddr returns the address family for the given IP. | ||
| func familyForAddr(is4 bool) addrFamily { | ||
| if is4 { | ||
| return afIPv4 | ||
| } | ||
| return afIPv6 | ||
| } | ||
|
|
||
| // protoNum converts a firewall protocol to the IP protocol number, | ||
| // using the correct ICMP variant for the address family. | ||
| func (af addrFamily) protoNum(protocol firewall.Protocol) (uint8, error) { | ||
| switch protocol { | ||
| case firewall.ProtocolTCP: | ||
| return unix.IPPROTO_TCP, nil | ||
| case firewall.ProtocolUDP: | ||
| return unix.IPPROTO_UDP, nil | ||
| case firewall.ProtocolICMP: | ||
| return af.icmpProto, nil | ||
| case firewall.ProtocolALL: | ||
| return 0, nil | ||
| default: | ||
| return 0, fmt.Errorf("unsupported protocol: %s", protocol) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the Go convection. Vars -> struct -> at the end statuc functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed