servicetraceroute

package
v0.0.0-...-7cff3e0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Video uint8 = 0
	Ads   uint8 = 1
	None  uint8 = 2
)
View Source
const (
	In  = 0
	Out = 1
)

Direction of the packet

View Source
const (
	PacketByPacket = "packetbypacket" //Send one packet and then wait the reply
	HopByHop       = "hopbyhop"       //Send all the packets with the same TTL and then wait the replies
	Concurrent     = "concurrent"     //Send all packets at once and then wait the replies (one timeout)
)

Available probing algorithms

View Source
const (
	V4   = "4"
	V6   = "6"
	Tcp  = "tcp"
	Icmp = "icmp"
	Udp  = "udp"
	Dns  = "dns"
)

IP Versions and protocols

View Source
const (
	DefaultIterations                = 10
	DefaultDistance                  = 32
	DefaultInterProbeTime            = 20  //ms
	DefaultInterIterationTime        = 100 // ms
	DefaultProbingAlgorithm          = PacketByPacket
	DefaultWaitProbe                 = false
	DefaultTimeout                   = 2000 //ms
	DefaultMaxConsecutiveMissingHops = 3
)

Default values for the a new traceroute

View Source
const Other = "Other"
View Source
const Unknown = "Unknown"
View Source
const (
	Version = "0.3d" // MAKE SURE TO INCREMENT AFTER EVERY CHANGE
)

Version of Service Traceroute

Variables

This section is empty.

Functions

This section is empty.

Types

type AhoCorasick

type AhoCorasick struct {
	CurrState  int
	StateMap   map[int]*State
	OutputMap  map[int][]string
	FailureMap map[int]int
	DoneState  bool
}

func (*AhoCorasick) AddString

func (ac *AhoCorasick) AddString(input string, output string)

func (*AhoCorasick) Failure

func (ac *AhoCorasick) Failure()

func (*AhoCorasick) FirstMatch

func (ac *AhoCorasick) FirstMatch(str string) []string

func (*AhoCorasick) GoTo

func (ac *AhoCorasick) GoTo(sId int, a rune) (int, bool)

func (*AhoCorasick) NewAhoCorasick

func (ac *AhoCorasick) NewAhoCorasick()

type BufferTrace

type BufferTrace struct {
	TransportProtocol string
	MaxTtl            int
	Iter              int
	InterProbe        int
	InterIter         int
	SendQ             chan []byte
	IPVersion         string
	R                 *Receiver
	FlowSeqMap        map[uint32]int64
	ProbeIdMap        map[uint16]int64
	ProbeSeqMap       map[uint16]int64
	E2eLatencies      []int64
	HopLatencies      map[uint16][]HopLatency

	BorderRouters       []net.IP
	BorderDistance      int
	ReachedBorderRouter bool
	BorderCheckChan     chan *CurrStatus
	Timeout             int

	MaxMissingHops        int
	ReachedMaxMissingHops bool

	IDOffset         uint16
	ProbingAlgorithm string

	ReachedFlowTimeout bool
	FlowEnded          bool
	DataTimeout        int
	LastPacketTime     int64

	StopAnalysis chan bool
	WaitAnalysis chan bool
	DoneSend     chan bool
	OutChan      chan string
	DoneExp      chan bool

	Buffer gopacket.SerializeBuffer

	StartTraceroutes bool
}

Structure which manage the probing phase and analysis of the results for one traceroute

func (*BufferTrace) AnalyzePackets

func (bt *BufferTrace) AnalyzePackets()

Listen for all decoded packets from receiver in order to evaluate whether they are: - A probe, which define the starting time for the RTT - A reply (ICMP), which define the ending time for the RTT and the IP of the interface used to send the packet - Incoming or Outgoing packet, to check if the application flow is still alive (flow timeout) or it is closing (FIN - RST) From probes and replies it builds the final results: TTL - IP - RTT

func (*BufferTrace) BuildTCP

func (bt *BufferTrace) BuildTCP(ttl int, id uint16, seqn uint32, ackn uint32) (layers.Ethernet, layers.IPv4, layers.TCP)

Build and return a TCP packet

func (*BufferTrace) BuildTCPIPv6

func (bt *BufferTrace) BuildTCPIPv6(ttl int, id uint16, seqn uint32, ackn uint32) (layers.Ethernet, layers.IPv6, layers.IPv6Destination, layers.TCP)

Build and return a TCP IPv6 packets (not fully implemented)

func (*BufferTrace) BuildUDP

func (bt *BufferTrace) BuildUDP(ttl int, id uint16) (layers.Ethernet, layers.IPv4, layers.UDP)

Build and return an UDP packet

func (*BufferTrace) BuildUDPIPv6

func (bt *BufferTrace) BuildUDPIPv6(ttl int, id uint16) (layers.Ethernet, layers.IPv6, layers.IPv6Destination, layers.UDP)

Build and return an UDP IPv6 packet (not fully implemented)

func (*BufferTrace) ConvertIDfromPktID

func (bt *BufferTrace) ConvertIDfromPktID(pktID uint16) uint16

Convert the IPID to the correct IP in order to get the correct iteration and TTL

func (*BufferTrace) ConvertIDtoPktID

func (bt *BufferTrace) ConvertIDtoPktID(id uint16) uint16

Convert the ID of the probe to the real IPID to be used to distinguish all ICMP replies between the different traceroutes

func (*BufferTrace) IsBorderRouter

func (bt *BufferTrace) IsBorderRouter(ip net.IP) bool

Check if an IP is a border router

func (*BufferTrace) IsFlowAlive

func (bt *BufferTrace) IsFlowAlive() bool

Return a flag specifying if the flow is alive or not

func (*BufferTrace) NewBufferTrace

