nginx/src/core/ngx_resolver.h

180 lines
4.6 KiB
C
Raw Normal View History

2007-11-24 01:13:26 +08:00
/*
* Copyright (C) Igor Sysoev
2012-01-18 23:07:43 +08:00
* Copyright (C) Nginx, Inc.
2007-11-24 01:13:26 +08:00
*/
#include <ngx_config.h>
#include <ngx_core.h>
#ifndef _NGX_RESOLVER_H_INCLUDED_
#define _NGX_RESOLVER_H_INCLUDED_
#define NGX_RESOLVE_A 1
#define NGX_RESOLVE_CNAME 5
#define NGX_RESOLVE_PTR 12
#define NGX_RESOLVE_MX 15
#define NGX_RESOLVE_TXT 16
#if (NGX_HAVE_INET6)
#define NGX_RESOLVE_AAAA 28
#endif
2008-04-11 01:12:21 +08:00
#define NGX_RESOLVE_DNAME 39
2007-11-24 01:13:26 +08:00
#define NGX_RESOLVE_FORMERR 1
#define NGX_RESOLVE_SERVFAIL 2
#define NGX_RESOLVE_NXDOMAIN 3
#define NGX_RESOLVE_NOTIMP 4
#define NGX_RESOLVE_REFUSED 5
#define NGX_RESOLVE_TIMEDOUT NGX_ETIMEDOUT
#define NGX_NO_RESOLVER (void *) -1
2008-04-12 15:29:20 +08:00
#define NGX_RESOLVER_MAX_RECURSION 50
2007-11-24 01:13:26 +08:00
typedef struct {
ngx_connection_t *connection;
struct sockaddr *sockaddr;
socklen_t socklen;
ngx_str_t server;
2010-01-11 19:01:02 +08:00
ngx_log_t log;
2007-11-24 01:13:26 +08:00
} ngx_udp_connection_t;
typedef struct ngx_resolver_ctx_s ngx_resolver_ctx_t;
typedef void (*ngx_resolver_handler_pt)(ngx_resolver_ctx_t *ctx);
typedef struct {
/* PTR: resolved name, A: name to resolve */
u_char *name;
ngx_queue_t queue;
/* event ident must be after 3 pointers as in ngx_connection_t */
ngx_int_t ident;
ngx_rbtree_node_t node;
#if (NGX_HAVE_INET6)
/* PTR: IPv6 address to resolve (IPv4 address is in rbtree node key) */
struct in6_addr addr6;
#endif
2007-11-24 01:13:26 +08:00
u_short nlen;
u_short qlen;
u_char *query;
#if (NGX_HAVE_INET6)
u_char *query6;
#endif
2007-11-24 01:13:26 +08:00
union {
in_addr_t addr;
in_addr_t *addrs;
u_char *cname;
} u;
u_char code;
2007-11-24 01:13:26 +08:00
u_short naddrs;
u_short cnlen;
#if (NGX_HAVE_INET6)
union {
struct in6_addr addr6;
struct in6_addr *addrs6;
} u6;
u_short naddrs6;
#endif
2007-11-24 01:13:26 +08:00
time_t expire;
time_t valid;
uint32_t ttl;
2007-11-24 01:13:26 +08:00
ngx_resolver_ctx_t *waiting;
} ngx_resolver_node_t;
typedef struct {
/* has to be pointer because of "incomplete type" */
ngx_event_t *event;
void *dummy;
2007-11-24 01:13:26 +08:00
ngx_log_t *log;
/* event ident must be after 3 pointers as in ngx_connection_t */
2007-11-24 01:13:26 +08:00
ngx_int_t ident;
/* simple round robin DNS peers balancer */
ngx_array_t udp_connections;
ngx_uint_t last_connection;
2007-11-24 01:13:26 +08:00
ngx_rbtree_t name_rbtree;
ngx_rbtree_node_t name_sentinel;
ngx_rbtree_t addr_rbtree;
ngx_rbtree_node_t addr_sentinel;
ngx_queue_t name_resend_queue;
ngx_queue_t addr_resend_queue;
ngx_queue_t name_expire_queue;
ngx_queue_t addr_expire_queue;
#if (NGX_HAVE_INET6)
ngx_uint_t ipv6; /* unsigned ipv6:1; */
ngx_rbtree_t addr6_rbtree;
ngx_rbtree_node_t addr6_sentinel;
ngx_queue_t addr6_resend_queue;
ngx_queue_t addr6_expire_queue;
#endif
2007-11-24 01:13:26 +08:00
time_t resend_timeout;
time_t expire;
time_t valid;
ngx_uint_t log_level;
} ngx_resolver_t;
struct ngx_resolver_ctx_s {
ngx_resolver_ctx_t *next;
ngx_resolver_t *resolver;
ngx_udp_connection_t *udp_connection;
ngx_int_t state;
ngx_str_t name;
ngx_uint_t naddrs;
ngx_addr_t *addrs;
ngx_addr_t addr;
struct sockaddr_in sin;
2007-11-24 01:13:26 +08:00
ngx_resolver_handler_pt handler;
void *data;
ngx_msec_t timeout;
ngx_uint_t quick; /* unsigned quick:1; */
2008-04-12 15:29:20 +08:00
ngx_uint_t recursion;
2007-11-24 01:13:26 +08:00
ngx_event_t *event;
};
ngx_resolver_t *ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names,
ngx_uint_t n);
2007-11-24 01:13:26 +08:00
ngx_resolver_ctx_t *ngx_resolve_start(ngx_resolver_t *r,
ngx_resolver_ctx_t *temp);
ngx_int_t ngx_resolve_name(ngx_resolver_ctx_t *ctx);
void ngx_resolve_name_done(ngx_resolver_ctx_t *ctx);
ngx_int_t ngx_resolve_addr(ngx_resolver_ctx_t *ctx);
void ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx);
char *ngx_resolver_strerror(ngx_int_t err);
#endif /* _NGX_RESOLVER_H_INCLUDED_ */