Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Apr 2024 16:36:20 +0200
From:      Dirk-Willem van Gulik <dirkx@webweaving.org>
To:        "Rodney W. Grimes" <freebsd-rwg@gndrsh.dnsmgr.net>
Cc:        FreeBSD Hackers <freebsd-hackers@FreeBSD.org>
Subject:   Re: Multicast & Tunnel devices
Message-ID:  <2C4BC70A-750C-4E0F-B400-351CBBD6374B@webweaving.org>
In-Reply-To: <202404290109.43T19HKw071603@gndrsh.dnsmgr.net>
References:  <202404290109.43T19HKw071603@gndrsh.dnsmgr.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_34D971FD-B2DA-4F26-B33F-055D8F4B9B9F
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii



> On 29 Apr 2024, at 03:09, Rodney W. Grimes =
<freebsd-rwg@gndrsh.dnsmgr.net> wrote:
>=20
>> Would anyone know if there is something special with tunnel devices =
and multicast ?=20
>>=20
>> I?ve got some code that happily processes multicast packets on a =
normal interface; but appears not to do this on a tunnel interface. Tun0 =
shows multicast enabled:
>> =09
>> 	tun0: flags=3D8043<UP,BROADCAST,RUNNING,MULTICAST> metric 0 mtu =
1500
>>=20
>> Tcpdump on that interface gives the expected thing (here with mDNS):
>>=20
>> 	tcpdump -n -i tun0 port 5353
>> 	listening on tun0, link-type NULL (BSD loopback), capture size =
262144 bytes
>> 	19:26:03.976259 IP 10.31.0.6.5353 > 224.0.0.251.5353: 0 PTR =
(QM)? _raop._tcp.local. (34)
>>=20
>> And code, with a simple IP_ADD_MEMBERSHIP  of the MC group on the IP =
of the local interface below works on a normal interface (e.g. =
igb0/10.0.0.1/24).=20
>>=20
>> 	./listener 10.0.0.1 224.0.0.251 5353
>=20
> Is 10.0.0.1 the IP address of tun0, or is it the address of some other =
interface?
> I suspect that the IP address of the tun0 interface is 10.31.0.6 from =
your tcpdump above.

That is correct 10.0.0.1/8. 10.31.0.6 is another machine at the other =
end of the tunnel broadcasting.