func (bt *BufferTrace) NewBufferTrace(transportProtocol string, ipVersion string, r *Receiver, maxTTL int, numberIterations int, interProbeTime int, interIterationTime int, timeout int, idOffset uint16, probingAlgorithm string, flowTimeout int, startTraceroutes bool, maxConsecutiveMissingHops int, borderRouters []net.IP, sendQ chan []byte, outChan chan string)

Initialize and configure a new buffer trace

func (*BufferTrace) PrintLatencies

func (bt *BufferTrace) PrintLatencies() ServiceTracerouteReport

Encode the results and configuration in a json format

func (*BufferTrace) Run

Run the traceroute: start the analysis thread and then send the probes

func (*BufferTrace) SendTCP

func (bt *BufferTrace) SendTCP(packetLayers []gopacket.SerializableLayer)

Encode a TCP packet and send it to sender for the final transmission on the interface

func (*BufferTrace) SendUDP

func (bt *BufferTrace) SendUDP(packetLayers []gopacket.SerializableLayer)

Encode an UDP packet and send it to sender for the final transmission on the interface

func (*BufferTrace) StartProbing

func (bt *BufferTrace) StartProbing()

Start sending probes to the destination

func (*BufferTrace) WaitProbe

func (bt *BufferTrace) WaitProbe(id uint16) (bool, bool)

Wait the reply to one probe After a timeout, stop the waiting and return if a border router was detected

func (*BufferTrace) WaitTrain

func (bt *BufferTrace) WaitTrain(ttl uint16, numberIterations int) (bool, bool)

Wait the replies to all probes sent with the same TTL After a timeout, stop the waiting and return if a border router was detected

type CName

type CName struct {
	Expire int64
}

Structures used for the DNS resolution

type CapThread

type CapThread struct {
	BPF     string
	Buffer  int
	CapSize int
	Port    uint16
	IP      string
}

Structure with main information for the capturing class

type CurrStatus

type CurrStatus struct {
	Ts         int64
	LocalHw    net.HardwareAddr
	RemHw      net.HardwareAddr
	LocalIp    net.IP
	RemIp      net.IP
	TCPLocalIp net.IP
	TCPRemIp   net.IP
	IpId       uint16
	IpIdIcmp   uint16
	IpTtl      uint8
	LocalPort  uint16
	RemPort    uint16
	Seq        uint32
	Ack        uint32
	TcpHLen    uint32
	IPv4       bool
	IPv6       bool
	Dir        int
	IpDataLen  uint32
	TcpFlags   Flags
	Transport  layers.IPProtocol
}

Current status of an application flow

type DNSResolver

type DNSResolver struct {
	Services      []Service
	IpLookup      map[string]IpMap
	ServiceLookup map[string]ServiceMap
	LastPkt       int64

	DNSChan  chan gopacket.Packet
	StopChan chan bool
	MapMutex *sync.Mutex
}

DNS resolver containing the detected DNS requests/responses

func (*DNSResolver) ClearDnsCache

func (ts *DNSResolver) ClearDnsCache()

Remove all the DNS records not update from a while

func (*DNSResolver) ComputeServices

func (ts *DNSResolver) ComputeServices()

Build the string matching graph of AHO Corasick

func (*DNSResolver) LoadServices

func (ts *DNSResolver) LoadServices(filename string)

Load the configuration from a file

func (*DNSResolver) NewDNSResolver

func (ts *DNSResolver) NewDNSResolver(filename string, DNSChan chan gopacket.Packet)

Initialize the DNS resolver loading the configuration from the filename and the input packets through the DNSChan

func (*DNSResolver) ParseDnsLayer

func (ts *DNSResolver) ParseDnsLayer(pkt gopacket.Packet) error

Parse the DNS request

func (*DNSResolver) ParseDnsResponse

func (ts *DNSResolver) ParseDnsResponse(dns layers.DNS, pTs int64)

Parse the DNS response to find the requests and responses

func (*DNSResolver) ResolveIP

func (ts *DNSResolver) ResolveIP(ip net.IP) (ServiceMap, error)

Given an IP it returns the resolution address corresponding to the IP

func (*DNSResolver) Run

func (ts *DNSResolver) Run()

Run the listener on the incoming DNS packets to be analyzed

func (*DNSResolver) Stop

func (ts *DNSResolver) Stop()

Stop the DNS resolver

func (*DNSResolver) UpdateService

func (ts *DNSResolver) UpdateService(service ServiceConfiguration)

Updates the services when one service is added

func (*DNSResolver) UpdateServiceLookup

func (ts *DNSResolver) UpdateServiceLookup(dns layers.DNS, pTs int64)

Parse the DNS response to find the requests and responses and find all services associated to an IP

type Flags

type Flags struct {
	SYN bool
	ACK bool
	RST bool
	FIN bool
}

TCP Flags

type HopLatency

type HopLatency struct {
	Ip  string
	Rtt int64
}

Structure which contains the results

type InJson

type InJson struct {
	Services []Service
}

Json structure contained in the configuration file

type IpMap

type IpMap struct {
	Name     string
	Domain   string
	Type     uint8
	Expire   int64
	LastUsed int64
}

Map one IP to a specific service

type Listeners

type Listeners struct {
	DefaultBuffer     int
	DefaultCapSize    int
	DefaultDNSBuffer  int
	DefaultDNSCapSize int

	DefaultUDP  CapThread
	DefaultTCP  CapThread
	DefaultICMP CapThread
	DefaultDNS  CapThread
	// contains filtered or unexported fields
}

Class for managing the listeners of ServiceTracerouteManager It manages the sniffer for TCP, UDP, ICMP and DNS It is possible to use this class to start custom sniffers

func (*Listeners) NewListeners

func (listeners *Listeners) NewListeners(iface string, outChan chan string)

