mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-01 23:55:44 +02:00
[client] Ignore route rules with no sources instead of erroring out (#2786)
This commit is contained in:
parent
b9f205b2ce
commit
46e37fa04c
@ -3,6 +3,7 @@ package acl
|
|||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@ -10,14 +11,18 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
nberrors "github.com/netbirdio/netbird/client/errors"
|
||||||
firewall "github.com/netbirdio/netbird/client/firewall/manager"
|
firewall "github.com/netbirdio/netbird/client/firewall/manager"
|
||||||
"github.com/netbirdio/netbird/client/internal/acl/id"
|
"github.com/netbirdio/netbird/client/internal/acl/id"
|
||||||
"github.com/netbirdio/netbird/client/ssh"
|
"github.com/netbirdio/netbird/client/ssh"
|
||||||
mgmProto "github.com/netbirdio/netbird/management/proto"
|
mgmProto "github.com/netbirdio/netbird/management/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrSourceRangesEmpty = errors.New("sources range is empty")
|
||||||
|
|
||||||
// Manager is a ACL rules manager
|
// Manager is a ACL rules manager
|
||||||
type Manager interface {
|
type Manager interface {
|
||||||
ApplyFiltering(networkMap *mgmProto.NetworkMap)
|
ApplyFiltering(networkMap *mgmProto.NetworkMap)
|
||||||
@ -167,31 +172,40 @@ func (d *DefaultManager) applyPeerACLs(networkMap *mgmProto.NetworkMap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DefaultManager) applyRouteACLs(rules []*mgmProto.RouteFirewallRule) error {
|
func (d *DefaultManager) applyRouteACLs(rules []*mgmProto.RouteFirewallRule) error {
|
||||||
var newRouteRules = make(map[id.RuleID]struct{})
|
newRouteRules := make(map[id.RuleID]struct{}, len(rules))
|
||||||
|
var merr *multierror.Error
|
||||||
|
|
||||||
|
// Apply new rules - firewall manager will return existing rule ID if already present
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
id, err := d.applyRouteACL(rule)
|
id, err := d.applyRouteACL(rule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("apply route ACL: %w", err)
|
if errors.Is(err, ErrSourceRangesEmpty) {
|
||||||
|
log.Debugf("skipping empty rule with destination %s: %v", rule.Destination, err)
|
||||||
|
} else {
|
||||||
|
merr = multierror.Append(merr, fmt.Errorf("add route rule: %w", err))
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
newRouteRules[id] = struct{}{}
|
newRouteRules[id] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up old firewall rules
|
||||||
for id := range d.routeRules {
|
for id := range d.routeRules {
|
||||||
if _, ok := newRouteRules[id]; !ok {
|
if _, exists := newRouteRules[id]; !exists {
|
||||||
if err := d.firewall.DeleteRouteRule(id); err != nil {
|
if err := d.firewall.DeleteRouteRule(id); err != nil {
|
||||||
log.Errorf("failed to delete route firewall rule: %v", err)
|
merr = multierror.Append(merr, fmt.Errorf("delete route rule: %w", err))
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
delete(d.routeRules, id)
|
// implicitly deleted from the map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.routeRules = newRouteRules
|
d.routeRules = newRouteRules
|
||||||
return nil
|
return nberrors.FormatErrorOrNil(merr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DefaultManager) applyRouteACL(rule *mgmProto.RouteFirewallRule) (id.RuleID, error) {
|
func (d *DefaultManager) applyRouteACL(rule *mgmProto.RouteFirewallRule) (id.RuleID, error) {
|
||||||
if len(rule.SourceRanges) == 0 {
|
if len(rule.SourceRanges) == 0 {
|
||||||
return "", fmt.Errorf("source ranges is empty")
|
return "", ErrSourceRangesEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
var sources []netip.Prefix
|
var sources []netip.Prefix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user