[master] c0330b4 Tabelize a lot of rfc7540 "MUST" error handling

Poul-Henning Kamp phk at FreeBSD.org
Sat Mar 4 19:55:05 CET 2017


commit c0330b4217714537f6f8463e88c3c7ee91209385
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Mar 4 18:54:09 2017 +0000

    Tabelize a lot of rfc7540 "MUST" error handling

diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h
index 3bf6eb0..38bf8c6 100644
--- a/bin/varnishd/http2/cache_http2.h
+++ b/bin/varnishd/http2/cache_http2.h
@@ -54,7 +54,7 @@ typedef const struct h2_error_s *h2_error;
 
 enum h2_frame_e {
 	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"
 };
 
diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index b2326e8..dd7f61c 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -55,7 +55,7 @@
 typedef h2_error h2_frame_f(struct worker *, struct h2_sess *, struct h2_req *);
 
 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"
 };
 
@@ -64,7 +64,7 @@ h2_framename(enum h2frame 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"
 	default:
 		return (NULL);
@@ -557,10 +557,13 @@ struct h2flist_s {
 	const char	*name;
 	h2_frame_f	*func;
 	uint8_t		flags;
+	h2_error	act_szero;
+	h2_error	act_snonzero;
+	h2_error	act_sidle;
 };
 
 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"
 };
 
@@ -574,6 +577,38 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2)
 	h2_error h2e;
 	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)) {
 		// rfc7540,l,1140,1145
 		// rfc7540,l,1153,1158
@@ -594,7 +629,7 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2)
 		if (h2->rxf_stream == 0)		// rfc7540,l,1993,1996
 			return (H2CE_PROTOCOL_ERROR);
 		if (h2->rxf_stream > h2->highest_stream)// rfc7540,l,1998,2001
-			return (H2CE_PROTOCOL_ERROR);	
+			return (H2CE_PROTOCOL_ERROR);
 		if (r2 == NULL)
 			return (0);
 	}
@@ -607,28 +642,6 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2)
 		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);
 	if (h2e == 0)
 		return (0);
diff --git a/bin/varnishtest/tests/t02003.vtc b/bin/varnishtest/tests/t02003.vtc
index 89f6298..ed7ce70 100644
--- a/bin/varnishtest/tests/t02003.vtc
+++ b/bin/varnishtest/tests/t02003.vtc
@@ -35,10 +35,10 @@ client c1 {
 		expect goaway.err == PROTOCOL_ERROR
 	} -start
 	stream 3 {
-		txwinup -size 1
+		txprio
 	} -run
 	stream 1 {
-		txwinup -size 1
+		txprio
 	} -run
 	stream 0 -wait
 } -run
@@ -48,11 +48,13 @@ client c1 {
 
 client c1 {
 	stream 1 {
+		txprio
 		txwinup -size 0
 		rxrst
 		expect rst.err == PROTOCOL_ERROR
 	} -run
 	stream 3 {
+		txprio
 		txwinup -size 0x40000000
 		txwinup -size 0x40000000
 		rxrst
@@ -64,6 +66,7 @@ client c1 {
 		expect goaway.err == FRAME_SIZE_ERROR
 	} -start
 	stream 5 {
+		txprio
 		sendhex "000003 08 00 00000005 010203"
 	} -run
 	stream 0 -wait
@@ -97,7 +100,7 @@ client c1 {
 	stream 0 {
 		rxgoaway
 		expect goaway.err == PROTOCOL_ERROR
-		expect goaway.laststream == 1
+		expect goaway.laststream == 0
 	} -start
 	stream 1 {
 		sendhex "000008 05 00 00000001 0001020304050607"
@@ -119,12 +122,16 @@ client c1 {
 
 client c1 {
 	stream 0 {
-		# RST wrong length
-		sendhex "000005 03 00 00000001 0000000800"
 		rxgoaway
 		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
+	stream 0 -wait
 } -run
 
 client c1 {
@@ -132,7 +139,7 @@ client c1 {
 		# RST stream zero
 		sendhex "000000 03 00 00000000 00000008"
 		rxgoaway
-		expect goaway.err == FRAME_SIZE_ERROR
+		expect goaway.err == PROTOCOL_ERROR
 		expect goaway.laststream == 0
 	} -run
 } -run
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 6b8f7d7..f1f03f6 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -62,7 +62,7 @@ static const char *const h2_errs[] = {
 };
 
 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>
 	NULL
 };
@@ -77,7 +77,7 @@ static const char * const h2_settings[] = {
 };
 
 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>
 	TYPE_MAX
 };
diff --git a/include/tbl/h2_frames.h b/include/tbl/h2_frames.h
index c7dc822..29c338f 100644
--- a/include/tbl/h2_frames.h
+++ b/include/tbl/h2_frames.h
@@ -31,17 +31,61 @@
 /*lint -save -e525 -e539 */
 
 #ifdef H2_FRAME
-/*	   lower,               upper,         type, valid flags */
-  H2_FRAME(data,		DATA,		0x0, 0x09)
-  H2_FRAME(headers,		HEADERS,	0x1, 0x2d)
-  H2_FRAME(priority,		PRIORITY,	0x2, 0x00)
-  H2_FRAME(rst_stream,		RST_STREAM,	0x3, 0x00)
-  H2_FRAME(settings,		SETTINGS,	0x4, 0x01)
-  H2_FRAME(push_promise,	PUSH_PROMISE,	0x5, 0x0c)
-  H2_FRAME(ping,		PING,		0x6, 0x01)
-  H2_FRAME(goaway,		GOAWAY,		0x7, 0x00)
-  H2_FRAME(window_update,	WINDOW_UPDATE,	0x8, 0x00)
-  H2_FRAME(continuation,	CONTINUATION,	0x9, 0x04)
+/*	   lower,               upper,         type, flags
+ *	stream-zero
+ *	stream-nonzero
+ *	stream-idle
+ */
+  H2_FRAME(data,		DATA,		0x0, 0x09,
+	H2CE_PROTOCOL_ERROR,		// rfc7540,l,1758,1761
+	0,
+	H2CE_PROTOCOL_ERROR
+  )
+  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
 #endif
 



More information about the varnish-commit mailing list