[libc-commits] [libc] [libc] Add struct ipv6_mreq and IPv6 socket options (PR #206448)
via libc-commits
libc-commits at lists.llvm.org
Mon Jun 29 03:31:09 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Pavel Labath (labath)
<details>
<summary>Changes</summary>
This patch adds struct ipv6_mreq and defines various IPv6 socket option macros in <netinet/in.h>. I've also moved the existing option definitions to the yaml file.
Assisted by Gemini.
---
Full diff: https://github.com/llvm/llvm-project/pull/206448.diff
9 Files Affected:
- (modified) libc/hdr/types/CMakeLists.txt (+9)
- (added) libc/hdr/types/struct_ipv6_mreq.h (+26)
- (modified) libc/include/CMakeLists.txt (+1)
- (modified) libc/include/llvm-libc-macros/netinet-in-macros.h (-8)
- (modified) libc/include/llvm-libc-types/CMakeLists.txt (+1)
- (added) libc/include/llvm-libc-types/struct_ipv6_mreq.h (+24)
- (modified) libc/include/netinet/in.yaml (+44)
- (modified) libc/test/src/netinet/CMakeLists.txt (+1)
- (modified) libc/test/src/netinet/in_test.cpp (+7)
``````````diff
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index a130f7ee0000a..ab16836dbab92 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -500,6 +500,15 @@ add_proxy_header_library(
libc.include.netinet_in
)
+add_proxy_header_library(
+ struct_ipv6_mreq
+ HDRS
+ struct_ipv6_mreq.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.struct_ipv6_mreq
+ libc.include.netinet_in
+)
+
add_proxy_header_library(
in_addr_t
HDRS
diff --git a/libc/hdr/types/struct_ipv6_mreq.h b/libc/hdr/types/struct_ipv6_mreq.h
new file mode 100644
index 0000000000000..4a8dbe9e05302
--- /dev/null
+++ b/libc/hdr/types/struct_ipv6_mreq.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for struct ipv6_mreq.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IPV6_MREQ_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IPV6_MREQ_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_ipv6_mreq.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IPV6_MREQ_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index caf5d61dfc1cb..04550bfdf4d83 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -917,6 +917,7 @@ add_header_macro(
.llvm-libc-types.struct_ip_mreqn
.llvm-libc-types.struct_ip_msfilter
.llvm-libc-types.struct_ip_opts
+ .llvm-libc-types.struct_ipv6_mreq
.llvm_libc_common_h
.sys_socket
)
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
index 6109140fb0ac5..7c9c337fded23 100644
--- a/libc/include/llvm-libc-macros/netinet-in-macros.h
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -19,14 +19,6 @@
#define IPPROTO_IPV6 41
#define IPPROTO_RAW 255
-#define IPV6_UNICAST_HOPS 16
-#define IPV6_MULTICAST_IF 17
-#define IPV6_MULTICAST_HOPS 18
-#define IPV6_MULTICAST_LOOP 19
-#define IPV6_JOIN_GROUP 20
-#define IPV6_LEAVE_GROUP 21
-#define IPV6_V6ONLY 26
-
#define INADDR_ANY __LLVM_LIBC_CAST(static_cast, in_addr_t, 0x00000000)
#define INADDR_BROADCAST __LLVM_LIBC_CAST(static_cast, in_addr_t, 0xffffffff)
#define INADDR_NONE __LLVM_LIBC_CAST(static_cast, in_addr_t, 0xffffffff)
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 0512d3f0e642a..d4d75e9934626 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -68,6 +68,7 @@ add_header(in_addr_t HDR in_addr_t.h)
add_header(in_port_t HDR in_port_t.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
add_header(struct_in_addr HDR struct_in_addr.h DEPENDS .in_addr_t)
add_header(struct_in6_addr HDR struct_in6_addr.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+add_header(struct_ipv6_mreq HDR struct_ipv6_mreq.h DEPENDS .struct_in6_addr)
add_header(struct_ip_mreq HDR struct_ip_mreq.h DEPENDS .struct_in_addr)
add_header(struct_ip_mreq_source HDR struct_ip_mreq_source.h DEPENDS .struct_in_addr)
add_header(struct_ip_mreqn HDR struct_ip_mreqn.h DEPENDS .struct_in_addr)
diff --git a/libc/include/llvm-libc-types/struct_ipv6_mreq.h b/libc/include/llvm-libc-types/struct_ipv6_mreq.h
new file mode 100644
index 0000000000000..b7750e0f6de49
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ipv6_mreq.h
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ipv6_mreq.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IPV6_MREQ_H
+#define LLVM_LIBC_TYPES_STRUCT_IPV6_MREQ_H
+
+#include "struct_in6_addr.h"
+
+struct ipv6_mreq {
+ struct in6_addr ipv6mr_multiaddr;
+ unsigned int ipv6mr_interface;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IPV6_MREQ_H
diff --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
index b78efacbbfe0f..72dea5763a959 100644
--- a/libc/include/netinet/in.yaml
+++ b/libc/include/netinet/in.yaml
@@ -105,6 +105,49 @@ macros:
- macro_name: IP_LOCAL_PORT_RANGE
macro_value: 51 # uint32_t
+ # IPv6 level socket options
+ - macro_name: IPV6_ADDRFORM
+ macro_value: 1 # int
+ - macro_name: IPV6_AUTHHDR
+ macro_value: 10 # int
+ - macro_name: IPV6_FLOWINFO
+ macro_value: 11 # int
+ - macro_name: IPV6_UNICAST_HOPS
+ macro_value: 16 # int
+ - macro_name: IPV6_MULTICAST_IF
+ macro_value: 17 # int
+ - macro_name: IPV6_MULTICAST_HOPS
+ macro_value: 18 # int
+ - macro_name: IPV6_MULTICAST_LOOP
+ macro_value: 19 # int
+ - macro_name: IPV6_JOIN_GROUP
+ macro_value: 20 # struct ipv6_mreq
+ - macro_name: IPV6_ADD_MEMBERSHIP
+ macro_value: IPV6_JOIN_GROUP
+ - macro_name: IPV6_LEAVE_GROUP
+ macro_value: 21 # struct ipv6_mreq
+ - macro_name: IPV6_DROP_MEMBERSHIP
+ macro_value: IPV6_LEAVE_GROUP
+ - macro_name: IPV6_ROUTER_ALERT
+ macro_value: 22 # int
+ - macro_name: IPV6_MTU_DISCOVER
+ macro_value: 23 # int
+ - macro_name: IPV6_MTU
+ macro_value: 24 # int
+ - macro_name: IPV6_RECVERR
+ macro_value: 25 # int
+ - macro_name: IPV6_V6ONLY
+ macro_value: 26 # int
+ - macro_name: IPV6_RECVPKTINFO
+ macro_value: 49 # int
+ - macro_name: IPV6_HOPLIMIT
+ macro_value: 52 # int
+ - macro_name: IPV6_HOPOPTS
+ macro_value: 54 # int
+ - macro_name: IPV6_RTHDR
+ macro_value: 57 # int
+ - macro_name: IPV6_DSTOPTS
+ macro_value: 59 # int
types:
- type_name: in_port_t
- type_name: in_addr_t
@@ -112,6 +155,7 @@ types:
- type_name: struct_sockaddr_in6
- type_name: struct_in_addr
- type_name: struct_in6_addr
+ - type_name: struct_ipv6_mreq
- type_name: struct_ip_mreq
- type_name: struct_ip_mreq_source
- type_name: struct_ip_mreqn
diff --git a/libc/test/src/netinet/CMakeLists.txt b/libc/test/src/netinet/CMakeLists.txt
index f1adcf0f56f17..7c56b7facc135 100644
--- a/libc/test/src/netinet/CMakeLists.txt
+++ b/libc/test/src/netinet/CMakeLists.txt
@@ -14,6 +14,7 @@ add_libc_unittest(
libc.hdr.types.struct_ip_mreqn
libc.hdr.types.struct_ip_msfilter
libc.hdr.types.struct_ip_opts
+ libc.hdr.types.struct_ipv6_mreq
libc.hdr.types.struct_sockaddr_in6
libc.src.arpa.inet.htons
libc.src.arpa.inet.htonl
diff --git a/libc/test/src/netinet/in_test.cpp b/libc/test/src/netinet/in_test.cpp
index eccfdf37d5514..68bae831d6492 100644
--- a/libc/test/src/netinet/in_test.cpp
+++ b/libc/test/src/netinet/in_test.cpp
@@ -23,6 +23,7 @@
#include "hdr/types/struct_ip_mreqn.h"
#include "hdr/types/struct_ip_msfilter.h"
#include "hdr/types/struct_ip_opts.h"
+#include "hdr/types/struct_ipv6_mreq.h"
#include "hdr/types/struct_sockaddr_in6.h"
#include "src/netinet/in6addr_any.h"
#include "src/netinet/in6addr_loopback.h"
@@ -104,6 +105,7 @@ TEST(LlvmLibcNetinetInTest, IpOptionLayout) {
EXPECT_EQ(sizeof(struct ip_mreqn), static_cast<size_t>(12));
EXPECT_EQ(sizeof(struct ip_msfilter), static_cast<size_t>(20));
EXPECT_EQ(sizeof(struct ip_opts), static_cast<size_t>(44));
+ EXPECT_EQ(sizeof(struct ipv6_mreq), static_cast<size_t>(20));
EXPECT_EQ(offsetof(struct ip_mreq, imr_multiaddr), static_cast<size_t>(0));
EXPECT_EQ(offsetof(struct ip_mreq, imr_interface), static_cast<size_t>(4));
@@ -129,4 +131,9 @@ TEST(LlvmLibcNetinetInTest, IpOptionLayout) {
EXPECT_EQ(offsetof(struct ip_opts, ip_dst), static_cast<size_t>(0));
EXPECT_EQ(offsetof(struct ip_opts, ip_opts), static_cast<size_t>(4));
+
+ EXPECT_EQ(offsetof(struct ipv6_mreq, ipv6mr_multiaddr),
+ static_cast<size_t>(0));
+ EXPECT_EQ(offsetof(struct ipv6_mreq, ipv6mr_interface),
+ static_cast<size_t>(16));
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/206448
More information about the libc-commits
mailing list