fix matcher generation

This commit is contained in:
Samuel Lorch 2023-03-02 00:40:36 +01:00
parent 06a0d20404
commit 4479627a00
2 changed files with 15 additions and 15 deletions

View file

@ -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

View file

@ -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: