unix: add SetsockoptSockFprog on Linux for attaching BPF filters

Adding this helper enables me to eliminate some nasty code which
invokes unix.Syscall6 directly, and which has 32-bit shims for
invoking setsockopt properly on 32-bit Linux.

Change-Id: I53ef411e4c96cef557999261760cddc00df58d8a
Reviewed-on: https://go-review.googlesource.com/c/163303
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go
index a07ee49..9a53ae2 100644
--- a/unix/syscall_linux.go
+++ b/unix/syscall_linux.go
@@ -994,6 +994,12 @@
 	return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq))
 }
 
+// SetsockoptSockFprog attaches a classic BPF or an extended BPF program to a
+// socket to filter incoming packets.  See 'man 7 socket' for usage information.
+func SetsockoptSockFprog(fd, level, opt int, fprog *SockFprog) error {
+	return setsockopt(fd, level, opt, unsafe.Pointer(fprog), unsafe.Sizeof(*fprog))
+}
+
 // Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
 
 // KeyctlInt calls keyctl commands in which each argument is an int.