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

Feature/exit nodes - Linux support #1667

Merged
merged 45 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d667bcf
Make gRPC dialers use fwmark
lixmal Mar 2, 2024
bec57e5
Improve error handling
lixmal Feb 29, 2024
a806218
Add fwmark to wireguard interface
lixmal Feb 29, 2024
38751f9
Add fwmark to ICE connections
lixmal Feb 29, 2024
c1781c6
Remove prefix length restriction
lixmal Feb 29, 2024
c5d4a24
Make routing operations table-aware and add new operations
lixmal Feb 29, 2024
82433fb
Mark missing sockets without fwmark and streamline existing markings
lixmal Mar 2, 2024
0f71870
Add default route handling
lixmal Mar 2, 2024
d60f1ed
Improve socket error handling
lixmal Mar 2, 2024
20c57b5
Rename and move packages
lixmal Mar 5, 2024
1b727f6
Make socket mark functions linux exclusive
lixmal Mar 5, 2024
f993fa0
Fix dialer
lixmal Mar 5, 2024
c9c8a18
Rename grpc dialer func for consistency
lixmal Mar 5, 2024
dc539f7
Remove forwarding on client
lixmal Mar 5, 2024
ae95173
Disallow routes without destination
lixmal Mar 5, 2024
e389f04
Remove aliasing issue
lixmal Mar 5, 2024
f3be573
Reverse cleanup order
lixmal Mar 5, 2024
f3cd3f8
Use multierr
lixmal Mar 5, 2024
d8abc40
Setup rules for all routes
lixmal Mar 6, 2024
6ab3839
Replace blackhole with unreachable
lixmal Mar 6, 2024
afa3290
Reinstate restriction for other OSs
lixmal Mar 6, 2024
3c68f7e
Merge branch 'main' into feature/exit-nodes
lixmal Mar 12, 2024
2ddf7fa
Merge branch 'main' into feature/exit-nodes
lixmal Mar 12, 2024
43918fa
Add non-linux setup functions
lixmal Mar 12, 2024
685bb32
Add non-linux intf params
lixmal Mar 12, 2024
8454fb4
Fix some tests
lixmal Mar 13, 2024
cafa324
Improve rule description
lixmal Mar 13, 2024
ae23022
Fix builds
lixmal Mar 13, 2024
8428a03
Fix cleanup for unreachable routes
lixmal Mar 13, 2024
41759ff
Add routing integration test
lixmal Mar 13, 2024
8f7af52
Tidy mods
lixmal Mar 13, 2024
8016774
Add pcap library to linter
lixmal Mar 13, 2024
53f262e
Enable CGO for the routing test
lixmal Mar 13, 2024
04844e3
Add remaining pcap deps
lixmal Mar 13, 2024
861007f
apt update
mlsmaycon Mar 14, 2024
8538364
Remove obsolete rule, add more tests and use correct syscall constants
lixmal Mar 16, 2024
d4e248e
Ignore exists errors in test
lixmal Mar 16, 2024
c9ca599
Ignore missing rt_tables
lixmal Mar 16, 2024
8c377fa
Fix tests when the default route exists with metric 0
lixmal Mar 18, 2024
4dc316d
Don't set fwmark on non-Linux
lixmal Mar 19, 2024
3c6ce49
Remove obsolete methods
lixmal Mar 19, 2024
fe8fffd
Merge branch 'main' into feature/exit-nodes
lixmal Mar 19, 2024
397a184
Fix missing fwmark setting
lixmal Mar 19, 2024
0b8cf53
Remove fwmark split on kernel configurer
lixmal Mar 19, 2024
70fda9f
Use masked address for forwarding/nat rules
lixmal Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make socket mark functions linux exclusive
  • Loading branch information
lixmal committed Mar 5, 2024
commit 1b727f6fca6dc601c843f6176751b5381923d075
32 changes: 0 additions & 32 deletions util/net/net.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
package net

import (
"fmt"
"syscall"
)

const (
// NetbirdFwmark is the fwmark value used by Netbird via wireguard
NetbirdFwmark = 0x1BD00
)

// SetSocketMark sets the SO_MARK option on the given socket connection
func SetSocketMark(conn syscall.Conn) error {
sysconn, err := conn.SyscallConn()
if err != nil {
return fmt.Errorf("get raw conn: %w", err)
}

return SetRawSocketMark(sysconn)
}

func SetRawSocketMark(conn syscall.RawConn) error {
var setErr error

err := conn.Control(func(fd uintptr) {
setErr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, NetbirdFwmark)
})
if err != nil {
return fmt.Errorf("control: %w", err)
}

if setErr != nil {
return fmt.Errorf("set SO_MARK: %w", setErr)
}

return nil
}
35 changes: 35 additions & 0 deletions util/net/net_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//go:build !android

package net

import (
"fmt"
"syscall"
)

// SetSocketMark sets the SO_MARK option on the given socket connection
func SetSocketMark(conn syscall.Conn) error {
sysconn, err := conn.SyscallConn()
if err != nil {
return fmt.Errorf("get raw conn: %w", err)
}

return SetRawSocketMark(sysconn)
}

func SetRawSocketMark(conn syscall.RawConn) error {
var setErr error

err := conn.Control(func(fd uintptr) {
setErr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, NetbirdFwmark)
})
if err != nil {
return fmt.Errorf("control: %w", err)
}

if setErr != nil {
return fmt.Errorf("set SO_MARK: %w", setErr)
}

return nil
}
Loading