[libc-commits] [libc] [libc] Add IPV6_PKTINFO, IPV6_TCLASS and related socket options (PR #243838)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Wed Nov 18 04:54:13 PST 2026
https://github.com/labath created https://github.com/llvm/llvm-project/pull/243838
This patch adds the IPV6_PKTINFO, IPV6_RECVHOPLIMIT, IPV6_RECVTCLASS and IPV6_TCLASS socket options as well as struct in6_pktinfo (used by IPV6_PKTINFO) to <netinet/in.h>.
The interface index in struct in6_pktinfo is unsigned int, which matches other implementations (the kernel uapi header uses a plain int).
Assisted-by: Gemini
>From 663ef59c82b431b24b548d58e72cc288005af52a Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Wed, 18 Nov 2026 12:52:03 +0000
Subject: [PATCH] [libc] Add IPV6_PKTINFO, IPV6_TCLASS and related socket
options
This patch adds the IPV6_PKTINFO, IPV6_RECVHOPLIMIT, IPV6_RECVTCLASS and
IPV6_TCLASS socket options as well as struct in6_pktinfo (used by
IPV6_PKTINFO) to <netinet/in.h>.
The interface index in struct in6_pktinfo is unsigned int, which matches
other implementations (the kernel uapi header uses a plain int).
Assisted-by: Gemini
---
libc/hdr/types/CMakeLists.txt | 8 ++++++
libc/hdr/types/struct_in6_pktinfo.h | 26 +++++++++++++++++++
libc/include/CMakeLists.txt | 1 +
libc/include/llvm-libc-types/CMakeLists.txt | 1 +
.../llvm-libc-types/struct_in6_pktinfo.h | 24 +++++++++++++++++
libc/include/netinet/in.yaml | 9 +++++++
libc/test/src/netinet/CMakeLists.txt | 1 +
libc/test/src/netinet/in_test.cpp | 6 +++++
libc/utils/docgen/netinet/in.yaml | 10 +++++++
9 files changed, 86 insertions(+)
create mode 100644 libc/hdr/types/struct_in6_pktinfo.h
create mode 100644 libc/include/llvm-libc-types/struct_in6_pktinfo.h
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 2b834cd4f21e77..0114248965d539 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -654,6 +654,14 @@ add_proxy_header_library(
libc.include.llvm-libc-types.struct_ip_opts
)
+add_proxy_header_library(
+ struct_in6_pktinfo
+ HDRS
+ struct_in6_pktinfo.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.struct_in6_pktinfo
+)
+
add_proxy_header_library(
struct_ipv6_mreq
HDRS
diff --git a/libc/hdr/types/struct_in6_pktinfo.h b/libc/hdr/types/struct_in6_pktinfo.h
new file mode 100644
index 00000000000000..e9b68dd13721eb
--- /dev/null
+++ b/libc/hdr/types/struct_in6_pktinfo.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 in6_pktinfo.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IN6_PKTINFO_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IN6_PKTINFO_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_in6_pktinfo.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IN6_PKTINFO_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 2261acf58095df..3b235a2e8509f5 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -1243,6 +1243,7 @@ add_header_macro(
.llvm-libc-types.struct_sockaddr_in6
.llvm-libc-types.struct_in_addr
.llvm-libc-types.struct_in6_addr
+ .llvm-libc-types.struct_in6_pktinfo
.llvm-libc-types.struct_ip_mreq
.llvm-libc-types.struct_ip_mreq_source
.llvm-libc-types.struct_ip_mreqn
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 4ec5ee3c714653..a9dd69264816e1 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -124,6 +124,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_in6_pktinfo HDR struct_in6_pktinfo.h DEPENDS .struct_in6_addr)
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)
diff --git a/libc/include/llvm-libc-types/struct_in6_pktinfo.h b/libc/include/llvm-libc-types/struct_in6_pktinfo.h
new file mode 100644
index 00000000000000..2eb8fffc81341e
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_in6_pktinfo.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 in6_pktinfo.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IN6_PKTINFO_H
+#define LLVM_LIBC_TYPES_STRUCT_IN6_PKTINFO_H
+
+#include "struct_in6_addr.h"
+
+struct in6_pktinfo {
+ struct in6_addr ipi6_addr;
+ unsigned int ipi6_ifindex;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IN6_PKTINFO_H
diff --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
index 9ec0047d7d8c5e..cd147d1888b158 100644
--- a/libc/include/netinet/in.yaml
+++ b/libc/include/netinet/in.yaml
@@ -152,6 +152,10 @@ macros:
macro_value: 26 # int
- macro_name: IPV6_RECVPKTINFO
macro_value: 49 # int
+ - macro_name: IPV6_PKTINFO
+ macro_value: 50 # struct in6_pktinfo
+ - macro_name: IPV6_RECVHOPLIMIT
+ macro_value: 51 # int
- macro_name: IPV6_HOPLIMIT
macro_value: 52 # int
- macro_name: IPV6_HOPOPTS
@@ -160,6 +164,10 @@ macros:
macro_value: 57 # int
- macro_name: IPV6_DSTOPTS
macro_value: 59 # int
+ - macro_name: IPV6_RECVTCLASS
+ macro_value: 66 # int
+ - macro_name: IPV6_TCLASS
+ macro_value: 67 # int
types:
- type_name: in_port_t
- type_name: in_addr_t
@@ -169,6 +177,7 @@ types:
- type_name: struct_group_source_req
- type_name: struct_in_addr
- type_name: struct_in6_addr
+ - type_name: struct_in6_pktinfo
- type_name: struct_ipv6_mreq
- type_name: struct_ip_mreq
- type_name: struct_ip_mreq_source
diff --git a/libc/test/src/netinet/CMakeLists.txt b/libc/test/src/netinet/CMakeLists.txt
index 87c84b31bb1e32..c2deb0479f5010 100644
--- a/libc/test/src/netinet/CMakeLists.txt
+++ b/libc/test/src/netinet/CMakeLists.txt
@@ -13,6 +13,7 @@ add_libc_test(
libc.hdr.types.struct_group_req
libc.hdr.types.struct_group_source_req
libc.hdr.types.struct_in6_addr
+ libc.hdr.types.struct_in6_pktinfo
libc.hdr.types.struct_ip_mreq
libc.hdr.types.struct_ip_mreq_source
libc.hdr.types.struct_ip_mreqn
diff --git a/libc/test/src/netinet/in_test.cpp b/libc/test/src/netinet/in_test.cpp
index 6357385a5a158b..a48328f41e1846 100644
--- a/libc/test/src/netinet/in_test.cpp
+++ b/libc/test/src/netinet/in_test.cpp
@@ -15,6 +15,7 @@
#include "hdr/types/struct_group_req.h"
#include "hdr/types/struct_group_source_req.h"
#include "hdr/types/struct_in6_addr.h"
+#include "hdr/types/struct_in6_pktinfo.h"
#include "hdr/types/struct_ip_mreq.h"
#include "hdr/types/struct_ip_mreq_source.h"
#include "hdr/types/struct_ip_mreqn.h"
@@ -105,6 +106,7 @@ TEST(LlvmLibcNetinetInTest, IpOptionLayout) {
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(sizeof(struct in6_pktinfo), 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));
@@ -135,6 +137,10 @@ TEST(LlvmLibcNetinetInTest, IpOptionLayout) {
static_cast<size_t>(0));
EXPECT_EQ(offsetof(struct ipv6_mreq, ipv6mr_interface),
static_cast<size_t>(16));
+
+ EXPECT_EQ(offsetof(struct in6_pktinfo, ipi6_addr), static_cast<size_t>(0));
+ EXPECT_EQ(offsetof(struct in6_pktinfo, ipi6_ifindex),
+ static_cast<size_t>(16));
}
TEST(LlvmLibcNetinetInTest, GroupSourceOptionLayout) {
diff --git a/libc/utils/docgen/netinet/in.yaml b/libc/utils/docgen/netinet/in.yaml
index 92b40bd0339ecf..0e5ce03fc982c0 100644
--- a/libc/utils/docgen/netinet/in.yaml
+++ b/libc/utils/docgen/netinet/in.yaml
@@ -14,6 +14,8 @@ types:
extension: linux
struct in6_addr:
in-latest-posix: ''
+ struct in6_pktinfo:
+ extension: linux
struct in_addr:
in-latest-posix: ''
struct ip_mreq:
@@ -126,14 +128,22 @@ macros:
extension: linux
IPV6_MTU_DISCOVER:
extension: linux
+ IPV6_PKTINFO:
+ extension: linux
IPV6_RECVERR:
extension: linux
+ IPV6_RECVHOPLIMIT:
+ extension: linux
IPV6_RECVPKTINFO:
extension: linux
+ IPV6_RECVTCLASS:
+ extension: linux
IPV6_ROUTER_ALERT:
extension: linux
IPV6_RTHDR:
extension: linux
+ IPV6_TCLASS:
+ extension: linux
IP_ADD_MEMBERSHIP:
extension: linux
IP_ADD_SOURCE_MEMBERSHIP:
More information about the libc-commits
mailing list