Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: expose Setsockopt for CAN Filtering #29638

Closed
iSchluff opened this issue Jan 9, 2019 · 3 comments
Closed

x/sys/unix: expose Setsockopt for CAN Filtering #29638

iSchluff opened this issue Jan 9, 2019 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Milestone

Comments

@iSchluff
Copy link

iSchluff commented Jan 9, 2019

Currently the support for AF_CAN sockets in x/sys/unix is not very useful, because kernel message filtering is not supported due to missing availability of the relevant sockopt. This sadly defeats the purpose of using go for CAN over other languages.

It also can not be worked around easily, as the unsafe setsockopt is only available in private. (Which is reasonable, but one needs unsafe to do ioctl SIOCGIFINDEX anyway when working with CAN sockets)

This comment comment on the original Request for AF_CAN sockets hints at the issue.

So I can see this being solved either with exposition of raw Setsockopt with unsafe pointers or introduction of a separate SetSockoptCanRawFilter function:

type CanFilter struct {
    Id   uint32
    Mask uint32
}

func SetsockoptCanRawFilter(fd, level, opt int, rfilter []CanFilter) error {
    ...
}

Which could be used as follows:

func main() {
    ...
    fd, _ := unix.Socket(unix.AF_CAN, unix.SOCK_RAW, unix.CAN_RAW)
    rfilter := make([]unix.CanFilter, 2)
        rfilter[0].Id = 0x123
        rfilter[0].Mask = unix.CAN_SFF_MASK
        rfilter[1].Id = 0x124
        rfilter[1].Mask = unix.CAN_SFF_MASK

    SetsockoptCanRawFilter(fd, unix.SOL_CAN_RAW, unix.CAN_RAW_FILTER, rfilter)
    ...
}
@gopherbot gopherbot added this to the Unreleased milestone Jan 9, 2019
@tklauser
Copy link
Member

Adding SetsockoptCanRawFilter and CanFilter sounds reasonable. Want to send a CL?

@tklauser tklauser added OS-Linux NeedsFix The path to resolution is known, but the work has not been done. labels Jan 10, 2019
@tklauser tklauser changed the title x/sys/unix/: Expose Setsockopt for CAN Filtering x/sys/unix: expose Setsockopt for CAN Filtering Jan 10, 2019
@iSchluff
Copy link
Author

I'll have to see whether the company can provide a CLA.

@gopherbot
Copy link

Change https://golang.org/cl/163318 mentions this issue: unix: add SetsockoptCanRawFilter for linux

@golang golang locked and limited conversation to collaborators Feb 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Projects
None yet
Development

No branches or pull requests

3 participants