mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-03 07:37:34 -04:00
unix: add SetsockoptCanRawFilter for linux
Add the SetsockoptCanRawFilter func and CanFilter type to allow kernel message filtering on AF_CAN sockets. Fixes golang/go#29638 Change-Id: I4042825527ba2bc9aeb8dbe70d1960a06b15c29e Reviewed-on: https://go-review.googlesource.com/c/163318 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
ec7b60b042
commit
a9d3bda3a2
@@ -493,6 +493,8 @@ type Ucred C.struct_ucred
|
|||||||
|
|
||||||
type TCPInfo C.struct_tcp_info
|
type TCPInfo C.struct_tcp_info
|
||||||
|
|
||||||
|
type CanFilter C.struct_can_filter
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||||
@@ -522,6 +524,7 @@ const (
|
|||||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||||
SizeofUcred = C.sizeof_struct_ucred
|
SizeofUcred = C.sizeof_struct_ucred
|
||||||
SizeofTCPInfo = C.sizeof_struct_tcp_info
|
SizeofTCPInfo = C.sizeof_struct_tcp_info
|
||||||
|
SizeofCanFilter = C.sizeof_struct_can_filter
|
||||||
)
|
)
|
||||||
|
|
||||||
// Netlink routing and interface messages
|
// Netlink routing and interface messages
|
||||||
|
|||||||
@@ -1000,6 +1000,14 @@ func SetsockoptSockFprog(fd, level, opt int, fprog *SockFprog) error {
|
|||||||
return setsockopt(fd, level, opt, unsafe.Pointer(fprog), unsafe.Sizeof(*fprog))
|
return setsockopt(fd, level, opt, unsafe.Pointer(fprog), unsafe.Sizeof(*fprog))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetsockoptCanRawFilter(fd, level, opt int, filter []CanFilter) error {
|
||||||
|
var p unsafe.Pointer
|
||||||
|
if len(filter) > 0 {
|
||||||
|
p = unsafe.Pointer(&filter[0])
|
||||||
|
}
|
||||||
|
return setsockopt(fd, level, opt, p, uintptr(len(filter)*SizeofCanFilter))
|
||||||
|
}
|
||||||
|
|
||||||
// Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
|
// Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
|
||||||
|
|
||||||
// KeyctlInt calls keyctl commands in which each argument is an int.
|
// KeyctlInt calls keyctl commands in which each argument is an int.
|
||||||
|
|||||||
@@ -405,6 +405,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -434,6 +439,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -406,6 +406,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -435,6 +440,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -409,6 +409,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -438,6 +443,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -407,6 +407,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -436,6 +441,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -408,6 +408,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -437,6 +442,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -407,6 +407,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -436,6 +441,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -407,6 +407,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -436,6 +441,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -408,6 +408,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -437,6 +442,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -408,6 +408,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -437,6 +442,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -408,6 +408,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -437,6 +442,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -407,6 +407,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -436,6 +441,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -406,6 +406,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -435,6 +440,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -410,6 +410,11 @@ type TCPInfo struct {
|
|||||||
Total_retrans uint32
|
Total_retrans uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter struct {
|
||||||
|
Id uint32
|
||||||
|
Mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
@@ -439,6 +444,7 @@ const (
|
|||||||
SizeofICMPv6Filter = 0x20
|
SizeofICMPv6Filter = 0x20
|
||||||
SizeofUcred = 0xc
|
SizeofUcred = 0xc
|
||||||
SizeofTCPInfo = 0x68
|
SizeofTCPInfo = 0x68
|
||||||
|
SizeofCanFilter = 0x8
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Reference in New Issue
Block a user