mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-12 22:02:43 +01:00
All routes are now installed in a custom netbird routing table. Management and wireguard traffic is now marked with a custom fwmark. When the mark is present the traffic is routed via the main routing table, bypassing the VPN. When the mark is absent the traffic is routed via the netbird routing table, if: - there's no match in the main routing table - it would match the default route in the routing table IPv6 traffic is blocked when a default route IPv4 route is configured to avoid leakage.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
//go:build !android
|
|
|
|
package net
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"syscall"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func NewDialer() *net.Dialer {
|
|
return &net.Dialer{
|
|
Control: func(network, address string, c syscall.RawConn) error {
|
|
return SetRawSocketMark(c)
|
|
},
|
|
}
|
|
}
|
|
|
|
func DialUDP(network string, laddr, raddr *net.UDPAddr) (*net.UDPConn, error) {
|
|
dialer := NewDialer()
|
|
dialer.LocalAddr = laddr
|
|
|
|
conn, err := dialer.DialContext(context.Background(), network, raddr.String())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("dialing UDP %s: %w", raddr.String(), err)
|
|
}
|
|
|
|
udpConn, ok := conn.(*net.UDPConn)
|
|
if !ok {
|
|
if err := conn.Close(); err != nil {
|
|
log.Errorf("Failed to close connection: %v", err)
|
|
}
|
|
return nil, fmt.Errorf("expected UDP connection, got different type")
|
|
}
|
|
|
|
return udpConn, nil
|
|
}
|
|
|
|
func DialTCP(network string, laddr, raddr *net.TCPAddr) (*net.TCPConn, error) {
|
|
dialer := NewDialer()
|
|
dialer.LocalAddr = laddr
|
|
|
|
conn, err := dialer.DialContext(context.Background(), network, raddr.String())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("dialing TCP %s: %w", raddr.String(), err)
|
|
}
|
|
|
|
tcpConn, ok := conn.(*net.TCPConn)
|
|
if !ok {
|
|
if err := conn.Close(); err != nil {
|
|
log.Errorf("Failed to close connection: %v", err)
|
|
}
|
|
return nil, fmt.Errorf("expected TCP connection, got different type")
|
|
}
|
|
|
|
return tcpConn, nil
|
|
}
|