Configure a new instance of listeners

func (*Listeners) StartCustomizedListener

func (listeners *Listeners) StartCustomizedListener(cap CapThread, outPktChan chan gopacket.Packet)

Start a customized listener which is configured through the struct CapThread

func (*Listeners) StartDNS

func (listeners *Listeners) StartDNS(outPktChan chan gopacket.Packet)

Start a DNS sniffer with default values of Listeners. It relies on StartCustomizedListener to start a new sniffer

func (*Listeners) StartICMP

func (listeners *Listeners) StartICMP(outPktChan chan gopacket.Packet)

Start a ICMP sniffer with default values of Listeners. It relies on StartCustomizedListener to start a new sniffer

func (*Listeners) StartTCP

func (listeners *Listeners) StartTCP(outPktChan chan gopacket.Packet)

Start a TCP sniffer with default values of Listeners. It relies on StartCustomizedListener to start a new sniffer

func (*Listeners) StartUDP

func (listeners *Listeners) StartUDP(outPktChan chan gopacket.Packet)

Start a UDP sniffer with default values of Listeners. It relies on StartCustomizedListener to start a new sniffer

func (*Listeners) StopCustomizedListener

func (listeners *Listeners) StopCustomizedListener(cap CapThread)

Stop and close a specific customized listener

func (*Listeners) StopDNS

func (listeners *Listeners) StopDNS()

Stop and close a DNS sniffer with default values of Listeners. It relies on StopCustomizedListener to start a new sniffer

func (*Listeners) StopTCP

func (listeners *Listeners) StopTCP()

Stop and close a TCP sniffer with default values of Listeners. It relies on StopCustomizedListener to start a new sniffer

func (*Listeners) StoptICMP

func (listeners *Listeners) StoptICMP()

Stop and close a ICMP sniffer with default values of Listeners. It relies on StopCustomizedListener to start a new sniffer

func (*Listeners) StoptUDP

func (listeners *Listeners) StoptUDP()

Stop and close a UDP sniffer with default values of Listeners. It relies on StopCustomizedListener to start a new sniffer

type OffsetInterval

type OffsetInterval struct {
	// contains filtered or unexported fields
}

Interval for Offsets [start, end)

type PcapHandler

type PcapHandler struct {
	BufferMb int
	SnapLen  int
	Port     uint16
	Filter   string
	Iface    string
	LocalV4  net.IP
	LocalV6  net.IP
	PktChan  chan gopacket.Packet
	OutChan  chan string
	DoneChan chan bool
	StopChan chan bool

	Handler *pcap.Handle

	Ready chan bool
}

Structure of the sniffer

func (*PcapHandler) NewPacketHandler

func (ph *PcapHandler) NewPacketHandler(cap CapThread, iface string, ip string, pktChan chan gopacket.Packet, outChan chan string, ready chan bool)

Initialize and configure a new sniffer

func (*PcapHandler) Run

func (ph *PcapHandler) Run()

Run the sniffer on a specific interface and the filters given in input during the initialization

func (*PcapHandler) Stop

func (ph *PcapHandler) Stop()

Stop the sniffer

type Receiver

type Receiver struct {
	PktChan              chan *gopacket.Packet
	LocalV4              net.IP
	LocalV6              net.IP
	SendStartChan        chan bool
	HasSentSend          bool
	StartWithEmptyPacket bool
	Curr                 CurrStatus
	OutChan              chan string
	FlowOutChan          chan CurrStatus
	FlowInChan           chan CurrStatus
	ProbeOutChan         chan CurrStatus
	ProbeInChan          chan CurrStatus

	StopChan chan bool
	DoneChan chan bool
}

Structure to decode incoming packets

func (*Receiver) GetHardwareAddresses

func (r *Receiver) GetHardwareAddresses(pkt *gopacket.Packet)

Parse the Hardware addresses from the ethernet layer

func (*Receiver) IsProbePacket

func (r *Receiver) IsProbePacket() bool

Return if the last packet is a probe or not

func (*Receiver) NewReceiver

func (r *Receiver) NewReceiver(pktChan chan *gopacket.Packet, startWithEmptyPacket bool, hostV4 net.IP, hostV6 net.IP, outChan chan string)

Initialize and configure a new receiver

func (*Receiver) ParseIcmpLayer

func (r *Receiver) ParseIcmpLayer(pkt *gopacket.Packet) error

Parse ICMP layer (supported only IPv4)

func (*Receiver) ParseIpLayer

func (r *Receiver) ParseIpLayer(pkt *gopacket.Packet) error

Parse the IP layer

func (*Receiver) ParseTcpIn

func (r *Receiver) ParseTcpIn(pkt *gopacket.Packet, tcp *layers.TCP)

Parse the incoming TCP packet

func (*Receiver) ParseTcpLayer

func (r *Receiver) ParseTcpLayer(pkt *gopacket.Packet) error

Parse the TCP layer

func (*Receiver) ParseTcpOut

func (r *Receiver) ParseTcpOut(pkt *gopacket.Packet, tcp *layers.TCP)

Parse the outgoing TCP packet

func (*Receiver) ParseUdpIn

func (r *Receiver) ParseUdpIn(pkt *gopacket.Packet, udp *layers.UDP)

Parse incoming UDP packet

func (*Receiver) ParseUdpLayer

func (r *Receiver) ParseUdpLayer(pkt *gopacket.Packet) error

Parse UDP layer

func (*Receiver) ParseUdpOut

func (r *Receiver) ParseUdpOut(pkt *gopacket.Packet, udp *layers.UDP)

Parse outgoing UDP packet

func (*Receiver) Run

func (r *Receiver) Run()

Start listening on the channel for packets to be parsed and sent to traceroute for the analysis

func (*Receiver) Stop

