jcorporation / myMPD

myMPD is a standalone and mobile friendly web mpd client with a tiny footprint and advanced features.
https://jcorporation.github.io/myMPD/
GNU General Public License v3.0
419 stars 65 forks source link

Missing AF_NETLINK in RestrictAddressFamilies #716

Closed lbschenkel closed 2 years ago

lbschenkel commented 2 years ago

myMPD version: 9.2.2

Cannot queue radio playlists.

The problem is because in my system (Debian testing) the following call fails: https://github.com/jcorporation/myMPD/blob/0b2a55f9b6452f9fa0ea50af201448c03291259d/src/mympd_api/mympd_api_utility.c#L56 with errno=EAFNOSUPPORT (Address family not supported by protocol), and then:

  1. get_local_ip() returns an empy string to the caller
  2. the URL of the playlist is generated with an empty host: https://github.com/jcorporation/myMPD/blob/0b2a55f9b6452f9fa0ea50af201448c03291259d/src/mympd_api/mympd_api_utility.c#L168
  3. MPD fails to resolve the URL:
    mpd[140]: client: [18] process command "load "http://:80/browse/webradios/...""
    mpd[140]: exception: CURL failed: URL using bad/illegal format or missing URL
    mpd[140]: exception: No such playlist
  4. The following is logged by myMPD:
    mympd[2129]: ERROR    mympdapi  Can not get list of inteface ip addresses
    mympd[2129]: ERROR    mympdapi  Address family not supported by protocol
    mympd[2129]: ERROR    mympdapi  MPD error: No such playlist (9)
    mympd[2129]: ERROR    mympdapi  Error in response to command mpd_run_load

The reason for getifaddrs failing with EAFNOSUPPORT is because the systemd unit file does not include AF_NETLINK in RestrictAddressFamilies: https://github.com/jcorporation/myMPD/blob/0b2a55f9b6452f9fa0ea50af201448c03291259d/contrib/initscripts/mympd.service.in#L22

Apparently this is necessary to enumerate interfaces. Once it is included:

RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK

then the problem goes away and myMPD can auto-detect its own IP and generate well-formed URLs with its own IP in the host field.

jcorporation commented 2 years ago

A bug report with a fix included - great!

lbschenkel commented 2 years ago

Thanks. I would like to add that I found out about myMPD just yesterday and I wish I knew about it sooner, it is exactly what I was looking for. Great project.