lsquic_conn.h revision bfc7bfd8
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 2 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_ok) (struct lsquic_conn *); 76 77 void 78 (*ci_handshake_failed) (struct lsquic_conn *); 79 80 int 81 (*ci_user_wants_read) (struct lsquic_conn *); 82 83 void 84 (*ci_destroy) (struct lsquic_conn *); 85}; 86 87#define RW_HIST_BITS 6 88typedef unsigned char rw_hist_idx_t; 89 90struct lsquic_conn 91{ 92 void *cn_peer_ctx; 93 struct lsquic_enc_session *cn_enc_session; 94 const struct enc_session_funcs 95 *cn_esf; 96 lsquic_cid_t cn_cid; 97 STAILQ_ENTRY(lsquic_conn) cn_next_closed_conn; 98 TAILQ_ENTRY(lsquic_conn) cn_next_all, 99 cn_next_in, 100 cn_next_pend_rw, 101 cn_next_out, 102 cn_next_hash; 103 const struct conn_iface *cn_if; 104 const struct parse_funcs *cn_pf; 105 struct attq_elem *cn_attq_elem; 106 lsquic_time_t cn_last_sent; 107 enum lsquic_conn_flags cn_flags; 108 enum lsquic_version cn_version; 109 unsigned cn_noprogress_count; 110 unsigned cn_hash; 111 unsigned short cn_pack_size; 112 rw_hist_idx_t cn_rw_hist_idx; 113 unsigned char cn_rw_hist_buf[ 1 << RW_HIST_BITS ]; 114 unsigned char cn_peer_addr[sizeof(struct sockaddr_in6)], 115 cn_local_addr[sizeof(struct sockaddr_in6)]; 116}; 117 118void 119lsquic_conn_record_sockaddr (lsquic_conn_t *lconn, const struct sockaddr *local, 120 const struct sockaddr *peer); 121 122void 123lsquic_conn_record_peer_sa (lsquic_conn_t *lconn, const struct sockaddr *peer); 124 125int 126lsquic_conn_decrypt_packet (lsquic_conn_t *lconn, 127 struct lsquic_engine_public *, struct lsquic_packet_in *); 128 129int 130lsquic_conn_copy_and_release_pi_data (const lsquic_conn_t *conn, 131 struct lsquic_engine_public *, struct lsquic_packet_in *); 132 133#define lsquic_conn_adv_time(c) ((c)->cn_attq_elem->ae_adv_time) 134 135#endif 136