Skip to content

Commit

Permalink
[client] Remove legacy forwarding rules in userspace mode (#2782)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal authored Oct 28, 2024
1 parent 46e37fa commit 940f8b4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
2 changes: 2 additions & 0 deletions client/firewall/iptables/router_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ func (r *router) RemoveAllLegacyRouteRules() error {
}
if err := r.iptablesClient.DeleteIfExists(tableFilter, chainRTFWD, rule...); err != nil {
merr = multierror.Append(merr, fmt.Errorf("remove legacy forwarding rule: %v", err))
} else {
delete(r.rules, k)
}
}

Expand Down
18 changes: 1 addition & 17 deletions client/firewall/nftables/manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,7 @@ func (m *Manager) AllowNetbird() error {

// SetLegacyManagement sets the route manager to use legacy management
func (m *Manager) SetLegacyManagement(isLegacy bool) error {
oldLegacy := m.router.legacyManagement

if oldLegacy != isLegacy {
m.router.legacyManagement = isLegacy
log.Debugf("Set legacy management to %v", isLegacy)
}

// client reconnected to a newer mgmt, we need to cleanup the legacy rules
if !isLegacy && oldLegacy {
if err := m.router.RemoveAllLegacyRouteRules(); err != nil {
return fmt.Errorf("remove legacy routing rules: %v", err)
}

log.Debugf("Legacy routing rules removed")
}

return nil
return firewall.SetLegacyManagement(m.router, isLegacy)
}

// Reset firewall to the default state
Expand Down
3 changes: 3 additions & 0 deletions client/firewall/nftables/router_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,10 @@ func (r *router) RemoveAllLegacyRouteRules() error {
}
if err := r.conn.DelRule(rule); err != nil {
merr = multierror.Append(merr, fmt.Errorf("remove legacy forwarding rule: %v", err))
} else {
delete(r.rules, k)
}

}
return nberrors.FormatErrorOrNil(merr)
}
Expand Down
7 changes: 5 additions & 2 deletions client/firewall/uspfilter/uspfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,11 @@ func (m *Manager) DeletePeerRule(rule firewall.Rule) error {
}

// SetLegacyManagement doesn't need to be implemented for this manager
func (m *Manager) SetLegacyManagement(_ bool) error {
return nil
func (m *Manager) SetLegacyManagement(isLegacy bool) error {
if m.nativeFirewall == nil {
return errRouteNotSupported
}
return m.nativeFirewall.SetLegacyManagement(isLegacy)
}

// Flush doesn't need to be implemented for this manager
Expand Down

0 comments on commit 940f8b4

Please sign in to comment.