> IIRC you have to join multicast group on all interfaces you expect to =
receive mustcast packets on.
>=20
>> 	Received packet, len=3D128
>> 	etc
>>=20
>> But yields no output if ran against above tun0 interface (while =
tcpdump on same is fine). Does that ring a bell with anyone ?
>>=20
>> Dw
>>=20
>>=20
>> int main(int argc, char *argv[])
>> {
>>    struct sockaddr_in addr;
>>    struct ip_mreq mreq;
>>=20
>> 	// skip error trapping command line arguments
>>=20
>>    char* ip =3D argv[1];=20
>>    char* group =3D argv[2];=20
>>    int port =3D atoi(argv[3]); // 0 if error, which is an invalid =
port
>>=20
>>    memset(&addr, 0, sizeof(addr));
>>    addr.sin_family =3D AF_INET;
>>    addr.sin_addr.s_addr =3D htonl(INADDR_ANY);
>>    addr.sin_port =3D htons(port);
>>=20
>>    mreq.imr_interface.s_addr =3D inet_addr(ip);=20
>>    mreq.imr_multiaddr.s_addr =3D inet_addr(group);
>>=20
>> 	// skip error trapping on inet_addr
>>=20
>>    int fd =3D socket(AF_INET, SOCK_DGRAM, 0);
>> 	// skip error trapping socket
>>=20
>>    if (bind(fd, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
>> 	// skip error trapping
>>=20
>>    if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &mreq, =
sizeof(mreq)) < 0 ){
>> 	// skip error trapping argumetns
>>=20
>>    while (1) {
>> 	..
>>        int nbytes =3D recvfrom(fd,msgbuf,MSGBUFSIZE,0,(struct =
sockaddr *) &addr,&addrlen);
>>        if (nbytes < 0) {
>>            perror("recvfrom");
>>            return 1;
>>        }
>> 	printf(?Received packet, len=3D%d\n", nbytes);
>>     }
>>=20


--Apple-Mail=_34D971FD-B2DA-4F26-B33F-055D8F4B9B9F
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; =
charset=3Dus-ascii"></head><body style=3D"overflow-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;"><br =
id=3D"lineBreakAtBeginningOfMessage"><div><br><blockquote =
type=3D"cite"><div>On 29 Apr 2024, at 03:09, Rodney W. Grimes =
&lt;freebsd-rwg@gndrsh.dnsmgr.net&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div><meta =
charset=3D"UTF-8"><blockquote type=3D"cite" style=3D"font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; orphans: auto; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;">Would anyone know if there is something special =
with tunnel devices and multicast ?<span =
class=3D"Apple-converted-space">&nbsp;</span><br><br>I?ve got some code =
that happily processes multicast packets on a normal interface; but =
appears not to do this on a tunnel interface. Tun0 shows multicast =
enabled:<br><span class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span><br><span class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>tun0: flags=3D8043&lt;UP,BROADCAST,RUNNING,MULTICAST&gt; metric 0 =
mtu 1500<br><br>Tcpdump on that interface gives the expected thing (here =
with mDNS):<br><br><span class=3D"Apple-tab-span" style=3D"white-space: =
pre;">	</span>tcpdump -n -i tun0 port 5353<br><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>listening =
on tun0, link-type NULL (BSD loopback), capture size 262144 =
bytes<br><span class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>19:26:03.976259 IP 10.31.0.6.5353 &gt; 224.0.0.251.5353: 0 PTR =
(QM)? _raop._tcp.local. (34)<br><br>And code, with a simple =
IP_ADD_MEMBERSHIP &nbsp;of the MC group on the IP of the local interface =
below works on a normal interface (e.g. igb0/10.0.0.1/24).<span =
class=3D"Apple-converted-space">&nbsp;</span><br><br><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>./listener 10.0.0.1 224.0.0.251 5353<br></blockquote><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">Is 10.0.0.1 the IP address of tun0, or is =
it the address of some other interface?</span><br style=3D"caret-color: =
rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: =
normal; font-variant-caps: normal; font-weight: 400; letter-spacing: =
normal; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;"></div></blockquote><div><blockquote =
type=3D"cite">I suspect that the IP address of the tun0 interface is =
10.31.0.6 from your tcpdump above.<br></blockquote><br></div>That is =
correct 10.0.0.1/8. 10.31.0.6 is another machine at the other end of the =
tunnel broadcasting.</div><div><br></div><div><blockquote =
type=3D"cite"><div><span style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;">IIRC =
you have to join multicast group on all interfaces you expect to receive =
mustcast packets on.</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;"><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;"><blockquote type=3D"cite" style=3D"font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; orphans: auto; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;"><span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span>Received packet, len=3D128<br><span=
 class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>etc<br><br>But yields no output if ran against above tun0 =
interface (while tcpdump on same is fine). Does that ring a bell with =
anyone ?<br><br>Dw<br><br><br>int main(int argc, char =
*argv[])<br>{<br>&nbsp;&nbsp;&nbsp;struct sockaddr_in =
addr;<br>&nbsp;&nbsp;&nbsp;struct ip_mreq mreq;<br><br><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>// skip =
error trapping command line arguments<br><br>&nbsp;&nbsp;&nbsp;char* ip =
=3D argv[1];<span =
class=3D"Apple-converted-space">&nbsp;</span><br>&nbsp;&nbsp;&nbsp;char* =
group =3D argv[2];<span =
class=3D"Apple-converted-space">&nbsp;</span><br>&nbsp;&nbsp;&nbsp;int =
port =3D atoi(argv[3]); // 0 if error, which is an invalid =
port<br><br>&nbsp;&nbsp;&nbsp;memset(&amp;addr, 0, =
sizeof(addr));<br>&nbsp;&nbsp;&nbsp;addr.sin_family =3D =
AF_INET;<br>&nbsp;&nbsp;&nbsp;addr.sin_addr.s_addr =3D =
htonl(INADDR_ANY);<br>&nbsp;&nbsp;&nbsp;addr.sin_port =3D =
htons(port);<br><br>&nbsp;&nbsp;&nbsp;mreq.imr_interface.s_addr =3D =
inet_addr(ip);<span =
class=3D"Apple-converted-space">&nbsp;</span><br>&nbsp;&nbsp;&nbsp;mreq.im=
r_multiaddr.s_addr =3D inet_addr(group);<br><br><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>// skip =
error trapping on inet_addr<br><br>&nbsp;&nbsp;&nbsp;int fd =3D =
socket(AF_INET, SOCK_DGRAM, 0);<br><span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span>// skip error trapping =
socket<br><br>&nbsp;&nbsp;&nbsp;if (bind(fd, (struct sockaddr*) =
&amp;addr, sizeof(addr)) &lt; 0) {<br><span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span>// skip error =
trapping<br><br>&nbsp;&nbsp;&nbsp;if (setsockopt(fd, IPPROTO_IP, =
IP_ADD_MEMBERSHIP, (char*) &amp;mreq, sizeof(mreq)) &lt; 0 ){<br><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>// skip =
error trapping argumetns<br><br>&nbsp;&nbsp;&nbsp;while (1) {<br><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>..<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int nbytes =3D =
recvfrom(fd,msgbuf,MSGBUFSIZE,0,(struct sockaddr *) =
&amp;addr,&amp;addrlen);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if =
(nbytes &lt; 0) =
{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;per=
ror("recvfrom");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;return =
1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>printf(?Received packet, len=3D%d\n", =
nbytes);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br></blockquote></div></blockquo=
te></div><br></body></html>=

--Apple-Mail=_34D971FD-B2DA-4F26-B33F-055D8F4B9B9F--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2C4BC70A-750C-4E0F-B400-351CBBD6374B>