Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Redefine flags as enum #2511

Merged
merged 4 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/core/ip_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ union sockaddr_union{
};


enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4,
SI_IS_ANY=8, SI_IS_MHOMED=16 };
enum si_flags {
SI_NONE = 0,
SI_IS_IP = (1<<0),
SI_IS_LO = (1<<1),
SI_IS_MCAST = (1<<2),
SI_IS_ANY = (1<<3),
SI_IS_MHOMED = (1<<4),
};

typedef struct addr_info {
str name; /* name - eg.: foo.bar or 10.0.0.1 */
Expand Down Expand Up @@ -128,9 +134,11 @@ typedef struct socket_info {


/* send flags */
#define SND_F_FORCE_CON_REUSE 1 /* reuse an existing connection or fail */
#define SND_F_CON_CLOSE 2 /* close the connection after sending */
#define SND_F_FORCE_SOCKET 4 /* send socket in dst is forced */
enum send_flags {
SND_F_FORCE_CON_REUSE = (1 << 0), /* reuse an existing connection or fail */
SND_F_CON_CLOSE = (1 << 1), /* close the connection after sending */
SND_F_FORCE_SOCKET = (1 << 2), /* send socket in dst is forced */
};

typedef struct snd_flags {
unsigned short f; /* snd flags */
Expand Down
43 changes: 22 additions & 21 deletions src/core/tcp_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ enum conn_cmds {
/* CONN_RELEASE, EOF, ERROR, DESTROY can be used by "reader" processes
* CONN_GET_FD, CONN_NEW*, CONN_QUEUED_WRITE only by writers */

/* tcp_req flags */
enum tcp_req_flags {
F_TCP_REQ_HAS_CLEN = (1<<0),
F_TCP_REQ_COMPLETE = (1<<1),
#ifdef READ_HTTP11
F_TCP_REQ_BCHUNKED = (1<<2),
#endif
#ifdef READ_MSRP
F_TCP_REQ_MSRP_NO = (1<<3),
F_TCP_REQ_MSRP_FRAME = (1<<4),
F_TCP_REQ_MSRP_BODY = (1<<5),
#endif
F_TCP_REQ_HEP3 = (1<<6),
};

#define TCP_REQ_HAS_CLEN(tr) ((tr)->flags & F_TCP_REQ_HAS_CLEN)
#define TCP_REQ_COMPLETE(tr) ((tr)->flags & F_TCP_REQ_COMPLETE)
#ifdef READ_HTTP11
#define TCP_REQ_BCHUNKED(tr) ((tr)->flags & F_TCP_REQ_BCHUNKED)
#endif

struct tcp_req{
struct tcp_req* next;
/* sockaddr ? */
Expand All @@ -135,32 +156,12 @@ struct tcp_req{
#ifdef READ_HTTP11
int chunk_size;
#endif
unsigned int flags; /* F_TCP_REQ_HAS_CLEN | F_TCP_REQ_COMPLETE */
enum tcp_req_flags flags; /* F_TCP_REQ_HAS_CLEN | F_TCP_REQ_COMPLETE */
int bytes_to_go; /* how many bytes we have still to read from the body*/
enum tcp_req_errors error;
enum tcp_req_states state;
};

/* tcp_req flags */
#define F_TCP_REQ_HAS_CLEN 1
#define F_TCP_REQ_COMPLETE 2
#ifdef READ_HTTP11
#define F_TCP_REQ_BCHUNKED 4
#endif
#ifdef READ_MSRP
#define F_TCP_REQ_MSRP_NO 8
#define F_TCP_REQ_MSRP_FRAME 16
#define F_TCP_REQ_MSRP_BODY 32
#endif
#define F_TCP_REQ_HEP3 64

#define TCP_REQ_HAS_CLEN(tr) ((tr)->flags & F_TCP_REQ_HAS_CLEN)
#define TCP_REQ_COMPLETE(tr) ((tr)->flags & F_TCP_REQ_COMPLETE)
#ifdef READ_HTTP11
#define TCP_REQ_BCHUNKED(tr) ((tr)->flags & F_TCP_REQ_BCHUNKED)
#endif


struct tcp_connection;

/* tcp port alias structure */
Expand Down
14 changes: 7 additions & 7 deletions src/core/tcp_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static int tcp_emit_closed_event(struct tcp_connection *con, enum tcp_closed_rea
* EOF checking should be done by checking the RD_CONN_EOF flag.
*/
int tcp_read_data(int fd, struct tcp_connection *c,
char* buf, int b_size, int* flags)
char* buf, int b_size, rd_conn_flags_t* flags)
{
int bytes_read;

Expand Down Expand Up @@ -329,7 +329,7 @@ int tcp_read_data(int fd, struct tcp_connection *c,
* (to distinguish from reads that would block which could return 0)
* RD_CONN_SHORT_READ is also set in *flags for short reads.
* sets also r->error */
int tcp_read(struct tcp_connection *c, int* flags)
int tcp_read(struct tcp_connection *c, rd_conn_flags_t* flags)
{
int bytes_free, bytes_read;
struct tcp_req *r;
Expand Down Expand Up @@ -369,7 +369,7 @@ int tcp_read(struct tcp_connection *c, int* flags)
* when either r->body!=0 or r->state==H_BODY =>
* all headers have been read. It should be called in a while loop.
* returns < 0 if error or 0 if EOF */
int tcp_read_headers(struct tcp_connection *c, int* read_flags)
int tcp_read_headers(struct tcp_connection *c, rd_conn_flags_t* read_flags)
{
int bytes, remaining;
char *p;
Expand Down Expand Up @@ -1082,7 +1082,7 @@ int msrp_process_msg(char* tcpbuf, unsigned int len,
#endif

#ifdef READ_WS
static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
static int tcp_read_ws(struct tcp_connection *c, rd_conn_flags_t* read_flags)
{
int bytes;
uint32_t size, pos, mask_present, len;
Expand Down Expand Up @@ -1237,7 +1237,7 @@ static int ws_process_msg(char* tcpbuf, unsigned int len,
}
#endif

static int tcp_read_hep3(struct tcp_connection *c, int* read_flags)
static int tcp_read_hep3(struct tcp_connection *c, rd_conn_flags_t* read_flags)
{
int bytes;
uint32_t size, len;
Expand Down Expand Up @@ -1429,7 +1429,7 @@ int receive_tcp_msg(char* tcpbuf, unsigned int len,
#endif /* TCP_CLONE_RCVBUF */
}

int tcp_read_req(struct tcp_connection* con, int* bytes_read, int* read_flags)
int tcp_read_req(struct tcp_connection* con, int* bytes_read, rd_conn_flags_t* read_flags)
{
int bytes;
int total_bytes;
Expand Down Expand Up @@ -1712,7 +1712,7 @@ inline static int handle_io(struct fd_map* fm, short events, int idx)
{
int ret;
int n;
int read_flags;
rd_conn_flags_t read_flags;
struct tcp_connection* con;
int s;
long resp;
Expand Down
14 changes: 8 additions & 6 deletions src/core/tcp_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@

#include "tcp_conn.h"

#define RD_CONN_SHORT_READ 1
#define RD_CONN_EOF 2
#define RD_CONN_REPEAT_READ 4 /* read should be repeated (more data)
(used so far only by tls) */
#define RD_CONN_FORCE_EOF 65536
typedef enum rd_conn_flags {
RD_CONN_SHORT_READ = (1<<0),
RD_CONN_EOF = (1<<1),
RD_CONN_REPEAT_READ = (1<<2), /* read should be repeated (more data)
(used so far only by tls) */
RD_CONN_FORCE_EOF = (1<<16),
} rd_conn_flags_t;

int tcp_read_data(int fd, struct tcp_connection *c,
char* buf, int b_size, int* flags);
char* buf, int b_size, rd_conn_flags_t* flags);


#endif /*__tcp_read_h*/
Expand Down
3 changes: 2 additions & 1 deletion src/core/tls_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
#endif

#include "tcp_conn.h"
#include "tcp_read.h"



struct tls_hooks{
/* read using tls (should use tcp internal read functions to
get the data from the connection) */
int (*read)(struct tcp_connection* c, int* flags);
int (*read)(struct tcp_connection* c, rd_conn_flags_t* flags);
/* process data for sending. Should replace pbuf & plen with
an internal buffer containing the tls records. If it was not able
to process the whole pbuf, it should set (rest_buf, rest_len) to
Expand Down
2 changes: 1 addition & 1 deletion src/modules/tls/tls_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ int tls_h_encode_f(struct tcp_connection *c,
* tcp connection flags and might set c->state and r->error on
* EOF or error).
*/
int tls_h_read_f(struct tcp_connection* c, int* flags)
int tls_h_read_f(struct tcp_connection* c, rd_conn_flags_t* flags)
{
struct tcp_req* r;
int bytes_free, bytes_read, read_size, ssl_error, ssl_read;
Expand Down
3 changes: 2 additions & 1 deletion src/modules/tls/tls_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <stdio.h>
#include "../../core/tcp_conn.h"
#include "../../core/tcp_read.h"
#include "tls_domain.h"
#include "tls_ct_wrq.h"

Expand Down Expand Up @@ -87,7 +88,7 @@ int tls_h_encode_f(struct tcp_connection *c, const char ** pbuf,
unsigned int* plen, const char** rest_buf, unsigned int* rest_len,
snd_flags_t* send_flags) ;

int tls_h_read_f(struct tcp_connection *c, int* flags);
int tls_h_read_f(struct tcp_connection *c, rd_conn_flags_t* flags);

int tls_h_fix_read_conn(struct tcp_connection *c);

Expand Down