s2n_ktls_parameters.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #pragma once
  16. /*
  17. * Linux doesn't expose kTLS headers in its uapi. Its possible to get these headers
  18. * via glibc but support can vary depending on the version of glibc on the host.
  19. * Instead we define linux specific values inline.
  20. *
  21. * - https://elixir.bootlin.com/linux/v6.3.8/A/ident/TCP_ULP
  22. * - https://elixir.bootlin.com/linux/v6.3.8/A/ident/SOL_TCP
  23. */
  24. #if defined(S2N_KTLS_SUPPORTED)
  25. #include <linux/tls.h>
  26. /* socket definitions */
  27. #define S2N_TCP_ULP 31 /* Attach a ULP to a TCP connection. */
  28. #define S2N_SOL_TCP 6 /* TCP level */
  29. #define S2N_SOL_TLS 282
  30. /* We typically only define values not available in the linux uapi. However,
  31. * only TLS_TX is defined in the first version of kTLS. Since calling setsockopt
  32. * with TLS_RX fails and is non destructive, define both TX and RX to keep the
  33. * definitions co-located and avoid extra ifdefs.
  34. * https://github.com/torvalds/linux/blob/3c4d7559159bfe1e3b94df3a657b2cda3a34e218/include/uapi/linux/tls.h#L43
  35. */
  36. #define S2N_TLS_TX 1
  37. #define S2N_TLS_RX 2
  38. #define S2N_TLS_SET_RECORD_TYPE TLS_SET_RECORD_TYPE
  39. #define S2N_TLS_GET_RECORD_TYPE TLS_GET_RECORD_TYPE
  40. #else
  41. /* For unsupported platforms 0-init (array of size 1) all values. */
  42. /* socket definitions */
  43. #define S2N_TCP_ULP 0
  44. #define S2N_SOL_TCP 0
  45. #define S2N_SOL_TLS 0
  46. #define S2N_TLS_TX 0
  47. #define S2N_TLS_RX 0
  48. #define S2N_TLS_SET_RECORD_TYPE 0
  49. #define S2N_TLS_GET_RECORD_TYPE 0
  50. #endif
  51. /* Common */
  52. #define S2N_TLS_ULP_NAME "tls"
  53. #define S2N_TLS_ULP_NAME_SIZE sizeof(S2N_TLS_ULP_NAME)