common

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2018 License: BSD-3-Clause Imports: 7 Imported by: 2

Documentation

Overview

Package common is used for combining common functions from other packages which aren't connected with C language part

Index

Constants

View Source
const (
	EtherAddrLen = 6
	IPv4AddrLen  = 4
	IPv6AddrLen  = 16
)

Length of addresses.

View Source
const (
	IPV4Number = 0x0800
	ARPNumber  = 0x0806
	VLANNumber = 0x8100
	MPLSNumber = 0x8847
	IPV6Number = 0x86dd

	SwapIPV4Number = 0x0008
	SwapARPNumber  = 0x0608
	SwapVLANNumber = 0x0081
	SwapMPLSNumber = 0x4788
	SwapIPV6Number = 0xdd86
)

Supported EtherType for L2

View Source
const (
	ICMPNumber   = 0x01
	IPNumber     = 0x04
	TCPNumber    = 0x06
	UDPNumber    = 0x11
	ICMPv6Number = 0x3a
	NoNextHeader = 0x3b
)

Supported L4 types

View Source
const (
	ICMPTypeEchoRequest         uint8 = 8
	ICMPTypeEchoResponse        uint8 = 0
	ICMPv6TypeEchoRequest       uint8 = 128
	ICMPv6TypeEchoResponse      uint8 = 129
	ICMPv6NeighborSolicitation  uint8 = 135
	ICMPv6NeighborAdvertisement uint8 = 136
)

Supported ICMP Types

View Source
const (
	EtherLen   = 14
	VLANLen    = 4
	MPLSLen    = 4
	IPv4MinLen = 20
	IPv6Len    = 40
	ICMPLen    = 8
	TCPMinLen  = 20
	UDPLen     = 8
	ARPLen     = 28
	GTPMinLen  = 8
)

These constants keep length of supported headers in bytes.

IPv6Len - minimum length of IPv6 header in bytes. It can be higher and it is not determined inside packet. Only default minimum size is used.

IPv4MinLen and TCPMinLen are used only in packet generation functions.

In parsing we take actual length of TCP header from DataOff field and length of IPv4 take from Ihl field.

View Source
const (
	TCPMinDataOffset = 0x50 // minimal tcp data offset
	IPv4VersionIhl   = 0x45 // IPv4, IHL = 5 (min header len)
	IPv6VtcFlow      = 0x60 // IPv6 version
)
View Source
const (
	// No - no output even after fatal errors
	No LogType = 1 << iota
	// Initialization - output during system initialization
	Initialization = 2
	// Debug - output during execution one time per time period (scheduler ticks)
	Debug = 4
	// Verbose - output during execution as soon as something happens. Can influence performance
	Verbose = 8
)
View Source
const (
	TCPFlagFin = 0x01
	TCPFlagSyn = 0x02
	TCPFlagRst = 0x04
	TCPFlagPsh = 0x08
	TCPFlagAck = 0x10
	TCPFlagUrg = 0x20
	TCPFlagEce = 0x40
	TCPFlagCwr = 0x80
)

Constants for valuues of TCP flags.

View Source
const MaxLength = math.MaxInt32

Max array length for type conversions

Variables

This section is empty.

Functions

func GetDPDKLogLevel

func GetDPDKLogLevel() string

GetDPDKLogLevel internal, used in flow package

func GetDefaultCPUs

func GetDefaultCPUs(cpuNumber int) []int

GetDefaultCPUs returns default core list {0, 1, ..., NumCPU}

func HandleCPUList

func HandleCPUList(s string, maxcpu int) ([]int, error)

HandleCPUs parses cpu list string into array of valid core numbers. Removes duplicates

func LogDebug

func LogDebug(logType LogType, v ...interface{})

LogDebug internal, used in all packages

func LogDrop

func LogDrop(logType LogType, v ...interface{})

LogDrop internal, used in all packages

func LogError

func LogError(logType LogType, v ...interface{}) string

LogError internal, used in all packages

func LogFatal

func LogFatal(logType LogType, v ...interface{})

LogFatal internal, used in all packages

func LogFatalf

func LogFatalf(logType LogType, format string, v ...interface{})

LogFatalf is a wrapper at LogFatal which makes formatting before logger.

func LogTitle

func LogTitle(logType LogType, v ...interface{})

LogTitle internal, used in all packages

func LogWarning

func LogWarning(logType LogType, v ...interface{})

LogWarning internal, used in all packages

func SetLogType

func SetLogType(logType LogType)

SetLogType internal, used in flow package

func WrapWithNFError

func WrapWithNFError(err error, message string, code ErrorCode) error

WrapWithNFError returns an error annotating err with a stack trace at the point WrapWithNFError is called, and the next our NFError. If err is nil, Wrap returns nil.

Types

type ErrorCode

type ErrorCode int

ErrorCode type for codes of errors

const (
	Fail ErrorCode
	ParseCPUListErr
	ReqTooManyPorts
	BadArgument
	UseNilFlowErr
	UseClosedFlowErr
	OpenedFlowAtTheEnd
	PortHasNoQueues
	NotAllQueuesUsed
	FailToInitPort
	ParseRuleJSONErr
	FileErr
	ParseRuleErr
	IncorrectArgInRules
	IncorrectRule
	AllocMbufErr
	PktMbufHeadRoomTooSmall
	NotEnoughCores
	CreatePortErr
	MaxCPUExceedErr
	PcapReadFail
	PcapWriteFail
	InvalidCPURangeErr
	SetAffinityErr
	MultipleReceivePort
	MultipleKNIPort
	WrongPort
	FailToInitDPDK
	FailToCreateKNI
)

constants with error codes

func GetNFErrorCode

func GetNFErrorCode(err error) ErrorCode

GetNFErrorCode returns value of cCode field if err is NFError or pointer to it and -1 otherwise.

type LogType

type LogType uint8

LogType - type of logging, used in flow package

type NFError

type NFError struct {
	Code     ErrorCode
	Message  string
	CauseErr error
}

NFError is error type returned by nff-go functions

func GetNFError

func GetNFError(err error) (nferr *NFError)

GetNFError if error is NFerror or pointer to int returns pointer to NFError, otherwise returns nil.

func (*NFError) Cause

func (err *NFError) Cause() error

Cause returns the underlying cause of error, if possible. If not, returns err itself.

func (NFError) Error

func (err NFError) Error() string

Error method to implement error interface

func (*NFError) Format

func (err *NFError) Format(s fmt.State, verb rune)

Format makes formatted printing of errors, the following verbs are supported: %s, %v print the error. If the error has a Cause it will be printed recursively %+v - extended format. Each Frame of the error's StackTrace will be printed in detail if possible.

type TCPFlags

type TCPFlags uint8

TCPFlags contains set TCP flags.

Jump to

Keyboard shortcuts

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