Skip to content

Commit

Permalink
add af-packet support ebpf filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hallelujah-shih authored and gconnell committed Aug 10, 2022
1 parent 65a1dfb commit 32ee382
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions afpacket/afpacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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++
Expand Down

0 comments on commit 32ee382

Please sign in to comment.