0.6.11 doesn't work on ipv4 only hardware

Report & discuss bugs found in SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
rustydust
Newbie
Newbie
Posts: 4
Joined: December 1st, 2011, 12:13 pm

0.6.11 doesn't work on ipv4 only hardware

Post by rustydust »

I don't know if anyone has ever tried to run SABnzbd 0.6.11 on hardware that only supports IPv4, but for me it fails because of a number of reasons when trying to attach the web interface to either 'localhost' or '0.0.0.0'. That's because in SABnzbd.py the following happens:

Code: Select all

line 1302: hosts = all_localhosts()
will always return an array with more than 1 element (three times '127.0.0.1' on all of my Debian/Ubuntu test systems)

Code: Select all

line 1303: multilocal = len(hosts) > 1 and cherryhost in ('localhost', '0.0.0.0')
also always true in the scenario given above and because of line 1302

thus, line 1305/1306 will set hosts[1] to '::1' - and that's where things start to break because on IPv4 only hardware this will raise an exception (protocol not supported). And it even doesn't evaluate the new --stack option, thus setting an IPv6 address even in case the user explicitly disables IPv6 by using '--stack ipv4'.

A non intrusive patch that makes use of the new '--stack' option could look like this:

Code: Select all

--- a/SABnzbd-0.6.11/SABnzbd.py	2011-11-29 21:28:21.000000000 +0100
+++ b/SABnzbd-0.6.11/SABnzbd.py	2011-12-01 18:50:30.393379263 +0100
@@ -1302,13 +1302,16 @@
     hosts = all_localhosts()
     multilocal = len(hosts) > 1 and cherryhost in ('localhost', '0.0.0.0')
 
-    # For 0.0.0.0 CherryPy will always pick IPv4, so make sure the secondary localhost is IPv6
-    if multilocal and cherryhost == '0.0.0.0' and hosts[1] == '127.0.0.1':
-        hosts[1] = '::1'
-
-    # The Windows binary requires numeric localhost as primary address
-    if multilocal and cherryhost == 'localhost' and hosts[1] == '127.0.0.1':
-        cherryhost = '::1'
+    if 'ipv6' in (stack) or stack == '':
+        # For 0.0.0.0 CherryPy will always pick IPv4, so make sure the secondary localhost is IPv6
+        if multilocal and cherryhost == '0.0.0.0' and hosts[1] == '127.0.0.1':
+            hosts[1] = '::1'
+
+        # The Windows binary requires numeric localhost as primary address
+        if multilocal and cherryhost == 'localhost' and hosts[1] == '127.0.0.1':
+            cherryhost = '::1'
+    else:
+        hosts[1] = '127.0.0.1'
 
     if enable_https:
         if https_port:
@@ -1329,7 +1332,10 @@
     elif multilocal:
         # Extra HTTP port for secondary localhost
         attach_server(hosts[1], cherryport)
-
+    else:
+        # if no https and no multilocal, it would be nice if we'd
+        # attach to at least some port, no?
+        attach_server(cherryhost, cherryport)
 
     if no_login:
         sabnzbd.cfg.username.set('')
This would trigger only if forced by using '--stack ipv4' and in that case set hosts[1] to '127.0.0.1' which actually shouldn't be necessary since that's what should be the value already. The second hunk is just to make sure that in case multilocal would really be set to False and https isn't enabled at least some sort of web interface is started.

Feel free to use, modify, ignore or to tell me where my error is ;-)
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: 0.6.11 doesn't work on ipv4 only hardware

Post by shypike »

Except for Windows XP, IPv4-only systems are becoming a rare breed.
(BTW: it works fine on XP).
I'm not sure what you're up to with the --stack modifications.
0.6.11 should work out of the box on IPv4 systems, if not then a fix is needed.
I'll look into this.
Which OS flavor and version are you using?
rustydust
Newbie
Newbie
Posts: 4
Joined: December 1st, 2011, 12:13 pm

Re: 0.6.11 doesn't work on ipv4 only hardware

Post by rustydust »

Older Debian (etch/sarge) on a ReadyNAS but may as well apply to older QNAP boxes and not too few routers where the hardware doesn't support IPv6.
What I'm up to with the --stack modifications is that I was under the impression that if I told a software to only use IPv4 I expect it to do exactly that. Not only for the transmission of files and communicating with the outside world but also for it's internal stuff. That's why I choose this approach in the patch above.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: 0.6.11 doesn't work on ipv4 only hardware

Post by shypike »

The --stack ipv4 is mean to force the use of only IPv4 on a dual stack system, should you want that.
On an IPv4-only system, things should just work (so without the option).
Unfortunately it seems that not all IPv4-only systems behave the same when reporting their localhost equivalents.
I'll see if I can fix this quickly.

PS:
Does replacing all_localhosts() with this help?

Code: Select all

def all_localhosts():
    """ Return all unique values of localhost """
    ips = []
    for item in socket.getaddrinfo('localhost', None):
        item = item[4][0]
        if item not in ips:
            ips.append(item)
    return ips
rustydust
Newbie
Newbie
Posts: 4
Joined: December 1st, 2011, 12:13 pm

Re: 0.6.11 doesn't work on ipv4 only hardware

Post by rustydust »

Works for me, thanks. Should have noticed that compacting the array would have solved the issue more elegantly ;)
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: 0.6.11 doesn't work on ipv4 only hardware

Post by shypike »

BTW: using -s 127.0.0.1:8080 would have solved the problem for you also.
But it's still a bug.
rustydust
Newbie
Newbie
Posts: 4
Joined: December 1st, 2011, 12:13 pm

Re: 0.6.11 doesn't work on ipv4 only hardware

Post by rustydust »

Doesn't make much sense to use -s 127.0.0.1:8080 on a NAS, does it? ;)
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: 0.6.11 doesn't work on ipv4 only hardware

Post by shypike »

Yeah, sure.
You were hit when you used 0.0.0.0.
So in that case using an empty hostname would be a work-around.
Because, like you said: localhost is no use for you, so 0.0.0.0 is overdone too (it means: all IP's including 127.0.0.1).
Post Reply