]>
jfr.im git - solanum.git/blob - ircd/dns.c
2 * dns.c: An interface to the resolver module in authd
3 * (based somewhat on ircd-ratbox dns.c)
5 * Copyright (C) 2005 Aaron Sethman <androsyn@ratbox.org>
6 * Copyright (C) 2005-2012 ircd-ratbox development team
7 * Copyright (C) 2016 William Pitcock <nenolod@dereferenced.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
26 #include <ratbox_lib.h>
28 #include <ircd_defs.h>
39 #define DNS_IDTABLE_SIZE 0x2000
41 #define DNS_HOST_IPV4 ((char)'4')
42 #define DNS_HOST_IPV6 ((char)'6')
43 #define DNS_REVERSE_IPV4 ((char)'R')
44 #define DNS_REVERSE_IPV6 ((char)'S')
46 static void submit_dns(uint16_t id
, char type
, const char *addr
);
54 static struct dnsreq querytable
[DNS_IDTABLE_SIZE
];
59 static uint16_t id
= 1;
63 if(++loopcnt
> DNS_IDTABLE_SIZE
)
65 if(id
< DNS_IDTABLE_SIZE
- 1 || id
== 0)
69 if(querytable
[id
].callback
== NULL
)
76 handle_dns_failure(uint16_t xid
)
80 req
= &querytable
[xid
];
81 if(req
->callback
== NULL
)
84 req
->callback("FAILED", 0, 0, req
->data
);
90 cancel_lookup(uint16_t xid
)
92 querytable
[xid
].callback
= NULL
;
93 querytable
[xid
].data
= NULL
;
97 lookup_hostname(const char *hostname
, int aftype
, DNSCB callback
, void *data
)
103 nid
= assign_dns_id();
104 if((nid
= assign_dns_id()) == 0)
107 req
= &querytable
[nid
];
109 req
->callback
= callback
;
113 if(aftype
== AF_INET6
)
119 submit_dns(nid
, aft
== 4 ? DNS_HOST_IPV4
: DNS_HOST_IPV6
, hostname
);
124 lookup_ip(const char *addr
, int aftype
, DNSCB callback
, void *data
)
131 if((nid
= assign_dns_id()) == 0)
134 req
= &querytable
[nid
];
136 req
->callback
= callback
;
140 if(aftype
== AF_INET6
)
146 submit_dns(nid
, aft
== 4 ? DNS_REVERSE_IPV4
: DNS_REVERSE_IPV6
, addr
);
151 dns_results_callback(const char *callid
, const char *status
, const char *type
, const char *results
)
157 long lnid
= strtol(callid
, NULL
, 16);
159 if(lnid
> DNS_IDTABLE_SIZE
|| lnid
== 0)
161 nid
= (uint16_t)lnid
;
162 req
= &querytable
[nid
];
164 aft
= *type
== '6' || *type
== 'S' ? 6 : 4;
165 if(req
->callback
== NULL
)
167 /* got cancelled..oh well */
178 req
->callback(results
, st
, aft
, req
->data
);
179 req
->callback
= NULL
;
184 report_dns_servers(struct Client
*source_p
)
188 RB_DLINK_FOREACH(ptr
, nameservers
.head
)
190 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "A %s", (char *)ptr
->data
);
196 submit_dns(uint16_t nid
, char type
, const char *addr
)
198 if(authd_helper
== NULL
)
200 handle_dns_failure(nid
);
203 rb_helper_write(authd_helper
, "D %x %c %s", nid
, type
, addr
);