Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 229 lines (162 sloc) 5.98 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 {
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
34
35 u_char packet_length[3];
36 u_char packet_number;
37
38 u_char protocol_version;
39 u_char others[0];
40 } __attribute__((packed)) mysql_handshake_init_t;
41
42 typedef struct {
2a82727 @yaoweibin add check type of http
authored
43 ngx_buf_t send;
44 ngx_buf_t recv;
45
46 void *parser;
47 } ngx_tcp_check_ctx;
48
49 /*state*/
50 #define NGX_TCP_CHECK_CONNECT_DONE 0x0001
51 #define NGX_TCP_CHECK_SEND_DONE 0x0002
52 #define NGX_TCP_CHECK_RECV_DONE 0x0004
53 #define NGX_TCP_CHECK_ALL_DONE 0x0008
54
55 typedef struct {
56 ngx_pid_t owner;
57
58 ngx_msec_t access_time;
59
60 ngx_uint_t fall_count;
61 ngx_uint_t rise_count;
62
63 ngx_atomic_t lock;
64 ngx_atomic_t busy;
65 ngx_atomic_t down;
66
67 unsigned last_down:1;
68 } ngx_tcp_check_peer_shm_t;
69
70 typedef struct {
71 ngx_uint_t generation;
72
73 ngx_uint_t state;
74 ngx_atomic_t lock;
75
76 /*store the ngx_tcp_check_status_peer_t*/
77 ngx_tcp_check_peer_shm_t peers[0];
78 } ngx_tcp_check_peers_shm_t;
79
80 typedef ngx_int_t (*ngx_tcp_check_packet_init_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
81 typedef ngx_int_t (*ngx_tcp_check_packet_parse_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
82 typedef void (*ngx_tcp_check_packet_clean_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
83
dd222ae @yaoweibin add check type of smtp and some test cases
authored
84 #define NGX_TCP_CHECK_TCP 0x0001
85 #define NGX_TCP_CHECK_HTTP 0x0002
86 #define NGX_TCP_CHECK_SSL_HELLO 0x0004
87 #define NGX_TCP_CHECK_SMTP 0x0008
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
88 #define NGX_TCP_CHECK_MYSQL 0x0010
df22ece @yaoweibin add check type of pop3 and imap, tag v0.19
authored
89 #define NGX_TCP_CHECK_POP3 0x0020
90 #define NGX_TCP_CHECK_IMAP 0x0040
dd222ae @yaoweibin add check type of smtp and some test cases
authored
91
92
93 #define NGX_CHECK_HTTP_2XX 0x0002
94 #define NGX_CHECK_HTTP_3XX 0x0004
95 #define NGX_CHECK_HTTP_4XX 0x0008
96 #define NGX_CHECK_HTTP_5XX 0x0010
97 #define NGX_CHECK_HTTP_6XX 0x0020
98 #define NGX_CHECK_HTTP_ERR 0x8000
99
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
100 #define NGX_CHECK_SMTP_2XX 0x0002
101 #define NGX_CHECK_SMTP_3XX 0x0004
102 #define NGX_CHECK_SMTP_4XX 0x0008
103 #define NGX_CHECK_SMTP_5XX 0x0010
104 #define NGX_CHECK_SMTP_6XX 0x0020
105 #define NGX_CHECK_SMTP_ERR 0x8000
106
dd222ae @yaoweibin add check type of smtp and some test cases
authored
107 struct check_conf_s {
108 ngx_uint_t type;
109
110 char *name;
111
112 ngx_str_t default_send;
113
114 /*HTTP*/
115 ngx_uint_t default_status_alive;
116
117 ngx_event_handler_pt send_handler;
118 ngx_event_handler_pt recv_handler;
119
120 ngx_tcp_check_packet_init_pt init;
121 ngx_tcp_check_packet_parse_pt parse;
122 ngx_tcp_check_packet_clean_pt reinit;
123
124 unsigned need_pool;
125 };
126
2a82727 @yaoweibin add check type of http
authored
127 struct ngx_tcp_check_peer_conf_s {
128
129 ngx_flag_t state;
130 ngx_pool_t *pool;
131 ngx_uint_t index;
132 ngx_tcp_upstream_srv_conf_t *conf;
133 ngx_peer_addr_t *peer;
134 ngx_event_t check_ev;
135 ngx_event_t check_timeout_ev;
136 ngx_peer_connection_t pc;
137
138 void * check_data;
dd222ae @yaoweibin add check type of smtp and some test cases
authored
139 ngx_event_handler_pt send_handler;
140 ngx_event_handler_pt recv_handler;
141
2a82727 @yaoweibin add check type of http
authored
142 ngx_tcp_check_packet_init_pt init;
143 ngx_tcp_check_packet_parse_pt parse;
144 ngx_tcp_check_packet_clean_pt reinit;
145
146 ngx_tcp_check_peer_shm_t *shm;
147 };
148
149 struct ngx_tcp_check_peers_conf_s {
150 ngx_str_t check_shm_name;
151 ngx_array_t peers;
152
153 ngx_tcp_check_peers_shm_t *peers_shm;
154 };
155
156
dd222ae @yaoweibin add check type of smtp and some test cases
authored
157 /*HTTP parser*/
2a82727 @yaoweibin add check type of http
authored
158 typedef void (*element_cb)(void *data, const char *at, size_t length);
159 typedef void (*field_cb)(void *data, const char *field, size_t flen, const char *value, size_t vlen);
160
161
162 typedef struct http_parser {
163 int cs;
164 size_t body_start;
165 int content_len;
166 int status_code_n;
167 size_t nread;
168 size_t mark;
169 size_t field_start;
170 size_t field_len;
171
172 void *data;
173
174 field_cb http_field;
175
176 element_cb http_version;
177 element_cb status_code;
178 element_cb reason_phrase;
179 element_cb header_done;
180
181 } http_parser;
182
183 int http_parser_init(http_parser *parser);
184 int http_parser_finish(http_parser *parser);
185 size_t http_parser_execute(http_parser *parser, const char *data, size_t len, size_t off);
186 int http_parser_has_error(http_parser *parser);
187 int http_parser_is_finished(http_parser *parser);
188
189 #define http_parser_nread(parser) (parser)->nread
190
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
191 typedef struct smtp_parser {
192
193 int cs;
194 size_t nread;
195 size_t mark;
196
197 int hello_reply_code;
198
199 void *data;
200
201 element_cb domain;
202 element_cb greeting_text;
203 element_cb reply_code;
204 element_cb reply_text;
205 element_cb smtp_done;
206
207 } smtp_parser;
208
209 int smtp_parser_init(smtp_parser *parser);
210 int smtp_parser_finish(smtp_parser *parser);
211 size_t smtp_parser_execute(smtp_parser *parser, const char *data, size_t len, size_t off);
212 int smtp_parser_has_error(smtp_parser *parser);
213 int smtp_parser_is_finished(smtp_parser *parser);
214
215 #define http_parser_nread(parser) (parser)->nread
216
2a82727 @yaoweibin add check type of http
authored
217
218 ngx_int_t ngx_tcp_upstream_init_main_check_conf(ngx_conf_t *cf, void*conf);
219
220 ngx_uint_t ngx_tcp_check_add_peer(ngx_conf_t *cf, ngx_tcp_upstream_srv_conf_t *uscf,
221 ngx_peer_addr_t *peer);
222
223 ngx_uint_t ngx_tcp_check_peer_down(ngx_uint_t index);
224
dd222ae @yaoweibin add check type of smtp and some test cases
authored
225 check_conf_t *ngx_tcp_get_check_type_conf(ngx_str_t *str);
2a82727 @yaoweibin add check type of http
authored
226
227 #endif //_NGX_TCP_UPSTREAM_CHECK_H_INCLUDED_
228
Something went wrong with that request. Please try again.