php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75721 MCAST_JOIN_GROUP is broken for FreeBSD
Submitted: 2017-12-22 01:17 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: jonathan at tangential dot ca Assigned:
Status: Open Package: Sockets related
PHP Version: 7.0.26 OS: FreeBSD 10.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jonathan at tangential dot ca
New email:
PHP Version: OS:

 

 [2017-12-22 01:17 UTC] jonathan at tangential dot ca
Description:
------------
FreeBSD supports listening on/joining both IPv4 and IPv6 multicast groups. However, it handles full RFC 3678 support (including IPv6) via a different interface (setsourcefilter vs setsockopt).

In order to properly support multicast on FreeBSD (including IPv6 support), one would have to (conditionally) use setsourcefilter instead of setsockopt (throughout much of ext/sockets/multicast.c).

Since I don't have the requirement or will to implement this with FreeBSD's newer protocol agnostic sourcefilter APIs, I've chosen to take the easy way out and just make it work with IPv4 only.

This bug report should likely be split into two bugs as I've only addressed the IPv4 case for now.

I've included versions that correspond to my environment. However, this is far more generally applicable.

This bug is the FreeBSD variant/equivalent of bug #63000 (which was for macOS).

Please see the following FreeBSD documentation references (for details on FreeBSD's multicast support):

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

Test script:
---------------
<?php

// This just listens for MDNS traffic. You could optionally dispatch a query if your test network doesn't have a bunch of MDNS traffic

$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (!socket_set_option($socket, IPPROTO_IP, MCAST_JOIN_GROUP, array('group' => '224.0.0.251', 'interface' => 0))) {
	echo socket_strerror(socket_last_error());
}
socket_set_option($socket, SOL_SOCKET, SO_REUSEPORT, 1);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 10, 'usec' => 0]);
socket_bind($socket, '0.0.0.0', 5353);

// socket_sendto($socket, $data, strlen($data), 0, '224.0.0.251', 5353);

$response = socket_read($socket, 1024, PHP_BINARY_READ);
var_dump($response);

Expected result:
----------------
true (and actually seeing multicast packets destined for the requested group address)

Actual result:
--------------
false (with a pass-through error message referencing code [22]/EINVAL)

Patches

FreeBSD-use-IP_ADD_MEMBERSHIP.patch (last revision 2017-12-22 01:18 UTC by jonathan at tangential dot ca)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-22 01:47 UTC] jonathan at tangential dot ca
It looks like FreeBSD does actually support RFC 3678 via setsockopt (See `sys/netinet/in_mcast.c`). However, it did not work for me until I rebuilt the sockets module so that it uses the `IP_ADD_MEMBERSHIP`/IP_DROP_MEMBERSHIP` flags instead. I may have to see whether I can reproduce the issue in another jail.
 [2023-11-22 23:27 UTC] j dot david dot lists at gmail dot com
This remains an issue with FreeBSD 13+ and PHP 8.2 and 8.3 in 2023.  This patch made multicast work for us.  Without it, PHP just gives "Invalid argument" for MCAST_JOIN_GROUP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC