triggers

package
v0.0.0-...-c1fdb11 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package triggers enumerates all of the various triggers that can be used to match packets.

See the top-level documentation for more details.

Index

Examples

Constants

View Source
const (
	IPFieldVersion = iota
	IPFieldIHL
	IPFieldTOS
	IPFieldLength
	IPFieldIdentification
	IPFieldFlags
	IPFieldFragmentOffset
	IPFieldTTL
	IPFieldProtocol
	IPFieldChecksum
	IPFieldSourceAddress
	IPFieldDestAddress
	IPFieldPayload
)
View Source
const (
	TCPFieldSourcePort = iota
	TCPFieldDestPort
	TCPFieldSeq
	TCPFieldAck
	TCPFieldDataOffset
	TCPFieldReserved
	TCPFieldFlags
	TCPFieldWindow
	TCPFieldChecksum
	TCPFieldUrgentPointer
	TCPFieldPayload
	TCPFieldOptionEOL
	TCPFieldOptionNOP
	TCPFieldOptionMSS
	TCPFieldOptionWScale
	TCPFieldOptionSackOk
	TCPFieldOptionSack
	TCPFieldOptionTimestamp
	TCPFieldOptionAltChecksum
	TCPFieldOptionAltChecksumOpt
	TCPFieldOptionMD5Header
	TCPFieldOptionUTO
)

Variables

View Source
var ErrUnsupportedOption = errors.New("unsupported option")

ErrUnsupportedOption is returned when an unsupported TCP option is specified in a trigger rule.

Functions

func IPFields

func IPFields() map[IPField]string

IPFields returns a list of the fields supported by the IP trigger.

func TCPFields

func TCPFields() map[TCPField]string

TCPFields returns a list of the fields supported by the TCP trigger.

Types

type IPField

type IPField int

IPField is the type of a supported IP field.

func ParseIPField

func ParseIPField(field string) (IPField, error)

ParseIPField parses a field name and returns an IPField, or an error if the field is not supported.

type IPTrigger

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

IPTrigger is a Trigger that matches on the IP layer.

func NewIPTrigger

func NewIPTrigger(field, value string, gas int) (*IPTrigger, error)

NewIPTrigger creates a new IP trigger.

Example
package main

import (
	"fmt"

	"github.com/getlantern/geneva/triggers"
)

func main() {
	t, _ := triggers.NewIPTrigger("ttl", "64", 0)

	fmt.Printf("%s", t)
}
Output:

[IP:ttl:64]

func (*IPTrigger) Field

func (t *IPTrigger) Field() string

Field is an IP-specific field name used by this trigger.

func (*IPTrigger) Gas

func (t *IPTrigger) Gas() int

Gas denotes how many times this trigger can fire before it stops triggering.

func (*IPTrigger) Matches

func (t *IPTrigger) Matches(pkt gopacket.Packet) (bool, error)

Matches returns whether the trigger matches the packet.

func (*IPTrigger) Protocol

func (t *IPTrigger) Protocol() string

Protocol is the protocol that this trigger can act upon.

func (*IPTrigger) String

func (t *IPTrigger) String() string

String returns a string representation of this trigger.

type TCPField

type TCPField int

TCPField is the type of a supported TCP field.

func ParseTCPField

func ParseTCPField(field string) (TCPField, error)

ParseTCPField parses a field name and returns an TCPField, or an error if the field is not supported.

type TCPTrigger

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

TCPTrigger is a Trigger that matches on the TCP layer.

func NewTCPTrigger

func NewTCPTrigger(field, value string, gas int) (*TCPTrigger, error)

NewTCPTrigger creates a new TCP trigger.

Example
package main

import (
	"fmt"

	"github.com/getlantern/geneva/triggers"
)

func main() {
	t, _ := triggers.NewTCPTrigger("flags", "SA", 0)

	fmt.Printf("%s", t)
}
Output:

[TCP:flags:SA]

func (*TCPTrigger) Field

func (t *TCPTrigger) Field() string

Field is an TCP-specific field name used by this trigger.

func (*TCPTrigger) Gas

func (t *TCPTrigger) Gas() int

Gas denotes how many times this trigger can fire before it stops triggering.

func (*TCPTrigger) Matches

func (t *TCPTrigger) Matches(pkt gopacket.Packet) (bool, error)

Matches returns whether the trigger matches the packet.

func (*TCPTrigger) Protocol

func (t *TCPTrigger) Protocol() string

Protocol is the protocol that this trigger can act upon.

func (*TCPTrigger) String

func (t *TCPTrigger) String() string

String returns a string representation of this trigger.

type Trigger

type Trigger interface {
	// Protocol is the protocol that a trigger can act upon.
	Protocol() string
	// Field is a protocol-specific field name.
	Field() string
	// Gas denotes how many times this trigger can fire before it stops triggering.
	Gas() int
	// Matches returns whether the trigger matches the packet.
	Matches(gopacket.Packet) (bool, error)
	fmt.Stringer
}

Trigger is implemented by any value that describes a Geneva trigger.

func ParseTrigger

func ParseTrigger(s *scanner.Scanner) (Trigger, error)

ParseTrigger parses a string representation of a trigger into the actual Trigger object.

If the string is malformed, an error will be returned instead.

Jump to

Keyboard shortcuts

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