Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 184 lines (129 sloc) 4.739 kB
2a82727 @yaoweibin add check type of http
authored
1 #ifndef _NGX_TCP_UPSTREAM_CHECK_H_INCLUDED_
2 #define _NGX_TCP_UPSTREAM_CHECK_H_INCLUDED_
3
4
5 #include <ngx_config.h>
6 #include <ngx_core.h>
7 #include <ngx_event.h>
8 #include <ngx_event_connect.h>
9 #include <ngx_event_pipe.h>
10 #include <ngx_tcp.h>
11
12
13 typedef struct {
14 u_char major;
15 u_char minor;
16 } ssl_protocol_version_t;
17
18 typedef struct {
19 u_char msg_type;
20 ssl_protocol_version_t version;
21 uint16_t length;
22
23 u_char handshake_type;
24 u_char handshake_length[3];
25 ssl_protocol_version_t hello_version;
26
27 time_t time;
28 u_char random[28];
29
30 u_char others[0];
31 } __attribute__((packed)) server_ssl_hello_t;
32
33 typedef struct {
34 ngx_buf_t send;
35 ngx_buf_t recv;
36
37 void *parser;
38 } ngx_tcp_check_ctx;
39
40 /*state*/
41 #define NGX_TCP_CHECK_CONNECT_DONE 0x0001
42 #define NGX_TCP_CHECK_SEND_DONE 0x0002
43 #define NGX_TCP_CHECK_RECV_DONE 0x0004
44 #define NGX_TCP_CHECK_ALL_DONE 0x0008
45
46 typedef struct {
47 ngx_pid_t owner;
48
49 ngx_msec_t access_time;
50
51 ngx_uint_t fall_count;
52 ngx_uint_t rise_count;
53
54 ngx_atomic_t lock;
55 ngx_atomic_t busy;
56 ngx_atomic_t down;
57
58 unsigned last_down:1;
59 } ngx_tcp_check_peer_shm_t;
60
61 typedef struct {
62 ngx_uint_t generation;
63
64 ngx_uint_t state;
65 ngx_atomic_t lock;
66
67 /*store the ngx_tcp_check_status_peer_t*/
68 ngx_tcp_check_peer_shm_t peers[0];
69 } ngx_tcp_check_peers_shm_t;
70
71 typedef ngx_int_t (*ngx_tcp_check_packet_init_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
72 typedef ngx_int_t (*ngx_tcp_check_packet_parse_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
73 typedef void (*ngx_tcp_check_packet_clean_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
74
dd222ae @yaoweibin add check type of smtp and some test cases
authored
75 #define NGX_TCP_CHECK_TCP 0x0001
76 #define NGX_TCP_CHECK_HTTP 0x0002
77 #define NGX_TCP_CHECK_SSL_HELLO 0x0004
78 #define NGX_TCP_CHECK_SMTP 0x0008
79
80
81 #define NGX_CHECK_HTTP_2XX 0x0002
82 #define NGX_CHECK_HTTP_3XX 0x0004
83 #define NGX_CHECK_HTTP_4XX 0x0008
84 #define NGX_CHECK_HTTP_5XX 0x0010
85 #define NGX_CHECK_HTTP_6XX 0x0020
86 #define NGX_CHECK_HTTP_ERR 0x8000
87
88 struct check_conf_s {
89 ngx_uint_t type;
90
91 char *name;
92
93 ngx_str_t default_send;
94
95 /*HTTP*/
96 ngx_uint_t default_status_alive;
97
98 ngx_event_handler_pt send_handler;
99 ngx_event_handler_pt recv_handler;
100
101 ngx_tcp_check_packet_init_pt init;
102 ngx_tcp_check_packet_parse_pt parse;
103 ngx_tcp_check_packet_clean_pt reinit;
104
105 unsigned need_pool;
106 };
107
2a82727 @yaoweibin add check type of http
authored
108 struct ngx_tcp_check_peer_conf_s {
109
110 ngx_flag_t state;
111 ngx_pool_t *pool;
112 ngx_uint_t index;
113 ngx_tcp_upstream_srv_conf_t *conf;
114 ngx_peer_addr_t *peer;
115 ngx_event_t check_ev;
116 ngx_event_t check_timeout_ev;
117 ngx_peer_connection_t pc;
118
119 void * check_data;
dd222ae @yaoweibin add check type of smtp and some test cases
authored
120 ngx_event_handler_pt send_handler;
121 ngx_event_handler_pt recv_handler;
122
2a82727 @yaoweibin add check type of http
authored
123 ngx_tcp_check_packet_init_pt init;
124 ngx_tcp_check_packet_parse_pt parse;
125 ngx_tcp_check_packet_clean_pt reinit;
126
127 ngx_tcp_check_peer_shm_t *shm;
128 };
129
130 struct ngx_tcp_check_peers_conf_s {
131 ngx_str_t check_shm_name;
132 ngx_array_t peers;
133
134 ngx_tcp_check_peers_shm_t *peers_shm;
135 };
136
137
dd222ae @yaoweibin add check type of smtp and some test cases
authored
138 /*HTTP parser*/
2a82727 @yaoweibin add check type of http
authored
139 typedef void (*element_cb)(void *data, const char *at, size_t length);
140 typedef void (*field_cb)(void *data, const char *field, size_t flen, const char *value, size_t vlen);
141
142
143 typedef struct http_parser {
144 int cs;
145 size_t body_start;
146 int content_len;
147 int status_code_n;
148 size_t nread;
149 size_t mark;
150 size_t field_start;
151 size_t field_len;
152
153 void *data;
154
155 field_cb http_field;
156
157 element_cb http_version;
158 element_cb status_code;
159 element_cb reason_phrase;
160 element_cb header_done;
161
162 } http_parser;
163
164 int http_parser_init(http_parser *parser);
165 int http_parser_finish(http_parser *parser);
166 size_t http_parser_execute(http_parser *parser, const char *data, size_t len, size_t off);
167 int http_parser_has_error(http_parser *parser);
168 int http_parser_is_finished(http_parser *parser);
169
170 #define http_parser_nread(parser) (parser)->nread
171
172
173 ngx_int_t ngx_tcp_upstream_init_main_check_conf(ngx_conf_t *cf, void*conf);
174
175 ngx_uint_t ngx_tcp_check_add_peer(ngx_conf_t *cf, ngx_tcp_upstream_srv_conf_t *uscf,
176 ngx_peer_addr_t *peer);
177
178 ngx_uint_t ngx_tcp_check_peer_down(ngx_uint_t index);
179
dd222ae @yaoweibin add check type of smtp and some test cases
authored
180 check_conf_t *ngx_tcp_get_check_type_conf(ngx_str_t *str);
2a82727 @yaoweibin add check type of http
authored
181
182 #endif //_NGX_TCP_UPSTREAM_CHECK_H_INCLUDED_
183
Something went wrong with that request. Please try again.