Commit 49c224e7 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

h2: Add a sess_close reason to h2 connection errors

And use that for logging purposes when a successfully opened h2 session
ends. RX_JUNK is still the default session close reason when existing
reasons aren't accurate enough.

Fixes #3393
parent da36ce3c
......@@ -42,15 +42,15 @@ struct h2_error_s {
uint32_t val;
int stream;
int connection;
enum sess_close reason;
};
typedef const struct h2_error_s *h2_error;
#define H2EC0(U,v,d)
#define H2EC1(U,v,d) extern const struct h2_error_s H2CE_##U[1];
#define H2EC2(U,v,d) extern const struct h2_error_s H2SE_##U[1];
#define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d)
#define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc)
#define H2EC1(U,v,r,d) extern const struct h2_error_s H2CE_##U[1];
#define H2EC2(U,v,r,d) extern const struct h2_error_s H2SE_##U[1];
#define H2EC3(U,v,r,d) H2EC1(U,v,r,d) H2EC2(U,v,r,d)
#define H2_ERROR(NAME, val, sc, reason, desc) H2EC##sc(NAME, val, reason, desc)
#include "tbl/h2_error.h"
#undef H2EC1
#undef H2EC2
......
......@@ -43,10 +43,10 @@
#include "vtcp.h"
#include "vtim.h"
#define H2EC1(U,v,d) const struct h2_error_s H2CE_##U[1] = {{#U,d,v,0,1}};
#define H2EC2(U,v,d) const struct h2_error_s H2SE_##U[1] = {{#U,d,v,1,0}};
#define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d)
#define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc)
#define H2EC1(U,v,r,d) const struct h2_error_s H2CE_##U[1] = {{#U,d,v,0,1,r}};
#define H2EC2(U,v,r,d) const struct h2_error_s H2SE_##U[1] = {{#U,d,v,1,0,r}};
#define H2EC3(U,v,r,d) H2EC1(U,v,r,d) H2EC2(U,v,r,d)
#define H2_ERROR(NAME, val, sc, reason, desc) H2EC##sc(NAME, val, reason, desc)
#include "tbl/h2_error.h"
#undef H2EC1
#undef H2EC2
......@@ -57,7 +57,8 @@ static const struct h2_error_s H2NN_ERROR[1] = {{
"Unknown error number",
0xffffffff,
1,
1
1,
SC_RX_JUNK
}};
enum h2frame {
......@@ -84,10 +85,10 @@ h2_framename(enum h2frame h2f)
*/
static const h2_error stream_errors[] = {
#define H2EC1(U,v,d)
#define H2EC2(U,v,d) [v] = H2SE_##U,
#define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d)
#define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc)
#define H2EC1(U,v,r,d)
#define H2EC2(U,v,r,d) [v] = H2SE_##U,
#define H2EC3(U,v,r,d) H2EC1(U,v,r,d) H2EC2(U,v,r,d)
#define H2_ERROR(NAME, val, sc, reason, desc) H2EC##sc(NAME, val, reason, desc)
#include "tbl/h2_error.h"
#undef H2EC1
#undef H2EC2
......@@ -109,10 +110,10 @@ h2_streamerror(uint32_t u)
*/
static const h2_error conn_errors[] = {
#define H2EC1(U,v,d) [v] = H2CE_##U,
#define H2EC2(U,v,d)
#define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d)
#define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc)
#define H2EC1(U,v,r,d) [v] = H2CE_##U,
#define H2EC2(U,v,r,d)
#define H2EC3(U,v,r,d) H2EC1(U,v,r,d) H2EC2(U,v,r,d)
#define H2_ERROR(NAME, val, sc, reason, desc) H2EC##sc(NAME, val, reason, desc)
#include "tbl/h2_error.h"
#undef H2EC1
#undef H2EC2
......
......@@ -144,6 +144,7 @@ h2_del_sess(struct worker *wrk, struct h2_sess *h2, enum sess_close reason)
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC);
AZ(h2->refcnt);
assert(VTAILQ_EMPTY(&h2->streams));
AN(reason);
VHT_Fini(h2->dectbl);
AZ(pthread_cond_destroy(h2->winupd_cond));
......@@ -433,8 +434,7 @@ h2_new_session(struct worker *wrk, void *arg)
h2->cond = NULL;
assert(h2->refcnt == 1);
h2_del_req(wrk, h2->req0);
/* TODO: proper sess close reason */
h2_del_sess(wrk, h2, SC_RX_JUNK);
h2_del_sess(wrk, h2, h2->error->reason);
}
struct transport H2_transport = {
......
......@@ -51,7 +51,7 @@
#define BUF_SIZE (1024*2048)
static const char *const h2_errs[] = {
#define H2_ERROR(n,v,sc,t) [v] = #n,
#define H2_ERROR(n,v,sc,r,t) [v] = #n,
#include <tbl/h2_error.h>
NULL
};
......@@ -1204,7 +1204,7 @@ cmd_var_resolve(const struct stream *s, const char *spec, char *buf)
else
return (NULL);
}
#define H2_ERROR(U,v,sc,t) \
#define H2_ERROR(U,v,sc,r,t) \
if (!strcmp(spec, #U)) { return (#v); }
#include "tbl/h2_error.h"
return (spec);
......
......@@ -28,6 +28,7 @@
* RFC7540 section 11.4
*
* Types: conn=1|stream=2
* Reason: enum sess_close
*/
/*lint -save -e525 -e539 */
......@@ -36,6 +37,7 @@ H2_ERROR(
/* name */ NO_ERROR,
/* val */ 0,
/* types */ 3,
/* reason */ SC_REM_CLOSE,
/* descr */ "Graceful shutdown"
)
......@@ -43,6 +45,7 @@ H2_ERROR(
/* name */ PROTOCOL_ERROR,
/* val */ 1,
/* types */ 3,
/* reason */ SC_RX_JUNK,
/* descr */ "Protocol error detected"
)
......@@ -50,6 +53,7 @@ H2_ERROR(
/* name */ INTERNAL_ERROR,
/* val */ 2,
/* types */ 3,
/* reason */ SC_VCL_FAILURE,
/* descr */ "Implementation fault"
)
......@@ -57,6 +61,7 @@ H2_ERROR(
/* name */ FLOW_CONTROL_ERROR,
/* val */ 3,
/* types */ 3,
/* reason */ SC_OVERLOAD,
/* descr */ "Flow-control limits exceeded"
)
......@@ -64,6 +69,7 @@ H2_ERROR(
/* name */ SETTINGS_TIMEOUT,
/* val */ 4,
/* types */ 1,
/* reason */ SC_RX_TIMEOUT,
/* descr */ "Settings not acknowledged"
)
......@@ -71,6 +77,7 @@ H2_ERROR(
/* name */ STREAM_CLOSED,
/* val */ 5,
/* types */ 2,
/* reason */ SC_NULL,
/* descr */ "Frame received for closed stream"
)
......@@ -78,6 +85,7 @@ H2_ERROR(
/* name */ FRAME_SIZE_ERROR,
/* val */ 6,
/* types */ 3,
/* reason */ SC_RX_JUNK,
/* descr */ "Frame size incorrect"
)
......@@ -85,6 +93,7 @@ H2_ERROR(
/* name */ REFUSED_STREAM,
/* val */ 7,
/* types */ 2,
/* reason */ SC_NULL,
/* descr */ "Stream not processed"
)
......@@ -92,6 +101,7 @@ H2_ERROR(
/* name */ CANCEL,
/* val */ 8,
/* types */ 2,
/* reason */ SC_NULL,
/* descr */ "Stream cancelled"
)
......@@ -99,6 +109,7 @@ H2_ERROR(
/* name */ COMPRESSION_ERROR,
/* val */ 9,
/* types */ 1,
/* reason */ SC_RX_JUNK,
/* descr */ "Compression state not updated"
)
......@@ -106,6 +117,7 @@ H2_ERROR(
/* name */ CONNECT_ERROR,
/* val */ 10,
/* types */ 2,
/* reason */ SC_NULL,
/* descr */ "TCP connection error for CONNECT method"
)
......@@ -113,6 +125,7 @@ H2_ERROR(
/* name */ ENHANCE_YOUR_CALM,
/* val */ 11,
/* types */ 3,
/* reason */ SC_OVERLOAD,
/* descr */ "Processing capacity exceeded"
)
......@@ -120,6 +133,7 @@ H2_ERROR(
/* name */ INADEQUATE_SECURITY,
/* val */ 12,
/* types */ 1,
/* reason */ SC_RX_JUNK,
/* descr */ "Negotiated TLS parameters not acceptable"
)
......@@ -127,6 +141,7 @@ H2_ERROR(
/* name */ HTTP_1_1_REQUIRED,
/* val */ 13,
/* types */ 1,
/* reason */ SC_REQ_HTTP20,
/* descr */ "Use HTTP/1.1 for the request"
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment