57 Commits

Author SHA1 Message Date
Justin Maggard
b4e55102af minissdp: Harden SSDP request parsing
Avoids a potential crash from malformed header.
2022-02-10 23:51:28 -08:00
Gleb Smirnoff
36b9136d2b Use newer IP_MULTICAST_IF API
Use newer API for IP_MULTICAST_IF which allows one to specify
interface by index, not by address. Introduced in Linux 3.5, it IMHO should
be available on all systems that declare struct ip_mreqn.

This fixes operation failure when a system has multiple interfaces
with same address, but only on of them is desired. Example:

> grep interface /usr/local/etc/minidlna.conf
network_interface=igb0
> ifconfig igb0
igb0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 0c:c4:7a:xx:xx:xx
        inet 10.1.10.3 netmask 0xffffff00 broadcast 10.1.10.255
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
> ifconfig ng0
ng0: flags=88d1<UP,POINTOPOINT,RUNNING,NOARP,SIMPLEX,MULTICAST> metric 0 mtu 1454
        inet 10.1.10.3 --> 10.1.10.2 netmask 0xffffffff

In such configuration, ng0 would be chosen before this fix.
2020-11-24 10:53:50 -08:00
Justin Maggard
9bb6cf5051 minissdp: Re-add SSDP filtering
Add back SSDP filtering.  Relying on the kernel to filter out multicast
traffic from non-member interfaces simply doesn't work the way many
people think it does, so we need to re-introduce manual filtering.  But
this time we will use in_pktinfo's ifindex for comparison rather than a
netmask comparison, so SSDP packets from other subnets should still work.
2018-01-16 17:12:20 -08:00
Gleb Smirnoff
f9a78d598e Support for pluggable event modules, stage 1. Take out select() loop and associated code into a separate module select.c. Detailed list of changes down below.
The idea is taken from the nginx web server, but much simplified and
almost no copypaste left. This will allow minidlna to use different
event dispatcher APIs, which would be defined at compile time.

My personal goal is to convert minidlna to kqueue(2) on FreeBSD. This
would later allow for kqueue based directory change notification, which
won't conflict with select(2) like the current patch does.
Other platforms will also benefit from the pluggability of the event
system, Linux can switch to epoll(2) or at least to poll(2).

Detailed list of changes:

* event.h [New]
  Our internal API to unify different event dispatch systems.
* select.c [New]
  Much simplified version of nginx's ngx_select_module.c.
* minidlna.c
  - Split out listen socket event processing into separate function
    ProcessListen(), which matches event_process_t type.
  - Create and initialize struct event for the monitor socket, SSDP
    socket, HTTP socket and beacon socket.
  - Simplify and make more precise timeout calculation using
    helper timeval functions from utils.c. Treat gettimeofday() error
    as a fatal event.
  - Rip out all stuff related to select(2). Just call event_module.process().
* upnpevents.c
  - Embed struct event into upnp_event_notify.
  - Merge upnp_event_create_notify() with upnp_event_notify_connect().
    Start connecting immediately after socket creation. Garbage collect
    now useless ECreated state.
  - Make upnp_event_process_notify() of event_process_t type, and use it
    as process callback for upnp_event_notify event.
  - Looks like we always create upnp_event_notify with existing subscriber,
    and never clear it later. Remove checks for obj->sub and assert that it
    is never NULL. Simplifies things.
  - When switching obj state, add/del it to event dispatcher accrodingly.
  - Garbage collect upnpevents_selectfds().
  - Garbage collect select(2) related stuff from upnpevents_processfds().
    Rename function to upnpevents_gc(), since the remaining functionality
    is garbage collecting, not file descriptor processing.
    Actually, this can be simplified even more. We can safely close sockets
    and free objects immediately, eliminating need for upnpevents_gc(). But
    this change would be beyond scope of this commit.
* upnphttp.c, upnphttp.h
  Embed struct event into struct upnphttp. Adjust Process_upnphttp() to match
  event_process_t type. Add/del to event dispatcher once creating/closing a
  socket.
* minissdp.c, minissdp.h
  Make ProcessSSDPRequest() of event_process_t type.
