diff --git a/service/service.go b/service/service.go index aa59e30..32108e5 100644 --- a/service/service.go +++ b/service/service.go @@ -29,6 +29,8 @@ import ( ) var ( + AllMatchers []matcher.Matcher + TCPMatchers []matcher.Matcher UDPMatchers []matcher.UDPMatcher @@ -38,64 +40,62 @@ var ( func init() { //TCP - TCPMatchers = append(TCPMatchers, smtp.NewMatcher()) - TCPMatchers = append(TCPMatchers, ldap.NewMatcher()) - TCPMatchers = append(TCPMatchers, activedirectory.NewMatcher()) - TCPMatchers = append(TCPMatchers, mongodb.NewMatcher()) - TCPMatchers = append(TCPMatchers, mysql.NewMatcher()) - TCPMatchers = append(TCPMatchers, mssql.NewMatcher()) - TCPMatchers = append(TCPMatchers, redis.NewMatcher()) - TCPMatchers = append(TCPMatchers, redis_protected.NewMatcher()) - TCPMatchers = append(TCPMatchers, netbios.NewMatcher()) - TCPMatchers = append(TCPMatchers, smb.NewMatcher()) - TCPMatchers = append(TCPMatchers, cassandra.NewMatcher()) - TCPMatchers = append(TCPMatchers, imap.NewMatcher()) - TCPMatchers = append(TCPMatchers, oracle.NewMatcher()) - TCPMatchers = append(TCPMatchers, pop.NewMatcher()) - TCPMatchers = append(TCPMatchers, wmi.NewMatcher()) - TCPMatchers = append(TCPMatchers, ftp.NewMatcher()) - TCPMatchers = append(TCPMatchers, http.NewMatcher()) - TCPMatchers = append(TCPMatchers, rmi.NewMatcher()) - TCPMatchers = append(TCPMatchers, ssh.NewMatcher()) - TCPMatchers = append(TCPMatchers, telnet.NewMatcher()) + registerTCPMatcher(smtp.NewMatcher()) + registerTCPMatcher(ldap.NewMatcher()) + registerTCPMatcher(activedirectory.NewMatcher()) + registerTCPMatcher(mongodb.NewMatcher()) + registerTCPMatcher(mysql.NewMatcher()) + registerTCPMatcher(mssql.NewMatcher()) + registerTCPMatcher(redis.NewMatcher()) + registerTCPMatcher(redis_protected.NewMatcher()) + registerTCPMatcher(netbios.NewMatcher()) + registerTCPMatcher(smb.NewMatcher()) + registerTCPMatcher(cassandra.NewMatcher()) + registerTCPMatcher(imap.NewMatcher()) + registerTCPMatcher(oracle.NewMatcher()) + registerTCPMatcher(pop.NewMatcher()) + registerTCPMatcher(wmi.NewMatcher()) + registerTCPMatcher(ftp.NewMatcher()) + registerTCPMatcher(http.NewMatcher()) + registerTCPMatcher(rmi.NewMatcher()) + registerTCPMatcher(ssh.NewMatcher()) + registerTCPMatcher(telnet.NewMatcher()) - UDPMatchers = append(UDPMatchers, dns.NewMatcher()) - UDPMatchers = append(UDPMatchers, snmp_v2.NewMatcher()) - UDPMatchers = append(UDPMatchers, snmp_v3.NewMatcher()) + // UDP + registerUDPMatcher(dns.NewMatcher()) + registerUDPMatcher(snmp_v2.NewMatcher()) + registerUDPMatcher(snmp_v3.NewMatcher()) +} + +func registerTCPMatcher(m matcher.Matcher) { + AllMatchers = append(AllMatchers, m) + TCPMatchers = append(TCPMatchers, m) + if m.IsPrePacket() { + TCPPrePacketMatchers = append(TCPPrePacketMatchers, m) + } else { + TCPNotPrePacketMatchers = append(TCPNotPrePacketMatchers, m) + } +} + +func registerUDPMatcher(m matcher.UDPMatcher) { + AllMatchers = append(AllMatchers, m) + UDPMatchers = append(UDPMatchers, m) } func GetTCPMatchers(ispre bool) []matcher.Matcher { - - retMatchers := make([]matcher.Matcher, 0) - l := len(TCPMatchers) - for i := 0; i < l; i++ { - c := TCPMatchers[i].IsPrePacket() - if c == ispre { - retMatchers = append(retMatchers, TCPMatchers[i]) - } + if ispre { + return TCPPrePacketMatchers } - return retMatchers + return TCPNotPrePacketMatchers } func GetUDPMatchers() []matcher.UDPMatcher { - - retMatchers := make([]matcher.UDPMatcher, 0) - l := len(UDPMatchers) - for i := 0; i < l; i++ { - retMatchers = append(retMatchers, UDPMatchers[i]) - } - - return retMatchers + return UDPMatchers } func GetMatcherByName(serName string) Matcher { - for _, m := range TCPMatchers { - if m.ServiceName() == serName { - return m - } - } - for _, m := range UDPMatchers { + for _, m := range AllMatchers { if m.ServiceName() == serName { return m }