chromium/third_party/grpc/src/src/core/lib/event_engine/posix_engine/internal_errqueue.h

// Copyright 2022 The gRPC Authors
//
// Licensed 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
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// 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.

#ifndef GRPC_SRC_CORE_LIB_EVENT_ENGINE_POSIX_ENGINE_INTERNAL_ERRQUEUE_H
#define GRPC_SRC_CORE_LIB_EVENT_ENGINE_POSIX_ENGINE_INTERNAL_ERRQUEUE_H

#include <grpc/support/port_platform.h>

#include <stdint.h>

#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_POSIX_SOCKET_TCP

#include <time.h>

#ifdef GRPC_LINUX_ERRQUEUE
#include <linux/errqueue.h>  // IWYU pragma: keep
#include <sys/socket.h>
#endif  // GRPC_LINUX_ERRQUEUE

namespace grpc_event_engine {
namespace experimental {

#ifdef GRPC_LINUX_ERRQUEUE

// Redefining scm_timestamping in the same way that <linux/errqueue.h> defines
// it, so that code compiles on systems that don't have it.
struct scm_timestamping {};
// Also redefine timestamp types
// The timestamp type for when the driver passed skb to NIC, or HW.
constexpr int SCM_TSTAMP_SND =;
// The timestamp type for when data entered the packet scheduler.
constexpr int SCM_TSTAMP_SCHED =;
// The timestamp type for when data acknowledged by peer.
constexpr int SCM_TSTAMP_ACK =;

// Control message type containing OPT_STATS
#ifndef SCM_TIMESTAMPING_OPT_STATS
#define SCM_TIMESTAMPING_OPT_STATS
#endif

// Redefine required constants from <linux/net_tstamp.h>
constexpr uint32_t SOF_TIMESTAMPING_TX_SOFTWARE =;
constexpr uint32_t SOF_TIMESTAMPING_SOFTWARE =;
constexpr uint32_t SOF_TIMESTAMPING_OPT_ID =;
constexpr uint32_t SOF_TIMESTAMPING_TX_SCHED =;
constexpr uint32_t SOF_TIMESTAMPING_TX_ACK =;
constexpr uint32_t SOF_TIMESTAMPING_OPT_TSONLY =;
constexpr uint32_t SOF_TIMESTAMPING_OPT_STATS =;

constexpr uint32_t kTimestampingSocketOptions =;
constexpr uint32_t kTimestampingRecordingOptions =;

// Netlink attribute types used for TCP opt stats.
enum TCPOptStats {};

// tcp_info from from linux/tcp.h
struct tcp_info {};

#ifndef TCP_INFO
#define TCP_INFO
#endif

int GetSocketTcpInfo(tcp_info* info, int fd);

#endif  // GRPC_LINUX_ERRQUEUE

// Returns true if kernel is capable of supporting errqueue and timestamping.
// Currently allowing only linux kernels above 4.0.0
bool KernelSupportsErrqueue();

}  // namespace experimental
}  // namespace grpc_event_engine

#endif  // GRPC_POSIX_SOCKET_TCP

#endif  // GRPC_SRC_CORE_LIB_EVENT_ENGINE_POSIX_ENGINE_INTERNAL_ERRQUEUE_H