func (r *Receiver) Stop()

Stop the receiver

type Sender

type Sender struct {
	Iface   string
	SendQ   chan []byte
	OutChan chan string

	StopChan chan bool
	DoneChan chan bool
}

Structure for sending packets to the interface

func (*Sender) NewSender

func (s *Sender) NewSender(iface string, outChan chan string)

Initialize and configure a new sender

func (*Sender) Run

func (s *Sender) Run()

Run a listener for packets to be transmitted

func (*Sender) Stop

func (s *Sender) Stop()

type Service

type Service struct {
	Name          string
	DomainsString []string
	DomainsRegex  []string
	ServiceType   uint8
	StringMatch   *AhoCorasick
	Regexps       []*regexp.Regexp
	CNames        map[string]CName
	Prefixes      []string
	PrefixNets    []*net.IPNet
}

Structure to identify the DNS request to one service

type ServiceConfiguration

type ServiceConfiguration struct {
	Service              string //Name of the service. If existing the input.conf, it can be used without IPs or URLs to identify automatically a specific service
	ServiceType          uint8  //Id of the service type.
	ConfHash             string //Set externally to identify the results
	Distance             int    //Maximum distance to probe
	Iterations           int    //Number of packets per hop
	InterProbeTime       int    //Time to wait between each probe
	InterIterationTime   int    //Time to wait between each iteration
	Timeout              int    //Timeout (milliseconds)
	FlowTimeout          int    //Timeout to consider a flow dead (milliseconds)
	ProbingAlgorithm     string //Spacify the probing algorithm to use. 0 to send 1 packet at the time. 1 to send 1 train of packet (same TTL) at the time. 2 to send all packets without waiting for the reply, only to wait the timeout at the end. If different, 0 will be used as default
	StartWithEmptyPacket bool   //Flag to specify whether ServiceTraceroute has to start when an empty ack is received. ServiceTraceroute always starts with ACK with payload
	StopOnBorderRouters  bool   //Flag to specify to stop when Service Traceroute detects a border router

	IPPrefixes []string //IP Prefixes appartaining to the service
	URLs       []string //URLs appartaining to the service
}

type ServiceMap

type ServiceMap struct {
	Names         []string
	IPResolutions []string
	Expire        int64
	LastUsed      int64
}

Map one IP to a set of services with the relative resolution address

type ServiceTraceroute

type ServiceTraceroute struct {
	//The input configuration of Service Traceroute
	Configuration ServiceTracerouteConfiguration
	//Receiver and analyser of the input packets
	Receiver   *Receiver
	Traceroute *BufferTrace

	//Queue containing the sniffed pacets
	SniffChannel chan *gopacket.Packet

	//Messages to be printed/stored
	OutChan chan string

	//Packets to be transmitted
	OutPacketsChan chan []byte

	//Notify when it finishes
	DoneChan chan bool
}

Struct which contains the required objects to run ServiceTraceroute This struct is associated to only one traceroute

func (*ServiceTraceroute) GetDistance

func (tt *ServiceTraceroute) GetDistance() int

Get the maximum distance to probe

func (*ServiceTraceroute) GetIDOffset

func (tt *ServiceTraceroute) GetIDOffset() uint16

Get the IPID offset

func (*ServiceTraceroute) GetIterations

func (tt *ServiceTraceroute) GetIterations() int

Get the number of probes per TTL

func (*ServiceTraceroute) GetProbingAlgorithm

func (tt *ServiceTraceroute) GetProbingAlgorithm() string

Get the probing algorithm

func (*ServiceTraceroute) NewConfiguredServiceTraceroute

func (tt *ServiceTraceroute) NewConfiguredServiceTraceroute(configuration ServiceTracerouteConfiguration)

Start Service Traceroute with the given configuration If the given configuration contains the wrong probing algorithm, the Service Traceroute use PacketByPacket as default algorithm

func (*ServiceTraceroute) NewDefaultServiceTraceroute

func (tt *ServiceTraceroute) NewDefaultServiceTraceroute(transportProtocol string, remoteIP net.IP, localIPv4 net.IP, localIPv6 net.IP, remotePort int, iface string, outchan chan string)

Start Service Traceroute with default parameters

func (*ServiceTraceroute) Run

Start a traceroute towards for a specific application flow given during the initialization of the object

func (*ServiceTraceroute) SetBorderIPs

func (tt *ServiceTraceroute) SetBorderIPs(borderIPs []net.IP)

Set the border routers for a specific traceroute

func (*ServiceTraceroute) SetDistance

func (tt *ServiceTraceroute) SetDistance(distance int)

Set the maximum distance to probe

func (*ServiceTraceroute) SetFlowTimeout

func (tt *ServiceTraceroute) SetFlowTimeout(timeout int)

Set the idle time to consider a flow as closed [ms]

func (*ServiceTraceroute) SetIDOffset

func (tt *ServiceTraceroute) SetIDOffset(idOffset uint16)

Set the IPID offset (to enable multiple traceroutes)

func (*ServiceTraceroute) SetIPv4

func (tt *ServiceTraceroute) SetIPv4()

Set the IP version to 4

func (*ServiceTraceroute) SetIPv6

func (tt *ServiceTraceroute) SetIPv6()

Set the IP version to 6 (it is not fully implemented)

func (*ServiceTraceroute) SetInterIterationTime

func (tt *ServiceTraceroute) SetInterIterationTime(interIterationTime int)

Set the time to wait between each pair of TTL [us]

func (*ServiceTraceroute) SetInterProbeTime

func (tt *ServiceTraceroute) SetInterProbeTime(interProbeTime int)

Set the time to wait between each pair of probe [us]

func (*ServiceTraceroute) SetInterface

func (tt *ServiceTraceroute) SetInterface(iface string)

