From owner-freebsd-net@freebsd.org  Thu Mar 22 23:39:33 2018
Return-Path: <owner-freebsd-net@freebsd.org>
Delivered-To: freebsd-net@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 44F01F53AC6
 for <freebsd-net@mailman.ysv.freebsd.org>;
 Thu, 22 Mar 2018 23:39:33 +0000 (UTC)
 (envelope-from ascherrer@gmail.com)
Received: from mail-wm0-x232.google.com (mail-wm0-x232.google.com
 [IPv6:2a00:1450:400c:c09::232])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (Client CN "smtp.gmail.com",
 Issuer "Google Internet Authority G2" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id C784C71EAF;
 Thu, 22 Mar 2018 23:39:32 +0000 (UTC)
 (envelope-from ascherrer@gmail.com)
Received: by mail-wm0-x232.google.com with SMTP id h76so539496wme.4;
 Thu, 22 Mar 2018 16:39:32 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=subject:to:references:from:cc:message-id:date:user-agent
 :mime-version:in-reply-to:content-language:content-transfer-encoding;
 bh=HG31GvAmgr1kUKTq6RP4xsqmcRLfHbdKRU+nY8DrBoQ=;
 b=CagM9zgMxxd5jlKvFP8aWN134klUjGSFugaB1g5YwdmWT9Zp3ipWxfwhAA+7c8Os/8
 tZzav8kPh4TofEeniRyYJnKhLuyJ4mGJg+K7OwEUs1fUebav6DJYPxOTI9o53s6OAHyH
 bHi9JP1yzcbJi1o0iCuDmaZ5OfhRyYTnv2uhkTB7raVgvn+wQapInn3eWchUJHP7d3uV
 FU03coCxoIpBWHHrm/yx9+DgCGVejkT/2gM44n+hiK0x0Psn4O5uw/sVsK6eqd8UY5Ei
 H1DmxHwE3hxwgYWGOQHFtHPTrkpNFEhJcwHpoGIPSOCtOr9cEy/Wne8H1359bF8ZwouX
 bHTw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:subject:to:references:from:cc:message-id:date
 :user-agent:mime-version:in-reply-to:content-language
 :content-transfer-encoding;
 bh=HG31GvAmgr1kUKTq6RP4xsqmcRLfHbdKRU+nY8DrBoQ=;
 b=qKAZ17VDNnY1im5FkwP/hGENXElktsT+n9lvfDthxEFeZuj+8dWZixHC0Acm1ILwoW
 MREI9M+s65a/ASHVjTtnOqUTgRnW9UQlJC3l2pDkLWINZawc3xW52bIWnx2QCVbV7sT0
 juhuaBwIfACT6FfnhhQXWQP17EK/hvYFSappAeyGA1oMlTcO/sFMmTtaEq/Q1S9qOSzG
 gCVBBGOF4nitFTmU5fWnzsmB6jT7Lkea2xX/woxb6XzeMSRRdR5FYv4v95Sq1La5BaUv
 mwhPsaaOGLXvpTJepTmU9jnCRuRUGhubdu3zIr8gE07bMCb33vnUb9IhuCPsn3PkGNRI
 EwKQ==
X-Gm-Message-State: AElRT7Fu9/MGNDX37ZKMWzADH46mXwCuZQRL9ias0QSWi3341MLJR95H
 aqmtG7oP37BzwZ0qVKkshXOFM/XC
X-Google-Smtp-Source: AG47ELsTcCRpBR/sZLKlR40PrVnNHE8uFbYgN9wNUzk1ye9o1M1NclrXNKX0r6tY6W8CEuvxx4z8IA==
X-Received: by 10.80.146.97 with SMTP id j30mr22141731eda.134.1521761971355;
 Thu, 22 Mar 2018 16:39:31 -0700 (PDT)
Received: from juntos.woohoo.ch ([2a02:168:681c:460:c1d6:42f5:a6b1:666e])
 by smtp.gmail.com with ESMTPSA id a88sm5577724edf.64.2018.03.22.16.39.29
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Thu, 22 Mar 2018 16:39:30 -0700 (PDT)
Subject: Re: Multicast/SSDP not working (on VLAN interface)
To: freebsd-net@freebsd.org
References: <201803220015.w2M0FFbg023791@pdx.rh.CN85.dnsmgr.net>
From: Andreas Scherrer <ascherrer@gmail.com>
Cc: sunpoet@FreeBSD.org
Message-ID: <bc610a15-e583-517f-3e58-8b9e2ef62b95@gmail.com>
Date: Fri, 23 Mar 2018 00:39:29 +0100
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0)
 Gecko/20100101 Thunderbird/52.6.0
