Help with IP binding, when I have a VPN installed

Need help? Post your questions here.

Moderator: moderators

Re: Help with IP binding, when I have a VPN installed

Postby WACOMalt » Fri Aug 16, 2013 2:45 am

Some more digging. My external IP address is currently 71.67.142.10 If I type 71.67.142.10:4040 on any machine in my LAN it sucessfully shows subsonic, and the address always shows that IP. Any machine outside my lan sent to that same IP also works. So my router is seeming to resolve correctly to the final 192.168.1.10:4040 no matter where it comes from as long as the traffic is coming directly to our external IP address. However, if I type in wacomalt.subsonic.org on any machine on my network, phone or PC, it gets routed to 5.6.104.XX and the server doesnt load (though it used to, if I was on a PC that was also part of the VPN, but that stopped working due to me manually binding ONLY to 192.168.1.10 in the vmsettings for the service)

What does this mean? Why would the external IP work perfect, for everyone, inside the network or not, while the subsonic vanity name does not. This tells me that it is doing something more than a simple redirect back to the IP registered.

I'm about to set up my own dynamic IP solution on my domain, because this is getting rediculous.
WACOMalt
 
Posts: 22
Joined: Fri Oct 12, 2012 3:55 am

Re: Help with IP binding, when I have a VPN installed

Postby GJ51 » Fri Aug 16, 2013 3:04 am

Suggestion:

Shut everything down. Reboot the router. Start the Subsonic host. Access it from your phone over cellular network. Then test internally. Then restart VPN and test again.

LOL - I just set up a new Madsonic site and can connect on my phone over 3g but it doesn't connect over wifi. First time that ever happened to me. All your fault :mrgreen:
Gary J

http://bios-mods.com
http://www.maplegrovepartners.com
http://theaverageguy.tv/category/tagpodcasts/cyberfrontiers/
User avatar
GJ51
 
Posts: 3492
Joined: Wed Oct 20, 2010 11:58 pm
Location: Western New York

Re: Help with IP binding, when I have a VPN installed

Postby WACOMalt » Fri Aug 16, 2013 5:04 am

Trust me I have done that. But thanks for the suggestion.

So here's the thing. I have found out how the redirection ACTUALLY works via some digging around in the source code https://github.com/hakko/subsonic/blob/ ... rvice.java around line 232

Basically this is the array that gets used during redirection, and lo and behold, LOCAL IP address IS involved in the actual redirection. The fault lies in the in line
Code: Select all
params.add(new BasicNameValuePair("localIp", Util.getLocalIpAddress()));
Which after searching appears to simply return the first non-loopback IP address of the server. In most cases this would be the LAN IP address, but depending on the behind the scenes ordering of the network adapters, as seen by java itself (I think) other adaptors can sometimes take precedence. Think of it like running ipconfig on windows, and imagine that this returned list also includes loopback adapters. The order things show up isnt necessarily gonna be the same on all machines. And for this case it would appear that on my machine, the VPN adapter's IP is reported first, before the LAN adapter's IP. I found another post on these forums expressing this as a bug: viewtopic.php?f=5&t=12001&start=15

I am not sure if this would be a bug in java itself (I think it would be, or more just a shortcoming or a case of this not really being the right thing to use to report Local IP in the way we need) or if this is actually a bug in subsonic itself.

So to summarize:

The redirection DOES involve local IP, though I dont know how it uses it. But it would appear the method for obtaining the "Local IP" shows very little care over WHICH local IP, and due to there being no way to manually specify via adapter ID or by manually entering the local IP, I am left with being stuck with it reporting my VPN IP, just because that is first in the report when it gets it's value for non-loopback IP list.

So I guess next in my list is building from source and simply (as a test) hardwiring the localip value in the array to 192.168.1.10, skipping the Until.getLocalIpAddress() function.

Now if only I knew anything about how to do that :D I guess it's time to try and get my eclipse development environment going again...

Until then, how can this be reported as a "potential" bug for future investigation by people who know more than I do? :P


EDIT: to be clearer, the fault (or more accurately the shortcoming) is in this file https://github.com/hakko/subsonic/blob/ ... /Util.java where the class getLocalIpAddress is defined.

Code: Select all
    public static String getLocalIpAddress() {
        try {

            // Try the simple way first.
            InetAddress address = InetAddress.getLocalHost();
            if (!address.isLoopbackAddress()) {
                return address.getHostAddress();
            }

            // Iterate through all network interfaces, looking for a suitable IP.
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            while (interfaces.hasMoreElements()) {
                NetworkInterface iface = interfaces.nextElement();
                Enumeration<InetAddress> addresses = iface.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    InetAddress addr = addresses.nextElement();
                    if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) {
                        return addr.getHostAddress();
                    }
                }
            }

        } catch (Throwable x) {
            LOG.warn("Failed to resolve local IP address.", x);
        }

        return "127.0.0.1";
    }


I'm going to fiddle with that once I get it building properly, and if I find a more robust way of finding the proper local IP address, I'll try to submit a merge request. But a forwarning, I am VERY new to java development and I know jack shit about github :) so anyone feel free to extend it in place of me.
WACOMalt
 
Posts: 22
Joined: Fri Oct 12, 2012 3:55 am

Re: Help with IP binding, when I have a VPN installed

Postby WACOMalt » Fri Aug 16, 2013 5:58 am

Success!

I tweaked that util function in the source to always return 192.168.1.10, no matter what, and it worked. wacomalt.subsonic.org, from inside my network, with VPN enabled or not, always sends the browser to 192.168.1.10:4040

booyah! :D I super happy this worked. I did not expect to find a "solution" myself :)

Now I feel the REAL solution would be to simply add a "manualy set local redirect IP?" check box on the network settings, and a box to fill in the IP. If that is check, then it simply hardcodes the IP string to that value rather than running this function.



A real solution I will try to post sometime tomorrow, but until then, anyone with the same issue I had can change "subsonic-4.8-src\subsonic-main\src\main\java\net\sourceforge\subsonic\util\Util.java" lines 91-119 replace every "return" line to say
return "192.168.1.XX"; Or whatever IP you need. Then build. and copy over your new subsonic.war file. The whole building from source tutorial (very easy) can be found here: http://sourceforge.net/apps/mediawiki/s ... ows_Source This is specifically windows, there are probably guides for linux and mac. but heck if your on linux you probably already know how :P

One more thing I want to try is that function has "the easy way" and "the hard way" of finding a local IP address. Through process of elimination I found that it was getting my incorrect IP via "the easy way". So I wonder if I disable the easy way, if the hard way will find it successfully instead? Worth a look.

Thanks everyone for helping me track down the issue, and hopefully a fix can be issued, if not by me than by someone a bit more skilled.
WACOMalt
 
Posts: 22
Joined: Fri Oct 12, 2012 3:55 am

Previous

Return to Help

Who is online

Users browsing this forum: No registered users and 20 guests