lsquic_conn.h revision 83287402
1/* Copyright (c) 2017 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#include <sys/socket.h> 11#include <netinet/in.h> 12 13struct lsquic_conn; 14struct lsquic_enc_session; 15struct lsquic_engine_public; 16struct lsquic_packet_out; 17struct lsquic_packet_in; 18struct sockaddr; 19struct parse_funcs; 20struct attq_elem; 21 22enum lsquic_conn_flags { 23 LSCONN_HAS_INCOMING = (1 << 0), 24 LSCONN_HAS_OUTGOING = (1 << 1), 25 LSCONN_HASHED = (1 << 2), 26 LSCONN_HAS_PEER_SA = (1 << 4), 27 LSCONN_HAS_LOCAL_SA = (1 << 5), 28 LSCONN_HANDSHAKE_DONE = (1 << 6), 29 LSCONN_CLOSING = (1 << 7), 30 LSCONN_PEER_GOING_AWAY= (1 << 8), 31 LSCONN_TCID0 = (1 << 9), 32 LSCONN_VER_SET = (1 <<10), /* cn_version is set */ 33 LSCONN_EVANESCENT = (1 <<11), /* evanescent connection */ 34 LSCONN_RW_PENDING = (1 <<12), 35 LSCONN_COI_ACTIVE = (1 <<13), 36 LSCONN_COI_INACTIVE = (1 <<14), 37 LSCONN_SEND_BLOCKED = (1 <<15), /* Send connection blocked frame */ 38 LSCONN_NEVER_PEND_RW = (1 <<17), /* Do not put onto Pending RW queue */ 39 LSCONN_ATTQ = (1 <<19), 40}; 41 42#define TICK_BIT_PROGRESS 3 43 44/* A connection may have things to send and be closed at the same time. 45 */ 46enum tick_st { 47 TICK_SEND = (1 << 0), 48 TICK_CLOSE = (1 << 1), 49 /* Progress was made (see @ref es_pendrw_check for definition of 50 * "progress.") 51 */ 52 TICK_PROGRESS= (1 << TICK_BIT_PROGRESS), 53}; 54 55#define TICK_QUIET 0 56 57struct conn_iface 58{ 59 enum tick_st 60 (*ci_tick) (struct lsquic_conn *, lsquic_time_t now); 61 62 void 63 (*ci_packet_in) (struct lsquic_conn *, struct lsquic_packet_in *); 64 65 struct lsquic_packet_out * 66 (*ci_next_packet_to_send) (struct lsquic_conn *); 67 68 void 69 (*ci_packet_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 70 71 void 72 (*ci_packet_not_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 73 74 void 75 (*ci_handshake_done) (struct lsquic_conn *); 76 77 int 78 (*ci_user_wants_read) (struct lsquic_conn *); 79 80 void 81 (*ci_destroy) (struct lsquic_conn *); 82}; 83 84#define RW_HIST_BITS 6 85typedef unsigned char rw_hist_idx_t; 86 87struct lsquic_conn 88{ 89 void *cn_peer_ctx; 90 struct lsquic_enc_session *cn_enc_session; 91 const struct enc_session_funcs 92 *cn_esf; 93 lsquic_cid_t cn_cid; 94 STAILQ_ENTRY(lsquic_conn) cn_next_closed_conn; 95 TAILQ_ENTRY(lsquic_conn) cn_next_all, 96 cn_next_in, 97 cn_next_pend_rw, 98 cn_next_out, 99 cn_next_hash; 100 const struct conn_iface *cn_if; 101 const struct parse_funcs *cn_pf; 102 struct attq_elem *cn_attq_elem; 103 lsquic_time_t cn_last_sent; 104 enum lsquic_conn_flags cn_flags; 105 enum lsquic_version cn_version; 106 unsigned cn_noprogress_count; 107 unsigned cn_hash; 108 unsigned short cn_pack_size; 109 rw_hist_idx_t cn_rw_hist_idx; 110 unsigned char cn_rw_hist_buf[ 1 << RW_HIST_BITS ]; 111 unsigned char cn_peer_addr[sizeof(struct sockaddr_in6)], 112 cn_local_addr[sizeof(struct sockaddr_in6)]; 113}; 114 115void 116lsquic_conn_record_sockaddr (lsquic_conn_t *lconn, const struct sockaddr *local, 117 const struct sockaddr *peer); 118 119void 120lsquic_conn_record_peer_sa (lsquic_conn_t *lconn, const struct sockaddr *peer); 121 122int 123lsquic_conn_decrypt_packet (lsquic_conn_t *lconn, 124 struct lsquic_engine_public *, struct lsquic_packet_in *); 125 126int 127lsquic_conn_copy_and_release_pi_data (const lsquic_conn_t *conn, 128 struct lsquic_engine_public *, struct lsquic_packet_in *); 129 130#define lsquic_conn_adv_time(c) ((c)->cn_attq_elem->ae_adv_time) 131 132#endif 133