Browse code

Merge 7e5dc0d7b1c2735becbf7944add9678dc72ba3a7 into 3d4f5fcafd4ecdee2ccdd0a81fe855dd8cea8549

Alex Hermann authored on 19/10/2020 12:46:31 • GitHub committed on 19/10/2020 12:46:31
Showing 7 changed files
... ...
@@ -77,8 +77,14 @@ union sockaddr_union{
77 77
 };
78 78
 
79 79
 
80
-enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4,
81
-	SI_IS_ANY=8, SI_IS_MHOMED=16 };
80
+enum si_flags {
81
+	SI_NONE         = 0,
82
+	SI_IS_IP        = (1<<0),
83
+	SI_IS_LO        = (1<<1),
84
+	SI_IS_MCAST     = (1<<2),
85
+	SI_IS_ANY       = (1<<3),
86
+	SI_IS_MHOMED    = (1<<4),
87
+};
82 88
 
83 89
 typedef struct addr_info {
84 90
 	str name; /* name - eg.: foo.bar or 10.0.0.1 */
... ...
@@ -128,9 +134,11 @@ typedef struct socket_info {
128 134
 
129 135
 
130 136
 /* send flags */
131
-#define SND_F_FORCE_CON_REUSE	1 /* reuse an existing connection or fail */
132
-#define SND_F_CON_CLOSE			2 /* close the connection after sending */
133
-#define SND_F_FORCE_SOCKET		4 /* send socket in dst is forced */
137
+enum send_flags {
138
+	SND_F_FORCE_CON_REUSE   = (1 << 0), /* reuse an existing connection or fail */
139
+	SND_F_CON_CLOSE         = (1 << 1), /* close the connection after sending */
140
+	SND_F_FORCE_SOCKET      = (1 << 2), /* send socket in dst is forced */
141
+};
134 142
 
135 143
 typedef struct snd_flags {
136 144
 	unsigned short f;          /* snd flags */
... ...
@@ -121,6 +121,27 @@ enum conn_cmds {
121 121
 /* CONN_RELEASE, EOF, ERROR, DESTROY can be used by "reader" processes
122 122
  * CONN_GET_FD, CONN_NEW*, CONN_QUEUED_WRITE only by writers */
123 123
 
124
+/* tcp_req flags */
125
+enum tcp_req_flags {
126
+	F_TCP_REQ_HAS_CLEN      = (1<<0),
127
+	F_TCP_REQ_COMPLETE      = (1<<1),
128
+#ifdef READ_HTTP11
129
+	F_TCP_REQ_BCHUNKED      = (1<<2),
130
+#endif
131
+#ifdef READ_MSRP
132
+	F_TCP_REQ_MSRP_NO       = (1<<3),
133
+	F_TCP_REQ_MSRP_FRAME    = (1<<4),
134
+	F_TCP_REQ_MSRP_BODY     = (1<<5),
135
+#endif
136
+	F_TCP_REQ_HEP3          = (1<<6),
137
+};
138
+
139
+#define TCP_REQ_HAS_CLEN(tr)  ((tr)->flags & F_TCP_REQ_HAS_CLEN)
140
+#define TCP_REQ_COMPLETE(tr)  ((tr)->flags & F_TCP_REQ_COMPLETE)
141
+#ifdef READ_HTTP11
142
+#define TCP_REQ_BCHUNKED(tr)  ((tr)->flags & F_TCP_REQ_BCHUNKED)
143
+#endif
144
+
124 145
 struct tcp_req{
125 146
 	struct tcp_req* next;
126 147
 	/* sockaddr ? */
... ...
@@ -135,32 +156,12 @@ struct tcp_req{
135 156
 #ifdef READ_HTTP11
136 157
 	int chunk_size;
137 158
 #endif
138
-	unsigned int flags; /* F_TCP_REQ_HAS_CLEN | F_TCP_REQ_COMPLETE */
159
+	enum tcp_req_flags flags; /* F_TCP_REQ_HAS_CLEN | F_TCP_REQ_COMPLETE */
139 160
 	int bytes_to_go; /* how many bytes we have still to read from the body*/
140 161
 	enum tcp_req_errors error;
141 162
 	enum tcp_req_states state;
142 163
 };
143 164
 
144
-/* tcp_req flags */
145
-#define F_TCP_REQ_HAS_CLEN 1
146
-#define F_TCP_REQ_COMPLETE 2
147
-#ifdef READ_HTTP11
148
-#define F_TCP_REQ_BCHUNKED 4
149
-#endif
150
-#ifdef READ_MSRP
151
-#define F_TCP_REQ_MSRP_NO     8
152
-#define F_TCP_REQ_MSRP_FRAME  16
153
-#define F_TCP_REQ_MSRP_BODY   32
154
-#endif
155
-#define F_TCP_REQ_HEP3        64
156
-
157
-#define TCP_REQ_HAS_CLEN(tr)  ((tr)->flags & F_TCP_REQ_HAS_CLEN)
158
-#define TCP_REQ_COMPLETE(tr)  ((tr)->flags & F_TCP_REQ_COMPLETE)
159
-#ifdef READ_HTTP11
160
-#define TCP_REQ_BCHUNKED(tr)  ((tr)->flags & F_TCP_REQ_BCHUNKED)
161
-#endif
162
-
163
-
164 165
 struct tcp_connection;
165 166
 
166 167
 /* tcp port alias structure */
... ...
@@ -218,7 +218,7 @@ static int tcp_emit_closed_event(struct tcp_connection *con, enum tcp_closed_rea
218 218
  * EOF checking should be done by checking the RD_CONN_EOF flag.
219 219
  */
220 220
 int tcp_read_data(int fd, struct tcp_connection *c,
221
-					char* buf, int b_size, int* flags)
221
+					char* buf, int b_size, rd_conn_flags_t* flags)
222 222
 {
223 223
 	int bytes_read;
224 224
 
... ...
@@ -329,7 +329,7 @@ again:
329 329
  * (to distinguish from reads that would block which could return 0)
330 330
  * RD_CONN_SHORT_READ is also set in *flags for short reads.
331 331
  * sets also r->error */
332
-int tcp_read(struct tcp_connection *c, int* flags)
332
+int tcp_read(struct tcp_connection *c, rd_conn_flags_t* flags)
333 333
 {
334 334
 	int bytes_free, bytes_read;
335 335
 	struct tcp_req *r;
... ...
@@ -369,7 +369,7 @@ int tcp_read(struct tcp_connection *c, int* flags)
369 369
  * when either r->body!=0 or r->state==H_BODY =>
370 370
  * all headers have been read. It should be called in a while loop.
371 371
  * returns < 0 if error or 0 if EOF */
372
-int tcp_read_headers(struct tcp_connection *c, int* read_flags)
372
+int tcp_read_headers(struct tcp_connection *c, rd_conn_flags_t* read_flags)
373 373
 {
374 374
 	int bytes, remaining;
375 375
 	char *p;
... ...
@@ -1082,7 +1082,7 @@ int msrp_process_msg(char* tcpbuf, unsigned int len,
1082 1082
 #endif
1083 1083
 
1084 1084
 #ifdef READ_WS
1085
-static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1085
+static int tcp_read_ws(struct tcp_connection *c, rd_conn_flags_t* read_flags)
1086 1086
 {
1087 1087
 	int bytes;
1088 1088
 	uint32_t size, pos, mask_present, len;
... ...
@@ -1237,7 +1237,7 @@ static int ws_process_msg(char* tcpbuf, unsigned int len,
1237 1237
 }
1238 1238
 #endif
1239 1239
 
1240
-static int tcp_read_hep3(struct tcp_connection *c, int* read_flags)
1240
+static int tcp_read_hep3(struct tcp_connection *c, rd_conn_flags_t* read_flags)
1241 1241
 {
1242 1242
 	int bytes;
1243 1243
 	uint32_t size, len;
... ...
@@ -1429,7 +1429,7 @@ int receive_tcp_msg(char* tcpbuf, unsigned int len,
1429 1429
 #endif /* TCP_CLONE_RCVBUF */
1430 1430
 }
1431 1431
 
1432
-int tcp_read_req(struct tcp_connection* con, int* bytes_read, int* read_flags)
1432
+int tcp_read_req(struct tcp_connection* con, int* bytes_read, rd_conn_flags_t* read_flags)
1433 1433
 {
1434 1434
 	int bytes;
1435 1435
 	int total_bytes;
... ...
@@ -1712,7 +1712,7 @@ inline static int handle_io(struct fd_map* fm, short events, int idx)
1712 1712
 {
1713 1713
 	int ret;
1714 1714
 	int n;
1715
-	int read_flags;
1715
+	rd_conn_flags_t read_flags;
1716 1716
 	struct tcp_connection* con;
1717 1717
 	int s;
1718 1718
 	long resp;
... ...
@@ -25,14 +25,16 @@
25 25
 
26 26
 #include  "tcp_conn.h"
27 27
 
28
-#define RD_CONN_SHORT_READ		1
29
-#define RD_CONN_EOF				2
30
-#define RD_CONN_REPEAT_READ		4 /* read should be repeated (more data)
31
-								   (used so far only by tls) */
32
-#define RD_CONN_FORCE_EOF		65536
28
+typedef enum rd_conn_flags {
29
+	RD_CONN_SHORT_READ  = (1<<0),
30
+	RD_CONN_EOF         = (1<<1),
31
+	RD_CONN_REPEAT_READ = (1<<2), /* read should be repeated (more data)
32
+	                                 (used so far only by tls) */
33
+	RD_CONN_FORCE_EOF   = (1<<16),
34
+} rd_conn_flags_t;
33 35
 
34 36
 int tcp_read_data(int fd, struct tcp_connection *c,
35
-					char* buf, int b_size, int* flags);
37
+					char* buf, int b_size, rd_conn_flags_t* flags);
36 38
 
37 39
 
38 40
 #endif /*__tcp_read_h*/
... ...
@@ -37,13 +37,14 @@
37 37
 #endif
38 38
 
39 39
 #include "tcp_conn.h"
40
+#include "tcp_read.h"
40 41
 
41 42
 
42 43
 
43 44
 struct tls_hooks{
44 45
 	/* read using tls (should use tcp internal read functions to
45 46
 	   get the data from the connection) */
46
-	int  (*read)(struct tcp_connection* c, int* flags);
47
+	int  (*read)(struct tcp_connection* c, rd_conn_flags_t* flags);
47 48
 	/* process data for sending. Should replace pbuf & plen with
48 49
 	   an internal buffer containing the tls records. If it was not able
49 50
 	   to process the whole pbuf, it should set (rest_buf, rest_len) to
... ...
@@ -991,7 +991,7 @@ ssl_eof:
991 991
  *         tcp connection flags and might set c->state and r->error on
992 992
  *         EOF or error).
993 993
  */
994
-int tls_h_read_f(struct tcp_connection* c, int* flags)
994
+int tls_h_read_f(struct tcp_connection* c, rd_conn_flags_t* flags)
995 995
 {
996 996
 	struct tcp_req* r;
997 997
 	int bytes_free, bytes_read, read_size, ssl_error, ssl_read;
... ...
@@ -30,6 +30,7 @@
30 30
 
31 31
 #include <stdio.h>
32 32
 #include "../../core/tcp_conn.h"
33
+#include "../../core/tcp_read.h"
33 34
 #include "tls_domain.h"
34 35
 #include "tls_ct_wrq.h"
35 36
 
... ...
@@ -87,7 +88,7 @@ int tls_h_encode_f(struct tcp_connection *c, const char ** pbuf,
87 88
 		unsigned int* plen, const char** rest_buf, unsigned int* rest_len,
88 89
 		snd_flags_t* send_flags) ;
89 90
 
90
-int tls_h_read_f(struct tcp_connection *c, int* flags);
91
+int tls_h_read_f(struct tcp_connection *c, rd_conn_flags_t* flags);
91 92
 
92 93
 int tls_h_fix_read_conn(struct tcp_connection *c);
93 94