coova / coova-chilli

CoovaChilli is an open-source software access controller for captive portal hotspots.
Other
518 stars 260 forks source link

Extrat bytes sent within the "302 Moved Temporarily" redirect response ! #106

Closed gbaligh closed 8 years ago

gbaligh commented 9 years ago

Hi,

I'm compiled coova-chilli (the last master HEAD revision) using OpenWRT for a MIPS. All appears to be OK. So I configured coova-chilli with all needed parameters, connected a client in the LAN interface, and asking for www.google.com page, and here the redirect response is received, but as binary file. In the response the 302 response is correct, but there is extra bytes before it.

`E <  À¨¶ ÷wwwgooglecom   HTTP/1.0 302 Moved Temporarily Connection: close Pragma: no-cache Expires: Fri, 01 Jan 1971 00:00:00 GMT Cache-Control: no-cache, must-revalidate P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"``

gbaligh commented 9 years ago

After reading the code, it seems that the extra bytes are a DNS reply sent from coova-chilli to the client using the TCP connection instead of UDP !!

wlanmac commented 9 years ago

Can you provide a patch or point us to the code in question? Thanks!

gbaligh commented 9 years ago

in file redir.c starting at line 4192, related to redirdnsreq option. I made a test to check if its really resolve the problem, and I disabled the redirdnsreq option, then after, no more extra bytes. Sorry but I did not resolved it yet. I'm trying to understand why the tun_encaps() function is redirecting messages to local client, it may be a wrong configuration that I made into the firewall, I don't now yet. I'll keep you in touch with last results.

gbaligh commented 9 years ago

When enabling log-debug, the "302 Moved Temporarily" response will contains the log from chilli !!

gbaligh commented 9 years ago

Resolved by adding -f to chilli arguments ! Even the redirdnsreq option works after making the chilli binary works in foreground !

gbaligh commented 9 years ago

Can be resolved by adding -f, to run CoovaChilli in the foreground. Resolved, no change needed in code.

gbaligh commented 9 years ago

It may be caused by the stdout,stderr and stdin redirect algorithm. After redirecting, there is a fclose(), but normally those files must remain open until the end of CoovaChilli program, and Syslog is using the option LOG_PERROR, witch need to the stderr to print log message. What do you think ?

ynezz commented 8 years ago

I'm seeing similar problem, but in different part, mixing syslog message in redir output:

<27>Dec  2 19:03:38 coova-chilli[3840]: X3�<27>Dec  2 19:03:38 coova-chilli[3840]: radius: Bad file descriptor: close(proxyfd=-1) failed!�HTTP/1.0 302 Moved Temporarily
Connection: close
Pragma: no-cache
Expires: Fri, 01 Jan 1971 00:00:00 GMT

That X3 is coming from my debugging line in src/redir.c in redir_radius():

2956     if (conn->response) {
2957       syslog(LOG_ERR, "X3");
2958       radius_free(radius);
2959       return 0;
2960     }

Probably some problem with fork()ing or file descriptors, it's going away if coova is running in foreground. I'll try to bisect it.

ynezz commented 8 years ago

I've bisected it down to this one big commit 43626e2052fcdd8ee06e0164911fbe534db1ced9.