2024-04-08 18:56:52 +02:00
|
|
|
package net
|
|
|
|
|
2024-04-12 16:53:11 +02:00
|
|
|
import (
|
2024-06-17 09:47:17 +02:00
|
|
|
"net"
|
2024-04-12 16:53:11 +02:00
|
|
|
"os"
|
|
|
|
|
2024-10-02 18:24:22 +02:00
|
|
|
"github.com/netbirdio/netbird/client/iface/netstack"
|
2024-06-17 09:47:17 +02:00
|
|
|
|
2024-04-12 16:53:11 +02:00
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
2024-04-08 18:56:52 +02:00
|
|
|
|
|
|
|
const (
|
|
|
|
// NetbirdFwmark is the fwmark value used by Netbird via wireguard
|
|
|
|
NetbirdFwmark = 0x1BD00
|
2024-04-12 16:53:11 +02:00
|
|
|
|
|
|
|
envDisableCustomRouting = "NB_DISABLE_CUSTOM_ROUTING"
|
2024-04-08 18:56:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ConnectionID provides a globally unique identifier for network connections.
|
|
|
|
// It's used to track connections throughout their lifecycle so the close hook can correlate with the dial hook.
|
|
|
|
type ConnectionID string
|
|
|
|
|
2024-06-17 09:47:17 +02:00
|
|
|
type AddHookFunc func(connID ConnectionID, IP net.IP) error
|
|
|
|
type RemoveHookFunc func(connID ConnectionID) error
|
|
|
|
|
2024-04-08 18:56:52 +02:00
|
|
|
// GenerateConnID generates a unique identifier for each connection.
|
|
|
|
func GenerateConnID() ConnectionID {
|
|
|
|
return ConnectionID(uuid.NewString())
|
|
|
|
}
|
2024-04-12 16:53:11 +02:00
|
|
|
|
|
|
|
func CustomRoutingDisabled() bool {
|
2024-06-07 15:07:23 +02:00
|
|
|
if netstack.IsEnabled() {
|
|
|
|
return true
|
|
|
|
}
|
2024-04-12 16:53:11 +02:00
|
|
|
return os.Getenv(envDisableCustomRouting) == "true"
|
|
|
|
}
|