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                            rcvbuf;
0066     int                            sndbuf;
0067     int                            type;
0068 } ngx_stream_listen_t;
0069 
0070 
0071 typedef struct {
0072     ngx_stream_conf_ctx_t         *ctx;
0073     ngx_str_t                      addr_text;
0074     unsigned                       ssl:1;
0075     unsigned                       proxy_protocol:1;
0076 } ngx_stream_addr_conf_t;
0077 
0078 typedef struct {
0079     in_addr_t                      addr;
0080     ngx_stream_addr_conf_t         conf;
0081 } ngx_stream_in_addr_t;
0082 
0083 
0084 #if (NGX_HAVE_INET6)
0085 
0086 typedef struct {
0087     struct in6_addr                addr6;
0088     ngx_stream_addr_conf_t         conf;
0089 } ngx_stream_in6_addr_t;
0090 
0091 #endif
0092 
0093 
0094 typedef struct {
0095     /* ngx_stream_in_addr_t or ngx_stream_in6_addr_t */
0096     void                          *addrs;
0097     ngx_uint_t                     naddrs;
0098 } ngx_stream_port_t;
0099 
0100 
0101 typedef struct {
0102     int                            family;
0103     int                            type;
0104     in_port_t                      port;
0105     ngx_array_t                    addrs; /* array of ngx_stream_conf_addr_t */
0106 } ngx_stream_conf_port_t;
0107 
0108 
0109 typedef struct {
0110     ngx_stream_listen_t            opt;
0111 } ngx_stream_conf_addr_t;
0112 
0113 
0114 typedef enum {
0115     NGX_STREAM_POST_ACCEPT_PHASE = 0,
0116     NGX_STREAM_PREACCESS_PHASE,
0117     NGX_STREAM_ACCESS_PHASE,
0118     NGX_STREAM_SSL_PHASE,
0119     NGX_STREAM_PREREAD_PHASE,
0120     NGX_STREAM_CONTENT_PHASE,
0121     NGX_STREAM_LOG_PHASE
0122 } ngx_stream_phases;
0123 
0124 
0125 typedef struct ngx_stream_phase_handler_s  ngx_stream_phase_handler_t;
0126 
0127 typedef ngx_int_t (*ngx_stream_phase_handler_pt)(ngx_stream_session_t *s,
0128     ngx_stream_phase_handler_t *ph);
0129 typedef ngx_int_t (*ngx_stream_handler_pt)(ngx_stream_session_t *s);
0130 typedef void (*ngx_stream_content_handler_pt)(ngx_stream_session_t *s);
0131 
0132 
0133 struct ngx_stream_phase_handler_s {
0134     ngx_stream_phase_handler_pt    checker;
0135     ngx_stream_handler_pt          handler;
0136     ngx_uint_t                     next;
0137 };
0138 
0139 
0140 typedef struct {
0141     ngx_stream_phase_handler_t    *handlers;
0142 } ngx_stream_phase_engine_t;
0143 
0144 
0145 typedef struct {
0146     ngx_array_t                    handlers;
0147 } ngx_stream_phase_t;
0148 
0149 
0150 typedef struct {
0151     ngx_array_t                    servers;     /* ngx_stream_core_srv_conf_t */
0152     ngx_array_t                    listen;      /* ngx_stream_listen_t */
0153 
0154     ngx_stream_phase_engine_t      phase_engine;
0155 
0156     ngx_hash_t                     variables_hash;
0157 
0158     ngx_array_t                    variables;        /* ngx_stream_variable_t */
0159     ngx_array_t                    prefix_variables; /* ngx_stream_variable_t */
0160     ngx_uint_t                     ncaptures;
0161 
0162     ngx_uint_t                     variables_hash_max_size;
0163     ngx_uint_t                     variables_hash_bucket_size;
0164 
0165     ngx_hash_keys_arrays_t        *variables_keys;
0166 
0167     ngx_stream_phase_t             phases[NGX_STREAM_LOG_PHASE + 1];
0168 } ngx_stream_core_main_conf_t;
0169 
0170 
0171 typedef struct {
0172     ngx_stream_content_handler_pt  handler;
0173 
0174     ngx_stream_conf_ctx_t         *ctx;
0175 
0176     u_char                        *file_name;
0177     ngx_uint_t                     line;
0178 
0179     ngx_flag_t                     tcp_nodelay;
0180     size_t                         preread_buffer_size;
0181     ngx_msec_t                     preread_timeout;
0182 
0183     ngx_log_t                     *error_log;
0184 
0185     ngx_msec_t                     resolver_timeout;
0186     ngx_resolver_t                *resolver;
0187 
0188     ngx_msec_t                     proxy_protocol_timeout;
0189 
0190     ngx_uint_t                     listen;  /* unsigned  listen:1; */
0191 } ngx_stream_core_srv_conf_t;
0192 
0193 
0194 struct ngx_stream_session_s {
0195     uint32_t                       signature;         /* "STRM" */
0196 
0197     ngx_connection_t              *connection;
0198 
0199     off_t                          received;
0200     time_t                         start_sec;
0201     ngx_msec_t                     start_msec;
0202 
0203     ngx_log_handler_pt             log_handler;
0204 
0205     void                         **ctx;
0206     void                         **main_conf;
0207     void                         **srv_conf;
0208 
0209     ngx_stream_upstream_t         *upstream;
0210     ngx_array_t                   *upstream_states;
0211                                            /* of ngx_stream_upstream_state_t */
0212     ngx_stream_variable_value_t   *variables;
0213 
0214 #if (NGX_PCRE)
0215     ngx_uint_t                     ncaptures;
0216     int                           *captures;
0217     u_char                        *captures_data;
0218 #endif
0219 
0220     ngx_int_t                      phase_handler;
0221     ngx_uint_t                     status;
0222 
0223     unsigned                       ssl:1;
0224 
0225     unsigned                       stat_processing:1;
0226 
0227     unsigned                       health_check:1;
0228 };
0229 
0230 
0231 typedef struct {
0232     ngx_int_t                    (*preconfiguration)(ngx_conf_t *cf);
0233     ngx_int_t                    (*postconfiguration)(ngx_conf_t *cf);
0234 
0235     void                        *(*create_main_conf)(ngx_conf_t *cf);
0236     char                        *(*init_main_conf)(ngx_conf_t *cf, void *conf);
0237 
0238     void                        *(*create_srv_conf)(ngx_conf_t *cf);
0239     char                        *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
0240                                                    void *conf);
0241 } ngx_stream_module_t;
0242 
0243 
0244 #define NGX_STREAM_MODULE       0x4d525453     /* "STRM" */
0245 
0246 #define NGX_STREAM_MAIN_CONF    0x02000000
0247 #define NGX_STREAM_SRV_CONF     0x04000000
0248 #define NGX_STREAM_UPS_CONF     0x08000000
0249 
0250 
0251 #define NGX_STREAM_MAIN_CONF_OFFSET  offsetof(ngx_stream_conf_ctx_t, main_conf)
0252 #define NGX_STREAM_SRV_CONF_OFFSET   offsetof(ngx_stream_conf_ctx_t, srv_conf)
0253 
0254 
0255 #define ngx_stream_get_module_ctx(s, module)   (s)->ctx[module.ctx_index]
0256 #define ngx_stream_set_ctx(s, c, module)       s->ctx[module.ctx_index] = c;
0257 #define ngx_stream_delete_ctx(s, module)       s->ctx[module.ctx_index] = NULL;
0258 
0259 
0260 #define ngx_stream_get_module_main_conf(s, module)                             \
0261     (s)->main_conf[module.ctx_index]
0262 #define ngx_stream_get_module_srv_conf(s, module)                              \
0263     (s)->srv_conf[module.ctx_index]
0264 
0265 #define ngx_stream_conf_get_module_main_conf(cf, module)                       \
0266     ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
0267 #define ngx_stream_conf_get_module_srv_conf(cf, module)                        \
0268     ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
0269 
0270 #define ngx_stream_cycle_get_module_main_conf(cycle, module)                   \
0271     (cycle->conf_ctx[ngx_stream_module.index] ?                                \
0272         ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index])   \
0273             ->main_conf[module.ctx_index]:                                     \
0274         NULL)
0275 
0276 
0277 #define NGX_STREAM_WRITE_BUFFERED  0x10
0278 
0279 
0280 void ngx_stream_core_run_phases(ngx_stream_session_t *s);
0281 ngx_int_t ngx_stream_core_generic_phase(ngx_stream_session_t *s,
0282     ngx_stream_phase_handler_t *ph);
0283 ngx_int_t ngx_stream_core_preread_phase(ngx_stream_session_t *s,
0284     ngx_stream_phase_handler_t *ph);
0285 ngx_int_t ngx_stream_core_content_phase(ngx_stream_session_t *s,
0286     ngx_stream_phase_handler_t *ph);
0287 
0288 
0289 void ngx_stream_init_connection(ngx_connection_t *c);
0290 void ngx_stream_session_handler(ngx_event_t *rev);
0291 void ngx_stream_finalize_session(ngx_stream_session_t *s, ngx_uint_t rc);
0292 
0293 
0294 extern ngx_module_t  ngx_stream_module;
0295 extern ngx_uint_t    ngx_stream_max_module;
0296 extern ngx_module_t  ngx_stream_core_module;
0297 
0298 
0299 typedef ngx_int_t (*ngx_stream_filter_pt)(ngx_stream_session_t *s,
0300     ngx_chain_t *chain, ngx_uint_t from_upstream);
0301 
0302 
0303 extern ngx_stream_filter_pt  ngx_stream_top_filter;
0304 
0305 
0306 #endif /* _NGX_STREAM_H_INCLUDED_ */