2018-10-31 22:59:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/inet/ipv6_setsockopt.c
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-10-31 22:59:05 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-10-31 22:59:05 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-10-31 22:59:05 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
2018-11-01 00:15:23 +01:00
|
|
|
#include <debug.h>
|
2018-10-31 22:59:05 +01:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
|
net:add IP_MULTICAST_IF & IPV6_MULTICAST_IF function implementation
refer to https://man7.org/linux/man-pages/man7/ip.7.html
IP_MULTICAST_IF (since Linux 1.2)
Set the local device for a multicast socket. The argument
for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
in_addr structure. (The kernel determines which structure
is being passed based on the size passed in optlen.) For
getsockopt(2), the argument is an in_addr structure.
refer to https://man7.org/linux/man-pages/man7/ipv6.7.html
IPV6_MULTICAST_IF
Set the device for outgoing multicast packets on the
socket. This is allowed only for SOCK_DGRAM and SOCK_RAW
socket. The argument is a pointer to an interface index
(see netdevice(7)) in an integer.
testcase1:
TEST_IMPL(udp_multicast_interface) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in addr;
struct sockaddr_in baddr;
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip4_addr("239.255.0.1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "0.0.0.0");
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
ASSERT(client.send_queue_size == 0);
ASSERT(server.send_queue_size == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}
testcase2:
TEST_IMPL(udp_multicast_interface6) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in6 addr;
struct sockaddr_in6 baddr;
if (!can_ipv6())
RETURN_SKIP("IPv6 not supported");
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip6_addr("::1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip6_addr("::", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "::1%lo0");
r = uv_udp_set_multicast_interface(&server, NULL);
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
MAKE_VALGRIND_HAPPY();
return 0;
}
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-21 04:49:02 +02:00
|
|
|
#include "netdev/netdev.h"
|
2018-11-02 19:06:57 +01:00
|
|
|
#include "mld/mld.h"
|
2018-10-31 22:59:05 +01:00
|
|
|
#include "inet/inet.h"
|
2023-04-21 11:42:57 +02:00
|
|
|
#include "socket/socket.h"
|
net:add IP_MULTICAST_IF & IPV6_MULTICAST_IF function implementation
refer to https://man7.org/linux/man-pages/man7/ip.7.html
IP_MULTICAST_IF (since Linux 1.2)
Set the local device for a multicast socket. The argument
for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
in_addr structure. (The kernel determines which structure
is being passed based on the size passed in optlen.) For
getsockopt(2), the argument is an in_addr structure.
refer to https://man7.org/linux/man-pages/man7/ipv6.7.html
IPV6_MULTICAST_IF
Set the device for outgoing multicast packets on the
socket. This is allowed only for SOCK_DGRAM and SOCK_RAW
socket. The argument is a pointer to an interface index
(see netdevice(7)) in an integer.
testcase1:
TEST_IMPL(udp_multicast_interface) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in addr;
struct sockaddr_in baddr;
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip4_addr("239.255.0.1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "0.0.0.0");
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
ASSERT(client.send_queue_size == 0);
ASSERT(server.send_queue_size == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}
testcase2:
TEST_IMPL(udp_multicast_interface6) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in6 addr;
struct sockaddr_in6 baddr;
if (!can_ipv6())
RETURN_SKIP("IPv6 not supported");
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip6_addr("::1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip6_addr("::", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "::1%lo0");
r = uv_udp_set_multicast_interface(&server, NULL);
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
MAKE_VALGRIND_HAPPY();
return 0;
}
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-21 04:49:02 +02:00
|
|
|
#include "udp/udp.h"
|
2018-10-31 22:59:05 +01:00
|
|
|
|
2023-04-21 11:42:57 +02:00
|
|
|
#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NET_SOCKOPTS)
|
2018-10-31 22:59:05 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ipv6_setsockopt
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* ipv6_setsockopt() sets the IPv6-protocol socket option specified by the
|
|
|
|
* 'option' argument to the value pointed to by the 'value' argument for
|
|
|
|
* the socket specified by the 'psock' argument.
|
|
|
|
*
|
|
|
|
* See <netinet/in.h> for the a complete list of values of IPv6 protocol
|
|
|
|
* socket options.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock Socket structure of socket to operate on
|
|
|
|
* option identifies the option to set
|
|
|
|
* value Points to the argument value
|
|
|
|
* value_len The length of the argument value
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Returns zero (OK) on success. On failure, it returns a negated errno
|
|
|
|
* value to indicate the nature of the error. See psock_setcockopt() for
|
|
|
|
* the list of possible error values.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int ipv6_setsockopt(FAR struct socket *psock, int option,
|
|
|
|
FAR const void *value, socklen_t value_len)
|
|
|
|
{
|
2018-11-01 00:15:23 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ninfo("option: %d\n", option);
|
|
|
|
|
2023-05-12 09:44:27 +02:00
|
|
|
if (value == NULL || value_len == 0)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-11-03 23:47:08 +01:00
|
|
|
net_lock();
|
2018-10-31 22:59:05 +01:00
|
|
|
switch (option)
|
|
|
|
{
|
2022-12-21 05:40:42 +01:00
|
|
|
#ifdef CONFIG_NET_MLD
|
|
|
|
|
|
|
|
/* Handle MLD-related socket options */
|
|
|
|
|
2018-10-31 22:59:05 +01:00
|
|
|
case IPV6_JOIN_GROUP: /* Join a multicast group */
|
2023-05-12 09:44:27 +02:00
|
|
|
ret = mld_joingroup(value);
|
2018-11-02 19:06:57 +01:00
|
|
|
break;
|
|
|
|
|
2018-10-31 22:59:05 +01:00
|
|
|
case IPV6_LEAVE_GROUP: /* Quit a multicast group */
|
2023-05-12 09:44:27 +02:00
|
|
|
ret = mld_leavegroup(value);
|
2018-11-02 19:06:57 +01:00
|
|
|
break;
|
|
|
|
|
2023-05-12 09:28:24 +02:00
|
|
|
case IPV6_MULTICAST_HOPS: /* Multicast hop limit */
|
|
|
|
{
|
2023-05-12 09:44:27 +02:00
|
|
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
2023-05-12 09:28:24 +02:00
|
|
|
|
2023-05-12 09:44:27 +02:00
|
|
|
conn->ttl = (value_len >= sizeof(int)) ?
|
|
|
|
*(FAR int *)value : (int)*(FAR unsigned char *)value;
|
2023-05-12 09:28:24 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-12-21 05:40:42 +01:00
|
|
|
case IPV6_MULTICAST_IF: /* Interface to use for outgoing multicast
|
|
|
|
* packets */
|
net:add IP_MULTICAST_IF & IPV6_MULTICAST_IF function implementation
refer to https://man7.org/linux/man-pages/man7/ip.7.html
IP_MULTICAST_IF (since Linux 1.2)
Set the local device for a multicast socket. The argument
for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
in_addr structure. (The kernel determines which structure
is being passed based on the size passed in optlen.) For
getsockopt(2), the argument is an in_addr structure.
refer to https://man7.org/linux/man-pages/man7/ipv6.7.html
IPV6_MULTICAST_IF
Set the device for outgoing multicast packets on the
socket. This is allowed only for SOCK_DGRAM and SOCK_RAW
socket. The argument is a pointer to an interface index
(see netdevice(7)) in an integer.
testcase1:
TEST_IMPL(udp_multicast_interface) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in addr;
struct sockaddr_in baddr;
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip4_addr("239.255.0.1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "0.0.0.0");
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
ASSERT(client.send_queue_size == 0);
ASSERT(server.send_queue_size == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}
testcase2:
TEST_IMPL(udp_multicast_interface6) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in6 addr;
struct sockaddr_in6 baddr;
if (!can_ipv6())
RETURN_SKIP("IPv6 not supported");
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip6_addr("::1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip6_addr("::", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "::1%lo0");
r = uv_udp_set_multicast_interface(&server, NULL);
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
MAKE_VALGRIND_HAPPY();
return 0;
}
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-21 04:49:02 +02:00
|
|
|
#ifdef NET_UDP_HAVE_STACK
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR struct udp_conn_s *conn = psock->s_conn;
|
|
|
|
int ifindex = *(FAR int *)value;
|
|
|
|
|
|
|
|
if (ifindex > 0)
|
|
|
|
{
|
|
|
|
dev = netdev_findbyindex(ifindex);
|
|
|
|
if (dev == NULL)
|
|
|
|
{
|
|
|
|
ret = -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_BINDTODEVICE
|
|
|
|
if (conn->sconn.s_boundto &&
|
|
|
|
ifindex != conn->sconn.s_boundto)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->mreq.imr_ifindex = ifindex;
|
|
|
|
|
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
}
|
2024-03-27 04:26:14 +01:00
|
|
|
#endif /* NET_UDP_HAVE_STACK */
|
|
|
|
#endif /* CONFIG_NET_MLD */
|
net:add IP_MULTICAST_IF & IPV6_MULTICAST_IF function implementation
refer to https://man7.org/linux/man-pages/man7/ip.7.html
IP_MULTICAST_IF (since Linux 1.2)
Set the local device for a multicast socket. The argument
for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
in_addr structure. (The kernel determines which structure
is being passed based on the size passed in optlen.) For
getsockopt(2), the argument is an in_addr structure.
refer to https://man7.org/linux/man-pages/man7/ipv6.7.html
IPV6_MULTICAST_IF
Set the device for outgoing multicast packets on the
socket. This is allowed only for SOCK_DGRAM and SOCK_RAW
socket. The argument is a pointer to an interface index
(see netdevice(7)) in an integer.
testcase1:
TEST_IMPL(udp_multicast_interface) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in addr;
struct sockaddr_in baddr;
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip4_addr("239.255.0.1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "0.0.0.0");
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
ASSERT(client.send_queue_size == 0);
ASSERT(server.send_queue_size == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}
testcase2:
TEST_IMPL(udp_multicast_interface6) {
/* TODO(gengjiawen): Fix test on QEMU. */
RETURN_SKIP("Test does not currently work in QEMU");
int r;
uv_udp_send_t req;
uv_buf_t buf;
struct sockaddr_in6 addr;
struct sockaddr_in6 baddr;
if (!can_ipv6())
RETURN_SKIP("IPv6 not supported");
close_cb_called = 0;
sv_send_cb_called = 0;
ASSERT(0 == uv_ip6_addr("::1", TEST_PORT, &addr));
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT(0 == uv_ip6_addr("::", 0, &baddr));
r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_interface(&server, "::1%lo0");
r = uv_udp_set_multicast_interface(&server, NULL);
ASSERT(r == 0);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req,
&server,
&buf,
1,
(const struct sockaddr*)&addr,
sv_send_cb);
ASSERT(r == 0);
ASSERT(close_cb_called == 0);
ASSERT(sv_send_cb_called == 0);
/* run the loop till all events are processed */
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(sv_send_cb_called == 1);
ASSERT(close_cb_called == 1);
MAKE_VALGRIND_HAPPY();
return 0;
}
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-21 04:49:02 +02:00
|
|
|
|
|
|
|
/* The following IPv6 socket options are defined, but not implemented */
|
|
|
|
|
2022-12-21 05:40:42 +01:00
|
|
|
case IPV6_V6ONLY: /* Restrict AF_INET6 socket to IPv6
|
|
|
|
* communications only */
|
|
|
|
nwarn("WARNING: Unimplemented IPv6 option: %d\n", option);
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
|
2023-05-12 09:28:24 +02:00
|
|
|
case IPV6_UNICAST_HOPS: /* Unicast hop limit */
|
|
|
|
{
|
2023-05-12 09:44:27 +02:00
|
|
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
2023-05-12 09:28:24 +02:00
|
|
|
|
2023-05-12 09:44:27 +02:00
|
|
|
conn->ttl = (value_len >= sizeof(int)) ?
|
|
|
|
*(FAR int *)value : (int)*(FAR unsigned char *)value;
|
2023-05-12 09:28:24 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-03-27 04:26:14 +01:00
|
|
|
#ifdef CONFIG_NET_MLD
|
|
|
|
case IPV6_MULTICAST_LOOP: /* Multicast packets are delivered back to
|
|
|
|
* the local application */
|
|
|
|
#endif
|
2022-08-24 08:55:56 +02:00
|
|
|
case IPV6_RECVPKTINFO:
|
2023-04-14 12:11:12 +02:00
|
|
|
case IPV6_RECVHOPLIMIT:
|
2022-08-24 08:55:56 +02:00
|
|
|
{
|
2023-05-12 09:44:27 +02:00
|
|
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
|
|
|
int enable = (value_len >= sizeof(int)) ?
|
|
|
|
*(FAR int *)value : (int)*(FAR unsigned char *)value;
|
2022-08-24 08:55:56 +02:00
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
2023-04-21 11:42:57 +02:00
|
|
|
_SO_SETOPT(conn->s_options, option);
|
2022-08-24 08:55:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-21 11:42:57 +02:00
|
|
|
_SO_CLROPT(conn->s_options, option);
|
2022-08-24 08:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-12-21 05:40:42 +01:00
|
|
|
case IPV6_TCLASS:
|
|
|
|
{
|
2023-05-08 16:11:04 +02:00
|
|
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
2023-05-12 09:44:27 +02:00
|
|
|
int tclass = (value_len >= sizeof(int)) ?
|
|
|
|
*(FAR int *)value : (int)*(FAR unsigned char *)value;
|
2022-12-21 05:40:42 +01:00
|
|
|
|
|
|
|
/* According to RFC3542 6.5, the interpretation of the integer
|
|
|
|
* traffic class value is:
|
|
|
|
* x < -1: return an error of EINVAL
|
|
|
|
* x == -1: use kernel default
|
|
|
|
* 0 <= x <= 255: use x
|
|
|
|
* x >= 256: return an error of EINVAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tclass < -1 || tclass > 0xff)
|
|
|
|
{
|
|
|
|
nerr("ERROR: invalid tclass:%d\n", tclass);
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tclass == -1)
|
|
|
|
{
|
|
|
|
/* Default value is 0 */
|
2018-11-02 19:06:57 +01:00
|
|
|
|
2022-12-21 05:40:42 +01:00
|
|
|
tclass = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->s_tclass = tclass;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 00:15:23 +01:00
|
|
|
break;
|
|
|
|
|
2018-10-31 22:59:05 +01:00
|
|
|
default:
|
2018-11-01 00:15:23 +01:00
|
|
|
nerr("ERROR: Unrecognized IPv6 option: %d\n", option);
|
|
|
|
ret = -ENOPROTOOPT;
|
2018-10-31 22:59:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-03 23:47:08 +01:00
|
|
|
net_unlock();
|
2018-11-01 00:15:23 +01:00
|
|
|
return ret;
|
2018-10-31 22:59:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_IPv6 */
|