* getifaddr.c, getifaddr.h
  Make ProcessMonitorEvent() of event_process_t type.
2018-01-16 16:53:08 -08:00
Justin Maggard
33fd018828 minissdp: Delay before answering ssdp:all requests
With some device combinations, our responses may be lost if we don't
delay for some time.
2018-01-08 18:04:57 -08:00
ynilu
914ac12302 ssdp: Fix UDP sendto bug
The size of the client address may be modified by recfrom.
So, the last parameter of sendto should be the modified size.
2017-07-28 17:47:51 -07:00
Vladislav Grishenko
b0cd672abf ssdp: fix M-SEARCH replies on non-linux OS and drop broadcast receiving due no read
On Darwin & *BSD binding to mcast address may force NITIFY packet send from
 this mcast address, not from primary interface address. Therefore subsequent
 NOTIFY packets might be ignored by some clients, including Samsung Smart TV
 and they will stop & disconnect after initial max-age timeout.

 SO_BROADCAST on notify packets is not needed, because there's no broadcasted
 M-SEARCH packets and notify socket queue is never read.
2017-05-25 17:38:36 -07:00
Justin Maggard
1b75093a43 ssdp: Allow SSDP M-SEARCH from other subnets
Based on a patch from SF user pasdVn <pasdVn3@gmx.de>.

Rely on the kernel to filter out multicasts from non-member interfaces.
Also get the address of the interface we received the multicast on using
sockopt IP_PKTINFO.

