forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 9
/
registry.go
93 lines (74 loc) · 2 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package protos
import (
"time"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/packetbeat/publish"
)
type ProtocolPlugin func(
testMode bool,
results publish.Transactions,
cfg *common.Config,
) (Plugin, error)
// Functions to be exported by a protocol plugin
type Plugin interface {
// Called to return the configured ports
GetPorts() []int
}
type TCPPlugin interface {
Plugin
// Called when TCP payload data is available for parsing.
Parse(pkt *Packet, tcptuple *common.TCPTuple,
dir uint8, private ProtocolData) ProtocolData
// Called when the FIN flag is seen in the TCP stream.
ReceivedFin(tcptuple *common.TCPTuple, dir uint8,
private ProtocolData) ProtocolData
// Called when a packets are missing from the tcp
// stream.
GapInStream(tcptuple *common.TCPTuple, dir uint8, nbytes int,
private ProtocolData) (priv ProtocolData, drop bool)
// ConnectionTimeout returns the per stream connection timeout.
// Return <=0 to set default tcp module transaction timeout.
ConnectionTimeout() time.Duration
}
type UDPPlugin interface {
Plugin
// ParseUDP is invoked when UDP payload data is available for parsing.
ParseUDP(pkt *Packet)
}
// Protocol identifier.
type Protocol uint16
// Protocol constants.
const (
UnknownProtocol Protocol = iota
)
// Protocol names
var protocolNames = []string{
"unknown",
}
func (p Protocol) String() string {
if int(p) >= len(protocolNames) {
return "impossible"
}
return protocolNames[p]
}
var (
protocolPlugins = map[Protocol]ProtocolPlugin{}
protocolSyms = map[string]Protocol{}
)
func Lookup(name string) Protocol {
if p, exists := protocolSyms[name]; exists {
return p
}
return UnknownProtocol
}
func Register(name string, plugin ProtocolPlugin) {
proto := Protocol(len(protocolNames))
if p, exists := protocolSyms[name]; exists {
// keep symbol table entries if plugin gets overwritten
proto = p
} else {
protocolNames = append(protocolNames, name)
protocolSyms[name] = proto
}
protocolPlugins[proto] = plugin
}