s2n_ktls.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <sys/socket.h>
  17. #include "api/unstable/ktls.h"
  18. #include "tls/s2n_connection.h"
  19. /* Define headers needed to enable and use kTLS.
  20. *
  21. * The inline header definitions are required to compile kTLS specific code.
  22. * kTLS has been tested on linux. For all other platforms, kTLS is marked as
  23. * unsupported, and will return an unsupported error.
  24. */
  25. #include "tls/s2n_ktls_parameters.h"
  26. /* A set of kTLS configurations representing the combination of sending
  27. * and receiving.
  28. */
  29. typedef enum {
  30. /* Enable kTLS for the send socket. */
  31. S2N_KTLS_MODE_SEND,
  32. /* Enable kTLS for the receive socket. */
  33. S2N_KTLS_MODE_RECV,
  34. } s2n_ktls_mode;
  35. bool s2n_ktls_is_supported_on_platform();
  36. S2N_RESULT s2n_ktls_get_file_descriptor(struct s2n_connection *conn, s2n_ktls_mode ktls_mode, int *fd);
  37. int s2n_ktls_send_cb(void *io_context, const uint8_t *buf, uint32_t len);
  38. S2N_RESULT s2n_ktls_sendmsg(void *io_context, uint8_t record_type, const struct iovec *msg_iov,
  39. size_t msg_iovlen, s2n_blocked_status *blocked, size_t *bytes_written);
  40. S2N_RESULT s2n_ktls_recvmsg(void *io_context, uint8_t *record_type, uint8_t *buf,
  41. size_t buf_len, s2n_blocked_status *blocked, size_t *bytes_read);
  42. ssize_t s2n_ktls_sendv_with_offset(struct s2n_connection *conn, const struct iovec *bufs,
  43. ssize_t count, ssize_t offs, s2n_blocked_status *blocked);
  44. int s2n_ktls_record_writev(struct s2n_connection *conn, uint8_t content_type,
  45. const struct iovec *in, int in_count, size_t offs, size_t to_write);
  46. int s2n_ktls_read_full_record(struct s2n_connection *conn, uint8_t *record_type);
  47. /* Testing */
  48. typedef int (*s2n_setsockopt_fn)(int socket, int level, int option_name, const void *option_value,
  49. socklen_t option_len);
  50. S2N_RESULT s2n_ktls_set_setsockopt_cb(s2n_setsockopt_fn cb);
  51. typedef ssize_t (*s2n_ktls_sendmsg_fn)(void *io_context, const struct msghdr *msg);
  52. typedef ssize_t (*s2n_ktls_recvmsg_fn)(void *io_context, struct msghdr *msg);
  53. S2N_RESULT s2n_ktls_set_sendmsg_cb(struct s2n_connection *conn, s2n_ktls_sendmsg_fn send_cb,
  54. void *send_ctx);
  55. S2N_RESULT s2n_ktls_set_recvmsg_cb(struct s2n_connection *conn, s2n_ktls_recvmsg_fn recv_cb,
  56. void *recv_ctx);
  57. void s2n_ktls_configure_connection(struct s2n_connection *conn, s2n_ktls_mode ktls_mode);
  58. /* These functions will be part of the public API. */
  59. int s2n_connection_ktls_enable_send(struct s2n_connection *conn);
  60. int s2n_connection_ktls_enable_recv(struct s2n_connection *conn);
  61. int s2n_sendfile(struct s2n_connection *conn, int in_fd, off_t offset, size_t count,
  62. size_t *bytes_written, s2n_blocked_status *blocked);