fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
dnsresolv.h
Go to the documentation of this file.
1#ifndef DNSRESOLV_H
2#define DNSRESOLV_H
3
4/*
5 * Revision 20230613, Erwin Hoffmann
6 * - DNS_NXD (return code 0) for NXDOMAIN and NODATA added
7 * - DNS_SOFT as shortcut for DNS_ERR or DNS_COM
8 * - DNS_HARD indicates DNS loop problems
9 * Revision 20221101, Erwin Hoffmann
10 * - DNS_COM has now return code -3 (as documented; tx. Franz S.)
11 * Revision 20210922, Erwin Hoffmann
12 * - Added constants MAXMSGSIZE and MAXSEGMENT - not used yet
13 * Revision 20210401, Erwin Hoffmann
14 * - removed obsolete dns_sortip(); not going to work with GCC-10 anyway
15 * Revision 20200719, Erwin Hoffmann
16 * - added dns_qualify_localhost function including fqdn retrun
17 * Revision 20190730, Erwin Hoffmann
18 * - revised DNS_* return codes to make them compliant with ucspi-*
19 * Revision 20190430, Erwin Hoffmann
20 * - added DNS_SOFT/HARD/MEM complient to s/qmail
21 * - code changes in all decendent modules
22 * Revision 20180222, Erwin Hoffmann
23 * - we consider in total 32 NS IPs (IPv4 + IPv6)
24 * - added dns_transmit_start6
25 * - added uint32 scope_ids[32],
26 * the initial NS scopes read from /etc/resolv.conf et al.
27 * Revision 20180118, Erwin Hoffmann
28 * - included MSGSIZE for DNS messages (instead of MTUSIZE)
29 * Revision 20171231, Erwin Hoffmann
30 * - renamed to dnsresolv.h and removed *qmail declarations
31 * Revision 20170902, Erwin Hoffmann
32 * - added old definitions from *qmail for (temp) backwards compatibility
33 * - added more DNS RR definitions
34*/
35
36#include "stralloc.h"
37#include "iopause.h"
38#include "taia.h"
39
40/* Note: The conventions are subject of change in forthcoming versions */
41
42#define DNS_NXD 0 /* NXDOMAIN, NODATA */
43#define DNS_MEM -1 /* out of memory; fatal */
44#define DNS_ERR -2 /* parsing errors and others */
45#define DNS_COM -3 /* (socket) communication errors: SERVFAIL */
46#define DNS_INT -4 /* internal errors */
47#define DNS_SOFT -5 /* DNS_ERR or DNS_COM */
48#define DNS_HARD -6 /* DNS loop problem */
49
50#define MSGSIZE MTUSIZE /* todays default */
51// #define MSGSIZE 512 /* RFC 1035 */
52#define MAXMSGSIZE 4096 /* 4069 seen with EDNS0 */
53#define MAXSEGMENT 65535 /* Max TCP buffer size */
54
55#define QUERY_MAXNS 32 /* 16 IPv4 + 16 IPv6 NS */
56#define QUERY_MAXIPLEN 512 /* QUERY_MAXNS * 16 */
57
58/* Note: These following definitions are subject of change */
59
60#define DNS_C_IN "\0\1"
61#define DNS_C_ANY "\0\377"
62
63#define DNS_T_A "\0\1"
64#define DNS_T_NS "\0\2"
65#define DNS_T_CNAME "\0\5"
66#define DNS_T_SOA "\0\6"
67#define DNS_T_PTR "\0\14"
68#define DNS_T_HINFO "\0\15"
69#define DNS_T_MX "\0\17"
70#define DNS_T_TXT "\0\20"
71#define DNS_T_RP "\0\21"
72#define DNS_T_SIG "\0\30"
73#define DNS_T_KEY "\0\31"
74#define DNS_T_AAAA "\0\34"
75#define DNS_T_SRV "\0\41"
76#define DNS_T_NAPTR "\0\43"
77#define DNS_T_CERT "\0\45"
78#define DNS_T_OPT "\0\51"
79#define DNS_T_DS "\0\53"
80#define DNS_T_SSHFP "\0\54"
81#define DNS_T_IPSECKEY "\0\55"
82#define DNS_T_RRSIG "\0\56"
83#define DNS_T_NSEC "\0\57"
84#define DNS_T_DNSKEY "\0\60"
85#define DNS_T_NSEC3 "\0\62"
86#define DNS_T_NSEC3PARAM "\0\63"
87#define DNS_T_TLSA "\0\64"
88#define DNS_T_HIP "\0\67"
89#define DNS_T_OPENPGPKEY "\0\75"
90#define DNS_T_SPF "\0\143"
91#define DNS_T_AXFR "\0\374"
92#define DNS_T_ANY "\0\377"
93#define DNS_T_CAA "\1\1"
94
95#define LOCALHOST "localhost" /* no clear distinction IPv4/IPv6 */
96#define IP4_LOOPBACK "ip4-loopback"
97#define IP6_LOOPBACK "ip6-loopback"
98
100 char *query; /* 0, or dynamically allocated */
101 unsigned int querylen;
102 char *packet; /* 0, or dynamically allocated */
103 unsigned int packetlen;
104 int s1; /* 0, or 1 + an open file descriptor */
106 unsigned int udploop;
107 unsigned int curserver;
109 unsigned int pos;
110 const char *servers;
112 char localip[16];
113 char qtype[2];
114} ;
115
116/* General */
117
118extern void dns_random_init(const char *);
119extern unsigned int dns_random(unsigned int);
120
121extern void dns_domain_free(char **);
122extern int dns_domain_copy(char **,const char *);
123extern unsigned int dns_domain_length(const char *);
124extern int dns_domain_equal(const char *,const char *);
125extern int dns_domain_suffix(const char *,const char *);
126extern unsigned int dns_domain_suffixpos(const char *,const char *);
127extern int dns_domain_fromdot(char **,const char *,unsigned int);
128extern int dns_domain_todot_cat(stralloc *,const char *);
129extern int dns_ip_qualify(stralloc *,stralloc *,const stralloc *);
130extern int dns_ip_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
131extern int dns_ip_qualify_localhost(stralloc *,stralloc *,const stralloc *);
132
133extern unsigned int dns_packet_copy(const char *,unsigned int,unsigned int,char *,unsigned int);
134extern unsigned int dns_packet_getname(const char *,unsigned int,unsigned int,char **);
135extern unsigned int dns_packet_skipname(const char *,unsigned int,unsigned int);
136
137extern struct dns_transmit dns_resolve_tx;
138extern int dns_transmit_start(struct dns_transmit *,const char *,int,const char *,const char *,const char *);
139extern void dns_transmit_free(struct dns_transmit *);
140extern void dns_transmit_io(struct dns_transmit *,iopause_fd *,struct taia *);
141extern int dns_transmit_get(struct dns_transmit *,const iopause_fd *,const struct taia *);
142
143/* Common IPv4 + IPv6 */
144
145extern int dns_resolvconfip(char *,uint32 *);
146extern int dns_resolvconfrewrite(stralloc *);
147extern int dns_resolve(const char *,const char *);
148
149extern int dns_name(stralloc *,const char *);
150extern int dns_name_packet(stralloc *,const char *,unsigned int);
151extern int dns_txt_packet(stralloc *,const char *,unsigned int);
152extern int dns_txt(stralloc *,const stralloc *);
153extern int dns_mx_packet(stralloc *,const char *,unsigned int);
154extern int dns_mx(stralloc *,const stralloc *);
155
156/* IPv4 specific */
157
158extern int dns_ip4_packet(stralloc *,const char *,unsigned int);
159extern int dns_ip4(stralloc *,stralloc *);
160extern void dns_sortip4(char *,unsigned int);
161
162extern int dns_ip4_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
163extern int dns_ip4_qualify(stralloc *,stralloc *,const stralloc *);
164
165#define DNS_NAME4_DOMAIN 31
166extern int dns_name4_domain(char *,const char *);
167extern int dns_name4(stralloc *,const char *);
168extern int randombind4(struct dns_transmit *);
169
170/* IPv6 specific */
171
172extern int dns_ip6_packet(stralloc *,const char *,unsigned int);
173extern int dns_ip6(stralloc *,stralloc *);
174extern void dns_sortip6(char *,unsigned int);
175
176extern int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
177extern int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *);
178
179#define DNS_NAME6_DOMAIN (4*16+11)
180extern int dns_name6_domain(char *,const char *);
181extern int dns_name6(stralloc *,const char *);
182
183extern int dns_cname_packet(stralloc *,const char *,unsigned int);
184extern int dns_cname(stralloc *,stralloc *);
185
186extern int dns_transmit_start6(struct dns_transmit *,const char *,int,const char *,const char *,const char *,const uint32 *);
187extern int randombind6(struct dns_transmit *);
188
189/* General */
190
191extern void socketfree(struct dns_transmit *);
192extern void queryfree(struct dns_transmit *);
193extern void packetfree(struct dns_transmit *);
194extern int serverwantstcp(const char *,unsigned int);
195extern int serverfailed(const char *,unsigned int);
196extern int getscopeid(const struct dns_transmit *,const char *);
197extern int firstudp(struct dns_transmit *);
198extern int nextudp(struct dns_transmit *);
199extern int firsttcp(struct dns_transmit *);
200extern int nexttcp(struct dns_transmit *);
201
202#endif
uint32_t uint32
Definition: uint_t.h:40
void dns_transmit_free(struct dns_transmit *)
Definition: dns_transmit.c:105
int dns_name(stralloc *, const char *)
void dns_transmit_io(struct dns_transmit *, iopause_fd *, struct taia *)
Definition: dns_transmit.c:294
int dns_ip4_qualify_rules(stralloc *, stralloc *, const stralloc *, const stralloc *)
Definition: dns_ipq.c:46
void dns_sortip4(char *, unsigned int)
Definition: dns_sortip.c:17
int serverwantstcp(const char *, unsigned int)
Definition: dns_transmit.c:38
void socketfree(struct dns_transmit *)
Definition: dns_transmit.c:98
int randombind6(struct dns_transmit *)
Definition: dns_transmit.c:112
unsigned int dns_packet_copy(const char *, unsigned int, unsigned int, char *, unsigned int)
Definition: dns_packet.c:12
int serverfailed(const char *, unsigned int)
Definition: dns_transmit.c:48
int dns_ip4_packet(stralloc *, const char *, unsigned int)
Definition: dns_ip.c:16
int dns_ip4(stralloc *, stralloc *)
Definition: dns_ip.c:49
int dns_ip_qualify_rules(stralloc *, stralloc *, const stralloc *, const stralloc *)
Definition: dns_ipq.c:142
int dns_resolvconfip(char *, uint32 *)
void packetfree(struct dns_transmit *)
Definition: dns_transmit.c:84
int dns_cname(stralloc *, stralloc *)
Definition: dns_cname.c:47
int dns_domain_equal(const char *, const char *)
Definition: dns_domain.c:46
int dns_cname_packet(stralloc *, const char *, unsigned int)
Definition: dns_cname.c:16
int dns_name4(stralloc *, const char *)
unsigned int dns_random(unsigned int)
Definition: dns_random.c:59
int dns_domain_fromdot(char **, const char *, unsigned int)
Definition: dns_dfd.c:13
int dns_domain_todot_cat(stralloc *, const char *)
Definition: dns_dtda.c:11
int dns_ip_qualify(stralloc *, stralloc *, const stralloc *)
Definition: dns_ipq.c:227
int firstudp(struct dns_transmit *)
Definition: dns_transmit.c:184
int dns_resolve(const char *, const char *)
int dns_domain_copy(char **, const char *)
Definition: dns_domain.c:32
int nexttcp(struct dns_transmit *)
Definition: dns_transmit.c:249
void dns_sortip6(char *, unsigned int)
Definition: dns_sortip.c:32
int dns_domain_suffix(const char *, const char *)
Definition: dns_domain.c:57
int dns_name_packet(stralloc *, const char *, unsigned int)
Definition: dns_name.c:16
int firsttcp(struct dns_transmit *)
Definition: dns_transmit.c:243
int dns_ip4_qualify(stralloc *, stralloc *, const stralloc *)
Definition: dns_ipq.c:82
unsigned int dns_packet_skipname(const char *, unsigned int, unsigned int)
Definition: dns_packet.c:22
int dns_transmit_start(struct dns_transmit *, const char *, int, const char *, const char *, const char *)
int dns_name4_domain(char *, const char *)
void dns_domain_free(char **)
Definition: dns_domain.c:24
unsigned int dns_domain_length(const char *)
Definition: dns_domain.c:13
int dns_txt_packet(stralloc *, const char *, unsigned int)
Definition: dns_txt.c:13
int dns_ip6_qualify_rules(stralloc *, stralloc *, const stralloc *, const stralloc *)
Definition: dns_ipq.c:94
unsigned int dns_domain_suffixpos(const char *, const char *)
Definition: dns_domain.c:69
void queryfree(struct dns_transmit *)
Definition: dns_transmit.c:91
int dns_resolvconfrewrite(stralloc *)
Definition: dns_rcrw.c:122
int dns_ip6(stralloc *, stralloc *)
Definition: dns_ip.c:148
int dns_name6_domain(char *, const char *)
int dns_transmit_start6(struct dns_transmit *, const char *, int, const char *, const char *, const char *, const uint32 *)
int dns_mx_packet(stralloc *, const char *, unsigned int)
Definition: dns_mx.c:16
int dns_ip_qualify_localhost(stralloc *, stralloc *, const stralloc *)
Definition: dns_ipq.c:201
int dns_ip6_qualify(stralloc *, stralloc *, const stralloc *)
Definition: dns_ipq.c:130
unsigned int dns_packet_getname(const char *, unsigned int, unsigned int, char **)
Definition: dns_packet.c:39
int dns_mx(stralloc *, const stralloc *)
Definition: dns_mx.c:51
void dns_random_init(const char *)
int dns_txt(stralloc *, const stralloc *)
Definition: dns_txt.c:60
struct dns_transmit dns_resolve_tx
Definition: dns_resolve.c:14
int randombind4(struct dns_transmit *)
Definition: dns_transmit.c:126
int nextudp(struct dns_transmit *)
Definition: dns_transmit.c:190
int dns_ip6_packet(stralloc *, const char *, unsigned int)
Definition: dns_ip.c:108
int dns_name6(stralloc *, const char *)
int getscopeid(const struct dns_transmit *, const char *)
Definition: dns_transmit.c:26
int dns_transmit_get(struct dns_transmit *, const iopause_fd *, const struct taia *)
Definition: dns_transmit.c:311
uint32 scope_id
Definition: dnsresolv.h:111
unsigned int curserver
Definition: dnsresolv.h:107
char qtype[2]
Definition: dnsresolv.h:113
unsigned int udploop
Definition: dnsresolv.h:106
char localip[16]
Definition: dnsresolv.h:112
struct taia deadline
Definition: dnsresolv.h:108
const char * servers
Definition: dnsresolv.h:110
unsigned int packetlen
Definition: dnsresolv.h:103
unsigned int querylen
Definition: dnsresolv.h:101
char * packet
Definition: dnsresolv.h:102
unsigned int pos
Definition: dnsresolv.h:109
char * query
Definition: dnsresolv.h:100
Definition: taia.h:13