Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Roman Arutyunyan
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_STREAM_H_INCLUDED_
0009 #define _NGX_STREAM_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 #if (NGX_STREAM_SSL)
0016 #include <ngx_stream_ssl_module.h>
0017 #endif
0018 
0019 
0020 typedef struct ngx_stream_session_s  ngx_stream_session_t;
0021 
0022 
0023 #include <ngx_stream_variables.h>
0024 #include <ngx_stream_script.h>
0025 #include <ngx_stream_upstream.h>
0026 #include <ngx_stream_upstream_round_robin.h>
0027 
0028 
0029 #define NGX_STREAM_OK                        200
0030 #define NGX_STREAM_BAD_REQUEST               400
0031 #define NGX_STREAM_FORBIDDEN                 403
0032 #define NGX_STREAM_INTERNAL_SERVER_ERROR     500
0033 #define NGX_STREAM_BAD_GATEWAY               502
0034 #define NGX_STREAM_SERVICE_UNAVAILABLE       503
0035 
0036 
0037 typedef struct {
0038     void                         **main_conf;
0039     void                         **srv_conf;
0040 } ngx_stream_conf_ctx_t;
0041 
0042 
0043 typedef struct {
0044     ngx_sockaddr_t                 sockaddr;
0045     socklen_t                      socklen;
0046 
0047     /* server ctx */
0048     ngx_stream_conf_ctx_t         *ctx;
0049 
0050     unsigned                       bind:1;
0051     unsigned                       wildcard:1;
0052     unsigned                       ssl:1;
0053 #if (NGX_HAVE_INET6)
0054     unsigned                       ipv6only:1;
0055 #endif
0056     unsigned                       reuseport:1;
0057     unsigned                       so_keepalive:2;
0058     unsigned                       proxy_protocol:1;
0059 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
0060     int                            tcp_keepidle;
0061     int                            tcp_keepintvl;
0062     int                            tcp_keepcnt;
0063 #endif
0064     int                            backlog;
0065     int                            type;
0066 } ngx_stream_listen_t;
0067 
0068 
0069 typedef struct {
0070     ngx_stream_conf_ctx_t         *ctx;
0071     ngx_str_t                      addr_text;
0072     unsigned                       ssl:1;
0073     unsigned                       proxy_protocol:1;
0074 } ngx_stream_addr_conf_t;
0075 
0076 typedef struct {
0077     in_addr_t                      addr;
0078     ngx_stream_addr_conf_t         conf;
0079 } ngx_stream_in_addr_t;
0080 
0081 
0082 #if (NGX_HAVE_INET6)
0083 
0084 typedef struct {
0085     struct in6_addr                addr6;
0086     ngx_stream_addr_conf_t         conf;
0087 } ngx_stream_in6_addr_t;
0088 
0089 #endif
0090 
0091 
0092 typedef struct {
0093     /* ngx_stream_in_addr_t or ngx_stream_in6_addr_t */
0094     void                          *addrs;
0095     ngx_uint_t                     naddrs;
0096 } ngx_stream_port_t;
0097 
0098 
0099 typedef struct {
0100     int                            family;
0101     int                            type;
0102     in_port_t                      port;
0103     ngx_array_t                    addrs; /* array of ngx_stream_conf_addr_t */
0104 } ngx_stream_conf_port_t;
0105 
0106 
0107 typedef struct {
0108     ngx_stream_listen_t            opt;
0109 } ngx_stream_conf_addr_t;
0110 
0111 
0112 typedef enum {
0113     NGX_STREAM_POST_ACCEPT_PHASE = 0,
0114     NGX_STREAM_PREACCESS_PHASE,
0115     NGX_STREAM_ACCESS_PHASE,
0116     NGX_STREAM_SSL_PHASE,
0117     NGX_STREAM_PREREAD_PHASE,
0118     NGX_STREAM_CONTENT_PHASE,
0119     NGX_STREAM_LOG_PHASE
0120 } ngx_stream_phases;
0121 
0122 
0123 typedef struct ngx_stream_phase_handler_s  ngx_stream_phase_handler_t;
0124 
0125 typedef ngx_int_t (*ngx_stream_phase_handler_pt)(ngx_stream_session_t *s,
0126     ngx_stream_phase_handler_t *ph);
0127 typedef ngx_int_t (*ngx_stream_handler_pt)(ngx_stream_session_t *s);
0128 typedef void (*ngx_stream_content_handler_pt)(ngx_stream_session_t *s);
0129 
0130 
0131 struct ngx_stream_phase_handler_s {
0132     ngx_stream_phase_handler_pt    checker;
0133     ngx_stream_handler_pt          handler;
0134     ngx_uint_t                     next;
0135 };
0136 
0137 
0138 typedef struct {
0139     ngx_stream_phase_handler_t    *handlers;
0140 } ngx_stream_phase_engine_t;
0141 
0142 
0143 typedef struct {
0144     ngx_array_t                    handlers;
0145 } ngx_stream_phase_t;
0146 
0147 
0148 typedef struct {
0149     ngx_array_t                    servers;     /* ngx_stream_core_srv_conf_t */
0150     ngx_array_t                    listen;      /* ngx_stream_listen_t */
0151 
0152     ngx_stream_phase_engine_t      phase_engine;
0153 
0154     ngx_hash_t                     variables_hash;
0155 
0156     ngx_array_t                    variables;        /* ngx_stream_variable_t */
0157     ngx_array_t                    prefix_variables; /* ngx_stream_variable_t */
0158     ngx_uint_t                     ncaptures;
0159 
0160     ngx_uint_t                     variables_hash_max_size;
0161     ngx_uint_t                     variables_hash_bucket_size;
0162 
0163     ngx_hash_keys_arrays_t        *variables_keys;
0164 
0165     ngx_stream_phase_t             phases[NGX_STREAM_LOG_PHASE + 1];
0166 } ngx_stream_core_main_conf_t;
0167 
0168 
0169 typedef struct {
0170     ngx_stream_content_handler_pt  handler;
0171 
0172     ngx_stream_conf_ctx_t         *ctx;
0173 
0174     u_char                        *file_name;
0175     ngx_uint_t                     line;
0176 
0177     ngx_flag_t                     tcp_nodelay;
0178     size_t                         preread_buffer_size;
0179     ngx_msec_t                     preread_timeout;
0180 
0181     ngx_log_t                     *error_log;
0182 
0183     ngx_msec_t                     resolver_timeout;
0184     ngx_resolver_t                *resolver;
0185 
0186     ngx_msec_t                     proxy_protocol_timeout;
0187 
0188     ngx_uint_t                     listen;  /* unsigned  listen:1; */
0189 } ngx_stream_core_srv_conf_t;
0190 
0191 
0192 struct ngx_stream_session_s {
0193     uint32_t                       signature;         /* "STRM" */
0194 
0195     ngx_connection_t              *connection;
0196 
0197     off_t                          received;
0198     time_t                         start_sec;
0199     ngx_msec_t                     start_msec;
0200 
0201     ngx_log_handler_pt             log_handler;
0202 
0203     void                         **ctx;
0204     void                         **main_conf;
0205     void                         **srv_conf;
0206 
0207     ngx_stream_upstream_t         *upstream;
0208     ngx_array_t                   *upstream_states;
0209                                            /* of ngx_stream_upstream_state_t */
0210     ngx_stream_variable_value_t   *variables;
0211 
0212 #if (NGX_PCRE)
0213     ngx_uint_t                     ncaptures;
0214     int                           *captures;
0215     u_char                        *captures_data;
0216 #endif
0217 
0218     ngx_int_t                      phase_handler;
0219     ngx_uint_t                     status;
0220 
0221     unsigned                       ssl:1;
0222 
0223     unsigned                       stat_processing:1;
0224 
0225     unsigned                       health_check:1;
0226 };
0227 
0228 
0229 typedef struct {
0230     ngx_int_t                    (*preconfiguration)(ngx_conf_t *cf);
0231     ngx_int_t                    (*postconfiguration)(ngx_conf_t *cf);
0232 
0233     void                        *(*create_main_conf)(ngx_conf_t *cf);
0234     char                        *(*init_main_conf)(ngx_conf_t *cf, void *conf);
0235 
0236     void                        *(*create_srv_conf)(ngx_conf_t *cf);
0237     char                        *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
0238                                                    void *conf);
0239 } ngx_stream_module_t;
0240 
0241 
0242 #define NGX_STREAM_MODULE       0x4d525453     /* "STRM" */
0243 
0244 #define NGX_STREAM_MAIN_CONF    0x02000000
0245 #define NGX_STREAM_SRV_CONF     0x04000000
0246 #define NGX_STREAM_UPS_CONF     0x08000000
0247 
0248 
0249 #define NGX_STREAM_MAIN_CONF_OFFSET  offsetof(ngx_stream_conf_ctx_t, main_conf)
0250 #define NGX_STREAM_SRV_CONF_OFFSET   offsetof(ngx_stream_conf_ctx_t, srv_conf)
0251 
0252 
0253 #define ngx_stream_get_module_ctx(s, module)   (s)->ctx[module.ctx_index]
0254 #define ngx_stream_set_ctx(s, c, module)       s->ctx[module.ctx_index] = c;
0255 #define ngx_stream_delete_ctx(s, module)       s->ctx[module.ctx_index] = NULL;
0256 
0257 
0258 #define ngx_stream_get_module_main_conf(s, module)                             \
0259     (s)->main_conf[module.ctx_index]
0260 #define ngx_stream_get_module_srv_conf(s, module)                              \
0261     (s)->srv_conf[module.ctx_index]
0262 
0263 #define ngx_stream_conf_get_module_main_conf(cf, module)                       \
0264     ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
0265 #define ngx_stream_conf_get_module_srv_conf(cf, module)                        \
0266     ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
0267 
0268 #define ngx_stream_cycle_get_module_main_conf(cycle, module)                   \
0269     (cycle->conf_ctx[ngx_stream_module.index] ?                                \
0270         ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index])   \
0271             ->main_conf[module.ctx_index]:                                     \
0272         NULL)
0273 
0274 
0275 #define NGX_STREAM_WRITE_BUFFERED  0x10
0276 
0277 
0278 void ngx_stream_core_run_phases(ngx_stream_session_t *s);
0279 ngx_int_t ngx_stream_core_generic_phase(ngx_stream_session_t *s,
0280     ngx_stream_phase_handler_t *ph);
0281 ngx_int_t ngx_stream_core_preread_phase(ngx_stream_session_t *s,
0282     ngx_stream_phase_handler_t *ph);
0283 ngx_int_t ngx_stream_core_content_phase(ngx_stream_session_t *s,
0284     ngx_stream_phase_handler_t *ph);
0285 
0286 
0287 void ngx_stream_init_connection(ngx_connection_t *c);
0288 void ngx_stream_session_handler(ngx_event_t *rev);
0289 void ngx_stream_finalize_session(ngx_stream_session_t *s, ngx_uint_t rc);
0290 
0291 
0292 extern ngx_module_t  ngx_stream_module;
0293 extern ngx_uint_t    ngx_stream_max_module;
0294 extern ngx_module_t  ngx_stream_core_module;
0295 
0296 
0297 typedef ngx_int_t (*ngx_stream_filter_pt)(ngx_stream_session_t *s,
0298     ngx_chain_t *chain, ngx_uint_t from_upstream);
0299 
0300 
0301 extern ngx_stream_filter_pt  ngx_stream_top_filter;
0302 
0303 
0304 #endif /* _NGX_STREAM_H_INCLUDED_ */