acl/lib_acl/include/net/acl_dns.h

182 lines
5.4 KiB
C
Raw Normal View History

2014-09-06 23:08:25 +08:00
#ifndef ACL_DNS_INCLUDE_H
#define ACL_DNS_INCLUDE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stdlib/acl_define.h"
#include "stdlib/acl_htable.h"
#include "stdlib/acl_cache2.h"
#ifdef ACL_UNIX
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include "event/acl_events.h"
#include "aio/acl_aio.h"
#include "acl_netdb.h"
/* DNS <20><>ѯʱ<D1AF>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EBB6A8> */
#define ACL_DNS_OK 0
#define ACL_DNS_OK_CACHE 1
#define ACL_DNS_ERR_FMT -1
#define ACL_DNS_ERR_SVR -2
#define ACL_DNS_ERR_NO_EXIST -3
#define ACL_DNS_ERR_NO_SUPPORT -4
#define ACL_DNS_ERR_DENY -5
#define ACL_DNS_ERR_YX -6
#define ACL_DNS_ERR_YXRR -7
#define ACL_DNS_ERR_NXRR -8
#define ACL_DNS_ERR_NO_AUTH -9
#define ACL_DNS_ERR_NOT_ZONE -10
#define ACL_DNS_ERR_UNPACK -15
#define ACL_DNS_ERR_TIMEOUT -16
#define ACL_DNS_ERR_EXIST -17
#define ACL_DNS_ERR_BUILD_REQ -18
typedef struct ACL_DNS_ADDR {
char ip[64]; /* DNS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ */
unsigned short port; /* DNS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD> */
struct sockaddr_in addr; /* DNS <20><>ַ */
int addr_len; /* addr <20><>С */
int mask_length; /* DNS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB3A4>(> 0 && < 32) */
struct in_addr in; /* addr <20><><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD>ַ */
} ACL_DNS_ADDR;
typedef struct ACL_DNS {
ACL_AIO *aio; /* <20>첽IO<49><4F><EFBFBD><EFBFBD> */
unsigned short qid; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID<49><44>ʶ<EFBFBD><CAB6> */
ACL_ASTREAM *astream; /* <20><EFBFBD><ECB2BD> */
ACL_ARRAY *groups; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD> */
ACL_ARRAY *dns_list; /* DNS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>б<EFBFBD> */
int dns_idx; /* <20><>ǰʹ<C7B0>õ<EFBFBD> dns_list <20><><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD> */
ACL_DNS_ADDR addr_from; /* <20><>Դ DNS <20><>ַ */
ACL_HTABLE *lookup_table; /* <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
ACL_CACHE2 *dns_cache; /* <20><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD>DNS<4E><53>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD> */
int timeout; /* ÿ<>β<EFBFBD>ѯ<EFBFBD>ij<EFBFBD>ʱʱ<CAB1><CAB1>ֵ(<28><>) */
int retry_limit; /* <20><>ѯ<EFBFBD><D1AF>ʱʱ<CAB1><CAB1><EFBFBD>ԵĴ<D4B5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
unsigned int flag; /* <20><>־λ */
#define ACL_DNS_FLAG_ALLOC (1 << 0) /* <20><><EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define ACL_DNS_FLAG_CHECK_DNS_IP (1 << 1) /* <20><><EFBFBD><EFBFBD>DNS<4E><53>ַ<EFBFBD>Ƿ<EFBFBD>ƥ<EFBFBD><C6A5> */
#define ACL_DNS_FLAG_CHECK_DNS_NET (1 << 2) /* <20><><EFBFBD><EFBFBD>DNS<4E><53><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ƥ<EFBFBD><C6A5> */
/* <20>ú<EFBFBD><C3BA><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⶯̬<E2B6AF><CCAC><EFBFBD>ؿ<EFBFBD><D8BF>ķ<EFBFBD><C4B7>ʵ<EFBFBD>ַ<EFBFBD><D6B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
ACL_EVENT_NOTIFY_TIME lookup_timeout;
} ACL_DNS;
typedef struct ACL_DNS_REQ ACL_DNS_REQ;
/**
* <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param aio {ACL_AIO*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param timeout {int} ÿ<EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ѯʱ<EFBFBD>ij<EFBFBD>ʱֵ
*/
ACL_API void acl_dns_init(ACL_DNS *dns, ACL_AIO *aio, int timeout);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><EFBFBD>
* @param aio {ACL_AIO*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param timeout {int} ÿ<EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ѯʱ<EFBFBD>ij<EFBFBD>ʱֵ
* @return {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API ACL_DNS *acl_dns_create(ACL_AIO *aio, int timeout);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param limit {int} DNS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󻺴<EFBFBD><EFBFBD><EFBFBD>Ŀ
*/
ACL_API void acl_dns_open_cache(ACL_DNS *dns, int limit);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dns_ip {const char*} DNS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD>ַ
* @param dns_port {unsigned short} DNS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
* @param mask_length {int} DNS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0 < && < 32)
*/
ACL_API void acl_dns_add_dns(ACL_DNS *dns, const char *dns_ip,
unsigned short dns_port, int mask_length);
/**
* <EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void acl_dns_close(ACL_DNS *dns);
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD>־λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ԴIP<EFBFBD><EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>Ϊ<EFBFBD>˷<EFBFBD>ֹDNS<EFBFBD><EFBFBD>ѯʱ<EFBFBD><EFBFBD>UDP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void acl_dns_check_dns_ip(ACL_DNS *dns);
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD>־λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ԴIP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>Ϊ<EFBFBD>˷<EFBFBD>ֹDNS<EFBFBD><EFBFBD>ѯʱ<EFBFBD><EFBFBD>UDP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void acl_dns_check_dns_net(ACL_DNS *dns);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD>
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param retry_limit {int} <EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void acl_dns_set_retry_limit(ACL_DNS *dns, int retry_limit);
/**
* <EFBFBD><EFBFBD><EFBFBD>ѯһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>A<EFBFBD><EFBFBD>¼IP<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param domain {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param callback {void (*)(ACL_DNS_DB*, void*)} <EFBFBD><EFBFBD>ѯ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܵĻص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD> callback <EFBFBD><EFBFBD> ACL_DNS_DB Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ѯʧ<EFBFBD><EFBFBD>, <EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ѯʧ<EFBFBD><EFBFBD>ʱ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param ctx {void*} callback <EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD>֮һ
* @return {ACL_DNS_REQ*} <EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>ΪNULL<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API ACL_DNS_REQ *acl_dns_lookup(ACL_DNS *dns, const char *domain,
void (*callback)(ACL_DNS_DB *, void *, int), void *ctx);
/**
* <EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param domain {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param ip_list {const char*} IP<EFBFBD><EFBFBD>ַ<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ϊ ';'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 192.168.0.1;192.168.0.2
*/
ACL_API void acl_dns_add_host(ACL_DNS *dns, const char *domain, const char *ip_list);
/**
* <EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* @param dns {ACL_DNS*} DNS<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param group {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: .test.com, <EFBFBD><EFBFBD> a.test.com, b.test.com
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> .test.com <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param ip_list {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD>ַ<EFBFBD>б<EFBFBD>
* @param refer {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ѯ
* @param excepts {ACL_ARGV*} <EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> group <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void acl_dns_add_group(ACL_DNS *dns, const char *group, const char *refer,
const char *ip_list, const char *excepts);
/**
* ȡ<EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param handle {ACL_DNS_REQ*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD>¼<EFBFBD>
*/
ACL_API void acl_dns_cancel(ACL_DNS_REQ *handle);
/**
* <EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵõ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* @param errnum {int} DNS<EFBFBD><EFBFBD>ѯʱ<EFBFBD><EFBFBD><EFBFBD>صĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
*/
ACL_API const char *acl_dns_serror(int errnum);
#ifdef __cplusplus
}
#endif
#endif