Skip to content

Commit 32ee382

Browse files
hallelujah-shihgconnell
authored andcommitted
add af-packet support ebpf filter
1 parent 65a1dfb commit 32ee382

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

afpacket/afpacket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// that can be found in the LICENSE file in the root of the source
55
// tree.
66

7+
//go:build linux
78
// +build linux
89

910
// Package afpacket provides Go bindings for MMap'd AF_PACKET socket reading.
@@ -273,6 +274,11 @@ func (h *TPacket) SetBPF(filter []bpf.RawInstruction) error {
273274
return setsockopt(h.fd, unix.SOL_SOCKET, unix.SO_ATTACH_FILTER, unsafe.Pointer(&p), unix.SizeofSockFprog)
274275
}
275276

277+
// attach ebpf filter to af-packet
278+
func (h *TPacket) SetEBPF(progFd int32) error {
279+
return setsockopt(h.fd, unix.SOL_SOCKET, unix.SO_ATTACH_BPF, unsafe.Pointer(&progFd), 4)
280+
}
281+
276282
func (h *TPacket) releaseCurrentPacket() error {
277283
h.current.clearStatus()
278284
h.offset++

0 commit comments

Comments
 (0)