Documentation
¶
Overview ¶
Package godpi provides the main API interface for utilizing the go-dpi library.
Package godpi provides the main API interface for utilizing the go-dpi library.
Index ¶
- func ClassifyFlow(flow *types.Flow) (result types.ClassificationResult)
- func ClassifyFlowAllModules(flow *types.Flow) (results []types.ClassificationResult)
- func Destroy() (errs []error)
- func GetPacketFlow(packet gopacket.Packet) (*types.Flow, bool)
- func Initialize(opts ...Options) (errs []error)
- func SetCacheExpiration(expiration time.Duration)
- func SetModules(modules []types.Module)
- type ClassifierOption
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClassifyFlow ¶
func ClassifyFlow(flow *types.Flow) (result types.ClassificationResult)
ClassifyFlow takes a Flow and tries to classify it with all of the activated modules sequentially in priority order, until one of them successfully classifies it. It returns the detected protocol as well as the source that made the classification. If no classification is made, the protocol Unknown is returned.
Module Priority Order (first match wins):
- go-dpi classifiers (fast heuristic-based detection)
- libprotoident/LPI (lightweight payload inspection)
- nDPI (deep packet inspection)
This priority order is maintained regardless of which modules are enabled. Each module internally runs its classifiers deterministically to ensure reproducible results across multiple runs.
Caching: Once a flow is successfully classified, the result is cached in the flow object. Subsequent calls to ClassifyFlow on the same flow will return the cached result immediately without re-running any classification modules. This ensures optimal performance when processing multiple packets from the same flow.
func ClassifyFlowAllModules ¶
func ClassifyFlowAllModules(flow *types.Flow) (results []types.ClassificationResult)
ClassifyFlowAllModules takes a Flow and tries to classify it with all of the activated modules sequentially in priority order. Unlike ClassifyFlow, this function runs all modules and returns all their classification results.
The modules are executed in the same priority order as ClassifyFlow:
- go-dpi classifiers
- libprotoident/LPI
- nDPI
Results are deduplicated by protocol - if multiple modules detect the same protocol, only the first detection (from the higher priority module) is included in the results.
This function is useful for debugging, analysis, or when you want to see what multiple detection engines report for the same flow.
func Destroy ¶
func Destroy() (errs []error)
Destroy frees all allocated resources and deactivates the active modules.
func GetPacketFlow ¶
GetPacketFlow returns a Flow for the given packet. If another packet has been processed before that was part of the same communication flow, the same Flow will be returned, with the new packet added. Otherwise, a new Flow will be created with only this packet. The function also returns whether the returned Flow is a new one, and not one that already existed.
func Initialize ¶
Initialize initializes the library and the selected modules.
func SetCacheExpiration ¶
SetCacheExpiration sets how long after being inactive flows should be discarded from the flow tracker. If a negative value is passed, flows will never expire. By default, this value is 5 minutes. After calling this method, Initialize should be called, in order to initialize the cache. If Initialize has already been called before, Destroy should be called as well before Initialize.
func SetModules ¶
SetModules selects the modules to be used by the library and their priority order. Modules are tried sequentially in the order provided, with the first successful classification being returned.
Recommended order for optimal performance:
- go-dpi classifiers (fast heuristic-based)
- libprotoident/LPI (lightweight)
- nDPI (comprehensive but slower)
After calling this method, Initialize should be called, in order to initialize any new modules. If Initialize has already been called before, Destroy should be called as well before Initialize.
Types ¶
type ClassifierOption ¶
type ClassifierOption struct {
}
ClassifierOption take classifier options to override default values for now this option was added for test
func (ClassifierOption) Apply ¶
func (o ClassifierOption) Apply(mod types.Module)
Directories
¶
| Path | Synopsis |
|---|---|
|
supported_protocols
command
|
|
|
modules
|
|
|
classifiers
Package classifiers contains the custom classifiers for each protocol and the helpers for applying them on a flow.
|
Package classifiers contains the custom classifiers for each protocol and the helpers for applying them on a flow. |
|
wrappers
Package wrappers contains wrappers for external libraries such as nDPI in order to use them for flow classification.
|
Package wrappers contains wrappers for external libraries such as nDPI in order to use them for flow classification. |
|
Package types contains the basic types used by the library.
|
Package types contains the basic types used by the library. |
|
Package utils provides some useful utility functions to the library.
|
Package utils provides some useful utility functions to the library. |