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
[-- Attachment #1 --]
> On 29 Apr 2024, at 03:09, Rodney W. Grimes <freebsd-rwg@gndrsh.dnsmgr.net> wrote:
>
>> Would anyone know if there is something special with tunnel devices and multicast ?
>>
>> 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:
>>
>> tun0: flags=8043<UP,BROADCAST,RUNNING,MULTICAST> metric 0 mtu 1500
>>
>> Tcpdump on that interface gives the expected thing (here with mDNS):
>>
>> 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)
>>
>> 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).
>>
>> ./listener 10.0.0.1 224.0.0.251 5353
>
> 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.
>
>> Received packet, len=128
>> etc
>>
>> But yields no output if ran against above tun0 interface (while tcpdump on same is fine). Does that ring a bell with anyone ?
>>
>> Dw
>>
>>
>> int main(int argc, char *argv[])
>> {
>> struct sockaddr_in addr;
>> struct ip_mreq mreq;
>>
>> // skip error trapping command line arguments
>>
>> char* ip = argv[1];
>> char* group = argv[2];
>> int port = atoi(argv[3]); // 0 if error, which is an invalid port
>>
>> memset(&addr, 0, sizeof(addr));
>> addr.sin_family = AF_INET;
>> addr.sin_addr.s_addr = htonl(INADDR_ANY);
>> addr.sin_port = htons(port);
>>
>> mreq.imr_interface.s_addr = inet_addr(ip);
>> mreq.imr_multiaddr.s_addr = inet_addr(group);
>>
>> // skip error trapping on inet_addr
>>
>> int fd = socket(AF_INET, SOCK_DGRAM, 0);
>> // skip error trapping socket
>>
>> if (bind(fd, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
>> // skip error trapping
>>
>> if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &mreq, sizeof(mreq)) < 0 ){
>> // skip error trapping argumetns
>>
>> while (1) {
>> ..
>> int nbytes = recvfrom(fd,msgbuf,MSGBUFSIZE,0,(struct sockaddr *) &addr,&addrlen);
>> if (nbytes < 0) {
>> perror("recvfrom");
>> return 1;
>> }
>> printf(?Received packet, len=%d\n", nbytes);
>> }
>>
[-- Attachment #2 --]
<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On 29 Apr 2024, at 03:09, Rodney W. Grimes <freebsd-rwg@gndrsh.dnsmgr.net> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><blockquote type="cite" style="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="Apple-converted-space"> </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="Apple-tab-span" style="white-space: pre;"> </span><br><span class="Apple-tab-span" style="white-space: pre;"> </span>tun0: flags=8043<UP,BROADCAST,RUNNING,MULTICAST> metric 0 mtu 1500<br><br>Tcpdump on that interface gives the expected thing (here with mDNS):<br><br><span class="Apple-tab-span" style="white-space: pre;"> </span>tcpdump -n -i tun0 port 5353<br><span class="Apple-tab-span" style="white-space: pre;"> </span>listening on tun0, link-type NULL (BSD loopback), capture size 262144 bytes<br><span class="Apple-tab-span" style="white-space: pre;"> </span>19:26:03.976259 IP 10.31.0.6.5353 > 224.0.0.251.5353: 0 PTR (QM)? _raop._tcp.local. (34)<br><br>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).<span class="Apple-converted-space"> </span><br><br><span class="Apple-tab-span" style="white-space: pre;"> </span>./listener 10.0.0.1 224.0.0.251 5353<br></blockquote><br style="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="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="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="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="cite"><div><span style="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="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="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="cite" style="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="Apple-tab-span" style="white-space: pre;"> </span>Received packet, len=128<br><span class="Apple-tab-span" style="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> struct sockaddr_in addr;<br> struct ip_mreq mreq;<br><br><span class="Apple-tab-span" style="white-space: pre;"> </span>// skip error trapping command line arguments<br><br> char* ip = argv[1];<span class="Apple-converted-space"> </span><br> char* group = argv[2];<span class="Apple-converted-space"> </span><br> int port = atoi(argv[3]); // 0 if error, which is an invalid port<br><br> memset(&addr, 0, sizeof(addr));<br> addr.sin_family = AF_INET;<br> addr.sin_addr.s_addr = htonl(INADDR_ANY);<br> addr.sin_port = htons(port);<br><br> mreq.imr_interface.s_addr = inet_addr(ip);<span class="Apple-converted-space"> </span><br> mreq.imr_multiaddr.s_addr = inet_addr(group);<br><br><span class="Apple-tab-span" style="white-space: pre;"> </span>// skip error trapping on inet_addr<br><br> int fd = socket(AF_INET, SOCK_DGRAM, 0);<br><span class="Apple-tab-span" style="white-space: pre;"> </span>// skip error trapping socket<br><br> if (bind(fd, (struct sockaddr*) &addr, sizeof(addr)) < 0) {<br><span class="Apple-tab-span" style="white-space: pre;"> </span>// skip error trapping<br><br> if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &mreq, sizeof(mreq)) < 0 ){<br><span class="Apple-tab-span" style="white-space: pre;"> </span>// skip error trapping argumetns<br><br> while (1) {<br><span class="Apple-tab-span" style="white-space: pre;"> </span>..<br> int nbytes = recvfrom(fd,msgbuf,MSGBUFSIZE,0,(struct sockaddr *) &addr,&addrlen);<br> if (nbytes < 0) {<br> perror("recvfrom");<br> return 1;<br> }<br><span class="Apple-tab-span" style="white-space: pre;"> </span>printf(?Received packet, len=%d\n", nbytes);<br> }<br><br></blockquote></div></blockquote></div><br></body></html>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2C4BC70A-750C-4E0F-B400-351CBBD6374B>
