Commit c0330b42 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Tabelize a lot of rfc7540 "MUST" error handling

parent e9f32d62
...@@ -54,7 +54,7 @@ typedef const struct h2_error_s *h2_error; ...@@ -54,7 +54,7 @@ typedef const struct h2_error_s *h2_error;
enum h2_frame_e { enum h2_frame_e {
H2_FRAME__DUMMY = -1, H2_FRAME__DUMMY = -1,
#define H2_FRAME(l,u,t,f) H2_FRAME_##u = t, #define H2_FRAME(l,u,t,f,...) H2_FRAME_##u = t,
#include "tbl/h2_frames.h" #include "tbl/h2_frames.h"
}; };
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
typedef h2_error h2_frame_f(struct worker *, struct h2_sess *, struct h2_req *); typedef h2_error h2_frame_f(struct worker *, struct h2_sess *, struct h2_req *);
enum h2frame { enum h2frame {
#define H2_FRAME(l,u,t,f) H2F_##u = t, #define H2_FRAME(l,u,t,f,...) H2F_##u = t,
#include "tbl/h2_frames.h" #include "tbl/h2_frames.h"
}; };
...@@ -64,7 +64,7 @@ h2_framename(enum h2frame h2f) ...@@ -64,7 +64,7 @@ h2_framename(enum h2frame h2f)
{ {
switch(h2f) { switch(h2f) {
#define H2_FRAME(l,u,t,f) case H2F_##u: return #u; #define H2_FRAME(l,u,t,f,...) case H2F_##u: return #u;
#include "tbl/h2_frames.h" #include "tbl/h2_frames.h"
default: default:
return (NULL); return (NULL);
...@@ -557,10 +557,13 @@ struct h2flist_s { ...@@ -557,10 +557,13 @@ struct h2flist_s {
const char *name; const char *name;
h2_frame_f *func; h2_frame_f *func;
uint8_t flags; uint8_t flags;
h2_error act_szero;
h2_error act_snonzero;
h2_error act_sidle;
}; };
static const struct h2flist_s h2flist[] = { static const struct h2flist_s h2flist[] = {
#define H2_FRAME(l,U,t,f) [t] = { #U, h2_rx_##l, f }, #define H2_FRAME(l,U,t,f,az,anz,ai) [t] = { #U, h2_rx_##l, f, az, anz,ai },
#include "tbl/h2_frames.h" #include "tbl/h2_frames.h"
}; };
...@@ -574,6 +577,38 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2) ...@@ -574,6 +577,38 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2)
h2_error h2e; h2_error h2e;
char b[4]; char b[4];
if (h2->rxf_type >= H2FMAX) {
// rfc7540,l,679,681
h2->bogosity++;
VSLb(h2->vsl, SLT_Debug,
"H2: Unknown Frame 0x%02x", h2->rxf_type);
return (0);
}
h2f = h2flist + h2->rxf_type;
if (h2f->name == NULL || h2f->func == NULL) {
// rfc7540,l,679,681
h2->bogosity++;
VSLb(h2->vsl, SLT_Debug,
"H2: Unimplemented Frame 0x%02x", h2->rxf_type);
return (0);
}
if (h2->rxf_flags & ~h2f->flags) {
// rfc7540,l,687,688
h2->bogosity++;
VSLb(h2->vsl, SLT_Debug, "H2: Bad flags 0x%02x on %s",
h2->rxf_flags, h2f->name);
h2->rxf_flags &= h2f->flags;
}
if (h2->rxf_stream == 0 && h2f->act_szero != 0)
return (h2f->act_szero);
if (h2->rxf_stream != 0 && h2f->act_snonzero != 0)
return (h2f->act_snonzero);
if (h2->rxf_stream > h2->highest_stream && h2f->act_sidle != 0)
return (h2f->act_sidle);
if (h2->rxf_stream != 0 && !(h2->rxf_stream & 1)) { if (h2->rxf_stream != 0 && !(h2->rxf_stream & 1)) {
// rfc7540,l,1140,1145 // rfc7540,l,1140,1145
// rfc7540,l,1153,1158 // rfc7540,l,1153,1158
...@@ -594,7 +629,7 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2) ...@@ -594,7 +629,7 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2)
if (h2->rxf_stream == 0) // rfc7540,l,1993,1996 if (h2->rxf_stream == 0) // rfc7540,l,1993,1996
return (H2CE_PROTOCOL_ERROR); return (H2CE_PROTOCOL_ERROR);
if (h2->rxf_stream > h2->highest_stream)// rfc7540,l,1998,2001 if (h2->rxf_stream > h2->highest_stream)// rfc7540,l,1998,2001
return (H2CE_PROTOCOL_ERROR); return (H2CE_PROTOCOL_ERROR);
if (r2 == NULL) if (r2 == NULL)
return (0); return (0);
} }
...@@ -607,28 +642,6 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2) ...@@ -607,28 +642,6 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2)
AN(r2); AN(r2);
} }
if (h2->rxf_type >= H2FMAX) {
// rfc7540,l,679,681
h2->bogosity++;
VSLb(h2->vsl, SLT_Debug,
"H2: Unknown Frame 0x%02x", h2->rxf_type);
return (0);
}
h2f = h2flist + h2->rxf_type;
if (h2f->name == NULL || h2f->func == NULL) {
// rfc7540,l,679,681
h2->bogosity++;
VSLb(h2->vsl, SLT_Debug,
"H2: Unimplemented Frame 0x%02x", h2->rxf_type);
return (0);
}
if (h2->rxf_flags & ~h2f->flags) {
// rfc7540,l,687,688
h2->bogosity++;
VSLb(h2->vsl, SLT_Debug, "H2: Bad flags 0x%02x on %s",
h2->rxf_flags, h2f->name);
h2->rxf_flags &= h2f->flags;
}
h2e = h2f->func(wrk, h2, r2); h2e = h2f->func(wrk, h2, r2);
if (h2e == 0) if (h2e == 0)
return (0); return (0);
......
...@@ -35,10 +35,10 @@ client c1 { ...@@ -35,10 +35,10 @@ client c1 {
expect goaway.err == PROTOCOL_ERROR expect goaway.err == PROTOCOL_ERROR
} -start } -start
stream 3 { stream 3 {
txwinup -size 1 txprio
} -run } -run
stream 1 { stream 1 {
txwinup -size 1 txprio
} -run } -run
stream 0 -wait stream 0 -wait
} -run } -run
...@@ -48,11 +48,13 @@ client c1 { ...@@ -48,11 +48,13 @@ client c1 {
client c1 { client c1 {
stream 1 { stream 1 {
txprio
txwinup -size 0 txwinup -size 0
rxrst rxrst
expect rst.err == PROTOCOL_ERROR expect rst.err == PROTOCOL_ERROR
} -run } -run
stream 3 { stream 3 {
txprio
txwinup -size 0x40000000 txwinup -size 0x40000000
txwinup -size 0x40000000 txwinup -size 0x40000000
rxrst rxrst
...@@ -64,6 +66,7 @@ client c1 { ...@@ -64,6 +66,7 @@ client c1 {
expect goaway.err == FRAME_SIZE_ERROR expect goaway.err == FRAME_SIZE_ERROR
} -start } -start
stream 5 { stream 5 {
txprio
sendhex "000003 08 00 00000005 010203" sendhex "000003 08 00 00000005 010203"
} -run } -run
stream 0 -wait stream 0 -wait
...@@ -97,7 +100,7 @@ client c1 { ...@@ -97,7 +100,7 @@ client c1 {
stream 0 { stream 0 {
rxgoaway rxgoaway
expect goaway.err == PROTOCOL_ERROR expect goaway.err == PROTOCOL_ERROR
expect goaway.laststream == 1 expect goaway.laststream == 0
} -start } -start
stream 1 { stream 1 {
sendhex "000008 05 00 00000001 0001020304050607" sendhex "000008 05 00 00000001 0001020304050607"
...@@ -119,12 +122,16 @@ client c1 { ...@@ -119,12 +122,16 @@ client c1 {
client c1 { client c1 {
stream 0 { stream 0 {
# RST wrong length
sendhex "000005 03 00 00000001 0000000800"
rxgoaway rxgoaway
expect goaway.err == FRAME_SIZE_ERROR expect goaway.err == FRAME_SIZE_ERROR
expect goaway.laststream == 0 expect goaway.laststream == 1
} -start
stream 1 {
txprio
# RST wrong length
sendhex "000005 03 00 00000001 0000000800"
} -run } -run
stream 0 -wait
} -run } -run
client c1 { client c1 {
...@@ -132,7 +139,7 @@ client c1 { ...@@ -132,7 +139,7 @@ client c1 {
# RST stream zero # RST stream zero
sendhex "000000 03 00 00000000 00000008" sendhex "000000 03 00 00000000 00000008"
rxgoaway rxgoaway
expect goaway.err == FRAME_SIZE_ERROR expect goaway.err == PROTOCOL_ERROR
expect goaway.laststream == 0 expect goaway.laststream == 0
} -run } -run
} -run } -run
...@@ -62,7 +62,7 @@ static const char *const h2_errs[] = { ...@@ -62,7 +62,7 @@ static const char *const h2_errs[] = {
}; };
static const char *const h2_types[] = { static const char *const h2_types[] = {
#define H2_FRAME(l,u,t,f) [t] = #u, #define H2_FRAME(l,u,t,f,...) [t] = #u,
#include <tbl/h2_frames.h> #include <tbl/h2_frames.h>
NULL NULL
}; };
...@@ -77,7 +77,7 @@ static const char * const h2_settings[] = { ...@@ -77,7 +77,7 @@ static const char * const h2_settings[] = {
}; };
enum h2_type { enum h2_type {
#define H2_FRAME(l,u,t,f) TYPE_##u = t, #define H2_FRAME(l,u,t,f,...) TYPE_##u = t,
#include <tbl/h2_frames.h> #include <tbl/h2_frames.h>
TYPE_MAX TYPE_MAX
}; };
......
...@@ -31,17 +31,61 @@ ...@@ -31,17 +31,61 @@
/*lint -save -e525 -e539 */ /*lint -save -e525 -e539 */
#ifdef H2_FRAME #ifdef H2_FRAME
/* lower, upper, type, valid flags */ /* lower, upper, type, flags
H2_FRAME(data, DATA, 0x0, 0x09) * stream-zero
H2_FRAME(headers, HEADERS, 0x1, 0x2d) * stream-nonzero
H2_FRAME(priority, PRIORITY, 0x2, 0x00) * stream-idle
H2_FRAME(rst_stream, RST_STREAM, 0x3, 0x00) */
H2_FRAME(settings, SETTINGS, 0x4, 0x01) H2_FRAME(data, DATA, 0x0, 0x09,
H2_FRAME(push_promise, PUSH_PROMISE, 0x5, 0x0c) H2CE_PROTOCOL_ERROR, // rfc7540,l,1758,1761
H2_FRAME(ping, PING, 0x6, 0x01) 0,
H2_FRAME(goaway, GOAWAY, 0x7, 0x00) H2CE_PROTOCOL_ERROR
H2_FRAME(window_update, WINDOW_UPDATE, 0x8, 0x00) )
H2_FRAME(continuation, CONTINUATION, 0x9, 0x04) H2_FRAME(headers, HEADERS, 0x1, 0x2d,
H2CE_PROTOCOL_ERROR, // rfc7540,l,1876,1879
0,
0 // rfc7540,l,938,940
)
H2_FRAME(priority, PRIORITY, 0x2, 0x00,
H2CE_PROTOCOL_ERROR, // rfc7540,l,1933,1936
0,
0 // rfc7540,l,938,940
)
H2_FRAME(rst_stream, RST_STREAM, 0x3, 0x00,
H2CE_PROTOCOL_ERROR, // rfc7540,l,1993,1996
0,
H2CE_PROTOCOL_ERROR
)
H2_FRAME(settings, SETTINGS, 0x4, 0x01,
0,
H2CE_PROTOCOL_ERROR, // rfc7540,l,2052,2056
H2CE_PROTOCOL_ERROR
)
H2_FRAME(push_promise, PUSH_PROMISE, 0x5, 0x0c,
H2CE_PROTOCOL_ERROR, // rfc7540,l,2262,2263
0,
H2CE_PROTOCOL_ERROR
)
H2_FRAME(ping, PING, 0x6, 0x01,
0,
H2CE_PROTOCOL_ERROR, // rfc7540,l,2359,2362
H2CE_PROTOCOL_ERROR
)
H2_FRAME(goaway, GOAWAY, 0x7, 0x00,
0,
H2CE_PROTOCOL_ERROR, // rfc7540,l,2432,2435
H2CE_PROTOCOL_ERROR
)
H2_FRAME(window_update, WINDOW_UPDATE, 0x8, 0x00,
0,
0,
H2CE_PROTOCOL_ERROR
)
H2_FRAME(continuation, CONTINUATION, 0x9, 0x04,
H2CE_PROTOCOL_ERROR, // rfc7540,l,2764,2767
0,
H2CE_PROTOCOL_ERROR
)
#undef H2_FRAME #undef H2_FRAME
#endif #endif
......
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