func (a *agent) setWorthCheckingIPTablesRoutine(auditClient *libaudit.AuditClient, iptablesIdle time.Duration) {
	var latestTrue time.Time
	go func() {
		for {
			time.Sleep(iptablesIdle)
			a.worthCheckingIPTablesMu.Lock()
			elapsedSinceLastTrue := time.Since(latestTrue)
			if elapsedSinceLastTrue >= iptablesIdle {
				logrus.Debug("setWorthCheckingIPTablesRoutine(): setting to false")
				a.worthCheckingIPTables = false
			}
			a.worthCheckingIPTablesMu.Unlock()
		}
	}()
	for {
		msg, err := auditClient.Receive(false)
		if err != nil {
			logrus.Error(err)
			continue
		}
		switch msg.Type {
		case auparse.AUDIT_NETFILTER_CFG:
			a.worthCheckingIPTablesMu.Lock()
			logrus.Debug("setWorthCheckingIPTablesRoutine(): setting to true")
			a.worthCheckingIPTables = true
			latestTrue = time.Now()
			a.worthCheckingIPTablesMu.Unlock()
		}
	}
}
setWorthCheckingIPTablesRoutine sets worthCheckingIPTables to be true
when received NETFILTER_CFG audit message.

setWorthCheckingIPTablesRoutine sets worthCheckingIPTables to be false
when no NETFILTER_CFG audit message was received for the iptablesIdle time.
package guestagent
import (
	"context"
	"encoding/binary"
	"errors"
	"reflect"
	"sync"
	"time"
	"github.com/elastic/go-libaudit/v2"
	"github.com/elastic/go-libaudit/v2/auparse"
	"github.com/lima-vm/lima/pkg/guestagent/api"
	"github.com/lima-vm/lima/pkg/guestagent/iptables"
	"github.com/lima-vm/lima/pkg/guestagent/procnettcp"
	"github.com/sirupsen/logrus"
	"github.com/yalue/native_endian"
)
func New(newTicker func() (<-chan time.Time, func()), iptablesIdle time.Duration) (Agent, error) {
	a := &agent{
		newTicker: newTicker,
	}
	auditClient, err := libaudit.NewMulticastAuditClient(nil)
	if err != nil {
		return nil, err
	}
	auditStatus, err := auditClient.GetStatus()
	if err != nil {
		return nil, err
	}
	if auditStatus.Enabled == 0 {
		if err = auditClient.SetEnabled(true, libaudit.WaitForReply); err != nil {
			return nil, err
		}
	}
	go a.setWorthCheckingIPTablesRoutine(auditClient, iptablesIdle)
	return a, nil
}
type agent struct {
	newTicker func() (<-chan time.Time, func())
	worthCheckingIPTables   bool
	worthCheckingIPTablesMu sync.RWMutex
	latestIPTables          []iptables.Entry
	latestIPTablesMu        sync.RWMutex
}