Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 176 lines (126 sloc) 4.866 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
7519a6d @yaoweibin add the parsers code
authored
12 #include <http_request_parser.h>
13 #include <http_response_parser.h>
14 #include <smtp_response_parser.h>
15
2a82727 @yaoweibin add check type of http
authored
16
17 typedef struct {
18 u_char major;
19 u_char minor;
20 } ssl_protocol_version_t;
21
22 typedef struct {
23 u_char msg_type;
24 ssl_protocol_version_t version;
25 uint16_t length;
26
27 u_char handshake_type;
28 u_char handshake_length[3];
29 ssl_protocol_version_t hello_version;
30
31 time_t time;
32 u_char random[28];
33
34 u_char others[0];
35 } __attribute__((packed)) server_ssl_hello_t;
36
37 typedef struct {
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
38 u_char packet_length[3];
39 u_char packet_number;
40
41 u_char protocol_version;
42 u_char others[0];
43 } __attribute__((packed)) mysql_handshake_init_t;
44
45 typedef struct {
2a82727 @yaoweibin add check type of http
authored
46 ngx_buf_t send;
47 ngx_buf_t recv;
48
49 void *parser;
50 } ngx_tcp_check_ctx;
51
52 /*state*/
53 #define NGX_TCP_CHECK_CONNECT_DONE 0x0001
54 #define NGX_TCP_CHECK_SEND_DONE 0x0002
55 #define NGX_TCP_CHECK_RECV_DONE 0x0004
56 #define NGX_TCP_CHECK_ALL_DONE 0x0008
57
58 typedef struct {
59 ngx_pid_t owner;
60
61 ngx_msec_t access_time;
62
63 ngx_uint_t fall_count;
64 ngx_uint_t rise_count;
65
66 ngx_atomic_t lock;
5bf2315 @yaoweibin add the upstream busyness module. not work well yet
authored
67 ngx_atomic_t busyness;
2a82727 @yaoweibin add check type of http
authored
68 ngx_atomic_t down;
69
fa3324f @yaoweibin add parameter of max_busy for each server
authored
70 ngx_uint_t access_count;
2a82727 @yaoweibin add check type of http
authored
71 } ngx_tcp_check_peer_shm_t;
72
73 typedef struct {
74 ngx_uint_t generation;
75
76 ngx_uint_t state;
77 ngx_atomic_t lock;
78
79 /*store the ngx_tcp_check_status_peer_t*/
888cfcb @yaoweibin fix the wrong offet in http check function
authored
80 ngx_tcp_check_peer_shm_t peers[1];
2a82727 @yaoweibin add check type of http
authored
81 } ngx_tcp_check_peers_shm_t;
82
83 typedef ngx_int_t (*ngx_tcp_check_packet_init_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
84 typedef ngx_int_t (*ngx_tcp_check_packet_parse_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
85 typedef void (*ngx_tcp_check_packet_clean_pt)(ngx_tcp_check_peer_conf_t *peer_conf);
86
dd222ae @yaoweibin add check type of smtp and some test cases
authored
87 #define NGX_TCP_CHECK_TCP 0x0001
88 #define NGX_TCP_CHECK_HTTP 0x0002
89 #define NGX_TCP_CHECK_SSL_HELLO 0x0004
90 #define NGX_TCP_CHECK_SMTP 0x0008
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
91 #define NGX_TCP_CHECK_MYSQL 0x0010
df22ece @yaoweibin add check type of pop3 and imap, tag v0.19
authored
92 #define NGX_TCP_CHECK_POP3 0x0020
93 #define NGX_TCP_CHECK_IMAP 0x0040
dd222ae @yaoweibin add check type of smtp and some test cases
authored
94
95 #define NGX_CHECK_HTTP_2XX 0x0002
96 #define NGX_CHECK_HTTP_3XX 0x0004
97 #define NGX_CHECK_HTTP_4XX 0x0008
98 #define NGX_CHECK_HTTP_5XX 0x0010
99 #define NGX_CHECK_HTTP_6XX 0x0020
100 #define NGX_CHECK_HTTP_ERR 0x8000
101
4f3868e @yaoweibin add mysql check, modify the smtp parser.
authored
102 #define NGX_CHECK_SMTP_2XX 0x0002
103 #define NGX_CHECK_SMTP_3XX 0x0004
104 #define NGX_CHECK_SMTP_4XX 0x0008
105 #define NGX_CHECK_SMTP_5XX 0x0010
106 #define NGX_CHECK_SMTP_6XX 0x0020
107 #define NGX_CHECK_SMTP_ERR 0x8000
108
dd222ae @yaoweibin add check type of smtp and some test cases
authored
109 struct check_conf_s {
110 ngx_uint_t type;
111
112 char *name;
113
114 ngx_str_t default_send;
115
116 /*HTTP*/
117 ngx_uint_t default_status_alive;
118
119 ngx_event_handler_pt send_handler;
120 ngx_event_handler_pt recv_handler;
121
122 ngx_tcp_check_packet_init_pt init;
123 ngx_tcp_check_packet_parse_pt parse;
124 ngx_tcp_check_packet_clean_pt reinit;
125
126 unsigned need_pool;
127 };
128
2a82727 @yaoweibin add check type of http
authored
129 struct ngx_tcp_check_peer_conf_s {
130
131 ngx_flag_t state;
132 ngx_pool_t *pool;
133 ngx_uint_t index;
fa3324f @yaoweibin add parameter of max_busy for each server
authored
134 ngx_uint_t max_busy;
2a82727 @yaoweibin add check type of http
authored
135 ngx_tcp_upstream_srv_conf_t *conf;
136 ngx_peer_addr_t *peer;
137 ngx_event_t check_ev;
138 ngx_event_t check_timeout_ev;
139 ngx_peer_connection_t pc;
140
141 void * check_data;
dd222ae @yaoweibin add check type of smtp and some test cases
authored
142 ngx_event_handler_pt send_handler;
143 ngx_event_handler_pt recv_handler;
144
2a82727 @yaoweibin add check type of http
authored
145 ngx_tcp_check_packet_init_pt init;
146 ngx_tcp_check_packet_parse_pt parse;
147 ngx_tcp_check_packet_clean_pt reinit;
148
149 ngx_tcp_check_peer_shm_t *shm;
150 };
151
152 struct ngx_tcp_check_peers_conf_s {
153 ngx_str_t check_shm_name;
154 ngx_array_t peers;
155
156 ngx_tcp_check_peers_shm_t *peers_shm;
157 };
158
159
160 ngx_int_t ngx_tcp_upstream_init_main_check_conf(ngx_conf_t *cf, void*conf);
161
162 ngx_uint_t ngx_tcp_check_add_peer(ngx_conf_t *cf, ngx_tcp_upstream_srv_conf_t *uscf,
fa3324f @yaoweibin add parameter of max_busy for each server
authored
163 ngx_peer_addr_t *peer, ngx_uint_t max_busy);
2a82727 @yaoweibin add check type of http
authored
164
165 ngx_uint_t ngx_tcp_check_peer_down(ngx_uint_t index);
166
5bf2315 @yaoweibin add the upstream busyness module. not work well yet
authored
167 ngx_uint_t ngx_tcp_check_get_peer_busyness(ngx_uint_t index);
168
fa3324f @yaoweibin add parameter of max_busy for each server
authored
169 void ngx_tcp_check_get_peer(ngx_uint_t index);
170 void ngx_tcp_check_free_peer(ngx_uint_t index);
171
dd222ae @yaoweibin add check type of smtp and some test cases
authored
172 check_conf_t *ngx_tcp_get_check_type_conf(ngx_str_t *str);
2a82727 @yaoweibin add check type of http
authored
173
174 #endif //_NGX_TCP_UPSTREAM_CHECK_H_INCLUDED_
175
Something went wrong with that request. Please try again.