comparison src/event/quic/ngx_event_quic_connection.h @ 8971:1e2f4e9c8195 quic

QUIC: reworked migration handling. The quic connection now holds active, backup and probe paths instead of sockets. The number of migration paths is now limited and cannot be inflated by a bad client or an attacker. The client id is now associated with path rather than socket. This allows to simplify processing of output and connection ids handling. New migration abandons any previously started migrations. This allows to free consumed client ids and request new for use in future migrations and make progress in case when connection id limit is hit during migration. A path now can be revalidated without losing its state. The patch also fixes various issues with NAT rebinding case handling: - paths are now validated (previously, there was no validation and paths were left in limited state) - attempt to reuse id on different path is now again verified (this was broken in 40445fc7c403) - former path is now validated in case of apparent migration
author Vladimir Homutov <vl@nginx.com>
date Wed, 19 Jan 2022 22:39:24 +0300
parents fb811b6c76ee
children a5aebd51e4c7
comparison
equal deleted inserted replaced
8970:7106a918a277 8971:1e2f4e9c8195
67 ngx_queue_t queue; 67 ngx_queue_t queue;
68 uint64_t seqnum; 68 uint64_t seqnum;
69 size_t len; 69 size_t len;
70 u_char id[NGX_QUIC_CID_LEN_MAX]; 70 u_char id[NGX_QUIC_CID_LEN_MAX];
71 u_char sr_token[NGX_QUIC_SR_TOKEN_LEN]; 71 u_char sr_token[NGX_QUIC_SR_TOKEN_LEN];
72 ngx_uint_t refcnt; 72 ngx_uint_t used; /* unsigned used:1; */
73 }; 73 };
74 74
75 75
76 struct ngx_quic_server_id_s { 76 struct ngx_quic_server_id_s {
77 uint64_t seqnum; 77 uint64_t seqnum;
81 81
82 82
83 struct ngx_quic_path_s { 83 struct ngx_quic_path_s {
84 ngx_queue_t queue; 84 ngx_queue_t queue;
85 struct sockaddr *sockaddr; 85 struct sockaddr *sockaddr;
86 ngx_sockaddr_t sa;
86 socklen_t socklen; 87 socklen_t socklen;
87 ngx_uint_t state; 88 ngx_quic_client_id_t *cid;
88 ngx_uint_t limited; /* unsigned limited:1; */
89 ngx_msec_t expires; 89 ngx_msec_t expires;
90 ngx_msec_t last_seen;
91 ngx_uint_t tries; 90 ngx_uint_t tries;
91 ngx_uint_t tag;
92 off_t sent; 92 off_t sent;
93 off_t received; 93 off_t received;
94 u_char challenge1[8]; 94 u_char challenge1[8];
95 u_char challenge2[8]; 95 u_char challenge2[8];
96 ngx_uint_t refcnt;
97 uint64_t seqnum; 96 uint64_t seqnum;
98 ngx_str_t addr_text; 97 ngx_str_t addr_text;
99 u_char text[NGX_SOCKADDR_STRLEN]; 98 u_char text[NGX_SOCKADDR_STRLEN];
99 unsigned validated:1;
100 unsigned validating:1;
101 unsigned limited:1;
100 }; 102 };
101 103
102 104
103 struct ngx_quic_socket_s { 105 struct ngx_quic_socket_s {
104 ngx_udp_connection_t udp; 106 ngx_udp_connection_t udp;
105 ngx_quic_connection_t *quic; 107 ngx_quic_connection_t *quic;
106 ngx_queue_t queue; 108 ngx_queue_t queue;
107
108 ngx_quic_server_id_t sid; 109 ngx_quic_server_id_t sid;
109 110 ngx_uint_t used; /* unsigned used:1; */
110 ngx_quic_path_t *path;
111 ngx_quic_client_id_t *cid;
112 }; 111 };
113 112
114 113
115 typedef struct { 114 typedef struct {
116 ngx_rbtree_t tree; 115 ngx_rbtree_t tree;
182 181
183 182
184 struct ngx_quic_connection_s { 183 struct ngx_quic_connection_s {
185 uint32_t version; 184 uint32_t version;
186 185
187 ngx_quic_socket_t *socket; 186 ngx_quic_path_t *path;
188 ngx_quic_socket_t *backup;
189 187
190 ngx_queue_t sockets; 188 ngx_queue_t sockets;
191 ngx_queue_t paths; 189 ngx_queue_t paths;
192 ngx_queue_t client_ids; 190 ngx_queue_t client_ids;
193 ngx_queue_t free_sockets; 191 ngx_queue_t free_sockets;