From nobody Mon Apr 29 14:36:20 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VSmCD6L3Pz5JSMq for ; Mon, 29 Apr 2024 14:38:00 +0000 (UTC) (envelope-from dirkx@webweaving.org) Received: from weser.webweaving.org (weser.webweaving.org [148.251.234.232]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "weser.webweaving.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VSmCD2RDDz4Lc9 for ; Mon, 29 Apr 2024 14:38:00 +0000 (UTC) (envelope-from dirkx@webweaving.org) Authentication-Results: mx1.freebsd.org; none Received: from smtpclient.apple (fiber.static.cbizz.nl [185.142.248.117] (may be forged)) (authenticated bits=0) by weser.webweaving.org (8.17.1/8.17.1) with ESMTPA id 43TEaaBc012772; Mon, 29 Apr 2024 16:36:37 +0200 (CEST) (envelope-from dirkx@webweaving.org) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=webweaving.org; s=shared; t=1714401400; bh=uCgvF6Y2uDrxaK0L+CI40Mr65qKYP2+XafKFPUU2hUQ=; h=From:Subject:Date:In-Reply-To:Cc:To:References; b=RwrwBTf7QuHY2Sv8rn3uvzOjFuLInOtJ4uzt4GbhBFhVd7ix8vybvRIWi+HtVJNsf Qd+o7PjN/piogTu25M6L6F/SyJ62VE+7LxYb/U/ZbOR1Il7F5POsLHzfKxdftC6DRO k5xkcTcBIwS6+AFsJYhyScK7qr/Xo97/tZKmVOQU= X-Authentication-Warning: weser.webweaving.org: Host fiber.static.cbizz.nl [185.142.248.117] (may be forged) claimed to be smtpclient.apple From: Dirk-Willem van Gulik Message-Id: <2C4BC70A-750C-4E0F-B400-351CBBD6374B@webweaving.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_34D971FD-B2DA-4F26-B33F-055D8F4B9B9F" List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: Re: Multicast & Tunnel devices Date: Mon, 29 Apr 2024 16:36:20 +0200 In-Reply-To: <202404290109.43T19HKw071603@gndrsh.dnsmgr.net> Cc: FreeBSD Hackers To: "Rodney W. Grimes" References: <202404290109.43T19HKw071603@gndrsh.dnsmgr.net> X-Mailer: Apple Mail (2.3774.500.171.1.1) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (weser.webweaving.org [148.251.234.232]); Mon, 29 Apr 2024 16:36:40 +0200 (CEST) X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:24940, ipnet:148.251.0.0/16, country:DE] X-Rspamd-Queue-Id: 4VSmCD2RDDz4Lc9 --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 = 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 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

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=3D8043<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=3D128
= 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 = =3D argv[1]; 
   char* = group =3D argv[2]; 
   int = port =3D atoi(argv[3]); // 0 if error, which is an invalid = port

   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);

   mreq.imr_interface.s_addr =3D = inet_addr(ip); 
   mreq.im= r_multiaddr.s_addr =3D inet_addr(group);

// skip = error trapping on inet_addr

   int fd =3D = 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 =3D = recvfrom(fd,msgbuf,MSGBUFSIZE,0,(struct sockaddr *) = &addr,&addrlen);
       if = (nbytes < 0) = {
           per= ror("recvfrom");
         =   return = 1;
       }
= printf(?Received packet, len=3D%d\n", = nbytes);
    }


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