Set the interface to use of the machine running Service Traceroute

func (*ServiceTraceroute) SetIterations

func (tt *ServiceTraceroute) SetIterations(iterations int)

Set the number of probes per TTL

func (*ServiceTraceroute) SetLocalIPv4

func (tt *ServiceTraceroute) SetLocalIPv4(localIPv4 net.IP)

Set the IPv4 of the machine running Service Traceroute

func (*ServiceTraceroute) SetLocalIPv6

func (tt *ServiceTraceroute) SetLocalIPv6(localIPv6 net.IP)

Set the IPv6 of the machine running Service Traceroute

func (*ServiceTraceroute) SetLocalPort

func (tt *ServiceTraceroute) SetLocalPort(localPort int)

Set the port of the the machine running Service Traceroute of a specific application flow

func (*ServiceTraceroute) SetOutPacketsChan

func (tt *ServiceTraceroute) SetOutPacketsChan(outPacketsChan chan []byte)

Set the channel for the packets to be transmitted

func (*ServiceTraceroute) SetProbingAlgorithm

func (tt *ServiceTraceroute) SetProbingAlgorithm(probingAlgorithm string)

Set the probing algorithm

func (*ServiceTraceroute) SetRemoteIP

func (tt *ServiceTraceroute) SetRemoteIP(remoteIP net.IP)

Set the IPv4 of the other end host of a specific application flow

func (*ServiceTraceroute) SetRemotePort

func (tt *ServiceTraceroute) SetRemotePort(remotePort int)

Set the port of the other end host of a specific application flow

func (*ServiceTraceroute) SetService

func (tt *ServiceTraceroute) SetService(service string)

Set the service associated to this traceroute

func (*ServiceTraceroute) SetStartWithEmptyPacket

func (tt *ServiceTraceroute) SetStartWithEmptyPacket(start bool)

Set whether the traceroute should start only when data is exchanged (=packets with payload) or also with empty packets

func (*ServiceTraceroute) SetStdOutChan

func (tt *ServiceTraceroute) SetStdOutChan(outchan chan string)

Set the channel for the standard output

func (*ServiceTraceroute) SetTimeout

func (tt *ServiceTraceroute) SetTimeout(timeout int)

Set the timeout for considering a probe lost [ms]

type ServiceTracerouteConfiguration

type ServiceTracerouteConfiguration struct {
	TransportProtocol         string   //Type of protocol to probe. UDP or TCP
	ConfHash                  string   //Hash to identify a specific traceroute. Given externally by who uses the library
	Service                   string   //Type of service of the remote IP
	IPResolution              string   //Resolution name of the remote IP
	LocalIPv4                 net.IP   //IPv4 of the local machine
	LocalIPv6                 net.IP   //IPv6 of the local machine
	RemoteIP                  net.IP   //IP of the remote target end host
	RemotePort                int      //Port of the remote target end host
	LocalPort                 int      //Port of the local end host
	Interface                 string   //Interface used to transmit packets
	Distance                  int      //Max TTL to reach (from 1 to Distance included ?)
	BorderIPs                 []net.IP //Set of IPs that, if encountered, will stop ServiceTraceroute
	Iterations                int      //Number of probes for each TTL
	InterProbeTime            int      //Time to wait between each probe
	InterIterationTime        int      //Time to wait between each iteration
	IPVersion                 string   //IP Version
	Timeout                   int      //Timeout (milliseconds)
	IDOffset                  uint16   //Offset for the IP ID field in order to allow parallelisation without interference with running ServiceTraceroutes
	ProbingAlgorithm          string   //Spacify the probing algorithm to use. 0 to send 1 packet at the time. 1 to send 1 train of packet (same TTL) at the time. 2 to send all packets without waiting for the reply, only to wait the timeout at the end. If different, 0 will be used as default
	StartWithEmptyPacket      bool     //Flag to specify whether ServiceTraceroute has to start when an empty ack is received. ServiceTraceroute always starts with ACK with payload
	FlowTimeout               int      //Time required to consider a flow dead
	MaxConsecutiveMissingHops int      //Set how many missing hops (stars *) are required before ending traceroute

	StartTraceroutes bool //Debug, stop immediately the traceroute
}

Configuration to run ServiceTraceroute

type ServiceTracerouteInfo

type ServiceTracerouteInfo struct {
	Version string
	Conf    string
	Type    string
}

One part of the Json output Version - the version of the tool Conf - a string that can be associated to a specific traceroute Type - the tool which generated the output

type ServiceTracerouteJson

type ServiceTracerouteJson struct {
	Info ServiceTracerouteInfo
	Data ServiceTracerouteReport
}

Main structure of the Json output Info - contains the info about the tool Data - contains all the data about the traceroute

type ServiceTracerouteLog

type ServiceTracerouteLog struct {
	Report        ServiceTracerouteJson          //Final report, if traceTCP completed
	Configuration ServiceTracerouteConfiguration //Configuration used for ServiceTraceroute

	IsRunning  bool  //Flag to specify if it is running or not
	StartedAt  int64 //When ServiceTraceroute started
	FinishedAt int64 //When ServiceTraceroute finished (if not, then it is negative)
}

Log of ServiceTraceroute which will be stored in the map

type ServiceTracerouteManager

