Skip to content

Commit

Permalink
Merge pull request #30 from negbie/master
Browse files Browse the repository at this point in the history
Sync
  • Loading branch information
negbie authored Feb 10, 2018
2 parents 1672fad + b1878c2 commit 1eaff5c
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 135 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
Zip bool
HepServer string
HepTLSProxy string
HepNodePW string
HepNodeID uint
}

Expand Down
30 changes: 17 additions & 13 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (

type Decoder struct {
Host string
Node uint32
NodeID uint32
NodePW []byte
LayerType gopacket.LayerType
defragger *ip4defrag.IPv4Defragmenter
fragCount int
Expand All @@ -41,13 +42,14 @@ type Decoder struct {

type Packet struct {
Host string
Node uint32
NodeID uint32
NodePW []byte
Tsec uint32
Tmsec uint32
Vlan uint16
Version uint8
Protocol uint8
ProtoType uint8
Version byte
Protocol byte
ProtoType byte
SrcIP net.IP
DstIP net.IP
SrcPort uint16
Expand Down Expand Up @@ -79,7 +81,8 @@ func NewDecoder(datalink layers.LinkType) *Decoder {

d := &Decoder{
Host: host,
Node: uint32(config.Cfg.HepNodeID),
NodeID: uint32(config.Cfg.HepNodeID),
NodePW: []byte(config.Cfg.HepNodePW),
LayerType: lt,
defragger: ip4defrag.NewIPv4Defragmenter(),
SIPCache: cSIP,
Expand All @@ -93,10 +96,11 @@ func NewDecoder(datalink layers.LinkType) *Decoder {

func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error) {
pkt := &Packet{
Host: d.Host,
Node: d.Node,
Tsec: uint32(ci.Timestamp.Unix()),
Tmsec: uint32(ci.Timestamp.Nanosecond() / 1000),
Host: d.Host,
NodeID: d.NodeID,
NodePW: d.NodePW,
Tsec: uint32(ci.Timestamp.Unix()),
Tmsec: uint32(ci.Timestamp.Nanosecond() / 1000),
}

if len(data) > 42 {
Expand Down Expand Up @@ -142,7 +146,7 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
return nil, nil
}

pkt.Version = ip4.Version
pkt.Version = 0x02
pkt.Protocol = uint8(ip4.Protocol)
pkt.SrcIP = ip4.SrcIP
pkt.DstIP = ip4.DstIP
Expand All @@ -165,7 +169,7 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
packet, string(packet.ApplicationLayer().Payload()), string(ip4New.Payload[8:]), ip4New.Length,
)

pkt.Version = ip4New.Version
pkt.Version = 0x02
pkt.Protocol = uint8(ip4New.Protocol)
pkt.SrcIP = ip4New.SrcIP
pkt.DstIP = ip4New.DstIP
Expand All @@ -185,7 +189,7 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
return nil, nil
}

pkt.Version = ip6.Version
pkt.Version = 0x0a
pkt.Protocol = uint8(ip6.NextHeader)
pkt.SrcIP = ip6.SrcIP
pkt.DstIP = ip6.DstIP
Expand Down
6 changes: 4 additions & 2 deletions decoder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (d *Decoder) flushFragments() {
func (p *Packet) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Host string
Node uint32
NodeID uint32
NodePW string
Tsec uint32
Tmsec uint32
Vlan uint16
Expand All @@ -65,7 +66,8 @@ func (p *Packet) MarshalJSON() ([]byte, error) {
Payload string
}{
Host: p.Host,
Node: p.Node,
NodeID: p.NodeID,
NodePW: string(p.NodePW),
Tsec: p.Tsec,
Tmsec: p.Tmsec,
Vlan: p.Vlan,
Expand Down
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/negbie/heplify/config"
"github.com/negbie/heplify/logp"
"github.com/negbie/heplify/sniffer"
//_ "github.com/mkevac/debugcharts"
)

const version = "heplify 1.0"
Expand Down Expand Up @@ -35,7 +36,7 @@ func parseFlags() {
flag.BoolVar(&ifaceConfig.ReadSpeed, "rs", false, "Maximum pcap read speed. Doesn't use packet timestamps")
flag.IntVar(&ifaceConfig.Snaplen, "s", 16384, "Snaplength")
flag.StringVar(&ifaceConfig.PortRange, "pr", "5060-5090", "Portrange to capture SIP")
flag.BoolVar(&ifaceConfig.WithVlan, "vl", false, "Capture vlans too")
flag.BoolVar(&ifaceConfig.WithVlan, "vl", false, "Vlan")
flag.IntVar(&ifaceConfig.BufferSizeMb, "b", 32, "Interface buffersize (MB)")
flag.StringVar(&logging.Level, "l", "info", "Log level [debug, info, warning, error]")
flag.BoolVar(&ifaceConfig.OneAtATime, "o", false, "Read packet for packet")
Expand All @@ -47,8 +48,9 @@ func parseFlags() {
flag.StringVar(&config.Cfg.Filter, "fi", "", "Filter interesting packets")
flag.StringVar(&config.Cfg.Discard, "di", "", "Discard uninteresting packets")
flag.StringVar(&config.Cfg.HepServer, "hs", "127.0.0.1:9060", "HEP UDP server address")
flag.StringVar(&config.Cfg.HepTLSProxy, "hp", "", "HEP TLS proxy address")
flag.UintVar(&config.Cfg.HepNodeID, "hi", 2002, "HEP Node ID")
flag.StringVar(&config.Cfg.HepTLSProxy, "hx", "", "HEP TLS proxy address")
flag.StringVar(&config.Cfg.HepNodePW, "hp", "myhep", "HepNodePW")
flag.UintVar(&config.Cfg.HepNodeID, "hi", 2002, "HepNodeID")
flag.Parse()

config.Cfg.Iface = &ifaceConfig
Expand All @@ -71,6 +73,10 @@ func checkCritErr(err error) {
func main() {
parseFlags()

/* go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}() */

err := logp.Init("heplify", config.Cfg.Logging)
checkCritErr(err)

Expand Down
16 changes: 10 additions & 6 deletions publish/file.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package publish

import (
"encoding/json"

"github.com/negbie/heplify/decoder"
"github.com/negbie/heplify/logp"
)
Expand All @@ -11,12 +9,18 @@ type FileOutputer struct {
}

func (fo *FileOutputer) Output(pkt *decoder.Packet) {
jsonPkt, err := json.MarshalIndent(pkt, "", " ")
/* jsonPkt, err := json.MarshalIndent(pkt, "", " ")
if err != nil {
logp.Err("json %v", err)
return
}
logp.Info("%s", jsonPkt)
*/
h, err := DecodeHEP(EncodeHEP(pkt))
if err != nil {
logp.Err("json %v", err)
return
logp.Info("%s", err)
}
logp.Info("%s", jsonPkt)
h.String()
}

func NewFileOutputer() (*FileOutputer, error) {
Expand Down
2 changes: 1 addition & 1 deletion publish/hep.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (ho *HEPOutputer) ConnectServer(addr string) (conn net.Conn, err error) {
}

func (ho *HEPOutputer) Output(pkt *decoder.Packet) {
ho.hepQueue <- NewHEP(pkt)
ho.hepQueue <- EncodeHEP(pkt)
}

func (ho *HEPOutputer) Send(msg []byte) {
Expand Down
Loading

0 comments on commit 1eaff5c

Please sign in to comment.