-
Notifications
You must be signed in to change notification settings - Fork 26
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
Macos routes #49
base: main
Are you sure you want to change the base?
Macos routes #49
Conversation
@database64128 could this be merged into the main source code tree? Or any additional things needs to be done? |
@alexander-potemkin No, like the author said, this is too much of a hack to be merged. If your internet-facing physical interface has a fixed IP address, like |
@lsgrep Off-topic shameless plug: Saw you wrote https://github.com/lsgrep/cfbind, thought you might be interested in a similar project of mine: https://github.com/database64128/ddns-go. On Linux and Windows, ddns-go can use native platform APIs to monitor network interface address changes, without the need of polling at a fixed interval. |
I move around a lot with laptop and sometimes I use mobile hotspot so fixed IP does not work for me. |
Does the network interface change? Would it work for you if I add an option to bind to a specific interface? |
Thank you for rebasing and keeping this PR up-to-date! It's in much better shape now that the route calls are implemented in code. Still, I have some concerns with the approach taken here. Polling for route changes will always leave room for routing loops in between polls. Instead of relying on the OS routing table, may I suggest another approach? Currently, swgp-go implements sticky sockets at the "listener" end. That is, it remembers the last network interface and IP the client packet was received from, and always sends back via the same path. The facility for implementing this is well abstracted, and can be used for the outgoing end as well. Lines 649 to 651 in 8c4f6a1
Your "default gateway" (or whatever you call it) service could maintain an atomic pointer to the current outgoing network interface index and IP address, and in the above code snippet, populate the relevant fields in if c.autoOutgoingIface {
if info := outgoingIfaceState.Load(); info != nil {
scm.PktinfoAddr = info.Addr
scm.PktinfoIfindex = info.Ifindex
}
} |
I can fix the IP address, but this may cause problems as I switch to new network the range might not be totally different from what I've setup on my machine. And There could be some IP address conflict even if the network range is the same. |
Please correct me If I am wrong, I am assuming that this approach assumes that we could get to send out packets successfully and we get to parse the control message out from the received packets? Current problem I am facing is that when I've been using the new deployed code on my machine it is working great. I could not see any issues so far. |
I'm not asking you to use a fixed IP address. I'm asking whether the physical interface in use changes between places. For example, when you switch to a mobile hotspot, is the physical interface still |
No, that's not what I meant. Your current approach is to discover the default physical interface and add a route to the swgp-go server address via the interface's gateway. What I'm saying is, instead of using the information to create routes, you could simply set the |
Yes. will be fixed for most of the time. en0 |
I surely can set the |
What's this It should be easy to verify whether my approach works or not. Lines 649 to 651 in 8c4f6a1
Just hardcode the |
Actually I tried this, it threw routing errors (could not route to the proxy server). It did not work. |
Sorry I didn't describe it clearly. The |
I also tried that as well, it also did not work. |
I also could not wrap my head around the networking, without the route how networking interface could send the packet out? Sorry this might be a dumb question |
Dec 23 21:49:30.393 WRN Failed to write swgpPacket to proxyConn client=client-mac listenAddress=[::]:23456 clientAddress=[::ffff:127.0.0.1]:51820 proxyConnListenAddress=192.168.1.4:60100 pr |
Thanks a lot for creating this. Here is how i am using this on macOS. It is pretty ugly (without syscall), but it might help out the if someone want to use this in macOS. It is working for me. I am just sharing my solution, rather than hoping getting it merged into the codebase.