Skip to content

Commit

Permalink
Allow inbound rosenpass port
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Dec 24, 2024
1 parent ad9f044 commit 2836424
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/firewall/iptables/manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (m *Manager) AllowNetbird() error {
}

_, err := m.AddPeerFiltering(
net.ParseIP("0.0.0.0"),
net.IP{0, 0, 0, 0},
"all",
nil,
nil,
Expand Down
2 changes: 1 addition & 1 deletion client/internal/dnsfwd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (h *Manager) allowDNSFirewall() error {
IsRange: false,
Values: []int{ListenPort},
}
dnsRules, err := h.firewall.AddPeerFiltering(net.ParseIP("0.0.0.0"), firewall.ProtocolUDP, nil, dport, firewall.RuleDirectionIN, firewall.ActionAccept, "", "")
dnsRules, err := h.firewall.AddPeerFiltering(net.IP{0, 0, 0, 0}, firewall.ProtocolUDP, nil, dport, firewall.RuleDirectionIN, firewall.ActionAccept, "", "")
if err != nil {
log.Errorf("failed to add allow DNS router rules, err: %v", err)
return err
Expand Down
42 changes: 35 additions & 7 deletions client/internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,9 @@ func (e *Engine) Start() error {
e.firewall, err = firewall.NewFirewall(e.wgInterface, e.stateManager)
if err != nil {
log.Errorf("failed creating firewall manager: %s", err)
}

if e.firewall != nil && e.firewall.IsServerRouteSupported() {
err = e.routeManager.EnableServerRouter(e.firewall)
if err != nil {
e.close()
return fmt.Errorf("enable server router: %w", err)
} else if e.firewall != nil {
if err := e.initFirewall(err); err != nil {
return err
}
}

Expand Down Expand Up @@ -455,6 +451,38 @@ func (e *Engine) Start() error {
return nil
}

func (e *Engine) initFirewall(err error) error {

Check failure on line 454 in client/internal/engine.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

SA4009: argument err is overwritten before first use (staticcheck)
if e.firewall.IsServerRouteSupported() {
if err = e.routeManager.EnableServerRouter(e.firewall); err != nil {

Check failure on line 456 in client/internal/engine.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

SA4009(related information): assignment to err (staticcheck)
e.close()
return fmt.Errorf("enable server router: %w", err)
}
}

if e.rpManager == nil || !e.config.RosenpassEnabled {
return nil
}

rosenpassPort := e.rpManager.GetAddress().Port
port := manager.Port{Values: []int{rosenpassPort}}
if _, err := e.firewall.AddPeerFiltering(
net.IP{0, 0, 0, 0},
manager.ProtocolUDP,
nil,
&port,
manager.RuleDirectionIN,
manager.ActionAccept,
"",
"",
); err != nil {
log.Errorf("failed to allow rosenpass interface traffic: %v", err)
}

log.Infof("rosenpass interface traffic allowed on port %d", rosenpassPort)

return nil
}

// modifyPeers updates peers that have been modified (e.g. IP address has been changed).
// It closes the existing connection, removes it from the peerConns map, and creates a new one.
func (e *Engine) modifyPeers(peersUpdate []*mgmProto.RemotePeerConfig) error {
Expand Down

0 comments on commit 2836424

Please sign in to comment.