View previous topic :: View next topic |
Author |
Message |
alexey123
Joined: 05 Nov 2014 Posts: 8
|
Posted: Wed Nov 05, 2014 2:10 pm Post subject: minissdpd on nas4free |
|
|
Hi. In first - many thanks for your work.
My name is Alexey, I'm doing an extension minidlna for NAS4Free.
I want add to this extension minissdpd - minidlna work more stable with minissdpd support. But I not understand one small question.
When I start minissdpd under nas4free host, I see on sockstat:
Code: | nasbox: ~ # sockstat |grep minissdp
root minissdpd 9688 4 udp4 *:1900 *:*
root minissdpd 9688 5 stream /var/run/minissdpd.sock |
I tried run it as
command_args="-s ${sockfile} -p ${pidfile} -i 10.0.0.1"
and
command_args="-s ${sockfile} -p ${pidfile} -i vlan0"
and with /etc/rc.conf entries,
and tried without rc.d file, run from simple command
Code: | /usr/local/sbin/minissdpd -s /var/run/minissdpd.sock -p /var/run/minissdpd.pid -i 10.0.0.1 |
with some result - it create socket as udp4 *:1900
But, if I run minissdpd under jail (one some host!!) it create socket normally, as
Code: | nasbox: ~ # jexec serviio csh
root@serviio:/ # sockstat
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root cron 10662 4 dgram -> /var/run/logpriv
root minissdpd 10650 4 udp4 10.0.0.3:1900 *:*
root minissdpd 10650 5 stream /var/run/minissdpd.sock
root syslogd 10595 4 dgram /var/run/log
root syslogd 10595 5 dgram /var/run/logpriv |
This is not bug, but I want to see on host some sockstat result as under jail
udp4 10.0.0.3:1900
Another services working correct on nas4free Examples
SSHD
Code: | nasbox: ~ # sockstat | grep sshd
root sshd 12727 5 tcp4 10.0.0.1:22 10.0.0.20:44975
root sshd 5711 5 tcp4 10.0.0.1:22 10.0.0.20:44742
root sshd 2596 4 tcp4 10.0.0.1:22 *:* |
lighttpd
Code: | nasbox: ~ # sockstat | grep lighttpd
www lighttpd 9704 3 dgram -> /var/run/log
www lighttpd 9704 4 tcp4 10.0.0.1:8280 *:*
root lighttpd 2808 3 dgram -> /var/run/logpriv
root lighttpd 2808 5 tcp4 10.0.0.1:443 *:*
root lighttpd 2196 3 dgram -> /var/run/logpriv
root lighttpd 2196 4 tcp4 10.0.0.1:80 *:* |
Where I must search problem ? |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Thu Nov 06, 2014 10:04 am Post subject: |
|
|
I think there might be an issue in openssdpsocket.c / OpenAndConfSSDPReceiveSocket
have you complied with #define ENABLE_IPV6 in config.h file ? _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
alexey123
Joined: 05 Nov 2014 Posts: 8
|
Posted: Fri Nov 07, 2014 1:18 pm Post subject: |
|
|
Thank you for good advice - I begin check used sources.
When I use installation from FreeBSD port tree - I have open socket as minissdpdd *:1900
When I compille last sources - 20140906 I have minissdpd socket as i want
Code: | sockstat | grep 1900
root minissdpd 66502 4 udp4 10.0.0.1:1900 *:* |
BUT!
minidlna 1.1.4 stop use minissdpd socket and open it itself as *.1900
My test log
Code: | nasbox: bin # pwd
/mnt/diskzfs/app/minidlna/bin
nasbox: bin # ./minissdpd.d start
Starting minissdpd.
nasbox: bin # sockstat | grep 1900
root minissdpd 67171 4 udp4 10.0.0.1:1900 *:*
nasbox: bin # ./minissdpd.d stop
Stopping minissdpd.
Waiting for PIDS: 67171.
nasbox: bin # /etc/rc.d/minidlna start
Starting minissdpd.
Starting minidlna.
Starting web_dlna.
Starting scanmedia
nasbox: bin # sockstat | grep 1900
root minidlna 67259 5 udp4 *:1900 *:*
root minissdpd 67257 4 udp4 10.0.0.1:1900 *:* |
Minidlna was patched at 1.1 version for use minissdpd unix socket or not? I stop understand anything. I need now patch minidlna? WOW!
In all cases - thank for advice
Special thank for very nice code testminissdpd.c - I make from it simple commandline controlpoint.
Code
Code: | #include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#define DECODELENGTH(n, p) n = 0; \
do { n = (n << 7) | (*p & 0x7f); } \
while(*(p++)&0x80);
#define SENDCOMMAND(command, size) write(s, command, size);
void printresponse(const unsigned char * resp, int n, int j)
{
int i, l;
unsigned int nresp;
const unsigned char * p;
for(i=0; i<n; i++)
/*printf("%02x ", resp[i]);
printf("\n");*/
nresp = resp[0];
p = resp + 1;
for(i = 0; i < (int)nresp; i++) {
/*l = *(p++);*/
DECODELENGTH(l, p);
printf("%d %d %.*s\n", j,i, l, p);
p += l;
/*l = *(p++);*/
DECODELENGTH(l, p);
/*printf(" %.*s\n", l, p);*/
p += l;
/*l = *(p++);*/
DECODELENGTH(l, p);
/*printf(" %.*s\n", l, p);*/
p += l;
}
}
int
main(int argc, char * * argv)
{
char command1[] = "\x01\x00urn:schemas-upnp-org:device:MediaServer";
char command2[] = "\x01\x00urn:schemas-upnp-org:device:MediaRenderer";
char command3[] = "\x01\x00urn:schemas-upnp-org:device:InternetGatewayDevice";
struct sockaddr_un addr;
int s;
int i;
unsigned char buf[2048];
ssize_t n;
const char * sockpath = "/var/run/minissdpd.sock";
for(i=0; i<argc-1; i++) {
if(0==strcmp(argv[i], "-s"))
sockpath = argv[++i];
}
command1[1] = sizeof(command1) - 3;
command2[1] = sizeof(command2) - 3;
command3[1] = sizeof(command3) - 3;
s = socket(PF_LOCAL, SOCK_STREAM, 0);
addr.sun_family = PF_LOCAL;
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
fprintf(stderr, "connecting to %s\n", addr.sun_path);
perror("connect");
return 1;
}
/*printf("Connected.\n");*/
SENDCOMMAND(command1, sizeof(command1) - 1);
n = read(s, buf, sizeof(buf));
/*printf("Response received %d bytes\n", (int)n);*/
printresponse(buf, n, 1);
SENDCOMMAND(command2, sizeof(command2) - 1);
n = read(s, buf, sizeof(buf));
/*printf("Response received %d bytes\n", (int)n);*/
printresponse(buf, n, 2);
SENDCOMMAND(command3, sizeof(command3) - 1);
n = read(s, buf, sizeof(buf));
/*printf("Response received %d bytes\n", (int)n);*/
printresponse(buf, n, 3);
close(s);
return 0;
} |
Result:
Output construct as <a b c>, where
a =1 - server
a=2 - client
a=3 - GatewayDevice
b - Device number
c - description URL
Last edited by alexey123 on Fri Nov 07, 2014 1:27 pm; edited 1 time in total |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Fri Nov 07, 2014 1:25 pm Post subject: |
|
|
I think I found the issue in minidlna.c :
Code: | sudp = OpenAndConfSSDPReceiveSocket(n_lan_addr, lan_addr);
if(sudp < 0)
{
DPRINTF(E_INFO, L_GENERAL, "Failed to open socket for receiving SSDP. Trying to use MiniSSDPd\n");
if(SubmitServicesToMiniSSDPD(lan_addr[0].str, runtime_vars.port) < 0) {
DPRINTF(E_FATAL, L_GENERAL, "Failed to connect to MiniSSDPd. EXITING");
return 1;
}
}
|
if opendlna fails to open the socket, it tries MiniSSDPD...
you should patch to do the other way around...
1st call SubmitServicesToMiniSSDPD(), if it fails call OpenAndConfSSDPReceiveSocket() _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
alexey123
Joined: 05 Nov 2014 Posts: 8
|
Posted: Fri Nov 07, 2014 7:04 pm Post subject: |
|
|
miniupnp wrote: |
you should patch to do the other way around...
1st call SubmitServicesToMiniSSDPD(), if it fails call OpenAndConfSSDPReceiveSocket() |
You right, but..
As for me minidlna needs to be honest revision
1. Minidlna itself create socket as *:1900 - i need find. repair it and send report and patch for minidlna developer.
2 As you says , minidlna need check minissdpd socket, and if it not present, try open itself
Update.
I patched minidlna.c, it work for me
Patch
Code: | --- minidlna.c.orig 2014-11-08 15:33:56.920485394 +0200
+++ minidlna.c 2014-11-08 15:36:38.112490345 +0200
@@ -1050,14 +1050,14 @@
}
#endif
smonitor = OpenAndConfMonitorSocket();
-
- sssdp = OpenAndConfSSDPReceiveSocket();
- if (sssdp < 0)
+
+
+ if (SubmitServicesToMiniSSDPD(lan_addr[0].str, runtime_vars.port) < 0)
{
- DPRINTF(E_INFO, L_GENERAL, "Failed to open socket for receiving SSDP. Trying to use MiniSSDPd\n");
- if (SubmitServicesToMiniSSDPD(lan_addr[0].str, runtime_vars.port) < 0)
- DPRINTF(E_FATAL, L_GENERAL, "Failed to connect to MiniSSDPd. EXITING");
- }
+ sssdp = OpenAndConfSSDPReceiveSocket();
+ if (sssdp < 0)
+ DPRINTF(E_FATAL, L_GENERAL, "Failed to connect to MiniSSDPd. EXITING");
+ }
/* open socket for HTTP connections. */
shttpl = OpenAndConfHTTPSocket(runtime_vars.port);
if (shttpl < 0)
|
3. Part of minidlna log messages not have EOL characters. It not critical for regular users - anyone not see logfile, but I do log parsing and display log as
It looks ugly without EOL
4 Minidlna open presentation page not as defined by config file ip:8200/index.php , it open as ip:8200 - also need find and repair.
Done.
Patch
Code: | --- upnphttp.c.orig 2014-11-10 10:02:08.425181892 +0200
+++ upnphttp.c 2014-11-10 10:01:10.249180105 +0200
@@ -999,6 +999,10 @@
{
SendResp_presentation(h);
}
+ else if(strncmp(HttpUrl, presentationurl, strlen(presentationurl)) == 0)
+ {
+ SendResp_presentation(h);
+ }
else if(strcmp(HttpUrl, "/") == 0)
{
#ifdef READYNAS |
I use presentation page for extract scan state message
and change status icon
5. Minidlna check HW adress devices by wrong for FreeBSD way, need execute arp -a , instead read /proc/net/arp file, it not present into /proc
Done. replace function/ Work on Ubuntu also
Code: | int
get_remote_mac(struct in_addr ip_addr, unsigned char *mac)
{
int found_entry=0;
int mib[6];
size_t needed;
char *lim, *buf, *next;
struct rt_msghdr *rtm;
struct sockaddr_inarp *sin;
struct sockaddr_dl *sdl;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
mib[3] = AF_INET;
mib[4] = NET_RT_FLAGS;
mib[5] = RTF_LLINFO;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
DPRINTF(E_ERROR, L_GENERAL, "route sysctl estimate");
if ((buf = malloc(needed)) == NULL)
DPRINTF(E_ERROR, L_GENERAL, "malloc");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
DPRINTF(E_ERROR, L_GENERAL, "actual retrieval of routing table");
lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
sin = (struct sockaddr_inarp *)(rtm + 1);
sdl = (struct sockaddr_dl *)(sin + 1);
if (ip_addr.s_addr != sin->sin_addr.s_addr)
continue;
if (sdl->sdl_alen) {
found_entry = 1;
memmove(mac, (u_char *)LLADDR(sdl), 6);
break;
}
}
if(!found_entry)
memset(mac, 0xFF, 6);
free(buf);
return !found_entry;
} |
6 I attach also webviewer for minidlna database, It work perfect, if defined only one media folder. But this is a completely different story, nothing to do with minissdpd and minidlna.
7 I want patch fuppes for work with minissdpd also..
WOW, controlpoint script was SECOND program by C . |
|
Back to top |
|
 |
