nfqueue

package
v0.0.0-...-eac3f56 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2017 License: GPL-2.0 Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInitialized = errors.New("nfqueue: queue not initialized")
View Source
var ErrOpenFailed = errors.New("nfqueue: open failed")
View Source
var ErrRuntime = errors.New("nfqueue: runtime error")
View Source
var NFQA_CFG_F_CONNTRACK uint32 = C.NFQA_CFG_F_CONNTRACK
View Source
var NFQA_CFG_F_FAIL_OPEN uint32 = C.NFQA_CFG_F_FAIL_OPEN
View Source
var NFQA_CFG_F_GSO uint32 = 1 << 2

These three variables seem not to be determinable by cgo, so they are statically * defined here. The values are taken from the ĺibnetfilter_queue source code (They are macros)

View Source
var NFQA_CFG_F_SECCTX uint32 = 1 << 4
View Source
var NFQA_CFG_F_UID_GID uint32 = 1 << 3
View Source
var NFQNL_COPY_META uint8 = C.NFQNL_COPY_META
View Source
var NFQNL_COPY_NONE uint8 = C.NFQNL_COPY_NONE
View Source
var NFQNL_COPY_PACKET uint8 = C.NFQNL_COPY_PACKET
View Source
var NF_ACCEPT = C.NF_ACCEPT
View Source
var NF_DROP = C.NF_DROP
View Source
var NF_QUEUE = C.NF_QUEUE
View Source
var NF_REPEAT = C.NF_REPEAT
View Source
var NF_STOP = C.NF_STOP

Functions

func GoCallbackWrapper

func GoCallbackWrapper(ptr_q *unsafe.Pointer, ptr_nfad *unsafe.Pointer) int

Cast argument to Queue* before calling the real callback

Notes:

This function must _nerver_ be called directly.

Types

type Callback

type Callback func(*Payload) error

Prototype for a NFQUEUE callback. The callback receives the NFQUEUE ID of the packet, and the packet payload. Packet data start from the IP layer (ethernet information are not included). It should return -1 on error to stop processing or >= 0 otherwise.

type Payload

type Payload struct {

	// NFQueue ID of the packet
	Id uint32
	// Packet data
	Data []byte
	// contains filtered or unexported fields
}

Payload is a structure describing a packet received from the kernel

func (*Payload) GetInDev

func (p *Payload) GetInDev() uint32

Returns the interface that the packet was received through

func (*Payload) GetNFMark

func (p *Payload) GetNFMark() uint32

Returns the packet mark

func (*Payload) GetOutDev

func (p *Payload) GetOutDev() uint32

Returns the interface that the packet will be routed out

func (*Payload) GetPhysInDev

func (p *Payload) GetPhysInDev() uint32

Returns the physical interface that the packet was received through

func (*Payload) GetPhysOutDev

func (p *Payload) GetPhysOutDev() uint32

Returns the physical interface that the packet will be routed out

func (*Payload) GetTimestamp

func (p *Payload) GetTimestamp() syscall.Timeval

GetTimestamp gives you the timestamp of the packet. *

func (*Payload) SetVerdict

func (p *Payload) SetVerdict(verdict int) error

SetVerdict issues a verdict for a packet.

Every queued packet _must_ have a verdict specified by userspace.

func (*Payload) SetVerdictModified

func (p *Payload) SetVerdictModified(verdict int, data []byte) error

SetVerdictModified issues a verdict for a packet, but replaces the packet with the provided one.

Every queued packet _must_ have a verdict specified by userspace.

type Queue

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

Queue is an opaque structure describing a connection to a kernel NFQUEUE, and the associated Go callback.

func (*Queue) Bind

func (q *Queue) Bind(af_family int) error

Bind binds a Queue to a given protocol family.

Usually, the family is syscall.AF_INET for IPv4, and syscall.AF_INET6 for IPv6

func (*Queue) Close

func (q *Queue) Close()

func (*Queue) CreateQueue

func (q *Queue) CreateQueue(queue_num uint16) error

Create a new queue handle

The queue must be initialized (using Init) and bound (using Bind), and a callback function must be set (using SetCallback).

func (*Queue) DestroyQueue

func (q *Queue) DestroyQueue() error

Destroy a queue handle

This also unbind from the nfqueue handler, so you don't have to call Unbind() Note that errors from this function can usually be ignored. WARNING: This function races with netlink sending messages and triggering the execution of the callback function! DO NOT rely on the callback function's negative return value to stop the netlink lib from calling the callback (because it doesn't)

func (*Queue) Init

func (q *Queue) Init() error

Init creates a netfilter queue which can be used to receive packets from the kernel.

func (*Queue) Loop

func (q *Queue) Loop() error

Main loop: Loop starts a loop, receiving kernel events and processing packets using the callback function.

func (*Queue) SetBufLen

func (q *Queue) SetBufLen(bufLen C.uint64_t) error

func (*Queue) SetCallback

func (q *Queue) SetCallback(cb Callback) error

SetCallback sets the callback function, fired when a packet is received. Returning from the callback and evaluation its return value races with the netlink socket receiving a new packet from the kernel. Do not rely on the execution of the callback, at the end of which you return a negative value, to be the last execution of it.

func (*Queue) SetMode

func (q *Queue) SetMode(mode uint8) error

SetMode sets the amount of packet data that nfqueue copies to userspace

Default mode is NFQNL_COPY_PACKET

func (*Queue) SetQueueFlags

func (q *Queue) SetQueueFlags(mask, flags uint32) error

func (*Queue) SetQueueMaxLen

func (q *Queue) SetQueueMaxLen(maxlen uint32) error

SetQueueMaxLen fixes the number of packets the kernel will store before internally before dropping upcoming packets

func (*Queue) StopLoop

func (q *Queue) StopLoop()

func (*Queue) Unbind

func (q *Queue) Unbind(af_family int) error

Unbind a queue from the given protocol family.

Note that errors from this function can usually be ignored.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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