aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-09-02 18:53:39 +0200
committerToni Uhlig <matzeton@googlemail.com>2020-09-02 18:57:58 +0200
commit001f84af3b9bfd8427c99af1a380d40b6577489a (patch)
tree66840c24bd8a23c5b933cba6046c3d2d87a72431
parent0a03293d16ca0fc9f493a58748da1c43d35782e4 (diff)
go-dashboard: Added event structs and JSON unmarshal semantic.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--Makefile11
-rw-r--r--examples/go-dashboard/main.go75
2 files changed, 79 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index f978c5492..71cc42719 100644
--- a/Makefile
+++ b/Makefile
@@ -7,13 +7,12 @@ GOFLAGS = -ldflags='-s -w'
ifneq ($(PKG_CONFIG_BIN),)
ifneq ($(PKG_CONFIG_PREFIX),)
-PC_CFLAGS=$(shell PKG_CONFIG_PATH=$(shell realpath $(PKG_CONFIG_PREFIX)) $(PKG_CONFIG_BIN) --define-prefix=$(shell realpath $(PKG_CONFIG_PREFIX)) --cflags libndpi)
-PC_LDFLAGS=$(shell PKG_CONFIG_PATH=$(shell realpath $(PKG_CONFIG_PREFIX)) $(PKG_CONFIG_BIN) --define-prefix=$(shell realpath $(PKG_CONFIG_PREFIX)) --libs libndpi)
-PROJECT_CFLAGS += -Wl,-rpath='$(shell realpath $(PKG_CONFIG_PREFIX)/..)'
+PC_CFLAGS=$(shell PKG_CONFIG_PATH=$(shell realpath $(PKG_CONFIG_PREFIX))/lib/pkgconfig $(PKG_CONFIG_BIN) --define-variable=prefix=$(shell realpath $(PKG_CONFIG_PREFIX)) --cflags libndpi)
+PC_LDFLAGS=$(shell PKG_CONFIG_PATH=$(shell realpath $(PKG_CONFIG_PREFIX))/lib/pkgconfig $(PKG_CONFIG_BIN) --define-variable=prefix=$(shell realpath $(PKG_CONFIG_PREFIX)) --libs libndpi)
+PROJECT_CFLAGS += -Wl,-rpath='$(shell realpath $(PKG_CONFIG_PREFIX)/lib)'
else
PC_CFLAGS=$(shell $(PKG_CONFIG_BIN) --cflags libndpi)
PC_LDFLAGS=$(shell $(PKG_CONFIG_BIN) --libs libndpi)
-PROJECT_CFLAGS += -Wl,-rpath='$(shell realpath $(PKG_CONFIG_PREFIX)/..)'
endif
else
@@ -66,6 +65,8 @@ ifneq ($(DISABLE_JSMN),yes)
DISABLE_JSMN = no
endif
+GO_DASHBOARD_SRCS := examples/go-dashboard/main.go examples/go-dashboard/ui/ui.go
+
RM = rm -f
all: help nDPId nDPIsrvd
@@ -85,7 +86,7 @@ else
$(CC) $(PROJECT_CFLAGS) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LIBS)
endif
-examples/go-dashboard/go-dashboard: examples/go-dashboard/main.go
+examples/go-dashboard/go-dashboard: $(GO_DASHBOARD_SRCS)
ifneq ($(GOCC),)
cd examples/go-dashboard && GO111MODULE=on $(GOCC) mod vendor
cd examples/go-dashboard && GO111MODULE=on $(GOCC) build $(GOFLAGS) .
diff --git a/examples/go-dashboard/main.go b/examples/go-dashboard/main.go
index 89ec9adef..c3ae62b37 100644
--- a/examples/go-dashboard/main.go
+++ b/examples/go-dashboard/main.go
@@ -22,6 +22,48 @@ var (
nDPIsrvd_JSON_BYTES uint16 = 4
)
+type packet_event struct {
+ ThreadID uint8 `json:"thread_id"`
+ PacketID uint64 `json:"packet_id"`
+
+ FlowID uint32 `json:"flow_id"`
+ FlowPacketID uint64 `json:"flow_packet_id"`
+ MaxPackets uint8 `json:"max_packets"`
+
+ PacketEventID uint8 `json:"packet_event_id"`
+ PacketEventName string `json:"packet_event_name"`
+ PacketOversize bool `json:"pkt_oversize"`
+ PacketTimestamp uint64 `json:"pkt_ts"`
+ PacketLength uint32 `json:"pkt_len"`
+ Packet string `json:"pkt"`
+ PacketCaptureLength uint32 `json:"pkt_caplen"`
+ PacketType uint32 `json:"pkt_type"`
+ PacketIpOffset uint32 `json:"pkt_ipoffset"`
+}
+
+type flow_event struct {
+ ThreadID uint8 `json:"thread_id"`
+ PacketID uint64 `json:"packet_id"`
+
+ FlowID uint32 `json:"flow_id"`
+ FlowPacketID uint64 `json:"flow_packet_id"`
+ FlowFirstSeen uint64 `json:"flow_first_seen"`
+ FlowLastSeen uint64 `json:"flow_last_seen"`
+ FlowTotalLayer4DataLength uint64 `json:"flow_tot_l4_data_len"`
+ FlowMinLayer4DataLength uint64 `json:"flow_min_l4_data_len"`
+ FlowMaxLayer4DataLength uint64 `json:"flow_max_l4_data_len"`
+ FlowAvgLayer4DataLength uint64 `json:"flow_avg_l4_data_len"`
+ IsMidstreamFlow uint32 `json:"midstream"`
+}
+
+type basic_event struct {
+ ThreadID uint8 `json:"thread_id"`
+ PacketID uint64 `json:"packet_id"`
+
+ BasicEventID uint8 `json:"basic_event_id"`
+ BasicEventName string `json:"basic_event_name"`
+}
+
func main() {
ui.Init()
@@ -29,7 +71,11 @@ func main() {
WarningLogger = log.New(os.Stderr, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile)
ErrorLogger = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
- conn, _ := net.Dial("tcp", "127.0.0.1:7000")
+ conn, err := net.Dial("tcp", "127.0.0.1:7000")
+ if err != nil {
+ ErrorLogger.Printf("Connection failed: %v\n", err)
+ os.Exit(1)
+ }
buf := make([]byte, NETWORK_BUFFER_MAX_SIZE)
var jsonStr string
@@ -94,7 +140,32 @@ func main() {
ErrorLogger.Printf("BUG: JSON error: %v\n", err)
os.Exit(1)
}
- InfoLogger.Printf("JSON map: %v\n-------------------------------------------------------\n", jsonMap)
+ if jsonMap["packet_event_id"] != nil {
+ pe := packet_event{}
+ if err := json.Unmarshal([]byte(jsonStr[nDPIsrvd_JSON_BYTES:nDPIsrvd_JSON_BYTES+jsonLen]), &pe); err != nil {
+ ErrorLogger.Printf("BUG: JSON Unmarshal error: %v\n", err)
+ os.Exit(1)
+ }
+ InfoLogger.Printf("PACKET EVENT %v\n", pe)
+ } else if jsonMap["flow_event_id"] != nil {
+ fe := flow_event{}
+ if err := json.Unmarshal([]byte(jsonStr[nDPIsrvd_JSON_BYTES:nDPIsrvd_JSON_BYTES+jsonLen]), &fe); err != nil {
+ ErrorLogger.Printf("BUG: JSON Unmarshal error: %v\n", err)
+ os.Exit(1)
+ }
+ InfoLogger.Printf("FLOW EVENT %v\n", fe)
+ } else if jsonMap["basic_event_id"] != nil {
+ be := basic_event{}
+ if err := json.Unmarshal([]byte(jsonStr[nDPIsrvd_JSON_BYTES:nDPIsrvd_JSON_BYTES+jsonLen]), &be); err != nil {
+ ErrorLogger.Printf("BUG: JSON Unmarshal error: %v\n", err)
+ os.Exit(1)
+ }
+ InfoLogger.Printf("BASIC EVENT %v\n", be)
+ } else {
+ ErrorLogger.Printf("BUG: Unknown JSON: %v\n", jsonStr[nDPIsrvd_JSON_BYTES:nDPIsrvd_JSON_BYTES+jsonLen])
+ os.Exit(1)
+ }
+ //InfoLogger.Printf("JSON map: %v\n-------------------------------------------------------\n", jsonMap)
jsonStr = jsonStr[jsonLen+nDPIsrvd_JSON_BYTES:]
jsonStrLen -= (jsonLen + nDPIsrvd_JSON_BYTES)