alexey123
Joined: 05 Nov 2014 Posts: 8
|
Posted: Sun Nov 23, 2014 2:45 pm Post subject: |
|
|
I continue.
I repaired all minidlna bugs, but now I see strangle behavior of minissdpd. ( I use sources from github)
1.
When I start minissdpd (with/without minidlna ) it see all my UPnP devices.
But after ~1.5 -2 hours ( sometimes 24 hours ) minissdpd lost his cache and not renew it.
In case work with minidlna - minissdpd show only main minidlna server, (UNIX socket work!!)
In case work without minidlna - it print empty output array.
Sometimes minissdpd lost not all devices, but lost
After restart service all devices go into cache whithout problem.
I inspect network and see only 1 packet MSEARCH from minissdpd, when it start. Into minissdpd.c main loop:
Code: | /* send M-SEARCH ssdp:all Requests */
ssdpDiscoverAll(s_ssdp, 0);
if(s_ssdp6 >= 0)
ssdpDiscoverAll(s_ssdp6, 1);
/* Main loop */
while(!quitting)
{
/* fill readfds fd_set */
FD_ZERO(&readfds);
if(s_ssdp >= 0) { |
MSEARCH outside loop, this just mistake ? But If insert MSEARCH into main loop , need specify notify interval, may be over a command argument.
2.
Quote: | minissdpd[12515]: setsockopt(udp, IP_ADD_MEMBERSHIP)(10.0.0.1): Address already in use |
I add route before minissdpd start. My code
Code: | minidlna_prestart()
{
minidlna_mkconf
/sbin/route add -net 239.0.0.0 -netmask 240.0.0.0 -interface ${_if} >/dev/null 2>&1
setint=`/usr/local/sbin/rconf attribute set minissdpd_flags "-i ${_if}"` #This is nas4free script for manipulate /etc/rc.conf
/etc/rc.d/minissdpd start
} |
Multicast broken or not ? |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Mon Nov 24, 2014 2:40 pm Post subject: |
|
|
That is OK that minissdpd sends MSEARCH only at start.
Running services are supposed to send "alive" messages.
You should check they are doing so.
Or maybe there is some issue and minissdpd cannot received broadcasted message on your setup _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
alexey123
Joined: 05 Nov 2014 Posts: 8
|
Posted: Thu Nov 27, 2014 7:59 am Post subject: |
|
|
Quote: | That is OK that minissdpd sends MSEARCH only at start. |
OK
Interest behavior.
I comment define ENABLE_IPV6 into config.h and begin to study debug mode plus wireshark
Results:
With ENABLE_IPV6 - minissdpd create socket as 10.0.0.1:1900, but listen network only one time.
With commented ENABLE_IPV6 minissdpd create socket as *:1900, but listen network allways (tested about 10 hours) ! BUT, if I shutdown my TV Samsung, minissdpd see message byebye, but not remove TV from cashe. Remove, when expire caсhe live time.
I see space into packet from samsung , may be here problem ?
Windows laptop not have space into packet , and detect on/off state perfect. |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Fri Nov 28, 2014 1:50 pm Post subject: |
|
|
what do you mean "I see space into packet from samsung" ?
I should check if byebye messages are taken into account...
I have to check what is your problem with IPV6 code _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Fri Nov 28, 2014 2:30 pm Post subject: |
|
|
I think I found the issue.
If we are listening on *:1900, all messages are received.
if we are listening on <ip>:1900, broadcast messages are not received (but M-SEARCH responses are)
This is the behaviour at least on my linux 2.6.32
So I think we should revert to always listening on *:1900 and filter the messages based on sender IP address. _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
|
Back to top |
|
 |
alexey123
Joined: 05 Nov 2014 Posts: 8
|
Posted: Sat Nov 29, 2014 6:24 pm Post subject: |
|
|
miniupnp wrote: | I think I found the issue.
If we are listening on *:1900, all messages are received.
if we are listening on <ip>:1900, broadcast messages are not received (but M-SEARCH responses are)
This is the behaviour at least on my linux 2.6.32 |
Some behavior I have on my nNas4Free ( aka FreeBSD 9.2 )
Quote: | So I think we should revert to always listening on *:1900 and filter the messages based on sender IP address. |
Yes, I also read books and internet about multicasting - it work only if defined INADDR_ANY.
As result - if we want to run multiple servers per host, we must install any manager, such minissdpd and patch servers for use minissdpd unix socket.
For Nas4Free - I know only Minidlna Fuppes and xupnpd, which can run under Nas4FRee directly, not under jail ( Currently under FreeBSD 9.2 jails multicast not work, I want check with FreeBSD10.x in future .)
Quote: | see minissdpd-1.2.20141128.tar.gz |
Checked. Work with
Code: | --- getroute.c.orig 2014-11-29 17:27:50.565040149 +0200
+++ getroute.c 2014-11-29 17:28:28.997041330 +0200
@@ -236,7 +236,7 @@
sa = (struct sockaddr *)p;
sockaddr_to_string(sa, tmp, sizeof(tmp));
syslog(LOG_DEBUG, "type=%d sa_len=%d sa_family=%d %s",
- i, SA_LEN(sa), sa->sa_family, tmp);
+ i, sa->sa_len, sa->sa_family, tmp);
if((i == RTA_DST || i == RTA_GATEWAY) &&
(src_len && src)) {
size_t len = 0;
@@ -266,7 +266,7 @@
*index = sdl->sdl_index;
}
#endif
- p += SA_LEN(sa);
+ p += sa->sa_len;
}
}
} |
Quote: | what do you mean "I see space into packet from samsung" ? |
4E 54 53 3A 20 73 73 64 70 3A 62 79 65 62 79 65 0D 0A
as
NTS: ssdp:byebye
so "space" have code 20. I think parsing not work not because of "space" between NTS: and ssdp:byebye, you drop all spaces in packet.
I upload 5 wireshark screenshots https://sites.google.com/site/aganimkarmiel/home/free-time/file-sharing/ssdpd_pict.tar.gz
Minissdpd not correct displays ON/OFF switch for minidlna on my Ubuntu-PC, and samsung TV - when I powerdown device, I see byebye message, but minissdpd not see it and wait some minutes for clear from cache).
but Windows Laptop ON/OFF conditions shown immediately (work as expected ). Windows have another bug, when I send it to standby, it send byebye properly, but if I send laptop to powerdown, it close network, then send byebye  |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Mon Dec 01, 2014 9:28 am Post subject: |
|
|
alexey123 wrote: |
Code: | --- getroute.c.orig 2014-11-29 17:27:50.565040149 +0200
+++ getroute.c 2014-11-29 17:28:28.997041330 +0200
@@ -236,7 +236,7 @@
sa = (struct sockaddr *)p;
sockaddr_to_string(sa, tmp, sizeof(tmp));
syslog(LOG_DEBUG, "type=%d sa_len=%d sa_family=%d %s",
- i, SA_LEN(sa), sa->sa_family, tmp);
+ i, sa->sa_len, sa->sa_family, tmp);
if((i == RTA_DST || i == RTA_GATEWAY) &&
(src_len && src)) {
size_t len = 0;
@@ -266,7 +266,7 @@
*index = sdl->sdl_index;
}
#endif
- p += SA_LEN(sa);
+ p += sa->sa_len;
}
}
} |
|
Thanks, I fixed that.
Quote: |
Quote: | what do you mean "I see space into packet from samsung" ? |
4E 54 53 3A 20 73 73 64 70 3A 62 79 65 62 79 65 0D 0A
as
NTS: ssdp:byebye
so "space" have code 20. I think parsing not work not because of "space" between NTS: and ssdp:byebye, you drop all spaces in packet.
|
byebye messages are supposed to be properly parsed...
what is minissdpd logs when recieving packets ?
should be something like
Code: | minissdpd[3249]: SSDP request: 'NOTIFY' (2) ssdp:byebye nt=upnp:rootdevice |
_________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
alexey123
Joined: 05 Nov 2014 Posts: 8
|
Posted: Tue Dec 02, 2014 9:03 pm Post subject: |
|
|
It see byebye meessage from samsung, but not delete it from cache.
Also I see header "CACHE-control, you also calculate lifetime for cache in minissdpd.c : 577 as
Code: | r = updateDevice(headers, time(NULL) + lifetime); |
But I cannot find how to work cache-control by time - minissdpd must remove from cache outdated devices, isn't it? |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
© 2007 Thomas Bernard, author of MiniUPNP.
|