mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-10-22 15:58:44 +00:00
* Remove `tcpStreamWrapper` struct * Refactor `tap` module and move some of the code to `tap/api` module * Move `TrafficFilteringOptions` struct to `shared` module * Change the `Dissect` method signature to have `*TcpReader` as an argument * Add `CloseOtherProtocolDissectors` method and use it to synchronously close the other protocol dissectors * Run `go mod tidy` in `cli` module * Rename `SuperIdentifier` struct to `ProtoIdentifier` * Remove `SuperTimer` struct * Bring back `CloseTimedoutTcpStreamChannels` method * Run `go mod tidy` everywhere * Remove `GOGC` environment variable from tapper * Fix the tests * Bring back `debug.FreeOSMemory()` call * Make `CloseOtherProtocolDissectors` method mutexed * Revert "Remove `GOGC` environment variable from tapper" This reverts commitcfc2484bbb
. * Bring back the removed `checksum`, `nooptcheck` and `ignorefsmerr` flags * Define a bunch of interfaces and don't export any new structs from `tap/api` * Keep the interfaces in `tap/api` but move the structs to `tap/tcp` * Fix the unit tests by depending on `github.com/up9inc/mizu/tap` * Use the modified `tlsEmitter` * Define `TlsChunk` interface and make `tlsReader` implement `TcpReader` * Remove unused fields in `tlsReader` * Define `ReassemblyStream` interface and separate `gopacket` specififc fields to `tcpReassemblyStream` struct Such that make `tap/api` don't depend on `gopacket` * Remove the unused fields * Make `tlsPoller` implement `TcpStream` interface and remove the call to `NewTcpStreamDummy` method * Remove unused fields from `tlsPoller` * Remove almost all of the setter methods in `TcpReader` and `TcpStream` interface and remove `TlsChunk` interface * Revert "Revert "Remove `GOGC` environment variable from tapper"" This reverts commitab2b9a803b
. * Revert "Bring back `debug.FreeOSMemory()` call" This reverts commit1cce863bbb
. * Remove excess comment * Fix acceptance tests (`logger` module) #run_acceptance_tests * Bring back `github.com/patrickmn/go-cache` * Fix `NewTcpStream` method signature * Put `tcpReader` and `tcpStream` mocks into protocol dissectors to remove `github.com/up9inc/mizu/tap` dependency * Fix AMQP tests * Revert960ba644cd
* Revert `go.mod` and `go.sum` files in protocol dissectors * Fix the comment position * Revert `AppStatsInst` change * Fix indent * Fix CLI build * Fix linter error * Fix error msg * Revert some of the changes in `chunk.go`
137 lines
2.8 KiB
Go
137 lines
2.8 KiB
Go
package tap
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/up9inc/mizu/tap/api"
|
|
)
|
|
|
|
/* It's a connection (bidirectional)
|
|
* Implements gopacket.reassembly.Stream interface (Accept, ReassembledSG, ReassemblyComplete)
|
|
* ReassembledSG gets called when new reassembled data is ready (i.e. bytes in order, no duplicates, complete)
|
|
* In our implementation, we pass information from ReassembledSG to the TcpReader through a shared channel.
|
|
*/
|
|
type tcpStream struct {
|
|
id int64
|
|
isClosed bool
|
|
protoIdentifier *api.ProtoIdentifier
|
|
isTapTarget bool
|
|
clients []api.TcpReader
|
|
servers []api.TcpReader
|
|
origin api.Capture
|
|
reqResMatcher api.RequestResponseMatcher
|
|
createdAt time.Time
|
|
streamsMap api.TcpStreamMap
|
|
sync.Mutex
|
|
}
|
|
|
|
func NewTcpStream(isTapTarget bool, streamsMap api.TcpStreamMap, capture api.Capture) api.TcpStream {
|
|
return &tcpStream{
|
|
isTapTarget: isTapTarget,
|
|
protoIdentifier: &api.ProtoIdentifier{},
|
|
streamsMap: streamsMap,
|
|
origin: capture,
|
|
}
|
|
}
|
|
|
|
func (t *tcpStream) getId() int64 {
|
|
return t.id
|
|
}
|
|
|
|
func (t *tcpStream) setId(id int64) {
|
|
t.id = id
|
|
}
|
|
|
|
func (t *tcpStream) close() {
|
|
t.Lock()
|
|
defer t.Unlock()
|
|
|
|
if t.isClosed {
|
|
return
|
|
}
|
|
|
|
t.isClosed = true
|
|
|
|
t.streamsMap.Delete(t.id)
|
|
|
|
for i := range t.clients {
|
|
reader := t.clients[i]
|
|
reader.(*tcpReader).close()
|
|
}
|
|
for i := range t.servers {
|
|
reader := t.servers[i]
|
|
reader.(*tcpReader).close()
|
|
}
|
|
}
|
|
|
|
func (t *tcpStream) addClient(reader api.TcpReader) {
|
|
t.clients = append(t.clients, reader)
|
|
}
|
|
|
|
func (t *tcpStream) addServer(reader api.TcpReader) {
|
|
t.servers = append(t.servers, reader)
|
|
}
|
|
|
|
func (t *tcpStream) getClients() []api.TcpReader {
|
|
return t.clients
|
|
}
|
|
|
|
func (t *tcpStream) getServers() []api.TcpReader {
|
|
return t.servers
|
|
}
|
|
|
|
func (t *tcpStream) getClient(index int) api.TcpReader {
|
|
return t.clients[index]
|
|
}
|
|
|
|
func (t *tcpStream) getServer(index int) api.TcpReader {
|
|
return t.servers[index]
|
|
}
|
|
|
|
func (t *tcpStream) SetProtocol(protocol *api.Protocol) {
|
|
t.Lock()
|
|
defer t.Unlock()
|
|
|
|
if t.protoIdentifier.IsClosedOthers {
|
|
return
|
|
}
|
|
|
|
t.protoIdentifier.Protocol = protocol
|
|
|
|
for i := range t.clients {
|
|
reader := t.clients[i]
|
|
if reader.GetExtension().Protocol != t.protoIdentifier.Protocol {
|
|
reader.(*tcpReader).close()
|
|
}
|
|
}
|
|
for i := range t.servers {
|
|
reader := t.servers[i]
|
|
if reader.GetExtension().Protocol != t.protoIdentifier.Protocol {
|
|
reader.(*tcpReader).close()
|
|
}
|
|
}
|
|
|
|
t.protoIdentifier.IsClosedOthers = true
|
|
}
|
|
|
|
func (t *tcpStream) GetOrigin() api.Capture {
|
|
return t.origin
|
|
}
|
|
|
|
func (t *tcpStream) GetProtoIdentifier() *api.ProtoIdentifier {
|
|
return t.protoIdentifier
|
|
}
|
|
|
|
func (t *tcpStream) GetReqResMatcher() api.RequestResponseMatcher {
|
|
return t.reqResMatcher
|
|
}
|
|
|
|
func (t *tcpStream) GetIsTapTarget() bool {
|
|
return t.isTapTarget
|
|
}
|
|
|
|
func (t *tcpStream) GetIsClosed() bool {
|
|
return t.isClosed
|
|
}
|