lsquic_conn.h revision 229fce07
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_conn.h -- Connection interface 4 * 5 */ 6#ifndef LSQUIC_CONN_H 7#define LSQUIC_CONN_H 8 9#include <sys/queue.h> 10#ifndef WIN32 11#include <sys/socket.h> 12#include <netinet/in.h> 13#else 14#include <ws2ipdef.h> 15#endif 16 17struct lsquic_conn; 18struct lsquic_enc_session; 19struct lsquic_engine_public; 20struct lsquic_packet_out; 21struct lsquic_packet_in; 22struct sockaddr; 23struct parse_funcs; 24struct attq_elem; 25 26enum lsquic_conn_flags { 27 LSCONN_TICKED = (1 << 0), 28 LSCONN_HAS_OUTGOING = (1 << 1), 29 LSCONN_HASHED = (1 << 2), 30 LSCONN_HAS_PEER_SA = (1 << 4), 31 LSCONN_HAS_LOCAL_SA = (1 << 5), 32 LSCONN_HANDSHAKE_DONE = (1 << 6), 33 LSCONN_CLOSING = (1 << 7), 34 LSCONN_PEER_GOING_AWAY= (1 << 8), 35 LSCONN_TCID0 = (1 << 9), 36 LSCONN_VER_SET = (1 <<10), /* cn_version is set */ 37 LSCONN_EVANESCENT = (1 <<11), /* evanescent connection */ 38 LSCONN_TICKABLE = (1 <<12), /* Connection is in the Tickable Queue */ 39 LSCONN_COI_ACTIVE = (1 <<13), 40 LSCONN_COI_INACTIVE = (1 <<14), 41 LSCONN_SEND_BLOCKED = (1 <<15), /* Send connection blocked frame */ 42 LSCONN_NEVER_TICKABLE = (1 <<17), /* Do not put onto the Tickable Queue */ 43 LSCONN_ATTQ = (1 <<19), 44}; 45 46/* A connection may have things to send and be closed at the same time. 47 */ 48enum tick_st { 49 TICK_SEND = (1 << 0), 50 TICK_CLOSE = (1 << 1), 51}; 52 53#define TICK_QUIET 0 54 55struct conn_iface 56{ 57 enum tick_st 58 (*ci_tick) (struct lsquic_conn *, lsquic_time_t now); 59 60 void 61 (*ci_packet_in) (struct lsquic_conn *, struct lsquic_packet_in *); 62 63 struct lsquic_packet_out * 64 (*ci_next_packet_to_send) (struct lsquic_conn *); 65 66 void 67 (*ci_packet_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 68 69 void 70 (*ci_packet_not_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 71 72 void 73 (*ci_handshake_ok) (struct lsquic_conn *); 74 75 void 76 (*ci_handshake_failed) (struct lsquic_conn *); 77 78 void 79 (*ci_destroy) (struct lsquic_conn *); 80 81 int 82 (*ci_is_tickable) (struct lsquic_conn *); 83 84 lsquic_time_t 85 (*ci_next_tick_time) (struct lsquic_conn *); 86}; 87 88struct lsquic_conn 89{ 90 void *cn_peer_ctx; 91 struct lsquic_enc_session *cn_enc_session; 92 const struct enc_session_funcs 93 *cn_esf; 94 lsquic_cid_t cn_cid; 95 STAILQ_ENTRY(lsquic_conn) cn_next_closed_conn; 96 TAILQ_ENTRY(lsquic_conn) cn_next_ticked; 97 TAILQ_ENTRY(lsquic_conn) cn_next_out, 98 cn_next_hash; 99 const struct conn_iface *cn_if; 100 const struct parse_funcs *cn_pf; 101 struct attq_elem *cn_attq_elem; 102 lsquic_time_t cn_last_sent; 103 lsquic_time_t cn_last_ticked; 104 enum lsquic_conn_flags cn_flags; 105 enum lsquic_version cn_version; 106 unsigned cn_hash; 107 unsigned short cn_pack_size; 108 unsigned char cn_local_addr[sizeof(struct sockaddr_in6)]; 109 union { 110 unsigned char buf[sizeof(struct sockaddr_in6)]; 111 struct sockaddr sa; 112 } cn_peer_addr_u; 113#define cn_peer_addr cn_peer_addr_u.buf 114}; 115 116void 117lsquic_conn_record_sockaddr (lsquic_conn_t *lconn, const struct sockaddr *local, 118 const struct sockaddr *peer); 119 120int 121lsquic_conn_decrypt_packet (lsquic_conn_t *lconn, 122 struct lsquic_engine_public *, struct lsquic_packet_in *); 123 124int 125lsquic_conn_copy_and_release_pi_data (const lsquic_conn_t *conn, 126 struct lsquic_engine_public *, struct lsquic_packet_in *); 127 128#define lsquic_conn_adv_time(c) ((c)->cn_attq_elem->ae_adv_time) 129 130#endif 131