1 /* Name resolution using adns */
6 #error secnet requires ADNS version 1.0 or above
13 struct resolver_if ops
;
20 resolve_answer_fn
*answer
;
24 static bool_t
resolve_request(void *sst
, string_t name
,
25 resolve_answer_fn
*cb
, void *cst
)
31 q
=safe_malloc(sizeof *q
,"resolve_request");
35 rv
=adns_submit(st
->ast
, name
, adns_r_a
, 0, q
, &q
->query
);
40 static int resolver_beforepoll(void *sst
, struct pollfd
*fds
, int *nfds_io
,
41 int *timeout_io
, const struct timeval
*tv_now
,
45 return adns_beforepoll(st
->ast
, fds
, nfds_io
, timeout_io
, tv_now
);
48 static void resolver_afterpoll(void *sst
, struct pollfd
*fds
, int nfds
,
49 const struct timeval
*tv_now
, uint64_t *now
)
58 adns_afterpoll(st
->ast
, fds
, nfds
, tv_now
);
62 rv
=adns_check(st
->ast
, &aq
, &ans
, &qp
);
65 if (ans
->status
!=adns_s_ok
) {
66 q
->answer(q
->cst
,NULL
); /* Failure */
70 q
->answer(q
->cst
,ans
->rrs
.inaddr
);
74 } else if (rv
==EAGAIN
|| rv
==ESRCH
) {
77 fatal("resolver_afterpoll: adns_check() returned %d\n",rv
);
84 /* Initialise adns, using parameters supplied */
85 static list_t
*adnsresolver_apply(closure_t
*self
, struct cloc loc
,
86 dict_t
*context
, list_t
*args
)
93 st
=safe_malloc(sizeof(*st
),"adnsresolver_apply");
94 st
->cl
.description
="adns";
95 st
->cl
.type
=CL_RESOLVER
;
97 st
->cl
.interface
=&st
->ops
;
100 st
->ops
.request
=resolve_request
;
103 if (!i
|| i
->type
!=t_dict
) {
104 cfgfatal(st
->loc
,"adns","first argument must be a dictionary\n");
107 conf
=dict_read_string(d
,"config",False
,"adns",loc
);
110 if (adns_init_strcfg(&st
->ast
, 0, 0, conf
)) {
111 fatal_perror("Failed to initialise ADNS");
114 if (adns_init(&st
->ast
, 0, 0)) {
115 fatal_perror("Failed to initialise ADNS");
119 register_for_poll(st
, resolver_beforepoll
, resolver_afterpoll
,
120 ADNS_POLLFDS_RECOMMENDED
+5,"resolver");
122 return new_closure(&st
->cl
);
125 init_module resolver_module
;
126 void resolver_module(dict_t
*dict
)
128 add_closure(dict
,"adns",adnsresolver_apply
);