From 1b1caf5b9e00f6e988fe3b71e2b0ed1ec4eb48fd Mon Sep 17 00:00:00 2001 From: Eugen Biegler Date: Mon, 18 Jun 2018 22:48:36 +0200 Subject: [PATCH] Add DiscardMethod option --- cmd/heplify-server/heplify-server.go | 2 +- config/config.go | 66 ++++++++++++----------- database/sqlhomer5.go | 2 +- database/sqlhomer7.go | 2 +- decoder.go | 12 ++++- example/homer5_config/heplify-server.toml | 2 + example/homer7_config/heplify-server.toml | 2 + server/hep.go | 2 + 8 files changed, 53 insertions(+), 37 deletions(-) diff --git a/cmd/heplify-server/heplify-server.go b/cmd/heplify-server/heplify-server.go index 5dafee7f..f333ae1f 100644 --- a/cmd/heplify-server/heplify-server.go +++ b/cmd/heplify-server/heplify-server.go @@ -16,7 +16,7 @@ import ( "github.com/negbie/logp" ) -const version = "heplify-server 0.92" +const version = "heplify-server 0.93" type server interface { Run() diff --git a/config/config.go b/config/config.go index 59ee142e..c522d7ea 100644 --- a/config/config.go +++ b/config/config.go @@ -3,38 +3,39 @@ package config var Setting HeplifyServer type HeplifyServer struct { - HEPAddr string `default:"0.0.0.0:9060"` - MQDriver string `default:""` - MQAddr string `default:""` - MQTopic string `default:""` - PromAddr string `default:""` - PromTargetIP string `default:""` - PromTargetName string `default:""` - HoraclifixStats bool `default:"false"` - RTPAgentStats bool `default:"false"` - DBShema string `default:"homer5"` - DBDriver string `default:"mysql"` - DBAddr string `default:"localhost:3306"` - DBUser string `default:"root"` - DBPass string `default:""` - DBDataTable string `default:"homer_data"` - DBConfTable string `default:"homer_configuration"` - DBTableSpace string `default:""` - DBBulk int `default:"200"` - DBTimer int `default:"2"` - DBRotate bool `default:"true"` - DBPartLog string `default:"6h"` - DBPartSip string `default:"2h"` - DBPartQos string `default:"12h"` - DBDropDays int `default:"0"` - DBDropOnStart bool `default:"false"` - Dedup bool `default:"false"` - AlegID string `default:"x-cid"` - LogDbg string `default:""` - LogLvl string `default:"info"` - LogStd bool `default:"false"` - Config string `default:"./heplify-server.toml"` - Version bool `default:"false"` + HEPAddr string `default:"0.0.0.0:9060"` + MQDriver string `default:""` + MQAddr string `default:""` + MQTopic string `default:""` + PromAddr string `default:""` + PromTargetIP string `default:""` + PromTargetName string `default:""` + HoraclifixStats bool `default:"false"` + RTPAgentStats bool `default:"false"` + DBShema string `default:"homer5"` + DBDriver string `default:"mysql"` + DBAddr string `default:"localhost:3306"` + DBUser string `default:"root"` + DBPass string `default:""` + DBDataTable string `default:"homer_data"` + DBConfTable string `default:"homer_configuration"` + DBTableSpace string `default:""` + DBBulk int `default:"200"` + DBTimer int `default:"2"` + DBRotate bool `default:"true"` + DBPartLog string `default:"6h"` + DBPartSip string `default:"2h"` + DBPartQos string `default:"12h"` + DBDropDays int `default:"0"` + DBDropOnStart bool `default:"false"` + Dedup bool `default:"false"` + DiscardMethod []string `default:""` + AlegID string `default:"x-cid"` + LogDbg string `default:""` + LogLvl string `default:"info"` + LogStd bool `default:"false"` + Config string `default:"./heplify-server.toml"` + Version bool `default:"false"` } func NewConfig() *HeplifyServer { @@ -65,6 +66,7 @@ func NewConfig() *HeplifyServer { DBDropDays: 0, DBDropOnStart: false, Dedup: false, + DiscardMethod: nil, AlegID: "x-cid", LogDbg: "", LogLvl: "info", diff --git a/database/sqlhomer5.go b/database/sqlhomer5.go index 453b0cb4..a106b200 100644 --- a/database/sqlhomer5.go +++ b/database/sqlhomer5.go @@ -258,7 +258,7 @@ func (s *SQLHomer5) insert(hCh chan *decoder.HEP) { } } - } else if pkt.ProtoType >= 2 && pkt.ProtoType <= 200 && pkt.CID != "" { + } else if pkt.ProtoType >= 2 && pkt.Payload != "" && pkt.CID != "" { switch pkt.ProtoType { case 5: rtcpRows = addRTCRow(rtcpRows) diff --git a/database/sqlhomer7.go b/database/sqlhomer7.go index e976261c..5afced2d 100644 --- a/database/sqlhomer7.go +++ b/database/sqlhomer7.go @@ -121,7 +121,7 @@ func (s *SQLHomer7) insert(hCh chan *decoder.HEP) { pHeader = formProtocolHeader(pkt) dHeader = formDataHeader(pkt, date) - if pkt.ProtoType == 1 && pkt.Payload != "" && pkt.CID != "" { + if pkt.ProtoType == 1 && pkt.Payload != "" && pkt.SIP != nil { switch pkt.SIP.CseqMethod { case "INVITE", "UPDATE", "BYE", "ACK", "PRACK", "REFER", "CANCEL", "INFO": callRows = append(callRows, []interface{}{pkt.CID, date, pHeader, dHeader, pkt.Payload}...) diff --git a/decoder.go b/decoder.go index 56e04d38..0b47d445 100644 --- a/decoder.go +++ b/decoder.go @@ -68,7 +68,7 @@ func DecodeHEP(packet []byte) (*HEP, error) { func (h *HEP) parse(packet []byte) error { var err error - if packet[0] == 0x48 && packet[1] == 0x45 && packet[2] == 0x50 && packet[3] == 0x33 { + if bytes.HasPrefix(packet, []byte("HEP3")) { err = h.parseHEP(packet) if err != nil { logp.Warn("%v", err) @@ -102,6 +102,14 @@ func (h *HEP) parse(packet []byte) error { return err } h.CID = h.SIP.CallID + + if len(config.Setting.DiscardMethod) > 0 { + for k := range config.Setting.DiscardMethod { + if config.Setting.DiscardMethod[k] == h.SIP.CseqMethod { + h.Payload = "" + } + } + } } logp.Debug("hep", "%+v\n\n", h) @@ -319,7 +327,7 @@ func makeChuncks(h *HEP, w *bytes.Buffer) []byte { // Chunk VLAN w.Write([]byte{0x00, 0x00, 0x00, 0x12}) w.Write(hepLen8) - binary.BigEndian.PutUint16(chunck16, h.Vlan) + binary.BigEndian.PutUint16(chunck16, uint16(h.Vlan)) w.Write(chunck16) // Chunk MOS only diff --git a/example/homer5_config/heplify-server.toml b/example/homer5_config/heplify-server.toml index 10893da8..a08805fc 100644 --- a/example/homer5_config/heplify-server.toml +++ b/example/homer5_config/heplify-server.toml @@ -24,6 +24,7 @@ DBPartQos = "12h" DBDropDays = 0 DBDropOnStart = false Dedup = false +DiscardMethod = [] AlegID = "x-cid" LogDbg = "" LogLvl = "info" @@ -39,6 +40,7 @@ Version = false # PromAddr = "0.0.0.0:8899" # PromTargetIP = "10.1.2.111,10.1.2.4,10.1.2.5,10.1.2.6,10.12.44.222" # PromTargetName = "sbc_access,sbc_core,kamailio,asterisk,pstn_gateway" +# DiscardMethod = ["OPTIONS","NOTIFY"] # LogDbg = "hep,sql" # LogLvl = "warning" # ------------------------------------- diff --git a/example/homer7_config/heplify-server.toml b/example/homer7_config/heplify-server.toml index ea1412ad..dfd5b992 100644 --- a/example/homer7_config/heplify-server.toml +++ b/example/homer7_config/heplify-server.toml @@ -24,6 +24,7 @@ DBPartQos = "12h" DBDropDays = 0 DBDropOnStart = false Dedup = false +DiscardMethod = [] AlegID = "x-cid" LogDbg = "" LogLvl = "info" @@ -39,6 +40,7 @@ Version = false # PromAddr = "0.0.0.0:8899" # PromTargetIP = "10.1.2.111,10.1.2.4,10.1.2.5,10.1.2.6,10.12.44.222" # PromTargetName = "sbc_access,sbc_core,kamailio,asterisk,pstn_gateway" +# DiscardMethod = ["OPTIONS","NOTIFY"] # LogDbg = "hep,sql" # LogLvl = "warning" # ------------------------------------- diff --git a/server/hep.go b/server/hep.go index d4732ae2..de00fbc9 100644 --- a/server/hep.go +++ b/server/hep.go @@ -240,6 +240,8 @@ GO: } else if hepPkt.ProtoType == 0 { atomic.AddUint64(&h.stats.DupCount, 1) continue + } else if hepPkt.Payload == "" { + continue } atomic.AddUint64(&h.stats.HEPCount, 1)