Skip to content

Commit

Permalink
fw minor changes
Browse files Browse the repository at this point in the history
use struct{} instead of bool for exit channels, func parms cosmetic
change.
  • Loading branch information
gustavo-iniguez-goya committed May 12, 2024
1 parent 8935bfe commit c9ad900
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions daemon/firewall/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type (
Common struct {
RulesChecker *time.Ticker
ErrChan chan string
stopChecker chan bool
stopChecker chan struct{}
RulesCheckInterval time.Duration
QueueNum uint16
Running bool
Expand Down Expand Up @@ -132,12 +132,12 @@ func (c *Common) NewRulesChecker(areRulesLoaded callbackBool, reloadRules callba
if c.RulesChecker != nil {
c.RulesChecker.Stop()
select {
case c.stopChecker <- true:
case c.stopChecker <- struct{}{}:
case <-time.After(5 * time.Millisecond):
log.Error("NewRulesChecker: timed out stopping monitor rules")
}
}
c.stopChecker = make(chan bool, 1)
c.stopChecker = make(chan struct{}, 1)
log.Info("Starting new fw checker every %s ...", c.RulesCheckInterval)
c.RulesChecker = time.NewTicker(c.RulesCheckInterval)

Expand All @@ -146,7 +146,7 @@ func (c *Common) NewRulesChecker(areRulesLoaded callbackBool, reloadRules callba

// StartCheckingRules monitors if our rules are loaded.
// If the rules to intercept traffic are not loaded, we'll try to insert them again.
func startCheckingRules(exitChan <-chan bool, rulesChecker *time.Ticker, areRulesLoaded callbackBool, reloadRules callback) {
func startCheckingRules(exitChan <-chan struct{}, rulesChecker *time.Ticker, areRulesLoaded callbackBool, reloadRules callback) {
for {
select {
case <-exitChan:
Expand All @@ -173,7 +173,7 @@ func (c *Common) StopCheckingRules() {

if c.RulesChecker != nil {
select {
case c.stopChecker <- true:
case c.stopChecker <- struct{}{}:
close(c.stopChecker)
case <-time.After(5 * time.Millisecond):
// We should not arrive here
Expand Down
6 changes: 3 additions & 3 deletions daemon/firewall/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type SystemConfig struct {
// This is the configuration to manage the system firewall (iptables, nftables).
type Config struct {
watcher *fsnotify.Watcher
monitorExitChan chan bool
monitorExitChan chan struct{}
// preloadCallback is called before reloading the configuration,
// in order to delete old fw rules.
preloadCallback func()
Expand All @@ -139,7 +139,7 @@ func (c *Config) NewSystemFwConfig(configPath string, preLoadCb, reLoadCb func()
defer c.Unlock()

c.file = configPath
c.monitorExitChan = make(chan bool, 1)
c.monitorExitChan = make(chan struct{}, 1)
c.preloadCallback = preLoadCb
c.reloadCallback = reLoadCb
c.watcher = watcher
Expand Down Expand Up @@ -232,7 +232,7 @@ func (c *Config) StopConfigWatcher() {
defer c.Unlock()

if c.monitorExitChan != nil {
c.monitorExitChan <- true
c.monitorExitChan <- struct{}{}
close(c.monitorExitChan)
}

Expand Down
4 changes: 2 additions & 2 deletions daemon/firewall/nftables/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// of resolved domains.
// This rule must be added in top of the system rules, otherwise it may get bypassed.
// nft insert rule ip filter input udp sport 53 queue num 0 bypass
func (n *Nft) QueueDNSResponses(enable bool, logError bool) (error, error) {
func (n *Nft) QueueDNSResponses(enable, logError bool) (error, error) {
if n.Conn == nil {
return nil, nil
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func (n *Nft) QueueDNSResponses(enable bool, logError bool) (error, error) {
// This rule must be added at the end of all the other rules, that way we can add
// rules above this one to exclude a service/app from being intercepted.
// nft insert rule ip mangle OUTPUT ct state new queue num 0 bypass
func (n *Nft) QueueConnections(enable bool, logError bool) (error, error) {
func (n *Nft) QueueConnections(enable, logError bool) (error, error) {
if n.Conn == nil {
return nil, fmt.Errorf("nftables QueueConnections: netlink connection not active")
}
Expand Down

0 comments on commit c9ad900

Please sign in to comment.