diff options
author | Oto Šťáva <oto.stava@nic.cz> | 2023-03-22 10:42:44 +0100 |
---|---|---|
committer | Oto Šťáva <oto.stava@nic.cz> | 2023-03-22 10:42:44 +0100 |
commit | 713ba54783a650a9100756a43e29f94a62fd0306 (patch) | |
tree | 02061ff8435253c89b1325d18a7aca85d53bb2f9 | |
parent | daemon: fix assertion errors on duplicate peers (diff) | |
download | knot-resolver-713ba54783a650a9100756a43e29f94a62fd0306.tar.xz knot-resolver-713ba54783a650a9100756a43e29f94a62fd0306.zip |
daemon: move connected flag from session to worker
-rw-r--r-- | daemon/session2.h | 5 | ||||
-rw-r--r-- | daemon/worker.c | 20 |
2 files changed, 12 insertions, 13 deletions
diff --git a/daemon/session2.h b/daemon/session2.h index 392e1935..00fa388c 100644 --- a/daemon/session2.h +++ b/daemon/session2.h @@ -847,11 +847,6 @@ struct session2 { * return a Bad Request status on a malformed query. */ bool custom_emalf_handling : 1; - /** If true, a connection is established. Only applicable to sessions - * using connection-based protocols. One of the stream-based protocol - * layers is going to be the writer for this flag. */ - bool connected : 1; - /** If true, session is being rate-limited. One of the protocol layers * is going to be the writer for this flag. */ bool throttled : 1; diff --git a/daemon/worker.c b/daemon/worker.c index 2e8fcfe3..813df6c7 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1801,6 +1801,7 @@ struct pl_dns_stream_sess_data { struct protolayer_data h; bool single : 1; /**< True: Stream only allows a single packet */ bool produced : 1; /**< True: At least one packet has been produced */ + bool connected : 1; /**< True: The stream is connected */ }; struct pl_dns_stream_iter_data { @@ -1893,12 +1894,12 @@ static enum protolayer_event_cb_result pl_dns_stream_resolution_timeout( } static enum protolayer_event_cb_result pl_dns_stream_connected( - struct session2 *session) + struct session2 *session, struct pl_dns_stream_sess_data *stream) { - if (kr_fails_assert(!session->connected)) + if (kr_fails_assert(!stream->connected)) return PROTOLAYER_EVENT_PROPAGATE; - session->connected = true; + stream->connected = true; struct sockaddr *peer = session2_get_peer(session); if (session->outgoing && worker_del_tcp_waiting(peer) != 0) { @@ -1971,16 +1972,16 @@ static enum protolayer_event_cb_result pl_dns_stream_connection_fail( } static enum protolayer_event_cb_result pl_dns_stream_disconnected( - struct session2 *session) + struct session2 *session, struct pl_dns_stream_sess_data *stream) { struct sockaddr *peer = session2_get_peer(session); worker_del_tcp_waiting(peer); worker_del_tcp_connected(peer); - if (!session->connected) + if (!stream->connected) return PROTOLAYER_EVENT_PROPAGATE; - session->connected = false; + stream->connected = false; while (!session2_waitinglist_is_empty(session)) { struct qr_task *task = session2_waitinglist_pop(session, false); @@ -2032,6 +2033,8 @@ static enum protolayer_event_cb_result pl_dns_stream_event_unwrap( if (session->closing) return PROTOLAYER_EVENT_PROPAGATE; + struct pl_dns_stream_sess_data *stream = sess_data; + switch (event) { case PROTOLAYER_EVENT_GENERAL_TIMEOUT: return pl_dns_stream_resolution_timeout(manager->session); @@ -2041,7 +2044,7 @@ static enum protolayer_event_cb_result pl_dns_stream_event_unwrap( KR_SELECTION_TCP_CONNECT_TIMEOUT); case PROTOLAYER_EVENT_CONNECT: - return pl_dns_stream_connected(session); + return pl_dns_stream_connected(session, stream); case PROTOLAYER_EVENT_CONNECT_FAIL:; enum kr_selection_error err = (*baton) @@ -2052,7 +2055,7 @@ static enum protolayer_event_cb_result pl_dns_stream_event_unwrap( case PROTOLAYER_EVENT_DISCONNECT: case PROTOLAYER_EVENT_CLOSE: case PROTOLAYER_EVENT_FORCE_CLOSE: - return pl_dns_stream_disconnected(session); + return pl_dns_stream_disconnected(session, stream); default: return PROTOLAYER_EVENT_PROPAGATE; @@ -2293,6 +2296,7 @@ int worker_init(void) .event_unwrap = pl_dns_dgram_event_unwrap }; protolayer_globals[PROTOLAYER_PROTOCOL_DNS_UNSIZED_STREAM] = (struct protolayer_globals){ + .sess_size = sizeof(struct pl_dns_stream_sess_data), .wire_buf_overhead = KNOT_WIRE_MAX_PKTSIZE, .sess_init = pl_dns_stream_sess_init, .unwrap = pl_dns_dgram_unwrap, |