diff --git a/pkg/definitions/service.go b/pkg/definitions/service.go index a40ea02..bf8f1d5 100644 --- a/pkg/definitions/service.go +++ b/pkg/definitions/service.go @@ -17,21 +17,21 @@ type Service struct { } func (s Service) GetSPort() string { - if *s.SPortStart == 0 { + if s.SPortStart == nil || *s.SPortStart == 0 { return "" - } else if *s.SPortEnd == 0 { - return fmt.Sprintf("sport %d", *s.SPortStart) + } else if s.SPortEnd == nil || *s.SPortEnd == 0 { + return fmt.Sprintf("%d", *s.SPortStart) } - return fmt.Sprintf("sport %d - %d", *s.SPortStart, *s.SPortEnd) + return fmt.Sprintf("%d - %d", *s.SPortStart, *s.SPortEnd) } func (s Service) GetDPort() string { - if *s.DPortStart == 0 { + if s.DPortStart == nil || *s.DPortStart == 0 { return "" - } else if *s.DPortEnd == 0 { - return fmt.Sprintf("dport %d", *s.DPortStart) + } else if s.DPortEnd == nil || *s.DPortEnd == 0 { + return fmt.Sprintf("%d", *s.DPortStart) } - return fmt.Sprintf("dport %d - %d", *s.DPortStart, *s.DPortEnd) + return fmt.Sprintf("%d - %d", *s.DPortStart, *s.DPortEnd) } type ServiceType int diff --git a/pkg/nftables/match.go b/pkg/nftables/match.go index ea1a12f..15f50fc 100644 --- a/pkg/nftables/match.go +++ b/pkg/nftables/match.go @@ -7,12 +7,12 @@ import ( "github.con/speatzle/nfsense/pkg/util" ) -func GenerateMatcher(services *map[string]definitions.Service, addresses *map[string]definitions.Address, match definitions.Match) (string, error) { +func GenerateMatcher(services map[string]definitions.Service, addresses map[string]definitions.Address, match definitions.Match) (string, error) { return GenerateServiceMatcher(services, match), nil } -func GenerateServiceMatcher(allServices *map[string]definitions.Service, match definitions.Match) string { - serviceList := util.ResolveBaseServices(*allServices, match.Services) +func GenerateServiceMatcher(allServices map[string]definitions.Service, match definitions.Match) string { + serviceList := util.ResolveBaseServices(allServices, match.Services) tcpSPorts := []string{} tcpDPorts := []string{} @@ -23,17 +23,17 @@ func GenerateServiceMatcher(allServices *map[string]definitions.Service, match d for _, service := range serviceList { switch service.Type { case definitions.TCP: - if service.GetSPort() != "0" { + if service.GetSPort() != "" { tcpSPorts = append(tcpSPorts, service.GetSPort()) } - if service.GetDPort() != "0" { + if service.GetDPort() != "" { tcpDPorts = append(tcpDPorts, service.GetDPort()) } case definitions.UDP: - if service.GetSPort() != "0" { + if service.GetSPort() != "" { udpSPorts = append(udpSPorts, service.GetSPort()) } - if service.GetDPort() != "0" { + if service.GetDPort() != "" { udpDPorts = append(udpDPorts, service.GetDPort()) } case definitions.ICMP: