153Sigor@sysoev.ru 253Sigor@sysoev.ru /* 353Sigor@sysoev.ru * Copyright (C) Igor Sysoev 453Sigor@sysoev.ru * Copyright (C) NGINX, Inc. 553Sigor@sysoev.ru */ 653Sigor@sysoev.ru 753Sigor@sysoev.ru #ifndef _NXT_ROUTER_H_INCLUDED_ 853Sigor@sysoev.ru #define _NXT_ROUTER_H_INCLUDED_ 953Sigor@sysoev.ru 1053Sigor@sysoev.ru 1153Sigor@sysoev.ru #include <nxt_main.h> 1253Sigor@sysoev.ru #include <nxt_runtime.h> 13240Sigor@sysoev.ru #include <nxt_main_process.h> 14444Sigor@sysoev.ru 15630Svbart@nginx.com typedef struct nxt_http_request_s nxt_http_request_t; 16133Sigor@sysoev.ru #include <nxt_application.h> 1753Sigor@sysoev.ru 1853Sigor@sysoev.ru 191264Sigor@sysoev.ru typedef struct nxt_http_action_s nxt_http_action_t; 20964Sigor@sysoev.ru typedef struct nxt_http_routes_s nxt_http_routes_t; 212132Sz.hong@f5.com typedef struct nxt_http_forward_s nxt_http_forward_t; 221394Sigor@sysoev.ru typedef struct nxt_upstream_s nxt_upstream_t; 231394Sigor@sysoev.ru typedef struct nxt_upstreams_s nxt_upstreams_t; 24630Svbart@nginx.com typedef struct nxt_router_access_log_s nxt_router_access_log_t; 25630Svbart@nginx.com 26630Svbart@nginx.com 271264Sigor@sysoev.ru #define NXT_HTTP_ACTION_ERROR ((nxt_http_action_t *) -1) 281060Sigor@sysoev.ru 291060Sigor@sysoev.ru 3053Sigor@sysoev.ru typedef struct { 31630Svbart@nginx.com nxt_thread_spinlock_t lock; 32630Svbart@nginx.com nxt_queue_t engines; 3353Sigor@sysoev.ru 34630Svbart@nginx.com nxt_queue_t sockets; /* of nxt_socket_conf_t */ 35630Svbart@nginx.com nxt_queue_t apps; /* of nxt_app_t */ 36630Svbart@nginx.com 37630Svbart@nginx.com nxt_router_access_log_t *access_log; 3853Sigor@sysoev.ru } nxt_router_t; 3953Sigor@sysoev.ru 4053Sigor@sysoev.ru 4153Sigor@sysoev.ru typedef struct { 42630Svbart@nginx.com uint32_t count; 43630Svbart@nginx.com uint32_t threads; 441183Svbart@nginx.com 451183Svbart@nginx.com nxt_mp_t *mem_pool; 462246Sz.hong@f5.com nxt_tstr_state_t *tstr_state; 471183Svbart@nginx.com 48630Svbart@nginx.com nxt_router_t *router; 49964Sigor@sysoev.ru nxt_http_routes_t *routes; 501394Sigor@sysoev.ru nxt_upstreams_t *upstreams; 511183Svbart@nginx.com 521183Svbart@nginx.com nxt_lvlhsh_t mtypes_hash; 531563Svbart@nginx.com nxt_lvlhsh_t apps_hash; 54630Svbart@nginx.com 55630Svbart@nginx.com nxt_router_access_log_t *access_log; 562246Sz.hong@f5.com nxt_tstr_t *log_format; 57*2625Sz.hong@f5.com nxt_tstr_t *log_expr; 58*2625Sz.hong@f5.com uint8_t log_negate; /* 1 bit */ 5953Sigor@sysoev.ru } nxt_router_conf_t; 6053Sigor@sysoev.ru 6153Sigor@sysoev.ru 6253Sigor@sysoev.ru typedef struct { 6353Sigor@sysoev.ru nxt_event_engine_t *engine; 64154Sigor@sysoev.ru nxt_work_t *jobs; 65315Sigor@sysoev.ru 66315Sigor@sysoev.ru enum { 67315Sigor@sysoev.ru NXT_ROUTER_ENGINE_KEEP = 0, 68315Sigor@sysoev.ru NXT_ROUTER_ENGINE_ADD, 69315Sigor@sysoev.ru NXT_ROUTER_ENGINE_DELETE, 70315Sigor@sysoev.ru } action; 7153Sigor@sysoev.ru } nxt_router_engine_conf_t; 7253Sigor@sysoev.ru 7353Sigor@sysoev.ru 7453Sigor@sysoev.ru typedef struct { 75774Svbart@nginx.com #if (NXT_TLS) 76774Svbart@nginx.com nxt_queue_t tls; /* of nxt_router_tlssock_t */ 77774Svbart@nginx.com #endif 78774Svbart@nginx.com 792450Sz.hong@f5.com #if (NXT_HAVE_NJS) 802450Sz.hong@f5.com nxt_queue_t js_modules; 812450Sz.hong@f5.com #endif 822450Sz.hong@f5.com 83133Sigor@sysoev.ru nxt_queue_t apps; /* of nxt_app_t */ 84133Sigor@sysoev.ru nxt_queue_t previous; /* of nxt_app_t */ 85133Sigor@sysoev.ru 8653Sigor@sysoev.ru uint32_t new_threads; 87139Sigor@sysoev.ru uint32_t stream; 88139Sigor@sysoev.ru uint32_t count; 8953Sigor@sysoev.ru 90139Sigor@sysoev.ru nxt_event_engine_t *engine; 91139Sigor@sysoev.ru nxt_port_t *port; 9253Sigor@sysoev.ru nxt_array_t *engines; 93591Sigor@sysoev.ru nxt_router_conf_t *router_conf; 9465Sigor@sysoev.ru nxt_mp_t *mem_pool; 9553Sigor@sysoev.ru } nxt_router_temp_conf_t; 9653Sigor@sysoev.ru 9753Sigor@sysoev.ru 98153Sigor@sysoev.ru typedef struct { 99153Sigor@sysoev.ru nxt_task_t task; 100153Sigor@sysoev.ru nxt_work_t work; 101153Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf; 102153Sigor@sysoev.ru } nxt_joint_job_t; 103153Sigor@sysoev.ru 104153Sigor@sysoev.ru 105753Smax.romanov@nginx.com typedef struct { 106753Smax.romanov@nginx.com uint32_t use_count; 107753Smax.romanov@nginx.com nxt_app_t *app; 108753Smax.romanov@nginx.com nxt_timer_t idle_timer; 109753Smax.romanov@nginx.com nxt_work_t free_app_work; 110753Smax.romanov@nginx.com } nxt_app_joint_t; 111753Smax.romanov@nginx.com 112753Smax.romanov@nginx.com 113141Smax.romanov@nginx.com struct nxt_app_s { 1141547Smax.romanov@nginx.com nxt_thread_mutex_t mutex; /* Protects ports queue. */ 1151547Smax.romanov@nginx.com nxt_queue_t ports; /* of nxt_port_t.app_link */ 1161547Smax.romanov@nginx.com nxt_lvlhsh_t port_hash; /* of nxt_port_t */ 117163Smax.romanov@nginx.com 118507Smax.romanov@nginx.com nxt_queue_t spare_ports; /* of nxt_port_t.idle_link */ 119507Smax.romanov@nginx.com nxt_queue_t idle_ports; /* of nxt_port_t.idle_link */ 120507Smax.romanov@nginx.com nxt_work_t adjust_idle_work; 121507Smax.romanov@nginx.com nxt_event_engine_t *engine; 122507Smax.romanov@nginx.com 123133Sigor@sysoev.ru nxt_str_t name; 124133Sigor@sysoev.ru 1251547Smax.romanov@nginx.com uint32_t port_hash_count; 1261547Smax.romanov@nginx.com 1271547Smax.romanov@nginx.com uint32_t active_requests; 128507Smax.romanov@nginx.com uint32_t pending_processes; 129507Smax.romanov@nginx.com uint32_t processes; 130507Smax.romanov@nginx.com uint32_t idle_processes; 131507Smax.romanov@nginx.com 132507Smax.romanov@nginx.com uint32_t max_processes; 133507Smax.romanov@nginx.com uint32_t spare_processes; 134507Smax.romanov@nginx.com uint32_t max_pending_processes; 135133Sigor@sysoev.ru 1361926Smax.romanov@nginx.com uint32_t generation; 1371998St.nateldemoura@f5.com uint32_t proto_port_requests; 1381926Smax.romanov@nginx.com 139318Smax.romanov@nginx.com nxt_msec_t timeout; 140507Smax.romanov@nginx.com nxt_msec_t idle_timeout; 141318Smax.romanov@nginx.com 1421473Svbart@nginx.com nxt_str_t *targets; 1431473Svbart@nginx.com 144133Sigor@sysoev.ru nxt_app_type_t type:8; 145133Sigor@sysoev.ru 1461473Svbart@nginx.com nxt_mp_t *mem_pool; 147133Sigor@sysoev.ru nxt_queue_link_t link; 148133Sigor@sysoev.ru 149133Sigor@sysoev.ru nxt_str_t conf; 150343Smax.romanov@nginx.com 151343Smax.romanov@nginx.com nxt_atomic_t use_count; 1521561Smax.romanov@nginx.com nxt_queue_t ack_waiting_req; /* of nxt_http_request_t.app_link */ 153753Smax.romanov@nginx.com 154753Smax.romanov@nginx.com nxt_app_joint_t *joint; 1551547Smax.romanov@nginx.com nxt_port_t *shared_port; 1561998St.nateldemoura@f5.com nxt_port_t *proto_port; 1571547Smax.romanov@nginx.com 1581547Smax.romanov@nginx.com nxt_port_mmaps_t outgoing; 159141Smax.romanov@nginx.com }; 160133Sigor@sysoev.ru 161133Sigor@sysoev.ru 162133Sigor@sysoev.ru typedef struct { 1631131Smax.romanov@nginx.com size_t max_frame_size; 1641131Smax.romanov@nginx.com nxt_msec_t read_timeout; 1651131Smax.romanov@nginx.com nxt_msec_t keepalive_interval; 1661131Smax.romanov@nginx.com } nxt_websocket_conf_t; 1671131Smax.romanov@nginx.com 1681131Smax.romanov@nginx.com 1691131Smax.romanov@nginx.com typedef struct { 17053Sigor@sysoev.ru uint32_t count; 17153Sigor@sysoev.ru nxt_queue_link_t link; 17253Sigor@sysoev.ru nxt_router_conf_t *router_conf; 173115Sigor@sysoev.ru 1741264Sigor@sysoev.ru nxt_http_action_t *action; 175133Sigor@sysoev.ru 176359Sigor@sysoev.ru /* 177359Sigor@sysoev.ru * A listen socket time can be shorter than socket configuration life 178359Sigor@sysoev.ru * time, so a copy of the non-wildcard socket sockaddr is stored here 179359Sigor@sysoev.ru * to be used as a local sockaddr in connections. 180359Sigor@sysoev.ru */ 181359Sigor@sysoev.ru nxt_sockaddr_t *sockaddr; 182359Sigor@sysoev.ru 183359Sigor@sysoev.ru nxt_listen_socket_t *listen; 18453Sigor@sysoev.ru 18553Sigor@sysoev.ru size_t header_buffer_size; 18653Sigor@sysoev.ru size_t large_header_buffer_size; 187206Smax.romanov@nginx.com size_t large_header_buffers; 188206Smax.romanov@nginx.com size_t body_buffer_size; 189206Smax.romanov@nginx.com size_t max_body_size; 1901270Sigor@sysoev.ru size_t proxy_header_buffer_size; 1911270Sigor@sysoev.ru size_t proxy_buffer_size; 1921270Sigor@sysoev.ru size_t proxy_buffers; 1931270Sigor@sysoev.ru 194431Sigor@sysoev.ru nxt_msec_t idle_timeout; 19553Sigor@sysoev.ru nxt_msec_t header_read_timeout; 196206Smax.romanov@nginx.com nxt_msec_t body_read_timeout; 197431Sigor@sysoev.ru nxt_msec_t send_timeout; 1981270Sigor@sysoev.ru nxt_msec_t proxy_timeout; 1991270Sigor@sysoev.ru nxt_msec_t proxy_send_timeout; 2001270Sigor@sysoev.ru nxt_msec_t proxy_read_timeout; 201771Sigor@sysoev.ru 2021131Smax.romanov@nginx.com nxt_websocket_conf_t websocket_conf; 2031131Smax.romanov@nginx.com 2041403Smax.romanov@nginx.com nxt_str_t body_temp_path; 2051403Smax.romanov@nginx.com 2062381Salx@nginx.com uint8_t log_route; /* 1 bit */ 2072381Salx@nginx.com 2081709Svbart@nginx.com uint8_t discard_unsafe_fields; /* 1 bit */ 2091709Svbart@nginx.com 2102437Sa.clayton@nginx.com uint8_t server_version; /* 1 bit */ 2112437Sa.clayton@nginx.com 2122133Sz.hong@f5.com nxt_http_forward_t *forwarded; 2132132Sz.hong@f5.com nxt_http_forward_t *client_ip; 2141936So.canty@f5.com 215771Sigor@sysoev.ru #if (NXT_TLS) 216771Sigor@sysoev.ru nxt_tls_conf_t *tls; 217771Sigor@sysoev.ru #endif 21853Sigor@sysoev.ru } nxt_socket_conf_t; 21953Sigor@sysoev.ru 22053Sigor@sysoev.ru 22153Sigor@sysoev.ru typedef struct { 22253Sigor@sysoev.ru uint32_t count; 22353Sigor@sysoev.ru nxt_queue_link_t link; 22453Sigor@sysoev.ru nxt_event_engine_t *engine; 22553Sigor@sysoev.ru nxt_socket_conf_t *socket_conf; 22653Sigor@sysoev.ru 2271867Smax.romanov@nginx.com nxt_joint_job_t *close_job; 2281867Smax.romanov@nginx.com 2291394Sigor@sysoev.ru nxt_upstream_t **upstreams; 2301394Sigor@sysoev.ru 23153Sigor@sysoev.ru /* Modules configuraitons. */ 23253Sigor@sysoev.ru } nxt_socket_conf_joint_t; 23353Sigor@sysoev.ru 23453Sigor@sysoev.ru 235630Svbart@nginx.com struct nxt_router_access_log_s { 236630Svbart@nginx.com void (*handler)(nxt_task_t *task, nxt_http_request_t *r, 2372166Sz.hong@f5.com nxt_router_access_log_t *access_log, 2382246Sz.hong@f5.com nxt_tstr_t *format); 239630Svbart@nginx.com nxt_fd_t fd; 240630Svbart@nginx.com nxt_str_t path; 241630Svbart@nginx.com uint32_t count; 242630Svbart@nginx.com }; 243630Svbart@nginx.com 244630Svbart@nginx.com 2451007Salexander.borisov@nginx.com void nxt_router_process_http_request(nxt_task_t *task, nxt_http_request_t *r, 2461925Sz.hong@f5.com nxt_http_action_t *action); 247343Smax.romanov@nginx.com void nxt_router_app_port_close(nxt_task_t *task, nxt_port_t *port); 2481925Sz.hong@f5.com nxt_int_t nxt_router_application_init(nxt_router_conf_t *rtcf, nxt_str_t *name, 2491925Sz.hong@f5.com nxt_str_t *target, nxt_http_action_t *action); 250683Sigor@sysoev.ru void nxt_router_listen_event_release(nxt_task_t *task, nxt_listen_event_t *lev, 251683Sigor@sysoev.ru nxt_socket_conf_joint_t *joint); 2522165Sz.hong@f5.com 2532165Sz.hong@f5.com void nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data); 2542165Sz.hong@f5.com void nxt_router_conf_error(nxt_task_t *task, nxt_router_temp_conf_t *tmcf); 255683Sigor@sysoev.ru void nxt_router_conf_release(nxt_task_t *task, nxt_socket_conf_joint_t *joint); 256115Sigor@sysoev.ru 2572165Sz.hong@f5.com nxt_int_t nxt_router_access_log_create(nxt_task_t *task, 2582165Sz.hong@f5.com nxt_router_conf_t *rtcf, nxt_conf_value_t *value); 2592165Sz.hong@f5.com void nxt_router_access_log_open(nxt_task_t *task, nxt_router_temp_conf_t *tmcf); 2602165Sz.hong@f5.com void nxt_router_access_log_use(nxt_thread_spinlock_t *lock, 2612165Sz.hong@f5.com nxt_router_access_log_t *access_log); 2622165Sz.hong@f5.com void nxt_router_access_log_release(nxt_task_t *task, 2632165Sz.hong@f5.com nxt_thread_spinlock_t *lock, nxt_router_access_log_t *access_log); 2642165Sz.hong@f5.com void nxt_router_access_log_reopen_handler(nxt_task_t *task, 2652165Sz.hong@f5.com nxt_port_recv_msg_t *msg); 2662165Sz.hong@f5.com 2672165Sz.hong@f5.com 2682165Sz.hong@f5.com extern nxt_router_t *nxt_router; 2692165Sz.hong@f5.com 270431Sigor@sysoev.ru 27153Sigor@sysoev.ru #endif /* _NXT_ROUTER_H_INCLUDED_ */ 272