Ensure that the selected default Gateway is the actual external router
oreillymj opened this issue · 8 comments
Hi,
On my home network I have 4 Wireless routers. Unusual yes, but I'm sure I'm not the only person with more than 1 router.
3 routers are running in AP mode connected back to the internet router over Cat5. They don't supply IP addresses but all have the same SSID
However when I look at a UPnP scan I get 1 Netgear D6200 (not connected to the Internet) and the D6400 which is.
The D6200 is coming back first in the UPnP scan and is incorrectly being selected as the default GW.
It may not be a complete fix, but I altered GatewayFinder to exclude the D6200 which has an external IP of 0.0.0.0 and also to store the Gateways IP address using the source address of the returned Unicast UpnP packet.
An unusual situation for sure, but not unheard of. As far as I know your fix should work, wanna send a PR?
Tried opening a PR but didn't want to push to master
How does this look?
@Override
public void run() {
boolean foundgw=false;
Gateway gw=null;
try {
byte[] req = this.req.getBytes();
DatagramSocket s = new DatagramSocket(new InetSocketAddress(ip, 0));
s.send(new DatagramPacket(req, req.length, new InetSocketAddress("239.255.255.250", 1900)));
s.setSoTimeout(3000);
for (;;) {
try {
DatagramPacket recv = new DatagramPacket(new byte[1536], 1536);
s.receive(recv);
//System.out.println("Gateway address " + recv.getAddress().getHostAddress());
gw = new Gateway(recv.getData(), ip, recv.getAddress());
String extIp= gw.getExternalIP();
if( (extIp!=null) && (!extIp.equalsIgnoreCase("0.0.0.0")) ){ //Exclude gateways without an external IP
gatewayFound(gw);
foundgw=true;
}
} catch (SocketTimeoutException t) {
break;
} catch (Throwable t) {
}
}
} catch (Throwable t) {
}
if( (!foundgw) && (gw!=null)){ //Pick the last GW if none have an external IP - internet not up yet??
gatewayFound(gw);
}
}
Sorry for the late reply
Your code should work. Pushing to master is the right thing to do, pushing to your master will update the PR, it won't go straight to my master.
Hi,
Tried to create a PR from InteliJ, but it says the oreillymj @ gmail .com doesn't have the required repo permissions.
Thanks for your patience, hopefully what I've done is correct.
Yes, you did it right. You don't have to call the PR "master" though, you should give a quick description of what your PR does.
Thanks, yes the Intelij dialog picked that as the default PR name. It wasn't obvious at the time what the field was.