Closes: SF Patch ticket #77.
2015-09-08 15:49:22 -07:00
Justin Maggard
13d36533b5 cleanup: Declare some unshared functions static. 2015-04-10 15:47:28 -07:00
Justin Maggard
e9a653d6e8 clients: restructure client cache 2014-06-09 18:02:03 -07:00
Justin Maggard
750917f7ea minissdp: fix minor uninitialized access 2014-04-25 17:13:07 -07:00
Justin Maggard
c6367aa4ce minissdp: fix potential out-of-bounds read 2014-04-11 12:31:32 -07:00
Justin Maggard
d492b43ef8 Fix various potential illegal access and memory leaks in error conditions. 2014-04-07 11:20:19 -07:00
Justin Maggard
6e43ab3c06 Introduce THISORNUL macro. 2014-04-07 10:29:56 -07:00
Justin Maggard
993a4adbbc ssdp: improve debug logging 2014-03-05 13:56:50 -08:00
Justin Maggard
6cef303fc1 try to ensure proper ownership of db_dir
If user has been set, try to ensure that db_dir is owned by that user.
If that fails, log an error.
2014-02-27 15:47:02 -08:00
Justin Maggard
4236d53b59 ssdp: add multicast membership as the individual interfaces come up
Previously, this was only done during startup, so interfaces that
came up later wouldn't have been added.
2014-02-26 15:09:21 -08:00
Justin Maggard
fe7c26da2f ssdp: send a full byebye + alive set when a new interface comes online
If an interface comes online after startup, we really need to send a
complete byebye + alive set on that interface, but we don't want to do
it for other interfaces.  So do it as the interfaces come up, and
skip it for interfaces that existed before the reload.
2014-02-26 15:04:46 -08:00
Justin Maggard
005cb0bd30 Fix uninitialized access when adding multicast membership.
Thanks Keith for pointing this out.
2014-02-18 10:39:43 -08:00
Justin Maggard
a3252bd2dd minissdp: Use struct ip_mreqn for multicast membership if it's available. 2014-02-03 15:02:30 -08:00
Justin Maggard
a21bbe557d Fix a couple file descriptor leaks. 2014-01-16 13:11:54 -08:00
Justin Maggard
e00d462a75 Add debug messages when sending ssdp:alive/ssdp:byebye packets. 2013-10-22 18:56:07 -07:00
Justin Maggard
07441e4e9a Silently ignore YOUKU-NOTIFY SSDP packets. 2013-06-10 22:43:03 -07:00
Justin Maggard
62b6e235b1 Don't require a configured network interface to start up, and add network interface monitoring support on Linux. 2013-05-08 23:52:02 -07:00
Justin Maggard
1c748c1d5a * Consolidate client detection code.
* Add forced sorting support for Panasonic devices.
2013-03-18 05:37:46 +00:00
Justin Maggard
11998204e2 * Code reformatting. 2013-02-04 20:23:49 +00:00
Justin Maggard
1de4ef8bc1 * Add configuration option to specify the user to run as. 2012-07-18 18:58:26 +00:00
Justin Maggard
ccc32409c5 * Change some --with options to --enable, and move ROOTDEV_* definitions to config.h. 2012-07-17 07:37:55 +00:00
Justin Maggard
f0c7768533 * Add a flag to tell ParseNameValue() to store empty XML elements. 2012-07-10 21:12:10 +00:00
Justin Maggard
61fbce18ba * Replace sqlite_int64 with int64_t in many places, to better allow for the possibility of other databases. (Thanks Douglas Carmichael) 2012-06-29 23:14:27 +00:00
Justin Maggard
ba7e33a062 * Add support for user-configurable log level settings. 2012-02-14 18:25:39 +00:00
Justin Maggard
cefe05677d * Use proper SSDP TTL of 4, instead of 1. 2012-02-13 22:39:54 +00:00
Justin Maggard
08172a4ed2 * Enhance error checking in some additional places as required by the latest UPnP CTT. 2012-01-21 01:00:26 +00:00
Justin Maggard
757eacc236 * Finalize version 1.0.22. 2011-08-25 01:27:56 +00:00
Justin Maggard
546175743a * Add WAV MIME workaround for Marantz Receivers and Roku SoundBridge.
* Fix bitrate displayed on Microsoft PFS devices.
2011-08-18 23:24:17 +00:00
Justin Maggard
052aa2613a * Fix memory leak in client detection code for a couple devices. 2011-08-10 00:40:26 +00:00
Justin Maggard
0b3295b701 * Use MiniSSDPd if it is available. (Thanks Thomas Bernard) 2011-07-22 23:03:38 +00:00
Justin Maggard
eff8bf22db * Fix FF/REW of AVI files on Samsung Series B TV's. 2011-07-11 20:01:42 +00:00
Justin Maggard
f6e3e0e8c1 * Only ignore bad source port SSDP requests if the strict DLNA flag is set. 2011-06-23 18:12:39 +00:00
Justin Maggard
4daad1291e * Fix a potential crash during parsing of SSDP alive packets. 2011-05-03 06:14:25 +00:00
Justin Maggard
9a9270cecf * Fix some issues reported by cppcheck. 2011-05-02 23:50:52 +00:00
Justin Maggard
ceeb9479be * Use more appropriate log levels for a couple messages. 2011-04-12 20:55:32 +00:00
Justin Maggard
07c5fd5dd6 * Add the ability to parse the root description of clients after they send an SSDP NOTIFY.
* Using this new capability, detect Roku SoundBridge clients.
2011-04-09 01:37:11 +00:00
Justin Maggard
fa056f590e * Ignore SSDP M-SEARCH packets from interfaces not in our list. 2011-03-15 02:20:58 +00:00
Justin Maggard
8e0fcd56f9 * Complete/clarify license information. 2010-11-11 23:48:14 +00:00
Justin Maggard
346ff6e293 * Add M3U/PLS music playlist support. 2010-01-13 21:15:26 +00:00
Justin Maggard
f3d9805d7b * Fix a potential buffer overflow in ProcessSSDPRequest(). 2009-10-09 01:13:07 +00:00
Justin Maggard
94989f8b15 * Take notifications back out of their own thread, and rely on select timeouts.
* Increment SystemUpdateID as necessary just before processing new HTTP requests.
2009-06-15 22:37:49 +00:00
Justin Maggard
27696edf6f * Move SSDP and TiVo beacon notifications to a separate thread. 2009-06-03 20:47:48 +00:00
Justin Maggard
c10c913b30 * Some fixes for the UPnP Device Validator. 2009-05-19 23:43:51 +00:00