forked from yaoweibin/nginx_upstream_check_module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngx_http_upstream_check_handler.h
138 lines (100 loc) · 3.6 KB
/
ngx_http_upstream_check_handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef _NGX_HTTP_UPSTREAM_CHECK_HANDLER_H_INCLUDED_
#define _NGX_HTTP_UPSTREAM_CHECK_HANDLER_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
#include <ngx_event_connect.h>
#include <ngx_event_pipe.h>
#include <ngx_http.h>
#include "ngx_http_upstream_check_module.h"
typedef struct {
u_char major;
u_char minor;
} ssl_protocol_version_t;
typedef struct {
u_char msg_type;
ssl_protocol_version_t version;
uint16_t length;
u_char handshake_type;
u_char handshake_length[3];
ssl_protocol_version_t hello_version;
time_t time;
u_char random[28];
u_char others[0];
} __attribute__((packed)) server_ssl_hello_t;
typedef struct {
u_char packet_length[3];
u_char packet_number;
u_char protocol_version;
u_char others[0];
} __attribute__((packed)) mysql_handshake_init_t;
typedef struct {
uint16_t preamble;
uint16_t length;
u_char type;
} __attribute__((packed)) ajp_raw_packet_t;
typedef struct {
ngx_buf_t send;
ngx_buf_t recv;
ngx_uint_t state;
ngx_http_status_t status;
} ngx_http_check_ctx;
/* state */
#define NGX_HTTP_CHECK_CONNECT_DONE 0x0001
#define NGX_HTTP_CHECK_SEND_DONE 0x0002
#define NGX_HTTP_CHECK_RECV_DONE 0x0004
#define NGX_HTTP_CHECK_ALL_DONE 0x0008
typedef struct {
ngx_pid_t owner;
ngx_msec_t access_time;
ngx_uint_t fall_count;
ngx_uint_t rise_count;
ngx_atomic_t lock;
ngx_atomic_t busyness;
ngx_atomic_t down;
ngx_uint_t access_count;
struct sockaddr *sockaddr;
socklen_t socklen;
} ngx_http_check_peer_shm_t;
typedef struct {
ngx_uint_t generation;
ngx_uint_t checksum;
ngx_uint_t state;
ngx_atomic_t lock;
ngx_uint_t number;
/* store ngx_http_check_status_peer_t */
ngx_http_check_peer_shm_t peers[1];
} ngx_http_check_peers_shm_t;
struct ngx_http_check_peer_s {
ngx_flag_t state;
ngx_pool_t *pool;
ngx_uint_t index;
ngx_uint_t max_busy;
ngx_str_t *upstream_name;
ngx_peer_addr_t *peer_addr;
ngx_event_t check_ev;
ngx_event_t check_timeout_ev;
ngx_peer_connection_t pc;
void * check_data;
ngx_event_handler_pt send_handler;
ngx_event_handler_pt recv_handler;
ngx_http_check_packet_init_pt init;
ngx_http_check_packet_parse_pt parse;
ngx_http_check_packet_clean_pt reinit;
ngx_http_check_peer_shm_t *shm;
ngx_http_upstream_check_srv_conf_t *conf;
};
struct ngx_http_check_peers_s {
ngx_str_t check_shm_name;
ngx_uint_t checksum;
ngx_array_t peers;
ngx_http_check_peers_shm_t *peers_shm;
};
ngx_int_t ngx_http_upstream_check_status_handler(ngx_http_request_t *r);
ngx_uint_t ngx_http_check_peer_down(ngx_uint_t index);
void ngx_http_check_get_peer(ngx_uint_t index);
void ngx_http_check_free_peer(ngx_uint_t index);
char * ngx_http_upstream_check_init_shm(ngx_conf_t *cf, void *conf);
ngx_int_t ngx_http_check_add_timers(ngx_cycle_t *cycle);
extern check_conf_t ngx_check_types[];
#endif //_NGX_HTTP_UPSTREAM_CHECK_HANDLER_H_INCLUDED_