type ServiceTracerouteManager struct {
	RunningServiceTraceroutes map[string]*ServiceTraceroute //Contains all running experiments
	AvailableOffsets          []OffsetInterval              //ID intervals available for new ServiceTraceroutes

	//Configuration
	Configuration ServiceTracerouteManagerConfiguration //Configuration of ServiceTraceroute

	//Input Channels (captured packets)
	TCPChan  chan gopacket.Packet //Input channel for TCP packets to be forwarded to ServiceTraceroute
	UDPChan  chan gopacket.Packet //Input channel for UDP packets to be forwarded to ServiceTraceroute
	ICMPChan chan gopacket.Packet //Input channel for ICMP packets to be forwarded to ServiceTraceroute
	DNSChan  chan gopacket.Packet //Input channel for DNS packets to be forwarded to ServiceTraceroute

	//Output Channels
	OutPacketChan chan []byte                //packets to be transmitted
	OutChan       chan string                //data to be printed/stored
	OutResultChan chan ServiceTracerouteJson //results to show

	//Channel to stop ServiceTracerouteManager
	StopChan chan bool //To stop the manager

	//DNS resolver
	DNS *DNSResolver

	//Packet Listeners
	Listeners *Listeners

	//Packet Sender
	Sender *Sender

	//Local IPs
	LocalIPv4 net.IP //Local IPv4 of the machine running this library
	LocalIPv6 net.IP //Local IPv6 of the machine running this library

	//Results
	LogsMap    map[string]ServiceTracerouteLog //Contains the running experiments and the results of those finished in the last 3 minutes
	LogsMapTTL int64                           //time to live for data in logs map when the experiment is finished
	// contains filtered or unexported fields
}

Main struct for the manager of multiple ServiceTraceroute

func (*ServiceTracerouteManager) AddBorderRouters

func (tm *ServiceTracerouteManager) AddBorderRouters(borderIPs ...net.IP)

Add one or an array of border routers

func (*ServiceTracerouteManager) AddService

func (tm *ServiceTracerouteManager) AddService(service ServiceConfiguration)

Add a service to the set of services for the automatic traceroutes

func (*ServiceTracerouteManager) AssignFlowIDToTraceroute

func (tm *ServiceTracerouteManager) AssignFlowIDToTraceroute(ip1 net.IP, port1 int, ip2 net.IP, port2 int) *ServiceTraceroute

At the beginning a Traceroute may not have the complete application flow ID This function fixes the flow ID of the traceroute when it is incomplete

func (*ServiceTracerouteManager) CheckAndAddServiceTracerouteExperiment

func (tm *ServiceTracerouteManager) CheckAndAddServiceTracerouteExperiment(st *ServiceTraceroute) bool

Check if there is an already running experiments If not, it adds the given ServiceTraceroute into the list of running experiments

func (*ServiceTracerouteManager) CheckExistanceServiceTracerouteExperiment

func (tm *ServiceTracerouteManager) CheckExistanceServiceTracerouteExperiment(protocol string, remoteIp net.IP, remotePort int, localPort int) bool

Check if there is an already running traceroute However, if it says that there are no traceTCP to the remoteIP, it may happen that a new experiment may be added immediately after it.

func (*ServiceTracerouteManager) ClearLogsMap

func (tm *ServiceTracerouteManager) ClearLogsMap()

Remove all expired logs

func (*ServiceTracerouteManager) ConvertPort

func (tm *ServiceTracerouteManager) ConvertPort(port string) int

Convert a port from string to int (in some cases it may contain some text)

func (*ServiceTracerouteManager) DecodeICMPIP

func (tm *ServiceTracerouteManager) DecodeICMPIP(payload []byte) (net.IP, net.IP, string, int, error)

Decode the ICMP payload to return the IP addresses, the protocol and header length of the dropped packet

func (*ServiceTracerouteManager) DecodeICMPTCP

func (tm *ServiceTracerouteManager) DecodeICMPTCP(payload []byte, HL int) (int, int, error)

Return source and destination port contained in the ICMP payload (TCP packet)

func (*ServiceTracerouteManager) DecodeICMPUDP

func (tm *ServiceTracerouteManager) DecodeICMPUDP(payload []byte, HL int) (int, int, error)

Return source and destination port contained in the ICMP payload (UDP packet)

func (*ServiceTracerouteManager) FreeInterval

func (tm *ServiceTracerouteManager) FreeInterval(offsetInterval OffsetInterval)

Free an used interval and put it into AvailableOffsets

func (*ServiceTracerouteManager) GetBorderRouters

func (tm *ServiceTracerouteManager) GetBorderRouters() []net.IP

Return the list of border routers

func (*ServiceTracerouteManager) GetFlowIDFromICMPPacket

func (tm *ServiceTracerouteManager) GetFlowIDFromICMPPacket(icmpPacket *gopacket.Packet) (net.IP, int, net.IP, int, error)

Return the final destination of traceTCP probe from the payload of ICMP

func (*ServiceTracerouteManager) GetFlowIDFromTCPPacket

func (tm *ServiceTracerouteManager) GetFlowIDFromTCPPacket(tcpPacket *gopacket.Packet) (net.IP, int, net.IP, int, error)

Get the Flow ID from a TCP packet

func (*ServiceTracerouteManager) GetFlowIDFromUDPPacket

func (tm *ServiceTracerouteManager) GetFlowIDFromUDPPacket(udpPacket *gopacket.Packet) (net.IP, int, net.IP, int, error)

Get the Flow Id from an UDP packet

func (*ServiceTracerouteManager) GetICMPInChan

func (tm *ServiceTracerouteManager) GetICMPInChan() chan gopacket.Packet

Get the channel used for the sniffing ICMP packets

func (*ServiceTracerouteManager) GetIPIDFromICMPPacket

func (tm *ServiceTracerouteManager) GetIPIDFromICMPPacket(icmpPacket *gopacket.Packet) (uint16, error)

Return the IPID contained in the ICMP payload

func (*ServiceTracerouteManager) GetLog

func (tm *ServiceTracerouteManager) GetLog(protocol string, remoteIp string, remotePort int, localPort int) (ServiceTracerouteLog, error)

Return the log of a traceroute for a specific application flow

func (*ServiceTracerouteManager) GetMapKey

