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) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 
0011 
0012 #ifndef _NGX_RESOLVER_H_INCLUDED_
0013 #define _NGX_RESOLVER_H_INCLUDED_
0014 
0015 
0016 #define NGX_RESOLVE_A         1
0017 #define NGX_RESOLVE_CNAME     5
0018 #define NGX_RESOLVE_PTR       12
0019 #define NGX_RESOLVE_MX        15
0020 #define NGX_RESOLVE_TXT       16
0021 #if (NGX_HAVE_INET6)
0022 #define NGX_RESOLVE_AAAA      28
0023 #endif
0024 #define NGX_RESOLVE_SRV       33
0025 #define NGX_RESOLVE_DNAME     39
0026 
0027 #define NGX_RESOLVE_FORMERR   1
0028 #define NGX_RESOLVE_SERVFAIL  2
0029 #define NGX_RESOLVE_NXDOMAIN  3
0030 #define NGX_RESOLVE_NOTIMP    4
0031 #define NGX_RESOLVE_REFUSED   5
0032 #define NGX_RESOLVE_TIMEDOUT  NGX_ETIMEDOUT
0033 
0034 
0035 #define NGX_NO_RESOLVER       (void *) -1
0036 
0037 #define NGX_RESOLVER_MAX_RECURSION    50
0038 
0039 
0040 typedef struct ngx_resolver_s  ngx_resolver_t;
0041 
0042 
0043 typedef struct {
0044     ngx_connection_t         *udp;
0045     ngx_connection_t         *tcp;
0046     struct sockaddr          *sockaddr;
0047     socklen_t                 socklen;
0048     ngx_str_t                 server;
0049     ngx_log_t                 log;
0050     ngx_buf_t                *read_buf;
0051     ngx_buf_t                *write_buf;
0052     ngx_resolver_t           *resolver;
0053 } ngx_resolver_connection_t;
0054 
0055 
0056 typedef struct ngx_resolver_ctx_s  ngx_resolver_ctx_t;
0057 
0058 typedef void (*ngx_resolver_handler_pt)(ngx_resolver_ctx_t *ctx);
0059 
0060 
0061 typedef struct {
0062     struct sockaddr          *sockaddr;
0063     socklen_t                 socklen;
0064     ngx_str_t                 name;
0065     u_short                   priority;
0066     u_short                   weight;
0067 } ngx_resolver_addr_t;
0068 
0069 
0070 typedef struct {
0071     ngx_str_t                 name;
0072     u_short                   priority;
0073     u_short                   weight;
0074     u_short                   port;
0075 } ngx_resolver_srv_t;
0076 
0077 
0078 typedef struct {
0079     ngx_str_t                 name;
0080     u_short                   priority;
0081     u_short                   weight;
0082     u_short                   port;
0083 
0084     ngx_resolver_ctx_t       *ctx;
0085     ngx_int_t                 state;
0086 
0087     ngx_uint_t                naddrs;
0088     ngx_addr_t               *addrs;
0089 } ngx_resolver_srv_name_t;
0090 
0091 
0092 typedef struct {
0093     ngx_rbtree_node_t         node;
0094     ngx_queue_t               queue;
0095 
0096     /* PTR: resolved name, A: name to resolve */
0097     u_char                   *name;
0098 
0099 #if (NGX_HAVE_INET6)
0100     /* PTR: IPv6 address to resolve (IPv4 address is in rbtree node key) */
0101     struct in6_addr           addr6;
0102 #endif
0103 
0104     u_short                   nlen;
0105     u_short                   qlen;
0106 
0107     u_char                   *query;
0108 #if (NGX_HAVE_INET6)
0109     u_char                   *query6;
0110 #endif
0111 
0112     union {
0113         in_addr_t             addr;
0114         in_addr_t            *addrs;
0115         u_char               *cname;
0116         ngx_resolver_srv_t   *srvs;
0117     } u;
0118 
0119     u_char                    code;
0120     u_short                   naddrs;
0121     u_short                   nsrvs;
0122     u_short                   cnlen;
0123 
0124 #if (NGX_HAVE_INET6)
0125     union {
0126         struct in6_addr       addr6;
0127         struct in6_addr      *addrs6;
0128     } u6;
0129 
0130     u_short                   naddrs6;
0131 #endif
0132 
0133     time_t                    expire;
0134     time_t                    valid;
0135     uint32_t                  ttl;
0136 
0137     unsigned                  tcp:1;
0138 #if (NGX_HAVE_INET6)
0139     unsigned                  tcp6:1;
0140 #endif
0141 
0142     ngx_uint_t                last_connection;
0143 
0144     ngx_resolver_ctx_t       *waiting;
0145 } ngx_resolver_node_t;
0146 
0147 
0148 struct ngx_resolver_s {
0149     /* has to be pointer because of "incomplete type" */
0150     ngx_event_t              *event;
0151     void                     *dummy;
0152     ngx_log_t                *log;
0153 
0154     /* event ident must be after 3 pointers as in ngx_connection_t */
0155     ngx_int_t                 ident;
0156 
0157     /* simple round robin DNS peers balancer */
0158     ngx_array_t               connections;
0159     ngx_uint_t                last_connection;
0160 
0161     ngx_rbtree_t              name_rbtree;
0162     ngx_rbtree_node_t         name_sentinel;
0163 
0164     ngx_rbtree_t              srv_rbtree;
0165     ngx_rbtree_node_t         srv_sentinel;
0166 
0167     ngx_rbtree_t              addr_rbtree;
0168     ngx_rbtree_node_t         addr_sentinel;
0169 
0170     ngx_queue_t               name_resend_queue;
0171     ngx_queue_t               srv_resend_queue;
0172     ngx_queue_t               addr_resend_queue;
0173 
0174     ngx_queue_t               name_expire_queue;
0175     ngx_queue_t               srv_expire_queue;
0176     ngx_queue_t               addr_expire_queue;
0177 
0178 #if (NGX_HAVE_INET6)
0179     ngx_uint_t                ipv6;                 /* unsigned  ipv6:1; */
0180     ngx_rbtree_t              addr6_rbtree;
0181     ngx_rbtree_node_t         addr6_sentinel;
0182     ngx_queue_t               addr6_resend_queue;
0183     ngx_queue_t               addr6_expire_queue;
0184 #endif
0185 
0186     time_t                    resend_timeout;
0187     time_t                    tcp_timeout;
0188     time_t                    expire;
0189     time_t                    valid;
0190 
0191     ngx_uint_t                log_level;
0192 };
0193 
0194 
0195 struct ngx_resolver_ctx_s {
0196     ngx_resolver_ctx_t       *next;
0197     ngx_resolver_t           *resolver;
0198     ngx_resolver_node_t      *node;
0199 
0200     /* event ident must be after 3 pointers as in ngx_connection_t */
0201     ngx_int_t                 ident;
0202 
0203     ngx_int_t                 state;
0204     ngx_str_t                 name;
0205     ngx_str_t                 service;
0206 
0207     time_t                    valid;
0208     ngx_uint_t                naddrs;
0209     ngx_resolver_addr_t      *addrs;
0210     ngx_resolver_addr_t       addr;
0211     struct sockaddr_in        sin;
0212 
0213     ngx_uint_t                count;
0214     ngx_uint_t                nsrvs;
0215     ngx_resolver_srv_name_t  *srvs;
0216 
0217     ngx_resolver_handler_pt   handler;
0218     void                     *data;
0219     ngx_msec_t                timeout;
0220 
0221     ngx_uint_t                quick;  /* unsigned  quick:1; */
0222     ngx_uint_t                recursion;
0223     ngx_event_t              *event;
0224 };
0225 
0226 
0227 ngx_resolver_t *ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names,
0228     ngx_uint_t n);
0229 ngx_resolver_ctx_t *ngx_resolve_start(ngx_resolver_t *r,
0230     ngx_resolver_ctx_t *temp);
0231 ngx_int_t ngx_resolve_name(ngx_resolver_ctx_t *ctx);
0232 void ngx_resolve_name_done(ngx_resolver_ctx_t *ctx);
0233 ngx_int_t ngx_resolve_addr(ngx_resolver_ctx_t *ctx);
0234 void ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx);
0235 char *ngx_resolver_strerror(ngx_int_t err);
0236 
0237 
0238 #endif /* _NGX_RESOLVER_H_INCLUDED_ */