mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-21 12:41:34 +01:00
* compile client under freebsd (#1620) Compile netbird client under freebsd and now support netstack and userspace modes. Refactoring linux specific code to share same code with FreeBSD, move to *_unix.go files. Not implemented yet: Kernel mode not supported DNS probably does not work yet Routing also probably does not work yet SSH support did not tested yet Lack of test environment for freebsd (dedicated VM for github runners under FreeBSD required) Lack of tests for freebsd specific code info reporting need to review and also implement, for example OS reported as GENERIC instead of FreeBSD (lack of FreeBSD icon in management interface) Lack of proper client setup under FreeBSD Lack of FreeBSD port/package * Add DNS routes (#1943) Given domains are resolved periodically and resolved IPs are replaced with the new ones. Unless the flag keep_route is set to true, then only new ones are added. This option is helpful if there are long-running connections that might still point to old IP addresses from changed DNS records. * Add process posture check (#1693) Introduces a process posture check to validate the existence and active status of specific binaries on peer systems. The check ensures that files are present at specified paths, and that corresponding processes are running. This check supports Linux, Windows, and macOS systems. Co-authored-by: Evgenii <mail@skillcoder.com> Co-authored-by: Pascal Fischer <pascal@netbird.io> Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com> Co-authored-by: Viktor Liu <17948409+lixmal@users.noreply.github.com> Co-authored-by: Bethuel Mmbaga <bethuelmbaga12@gmail.com>
160 lines
3.3 KiB
Go
160 lines
3.3 KiB
Go
//go:build (linux && !android) || freebsd
|
|
|
|
package iface
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
|
|
"github.com/pion/transport/v3"
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/netbirdio/netbird/iface/bind"
|
|
"github.com/netbirdio/netbird/sharedsock"
|
|
)
|
|
|
|
type tunKernelDevice struct {
|
|
name string
|
|
address WGAddress
|
|
wgPort int
|
|
key string
|
|
mtu int
|
|
ctx context.Context
|
|
ctxCancel context.CancelFunc
|
|
transportNet transport.Net
|
|
|
|
link *wgLink
|
|
udpMuxConn net.PacketConn
|
|
udpMux *bind.UniversalUDPMuxDefault
|
|
}
|
|
|
|
func newTunDevice(name string, address WGAddress, wgPort int, key string, mtu int, transportNet transport.Net) wgTunDevice {
|
|
checkUser()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
return &tunKernelDevice{
|
|
ctx: ctx,
|
|
ctxCancel: cancel,
|
|
name: name,
|
|
address: address,
|
|
wgPort: wgPort,
|
|
key: key,
|
|
mtu: mtu,
|
|
transportNet: transportNet,
|
|
}
|
|
}
|
|
|
|
func (t *tunKernelDevice) Create() (wgConfigurer, error) {
|
|
link := newWGLink(t.name)
|
|
|
|
if err := link.recreate(); err != nil {
|
|
return nil, fmt.Errorf("recreate: %w", err)
|
|
}
|
|
|
|
t.link = link
|
|
|
|
if err := t.assignAddr(); err != nil {
|
|
return nil, fmt.Errorf("assign addr: %w", err)
|
|
}
|
|
|
|
// TODO: do a MTU discovery
|
|
log.Debugf("setting MTU: %d interface: %s", t.mtu, t.name)
|
|
|
|
if err := link.setMTU(t.mtu); err != nil {
|
|
return nil, fmt.Errorf("set mtu: %w", err)
|
|
}
|
|
|
|
configurer := newWGConfigurer(t.name)
|
|
|
|
if err := configurer.configureInterface(t.key, t.wgPort); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return configurer, nil
|
|
}
|
|
|
|
func (t *tunKernelDevice) Up() (*bind.UniversalUDPMuxDefault, error) {
|
|
if t.udpMux != nil {
|
|
return t.udpMux, nil
|
|
}
|
|
|
|
if t.link == nil {
|
|
return nil, fmt.Errorf("device is not ready yet")
|
|
}
|
|
|
|
log.Debugf("bringing up interface: %s", t.name)
|
|
|
|
if err := t.link.up(); err != nil {
|
|
log.Errorf("error bringing up interface: %s", t.name)
|
|
|
|
return nil, err
|
|
}
|
|
|
|
rawSock, err := sharedsock.Listen(t.wgPort, sharedsock.NewIncomingSTUNFilter())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
bindParams := bind.UniversalUDPMuxParams{
|
|
UDPConn: rawSock,
|
|
Net: t.transportNet,
|
|
}
|
|
mux := bind.NewUniversalUDPMuxDefault(bindParams)
|
|
go mux.ReadFromConn(t.ctx)
|
|
t.udpMuxConn = rawSock
|
|
t.udpMux = mux
|
|
|
|
log.Debugf("device is ready to use: %s", t.name)
|
|
return t.udpMux, nil
|
|
}
|
|
|
|
func (t *tunKernelDevice) UpdateAddr(address WGAddress) error {
|
|
t.address = address
|
|
return t.assignAddr()
|
|
}
|
|
|
|
func (t *tunKernelDevice) Close() error {
|
|
if t.link == nil {
|
|
return nil
|
|
}
|
|
|
|
t.ctxCancel()
|
|
|
|
var closErr error
|
|
if err := t.link.Close(); err != nil {
|
|
log.Debugf("failed to close link: %s", err)
|
|
closErr = err
|
|
}
|
|
|
|
if t.udpMux != nil {
|
|
if err := t.udpMux.Close(); err != nil {
|
|
log.Debugf("failed to close udp mux: %s", err)
|
|
closErr = err
|
|
}
|
|
|
|
if err := t.udpMuxConn.Close(); err != nil {
|
|
log.Debugf("failed to close udp mux connection: %s", err)
|
|
closErr = err
|
|
}
|
|
}
|
|
|
|
return closErr
|
|
}
|
|
|
|
func (t *tunKernelDevice) WgAddress() WGAddress {
|
|
return t.address
|
|
}
|
|
|
|
func (t *tunKernelDevice) DeviceName() string {
|
|
return t.name
|
|
}
|
|
|
|
func (t *tunKernelDevice) Wrapper() *DeviceWrapper {
|
|
return nil
|
|
}
|
|
|
|
// assignAddr Adds IP address to the tunnel interface
|
|
func (t *tunKernelDevice) assignAddr() error {
|
|
return t.link.assignAddr(t.address)
|
|
}
|