func (tm *ServiceTracerouteManager) GetMapKey(protocol string, remoteIp net.IP, remotePort int, localPort int) string

Convert the application flows 5-tuple into a key for identifying the traceroutes

func (*ServiceTracerouteManager) GetNumberOfRunningServiceTraceroute

func (tm *ServiceTracerouteManager) GetNumberOfRunningServiceTraceroute() int

Return the number of running ServiceTraceroute

func (*ServiceTracerouteManager) GetOutChan

func (tm *ServiceTracerouteManager) GetOutChan() chan string

Return the used stdout channel

func (*ServiceTracerouteManager) GetOutPktsChan

func (tm *ServiceTracerouteManager) GetOutPktsChan() chan []byte

Get the channel used for the transmission of packets

func (*ServiceTracerouteManager) GetTCPInChan

func (tm *ServiceTracerouteManager) GetTCPInChan() chan gopacket.Packet

Get the channel used for the sniffing TCP packets

func (*ServiceTracerouteManager) GetTracerouteFromFlowID

func (tm *ServiceTracerouteManager) GetTracerouteFromFlowID(ip1 net.IP, port1 int, ip2 net.IP, port2 int) *ServiceTraceroute

GetServiceTracerouteExperimentFromFlowID return the ServiceTraceroute where remoteIP and remotePort matches one of 2 pairs given as input (where one is local end host and the other is the remote one)

func (*ServiceTracerouteManager) GetTracerouteFromIPID

func (tm *ServiceTracerouteManager) GetTracerouteFromIPID(id uint16) *ServiceTraceroute

Return ServiceTraceroute which contains the input IP ID

func (*ServiceTracerouteManager) GetUDPInChan

func (tm *ServiceTracerouteManager) GetUDPInChan() chan gopacket.Packet

Get the channel used for the sniffing UDP packets

func (*ServiceTracerouteManager) LoadBorderRouters

func (tm *ServiceTracerouteManager) LoadBorderRouters(filename string) error

Load border routers from a file

func (*ServiceTracerouteManager) NewServiceTracerouteManager

func (tm *ServiceTracerouteManager) NewServiceTracerouteManager(iface string, ipVersion string, parallelProbesPerDestination bool, parallelProbesPerDstPort bool, startSniffer bool, startSender bool, startDNSResolver bool, startTraceroutes bool, interTraceTime int, maxConsecutiveMissingHops int, borderRouters []net.IP, outChan chan string, outResultsChan chan ServiceTracerouteJson) error

NewServiceTracerouteManager initialize the manager of multiple ServiceTraceroute experiments iface string: is the name of the interface. It must be set ipVersion string: is the version of the IP layer ('4' or '6'). Use the const V4 or V6 borderRouters []net.IP: are the IPs of the border routers, where ServiceTraceroute will stop. It can be nil if not used return error: nil if no error happened during the initialization

func (*ServiceTracerouteManager) RemoveLogsMap

func (tm *ServiceTracerouteManager) RemoveLogsMap(log ServiceTracerouteLog) error

Remove a given log from the map

func (*ServiceTracerouteManager) RemoveService

func (tm *ServiceTracerouteManager) RemoveService(service ServiceConfiguration)

Remove one service from the set of services for the automatic traceroutes

func (*ServiceTracerouteManager) RemoveServiceTracerouteExperiment

func (tm *ServiceTracerouteManager) RemoveServiceTracerouteExperiment(st *ServiceTraceroute)

Remove the input st from the array of running experiments

func (*ServiceTracerouteManager) Run

func (tm *ServiceTracerouteManager) Run()

Start the multiplexer for input packets. It forwards the input packets to the correct traceroute

func (*ServiceTracerouteManager) SetBorderRouters

func (tm *ServiceTracerouteManager) SetBorderRouters(borderIPs []net.IP)

Set border routers

func (*ServiceTracerouteManager) SetICMPInChan

func (tm *ServiceTracerouteManager) SetICMPInChan(icmpChan chan gopacket.Packet)

Set the channel used for the sniffing ICMP packets

func (*ServiceTracerouteManager) SetLocalIPs

func (tm *ServiceTracerouteManager) SetLocalIPs() error

Set the local IPs taking the from the interface used by traceTCPmanager

func (*ServiceTracerouteManager) SetOutChan

func (tm *ServiceTracerouteManager) SetOutChan(outchan chan string)

Set the stdout channel

func (*ServiceTracerouteManager) SetOutPktsChan

func (tm *ServiceTracerouteManager) SetOutPktsChan(outPktsChan chan []byte)

Set the channel used for the transmission of packets

func (*ServiceTracerouteManager) SetServices

func (tm *ServiceTracerouteManager) SetServices(services []ServiceConfiguration)

Set the services to start automatically traceroute

func (*ServiceTracerouteManager) SetStartNewTraceroutes

func (tm *ServiceTracerouteManager) SetStartNewTraceroutes(newTraceroutes bool)

Set the flag to start new traceroute. Used if the goal is to stop new traceroutes for a while

func (*ServiceTracerouteManager) SetTCPInChan

func (tm *ServiceTracerouteManager) SetTCPInChan(tcpChan chan gopacket.Packet)

Set the channel used for the sniffing TCP packets

func (*ServiceTracerouteManager) SetUDPInChan

func (tm *ServiceTracerouteManager) SetUDPInChan(udpChan chan gopacket.Packet)

Set the channel used for the sniffing UDP packets

func (*ServiceTracerouteManager) SetVerbose

func (tm *ServiceTracerouteManager) SetVerbose(verbose bool)

Set verbose flag

func (*ServiceTracerouteManager) StartDNSResolver

func (tm *ServiceTracerouteManager) StartDNSResolver(dnsChan chan gopacket.Packet) error

