2023-12-08 10:48:21 +01:00
|
|
|
//go:build !linux || android
|
|
|
|
|
|
|
|
package firewall
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
firewall "github.com/netbirdio/netbird/client/firewall/manager"
|
|
|
|
"github.com/netbirdio/netbird/client/firewall/uspfilter"
|
2024-10-24 14:46:24 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/statemanager"
|
2023-12-08 10:48:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewFirewall creates a firewall manager instance
|
2024-10-24 14:46:24 +02:00
|
|
|
func NewFirewall(iface IFaceMapper, _ *statemanager.Manager) (firewall.Manager, error) {
|
2023-12-08 10:48:21 +01:00
|
|
|
if !iface.IsUserspaceBind() {
|
|
|
|
return nil, fmt.Errorf("not implemented for this OS: %s", runtime.GOOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
// use userspace packet filtering firewall
|
|
|
|
fm, err := uspfilter.Create(iface)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = fm.AllowNetbird()
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("failed to allow netbird interface traffic: %v", err)
|
|
|
|
}
|
|
|
|
return fm, nil
|
|
|
|
}
|