diff --git a/afpacket/afpacket.go b/afpacket/afpacket.go index bdf888840..6600ae25e 100644 --- a/afpacket/afpacket.go +++ b/afpacket/afpacket.go @@ -4,6 +4,7 @@ // that can be found in the LICENSE file in the root of the source // tree. +//go:build linux // +build linux // Package afpacket provides Go bindings for MMap'd AF_PACKET socket reading. @@ -273,6 +274,11 @@ func (h *TPacket) SetBPF(filter []bpf.RawInstruction) error { return setsockopt(h.fd, unix.SOL_SOCKET, unix.SO_ATTACH_FILTER, unsafe.Pointer(&p), unix.SizeofSockFprog) } +// attach ebpf filter to af-packet +func (h *TPacket) SetEBPF(progFd int32) error { + return setsockopt(h.fd, unix.SOL_SOCKET, unix.SO_ATTACH_BPF, unsafe.Pointer(&progFd), 4) +} + func (h *TPacket) releaseCurrentPacket() error { h.current.clearStatus() h.offset++