Move HTTP files into tap/extensions/lib for now

This commit is contained in:
M. Mert Yildiran 2021-08-17 04:02:48 +03:00
parent 648a4d21f3
commit 2c7e857075
No known key found for this signature in database
GPG Key ID: D42ADB236521BF7A
11 changed files with 85 additions and 19 deletions

View File

@ -31,6 +31,7 @@ cli: ## Build CLI.
agent: ## Build agent. agent: ## Build agent.
@(echo "building mizu agent .." ) @(echo "building mizu agent .." )
@(cd agent; go build -o build/mizuagent main.go) @(cd agent; go build -o build/mizuagent main.go)
${MAKE} extensions
@ls -l agent/build @ls -l agent/build
docker: ## Build and publish agent docker image. docker: ## Build and publish agent docker image.
@ -65,6 +66,11 @@ clean-cli: ## Clean CLI.
clean-docker: clean-docker:
@(echo "DOCKER cleanup - NOT IMPLEMENTED YET " ) @(echo "DOCKER cleanup - NOT IMPLEMENTED YET " )
http: extensions: extension-http
extension-http:
cd tap/extensions/http && \ cd tap/extensions/http && \
go build -buildmode=plugin -o ../http.so . go build -buildmode=plugin -o ../http.so .
cd ../../..
mkdir -p agent/build/extensions
cp tap/extensions/http.so agent/build/extensions

View File

@ -1,12 +1,7 @@
module github.com/up9inc/mizu/tap module github.com/up9inc/mizu/tap/extensions/http
go 1.16 go 1.16
require ( require github.com/up9inc/mizu/tap/extensions/http/lib v0.0.0-00010101000000-000000000000
github.com/bradleyfalzon/tlsx v0.0.0-20170624122154-28fd0e59bac4
github.com/google/martian v2.1.0+incompatible replace github.com/up9inc/mizu/tap/extensions/http/lib => ./lib
github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc
github.com/romana/rlog v0.0.0-20171115192701-f018bc92e7d7
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d
golang.org/x/text v0.3.7 // indirect
)

View File

@ -0,0 +1,12 @@
module github.com/up9inc/mizu/tap/extensions/http/lib
go 1.16
require (
github.com/bradleyfalzon/tlsx v0.0.0-20170624122154-28fd0e59bac4
github.com/google/martian v2.1.0+incompatible
github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc
github.com/romana/rlog v0.0.0-20171115192701-f018bc92e7d7
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d
golang.org/x/text v0.3.7 // indirect
)

View File

@ -0,0 +1,17 @@
github.com/bradleyfalzon/tlsx v0.0.0-20170624122154-28fd0e59bac4 h1:NJOOlc6ZJjix0A1rAU+nxruZtR8KboG1848yqpIUo4M=
github.com/bradleyfalzon/tlsx v0.0.0-20170624122154-28fd0e59bac4/go.mod h1:DQPxZS994Ld1Y8uwnJT+dRL04XPD0cElP/pHH/zEBHM=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc h1:Ak86L+yDSOzKFa7WM5bf5itSOo1e3Xh8bm5YCMUXIjQ=
github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/romana/rlog v0.0.0-20171115192701-f018bc92e7d7 h1:jkvpcEatpwuMF5O5LVxTnehj6YZ/aEZN4NWD/Xml4pI=
github.com/romana/rlog v0.0.0-20171115192701-f018bc92e7d7/go.mod h1:KTrHyWpO1sevuXPZwyeZc72ddWRFqNSKDFl7uVWKpg0=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View File

@ -1,4 +1,4 @@
package main package lib
import ( import (
"bufio" "bufio"

View File

@ -1,4 +1,4 @@
package main package lib
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package main package lib
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package main package lib
type OutboundLinkProtocol string type OutboundLinkProtocol string

View File

@ -1,4 +1,4 @@
package main package lib
import ( import (
"bufio" "bufio"
@ -37,6 +37,10 @@ type ConnectionInfo struct {
IsOutgoing bool IsOutgoing bool
} }
func SomeExample() {
fmt.Println("Hello from SomeExample")
}
func (tid *tcpID) String() string { func (tid *tcpID) String() string {
return fmt.Sprintf("%s->%s %s->%s", tid.srcIP, tid.dstIP, tid.srcPort, tid.dstPort) return fmt.Sprintf("%s->%s %s->%s", tid.srcIP, tid.dstIP, tid.srcPort, tid.dstPort)
} }

View File

@ -0,0 +1,17 @@
package main
import (
"fmt"
"github.com/up9inc/mizu/tap/extensions/http/lib"
)
type greeting string
func (g greeting) Greet() {
fmt.Println("Hello HTTP")
lib.SomeExample()
}
// exported as symbol named "Greeter"
var Greeter greeting

View File

@ -15,6 +15,8 @@ import (
"log" "log"
"os" "os"
"os/signal" "os/signal"
"path"
"path/filepath"
"plugin" "plugin"
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
@ -128,6 +130,10 @@ type Extension struct {
Plug *plugin.Plugin Plug *plugin.Plugin
} }
type Greeter interface {
Greet()
}
var extensions []Extension // global var extensions []Extension // global
type OutputChannelItem struct { type OutputChannelItem struct {
@ -196,15 +202,16 @@ func (c *Context) GetCaptureInfo() gopacket.CaptureInfo {
} }
func StartPassiveTapper(opts *TapOpts) (<-chan *OutputChannelItem, <-chan *OutboundLink) { func StartPassiveTapper(opts *TapOpts) (<-chan *OutputChannelItem, <-chan *OutboundLink) {
fmt.Printf("called StartPassiveTapper\n")
hostMode = opts.HostMode hostMode = opts.HostMode
// var harWriter *HarWriter // var harWriter *HarWriter
// if *dumpToHar { // if *dumpToHar {
// harWriter = NewHarWriter(*HarOutputDir, *harEntriesPerFile) // harWriter = NewHarWriter(*HarOutputDir, *harEntriesPerFile)
// } // }
// outboundLinkWriter := NewOutboundLinkWriter() outboundLinkWriter := NewOutboundLinkWriter()
// go startPassiveTapper(harWriter, outboundLinkWriter) go startPassiveTapper(outboundLinkWriter)
// if harWriter != nil { // if harWriter != nil {
// return harWriter.OutChan, outboundLinkWriter.OutChan // return harWriter.OutChan, outboundLinkWriter.OutChan
@ -245,12 +252,20 @@ func startMemoryProfiler() {
} }
func loadExtensions() { func loadExtensions() {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
abspath := path.Join(dir, "./extensions/http.so")
fmt.Printf("abspath: %v\n", abspath)
extension := &Extension{ extension := &Extension{
Name: "http", Name: "http",
Path: "./extensions/http.so", Path: abspath,
} }
plug, _ := plugin.Open(extension.Path) plug, _ := plugin.Open(extension.Path)
extension.Plug = plug extension.Plug = plug
symGreeter, _ := plug.Lookup("Greeter")
var greeter Greeter
greeter, _ = symGreeter.(Greeter)
greeter.Greet()
} }
func startPassiveTapper(outboundLinkWriter *OutboundLinkWriter) { func startPassiveTapper(outboundLinkWriter *OutboundLinkWriter) {