1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// Berkeley packet filter for BSD variants
13
func BpfStmt(code, k int) *BpfInsn {
14
return &BpfInsn{Code: uint16(code), K: uint32(k)}
17
func BpfJump(code, k, jt, jf int) *BpfInsn {
18
return &BpfInsn{Code: uint16(code), Jt: uint8(jt), Jf: uint8(jf), K: uint32(k)}
21
func BpfBuflen(fd int) (int, int) {
23
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGBLEN, uintptr(unsafe.Pointer(&l)))
24
if e := int(ep); e != 0 {
30
func SetBpfBuflen(fd, l int) (int, int) {
31
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSBLEN, uintptr(unsafe.Pointer(&l)))
32
if e := int(ep); e != 0 {
38
func BpfDatalink(fd int) (int, int) {
40
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGDLT, uintptr(unsafe.Pointer(&t)))
41
if e := int(ep); e != 0 {
47
func SetBpfDatalink(fd, t int) (int, int) {
48
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSDLT, uintptr(unsafe.Pointer(&t)))
49
if e := int(ep); e != 0 {
55
func SetBpfPromisc(fd, m int) int {
56
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCPROMISC, uintptr(unsafe.Pointer(&m)))
57
if e := int(ep); e != 0 {
63
func FlushBpf(fd int) int {
64
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCFLUSH, 0)
65
if e := int(ep); e != 0 {
76
func BpfInterface(fd int, name string) (string, int) {
78
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGETIF, uintptr(unsafe.Pointer(&iv)))
79
if e := int(ep); e != 0 {
85
func SetBpfInterface(fd int, name string) int {
87
copy(iv.name[:], []byte(name))
88
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETIF, uintptr(unsafe.Pointer(&iv)))
89
if e := int(ep); e != 0 {
95
func BpfTimeout(fd int) (*Timeval, int) {
97
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGRTIMEOUT, uintptr(unsafe.Pointer(&tv)))
98
if e := int(ep); e != 0 {
104
func SetBpfTimeout(fd int, tv *Timeval) int {
105
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSRTIMEOUT, uintptr(unsafe.Pointer(tv)))
106
if e := int(ep); e != 0 {
112
func BpfStats(fd int) (*BpfStat, int) {
114
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGSTATS, uintptr(unsafe.Pointer(&s)))
115
if e := int(ep); e != 0 {
121
func SetBpfImmediate(fd, m int) int {
122
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCIMMEDIATE, uintptr(unsafe.Pointer(&m)))
123
if e := int(ep); e != 0 {
129
func SetBpf(fd int, i []BpfInsn) int {
131
p.Len = uint32(len(i))
132
p.Insns = (*BpfInsn)(unsafe.Pointer(&i[0]))
133
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETF, uintptr(unsafe.Pointer(&p)))
134
if e := int(ep); e != 0 {
140
func CheckBpfVersion(fd int) int {
142
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCVERSION, uintptr(unsafe.Pointer(&v)))
143
if e := int(ep); e != 0 {
146
if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION {
152
func BpfHeadercmpl(fd int) (int, int) {
154
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGHDRCMPLT, uintptr(unsafe.Pointer(&f)))
155
if e := int(ep); e != 0 {
161
func SetBpfHeadercmpl(fd, f int) int {
162
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSHDRCMPLT, uintptr(unsafe.Pointer(&f)))
163
if e := int(ep); e != 0 {