Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 227 lines (160 sloc) 5.888 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
dd222ae @yaoweibin add check type of smtp and some test cases
authored
89
90
91 #define NGX_CHECK_HTTP_2XX 0x0002
92 #define NGX_CHECK_HTTP_3XX 0x0004
93 #define NGX_CHECK_HTTP_4XX 0x0008
94 #define NGX_CHECK_HTTP_5XX 0x0010
95 #define NGX_CHECK_HTTP_6XX 0x0020
96 #define NGX_CHECK_HTTP_ERR 0x8000
97
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
98 #define NGX_CHECK_SMTP_2XX 0x0002
99 #define NGX_CHECK_SMTP_3XX 0x0004
100 #define NGX_CHECK_SMTP_4XX 0x0008
101 #define NGX_CHECK_SMTP_5XX 0x0010
102 #define NGX_CHECK_SMTP_6XX 0x0020
103 #define NGX_CHECK_SMTP_ERR 0x8000
104
dd222ae @yaoweibin add check type of smtp and some test cases
authored
105 struct check_conf_s {
106 ngx_uint_t type;
107
108 char *name;
109
110 ngx_str_t default_send;
111
112 /*HTTP*/
113 ngx_uint_t default_status_alive;
114
115 ngx_event_handler_pt send_handler;
116 ngx_event_handler_pt recv_handler;
117
118 ngx_tcp_check_packet_init_pt init;
119 ngx_tcp_check_packet_parse_pt parse;
120 ngx_tcp_check_packet_clean_pt reinit;
121
122 unsigned need_pool;
123 };
124
2a82727 @yaoweibin add check type of http
authored
125 struct ngx_tcp_check_peer_conf_s {
126
127 ngx_flag_t state;
128 ngx_pool_t *pool;
129 ngx_uint_t index;
130 ngx_tcp_upstream_srv_conf_t *conf;
131 ngx_peer_addr_t *peer;
132 ngx_event_t check_ev;
133 ngx_event_t check_timeout_ev;
134 ngx_peer_connection_t pc;
135
136 void * check_data;
dd222ae @yaoweibin add check type of smtp and some test cases
authored
137 ngx_event_handler_pt send_handler;
138 ngx_event_handler_pt recv_handler;
139
2a82727 @yaoweibin add check type of http
authored
140 ngx_tcp_check_packet_init_pt init;
141 ngx_tcp_check_packet_parse_pt parse;
142 ngx_tcp_check_packet_clean_pt reinit;
143
144 ngx_tcp_check_peer_shm_t *shm;
145 };
146
147 struct ngx_tcp_check_peers_conf_s {
148 ngx_str_t check_shm_name;
149 ngx_array_t peers;
150
151 ngx_tcp_check_peers_shm_t *peers_shm;
152 };
153
154
dd222ae @yaoweibin add check type of smtp and some test cases
authored
155 /*HTTP parser*/
2a82727 @yaoweibin add check type of http
authored
156 typedef void (*element_cb)(void *data, const char *at, size_t length);
157 typedef void (*field_cb)(void *data, const char *field, size_t flen, const char *value, size_t vlen);
158
159
160 typedef struct http_parser {
161 int cs;
162 size_t body_start;
163 int content_len;
164 int status_code_n;
165 size_t nread;
166 size_t mark;
167 size_t field_start;
168 size_t field_len;
169
170 void *data;
171
172 field_cb http_field;
173
174 element_cb http_version;
175 element_cb status_code;
176 element_cb reason_phrase;
177 element_cb header_done;
178
179 } http_parser;
180
181 int http_parser_init(http_parser *parser);
182 int http_parser_finish(http_parser *parser);
183 size_t http_parser_execute(http_parser *parser, const char *data, size_t len, size_t off);
184 int http_parser_has_error(http_parser *parser);
185 int http_parser_is_finished(http_parser *parser);
186
187 #define http_parser_nread(parser) (parser)->nread
188
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
189 typedef struct smtp_parser {
190
191 int cs;
192 size_t nread;
193 size_t mark;
194
195 int hello_reply_code;
196
197 void *data;
198
199 element_cb domain;
200 element_cb greeting_text;
201 element_cb reply_code;
202 element_cb reply_text;
203 element_cb smtp_done;
204
205 } smtp_parser;
206
207 int smtp_parser_init(smtp_parser *parser);
208 int smtp_parser_finish(smtp_parser *parser);
209 size_t smtp_parser_execute(smtp_parser *parser, const char *data, size_t len, size_t off);
210 int smtp_parser_has_error(smtp_parser *parser);
211 int smtp_parser_is_finished(smtp_parser *parser);
212
213 #define http_parser_nread(parser) (parser)->nread
214
2a82727 @yaoweibin add check type of http
authored
215
216 ngx_int_t ngx_tcp_upstream_init_main_check_conf(ngx_conf_t *cf, void*conf);
217
218 ngx_uint_t ngx_tcp_check_add_peer(ngx_conf_t *cf, ngx_tcp_upstream_srv_conf_t *uscf,
219 ngx_peer_addr_t *peer);
220
221 ngx_uint_t ngx_tcp_check_peer_down(ngx_uint_t index);
222
dd222ae @yaoweibin add check type of smtp and some test cases
authored
223 check_conf_t *ngx_tcp_get_check_type_conf(ngx_str_t *str);
2a82727 @yaoweibin add check type of http
authored
224
225 #endif //_NGX_TCP_UPSTREAM_CHECK_H_INCLUDED_
226
Something went wrong with that request. Please try again.