-
Notifications
You must be signed in to change notification settings - Fork 96
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
How to determine interface from within handler? #41
Comments
You need to create your own Conn utilising "golang.org/x/net/ipv4". Look at conn/filter.go for inspiration. It detects which interface the packet came from and ignores it if it doesn't match what it's looking for. |
That creates other problems. I have a mix or real EtherNet interfaces and bridges (which don't have an IP address). If I don't specify the host address to bind to (i.e. default to |
You still want to bind to 0.0.0.0, you just use "golang.org/x/net/ipv4" to detect what interface the packet came from, like conn/NewUDP4FilterListener does, and set laddr param to 0.0.0.0. I had to use this technique, when I couldn't bind to given interface. |
Are you sure? I'm currently using |
Sorry I meant: 0.0.0.0:67. Pretty sure, used the technique in a router type box... |
I'm thinking you must have done something different than calling |
This is exactly why ListenAndServeIf was deprecated. Use a conn with Serve. The best case is to use conn/NewUDP4BoundListener for each interface you have. You can use the same handler if appropriate. If you can't use NewUDP4BoundListener (i.e. not linux), you'll need to create your own conn, probably based on NewUDP4FilterListener - where you would likely bind to 0.0.0.0:67, unless you have some specialised syscalls for your OS. |
I was using something like NewUDP4FilterListener, before NewUDP4BoundListener was developed on a router like pc. One of the largest challenges is that go's net lib doesn't support binding on a given interface in broadcast mode - otherwise ListenAndServeIf would have been able to do exactly what you want. Alas, that's not to be. |
In my case, my main concern is to ensure that reply packets go back to the requestor. I'm giving up for now having the
|
It would be nice if |
Another approach would be to define a new |
No, but feel free to fork. Currently, this can be accomplished by creating a link between your conn and your handler. Ideally, I think one interface per goroutine is cleaner as goroutines are designed to be cheap (go web servers have 1000s). |
I was hoping to avoid having to fork, as it means I'd have to maintain the fork, the feature sets would diverge and there would be fragmentation. I think there's a quality of implementation argument to at least ensure that |
Actually, you don't need to fork, you could create a new pkg with just your ExtendedHandler in it and have it import dhcp4. That way you only need to maintain your code, and it benefits from changes in the dhcp4, rather than you have to keep pulling through. As a maintainer of such a project, you will get to choose whether changes sent in by users are appropriate for your project. You may need to disappoint some people because you do not believe in their approach. You might be right, you might be wrong; but someone has to choose and that person is you because you maintain the project. If you do go ahead, please add a link of your project to this issue. |
Closing as issue is directly related to deprecated code. |
I'm using the
ListenAndServe
method to register my handler, so the same handler will be used for responding for all interfaces. How do I determine (from within the handler) which interface a DHCP packet was received on? I looked at the documentation and this information does not seems to be exposed.The text was updated successfully, but these errors were encountered: