1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef QUICHE_COMMON_PLATFORM_API_QUICHE_UDP_SOCKET_PLATFORM_API_H_
6 #define QUICHE_COMMON_PLATFORM_API_QUICHE_UDP_SOCKET_PLATFORM_API_H_
7
8 #include "quiche_platform_impl/quiche_udp_socket_platform_impl.h"
9
10 #include "quiche/quic/core/quic_types.h"
11 #include "quiche/common/quiche_ip_address_family.h"
12
13 namespace quiche {
14
15 const size_t kCmsgSpaceForGooglePacketHeader =
16 kCmsgSpaceForGooglePacketHeaderImpl;
17
GetGooglePacketHeadersFromControlMessage(struct::cmsghdr * cmsg,char ** packet_headers,size_t * packet_headers_len)18 inline bool GetGooglePacketHeadersFromControlMessage(
19 struct ::cmsghdr* cmsg, char** packet_headers, size_t* packet_headers_len) {
20 return GetGooglePacketHeadersFromControlMessageImpl(cmsg, packet_headers,
21 packet_headers_len);
22 }
23
SetGoogleSocketOptions(int fd)24 inline void SetGoogleSocketOptions(int fd) { SetGoogleSocketOptionsImpl(fd); }
25
26 // Retrieves the IP TOS byte for |fd| and |address_family|, based on the correct
27 // sockopt for the platform, replaces the two ECN bits of that byte with the
28 // value in |ecn_codepoint|.
29 // The result is stored in |value| in the proper format to set the TOS byte
30 // using a cmsg. |value| must point to memory of size |value_len|. Stores the
31 // correct cmsg type to use in |type|.
32 // Returns 0 on success. Returns EINVAL if |address_family| is neither IP_V4 nor
33 // IP_V6, or if |value_len| is not large enough to store the appropriately
34 // formatted argument. If getting the socket option fails, returns the
35 // associated error code.
GetEcnCmsgArgsPreserveDscp(const int fd,const quiche::IpAddressFamily address_family,quic::QuicEcnCodepoint ecn_codepoint,int & type,void * value,socklen_t & value_len)36 inline int GetEcnCmsgArgsPreserveDscp(
37 const int fd, const quiche::IpAddressFamily address_family,
38 quic::QuicEcnCodepoint ecn_codepoint, int& type, void* value,
39 socklen_t& value_len) {
40 return GetEcnCmsgArgsPreserveDscpImpl(
41 fd, ToPlatformAddressFamily(address_family),
42 static_cast<uint8_t>(ecn_codepoint), type, value, value_len);
43 }
44
45 } // namespace quiche
46
47 #endif // QUICHE_COMMON_PLATFORM_API_QUICHE_UDP_SOCKET_PLATFORM_API_H_
48