Bug #75721 [Com]: MCAST_JOIN_GROUP is broken for FreeBSD
| From: | jonathan at tangential dot ca | Date: | Fri, 22 Dec 2017 01:47:53 +0000 |
| Subject: | Bug #75721 [Com]: MCAST_JOIN_GROUP is broken for FreeBSD | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213237@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75721&edit=1
ID: 75721
Comment by: jonathan at tangential dot ca
Reported by: jonathan at tangential dot ca
Summary: MCAST_JOIN_GROUP is broken for FreeBSD
Status: Open
Type: Bug
Package: Sockets related
Operating System: FreeBSD 10.3
PHP Version: 7.0.26
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2017-12-22 01:17:28] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75721&edit=1