probe/internal/matcher/matcher.go
crusader 59add71a72 ing
2018-10-23 14:16:41 +09:00

98 lines
2.4 KiB
Go

package matcher
import (
osm "git.loafle.net/overflow/service_matcher-go"
"git.loafle.net/overflow/service_matcher-go/echo"
"git.loafle.net/overflow/service_matcher-go/elasticsearch"
"git.loafle.net/overflow/service_matcher-go/ftp"
"git.loafle.net/overflow/service_matcher-go/http"
"git.loafle.net/overflow/service_matcher-go/ldap"
"git.loafle.net/overflow/service_matcher-go/lpd"
"git.loafle.net/overflow/service_matcher-go/mongodb"
"git.loafle.net/overflow/service_matcher-go/mysql"
"git.loafle.net/overflow/service_matcher-go/nbss"
"git.loafle.net/overflow/service_matcher-go/postgresql"
"git.loafle.net/overflow/service_matcher-go/redis"
"git.loafle.net/overflow/service_matcher-go/ssh"
"git.loafle.net/overflow/service_matcher-go/telnet"
)
var (
AllMatchers []osm.Matcher
TCPMatchers []osm.Matcher
UDPMatchers []osm.UDPMatcher
TCPPrePacketMatchers []osm.Matcher
TCPNotPrePacketMatchers []osm.Matcher
HTTPSubMatchers []osm.Matcher
)
func init() {
//TCP
addTCPMatcher(ssh.NewMatcher())
addTCPMatcher(echo.NewMatcher())
addTCPMatcher(mongodb.NewMatcher())
addTCPMatcher(mysql.NewMatcher())
addTCPMatcher(redis.NewMatcher())
addTCPMatcher(postgresql.NewMatcher())
addTCPMatcher(ftp.NewMatcher())
addTCPMatcher(http.NewMatcher())
addTCPMatcher(lpd.NewMatcher())
addTCPMatcher(telnet.NewMatcher())
addTCPMatcher(nbss.NewMatcher())
addTCPMatcher(ldap.NewMatcher())
addTCPMatcher(mysql.NewMatcher())
// UDP
// addUDPMatcher(dns.NewMatcher())
// HTTP-relative
addHTTPSubMatcher(elasticsearch.NewMatcher())
}
func addTCPMatcher(m osm.Matcher) {
AllMatchers = append(AllMatchers, m)
TCPMatchers = append(TCPMatchers, m)
if m.IsPrePacket() {
TCPPrePacketMatchers = append(TCPPrePacketMatchers, m)
} else {
TCPNotPrePacketMatchers = append(TCPNotPrePacketMatchers, m)
}
}
func addUDPMatcher(m osm.UDPMatcher) {
AllMatchers = append(AllMatchers, m)
UDPMatchers = append(UDPMatchers, m)
}
func addHTTPSubMatcher(m osm.Matcher) {
HTTPSubMatchers = append(HTTPSubMatchers, m)
}
func GetTCPMatchers(isPrePacket bool) []osm.Matcher {
if isPrePacket {
return TCPPrePacketMatchers
}
return TCPNotPrePacketMatchers
}
func GetUDPMatchers() []osm.UDPMatcher {
return UDPMatchers
}
func GetHTTPSubMatchers() []osm.Matcher {
return HTTPSubMatchers
}
func GetMatcherByKey(matchCtx *osm.MatchCtx, key string) osm.Matcher {
for _, m := range AllMatchers {
if m.Key(matchCtx) == key {
return m
}
}
return nil
}