Add support of defining multiple ports to the extension API

This commit is contained in:
M. Mert Yildiran
2021-08-17 08:47:59 +03:00
parent 3410a6067c
commit 5c0a7d907a
5 changed files with 17 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ type Extension struct {
Name string
Path string
Plug *plugin.Plugin
Port string
Ports []string
Dissector Dissector
}

View File

@@ -15,11 +15,11 @@ type dissecting string
func (g dissecting) Register(extension *api.Extension) {
fmt.Printf("extension: %v\n", extension)
extension.Port = "5672"
extension.Ports = []string{"5671", "5672"}
}
func (g dissecting) Ping() {
fmt.Printf("pong\n")
fmt.Printf("pong AMQP\n")
}
// exported as symbol named "Greeter"

View File

@@ -15,11 +15,11 @@ type dissecting string
func (g dissecting) Register(extension *api.Extension) {
fmt.Printf("extension: %v\n", extension)
extension.Port = "80"
extension.Ports = []string{"80", "8080", "443"}
}
func (g dissecting) Ping() {
fmt.Printf("pong\n")
fmt.Printf("pong HTTP\n")
}
// exported as symbol named "Greeter"

View File

@@ -15,11 +15,11 @@ type dissecting string
func (g dissecting) Register(extension *api.Extension) {
fmt.Printf("extension: %v\n", extension)
extension.Port = "9092"
extension.Ports = []string{"9092"}
}
func (g dissecting) Ping() {
fmt.Printf("pong\n")
fmt.Printf("pong Kafka\n")
}
// exported as symbol named "Greeter"

View File

@@ -26,10 +26,19 @@ type tcpStreamFactory struct {
const checkTLSPacketAmount = 100
func containsPort(ports []string, port string) bool {
for _, x := range ports {
if x == port {
return true
}
}
return false
}
func (h *tcpStream) run(wg *sync.WaitGroup) {
defer wg.Done()
for _, extension := range extensions {
if extension.Port == h.transport.Dst().String() {
if containsPort(extension.Ports, h.transport.Dst().String()) {
extension.Dissector.Ping()
}
}