MIME-Version: 1.0
In-Reply-To: <201803220015.w2M0FFbg023791@pdx.rh.CN85.dnsmgr.net>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: freebsd-net@freebsd.org
X-Mailman-Version: 2.1.25
Precedence: list
List-Id: Networking and TCP/IP with FreeBSD <freebsd-net.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-net>,
 <mailto:freebsd-net-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-net/>
List-Post: <mailto:freebsd-net@freebsd.org>
List-Help: <mailto:freebsd-net-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-net>,
 <mailto:freebsd-net-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 22 Mar 2018 23:39:33 -0000

@sunpoet@FreeBSD.org: as you are the (brand new?) maintainer of the 
miniDLNA port for FreeBSD, my hopes are with you :D

tl;dr
"setsockopt" should be replaced by "sourcefilter" (at least in 
minissdp.c's "AddMulticastMembership)

On 22.03.18 01:15, Rodney W. Grimes wrote:

...

> Try as a very first rules:
> 
> ipfw add 1 log allow ip from any to 224.0.0.0/4
> ipfw add 2 log allow ip from 224.0.0.0/4 to any
> 
> DO NOT put any restricting clauses on these.. if this makes things
> work simply move them down a few rules until you find the point
> at which things stop working.

I tried this; to no avail.

But it got me on the right track! MiniDLNA was actually (trying to) send 
IGMPv3 packets (224.0.0.22) back to the client but they were following 
the default route!

The problem is here (please excuse if I do not get all the terminology 
right, I am not a network programmer):

The function "AddMulticastMembership" in minissdp.c uses the "ip_mreqn" 
struct to call "setsockopt" for "IP_ADD_MEMBERSHIP".

It is trying to use an interface index "imr.imr_ifindex = 
iface->ifindex" in "ip_mreqn".

The code I am talking about can be found here:
https://sourceforge.net/p/minidlna/git/ci/master/tree/minissdp.c#l69

Using an interface index for "IP_ADD_MEMBERSHIP" is not supported (since 
FreeBSD 7.0):

-----
A host must become a member of a multicast group before it can receive
datagrams sent to the group. To join a multicast group, use the 
IP_ADD_MEMBERSHIP option:

struct ip_mreq mreq;
setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

where mreq is the following structure:

struct ip_mreq {
  struct   in_addr   imr_multiaddr; /* IP multicast address of group  */
  struct   in_addr   imr_interface; /* local IP address of interface  */
}

imr_interface should be set to the IP address of a particular multicast-
capable interface if the host is multihomed.  It may be set to 
INADDR_ANY to choose the default interface, although this is not 
recommended; this is considered to be the first interface corresponding 
to the default route. Otherwise, the first multicast-capable interface 
configured in the system will be used.

Prior to FreeBSD 7.0, if the imr_interface member is within the network
range 0.0.0.0/8, it is treated as an interface index in the system 
interface MIB, as per the RIP Version 2	MIB Extension (RFC-1724). In 
versions of FreeBSD since 7.0, this behavior is no longer supported. 
Developers should instead use the RFC 3678 multicast source filter APIs; 
in particular, MCAST_JOIN_GROUP.
-----

As documented here:
https://www.freebsd.org/cgi/man.cgi?query=ip&apropos=0&sektion=4&manpath=FreeBSD+11.1-RELEASE&arch=default&format=html

I have verified that things start to work when I forced the "other 
execution path" in "AddMulticastMembership" (using "ip_mreq" instead of 
"ip_mreqn"; I have achieved this by changing the "#ifdef 
HAVE_STRUCT_IP_MREQN" statement into it's negated form "#ifndef 
HAVE_STRUCT_IP_MREQN").

Unfortunately I am not qualified to (properly) fix this :(

I read the statement that MCAST_JOIN_GROUP should be used (meaning 
replace "setsockopt" with "sourcefilter", if I get that correctly). But 
I do not really understand what that means/how to do that.

https://www.freebsd.org/cgi/man.cgi?query=sourcefilter&apropos=0&sektion=3&manpath=FreeBSD+11.1-RELEASE&arch=default&format=html

If someone could point me in the right direction (a tutorial how 
"sourcefilter" must be used for example), I might be able to come up 
with something that can be developed into a proper patch. Of course, if 
someone can fix this right away, that would be even better.


Best regards
andreas