Start the DNS resolution using an external channel

func (*ServiceTracerouteManager) StartServiceTraceroute

func (tm *ServiceTracerouteManager) StartServiceTraceroute(transportProtocol string, services []string, ipresolutions []string, dstIp net.IP, dstPort int, localPort int)

Start a traceceroute to a specific service if the given service is in the list of services to be analyzed

func (*ServiceTracerouteManager) StartTraceroute

func (tm *ServiceTracerouteManager) StartTraceroute(transportProtocol string, remoteIP net.IP, remotePort int, localPort int, service string, ipresolution string, maxDistance int, numberIterations int, timeout int, flowTimeout int, interProbeTime int, interIterationTime int, probingAlgorithm string, stopWithBorderRouters bool, startWithEmptyPacket bool, maxConsecutiveMissingHops int) error

Open a new traceroute It must run on a thread, otherwise it locks the thread until the end If there is no space (i.e. no available offset spot), return error At the end of the run it will return the report through the outResultChan The new traceroute can start only if: - StartAnalysis is true (default) - There aren't any other traceroute for the same application flow - The results are expired in the log (depends by the time) - The IP versions are correct

func (*ServiceTracerouteManager) Stop

func (tm *ServiceTracerouteManager) Stop()

Stop the multiplexer (Run() function)

func (*ServiceTracerouteManager) StopDNSResolver

func (tm *ServiceTracerouteManager) StopDNSResolver()

Stop the DNS resolution

func (*ServiceTracerouteManager) SwitchLogsKey

func (tm *ServiceTracerouteManager) SwitchLogsKey(key string, oldkey string) error

Change the key corresponding to a specific log

func (*ServiceTracerouteManager) SwitchTracerouteKeys

func (tm *ServiceTracerouteManager) SwitchTracerouteKeys(key string, oldkey string)

Change the ID (key) identifying a traceroute

func (*ServiceTracerouteManager) UpdateLogsMap

func (tm *ServiceTracerouteManager) UpdateLogsMap(log ServiceTracerouteLog) error

Remove old logs and add/update the input log

func (*ServiceTracerouteManager) UseInterval

func (tm *ServiceTracerouteManager) UseInterval(size int) (OffsetInterval, error)

Find the interval which fits for the given interval size Remove spot from the available spots in AvailableOffsets

type ServiceTracerouteManagerConfiguration

type ServiceTracerouteManagerConfiguration struct {
	Interface string                 //Interface used to listen/send packets
	BorderIPs []net.IP               //Router where traceTCP will stop (if flag is set to True)
	Services  []ServiceConfiguration //Services to trace
	IPVersion string                 //IP version

	Sniffer     bool //True for auto sniffing from library
	DNSResolver bool //True for using DNS Service detection
	Sender      bool //True to send automatically packets

	DestinationMultipleProbing bool //To start multiple probing towards the same destination
	PortMultipleProbing        bool //To start multiple probing towards the same destination port

	MaxConsecutiveMissingHops int //Maximum number of missing hops (= no replyies to all probes) are required before stopping traceroute

	DNSResolverConfFile string //Filename containing configuration of the dns resolver

	//Debug
	StartTraceroutes bool //To only obtain the IPs of the server that would have been analysed
	Verbose          bool
	StartAnalysis    bool //Specify if ServiceTraceroute can start new traceroutes or not
}

Configuration of ServiceTraceroute Manager

type ServiceTracerouteReport

type ServiceTracerouteReport struct {
	TransportProtocol string    //Transport protocol that was used during the traceroute. UDP or TCP
	TargetIP          string    //The target IP to reach
	TargetPort        int       //The port of the target IP appartaining at the target application flow
	LocalIP           string    //IP of the host running the traceroute
	LocalPort         int       //Port of the host appartaining at target application flow
	Service           string    //Name of the service
	IPResolution      string    //Corresponding resolution name used to detect the application flow
	Hops              []string  //IP for each hop
	RttsAvg           []float64 //RTT AVG for each hop
	RttsVar           []float64 //RTT VAR for each hop (if >1 iterations)

	MaxTtl         int //Maximum TTL to reach
	BorderDistance int //Distance reached by the tool during the probing phase. It depends on border routers, lifetime of the application flow or when there are consecutive non replying hops
	Iterations     int //Number of probes per hop

	MaxConsecutiveMissingHops        int  //Maximum number of consecutive non replying hops before considering the flow and completed
	ReachedMaxConsecutiveMissingHops bool //Flag to specify if the traceroute was stopped by the maximum number of consecutive non replying hops

	ProbingAlgorithm     string //The type of probing algorithm used during the traceroute
	StartWithEmptyPacket bool   //Whether Service Traceroute can start when it detects an empty packet or a packet with transport payload

	InterProbeTime     int //Time between each probe in [us]
	InterIterationTime int //Time between each iteration of TTL [us]

	Timeout            int  //The maximum time to wait before considering a packet as lost
	FlowTimeout        int  //The maximum idle time to consider a flow as dead
	ReachedFlowTimeout bool //Flag to specify if the application flow is considered dead due to inactivity (in case no RST or FIN packets are exchanged)
	FlowEnded          bool //Flag to specify if the application flow was closed with RST or FIN

	ReachedBorderRouter bool //Flag to specify if Service Traceroute reached a border router

	TsStart int64 //Timestamp of the start of the traceroute
	TsEnd   int64 //Timestamp of the end of the traceroute

	HopIPs [][]string  //Full list of received IPs
	Rtts   [][]float64 //Full list of RTTs
}

Contains all information and results about traceroute

type State

type State struct {
	Id         int
	Char       rune
	NextStates map[rune]int
}

func (*State) NewState

func (s *State) NewState(id int, char rune)

Jump to

Keyboard shortcuts

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