1 /* Name resolution using adns */
9 struct resolver_if ops
;
16 resolve_answer_fn
*answer
;
20 static bool_t
resolve_request(void *sst
, string_t name
,
21 resolve_answer_fn
*cb
, void *cst
)
27 q
=safe_malloc(sizeof *q
,"resolve_request");
31 rv
=adns_submit(st
->ast
, name
, adns_r_a
, 0, q
, &q
->query
);
36 static int resolver_beforepoll(void *sst
, struct pollfd
*fds
, int *nfds_io
,
37 int *timeout_io
, const struct timeval
*tv_now
,
41 return adns_beforepoll(st
->ast
, fds
, nfds_io
, timeout_io
, tv_now
);
44 static void resolver_afterpoll(void *sst
, struct pollfd
*fds
, int nfds
,
45 const struct timeval
*tv_now
, uint64_t *now
)
54 adns_afterpoll(st
->ast
, fds
, nfds
, tv_now
);
58 rv
=adns_check(st
->ast
, &aq
, &ans
, &qp
);
61 if (ans
->status
!=adns_s_ok
) {
62 q
->answer(q
->cst
,NULL
); /* Failure */
66 q
->answer(q
->cst
,ans
->rrs
.inaddr
);
70 } else if (rv
==EAGAIN
|| rv
==ESRCH
) {
73 fatal("resolver_afterpoll: adns_check() returned %d\n",rv
);
80 /* Initialise adns, using parameters supplied */
81 static list_t
*adnsresolver_apply(closure_t
*self
, struct cloc loc
,
82 dict_t
*context
, list_t
*args
)
89 st
=safe_malloc(sizeof(*st
),"adnsresolver_apply");
90 st
->cl
.description
="adns";
91 st
->cl
.type
=CL_RESOLVER
;
93 st
->cl
.interface
=&st
->ops
;
96 st
->ops
.request
=resolve_request
;
99 if (!i
|| i
->type
!=t_dict
) {
100 cfgfatal(st
->loc
,"adns","first argument must be a dictionary\n");
103 conf
=dict_read_string(d
,"config",False
,"adns",loc
);
106 if (adns_init_strcfg(&st
->ast
, 0, 0, conf
)) {
107 fatal_perror("Failed to initialise ADNS");
110 if (adns_init(&st
->ast
, 0, 0)) {
111 fatal_perror("Failed to initialise ADNS");
115 register_for_poll(st
, resolver_beforepoll
, resolver_afterpoll
,
116 ADNS_POLLFDS_RECOMMENDED
+5,"resolver");
118 return new_closure(&st
->cl
);
121 init_module resolver_module
;
122 void resolver_module(dict_t
*dict
)
124 add_closure(dict
,"adns",adnsresolver_apply
);