hepparser

package module
v0.0.0-...-0d40e75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

README

Its part of heplify-server. Possible to use inside your project.

###Example usage:

    import (
        "github.com/custompbx/hepparser"
        "net"
    )  

    const maxPktLen = 8192
    const addr = "127.0.0.1:9060"

    func Listener() {
        ua, err := net.ResolveUDPAddr("udp", addr)
        if err != nil {
            return
        }
    
        uc, err := net.ListenUDP("udp", ua)
        if err != nil {
            return
        }
    
        for {
            buf := make([]byte, maxPktLen)
            n, err := uc.Read(buf)
            if err != nil {
                log.Printf("%v\n return", err)
                return
            } else if n > maxPktLen {
                continue
            }
            go parser(buf[:n])
        }
    }
    
    func parser(packet) {
        hepPacket, err := hepparser.DecodeHEP(packet)
        if err != nil {
            log.Println(err)
            return
        }
        // Do whatever with packet -- hepPacket
    }

Documentation

Index

Constants

View Source
const (
	Version   = 1  // Chunk 0x0001 IP protocol family (0x02=IPv4, 0x0a=IPv6)
	Protocol  = 2  // Chunk 0x0002 IP protocol ID (0x06=TCP, 0x11=UDP)
	IP4SrcIP  = 3  // Chunk 0x0003 IPv4 source address
	IP4DstIP  = 4  // Chunk 0x0004 IPv4 destination address
	IP6SrcIP  = 5  // Chunk 0x0005 IPv6 source address
	IP6DstIP  = 6  // Chunk 0x0006 IPv6 destination address
	SrcPort   = 7  // Chunk 0x0007 Protocol source port
	DstPort   = 8  // Chunk 0x0008 Protocol destination port
	Tsec      = 9  // Chunk 0x0009 Unix timestamp, seconds
	Tmsec     = 10 // Chunk 0x000a Unix timestamp, microseconds
	ProtoType = 11 // Chunk 0x000b Protocol type (DNS, LOG, RTCP, SIP)
	NodeID    = 12 // Chunk 0x000c Capture client ID
	NodePW    = 14 // Chunk 0x000e Authentication key (plain text / TLS connection)
	Payload   = 15 // Chunk 0x000f Captured packet payload
	CID       = 17 // Chunk 0x0011 Correlation ID
	Vlan      = 18 // Chunk 0x0012 VLAN
	NodeName  = 19 // Chunk 0x0013 NodeName
)

HEP chunks

Variables

View Source
var (
	ErrInvalidLengthHep = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowHep   = fmt.Errorf("proto: integer overflow")
)

Functions

This section is empty.

Types

type HEP

type HEP struct {
	Version     uint32 `protobuf:"varint,1,req,name=Version" json:"Version"`
	Protocol    uint32 `protobuf:"varint,2,req,name=Protocol" json:"Protocol"`
	SrcIP       string `protobuf:"bytes,3,req,name=SrcIP" json:"SrcIP"`
	DstIP       string `protobuf:"bytes,4,req,name=DstIP" json:"DstIP"`
	SrcPort     uint32 `protobuf:"varint,5,req,name=SrcPort" json:"SrcPort"`
	DstPort     uint32 `protobuf:"varint,6,req,name=DstPort" json:"DstPort"`
	Tsec        uint32 `protobuf:"varint,7,req,name=Tsec" json:"Tsec"`
	Tmsec       uint32 `protobuf:"varint,8,req,name=Tmsec" json:"Tmsec"`
	ProtoType   uint32 `protobuf:"varint,9,req,name=ProtoType" json:"ProtoType"`
	NodeID      uint32 `protobuf:"varint,10,req,name=NodeID" json:"NodeID"`
	NodePW      string `protobuf:"bytes,11,req,name=NodePW" json:"NodePW"`
	Payload     string `protobuf:"bytes,12,req,name=Payload" json:"Payload"`
	CID         string `protobuf:"bytes,13,req,name=CID" json:"CID"`
	Vlan        uint32 `protobuf:"varint,14,req,name=Vlan" json:"Vlan"`
	ProtoString string
	Timestamp   time.Time
	SIP         *sipparser.SipMsg
	NodeName    string
	SID         string
}

HEP represents HEP packet

func DecodeHEP

func DecodeHEP(packet []byte) (*HEP, error)

DecodeHEP returns a parsed HEP message

func (*HEP) EscapeFields

func (h *HEP) EscapeFields(w io.Writer, tag string) (int, error)

func (*HEP) Unmarshal

func (m *HEP) Unmarshal(dAtA []byte) error

type HeplifyServer

type HeplifyServer struct {
	HEPAddr            string   `default:"0.0.0.0:9060"`
	HEPTCPAddr         string   `default:""`
	HEPTLSAddr         string   `default:"0.0.0.0:9060"`
	ESAddr             string   `default:""`
	ESDiscovery        bool     `default:"true"`
	ESUser             string   `default:""`
	ESPass             string   `default:""`
	LokiURL            string   `default:""`
	LokiBulk           int      `default:"400"`
	LokiTimer          int      `default:"4"`
	LokiBuffer         int      `default:"100000"`
	LokiHEPFilter      []int    `default:"1,5,100"`
	ForceHEPPayload    []int    `default:""`
	PromAddr           string   `default:":9096"`
	PromTargetIP       string   `default:""`
	PromTargetName     string   `default:""`
	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"`
	DBBulk             int      `default:"400"`
	DBTimer            int      `default:"4"`
	DBBuffer           int      `default:"400000"`
	DBWorker           int      `default:"8"`
	DBRotate           bool     `default:"true"`
	DBPartLog          string   `default:"2h"`
	DBPartIsup         string   `default:"6h"`
	DBPartSip          string   `default:"2h"`
	DBPartQos          string   `default:"6h"`
	DBDropDays         int      `default:"14"`
	DBDropDaysCall     int      `default:"0"`
	DBDropDaysRegister int      `default:"0"`
	DBDropDaysDefault  int      `default:"0"`
	DBDropOnStart      bool     `default:"false"`
	Dedup              bool     `default:"false"`
	DiscardMethod      []string `default:""`
	AlegIDs            []string `default:""`
	CustomHeader       []string `default:""`
	SIPHeader          []string `default:"ruri_user,ruri_domain,from_user,from_domain,to_user,callid,method,user_agent"`
	LogDbg             string   `default:""`
	LogLvl             string   `default:"info"`
	LogStd             bool     `default:"false"`
	LogSys             bool     `default:"false"`
	Config             string   `default:"./heplify-server.toml"`
	ConfigHTTPAddr     string   `default:""`
	ConfigHTTPPW       string   `default:""`
}
var Setting HeplifyServer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL