gofilter

package module
v0.0.0-...-3a865ac Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

RE2-Gofilter

RE2-Gofilter is a Go implementation of the Wireshark display filter for type Message (map[string]interface{}).

Yacc and Ragel are used for filter parser.

Installation
go get github.com/PHYLAXIS-NET/re2-gofilter

Filter syntax

Comparison operators
eq, ==    Equal
ne, !=    Not Equal
gt, >     Greater Than
lt, <     Less Than
ge, >=    Greater than or Equal to
le, <=    Less than or Equal to
Search and match operators
contains  Does the protocol, field or slice contain a value
matches   Does the protocol or text string match the given Perl
          regular expression
Logical expressions
and, &&   Logical AND
or,  ||   Logical OR
not, !    Logical NOT
Unsupported features

Functions to convert strings:

upper(string-field) - converts a string field to uppercase
lower(string-field) - converts a string field to lowercase

The slice operator:

eth.src[0:3] == 00:00:83

Bit field operations:

bitwise_and, & - Bitwise AND
Fields type
FT_BOOL   ftenum = iota // bool
FT_STRING ftenum = iota // string
FT_INT    ftenum = iota // int
FT_UINT   ftenum = iota // uint

FT_UINT8  ftenum = iota // uint8
FT_UINT16 ftenum = iota // uint16
FT_UINT24 ftenum = iota // uint24
FT_UINT32 ftenum = iota // uint32
FT_UINT64 ftenum = iota // uint64
FT_INT8   ftenum = iota // int8
FT_INT16  ftenum = iota // int16
FT_INT24  ftenum = iota // int24
FT_INT32  ftenum = iota // int32
FT_INT64  ftenum = iota // int64

FT_FLOAT32 ftenum = iota // float32
FT_FLOAT64 ftenum = iota // float64

FT_BYTES ftenum = iota // []byte

FT_IP  ftenum = iota // net.IP
FT_MAC ftenum = iota // net.HardwareAddr

Usage example

package main

import (
	"fmt"
	"github.com/PHYLAXIS-NET/re2-gofilter"
	"net"
)

func main() {
	gofilter.RegisterField("ip.src", gofilter.FT_IP)
	gofilter.RegisterField("ip.dst", gofilter.FT_IP)

	f, err := gofilter.NewFilter("ip.src == 192.168.0.0/24 and ip.dst == 192.168.0.1")
	if err != nil {
		fmt.Printf("Filter parse error: %s", err)
	}

	msg := gofilter.Message{
		"ip.src": net.ParseIP("192.168.0.100"),
		"ip.dst": net.ParseIP("192.168.0.1"),
	}

	if f.Apply(msg) {
		fmt.Println("Message pass")
	} else {
		fmt.Println("Message not pass")
	}
}

Documentation

Overview

Package gofilter provides implementation of Wireshark display filter.

Index

Constants

View Source
const (
	FT_BOOL   ftenum = iota // bool
	FT_STRING ftenum = iota // string
	FT_INT    ftenum = iota // int
	FT_UINT   ftenum = iota // uint

	FT_UINT8  ftenum = iota // uint8
	FT_UINT16 ftenum = iota // uint16
	FT_UINT24 ftenum = iota // uint24
	FT_UINT32 ftenum = iota // uint32
	FT_UINT64 ftenum = iota // uint64
	FT_INT8   ftenum = iota // int8
	FT_INT16  ftenum = iota // int16
	FT_INT24  ftenum = iota // int24
	FT_INT32  ftenum = iota // int32
	FT_INT64  ftenum = iota // int64

	FT_FLOAT32 ftenum = iota // float32
	FT_FLOAT64 ftenum = iota // float64

	FT_BYTES ftenum = iota // []byte

	FT_IP  ftenum = iota // net.IP
	FT_MAC ftenum = iota // net.HardwareAddr

)

Lis of available field types

Variables

View Source
var ErrFieldExist = errors.New("Field is already registered")

Functions

func RegisterField

func RegisterField(name string, f_type ftenum) error

RegisterField adds field with name and f_type to known fields. When try to register field with name which was already registered return ErrFieldExist.

Types

type Filter

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

Filter stores parsed filter string.

func NewFilter

func NewFilter(str string) (*Filter, error)

Create new filter

func (*Filter) Apply

func (f *Filter) Apply(m Message) bool

Apply checks all values. Return true if filter pass message.

type Message

type Message map[string]interface{}

Jump to

Keyboard shortcuts

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