• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "quiche/quic/core/quic_types.h"
10 #include "quiche/common/quiche_ip_address_family.h"
11 
12 namespace quiche {
13 
14 const size_t kCmsgSpaceForGooglePacketHeader =
15     kCmsgSpaceForGooglePacketHeaderImpl;
16 
GetGooglePacketHeadersFromControlMessage(struct::cmsghdr * cmsg,char ** packet_headers,size_t * packet_headers_len)17 inline bool GetGooglePacketHeadersFromControlMessage(
18     struct ::cmsghdr* cmsg, char** packet_headers, size_t* packet_headers_len) {
19   return GetGooglePacketHeadersFromControlMessageImpl(cmsg, packet_headers,
20                                                       packet_headers_len);
21 }
22 
SetGoogleSocketOptions(int fd)23 inline void SetGoogleSocketOptions(int fd) { SetGoogleSocketOptionsImpl(fd); }
24 
25 // Retrieves the IP TOS byte for |fd| and |address_family|, based on the correct
26 // sockopt for the platform, replaces the two ECN bits of that byte with the
27 // value in |ecn_codepoint|.
28 // The result is stored in |value| in the proper format to set the TOS byte
29 // using a cmsg. |value| must point to memory of size |value_len|. Stores the
30 // correct cmsg type to use in |type|.
31 // Returns 0 on success. Returns EINVAL if |address_family| is neither IP_V4 nor
32 // IP_V6, or if |value_len| is not large enough to store the appropriately
33 // formatted argument. If getting the socket option fails, returns the
34 // associated error code.
GetEcnCmsgArgsPreserveDscp(const int fd,const quiche::IpAddressFamily address_family,quic::QuicEcnCodepoint ecn_codepoint,int & type,void * value,socklen_t & value_len)35 inline int GetEcnCmsgArgsPreserveDscp(
36     const int fd, const quiche::IpAddressFamily address_family,
37     quic::QuicEcnCodepoint ecn_codepoint, int& type, void* value,
38     socklen_t& value_len) {
39   return GetEcnCmsgArgsPreserveDscpImpl(
40       fd, ToPlatformAddressFamily(address_family),
41       static_cast<uint8_t>(ecn_codepoint), type, value, value_len);
42 }
43 
44 }  // namespace quiche
45 
46 #endif  // QUICHE_COMMON_PLATFORM_API_QUICHE_UDP_SOCKET_PLATFORM_API_H_
47