Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/sockets: UDP_SEGMENT support. #18213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/sockets/config.m4
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ PHP_ARG_ENABLE([sockets],

if test "$PHP_SOCKETS" != "no"; then
AC_CHECK_FUNCS([hstrerror if_nametoindex if_indextoname sockatmark])
AC_CHECK_HEADERS([sys/sockio.h linux/filter.h linux/if_packet.h linux/if_ether.h])
AC_CHECK_HEADERS([sys/sockio.h linux/filter.h linux/if_packet.h linux/if_ether.h linux/udp.h])
AC_DEFINE([HAVE_SOCKETS], [1],
[Define to 1 if the PHP extension 'sockets' is available.])

19 changes: 19 additions & 0 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
@@ -70,6 +70,9 @@
# if defined(HAVE_LINUX_IF_ETHER_H)
# include <linux/if_ether.h>
# endif
# if defined(HAVE_LINUX_UDP_H)
# include <linux/udp.h>
# endif
#endif

#include <stddef.h>
@@ -2300,6 +2303,22 @@ PHP_FUNCTION(socket_set_option)
}
#endif

#if defined(UDP_SEGMENT)
case UDP_SEGMENT: {
ov = zval_get_long(arg4);

// UDP segmentation offload maximum size or 0 to disable it
if (ov < 0 || ov > USHRT_MAX) {
zend_argument_value_error(4, "must be of between 0 and %u", USHRT_MAX);
RETURN_FALSE;
}

optlen = sizeof(ov);
opt_ptr = &ov;
break;
}
#endif

default:
default_case:
ov = zval_get_long(arg4);
8 changes: 8 additions & 0 deletions ext/sockets/sockets.stub.php
Original file line number Diff line number Diff line change
@@ -2022,6 +2022,14 @@
const ETH_P_ALL = UNKNOWN;
#endif

#ifdef UDP_SEGMENT
/**
* @var int
* @cvalue UDP_SEGMENT
*/
const UDP_SEGMENT = UNKNOWN;
#endif

/**
* @strict-properties
* @not-serializable
5 changes: 4 additions & 1 deletion ext/sockets/sockets_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions ext/sockets/tests/socket_cmsg_udp_segment.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
UDP_SEGMENT setsockopt(), can't really test is as the kernel support might not be enabled.
--EXTENSIONS--
sockets
--SKIPIF--
<?php
if (!defined('UDP_SEGMENT')) { die('skip UDP_SEGMENT is not defined'); }
?>
--FILE--
<?php
$src = socket_create(AF_UNIX, SOCK_DGRAM, 0);

try {
socket_setopt($src, SOL_UDP, UDP_SEGMENT, -1);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
socket_setopt($src, SOL_UDP, UDP_SEGMENT, 65536);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
socket_setopt(): Argument #4 ($value) must be of between 0 and 65535
socket_setopt(): Argument #4 ($value) must be of between 0 and 65535