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

net: File{Conn,PacketConn} cannot accept AF_NETLINK, AF_ROUTE or other sockets #10565

Closed
mikioh opened this issue Apr 24, 2015 · 13 comments
Closed

Comments

@mikioh
Copy link
Contributor

mikioh commented Apr 24, 2015

For example, attached fails with "file file+net netlink: protocol not supported." When we want to know some status of network, routing information updates like "interface is going down", talking to a kernel by using netlink/route sockets is a only way to achieve it, and for handling chatty, sometimes massive events from/to the kernel we need support of runtime-integrated network poller.

package main

import (
    "log"
    "net"
    "os"
    "syscall"
)

func main() {
    s, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_ROUTE)
    if err != nil {
        log.Fatal(err)
    }
    lsa := syscall.SockaddrNetlink{Family: syscall.AF_NETLINK}
    if err := syscall.Bind(s, &lsa); err != nil {
        syscall.Close(s)
        log.Fatal(err)
    }
    f := os.NewFile(uintptr(s), "netlink")
    c, err := net.FilePacketConn(f)
    f.Close()
    if err != nil {
        log.Fatal(err)
    }
    log.Println(c.LocalAddr())
    c.Close()
}
``
@gopherbot
Copy link

CL https://golang.org/cl/9275 mentions this issue.

@mikioh mikioh added this to the Go1.5Maybe milestone May 2, 2015
@mikioh mikioh closed this as completed in 6f7961d May 13, 2015
@mikioh mikioh modified the milestones: Go1.5, Go1.5Maybe May 15, 2015
@nightlyone
Copy link
Contributor

@mikioh I miss SocketListener(*os.File, SocketAddr) (Listener, error). Is this oversight or intention?

@mikioh
Copy link
Contributor Author

mikioh commented May 15, 2015

It's intentional. I don't see any good use cases for SocketListener.

@mikioh mikioh reopened this Jul 2, 2015
@mikioh mikioh modified the milestones: Go1.6, Go1.5 Jul 2, 2015
@mdlayher
Copy link
Member

mdlayher commented Jul 4, 2015

I was literally just looking for this functionality. I got excited when I saw it was merged, but bummed out when I saw it was reverted.

@mikioh , do you have another solution in mind for Go 1.6 or later? I'd be very curious to hear about it.

@mikioh
Copy link
Contributor Author

mikioh commented Jul 7, 2015

This issue is re-opened as per request on #11492.

@mdlayher
Copy link
Member

Any word on a fix for this in Go 1.6? I remember hearing something about a syscall registration mechanism or similar to get at the runtime network poller.

@mdlayher
Copy link
Member

Hi @rsc and @mikioh , sorry to bother you again, but has any headway been made on this issue?

From #11492:

It seems to me that the net package should just keep using (and providing) only FileConn but perhaps we can put a registration mechanism in package syscall to let clients register converters between sockaddrs and net.Addr for non-standard sockaddr types.

This would be great, but I haven't found any changelists mentioning anything like it. Any news? Thanks for your time.

@rsc
Copy link
Contributor

rsc commented Dec 5, 2015

No, sorry. We've been busy with other work. We aren't going to get to this for Go 1.6.

@rsc rsc modified the milestones: Unplanned, Go1.6 Dec 5, 2015
@mdlayher
Copy link
Member

I did a bit of playing around this morning and was able to come up with a function net.RegisterSockaddr which enables registering an address family, a net.Addr, a syscall.Sockaddr, and converter functions between the two.

My understanding is that package syscall is frozen, but I was able to make this work by only modifying the net package anyway.

I was able to use it to successfully send ARP requests using a modified copy of my https://github.com/mdlayher/raw package which registers link-layer sockets using this mechanism.

I'd like to send a proposal later today, and if the idea is sound, clean it up, test it, and submit changelists to try to make this work. If this is able to go in, I'd be able to contribute x/net/linklayer or similar for raw ethernet sockets.

Any further thoughts, @rsc and/or @mikioh ?

@mdlayher
Copy link
Member

It's also worth mentioning that I personally think the mechanism introduced in https://go-review.googlesource.com/#/c/9275/ is cleaner, but as long as I can get access to the runtime network poller, I'm okay with whatever option the Go team would like to pursue.

@mdlayher
Copy link
Member

@mikioh Any chance you have more ideas on how to tackle this in 1.10? Will the new syscall.Conn interface be helpful?

@mikioh
Copy link
Contributor Author

mikioh commented Jun 3, 2017

@mdlayher,

Perhaps just three steps like the following:

  1. add socket type registration functionality into the syscall package,
  2. make the internal/poll package use the functionality introduced in (1),
  3. make the net package use the functionality introduced in (2).

@mikioh
Copy link
Contributor Author

mikioh commented Dec 28, 2018

#24331 provides a way to make socket descriptors work together with the runtime-integrated network poller, so I'll merge this issue into #24331.

@mikioh mikioh closed this as completed Dec 28, 2018
@golang golang locked and limited conversation to collaborators Dec 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants