connectbyname.h
Go to the documentation of this file.
1 /*
2 connectbyname.h
3 
4 Interface for connectbyname
5 */
6 
47 #include <getdns/getdns.h>
48 #include <ldns/ldns.h>
49 
50 enum cbn_status
51 {
52  CBN_OK,
53  CBN_BAD_PORT,
54  CBN_BAD_PORT_NAME,
55  CBN_GETDNS_ERROR,
56  CBN_GETDNS_REPSTATUS,
57  CBN_A_AAAA_TIMEOUT,
58  CBN_HOSTNAME_TOO_LONG,
59  CBN_ERROR_CALLBACK,
60  CBN_LDNS_ERROR,
61  CBN_LDNS_RESULT,
62  CBN_SSL_ERROR,
63  CBN_TLSA_MISMATCH,
64  CBN_DANE_TIMEOUT,
65  CBN_PKIX_DID_NOT_VALIDATE
66 };
67 
68 struct cbn_error
69 {
70  enum cbn_status status;
71  const char *msg;
72  const char *file;
73  int line;
74  const char *func;
75  union
76  {
77  getdns_callback_type_t callback_type;
78  getdns_return_t getdns_result;
79  int getdns_repstatus;
80  ldns_status ldns_status;
81  } u;
82 };
83 
84 #define SET_ERROR_GENERIC(errp, error_status) \
85  (errp)->status= error_status, \
86  (errp)->file= __FILE__, \
87  (errp)->line= __LINE__, \
88  (errp)->func= __func__
89 #define SET_ERROR_CALLBACK(errp, callback_type) \
90  SET_ERROR_GENERIC(errp, CBN_ERROR_CALLBACK), \
91  (errp)->u.callback_type= callback_type
92 #define SET_ERROR_GETDNS(errp, msgstr, r) \
93  SET_ERROR_GENERIC(errp, CBN_GETDNS_ERROR), \
94  (errp)->msg= msgstr, \
95  (errp)->u.getdns_result= r
96 #define SET_ERROR_GETDNS_REPSTATUS(errp, msgstr, r) \
97  SET_ERROR_GENERIC(errp, CBN_GETDNS_REPSTATUS), \
98  (errp)->msg= msgstr, \
99  (errp)->u.getdns_repstatus= r
100 #define SET_ERROR_A_AAAA_TIMEOUT(errp) \
101  SET_ERROR_GENERIC(errp, CBN_A_AAAA_TIMEOUT)
102 #define SET_ERROR_LDNS(errp, msgstr) \
103  SET_ERROR_GENERIC(errp, CBN_LDNS_ERROR), \
104  (errp)->msg= msgstr
105 #define SET_ERROR_LDNS_RESULT(errp, msgstr, r) \
106  SET_ERROR_GENERIC(errp, CBN_LDNS_RESULT), \
107  (errp)->msg= msgstr, \
108  (errp)->u.ldns_status= r
109 #define SET_ERROR_SSL(errp, msgstr) \
110  SET_ERROR_GENERIC(errp, CBN_SSL_ERROR), \
111  (errp)->msg= msgstr
112 #define SET_ERROR_TLSA_MISMATCH(errp) \
113  SET_ERROR_GENERIC(errp, CBN_TLSA_MISMATCH)
114 #define SET_ERROR_DANE_TIMEOUT(errp) \
115  SET_ERROR_GENERIC(errp, CBN_DANE_TIMEOUT)
116 #define SET_ERROR_PKIX_DID_NOT_VALIDATE(errp) \
117  SET_ERROR_GENERIC(errp, CBN_PKIX_DID_NOT_VALIDATE)
118 
119 struct bufferevent;
120 typedef void (*cbn_callback_T)(struct bufferevent *bev, void *ref);
121 typedef void (*cbn_callback_error_T)(struct cbn_error *error, void *ref);
122 
123 #define CBNPR_MAX_ADDRS 3
124 
125 /* Policy for connecting upstream resolver */
127 {
128  unsigned int settings;
129  char *domain_name;
130  int naddrs;
131  struct sockaddr_storage addrs[CBNPR_MAX_ADDRS];
132  char *svcparams;
133  char *interface;
134 };
135 
136 #define CBN_UNENCRYPTED (1 << 0)
137 #define CBN_UNAUTHENTICATED_ENCRYPTION (1 << 1)
138 #define CBN_AUTHENTICATED_ENCRYPTION (1 << 2)
139 #define CBN_PKIX_AUTH_REQUIRED (1 << 3)
140 #define CBN_DANE_AUTH_REQUIRED (1 << 4)
141 #define CBN_DEFAULT_DISALLOW_OTHER_TRANSPORTS (1 << 5)
142 #define CBN_ALLOW_DO53 (1 << 8)
143 #define CBN_DISALLOW_DO53 (1 << 9)
144 #define CBN_ALLOW_DOT (1 << 10)
145 #define CBN_DISALLOW_DOT (1 << 11)
146 #define CBN_ALLOW_DOH2 (1 << 12)
147 #define CBN_DISALLOW_DOH2 (1 << 13)
148 #define CBN_ALLOW_DOH3 (1 << 14)
149 #define CBN_DISALLOW_DOH3 (1 << 15)
150 #define CBN_ALLOW_DOQ (1 << 16)
151 #define CBN_DISALLOW_DOQ (1 << 17)
152 
153 #define MAX_RESOLVERS 10
154 
156 {
157  int resolver_count;
158  struct cbnp_resolver resolver[MAX_RESOLVERS];
159 };
160 
162 {
163  struct event_base *event_base;
164  getdns_context *getdns_ctx;
165  struct cbn_policy policy;
166 };
167 
180  struct cbn_policy *policy, const char *name, unsigned int settings);
181 
190 static inline
191 struct cbn_policy *cbn_policy_init(struct cbn_policy *policy)
192 { return cbn_policy_init2(policy, NULL, 0); }
193 
200 static inline struct cbn_policy *cbn_policy_new()
201 { return cbn_policy_init2(NULL, NULL, 0); }
202 
209 int cbn_policy_add_resolver(struct cbn_policy *policy,
210  struct cbnp_resolver *resolver);
211 
218 int cbn_init(struct cbn_context *cbn_ctx, struct event_base *event_base);
219 
229 int cbn_init2(struct cbn_context *cbn_ctx, struct cbn_policy *policy,
230  char *name, int flags, struct event_base *event_base);
236 void cbn_clean(struct cbn_context *cbn_ctx);
237 
246 int connectbyname(struct cbn_context *cbn_ctx,
247  const char *hostname, const char *servname, int *fdp);
248 
260 int connectbyname_asyn(struct cbn_context *cbn_ctx,
261  const char *hostname, const char *servname,
262  cbn_callback_T user_cb, cbn_callback_error_T error_cb,
263  void *user_ref, void **refp);
264 
270 void connectbyname_free(void *ref);
int cbn_policy_add_resolver(struct cbn_policy *policy, struct cbnp_resolver *resolver)
Definition: connectbyname.c:189
int cbn_init(struct cbn_context *cbn_ctx, struct event_base *event_base)
Definition: connectbyname.c:142
void connectbyname_free(void *ref)
Definition: connectbyname.c:352
int connectbyname_asyn(struct cbn_context *cbn_ctx, const char *hostname, const char *servname, cbn_callback_T user_cb, cbn_callback_error_T error_cb, void *user_ref, void **refp)
Definition: connectbyname.c:216
void cbn_clean(struct cbn_context *cbn_ctx)
Definition: connectbyname.c:176
int cbn_init2(struct cbn_context *cbn_ctx, struct cbn_policy *policy, char *name, int flags, struct event_base *event_base)
Definition: connectbyname.c:149
int connectbyname(struct cbn_context *cbn_ctx, const char *hostname, const char *servname, int *fdp)
struct cbn_policy * cbn_policy_init2(struct cbn_policy *policy, const char *name, unsigned int settings)
Definition: connectbyname.c:183
Definition: connectbyname.h:162
Definition: connectbyname.h:69
Definition: connectbyname.h:156
Definition: connectbyname.h:127