diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/dns | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/dns')
-rw-r--r-- | src/dns/dns.h | 9 | ||||
-rw-r--r-- | src/dns/dns_api.c | 220 | ||||
-rw-r--r-- | src/dns/gnunet-dns-monitor.c | 348 | ||||
-rw-r--r-- | src/dns/gnunet-dns-redirector.c | 227 | ||||
-rw-r--r-- | src/dns/gnunet-helper-dns.c | 1373 | ||||
-rw-r--r-- | src/dns/gnunet-service-dns.c | 1192 | ||||
-rw-r--r-- | src/dns/gnunet-zonewalk.c | 575 | ||||
-rw-r--r-- | src/dns/plugin_block_dns.c | 193 |
8 files changed, 2077 insertions, 2060 deletions
diff --git a/src/dns/dns.h b/src/dns/dns.h index 12d8f6025..515012079 100644 --- a/src/dns/dns.h +++ b/src/dns/dns.h | |||
@@ -32,7 +32,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
32 | /** | 32 | /** |
33 | * Message from client to DNS service to register itself. | 33 | * Message from client to DNS service to register itself. |
34 | */ | 34 | */ |
35 | struct GNUNET_DNS_Register { | 35 | struct GNUNET_DNS_Register |
36 | { | ||
36 | /** | 37 | /** |
37 | * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT | 38 | * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT |
38 | */ | 39 | */ |
@@ -48,7 +49,8 @@ struct GNUNET_DNS_Register { | |||
48 | /** | 49 | /** |
49 | * Message from DNS service to client: please handle a request. | 50 | * Message from DNS service to client: please handle a request. |
50 | */ | 51 | */ |
51 | struct GNUNET_DNS_Request { | 52 | struct GNUNET_DNS_Request |
53 | { | ||
52 | /** | 54 | /** |
53 | * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST | 55 | * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST |
54 | */ | 56 | */ |
@@ -71,7 +73,8 @@ struct GNUNET_DNS_Request { | |||
71 | /** | 73 | /** |
72 | * Message from client to DNS service: here is my reply. | 74 | * Message from client to DNS service: here is my reply. |
73 | */ | 75 | */ |
74 | struct GNUNET_DNS_Response { | 76 | struct GNUNET_DNS_Response |
77 | { | ||
75 | /** | 78 | /** |
76 | * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE | 79 | * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE |
77 | */ | 80 | */ |
diff --git a/src/dns/dns_api.c b/src/dns/dns_api.c index 4dc8e00dd..cd208d820 100644 --- a/src/dns/dns_api.c +++ b/src/dns/dns_api.c | |||
@@ -31,7 +31,8 @@ | |||
31 | /** | 31 | /** |
32 | * Handle to identify an individual DNS request. | 32 | * Handle to identify an individual DNS request. |
33 | */ | 33 | */ |
34 | struct GNUNET_DNS_RequestHandle { | 34 | struct GNUNET_DNS_RequestHandle |
35 | { | ||
35 | /** | 36 | /** |
36 | * Handle to DNS API. | 37 | * Handle to DNS API. |
37 | */ | 38 | */ |
@@ -52,7 +53,8 @@ struct GNUNET_DNS_RequestHandle { | |||
52 | /** | 53 | /** |
53 | * DNS handle | 54 | * DNS handle |
54 | */ | 55 | */ |
55 | struct GNUNET_DNS_Handle { | 56 | struct GNUNET_DNS_Handle |
57 | { | ||
56 | /** | 58 | /** |
57 | * Connection to DNS service, or NULL. | 59 | * Connection to DNS service, or NULL. |
58 | */ | 60 | */ |
@@ -103,7 +105,7 @@ struct GNUNET_DNS_Handle { | |||
103 | * @param tc scheduler context (unused) | 105 | * @param tc scheduler context (unused) |
104 | */ | 106 | */ |
105 | static void | 107 | static void |
106 | reconnect(void *cls); | 108 | reconnect (void *cls); |
107 | 109 | ||
108 | 110 | ||
109 | /** | 111 | /** |
@@ -112,17 +114,17 @@ reconnect(void *cls); | |||
112 | * @param dh handle with the connection | 114 | * @param dh handle with the connection |
113 | */ | 115 | */ |
114 | static void | 116 | static void |
115 | force_reconnect(struct GNUNET_DNS_Handle *dh) | 117 | force_reconnect (struct GNUNET_DNS_Handle *dh) |
116 | { | 118 | { |
117 | if (NULL != dh->mq) | 119 | if (NULL != dh->mq) |
118 | { | 120 | { |
119 | GNUNET_MQ_destroy(dh->mq); | 121 | GNUNET_MQ_destroy (dh->mq); |
120 | dh->mq = NULL; | 122 | dh->mq = NULL; |
121 | } | 123 | } |
122 | dh->reconnect_task = | 124 | dh->reconnect_task = |
123 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | 125 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
124 | &reconnect, | 126 | &reconnect, |
125 | dh); | 127 | dh); |
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
@@ -135,12 +137,12 @@ force_reconnect(struct GNUNET_DNS_Handle *dh) | |||
135 | * @param error error code | 137 | * @param error error code |
136 | */ | 138 | */ |
137 | static void | 139 | static void |
138 | mq_error_handler(void *cls, | 140 | mq_error_handler (void *cls, |
139 | enum GNUNET_MQ_Error error) | 141 | enum GNUNET_MQ_Error error) |
140 | { | 142 | { |
141 | struct GNUNET_DNS_Handle *dh = cls; | 143 | struct GNUNET_DNS_Handle *dh = cls; |
142 | 144 | ||
143 | force_reconnect(dh); | 145 | force_reconnect (dh); |
144 | } | 146 | } |
145 | 147 | ||
146 | 148 | ||
@@ -153,14 +155,14 @@ mq_error_handler(void *cls, | |||
153 | * @param req message from the service (request) | 155 | * @param req message from the service (request) |
154 | */ | 156 | */ |
155 | static int | 157 | static int |
156 | check_request(void *cls, | 158 | check_request (void *cls, |
157 | const struct GNUNET_DNS_Request *req) | 159 | const struct GNUNET_DNS_Request *req) |
158 | { | 160 | { |
159 | if (0 != ntohl(req->reserved)) | 161 | if (0 != ntohl (req->reserved)) |
160 | { | 162 | { |
161 | GNUNET_break(0); | 163 | GNUNET_break (0); |
162 | return GNUNET_SYSERR; | 164 | return GNUNET_SYSERR; |
163 | } | 165 | } |
164 | return GNUNET_OK; | 166 | return GNUNET_OK; |
165 | } | 167 | } |
166 | 168 | ||
@@ -173,22 +175,22 @@ check_request(void *cls, | |||
173 | * @param msg message from the service (request) | 175 | * @param msg message from the service (request) |
174 | */ | 176 | */ |
175 | static void | 177 | static void |
176 | handle_request(void *cls, | 178 | handle_request (void *cls, |
177 | const struct GNUNET_DNS_Request *req) | 179 | const struct GNUNET_DNS_Request *req) |
178 | { | 180 | { |
179 | struct GNUNET_DNS_Handle *dh = cls; | 181 | struct GNUNET_DNS_Handle *dh = cls; |
180 | size_t payload_length = ntohs(req->header.size) - sizeof(*req); | 182 | size_t payload_length = ntohs (req->header.size) - sizeof(*req); |
181 | struct GNUNET_DNS_RequestHandle *rh; | 183 | struct GNUNET_DNS_RequestHandle *rh; |
182 | 184 | ||
183 | rh = GNUNET_new(struct GNUNET_DNS_RequestHandle); | 185 | rh = GNUNET_new (struct GNUNET_DNS_RequestHandle); |
184 | rh->dh = dh; | 186 | rh->dh = dh; |
185 | rh->request_id = req->request_id; | 187 | rh->request_id = req->request_id; |
186 | rh->generation = dh->generation; | 188 | rh->generation = dh->generation; |
187 | dh->pending_requests++; | 189 | dh->pending_requests++; |
188 | dh->rh(dh->rh_cls, | 190 | dh->rh (dh->rh_cls, |
189 | rh, | 191 | rh, |
190 | payload_length, | 192 | payload_length, |
191 | (const char*)&req[1]); | 193 | (const char*) &req[1]); |
192 | } | 194 | } |
193 | 195 | ||
194 | 196 | ||
@@ -198,33 +200,33 @@ handle_request(void *cls, | |||
198 | * @param cls handle with the connection to connect | 200 | * @param cls handle with the connection to connect |
199 | */ | 201 | */ |
200 | static void | 202 | static void |
201 | reconnect(void *cls) | 203 | reconnect (void *cls) |
202 | { | 204 | { |
203 | struct GNUNET_DNS_Handle *dh = cls; | 205 | struct GNUNET_DNS_Handle *dh = cls; |
204 | struct GNUNET_MQ_MessageHandler handlers[] = { | 206 | struct GNUNET_MQ_MessageHandler handlers[] = { |
205 | GNUNET_MQ_hd_var_size(request, | 207 | GNUNET_MQ_hd_var_size (request, |
206 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST, | 208 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST, |
207 | struct GNUNET_DNS_Request, | 209 | struct GNUNET_DNS_Request, |
208 | dh), | 210 | dh), |
209 | GNUNET_MQ_handler_end() | 211 | GNUNET_MQ_handler_end () |
210 | }; | 212 | }; |
211 | struct GNUNET_MQ_Envelope *env; | 213 | struct GNUNET_MQ_Envelope *env; |
212 | struct GNUNET_DNS_Register *msg; | 214 | struct GNUNET_DNS_Register *msg; |
213 | 215 | ||
214 | dh->reconnect_task = NULL; | 216 | dh->reconnect_task = NULL; |
215 | dh->mq = GNUNET_CLIENT_connect(dh->cfg, | 217 | dh->mq = GNUNET_CLIENT_connect (dh->cfg, |
216 | "dns", | 218 | "dns", |
217 | handlers, | 219 | handlers, |
218 | &mq_error_handler, | 220 | &mq_error_handler, |
219 | dh); | 221 | dh); |
220 | if (NULL == dh->mq) | 222 | if (NULL == dh->mq) |
221 | return; | 223 | return; |
222 | dh->generation++; | 224 | dh->generation++; |
223 | env = GNUNET_MQ_msg(msg, | 225 | env = GNUNET_MQ_msg (msg, |
224 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT); | 226 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT); |
225 | msg->flags = htonl(dh->flags); | 227 | msg->flags = htonl (dh->flags); |
226 | GNUNET_MQ_send(dh->mq, | 228 | GNUNET_MQ_send (dh->mq, |
227 | env); | 229 | env); |
228 | } | 230 | } |
229 | 231 | ||
230 | 232 | ||
@@ -239,24 +241,24 @@ reconnect(void *cls) | |||
239 | * @param rh request that should now be forwarded | 241 | * @param rh request that should now be forwarded |
240 | */ | 242 | */ |
241 | void | 243 | void |
242 | GNUNET_DNS_request_forward(struct GNUNET_DNS_RequestHandle *rh) | 244 | GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh) |
243 | { | 245 | { |
244 | struct GNUNET_MQ_Envelope *env; | 246 | struct GNUNET_MQ_Envelope *env; |
245 | struct GNUNET_DNS_Response *resp; | 247 | struct GNUNET_DNS_Response *resp; |
246 | 248 | ||
247 | GNUNET_assert(0 < rh->dh->pending_requests--); | 249 | GNUNET_assert (0 < rh->dh->pending_requests--); |
248 | if (rh->generation != rh->dh->generation) | 250 | if (rh->generation != rh->dh->generation) |
249 | { | 251 | { |
250 | GNUNET_free(rh); | 252 | GNUNET_free (rh); |
251 | return; | 253 | return; |
252 | } | 254 | } |
253 | env = GNUNET_MQ_msg(resp, | 255 | env = GNUNET_MQ_msg (resp, |
254 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); | 256 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); |
255 | resp->drop_flag = htonl(1); | 257 | resp->drop_flag = htonl (1); |
256 | resp->request_id = rh->request_id; | 258 | resp->request_id = rh->request_id; |
257 | GNUNET_MQ_send(rh->dh->mq, | 259 | GNUNET_MQ_send (rh->dh->mq, |
258 | env); | 260 | env); |
259 | GNUNET_free(rh); | 261 | GNUNET_free (rh); |
260 | } | 262 | } |
261 | 263 | ||
262 | 264 | ||
@@ -267,24 +269,24 @@ GNUNET_DNS_request_forward(struct GNUNET_DNS_RequestHandle *rh) | |||
267 | * @param rh request that should now be dropped | 269 | * @param rh request that should now be dropped |
268 | */ | 270 | */ |
269 | void | 271 | void |
270 | GNUNET_DNS_request_drop(struct GNUNET_DNS_RequestHandle *rh) | 272 | GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh) |
271 | { | 273 | { |
272 | struct GNUNET_MQ_Envelope *env; | 274 | struct GNUNET_MQ_Envelope *env; |
273 | struct GNUNET_DNS_Response *resp; | 275 | struct GNUNET_DNS_Response *resp; |
274 | 276 | ||
275 | GNUNET_assert(0 < rh->dh->pending_requests--); | 277 | GNUNET_assert (0 < rh->dh->pending_requests--); |
276 | if (rh->generation != rh->dh->generation) | 278 | if (rh->generation != rh->dh->generation) |
277 | { | 279 | { |
278 | GNUNET_free(rh); | 280 | GNUNET_free (rh); |
279 | return; | 281 | return; |
280 | } | 282 | } |
281 | env = GNUNET_MQ_msg(resp, | 283 | env = GNUNET_MQ_msg (resp, |
282 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); | 284 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); |
283 | resp->request_id = rh->request_id; | 285 | resp->request_id = rh->request_id; |
284 | resp->drop_flag = htonl(0); | 286 | resp->drop_flag = htonl (0); |
285 | GNUNET_MQ_send(rh->dh->mq, | 287 | GNUNET_MQ_send (rh->dh->mq, |
286 | env); | 288 | env); |
287 | GNUNET_free(rh); | 289 | GNUNET_free (rh); |
288 | } | 290 | } |
289 | 291 | ||
290 | 292 | ||
@@ -298,37 +300,37 @@ GNUNET_DNS_request_drop(struct GNUNET_DNS_RequestHandle *rh) | |||
298 | * @param reply reply data | 300 | * @param reply reply data |
299 | */ | 301 | */ |
300 | void | 302 | void |
301 | GNUNET_DNS_request_answer(struct GNUNET_DNS_RequestHandle *rh, | 303 | GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, |
302 | uint16_t reply_length, | 304 | uint16_t reply_length, |
303 | const char *reply) | 305 | const char *reply) |
304 | { | 306 | { |
305 | struct GNUNET_MQ_Envelope *env; | 307 | struct GNUNET_MQ_Envelope *env; |
306 | struct GNUNET_DNS_Response *resp; | 308 | struct GNUNET_DNS_Response *resp; |
307 | 309 | ||
308 | GNUNET_assert(0 < rh->dh->pending_requests--); | 310 | GNUNET_assert (0 < rh->dh->pending_requests--); |
309 | if (rh->generation != rh->dh->generation) | 311 | if (rh->generation != rh->dh->generation) |
310 | { | 312 | { |
311 | GNUNET_free(rh); | 313 | GNUNET_free (rh); |
312 | return; | 314 | return; |
313 | } | 315 | } |
314 | if (reply_length + sizeof(struct GNUNET_DNS_Response) | 316 | if (reply_length + sizeof(struct GNUNET_DNS_Response) |
315 | >= GNUNET_MAX_MESSAGE_SIZE) | 317 | >= GNUNET_MAX_MESSAGE_SIZE) |
316 | { | 318 | { |
317 | GNUNET_break(0); | 319 | GNUNET_break (0); |
318 | GNUNET_free(rh); | 320 | GNUNET_free (rh); |
319 | return; | 321 | return; |
320 | } | 322 | } |
321 | env = GNUNET_MQ_msg_extra(resp, | 323 | env = GNUNET_MQ_msg_extra (resp, |
322 | reply_length, | 324 | reply_length, |
323 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); | 325 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); |
324 | resp->drop_flag = htonl(2); | 326 | resp->drop_flag = htonl (2); |
325 | resp->request_id = rh->request_id; | 327 | resp->request_id = rh->request_id; |
326 | GNUNET_memcpy(&resp[1], | 328 | GNUNET_memcpy (&resp[1], |
327 | reply, | 329 | reply, |
328 | reply_length); | 330 | reply_length); |
329 | GNUNET_MQ_send(rh->dh->mq, | 331 | GNUNET_MQ_send (rh->dh->mq, |
330 | env); | 332 | env); |
331 | GNUNET_free(rh); | 333 | GNUNET_free (rh); |
332 | } | 334 | } |
333 | 335 | ||
334 | 336 | ||
@@ -342,19 +344,19 @@ GNUNET_DNS_request_answer(struct GNUNET_DNS_RequestHandle *rh, | |||
342 | * @return DNS handle | 344 | * @return DNS handle |
343 | */ | 345 | */ |
344 | struct GNUNET_DNS_Handle * | 346 | struct GNUNET_DNS_Handle * |
345 | GNUNET_DNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | 347 | GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
346 | enum GNUNET_DNS_Flags flags, | 348 | enum GNUNET_DNS_Flags flags, |
347 | GNUNET_DNS_RequestHandler rh, | 349 | GNUNET_DNS_RequestHandler rh, |
348 | void *rh_cls) | 350 | void *rh_cls) |
349 | { | 351 | { |
350 | struct GNUNET_DNS_Handle *dh; | 352 | struct GNUNET_DNS_Handle *dh; |
351 | 353 | ||
352 | dh = GNUNET_new(struct GNUNET_DNS_Handle); | 354 | dh = GNUNET_new (struct GNUNET_DNS_Handle); |
353 | dh->cfg = cfg; | 355 | dh->cfg = cfg; |
354 | dh->flags = flags; | 356 | dh->flags = flags; |
355 | dh->rh = rh; | 357 | dh->rh = rh; |
356 | dh->rh_cls = rh_cls; | 358 | dh->rh_cls = rh_cls; |
357 | dh->reconnect_task = GNUNET_SCHEDULER_add_now(&reconnect, dh); | 359 | dh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, dh); |
358 | return dh; | 360 | return dh; |
359 | } | 361 | } |
360 | 362 | ||
@@ -365,21 +367,21 @@ GNUNET_DNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
365 | * @param dh DNS handle | 367 | * @param dh DNS handle |
366 | */ | 368 | */ |
367 | void | 369 | void |
368 | GNUNET_DNS_disconnect(struct GNUNET_DNS_Handle *dh) | 370 | GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh) |
369 | { | 371 | { |
370 | if (NULL != dh->mq) | 372 | if (NULL != dh->mq) |
371 | { | 373 | { |
372 | GNUNET_MQ_destroy(dh->mq); | 374 | GNUNET_MQ_destroy (dh->mq); |
373 | dh->mq = NULL; | 375 | dh->mq = NULL; |
374 | } | 376 | } |
375 | if (NULL != dh->reconnect_task) | 377 | if (NULL != dh->reconnect_task) |
376 | { | 378 | { |
377 | GNUNET_SCHEDULER_cancel(dh->reconnect_task); | 379 | GNUNET_SCHEDULER_cancel (dh->reconnect_task); |
378 | dh->reconnect_task = NULL; | 380 | dh->reconnect_task = NULL; |
379 | } | 381 | } |
380 | /* make sure client has no pending requests left over! */ | 382 | /* make sure client has no pending requests left over! */ |
381 | GNUNET_break(0 == dh->pending_requests); | 383 | GNUNET_break (0 == dh->pending_requests); |
382 | GNUNET_free(dh); | 384 | GNUNET_free (dh); |
383 | } | 385 | } |
384 | 386 | ||
385 | /* end of dns_api.c */ | 387 | /* end of dns_api.c */ |
diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c index 819cb025d..311544f2e 100644 --- a/src/dns/gnunet-dns-monitor.c +++ b/src/dns/gnunet-dns-monitor.c | |||
@@ -62,31 +62,31 @@ static unsigned int verbosity; | |||
62 | * @return type as string, only valid until the next call to this function | 62 | * @return type as string, only valid until the next call to this function |
63 | */ | 63 | */ |
64 | static const char * | 64 | static const char * |
65 | get_type(uint16_t type) | 65 | get_type (uint16_t type) |
66 | { | 66 | { |
67 | static char buf[6]; | 67 | static char buf[6]; |
68 | 68 | ||
69 | switch (type) | 69 | switch (type) |
70 | { | 70 | { |
71 | case GNUNET_DNSPARSER_TYPE_A: return "A"; | 71 | case GNUNET_DNSPARSER_TYPE_A: return "A"; |
72 | 72 | ||
73 | case GNUNET_DNSPARSER_TYPE_NS: return "NS"; | 73 | case GNUNET_DNSPARSER_TYPE_NS: return "NS"; |
74 | 74 | ||
75 | case GNUNET_DNSPARSER_TYPE_CNAME: return "CNAME"; | 75 | case GNUNET_DNSPARSER_TYPE_CNAME: return "CNAME"; |
76 | 76 | ||
77 | case GNUNET_DNSPARSER_TYPE_SOA: return "SOA"; | 77 | case GNUNET_DNSPARSER_TYPE_SOA: return "SOA"; |
78 | 78 | ||
79 | case GNUNET_DNSPARSER_TYPE_PTR: return "PTR"; | 79 | case GNUNET_DNSPARSER_TYPE_PTR: return "PTR"; |
80 | 80 | ||
81 | case GNUNET_DNSPARSER_TYPE_MX: return "MX"; | 81 | case GNUNET_DNSPARSER_TYPE_MX: return "MX"; |
82 | 82 | ||
83 | case GNUNET_DNSPARSER_TYPE_TXT: return "TXT"; | 83 | case GNUNET_DNSPARSER_TYPE_TXT: return "TXT"; |
84 | 84 | ||
85 | case GNUNET_DNSPARSER_TYPE_AAAA: return "AAAA"; | 85 | case GNUNET_DNSPARSER_TYPE_AAAA: return "AAAA"; |
86 | 86 | ||
87 | case GNUNET_DNSPARSER_TYPE_SRV: return "SRV"; | 87 | case GNUNET_DNSPARSER_TYPE_SRV: return "SRV"; |
88 | } | 88 | } |
89 | GNUNET_snprintf(buf, sizeof(buf), "%u", (unsigned int)type); | 89 | GNUNET_snprintf (buf, sizeof(buf), "%u", (unsigned int) type); |
90 | return buf; | 90 | return buf; |
91 | } | 91 | } |
92 | 92 | ||
@@ -98,19 +98,19 @@ get_type(uint16_t type) | |||
98 | * @return class as string, only valid until the next call to this function | 98 | * @return class as string, only valid until the next call to this function |
99 | */ | 99 | */ |
100 | static const char * | 100 | static const char * |
101 | get_class(uint16_t class) | 101 | get_class (uint16_t class) |
102 | { | 102 | { |
103 | static char buf[6]; | 103 | static char buf[6]; |
104 | 104 | ||
105 | switch (class) | 105 | switch (class) |
106 | { | 106 | { |
107 | case GNUNET_TUN_DNS_CLASS_INTERNET: return "IN"; | 107 | case GNUNET_TUN_DNS_CLASS_INTERNET: return "IN"; |
108 | 108 | ||
109 | case GNUNET_TUN_DNS_CLASS_CHAOS: return "CHAOS"; | 109 | case GNUNET_TUN_DNS_CLASS_CHAOS: return "CHAOS"; |
110 | 110 | ||
111 | case GNUNET_TUN_DNS_CLASS_HESIOD: return "HESIOD"; | 111 | case GNUNET_TUN_DNS_CLASS_HESIOD: return "HESIOD"; |
112 | } | 112 | } |
113 | GNUNET_snprintf(buf, sizeof(buf), "%u", (unsigned int)class); | 113 | GNUNET_snprintf (buf, sizeof(buf), "%u", (unsigned int) class); |
114 | return buf; | 114 | return buf; |
115 | } | 115 | } |
116 | 116 | ||
@@ -121,13 +121,13 @@ get_class(uint16_t class) | |||
121 | * @param query query to display. | 121 | * @param query query to display. |
122 | */ | 122 | */ |
123 | static void | 123 | static void |
124 | display_query(const struct GNUNET_DNSPARSER_Query *query) | 124 | display_query (const struct GNUNET_DNSPARSER_Query *query) |
125 | { | 125 | { |
126 | fprintf(stdout, | 126 | fprintf (stdout, |
127 | "\t\t%s %s: %s\n", | 127 | "\t\t%s %s: %s\n", |
128 | get_class(query->dns_traffic_class), | 128 | get_class (query->dns_traffic_class), |
129 | get_type(query->type), | 129 | get_type (query->type), |
130 | query->name); | 130 | query->name); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
@@ -137,7 +137,7 @@ display_query(const struct GNUNET_DNSPARSER_Query *query) | |||
137 | * @param record record to display. | 137 | * @param record record to display. |
138 | */ | 138 | */ |
139 | static void | 139 | static void |
140 | display_record(const struct GNUNET_DNSPARSER_Record *record) | 140 | display_record (const struct GNUNET_DNSPARSER_Record *record) |
141 | { | 141 | { |
142 | const char *format; | 142 | const char *format; |
143 | char buf[INET6_ADDRSTRLEN]; | 143 | char buf[INET6_ADDRSTRLEN]; |
@@ -145,93 +145,95 @@ display_record(const struct GNUNET_DNSPARSER_Record *record) | |||
145 | 145 | ||
146 | tmp = NULL; | 146 | tmp = NULL; |
147 | switch (record->type) | 147 | switch (record->type) |
148 | { | ||
149 | case GNUNET_DNSPARSER_TYPE_A: | ||
150 | if (record->data.raw.data_len != sizeof(struct in_addr)) | ||
151 | format = "<invalid>"; | ||
152 | else | ||
153 | format = inet_ntop (AF_INET, record->data.raw.data, buf, sizeof(buf)); | ||
154 | break; | ||
155 | |||
156 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
157 | if (record->data.raw.data_len != sizeof(struct in6_addr)) | ||
158 | format = "<invalid>"; | ||
159 | else | ||
160 | format = inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof(buf)); | ||
161 | break; | ||
162 | |||
163 | case GNUNET_DNSPARSER_TYPE_NS: | ||
164 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
165 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
166 | format = record->data.hostname; | ||
167 | break; | ||
168 | |||
169 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
170 | if (NULL == record->data.soa) | ||
171 | format = "<invalid>"; | ||
172 | else | ||
173 | { | ||
174 | GNUNET_asprintf (&tmp, | ||
175 | "origin: %s, mail: %s, serial = %u, refresh = %u s, retry = %u s, expire = %u s, minimum = %u s", | ||
176 | record->data.soa->mname, | ||
177 | record->data.soa->rname, | ||
178 | (unsigned int) record->data.soa->serial, | ||
179 | (unsigned int) record->data.soa->refresh, | ||
180 | (unsigned int) record->data.soa->retry, | ||
181 | (unsigned int) record->data.soa->expire, | ||
182 | (unsigned int) record->data.soa->minimum_ttl); | ||
183 | format = tmp; | ||
184 | } | ||
185 | break; | ||
186 | |||
187 | case GNUNET_DNSPARSER_TYPE_MX: | ||
188 | if (record->data.mx == NULL) | ||
189 | format = "<invalid>"; | ||
190 | else | ||
148 | { | 191 | { |
149 | case GNUNET_DNSPARSER_TYPE_A: | 192 | GNUNET_asprintf (&tmp, |
150 | if (record->data.raw.data_len != sizeof(struct in_addr)) | 193 | "%u: %s", |
151 | format = "<invalid>"; | 194 | record->data.mx->preference, |
152 | else | 195 | record->data.mx->mxhost); |
153 | format = inet_ntop(AF_INET, record->data.raw.data, buf, sizeof(buf)); | ||
154 | break; | ||
155 | |||
156 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
157 | if (record->data.raw.data_len != sizeof(struct in6_addr)) | ||
158 | format = "<invalid>"; | ||
159 | else | ||
160 | format = inet_ntop(AF_INET6, record->data.raw.data, buf, sizeof(buf)); | ||
161 | break; | ||
162 | |||
163 | case GNUNET_DNSPARSER_TYPE_NS: | ||
164 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
165 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
166 | format = record->data.hostname; | ||
167 | break; | ||
168 | |||
169 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
170 | if (NULL == record->data.soa) | ||
171 | format = "<invalid>"; | ||
172 | else | ||
173 | { | ||
174 | GNUNET_asprintf(&tmp, | ||
175 | "origin: %s, mail: %s, serial = %u, refresh = %u s, retry = %u s, expire = %u s, minimum = %u s", | ||
176 | record->data.soa->mname, | ||
177 | record->data.soa->rname, | ||
178 | (unsigned int)record->data.soa->serial, | ||
179 | (unsigned int)record->data.soa->refresh, | ||
180 | (unsigned int)record->data.soa->retry, | ||
181 | (unsigned int)record->data.soa->expire, | ||
182 | (unsigned int)record->data.soa->minimum_ttl); | ||
183 | format = tmp; | ||
184 | } | ||
185 | break; | ||
186 | |||
187 | case GNUNET_DNSPARSER_TYPE_MX: | ||
188 | if (record->data.mx == NULL) | ||
189 | format = "<invalid>"; | ||
190 | else | ||
191 | { | ||
192 | GNUNET_asprintf(&tmp, | ||
193 | "%u: %s", | ||
194 | record->data.mx->preference, | ||
195 | record->data.mx->mxhost); | ||
196 | format = tmp; | ||
197 | } | ||
198 | break; | ||
199 | |||
200 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
201 | if (NULL == record->data.srv) | ||
202 | format = "<invalid>"; | ||
203 | else | ||
204 | { | ||
205 | GNUNET_asprintf(&tmp, | ||
206 | "priority %u, weight = %s, port = %u, target = %s", | ||
207 | (unsigned int)record->data.srv->priority, | ||
208 | (unsigned int)record->data.srv->weight, | ||
209 | (unsigned int)record->data.srv->port, | ||
210 | record->data.srv->target); | ||
211 | format = tmp; | ||
212 | } | ||
213 | break; | ||
214 | |||
215 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
216 | GNUNET_asprintf(&tmp, | ||
217 | "%.*s", | ||
218 | (unsigned int)record->data.raw.data_len, | ||
219 | record->data.raw.data); | ||
220 | format = tmp; | 196 | format = tmp; |
221 | break; | 197 | } |
198 | break; | ||
222 | 199 | ||
223 | default: | 200 | case GNUNET_DNSPARSER_TYPE_SRV: |
224 | format = "<payload>"; | 201 | if (NULL == record->data.srv) |
225 | break; | 202 | format = "<invalid>"; |
203 | else | ||
204 | { | ||
205 | GNUNET_asprintf (&tmp, | ||
206 | "priority %u, weight = %s, port = %u, target = %s", | ||
207 | (unsigned int) record->data.srv->priority, | ||
208 | (unsigned int) record->data.srv->weight, | ||
209 | (unsigned int) record->data.srv->port, | ||
210 | record->data.srv->target); | ||
211 | format = tmp; | ||
226 | } | 212 | } |
227 | fprintf(stdout, | 213 | break; |
228 | "\t\t%s %s: %s = %s (%u s)\n", | 214 | |
229 | get_class(record->dns_traffic_class), | 215 | case GNUNET_DNSPARSER_TYPE_TXT: |
230 | get_type(record->type), | 216 | GNUNET_asprintf (&tmp, |
231 | record->name, | 217 | "%.*s", |
232 | format, | 218 | (unsigned int) record->data.raw.data_len, |
233 | (unsigned int)(GNUNET_TIME_absolute_get_remaining(record->expiration_time).rel_value_us / 1000LL / 1000LL)); | 219 | record->data.raw.data); |
234 | GNUNET_free_non_null(tmp); | 220 | format = tmp; |
221 | break; | ||
222 | |||
223 | default: | ||
224 | format = "<payload>"; | ||
225 | break; | ||
226 | } | ||
227 | fprintf (stdout, | ||
228 | "\t\t%s %s: %s = %s (%u s)\n", | ||
229 | get_class (record->dns_traffic_class), | ||
230 | get_type (record->type), | ||
231 | record->name, | ||
232 | format, | ||
233 | (unsigned int) (GNUNET_TIME_absolute_get_remaining ( | ||
234 | record->expiration_time).rel_value_us / 1000LL | ||
235 | / 1000LL)); | ||
236 | GNUNET_free_non_null (tmp); | ||
235 | } | 237 | } |
236 | 238 | ||
237 | 239 | ||
@@ -259,20 +261,18 @@ display_record(const struct GNUNET_DNSPARSER_Record *record) | |||
259 | * @param request udp payload of the DNS request | 261 | * @param request udp payload of the DNS request |
260 | */ | 262 | */ |
261 | static void | 263 | static void |
262 | display_request(void *cls, | 264 | display_request (void *cls, |
263 | struct GNUNET_DNS_RequestHandle *rh, | 265 | struct GNUNET_DNS_RequestHandle *rh, |
264 | size_t request_length, | 266 | size_t request_length, |
265 | const char *request) | 267 | const char *request) |
266 | { | 268 | { |
267 | static const char *return_codes[] = | 269 | static const char *return_codes[] = { |
268 | { | ||
269 | "No error", "Format error", "Server failure", "Name error", | 270 | "No error", "Format error", "Server failure", "Name error", |
270 | "Not implemented", "Refused", "YXDomain", "YXRRset", | 271 | "Not implemented", "Refused", "YXDomain", "YXRRset", |
271 | "NXRRset", "NOT AUTH", "NOT ZONE", "<invalid>", | 272 | "NXRRset", "NOT AUTH", "NOT ZONE", "<invalid>", |
272 | "<invalid>", "<invalid>", "<invalid>", "<invalid>" | 273 | "<invalid>", "<invalid>", "<invalid>", "<invalid>" |
273 | }; | 274 | }; |
274 | static const char *op_codes[] = | 275 | static const char *op_codes[] = { |
275 | { | ||
276 | "Query", "Inverse query", "Status", "<invalid>", | 276 | "Query", "Inverse query", "Status", "<invalid>", |
277 | "<invalid>", "<invalid>", "<invalid>", "<invalid>", | 277 | "<invalid>", "<invalid>", "<invalid>", "<invalid>", |
278 | "<invalid>", "<invalid>", "<invalid>", "<invalid>", | 278 | "<invalid>", "<invalid>", "<invalid>", "<invalid>", |
@@ -281,40 +281,40 @@ display_request(void *cls, | |||
281 | struct GNUNET_DNSPARSER_Packet *p; | 281 | struct GNUNET_DNSPARSER_Packet *p; |
282 | unsigned int i; | 282 | unsigned int i; |
283 | 283 | ||
284 | p = GNUNET_DNSPARSER_parse(request, request_length); | 284 | p = GNUNET_DNSPARSER_parse (request, request_length); |
285 | if (NULL == p) | 285 | if (NULL == p) |
286 | { | 286 | { |
287 | fprintf(stderr, "Received malformed DNS packet!\n"); | 287 | fprintf (stderr, "Received malformed DNS packet!\n"); |
288 | // FIXME: drop instead? | 288 | // FIXME: drop instead? |
289 | GNUNET_DNS_request_forward(rh); | 289 | GNUNET_DNS_request_forward (rh); |
290 | return; | 290 | return; |
291 | } | 291 | } |
292 | fprintf(stdout, | 292 | fprintf (stdout, |
293 | "%s with ID: %5u Flags: %s%s%s%s%s%s, Return Code: %s, Opcode: %s\n", | 293 | "%s with ID: %5u Flags: %s%s%s%s%s%s, Return Code: %s, Opcode: %s\n", |
294 | p->flags.query_or_response ? "Response" : "Query", | 294 | p->flags.query_or_response ? "Response" : "Query", |
295 | p->id, | 295 | p->id, |
296 | p->flags.recursion_desired ? "RD " : "", | 296 | p->flags.recursion_desired ? "RD " : "", |
297 | p->flags.message_truncated ? "MT " : "", | 297 | p->flags.message_truncated ? "MT " : "", |
298 | p->flags.authoritative_answer ? "AA " : "", | 298 | p->flags.authoritative_answer ? "AA " : "", |
299 | p->flags.checking_disabled ? "CD " : "", | 299 | p->flags.checking_disabled ? "CD " : "", |
300 | p->flags.authenticated_data ? "AD " : "", | 300 | p->flags.authenticated_data ? "AD " : "", |
301 | p->flags.recursion_available ? "RA " : "", | 301 | p->flags.recursion_available ? "RA " : "", |
302 | return_codes[p->flags.return_code & 15], | 302 | return_codes[p->flags.return_code & 15], |
303 | op_codes[p->flags.opcode & 15]); | 303 | op_codes[p->flags.opcode & 15]); |
304 | if (p->num_queries > 0) | 304 | if (p->num_queries > 0) |
305 | fprintf(stdout, | 305 | fprintf (stdout, |
306 | "\tQueries:\n"); | 306 | "\tQueries:\n"); |
307 | for (i = 0; i < p->num_queries; i++) | 307 | for (i = 0; i < p->num_queries; i++) |
308 | display_query(&p->queries[i]); | 308 | display_query (&p->queries[i]); |
309 | 309 | ||
310 | if (p->num_answers > 0) | 310 | if (p->num_answers > 0) |
311 | fprintf(stdout, | 311 | fprintf (stdout, |
312 | "\tAnswers:\n"); | 312 | "\tAnswers:\n"); |
313 | for (i = 0; i < p->num_answers; i++) | 313 | for (i = 0; i < p->num_answers; i++) |
314 | display_record(&p->answers[i]); | 314 | display_record (&p->answers[i]); |
315 | fprintf(stdout, "\n"); | 315 | fprintf (stdout, "\n"); |
316 | GNUNET_DNSPARSER_free_packet(p); | 316 | GNUNET_DNSPARSER_free_packet (p); |
317 | GNUNET_DNS_request_forward(rh); | 317 | GNUNET_DNS_request_forward (rh); |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
@@ -322,13 +322,13 @@ display_request(void *cls, | |||
322 | * Shutdown. | 322 | * Shutdown. |
323 | */ | 323 | */ |
324 | static void | 324 | static void |
325 | do_disconnect(void *cls) | 325 | do_disconnect (void *cls) |
326 | { | 326 | { |
327 | if (NULL != handle) | 327 | if (NULL != handle) |
328 | { | 328 | { |
329 | GNUNET_DNS_disconnect(handle); | 329 | GNUNET_DNS_disconnect (handle); |
330 | handle = NULL; | 330 | handle = NULL; |
331 | } | 331 | } |
332 | } | 332 | } |
333 | 333 | ||
334 | 334 | ||
@@ -341,8 +341,8 @@ do_disconnect(void *cls) | |||
341 | * @param cfg configuration | 341 | * @param cfg configuration |
342 | */ | 342 | */ |
343 | static void | 343 | static void |
344 | run(void *cls, char *const *args, const char *cfgfile, | 344 | run (void *cls, char *const *args, const char *cfgfile, |
345 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 345 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
346 | { | 346 | { |
347 | enum GNUNET_DNS_Flags flags; | 347 | enum GNUNET_DNS_Flags flags; |
348 | 348 | ||
@@ -354,40 +354,40 @@ run(void *cls, char *const *args, const char *cfgfile, | |||
354 | if (outbound_only) | 354 | if (outbound_only) |
355 | flags |= GNUNET_DNS_FLAG_RESPONSE_MONITOR; | 355 | flags |= GNUNET_DNS_FLAG_RESPONSE_MONITOR; |
356 | handle = | 356 | handle = |
357 | GNUNET_DNS_connect(cfg, | 357 | GNUNET_DNS_connect (cfg, |
358 | flags, | 358 | flags, |
359 | &display_request, | 359 | &display_request, |
360 | NULL); | 360 | NULL); |
361 | GNUNET_SCHEDULER_add_shutdown(&do_disconnect, NULL); | 361 | GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL); |
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | int | 365 | int |
366 | main(int argc, char *const *argv) | 366 | main (int argc, char *const *argv) |
367 | { | 367 | { |
368 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 368 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
369 | GNUNET_GETOPT_option_flag('i', | 369 | GNUNET_GETOPT_option_flag ('i', |
370 | "inbound-only", | 370 | "inbound-only", |
371 | gettext_noop("only monitor DNS queries"), | 371 | gettext_noop ("only monitor DNS queries"), |
372 | &inbound_only), | 372 | &inbound_only), |
373 | 373 | ||
374 | GNUNET_GETOPT_option_flag('o', | 374 | GNUNET_GETOPT_option_flag ('o', |
375 | "outbound-only", | 375 | "outbound-only", |
376 | gettext_noop("only monitor DNS queries"), | 376 | gettext_noop ("only monitor DNS queries"), |
377 | &outbound_only), | 377 | &outbound_only), |
378 | 378 | ||
379 | GNUNET_GETOPT_option_verbose(&verbosity), | 379 | GNUNET_GETOPT_option_verbose (&verbosity), |
380 | GNUNET_GETOPT_OPTION_END | 380 | GNUNET_GETOPT_OPTION_END |
381 | }; | 381 | }; |
382 | 382 | ||
383 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 383 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
384 | return 2; | 384 | return 2; |
385 | ret = (GNUNET_OK == | 385 | ret = (GNUNET_OK == |
386 | GNUNET_PROGRAM_run(argc, argv, "gnunet-dns-monitor", | 386 | GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-monitor", |
387 | gettext_noop | 387 | gettext_noop |
388 | ("Monitor DNS queries."), options, | 388 | ("Monitor DNS queries."), options, |
389 | &run, NULL)) ? ret : 1; | 389 | &run, NULL)) ? ret : 1; |
390 | GNUNET_free((void*)argv); | 390 | GNUNET_free ((void*) argv); |
391 | return ret; | 391 | return ret; |
392 | } | 392 | } |
393 | 393 | ||
diff --git a/src/dns/gnunet-dns-redirector.c b/src/dns/gnunet-dns-redirector.c index f1978ce92..6a3899a46 100644 --- a/src/dns/gnunet-dns-redirector.c +++ b/src/dns/gnunet-dns-redirector.c | |||
@@ -61,51 +61,51 @@ static unsigned int verbosity; | |||
61 | * @param record record to modify | 61 | * @param record record to modify |
62 | */ | 62 | */ |
63 | static void | 63 | static void |
64 | modify_record(const struct GNUNET_DNSPARSER_Record *record) | 64 | modify_record (const struct GNUNET_DNSPARSER_Record *record) |
65 | { | 65 | { |
66 | char buf[INET6_ADDRSTRLEN]; | 66 | char buf[INET6_ADDRSTRLEN]; |
67 | 67 | ||
68 | switch (record->type) | 68 | switch (record->type) |
69 | { | ||
70 | case GNUNET_DNSPARSER_TYPE_A: | ||
71 | if (record->data.raw.data_len != sizeof(struct in_addr)) | ||
72 | return; | ||
73 | if (NULL != n4) | ||
74 | { | ||
75 | if (verbosity > 1) | ||
76 | fprintf (stderr, | ||
77 | "Changing A record from `%s' to `%s'\n", | ||
78 | inet_ntop (AF_INET, record->data.raw.data, buf, sizeof(buf)), | ||
79 | n4); | ||
80 | GNUNET_assert (1 == inet_pton (AF_INET, n4, record->data.raw.data)); | ||
81 | } | ||
82 | break; | ||
83 | |||
84 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
85 | if (record->data.raw.data_len != sizeof(struct in6_addr)) | ||
86 | return; | ||
87 | if (NULL != n6) | ||
69 | { | 88 | { |
70 | case GNUNET_DNSPARSER_TYPE_A: | 89 | if (verbosity > 1) |
71 | if (record->data.raw.data_len != sizeof(struct in_addr)) | 90 | fprintf (stderr, |
72 | return; | 91 | "Changing AAAA record from `%s' to `%s'\n", |
73 | if (NULL != n4) | 92 | inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof(buf)), |
74 | { | 93 | n6); |
75 | if (verbosity > 1) | 94 | GNUNET_assert (1 == inet_pton (AF_INET6, n6, record->data.raw.data)); |
76 | fprintf(stderr, | ||
77 | "Changing A record from `%s' to `%s'\n", | ||
78 | inet_ntop(AF_INET, record->data.raw.data, buf, sizeof(buf)), | ||
79 | n4); | ||
80 | GNUNET_assert(1 == inet_pton(AF_INET, n4, record->data.raw.data)); | ||
81 | } | ||
82 | break; | ||
83 | |||
84 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
85 | if (record->data.raw.data_len != sizeof(struct in6_addr)) | ||
86 | return; | ||
87 | if (NULL != n6) | ||
88 | { | ||
89 | if (verbosity > 1) | ||
90 | fprintf(stderr, | ||
91 | "Changing AAAA record from `%s' to `%s'\n", | ||
92 | inet_ntop(AF_INET6, record->data.raw.data, buf, sizeof(buf)), | ||
93 | n6); | ||
94 | GNUNET_assert(1 == inet_pton(AF_INET6, n6, record->data.raw.data)); | ||
95 | } | ||
96 | break; | ||
97 | |||
98 | case GNUNET_DNSPARSER_TYPE_NS: | ||
99 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
100 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
101 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
102 | case GNUNET_DNSPARSER_TYPE_MX: | ||
103 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
104 | break; | ||
105 | |||
106 | default: | ||
107 | break; | ||
108 | } | 95 | } |
96 | break; | ||
97 | |||
98 | case GNUNET_DNSPARSER_TYPE_NS: | ||
99 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
100 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
101 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
102 | case GNUNET_DNSPARSER_TYPE_MX: | ||
103 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
104 | break; | ||
105 | |||
106 | default: | ||
107 | break; | ||
108 | } | ||
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
@@ -133,10 +133,10 @@ modify_record(const struct GNUNET_DNSPARSER_Record *record) | |||
133 | * @param request udp payload of the DNS request | 133 | * @param request udp payload of the DNS request |
134 | */ | 134 | */ |
135 | static void | 135 | static void |
136 | modify_request(void *cls, | 136 | modify_request (void *cls, |
137 | struct GNUNET_DNS_RequestHandle *rh, | 137 | struct GNUNET_DNS_RequestHandle *rh, |
138 | size_t request_length, | 138 | size_t request_length, |
139 | const char *request) | 139 | const char *request) |
140 | { | 140 | { |
141 | struct GNUNET_DNSPARSER_Packet *p; | 141 | struct GNUNET_DNSPARSER_Packet *p; |
142 | unsigned int i; | 142 | unsigned int i; |
@@ -144,35 +144,35 @@ modify_request(void *cls, | |||
144 | size_t len; | 144 | size_t len; |
145 | int ret; | 145 | int ret; |
146 | 146 | ||
147 | p = GNUNET_DNSPARSER_parse(request, request_length); | 147 | p = GNUNET_DNSPARSER_parse (request, request_length); |
148 | if (NULL == p) | 148 | if (NULL == p) |
149 | { | 149 | { |
150 | fprintf(stderr, "Received malformed DNS packet, leaving it untouched\n"); | 150 | fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n"); |
151 | GNUNET_DNS_request_forward(rh); | 151 | GNUNET_DNS_request_forward (rh); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | for (i = 0; i < p->num_answers; i++) | 154 | for (i = 0; i < p->num_answers; i++) |
155 | modify_record(&p->answers[i]); | 155 | modify_record (&p->answers[i]); |
156 | buf = NULL; | 156 | buf = NULL; |
157 | ret = GNUNET_DNSPARSER_pack(p, 1024, &buf, &len); | 157 | ret = GNUNET_DNSPARSER_pack (p, 1024, &buf, &len); |
158 | GNUNET_DNSPARSER_free_packet(p); | 158 | GNUNET_DNSPARSER_free_packet (p); |
159 | if (GNUNET_OK != ret) | 159 | if (GNUNET_OK != ret) |
160 | { | 160 | { |
161 | if (GNUNET_NO == ret) | 161 | if (GNUNET_NO == ret) |
162 | fprintf(stderr, | 162 | fprintf (stderr, |
163 | "Modified DNS response did not fit, keeping old response\n"); | 163 | "Modified DNS response did not fit, keeping old response\n"); |
164 | else | 164 | else |
165 | GNUNET_break(0); /* our modifications should have been sane! */ | 165 | GNUNET_break (0); /* our modifications should have been sane! */ |
166 | GNUNET_DNS_request_forward(rh); | 166 | GNUNET_DNS_request_forward (rh); |
167 | } | 167 | } |
168 | else | 168 | else |
169 | { | 169 | { |
170 | if (verbosity > 0) | 170 | if (verbosity > 0) |
171 | fprintf(stdout, | 171 | fprintf (stdout, |
172 | "Injecting modified DNS response\n"); | 172 | "Injecting modified DNS response\n"); |
173 | GNUNET_DNS_request_answer(rh, len, buf); | 173 | GNUNET_DNS_request_answer (rh, len, buf); |
174 | } | 174 | } |
175 | GNUNET_free_non_null(buf); | 175 | GNUNET_free_non_null (buf); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
@@ -180,13 +180,13 @@ modify_request(void *cls, | |||
180 | * Shutdown. | 180 | * Shutdown. |
181 | */ | 181 | */ |
182 | static void | 182 | static void |
183 | do_disconnect(void *cls) | 183 | do_disconnect (void *cls) |
184 | { | 184 | { |
185 | if (NULL != handle) | 185 | if (NULL != handle) |
186 | { | 186 | { |
187 | GNUNET_DNS_disconnect(handle); | 187 | GNUNET_DNS_disconnect (handle); |
188 | handle = NULL; | 188 | handle = NULL; |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
@@ -199,67 +199,68 @@ do_disconnect(void *cls) | |||
199 | * @param cfg configuration | 199 | * @param cfg configuration |
200 | */ | 200 | */ |
201 | static void | 201 | static void |
202 | run(void *cls, char *const *args, const char *cfgfile, | 202 | run (void *cls, char *const *args, const char *cfgfile, |
203 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 203 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
204 | { | 204 | { |
205 | struct in_addr i4; | 205 | struct in_addr i4; |
206 | struct in6_addr i6; | 206 | struct in6_addr i6; |
207 | 207 | ||
208 | if ((n4 != NULL) && | 208 | if ((n4 != NULL) && |
209 | (1 != inet_pton(AF_INET, n4, &i4))) | 209 | (1 != inet_pton (AF_INET, n4, &i4))) |
210 | { | 210 | { |
211 | fprintf(stderr, | 211 | fprintf (stderr, |
212 | "`%s' is nto a valid IPv4 address!\n", | 212 | "`%s' is nto a valid IPv4 address!\n", |
213 | n4); | 213 | n4); |
214 | return; | 214 | return; |
215 | } | 215 | } |
216 | if ((n6 != NULL) && | 216 | if ((n6 != NULL) && |
217 | (1 != inet_pton(AF_INET6, n6, &i6))) | 217 | (1 != inet_pton (AF_INET6, n6, &i6))) |
218 | { | 218 | { |
219 | fprintf(stderr, | 219 | fprintf (stderr, |
220 | "`%s' is nto a valid IPv6 address!\n", | 220 | "`%s' is nto a valid IPv6 address!\n", |
221 | n6); | 221 | n6); |
222 | return; | 222 | return; |
223 | } | 223 | } |
224 | 224 | ||
225 | handle = | 225 | handle = |
226 | GNUNET_DNS_connect(cfg, | 226 | GNUNET_DNS_connect (cfg, |
227 | GNUNET_DNS_FLAG_POST_RESOLUTION, | 227 | GNUNET_DNS_FLAG_POST_RESOLUTION, |
228 | &modify_request, | 228 | &modify_request, |
229 | NULL); | 229 | NULL); |
230 | GNUNET_SCHEDULER_add_shutdown(&do_disconnect, NULL); | 230 | GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL); |
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | int | 234 | int |
235 | main(int argc, char *const *argv) | 235 | main (int argc, char *const *argv) |
236 | { | 236 | { |
237 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 237 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
238 | GNUNET_GETOPT_option_string('4', | 238 | GNUNET_GETOPT_option_string ('4', |
239 | "ipv4", | 239 | "ipv4", |
240 | "IPV4", | 240 | "IPV4", |
241 | gettext_noop("set A records"), | 241 | gettext_noop ("set A records"), |
242 | &n4), | 242 | &n4), |
243 | 243 | ||
244 | GNUNET_GETOPT_option_string('6', | 244 | GNUNET_GETOPT_option_string ('6', |
245 | "ipv4", | 245 | "ipv4", |
246 | "IPV6", | 246 | "IPV6", |
247 | gettext_noop("set AAAA records"), | 247 | gettext_noop ("set AAAA records"), |
248 | &n6), | 248 | &n6), |
249 | 249 | ||
250 | GNUNET_GETOPT_option_verbose(&verbosity), | 250 | GNUNET_GETOPT_option_verbose (&verbosity), |
251 | GNUNET_GETOPT_OPTION_END | 251 | GNUNET_GETOPT_OPTION_END |
252 | }; | 252 | }; |
253 | 253 | ||
254 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 254 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
255 | return 2; | 255 | return 2; |
256 | 256 | ||
257 | ret = (GNUNET_OK == | 257 | ret = (GNUNET_OK == |
258 | GNUNET_PROGRAM_run(argc, argv, "gnunet-dns-redirector", | 258 | GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-redirector", |
259 | gettext_noop | 259 | gettext_noop |
260 | ("Change DNS replies to point elsewhere."), options, | 260 | ("Change DNS replies to point elsewhere."), |
261 | &run, NULL)) ? ret : 1; | 261 | options, |
262 | GNUNET_free((void*)argv); | 262 | &run, NULL)) ? ret : 1; |
263 | GNUNET_free ((void*) argv); | ||
263 | return ret; | 264 | return ret; |
264 | } | 265 | } |
265 | 266 | ||
diff --git a/src/dns/gnunet-helper-dns.c b/src/dns/gnunet-helper-dns.c index e837d81c6..eceb278d2 100644 --- a/src/dns/gnunet-helper-dns.c +++ b/src/dns/gnunet-helper-dns.c | |||
@@ -83,11 +83,12 @@ | |||
83 | */ | 83 | */ |
84 | #define MAX_SIZE 65536 | 84 | #define MAX_SIZE 65536 |
85 | 85 | ||
86 | #if !HAVE_DECL_STRUCT_IN6_IFREQ | 86 | #if ! HAVE_DECL_STRUCT_IN6_IFREQ |
87 | /** | 87 | /** |
88 | * This is in linux/include/net/ipv6.h, but not always exported... | 88 | * This is in linux/include/net/ipv6.h, but not always exported... |
89 | */ | 89 | */ |
90 | struct in6_ifreq { | 90 | struct in6_ifreq |
91 | { | ||
91 | struct in6_addr ifr6_addr; | 92 | struct in6_addr ifr6_addr; |
92 | uint32_t ifr6_prefixlen; | 93 | uint32_t ifr6_prefixlen; |
93 | unsigned int ifr6_ifindex; | 94 | unsigned int ifr6_ifindex; |
@@ -151,11 +152,11 @@ static int cpipe[2]; | |||
151 | * @param signal signal number of the signal (not used) | 152 | * @param signal signal number of the signal (not used) |
152 | */ | 153 | */ |
153 | static void | 154 | static void |
154 | signal_handler(int signal) | 155 | signal_handler (int signal) |
155 | { | 156 | { |
156 | /* ignore return value, as the signal handler could theoretically | 157 | /* ignore return value, as the signal handler could theoretically |
157 | be called many times before the shutdown can actually happen */ | 158 | be called many times before the shutdown can actually happen */ |
158 | (void)write(cpipe[1], "K", 1); | 159 | (void) write (cpipe[1], "K", 1); |
159 | } | 160 | } |
160 | 161 | ||
161 | 162 | ||
@@ -167,22 +168,22 @@ signal_handler(int signal) | |||
167 | * @param flags open flags (O_RDONLY, O_WRONLY) | 168 | * @param flags open flags (O_RDONLY, O_WRONLY) |
168 | */ | 169 | */ |
169 | static void | 170 | static void |
170 | open_dev_null(int target_fd, | 171 | open_dev_null (int target_fd, |
171 | int flags) | 172 | int flags) |
172 | { | 173 | { |
173 | int fd; | 174 | int fd; |
174 | 175 | ||
175 | fd = open("/dev/null", flags); | 176 | fd = open ("/dev/null", flags); |
176 | if (-1 == fd) | 177 | if (-1 == fd) |
177 | abort(); | 178 | abort (); |
178 | if (fd == target_fd) | 179 | if (fd == target_fd) |
179 | return; | 180 | return; |
180 | if (-1 == dup2(fd, target_fd)) | 181 | if (-1 == dup2 (fd, target_fd)) |
181 | { | 182 | { |
182 | (void)close(fd); | 183 | (void) close (fd); |
183 | abort(); | 184 | abort (); |
184 | } | 185 | } |
185 | (void)close(fd); | 186 | (void) close (fd); |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
@@ -194,50 +195,50 @@ open_dev_null(int target_fd, | |||
194 | * @return 0 on success, 1 on any error | 195 | * @return 0 on success, 1 on any error |
195 | */ | 196 | */ |
196 | static int | 197 | static int |
197 | fork_and_exec(const char *file, | 198 | fork_and_exec (const char *file, |
198 | char *const cmd[]) | 199 | char *const cmd[]) |
199 | { | 200 | { |
200 | int status; | 201 | int status; |
201 | pid_t pid; | 202 | pid_t pid; |
202 | pid_t ret; | 203 | pid_t ret; |
203 | 204 | ||
204 | pid = fork(); | 205 | pid = fork (); |
205 | if (-1 == pid) | 206 | if (-1 == pid) |
206 | { | 207 | { |
207 | fprintf(stderr, | 208 | fprintf (stderr, |
208 | "fork failed: %s\n", | 209 | "fork failed: %s\n", |
209 | strerror(errno)); | 210 | strerror (errno)); |
210 | return 1; | 211 | return 1; |
211 | } | 212 | } |
212 | if (0 == pid) | 213 | if (0 == pid) |
213 | { | 214 | { |
214 | /* we are the child process */ | 215 | /* we are the child process */ |
215 | /* close stdin/stdout to not cause interference | 216 | /* close stdin/stdout to not cause interference |
216 | with the helper's main protocol! */ | 217 | with the helper's main protocol! */ |
217 | (void)close(0); | 218 | (void) close (0); |
218 | open_dev_null(0, O_RDONLY); | 219 | open_dev_null (0, O_RDONLY); |
219 | (void)close(1); | 220 | (void) close (1); |
220 | open_dev_null(1, O_WRONLY); | 221 | open_dev_null (1, O_WRONLY); |
221 | (void)execv(file, cmd); | 222 | (void) execv (file, cmd); |
222 | /* can only get here on error */ | 223 | /* can only get here on error */ |
223 | fprintf(stderr, | 224 | fprintf (stderr, |
224 | "exec `%s' failed: %s\n", | 225 | "exec `%s' failed: %s\n", |
225 | file, | 226 | file, |
226 | strerror(errno)); | 227 | strerror (errno)); |
227 | _exit(1); | 228 | _exit (1); |
228 | } | 229 | } |
229 | /* keep running waitpid as long as the only error we get is 'EINTR' */ | 230 | /* keep running waitpid as long as the only error we get is 'EINTR' */ |
230 | while ((-1 == (ret = waitpid(pid, &status, 0))) && | 231 | while ((-1 == (ret = waitpid (pid, &status, 0))) && |
231 | (errno == EINTR)) | 232 | (errno == EINTR)) |
232 | ; | 233 | ; |
233 | if (-1 == ret) | 234 | if (-1 == ret) |
234 | { | 235 | { |
235 | fprintf(stderr, | 236 | fprintf (stderr, |
236 | "waitpid failed: %s\n", | 237 | "waitpid failed: %s\n", |
237 | strerror(errno)); | 238 | strerror (errno)); |
238 | return 1; | 239 | return 1; |
239 | } | 240 | } |
240 | if (!(WIFEXITED(status) && (0 == WEXITSTATUS(status)))) | 241 | if (! (WIFEXITED (status) && (0 == WEXITSTATUS (status)))) |
241 | return 1; | 242 | return 1; |
242 | /* child process completed and returned success, we're happy */ | 243 | /* child process completed and returned success, we're happy */ |
243 | return 0; | 244 | return 0; |
@@ -252,45 +253,45 @@ fork_and_exec(const char *file, | |||
252 | * @return the fd to the tun or -1 on error | 253 | * @return the fd to the tun or -1 on error |
253 | */ | 254 | */ |
254 | static int | 255 | static int |
255 | init_tun(char *dev) | 256 | init_tun (char *dev) |
256 | { | 257 | { |
257 | struct ifreq ifr; | 258 | struct ifreq ifr; |
258 | int fd; | 259 | int fd; |
259 | 260 | ||
260 | if (NULL == dev) | 261 | if (NULL == dev) |
261 | { | 262 | { |
262 | errno = EINVAL; | 263 | errno = EINVAL; |
263 | return -1; | 264 | return -1; |
264 | } | 265 | } |
265 | 266 | ||
266 | if (-1 == (fd = open("/dev/net/tun", O_RDWR))) | 267 | if (-1 == (fd = open ("/dev/net/tun", O_RDWR))) |
267 | { | 268 | { |
268 | fprintf(stderr, "Error opening `%s': %s\n", "/dev/net/tun", | 269 | fprintf (stderr, "Error opening `%s': %s\n", "/dev/net/tun", |
269 | strerror(errno)); | 270 | strerror (errno)); |
270 | return -1; | 271 | return -1; |
271 | } | 272 | } |
272 | 273 | ||
273 | if (fd >= FD_SETSIZE) | 274 | if (fd >= FD_SETSIZE) |
274 | { | 275 | { |
275 | fprintf(stderr, "File descriptor to large: %d", fd); | 276 | fprintf (stderr, "File descriptor to large: %d", fd); |
276 | (void)close(fd); | 277 | (void) close (fd); |
277 | return -1; | 278 | return -1; |
278 | } | 279 | } |
279 | 280 | ||
280 | memset(&ifr, 0, sizeof(ifr)); | 281 | memset (&ifr, 0, sizeof(ifr)); |
281 | ifr.ifr_flags = IFF_TUN; | 282 | ifr.ifr_flags = IFF_TUN; |
282 | 283 | ||
283 | if ('\0' != *dev) | 284 | if ('\0' != *dev) |
284 | strncpy(ifr.ifr_name, dev, IFNAMSIZ); | 285 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); |
285 | 286 | ||
286 | if (-1 == ioctl(fd, TUNSETIFF, (void *)&ifr)) | 287 | if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) |
287 | { | 288 | { |
288 | fprintf(stderr, "Error with ioctl on `%s': %s\n", "/dev/net/tun", | 289 | fprintf (stderr, "Error with ioctl on `%s': %s\n", "/dev/net/tun", |
289 | strerror(errno)); | 290 | strerror (errno)); |
290 | (void)close(fd); | 291 | (void) close (fd); |
291 | return -1; | 292 | return -1; |
292 | } | 293 | } |
293 | strcpy(dev, ifr.ifr_name); | 294 | strcpy (dev, ifr.ifr_name); |
294 | return fd; | 295 | return fd; |
295 | } | 296 | } |
296 | 297 | ||
@@ -303,7 +304,7 @@ init_tun(char *dev) | |||
303 | * @param prefix_len the length of the network-prefix | 304 | * @param prefix_len the length of the network-prefix |
304 | */ | 305 | */ |
305 | static void | 306 | static void |
306 | set_address6(const char *dev, const char *address, unsigned long prefix_len) | 307 | set_address6 (const char *dev, const char *address, unsigned long prefix_len) |
307 | { | 308 | { |
308 | struct ifreq ifr; | 309 | struct ifreq ifr; |
309 | struct in6_ifreq ifr6; | 310 | struct in6_ifreq ifr6; |
@@ -313,39 +314,39 @@ set_address6(const char *dev, const char *address, unsigned long prefix_len) | |||
313 | /* | 314 | /* |
314 | * parse the new address | 315 | * parse the new address |
315 | */ | 316 | */ |
316 | memset(&sa6, 0, sizeof(struct sockaddr_in6)); | 317 | memset (&sa6, 0, sizeof(struct sockaddr_in6)); |
317 | sa6.sin6_family = AF_INET6; | 318 | sa6.sin6_family = AF_INET6; |
318 | if (1 != inet_pton(AF_INET6, address, sa6.sin6_addr.s6_addr)) | 319 | if (1 != inet_pton (AF_INET6, address, sa6.sin6_addr.s6_addr)) |
319 | { | 320 | { |
320 | fprintf(stderr, | 321 | fprintf (stderr, |
321 | "Failed to parse IPv6 address `%s': %s\n", | 322 | "Failed to parse IPv6 address `%s': %s\n", |
322 | address, | 323 | address, |
323 | strerror(errno)); | 324 | strerror (errno)); |
324 | exit(1); | 325 | exit (1); |
325 | } | 326 | } |
326 | 327 | ||
327 | if (-1 == (fd = socket(PF_INET6, SOCK_DGRAM, 0))) | 328 | if (-1 == (fd = socket (PF_INET6, SOCK_DGRAM, 0))) |
328 | { | 329 | { |
329 | fprintf(stderr, | 330 | fprintf (stderr, |
330 | "Error creating IPv6 socket: %s (ignored)\n", | 331 | "Error creating IPv6 socket: %s (ignored)\n", |
331 | strerror(errno)); | 332 | strerror (errno)); |
332 | /* ignore error, maybe only IPv4 works on this system! */ | 333 | /* ignore error, maybe only IPv4 works on this system! */ |
333 | return; | 334 | return; |
334 | } | 335 | } |
335 | 336 | ||
336 | memset(&ifr, 0, sizeof(struct ifreq)); | 337 | memset (&ifr, 0, sizeof(struct ifreq)); |
337 | /* | 338 | /* |
338 | * Get the index of the if | 339 | * Get the index of the if |
339 | */ | 340 | */ |
340 | strncpy(ifr.ifr_name, dev, IFNAMSIZ); | 341 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); |
341 | if (-1 == ioctl(fd, SIOGIFINDEX, &ifr)) | 342 | if (-1 == ioctl (fd, SIOGIFINDEX, &ifr)) |
342 | { | 343 | { |
343 | fprintf(stderr, "ioctl failed at %d: %s\n", __LINE__, strerror(errno)); | 344 | fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno)); |
344 | (void)close(fd); | 345 | (void) close (fd); |
345 | exit(1); | 346 | exit (1); |
346 | } | 347 | } |
347 | 348 | ||
348 | memset(&ifr6, 0, sizeof(struct in6_ifreq)); | 349 | memset (&ifr6, 0, sizeof(struct in6_ifreq)); |
349 | ifr6.ifr6_addr = sa6.sin6_addr; | 350 | ifr6.ifr6_addr = sa6.sin6_addr; |
350 | ifr6.ifr6_ifindex = ifr.ifr_ifindex; | 351 | ifr6.ifr6_ifindex = ifr.ifr_ifindex; |
351 | ifr6.ifr6_prefixlen = prefix_len; | 352 | ifr6.ifr6_prefixlen = prefix_len; |
@@ -353,42 +354,42 @@ set_address6(const char *dev, const char *address, unsigned long prefix_len) | |||
353 | /* | 354 | /* |
354 | * Set the address | 355 | * Set the address |
355 | */ | 356 | */ |
356 | if (-1 == ioctl(fd, SIOCSIFADDR, &ifr6)) | 357 | if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6)) |
357 | { | 358 | { |
358 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, | 359 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, |
359 | strerror(errno)); | 360 | strerror (errno)); |
360 | (void)close(fd); | 361 | (void) close (fd); |
361 | exit(1); | 362 | exit (1); |
362 | } | 363 | } |
363 | 364 | ||
364 | /* | 365 | /* |
365 | * Get the flags | 366 | * Get the flags |
366 | */ | 367 | */ |
367 | if (-1 == ioctl(fd, SIOCGIFFLAGS, &ifr)) | 368 | if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) |
368 | { | 369 | { |
369 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, | 370 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, |
370 | strerror(errno)); | 371 | strerror (errno)); |
371 | (void)close(fd); | 372 | (void) close (fd); |
372 | exit(1); | 373 | exit (1); |
373 | } | 374 | } |
374 | 375 | ||
375 | /* | 376 | /* |
376 | * Add the UP and RUNNING flags | 377 | * Add the UP and RUNNING flags |
377 | */ | 378 | */ |
378 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; | 379 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; |
379 | if (-1 == ioctl(fd, SIOCSIFFLAGS, &ifr)) | 380 | if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) |
380 | { | 381 | { |
381 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, | 382 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, |
382 | strerror(errno)); | 383 | strerror (errno)); |
383 | (void)close(fd); | 384 | (void) close (fd); |
384 | exit(1); | 385 | exit (1); |
385 | } | 386 | } |
386 | 387 | ||
387 | if (0 != close(fd)) | 388 | if (0 != close (fd)) |
388 | { | 389 | { |
389 | fprintf(stderr, "close failed: %s\n", strerror(errno)); | 390 | fprintf (stderr, "close failed: %s\n", strerror (errno)); |
390 | exit(1); | 391 | exit (1); |
391 | } | 392 | } |
392 | } | 393 | } |
393 | 394 | ||
394 | 395 | ||
@@ -400,100 +401,100 @@ set_address6(const char *dev, const char *address, unsigned long prefix_len) | |||
400 | * @param mask the netmask | 401 | * @param mask the netmask |
401 | */ | 402 | */ |
402 | static void | 403 | static void |
403 | set_address4(const char *dev, const char *address, const char *mask) | 404 | set_address4 (const char *dev, const char *address, const char *mask) |
404 | { | 405 | { |
405 | int fd; | 406 | int fd; |
406 | struct sockaddr_in *addr; | 407 | struct sockaddr_in *addr; |
407 | struct ifreq ifr; | 408 | struct ifreq ifr; |
408 | 409 | ||
409 | memset(&ifr, 0, sizeof(struct ifreq)); | 410 | memset (&ifr, 0, sizeof(struct ifreq)); |
410 | addr = (struct sockaddr_in *)&(ifr.ifr_addr); | 411 | addr = (struct sockaddr_in *) &(ifr.ifr_addr); |
411 | addr->sin_family = AF_INET; | 412 | addr->sin_family = AF_INET; |
412 | 413 | ||
413 | /* | 414 | /* |
414 | * Parse the address | 415 | * Parse the address |
415 | */ | 416 | */ |
416 | if (1 != inet_pton(AF_INET, address, &addr->sin_addr.s_addr)) | 417 | if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr)) |
417 | { | 418 | { |
418 | fprintf(stderr, | 419 | fprintf (stderr, |
419 | "Failed to parse IPv4 address `%s': %s\n", | 420 | "Failed to parse IPv4 address `%s': %s\n", |
420 | address, | 421 | address, |
421 | strerror(errno)); | 422 | strerror (errno)); |
422 | exit(1); | 423 | exit (1); |
423 | } | 424 | } |
424 | 425 | ||
425 | if (-1 == (fd = socket(PF_INET, SOCK_DGRAM, 0))) | 426 | if (-1 == (fd = socket (PF_INET, SOCK_DGRAM, 0))) |
426 | { | 427 | { |
427 | fprintf(stderr, | 428 | fprintf (stderr, |
428 | "Error creating IPv4 socket: %s\n", | 429 | "Error creating IPv4 socket: %s\n", |
429 | strerror(errno)); | 430 | strerror (errno)); |
430 | exit(1); | 431 | exit (1); |
431 | } | 432 | } |
432 | 433 | ||
433 | strncpy(ifr.ifr_name, dev, IFNAMSIZ); | 434 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); |
434 | 435 | ||
435 | /* | 436 | /* |
436 | * Set the address | 437 | * Set the address |
437 | */ | 438 | */ |
438 | if (-1 == ioctl(fd, SIOCSIFADDR, &ifr)) | 439 | if (-1 == ioctl (fd, SIOCSIFADDR, &ifr)) |
439 | { | 440 | { |
440 | fprintf(stderr, "ioctl failed at %d: %s\n", __LINE__, strerror(errno)); | 441 | fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno)); |
441 | (void)close(fd); | 442 | (void) close (fd); |
442 | exit(1); | 443 | exit (1); |
443 | } | 444 | } |
444 | 445 | ||
445 | /* | 446 | /* |
446 | * Parse the netmask | 447 | * Parse the netmask |
447 | */ | 448 | */ |
448 | addr = (struct sockaddr_in *)&(ifr.ifr_netmask); | 449 | addr = (struct sockaddr_in *) &(ifr.ifr_netmask); |
449 | if (1 != inet_pton(AF_INET, mask, &addr->sin_addr.s_addr)) | 450 | if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr)) |
450 | { | 451 | { |
451 | fprintf(stderr, "Failed to parse address `%s': %s\n", mask, | 452 | fprintf (stderr, "Failed to parse address `%s': %s\n", mask, |
452 | strerror(errno)); | 453 | strerror (errno)); |
453 | (void)close(fd); | 454 | (void) close (fd); |
454 | exit(1); | 455 | exit (1); |
455 | } | 456 | } |
456 | 457 | ||
457 | /* | 458 | /* |
458 | * Set the netmask | 459 | * Set the netmask |
459 | */ | 460 | */ |
460 | if (-1 == ioctl(fd, SIOCSIFNETMASK, &ifr)) | 461 | if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr)) |
461 | { | 462 | { |
462 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, | 463 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, |
463 | strerror(errno)); | 464 | strerror (errno)); |
464 | (void)close(fd); | 465 | (void) close (fd); |
465 | exit(1); | 466 | exit (1); |
466 | } | 467 | } |
467 | 468 | ||
468 | /* | 469 | /* |
469 | * Get the flags | 470 | * Get the flags |
470 | */ | 471 | */ |
471 | if (-1 == ioctl(fd, SIOCGIFFLAGS, &ifr)) | 472 | if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) |
472 | { | 473 | { |
473 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, | 474 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, |
474 | strerror(errno)); | 475 | strerror (errno)); |
475 | (void)close(fd); | 476 | (void) close (fd); |
476 | exit(1); | 477 | exit (1); |
477 | } | 478 | } |
478 | 479 | ||
479 | /* | 480 | /* |
480 | * Add the UP and RUNNING flags | 481 | * Add the UP and RUNNING flags |
481 | */ | 482 | */ |
482 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; | 483 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; |
483 | if (-1 == ioctl(fd, SIOCSIFFLAGS, &ifr)) | 484 | if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) |
484 | { | 485 | { |
485 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, | 486 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, |
486 | strerror(errno)); | 487 | strerror (errno)); |
487 | (void)close(fd); | 488 | (void) close (fd); |
488 | exit(1); | 489 | exit (1); |
489 | } | 490 | } |
490 | 491 | ||
491 | if (0 != close(fd)) | 492 | if (0 != close (fd)) |
492 | { | 493 | { |
493 | fprintf(stderr, "close failed: %s\n", strerror(errno)); | 494 | fprintf (stderr, "close failed: %s\n", strerror (errno)); |
494 | (void)close(fd); | 495 | (void) close (fd); |
495 | exit(1); | 496 | exit (1); |
496 | } | 497 | } |
497 | } | 498 | } |
498 | 499 | ||
499 | 500 | ||
@@ -505,7 +506,7 @@ set_address4(const char *dev, const char *address, const char *mask) | |||
505 | * @param fd_tun tunnel FD | 506 | * @param fd_tun tunnel FD |
506 | */ | 507 | */ |
507 | static void | 508 | static void |
508 | run(int fd_tun) | 509 | run (int fd_tun) |
509 | { | 510 | { |
510 | /* | 511 | /* |
511 | * The buffer filled by reading from fd_tun | 512 | * The buffer filled by reading from fd_tun |
@@ -526,176 +527,176 @@ run(int fd_tun) | |||
526 | int max; | 527 | int max; |
527 | 528 | ||
528 | while (1) | 529 | while (1) |
530 | { | ||
531 | FD_ZERO (&fds_w); | ||
532 | FD_ZERO (&fds_r); | ||
533 | |||
534 | /* | ||
535 | * We are supposed to read and the buffer is empty | ||
536 | * -> select on read from tun | ||
537 | */ | ||
538 | if (0 == buftun_size) | ||
539 | FD_SET (fd_tun, &fds_r); | ||
540 | |||
541 | /* | ||
542 | * We are supposed to read and the buffer is not empty | ||
543 | * -> select on write to stdout | ||
544 | */ | ||
545 | if (0 < buftun_size) | ||
546 | FD_SET (1, &fds_w); | ||
547 | |||
548 | /* | ||
549 | * We are supposed to write and the buffer is empty | ||
550 | * -> select on read from stdin | ||
551 | */ | ||
552 | if (NULL == bufin_read) | ||
553 | FD_SET (0, &fds_r); | ||
554 | |||
555 | /* | ||
556 | * We are supposed to write and the buffer is not empty | ||
557 | * -> select on write to tun | ||
558 | */ | ||
559 | if (NULL != bufin_read) | ||
560 | FD_SET (fd_tun, &fds_w); | ||
561 | |||
562 | FD_SET (cpipe[0], &fds_r); | ||
563 | max = (fd_tun > cpipe[0]) ? fd_tun : cpipe[0]; | ||
564 | |||
565 | int r = select (max + 1, &fds_r, &fds_w, NULL, NULL); | ||
566 | |||
567 | if (-1 == r) | ||
568 | { | ||
569 | if (EINTR == errno) | ||
570 | continue; | ||
571 | fprintf (stderr, "select failed: %s\n", strerror (errno)); | ||
572 | return; | ||
573 | } | ||
574 | |||
575 | if (r > 0) | ||
529 | { | 576 | { |
530 | FD_ZERO(&fds_w); | 577 | if (FD_ISSET (cpipe[0], &fds_r)) |
531 | FD_ZERO(&fds_r); | 578 | return; /* aborted by signal */ |
532 | 579 | ||
533 | /* | 580 | if (FD_ISSET (fd_tun, &fds_r)) |
534 | * We are supposed to read and the buffer is empty | 581 | { |
535 | * -> select on read from tun | 582 | buftun_size = |
536 | */ | 583 | read (fd_tun, buftun + sizeof(struct GNUNET_MessageHeader), |
537 | if (0 == buftun_size) | 584 | MAX_SIZE - sizeof(struct GNUNET_MessageHeader)); |
538 | FD_SET(fd_tun, &fds_r); | 585 | if (-1 == buftun_size) |
539 | 586 | { | |
540 | /* | 587 | if ((errno == EINTR) || |
541 | * We are supposed to read and the buffer is not empty | 588 | (errno == EAGAIN)) |
542 | * -> select on write to stdout | 589 | { |
543 | */ | 590 | buftun_size = 0; |
544 | if (0 < buftun_size) | 591 | continue; |
545 | FD_SET(1, &fds_w); | 592 | } |
546 | 593 | fprintf (stderr, "read-error: %s\n", strerror (errno)); | |
547 | /* | 594 | return; |
548 | * We are supposed to write and the buffer is empty | 595 | } |
549 | * -> select on read from stdin | 596 | if (0 == buftun_size) |
550 | */ | 597 | { |
551 | if (NULL == bufin_read) | 598 | fprintf (stderr, "EOF on tun\n"); |
552 | FD_SET(0, &fds_r); | 599 | return; |
553 | 600 | } | |
554 | /* | 601 | buftun_read = buftun; |
555 | * We are supposed to write and the buffer is not empty | ||
556 | * -> select on write to tun | ||
557 | */ | ||
558 | if (NULL != bufin_read) | ||
559 | FD_SET(fd_tun, &fds_w); | ||
560 | |||
561 | FD_SET(cpipe[0], &fds_r); | ||
562 | max = (fd_tun > cpipe[0]) ? fd_tun : cpipe[0]; | ||
563 | |||
564 | int r = select(max + 1, &fds_r, &fds_w, NULL, NULL); | ||
565 | |||
566 | if (-1 == r) | ||
567 | { | 602 | { |
568 | if (EINTR == errno) | 603 | struct GNUNET_MessageHeader *hdr = |
604 | (struct GNUNET_MessageHeader *) buftun; | ||
605 | buftun_size += sizeof(struct GNUNET_MessageHeader); | ||
606 | hdr->type = htons (GNUNET_MESSAGE_TYPE_DNS_HELPER); | ||
607 | hdr->size = htons (buftun_size); | ||
608 | } | ||
609 | } | ||
610 | else if (FD_ISSET (1, &fds_w)) | ||
611 | { | ||
612 | ssize_t written = write (1, buftun_read, buftun_size); | ||
613 | |||
614 | if (-1 == written) | ||
615 | { | ||
616 | if ((errno == EINTR) || | ||
617 | (errno == EAGAIN)) | ||
569 | continue; | 618 | continue; |
570 | fprintf(stderr, "select failed: %s\n", strerror(errno)); | 619 | fprintf (stderr, "write-error to stdout: %s\n", strerror (errno)); |
571 | return; | 620 | return; |
572 | } | 621 | } |
622 | if (0 == written) | ||
623 | { | ||
624 | fprintf (stderr, "write returned 0\n"); | ||
625 | return; | ||
626 | } | ||
627 | buftun_size -= written; | ||
628 | buftun_read += written; | ||
629 | } | ||
573 | 630 | ||
574 | if (r > 0) | 631 | if (FD_ISSET (0, &fds_r)) |
632 | { | ||
633 | bufin_size = read (0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos); | ||
634 | if (-1 == bufin_size) | ||
635 | { | ||
636 | bufin_read = NULL; | ||
637 | if ((errno == EINTR) || | ||
638 | (errno == EAGAIN)) | ||
639 | continue; | ||
640 | fprintf (stderr, "read-error: %s\n", strerror (errno)); | ||
641 | return; | ||
642 | } | ||
643 | if (0 == bufin_size) | ||
644 | { | ||
645 | bufin_read = NULL; | ||
646 | fprintf (stderr, "EOF on stdin\n"); | ||
647 | return; | ||
648 | } | ||
575 | { | 649 | { |
576 | if (FD_ISSET(cpipe[0], &fds_r)) | 650 | struct GNUNET_MessageHeader *hdr; |
577 | return; /* aborted by signal */ | ||
578 | |||
579 | if (FD_ISSET(fd_tun, &fds_r)) | ||
580 | { | ||
581 | buftun_size = | ||
582 | read(fd_tun, buftun + sizeof(struct GNUNET_MessageHeader), | ||
583 | MAX_SIZE - sizeof(struct GNUNET_MessageHeader)); | ||
584 | if (-1 == buftun_size) | ||
585 | { | ||
586 | if ((errno == EINTR) || | ||
587 | (errno == EAGAIN)) | ||
588 | { | ||
589 | buftun_size = 0; | ||
590 | continue; | ||
591 | } | ||
592 | fprintf(stderr, "read-error: %s\n", strerror(errno)); | ||
593 | return; | ||
594 | } | ||
595 | if (0 == buftun_size) | ||
596 | { | ||
597 | fprintf(stderr, "EOF on tun\n"); | ||
598 | return; | ||
599 | } | ||
600 | buftun_read = buftun; | ||
601 | { | ||
602 | struct GNUNET_MessageHeader *hdr = | ||
603 | (struct GNUNET_MessageHeader *)buftun; | ||
604 | buftun_size += sizeof(struct GNUNET_MessageHeader); | ||
605 | hdr->type = htons(GNUNET_MESSAGE_TYPE_DNS_HELPER); | ||
606 | hdr->size = htons(buftun_size); | ||
607 | } | ||
608 | } | ||
609 | else if (FD_ISSET(1, &fds_w)) | ||
610 | { | ||
611 | ssize_t written = write(1, buftun_read, buftun_size); | ||
612 | |||
613 | if (-1 == written) | ||
614 | { | ||
615 | if ((errno == EINTR) || | ||
616 | (errno == EAGAIN)) | ||
617 | continue; | ||
618 | fprintf(stderr, "write-error to stdout: %s\n", strerror(errno)); | ||
619 | return; | ||
620 | } | ||
621 | if (0 == written) | ||
622 | { | ||
623 | fprintf(stderr, "write returned 0\n"); | ||
624 | return; | ||
625 | } | ||
626 | buftun_size -= written; | ||
627 | buftun_read += written; | ||
628 | } | ||
629 | |||
630 | if (FD_ISSET(0, &fds_r)) | ||
631 | { | ||
632 | bufin_size = read(0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos); | ||
633 | if (-1 == bufin_size) | ||
634 | { | ||
635 | bufin_read = NULL; | ||
636 | if ((errno == EINTR) || | ||
637 | (errno == EAGAIN)) | ||
638 | continue; | ||
639 | fprintf(stderr, "read-error: %s\n", strerror(errno)); | ||
640 | return; | ||
641 | } | ||
642 | if (0 == bufin_size) | ||
643 | { | ||
644 | bufin_read = NULL; | ||
645 | fprintf(stderr, "EOF on stdin\n"); | ||
646 | return; | ||
647 | } | ||
648 | { | ||
649 | struct GNUNET_MessageHeader *hdr; | ||
650 | 651 | ||
651 | PROCESS_BUFFER: | 652 | PROCESS_BUFFER: |
652 | bufin_rpos += bufin_size; | 653 | bufin_rpos += bufin_size; |
653 | if (bufin_rpos < sizeof(struct GNUNET_MessageHeader)) | 654 | if (bufin_rpos < sizeof(struct GNUNET_MessageHeader)) |
654 | continue; | 655 | continue; |
655 | hdr = (struct GNUNET_MessageHeader *)bufin; | 656 | hdr = (struct GNUNET_MessageHeader *) bufin; |
656 | if (ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_DNS_HELPER) | 657 | if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_DNS_HELPER) |
657 | { | 658 | { |
658 | fprintf(stderr, "protocol violation!\n"); | 659 | fprintf (stderr, "protocol violation!\n"); |
659 | return; | 660 | return; |
660 | } | 661 | } |
661 | if (ntohs(hdr->size) > bufin_rpos) | 662 | if (ntohs (hdr->size) > bufin_rpos) |
662 | continue; | 663 | continue; |
663 | bufin_read = bufin + sizeof(struct GNUNET_MessageHeader); | 664 | bufin_read = bufin + sizeof(struct GNUNET_MessageHeader); |
664 | bufin_size = ntohs(hdr->size) - sizeof(struct GNUNET_MessageHeader); | 665 | bufin_size = ntohs (hdr->size) - sizeof(struct GNUNET_MessageHeader); |
665 | bufin_rpos -= bufin_size + sizeof(struct GNUNET_MessageHeader); | 666 | bufin_rpos -= bufin_size + sizeof(struct GNUNET_MessageHeader); |
666 | } | ||
667 | } | ||
668 | else if (FD_ISSET(fd_tun, &fds_w)) | ||
669 | { | ||
670 | ssize_t written = write(fd_tun, bufin_read, bufin_size); | ||
671 | |||
672 | if (-1 == written) | ||
673 | { | ||
674 | if ((errno == EINTR) || | ||
675 | (errno == EAGAIN)) | ||
676 | continue; | ||
677 | fprintf(stderr, "write-error to tun: %s\n", strerror(errno)); | ||
678 | return; | ||
679 | } | ||
680 | if (0 == written) | ||
681 | { | ||
682 | fprintf(stderr, "write returned 0\n"); | ||
683 | return; | ||
684 | } | ||
685 | { | ||
686 | bufin_size -= written; | ||
687 | bufin_read += written; | ||
688 | if (0 == bufin_size) | ||
689 | { | ||
690 | memmove(bufin, bufin_read, bufin_rpos); | ||
691 | bufin_read = NULL; /* start reading again */ | ||
692 | bufin_size = 0; | ||
693 | goto PROCESS_BUFFER; | ||
694 | } | ||
695 | } | ||
696 | } | ||
697 | } | 667 | } |
668 | } | ||
669 | else if (FD_ISSET (fd_tun, &fds_w)) | ||
670 | { | ||
671 | ssize_t written = write (fd_tun, bufin_read, bufin_size); | ||
672 | |||
673 | if (-1 == written) | ||
674 | { | ||
675 | if ((errno == EINTR) || | ||
676 | (errno == EAGAIN)) | ||
677 | continue; | ||
678 | fprintf (stderr, "write-error to tun: %s\n", strerror (errno)); | ||
679 | return; | ||
680 | } | ||
681 | if (0 == written) | ||
682 | { | ||
683 | fprintf (stderr, "write returned 0\n"); | ||
684 | return; | ||
685 | } | ||
686 | { | ||
687 | bufin_size -= written; | ||
688 | bufin_read += written; | ||
689 | if (0 == bufin_size) | ||
690 | { | ||
691 | memmove (bufin, bufin_read, bufin_rpos); | ||
692 | bufin_read = NULL; /* start reading again */ | ||
693 | bufin_size = 0; | ||
694 | goto PROCESS_BUFFER; | ||
695 | } | ||
696 | } | ||
697 | } | ||
698 | } | 698 | } |
699 | } | ||
699 | } | 700 | } |
700 | 701 | ||
701 | 702 | ||
@@ -732,7 +733,7 @@ PROCESS_BUFFER: | |||
732 | * 255 failed to handle kill signal properly | 733 | * 255 failed to handle kill signal properly |
733 | */ | 734 | */ |
734 | int | 735 | int |
735 | main(int argc, char *const*argv) | 736 | main (int argc, char *const*argv) |
736 | { | 737 | { |
737 | int r; | 738 | int r; |
738 | char dev[IFNAMSIZ]; | 739 | char dev[IFNAMSIZ]; |
@@ -742,224 +743,225 @@ main(int argc, char *const*argv) | |||
742 | int nortsetup = 0; | 743 | int nortsetup = 0; |
743 | 744 | ||
744 | if (7 != argc) | 745 | if (7 != argc) |
745 | { | 746 | { |
746 | fprintf(stderr, "Fatal: must supply 6 arguments!\n"); | 747 | fprintf (stderr, "Fatal: must supply 6 arguments!\n"); |
747 | return 1; | 748 | return 1; |
748 | } | 749 | } |
749 | 750 | ||
750 | /* assert privs so we can modify the firewall rules! */ | 751 | /* assert privs so we can modify the firewall rules! */ |
751 | uid = getuid(); | 752 | uid = getuid (); |
752 | #ifdef HAVE_SETRESUID | 753 | #ifdef HAVE_SETRESUID |
753 | if (0 != setresuid(uid, 0, 0)) | 754 | if (0 != setresuid (uid, 0, 0)) |
754 | { | 755 | { |
755 | fprintf(stderr, "Failed to setresuid to root: %s\n", strerror(errno)); | 756 | fprintf (stderr, "Failed to setresuid to root: %s\n", strerror (errno)); |
756 | return 254; | 757 | return 254; |
757 | } | 758 | } |
758 | #else | 759 | #else |
759 | if (0 != seteuid(0)) | 760 | if (0 != seteuid (0)) |
760 | { | 761 | { |
761 | fprintf(stderr, "Failed to seteuid back to root: %s\n", strerror(errno)); | 762 | fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno)); |
762 | return 254; | 763 | return 254; |
763 | } | 764 | } |
764 | #endif | 765 | #endif |
765 | if (0 == strncmp(argv[6], "1", 2)) | 766 | if (0 == strncmp (argv[6], "1", 2)) |
766 | nortsetup = 1; | 767 | nortsetup = 1; |
767 | 768 | ||
768 | if (0 == nortsetup) | 769 | if (0 == nortsetup) |
769 | { | 770 | { |
770 | /* verify that the binaries we care about are executable */ | 771 | /* verify that the binaries we care about are executable */ |
771 | #ifdef IPTABLES | 772 | #ifdef IPTABLES |
772 | if (0 == access(IPTABLES, X_OK)) | 773 | if (0 == access (IPTABLES, X_OK)) |
773 | sbin_iptables = IPTABLES; | 774 | sbin_iptables = IPTABLES; |
774 | else | 775 | else |
775 | #endif | 776 | #endif |
776 | if (0 == access("/sbin/iptables", X_OK)) | 777 | if (0 == access ("/sbin/iptables", X_OK)) |
777 | sbin_iptables = "/sbin/iptables"; | 778 | sbin_iptables = "/sbin/iptables"; |
778 | else if (0 == access("/usr/sbin/iptables", X_OK)) | 779 | else if (0 == access ("/usr/sbin/iptables", X_OK)) |
779 | sbin_iptables = "/usr/sbin/iptables"; | 780 | sbin_iptables = "/usr/sbin/iptables"; |
780 | else | 781 | else |
781 | { | 782 | { |
782 | fprintf(stderr, | 783 | fprintf (stderr, |
783 | "Fatal: executable iptables not found in approved directories: %s\n", | 784 | "Fatal: executable iptables not found in approved directories: %s\n", |
784 | strerror(errno)); | 785 | strerror (errno)); |
785 | return 3; | 786 | return 3; |
786 | } | 787 | } |
787 | #ifdef IP6TABLES | 788 | #ifdef IP6TABLES |
788 | if (0 == access(IP6TABLES, X_OK)) | 789 | if (0 == access (IP6TABLES, X_OK)) |
789 | sbin_ip6tables = IP6TABLES; | 790 | sbin_ip6tables = IP6TABLES; |
790 | else | 791 | else |
791 | #endif | 792 | #endif |
792 | if (0 == access("/sbin/ip6tables", X_OK)) | 793 | if (0 == access ("/sbin/ip6tables", X_OK)) |
793 | sbin_ip6tables = "/sbin/ip6tables"; | 794 | sbin_ip6tables = "/sbin/ip6tables"; |
794 | else if (0 == access("/usr/sbin/ip6tables", X_OK)) | 795 | else if (0 == access ("/usr/sbin/ip6tables", X_OK)) |
795 | sbin_ip6tables = "/usr/sbin/ip6tables"; | 796 | sbin_ip6tables = "/usr/sbin/ip6tables"; |
796 | else | 797 | else |
797 | { | 798 | { |
798 | fprintf(stderr, | 799 | fprintf (stderr, |
799 | "Fatal: executable ip6tables not found in approved directories: %s\n", | 800 | "Fatal: executable ip6tables not found in approved directories: %s\n", |
800 | strerror(errno)); | 801 | strerror (errno)); |
801 | return 3; | 802 | return 3; |
802 | } | 803 | } |
803 | #ifdef PATH_TO_IP | 804 | #ifdef PATH_TO_IP |
804 | if (0 == access(PATH_TO_IP, X_OK)) | 805 | if (0 == access (PATH_TO_IP, X_OK)) |
805 | sbin_ip = PATH_TO_IP; | 806 | sbin_ip = PATH_TO_IP; |
806 | else | 807 | else |
807 | #endif | 808 | #endif |
808 | if (0 == access("/sbin/ip", X_OK)) | 809 | if (0 == access ("/sbin/ip", X_OK)) |
809 | sbin_ip = "/sbin/ip"; | 810 | sbin_ip = "/sbin/ip"; |
810 | else if (0 == access("/usr/sbin/ip", X_OK)) | 811 | else if (0 == access ("/usr/sbin/ip", X_OK)) |
811 | sbin_ip = "/usr/sbin/ip"; | 812 | sbin_ip = "/usr/sbin/ip"; |
812 | else if (0 == access("/bin/ip", X_OK)) /* gentoo has it there */ | 813 | else if (0 == access ("/bin/ip", X_OK)) /* gentoo has it there */ |
813 | sbin_ip = "/bin/ip"; | 814 | sbin_ip = "/bin/ip"; |
814 | else | 815 | else |
815 | { | 816 | { |
816 | fprintf(stderr, | 817 | fprintf (stderr, |
817 | "Fatal: executable ip not found in approved directories: %s\n", | 818 | "Fatal: executable ip not found in approved directories: %s\n", |
818 | strerror(errno)); | 819 | strerror (errno)); |
819 | return 4; | 820 | return 4; |
820 | } | 821 | } |
821 | #ifdef SYSCTL | 822 | #ifdef SYSCTL |
822 | if (0 == access(SYSCTL, X_OK)) | 823 | if (0 == access (SYSCTL, X_OK)) |
823 | sbin_sysctl = SYSCTL; | 824 | sbin_sysctl = SYSCTL; |
824 | else | 825 | else |
825 | #endif | 826 | #endif |
826 | if (0 == access("/sbin/sysctl", X_OK)) | 827 | if (0 == access ("/sbin/sysctl", X_OK)) |
827 | sbin_sysctl = "/sbin/sysctl"; | 828 | sbin_sysctl = "/sbin/sysctl"; |
828 | else if (0 == access("/usr/sbin/sysctl", X_OK)) | 829 | else if (0 == access ("/usr/sbin/sysctl", X_OK)) |
829 | sbin_sysctl = "/usr/sbin/sysctl"; | 830 | sbin_sysctl = "/usr/sbin/sysctl"; |
830 | else | 831 | else |
831 | { | 832 | { |
832 | fprintf(stderr, | 833 | fprintf (stderr, |
833 | "Fatal: executable sysctl not found in approved directories: %s\n", | 834 | "Fatal: executable sysctl not found in approved directories: %s\n", |
834 | strerror(errno)); | 835 | strerror (errno)); |
835 | return 5; | 836 | return 5; |
836 | } | ||
837 | } | 837 | } |
838 | } | ||
838 | 839 | ||
839 | /* setup 'mygid' string */ | 840 | /* setup 'mygid' string */ |
840 | snprintf(mygid, sizeof(mygid), "%d", (int)getegid()); | 841 | snprintf (mygid, sizeof(mygid), "%d", (int) getegid ()); |
841 | 842 | ||
842 | /* do not die on SIGPIPE */ | 843 | /* do not die on SIGPIPE */ |
843 | if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) | 844 | if (SIG_ERR == signal (SIGPIPE, SIG_IGN)) |
844 | { | 845 | { |
845 | fprintf(stderr, "Failed to protect against SIGPIPE: %s\n", | 846 | fprintf (stderr, "Failed to protect against SIGPIPE: %s\n", |
846 | strerror(errno)); | 847 | strerror (errno)); |
847 | return 7; | 848 | return 7; |
848 | } | 849 | } |
849 | 850 | ||
850 | /* setup pipe to shutdown nicely on SIGINT */ | 851 | /* setup pipe to shutdown nicely on SIGINT */ |
851 | if (0 != pipe(cpipe)) | 852 | if (0 != pipe (cpipe)) |
852 | { | 853 | { |
853 | fprintf(stderr, | 854 | fprintf (stderr, |
854 | "Fatal: could not setup control pipe: %s\n", | 855 | "Fatal: could not setup control pipe: %s\n", |
855 | strerror(errno)); | 856 | strerror (errno)); |
856 | return 6; | 857 | return 6; |
857 | } | 858 | } |
858 | if (cpipe[0] >= FD_SETSIZE) | 859 | if (cpipe[0] >= FD_SETSIZE) |
859 | { | 860 | { |
860 | fprintf(stderr, "Pipe file descriptor to large: %d", cpipe[0]); | 861 | fprintf (stderr, "Pipe file descriptor to large: %d", cpipe[0]); |
861 | (void)close(cpipe[0]); | 862 | (void) close (cpipe[0]); |
862 | (void)close(cpipe[1]); | 863 | (void) close (cpipe[1]); |
863 | return 6; | 864 | return 6; |
864 | } | 865 | } |
865 | { | 866 | { |
866 | /* make pipe non-blocking, as we theoretically could otherwise block | 867 | /* make pipe non-blocking, as we theoretically could otherwise block |
867 | in the signal handler */ | 868 | in the signal handler */ |
868 | int flags = fcntl(cpipe[1], F_GETFL); | 869 | int flags = fcntl (cpipe[1], F_GETFL); |
869 | if (-1 == flags) | 870 | if (-1 == flags) |
870 | { | 871 | { |
871 | fprintf(stderr, "Failed to read flags for pipe: %s", strerror(errno)); | 872 | fprintf (stderr, "Failed to read flags for pipe: %s", strerror (errno)); |
872 | (void)close(cpipe[0]); | 873 | (void) close (cpipe[0]); |
873 | (void)close(cpipe[1]); | 874 | (void) close (cpipe[1]); |
874 | return 6; | 875 | return 6; |
875 | } | 876 | } |
876 | flags |= O_NONBLOCK; | 877 | flags |= O_NONBLOCK; |
877 | if (0 != fcntl(cpipe[1], F_SETFL, flags)) | 878 | if (0 != fcntl (cpipe[1], F_SETFL, flags)) |
878 | { | 879 | { |
879 | fprintf(stderr, "Failed to make pipe non-blocking: %s", strerror(errno)); | 880 | fprintf (stderr, "Failed to make pipe non-blocking: %s", strerror ( |
880 | (void)close(cpipe[0]); | 881 | errno)); |
881 | (void)close(cpipe[1]); | 882 | (void) close (cpipe[0]); |
882 | return 6; | 883 | (void) close (cpipe[1]); |
883 | } | 884 | return 6; |
885 | } | ||
884 | } | 886 | } |
885 | if ((SIG_ERR == signal(SIGTERM, &signal_handler)) || | 887 | if ((SIG_ERR == signal (SIGTERM, &signal_handler)) || |
886 | #if (SIGTERM != GNUNET_TERM_SIG) | 888 | #if (SIGTERM != GNUNET_TERM_SIG) |
887 | (SIG_ERR == signal(GNUNET_TERM_SIG, &signal_handler)) || | 889 | (SIG_ERR == signal (GNUNET_TERM_SIG, &signal_handler)) || |
888 | #endif | 890 | #endif |
889 | (SIG_ERR == signal(SIGINT, &signal_handler)) || | 891 | (SIG_ERR == signal (SIGINT, &signal_handler)) || |
890 | (SIG_ERR == signal(SIGHUP, &signal_handler))) | 892 | (SIG_ERR == signal (SIGHUP, &signal_handler))) |
891 | { | 893 | { |
892 | fprintf(stderr, | 894 | fprintf (stderr, |
893 | "Fatal: could not initialize signal handler: %s\n", | 895 | "Fatal: could not initialize signal handler: %s\n", |
894 | strerror(errno)); | 896 | strerror (errno)); |
895 | (void)close(cpipe[0]); | 897 | (void) close (cpipe[0]); |
896 | (void)close(cpipe[1]); | 898 | (void) close (cpipe[1]); |
897 | return 7; | 899 | return 7; |
898 | } | 900 | } |
899 | 901 | ||
900 | 902 | ||
901 | /* get interface name */ | 903 | /* get interface name */ |
902 | strncpy(dev, argv[1], IFNAMSIZ); | 904 | strncpy (dev, argv[1], IFNAMSIZ); |
903 | dev[IFNAMSIZ - 1] = '\0'; | 905 | dev[IFNAMSIZ - 1] = '\0'; |
904 | 906 | ||
905 | /* Disable rp filtering */ | 907 | /* Disable rp filtering */ |
906 | if (0 == nortsetup) | 908 | if (0 == nortsetup) |
909 | { | ||
910 | char *const sysctl_args[] = { "sysctl", "-w", | ||
911 | "net.ipv4.conf.all.rp_filter=0", NULL }; | ||
912 | char *const sysctl_args2[] = { "sysctl", "-w", | ||
913 | "net.ipv4.conf.default.rp_filter=0", NULL }; | ||
914 | if ((0 != fork_and_exec (sbin_sysctl, sysctl_args)) || | ||
915 | (0 != fork_and_exec (sbin_sysctl, sysctl_args2))) | ||
907 | { | 916 | { |
908 | char *const sysctl_args[] = { "sysctl", "-w", | 917 | fprintf (stderr, |
909 | "net.ipv4.conf.all.rp_filter=0", NULL }; | 918 | "Failed to disable rp filtering.\n"); |
910 | char *const sysctl_args2[] = { "sysctl", "-w", | 919 | return 5; |
911 | "net.ipv4.conf.default.rp_filter=0", NULL }; | ||
912 | if ((0 != fork_and_exec(sbin_sysctl, sysctl_args)) || | ||
913 | (0 != fork_and_exec(sbin_sysctl, sysctl_args2))) | ||
914 | { | ||
915 | fprintf(stderr, | ||
916 | "Failed to disable rp filtering.\n"); | ||
917 | return 5; | ||
918 | } | ||
919 | } | 920 | } |
921 | } | ||
920 | 922 | ||
921 | 923 | ||
922 | /* now open virtual interface (first part that requires root) */ | 924 | /* now open virtual interface (first part that requires root) */ |
923 | if (-1 == (fd_tun = init_tun(dev))) | 925 | if (-1 == (fd_tun = init_tun (dev))) |
924 | { | 926 | { |
925 | fprintf(stderr, "Fatal: could not initialize tun-interface\n"); | 927 | fprintf (stderr, "Fatal: could not initialize tun-interface\n"); |
926 | (void)signal(SIGTERM, SIG_IGN); | 928 | (void) signal (SIGTERM, SIG_IGN); |
927 | #if (SIGTERM != GNUNET_TERM_SIG) | 929 | #if (SIGTERM != GNUNET_TERM_SIG) |
928 | (void)signal(GNUNET_TERM_SIG, SIG_IGN); | 930 | (void) signal (GNUNET_TERM_SIG, SIG_IGN); |
929 | #endif | 931 | #endif |
930 | (void)signal(SIGINT, SIG_IGN); | 932 | (void) signal (SIGINT, SIG_IGN); |
931 | (void)signal(SIGHUP, SIG_IGN); | 933 | (void) signal (SIGHUP, SIG_IGN); |
932 | (void)close(cpipe[0]); | 934 | (void) close (cpipe[0]); |
933 | (void)close(cpipe[1]); | 935 | (void) close (cpipe[1]); |
934 | return 5; | 936 | return 5; |
935 | } | 937 | } |
936 | 938 | ||
937 | /* now set interface addresses */ | 939 | /* now set interface addresses */ |
938 | { | 940 | { |
939 | const char *address = argv[2]; | 941 | const char *address = argv[2]; |
940 | long prefix_len = atol(argv[3]); | 942 | long prefix_len = atol (argv[3]); |
941 | 943 | ||
942 | if ((prefix_len < 1) || (prefix_len > 127)) | 944 | if ((prefix_len < 1) || (prefix_len > 127)) |
943 | { | 945 | { |
944 | fprintf(stderr, "Fatal: prefix_len out of range\n"); | 946 | fprintf (stderr, "Fatal: prefix_len out of range\n"); |
945 | (void)signal(SIGTERM, SIG_IGN); | 947 | (void) signal (SIGTERM, SIG_IGN); |
946 | #if (SIGTERM != GNUNET_TERM_SIG) | 948 | #if (SIGTERM != GNUNET_TERM_SIG) |
947 | (void)signal(GNUNET_TERM_SIG, SIG_IGN); | 949 | (void) signal (GNUNET_TERM_SIG, SIG_IGN); |
948 | #endif | 950 | #endif |
949 | (void)signal(SIGINT, SIG_IGN); | 951 | (void) signal (SIGINT, SIG_IGN); |
950 | (void)signal(SIGHUP, SIG_IGN); | 952 | (void) signal (SIGHUP, SIG_IGN); |
951 | (void)close(cpipe[0]); | 953 | (void) close (cpipe[0]); |
952 | (void)close(cpipe[1]); | 954 | (void) close (cpipe[1]); |
953 | return 2; | 955 | return 2; |
954 | } | 956 | } |
955 | set_address6(dev, address, prefix_len); | 957 | set_address6 (dev, address, prefix_len); |
956 | } | 958 | } |
957 | 959 | ||
958 | { | 960 | { |
959 | const char *address = argv[4]; | 961 | const char *address = argv[4]; |
960 | const char *mask = argv[5]; | 962 | const char *mask = argv[5]; |
961 | 963 | ||
962 | set_address4(dev, address, mask); | 964 | set_address4 (dev, address, mask); |
963 | } | 965 | } |
964 | 966 | ||
965 | 967 | ||
@@ -968,237 +970,222 @@ main(int argc, char *const*argv) | |||
968 | by the 'gnunet-service-dns') and with destination | 970 | by the 'gnunet-service-dns') and with destination |
969 | to port 53 on UDP, without hijacking */ | 971 | to port 53 on UDP, without hijacking */ |
970 | if (0 == nortsetup) | 972 | if (0 == nortsetup) |
973 | { | ||
974 | r = 8; /* failed to fully setup routing table */ | ||
971 | { | 975 | { |
972 | r = 8; /* failed to fully setup routing table */ | 976 | char *const mangle_args[] = { |
973 | { | 977 | "iptables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", |
974 | char *const mangle_args[] = | 978 | "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", |
975 | { | 979 | "ACCEPT", NULL |
976 | "iptables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", | 980 | }; |
977 | "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", | 981 | if (0 != fork_and_exec (sbin_iptables, mangle_args)) |
978 | "ACCEPT", NULL | 982 | goto cleanup_rest; |
979 | }; | ||
980 | if (0 != fork_and_exec(sbin_iptables, mangle_args)) | ||
981 | goto cleanup_rest; | ||
982 | } | ||
983 | { | ||
984 | char *const mangle_args[] = | ||
985 | { | ||
986 | "ip6tables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", | ||
987 | "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", | ||
988 | "ACCEPT", NULL | ||
989 | }; | ||
990 | if (0 != fork_and_exec(sbin_ip6tables, mangle_args)) | ||
991 | goto cleanup_mangle_1b; | ||
992 | } | ||
993 | /* Mark all of the other DNS traffic using our mark DNS_MARK, | ||
994 | unless it is on a link-local IPv6 address, which we cannot support. */ | ||
995 | { | ||
996 | char *const mark_args[] = | ||
997 | { | ||
998 | "iptables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", | ||
999 | "udp", "--dport", DNS_PORT, | ||
1000 | "-j", "MARK", "--set-mark", DNS_MARK, | ||
1001 | NULL | ||
1002 | }; | ||
1003 | if (0 != fork_and_exec(sbin_iptables, mark_args)) | ||
1004 | goto cleanup_mangle_1; | ||
1005 | } | ||
1006 | { | ||
1007 | char *const mark_args[] = | ||
1008 | { | ||
1009 | "ip6tables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", | ||
1010 | "udp", "--dport", DNS_PORT, | ||
1011 | "!", "-s", "fe80::/10", /* this line excludes link-local traffic */ | ||
1012 | "-j", "MARK", "--set-mark", DNS_MARK, | ||
1013 | NULL | ||
1014 | }; | ||
1015 | if (0 != fork_and_exec(sbin_ip6tables, mark_args)) | ||
1016 | goto cleanup_mark_2b; | ||
1017 | } | ||
1018 | /* Forward all marked DNS traffic to our DNS_TABLE */ | ||
1019 | { | ||
1020 | char *const forward_args[] = | ||
1021 | { | ||
1022 | "ip", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL | ||
1023 | }; | ||
1024 | if (0 != fork_and_exec(sbin_ip, forward_args)) | ||
1025 | goto cleanup_mark_2; | ||
1026 | } | ||
1027 | { | ||
1028 | char *const forward_args[] = | ||
1029 | { | ||
1030 | "ip", "-6", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL | ||
1031 | }; | ||
1032 | if (0 != fork_and_exec(sbin_ip, forward_args)) | ||
1033 | goto cleanup_forward_3b; | ||
1034 | } | ||
1035 | /* Finally, add rule in our forwarding table to pass to our virtual interface */ | ||
1036 | { | ||
1037 | char *const route_args[] = | ||
1038 | { | ||
1039 | "ip", "route", "add", "default", "dev", dev, | ||
1040 | "table", DNS_TABLE, NULL | ||
1041 | }; | ||
1042 | if (0 != fork_and_exec(sbin_ip, route_args)) | ||
1043 | goto cleanup_forward_3; | ||
1044 | } | ||
1045 | { | ||
1046 | char *const route_args[] = | ||
1047 | { | ||
1048 | "ip", "-6", "route", "add", "default", "dev", dev, | ||
1049 | "table", DNS_TABLE, NULL | ||
1050 | }; | ||
1051 | if (0 != fork_and_exec(sbin_ip, route_args)) | ||
1052 | goto cleanup_route_4b; | ||
1053 | } | ||
1054 | } | 983 | } |
984 | { | ||
985 | char *const mangle_args[] = { | ||
986 | "ip6tables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", | ||
987 | "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", | ||
988 | "ACCEPT", NULL | ||
989 | }; | ||
990 | if (0 != fork_and_exec (sbin_ip6tables, mangle_args)) | ||
991 | goto cleanup_mangle_1b; | ||
992 | } | ||
993 | /* Mark all of the other DNS traffic using our mark DNS_MARK, | ||
994 | unless it is on a link-local IPv6 address, which we cannot support. */ | ||
995 | { | ||
996 | char *const mark_args[] = { | ||
997 | "iptables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", | ||
998 | "udp", "--dport", DNS_PORT, | ||
999 | "-j", "MARK", "--set-mark", DNS_MARK, | ||
1000 | NULL | ||
1001 | }; | ||
1002 | if (0 != fork_and_exec (sbin_iptables, mark_args)) | ||
1003 | goto cleanup_mangle_1; | ||
1004 | } | ||
1005 | { | ||
1006 | char *const mark_args[] = { | ||
1007 | "ip6tables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", | ||
1008 | "udp", "--dport", DNS_PORT, | ||
1009 | "!", "-s", "fe80::/10", /* this line excludes link-local traffic */ | ||
1010 | "-j", "MARK", "--set-mark", DNS_MARK, | ||
1011 | NULL | ||
1012 | }; | ||
1013 | if (0 != fork_and_exec (sbin_ip6tables, mark_args)) | ||
1014 | goto cleanup_mark_2b; | ||
1015 | } | ||
1016 | /* Forward all marked DNS traffic to our DNS_TABLE */ | ||
1017 | { | ||
1018 | char *const forward_args[] = { | ||
1019 | "ip", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL | ||
1020 | }; | ||
1021 | if (0 != fork_and_exec (sbin_ip, forward_args)) | ||
1022 | goto cleanup_mark_2; | ||
1023 | } | ||
1024 | { | ||
1025 | char *const forward_args[] = { | ||
1026 | "ip", "-6", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL | ||
1027 | }; | ||
1028 | if (0 != fork_and_exec (sbin_ip, forward_args)) | ||
1029 | goto cleanup_forward_3b; | ||
1030 | } | ||
1031 | /* Finally, add rule in our forwarding table to pass to our virtual interface */ | ||
1032 | { | ||
1033 | char *const route_args[] = { | ||
1034 | "ip", "route", "add", "default", "dev", dev, | ||
1035 | "table", DNS_TABLE, NULL | ||
1036 | }; | ||
1037 | if (0 != fork_and_exec (sbin_ip, route_args)) | ||
1038 | goto cleanup_forward_3; | ||
1039 | } | ||
1040 | { | ||
1041 | char *const route_args[] = { | ||
1042 | "ip", "-6", "route", "add", "default", "dev", dev, | ||
1043 | "table", DNS_TABLE, NULL | ||
1044 | }; | ||
1045 | if (0 != fork_and_exec (sbin_ip, route_args)) | ||
1046 | goto cleanup_route_4b; | ||
1047 | } | ||
1048 | } | ||
1055 | 1049 | ||
1056 | /* drop privs *except* for the saved UID; this is not perfect, but better | 1050 | /* drop privs *except* for the saved UID; this is not perfect, but better |
1057 | than doing nothing */ | 1051 | than doing nothing */ |
1058 | #ifdef HAVE_SETRESUID | 1052 | #ifdef HAVE_SETRESUID |
1059 | if (0 != setresuid(uid, uid, 0)) | 1053 | if (0 != setresuid (uid, uid, 0)) |
1060 | { | 1054 | { |
1061 | fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno)); | 1055 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); |
1062 | r = 24; | 1056 | r = 24; |
1063 | goto cleanup_route_4; | 1057 | goto cleanup_route_4; |
1064 | } | 1058 | } |
1065 | #else | 1059 | #else |
1066 | /* Note: no 'setuid' here as we must keep our saved UID as root */ | 1060 | /* Note: no 'setuid' here as we must keep our saved UID as root */ |
1067 | if (0 != seteuid(uid)) | 1061 | if (0 != seteuid (uid)) |
1068 | { | 1062 | { |
1069 | fprintf(stderr, "Failed to seteuid: %s\n", strerror(errno)); | 1063 | fprintf (stderr, "Failed to seteuid: %s\n", strerror (errno)); |
1070 | r = 24; | 1064 | r = 24; |
1071 | goto cleanup_route_4; | 1065 | goto cleanup_route_4; |
1072 | } | 1066 | } |
1073 | #endif | 1067 | #endif |
1074 | 1068 | ||
1075 | r = 0; /* did fully setup routing table (if nothing else happens, we were successful!) */ | 1069 | r = 0; /* did fully setup routing table (if nothing else happens, we were successful!) */ |
1076 | 1070 | ||
1077 | /* now forward until we hit a problem */ | 1071 | /* now forward until we hit a problem */ |
1078 | run(fd_tun); | 1072 | run (fd_tun); |
1079 | 1073 | ||
1080 | /* now need to regain privs so we can remove the firewall rules we added! */ | 1074 | /* now need to regain privs so we can remove the firewall rules we added! */ |
1081 | #ifdef HAVE_SETRESUID | 1075 | #ifdef HAVE_SETRESUID |
1082 | if (0 != setresuid(uid, 0, 0)) | 1076 | if (0 != setresuid (uid, 0, 0)) |
1083 | { | 1077 | { |
1084 | fprintf(stderr, "Failed to setresuid back to root: %s\n", strerror(errno)); | 1078 | fprintf (stderr, "Failed to setresuid back to root: %s\n", strerror ( |
1085 | r = 40; | 1079 | errno)); |
1086 | goto cleanup_route_4; | 1080 | r = 40; |
1087 | } | 1081 | goto cleanup_route_4; |
1082 | } | ||
1088 | #else | 1083 | #else |
1089 | if (0 != seteuid(0)) | 1084 | if (0 != seteuid (0)) |
1090 | { | 1085 | { |
1091 | fprintf(stderr, "Failed to seteuid back to root: %s\n", strerror(errno)); | 1086 | fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno)); |
1092 | r = 40; | 1087 | r = 40; |
1093 | goto cleanup_route_4; | 1088 | goto cleanup_route_4; |
1094 | } | 1089 | } |
1095 | #endif | 1090 | #endif |
1096 | 1091 | ||
1097 | /* update routing tables again -- this is why we could not fully drop privs */ | 1092 | /* update routing tables again -- this is why we could not fully drop privs */ |
1098 | /* now undo updating of routing tables; normal exit or clean-up-on-error case */ | 1093 | /* now undo updating of routing tables; normal exit or clean-up-on-error case */ |
1099 | cleanup_route_4: | 1094 | cleanup_route_4: |
1100 | if (0 == nortsetup) | 1095 | if (0 == nortsetup) |
1101 | { | 1096 | { |
1102 | char *const route_clean_args[] = | 1097 | char *const route_clean_args[] = { |
1103 | { | 1098 | "ip", "-6", "route", "del", "default", "dev", dev, |
1104 | "ip", "-6", "route", "del", "default", "dev", dev, | 1099 | "table", DNS_TABLE, NULL |
1105 | "table", DNS_TABLE, NULL | 1100 | }; |
1106 | }; | 1101 | if (0 != fork_and_exec (sbin_ip, route_clean_args)) |
1107 | if (0 != fork_and_exec(sbin_ip, route_clean_args)) | 1102 | r += 1; |
1108 | r += 1; | 1103 | } |
1109 | } | ||
1110 | cleanup_route_4b: | 1104 | cleanup_route_4b: |
1111 | if (0 == nortsetup) | 1105 | if (0 == nortsetup) |
1112 | { | 1106 | { |
1113 | char *const route_clean_args[] = | 1107 | char *const route_clean_args[] = { |
1114 | { | 1108 | "ip", "route", "del", "default", "dev", dev, |
1115 | "ip", "route", "del", "default", "dev", dev, | 1109 | "table", DNS_TABLE, NULL |
1116 | "table", DNS_TABLE, NULL | 1110 | }; |
1117 | }; | 1111 | if (0 != fork_and_exec (sbin_ip, route_clean_args)) |
1118 | if (0 != fork_and_exec(sbin_ip, route_clean_args)) | 1112 | r += 1; |
1119 | r += 1; | 1113 | } |
1120 | } | ||
1121 | cleanup_forward_3: | 1114 | cleanup_forward_3: |
1122 | if (0 == nortsetup) | 1115 | if (0 == nortsetup) |
1123 | { | 1116 | { |
1124 | char *const forward_clean_args[] = | 1117 | char *const forward_clean_args[] = { |
1125 | { | 1118 | "ip", "-6", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL |
1126 | "ip", "-6", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL | 1119 | }; |
1127 | }; | 1120 | if (0 != fork_and_exec (sbin_ip, forward_clean_args)) |
1128 | if (0 != fork_and_exec(sbin_ip, forward_clean_args)) | 1121 | r += 2; |
1129 | r += 2; | 1122 | } |
1130 | } | ||
1131 | cleanup_forward_3b: | 1123 | cleanup_forward_3b: |
1132 | if (0 == nortsetup) | 1124 | if (0 == nortsetup) |
1133 | { | 1125 | { |
1134 | char *const forward_clean_args[] = | 1126 | char *const forward_clean_args[] = { |
1135 | { | 1127 | "ip", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL |
1136 | "ip", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL | 1128 | }; |
1137 | }; | 1129 | if (0 != fork_and_exec (sbin_ip, forward_clean_args)) |
1138 | if (0 != fork_and_exec(sbin_ip, forward_clean_args)) | 1130 | r += 2; |
1139 | r += 2; | 1131 | } |
1140 | } | ||
1141 | cleanup_mark_2: | 1132 | cleanup_mark_2: |
1142 | if (0 == nortsetup) | 1133 | if (0 == nortsetup) |
1143 | { | 1134 | { |
1144 | char *const mark_clean_args[] = | 1135 | char *const mark_clean_args[] = { |
1145 | { | 1136 | "ip6tables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", |
1146 | "ip6tables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", | 1137 | "--dport", DNS_PORT, |
1147 | "--dport", DNS_PORT, | 1138 | "!", "-s", "fe80::/10", /* this line excludes link-local traffic */ |
1148 | "!", "-s", "fe80::/10", /* this line excludes link-local traffic */ | 1139 | "-j", "MARK", "--set-mark", DNS_MARK, NULL |
1149 | "-j", "MARK", "--set-mark", DNS_MARK, NULL | 1140 | }; |
1150 | }; | 1141 | if (0 != fork_and_exec (sbin_ip6tables, mark_clean_args)) |
1151 | if (0 != fork_and_exec(sbin_ip6tables, mark_clean_args)) | 1142 | r += 4; |
1152 | r += 4; | 1143 | } |
1153 | } | ||
1154 | cleanup_mark_2b: | 1144 | cleanup_mark_2b: |
1155 | if (0 == nortsetup) | 1145 | if (0 == nortsetup) |
1156 | { | 1146 | { |
1157 | char *const mark_clean_args[] = | 1147 | char *const mark_clean_args[] = { |
1158 | { | 1148 | "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", |
1159 | "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", | 1149 | "--dport", DNS_PORT, "-j", "MARK", "--set-mark", DNS_MARK, NULL |
1160 | "--dport", DNS_PORT, "-j", "MARK", "--set-mark", DNS_MARK, NULL | 1150 | }; |
1161 | }; | 1151 | if (0 != fork_and_exec (sbin_iptables, mark_clean_args)) |
1162 | if (0 != fork_and_exec(sbin_iptables, mark_clean_args)) | 1152 | r += 4; |
1163 | r += 4; | 1153 | } |
1164 | } | ||
1165 | cleanup_mangle_1: | 1154 | cleanup_mangle_1: |
1166 | if (0 == nortsetup) | 1155 | if (0 == nortsetup) |
1167 | { | 1156 | { |
1168 | char *const mangle_clean_args[] = | 1157 | char *const mangle_clean_args[] = { |
1169 | { | 1158 | "ip6tables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", |
1170 | "ip6tables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", | 1159 | "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", |
1171 | "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", | 1160 | NULL |
1172 | NULL | 1161 | }; |
1173 | }; | 1162 | if (0 != fork_and_exec (sbin_ip6tables, mangle_clean_args)) |
1174 | if (0 != fork_and_exec(sbin_ip6tables, mangle_clean_args)) | 1163 | r += 8; |
1175 | r += 8; | 1164 | } |
1176 | } | ||
1177 | cleanup_mangle_1b: | 1165 | cleanup_mangle_1b: |
1178 | if (0 == nortsetup) | 1166 | if (0 == nortsetup) |
1179 | { | 1167 | { |
1180 | char *const mangle_clean_args[] = | 1168 | char *const mangle_clean_args[] = { |
1181 | { | 1169 | "iptables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", |
1182 | "iptables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", | 1170 | "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", |
1183 | "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", | 1171 | NULL |
1184 | NULL | 1172 | }; |
1185 | }; | 1173 | if (0 != fork_and_exec (sbin_iptables, mangle_clean_args)) |
1186 | if (0 != fork_and_exec(sbin_iptables, mangle_clean_args)) | 1174 | r += 8; |
1187 | r += 8; | 1175 | } |
1188 | } | ||
1189 | 1176 | ||
1190 | cleanup_rest: | 1177 | cleanup_rest: |
1191 | /* close virtual interface */ | 1178 | /* close virtual interface */ |
1192 | (void)close(fd_tun); | 1179 | (void) close (fd_tun); |
1193 | /* remove signal handler so we can close the pipes */ | 1180 | /* remove signal handler so we can close the pipes */ |
1194 | (void)signal(SIGTERM, SIG_IGN); | 1181 | (void) signal (SIGTERM, SIG_IGN); |
1195 | #if (SIGTERM != GNUNET_TERM_SIG) | 1182 | #if (SIGTERM != GNUNET_TERM_SIG) |
1196 | (void)signal(GNUNET_TERM_SIG, SIG_IGN); | 1183 | (void) signal (GNUNET_TERM_SIG, SIG_IGN); |
1197 | #endif | 1184 | #endif |
1198 | (void)signal(SIGINT, SIG_IGN); | 1185 | (void) signal (SIGINT, SIG_IGN); |
1199 | (void)signal(SIGHUP, SIG_IGN); | 1186 | (void) signal (SIGHUP, SIG_IGN); |
1200 | (void)close(cpipe[0]); | 1187 | (void) close (cpipe[0]); |
1201 | (void)close(cpipe[1]); | 1188 | (void) close (cpipe[1]); |
1202 | return r; | 1189 | return r; |
1203 | } | 1190 | } |
1204 | 1191 | ||
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 9a2293b2d..e1cb7a6ff 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c | |||
@@ -59,13 +59,14 @@ | |||
59 | * Generic logging shorthand | 59 | * Generic logging shorthand |
60 | */ | 60 | */ |
61 | #define LOG(kind, ...) \ | 61 | #define LOG(kind, ...) \ |
62 | GNUNET_log_from(kind, "dns", __VA_ARGS__); | 62 | GNUNET_log_from (kind, "dns", __VA_ARGS__); |
63 | 63 | ||
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Phases each request goes through. | 66 | * Phases each request goes through. |
67 | */ | 67 | */ |
68 | enum RequestPhase { | 68 | enum RequestPhase |
69 | { | ||
69 | /** | 70 | /** |
70 | * Request has just been received. | 71 | * Request has just been received. |
71 | */ | 72 | */ |
@@ -111,7 +112,8 @@ enum RequestPhase { | |||
111 | /** | 112 | /** |
112 | * Entry we keep for each client. | 113 | * Entry we keep for each client. |
113 | */ | 114 | */ |
114 | struct ClientRecord { | 115 | struct ClientRecord |
116 | { | ||
115 | /** | 117 | /** |
116 | * Kept in doubly-linked list. | 118 | * Kept in doubly-linked list. |
117 | */ | 119 | */ |
@@ -142,7 +144,8 @@ struct ClientRecord { | |||
142 | /** | 144 | /** |
143 | * Entry we keep for each active request. | 145 | * Entry we keep for each active request. |
144 | */ | 146 | */ |
145 | struct RequestRecord { | 147 | struct RequestRecord |
148 | { | ||
146 | /** | 149 | /** |
147 | * List of clients that still need to see this request (each entry | 150 | * List of clients that still need to see this request (each entry |
148 | * is set to NULL when the client is done). | 151 | * is set to NULL when the client is done). |
@@ -252,14 +255,14 @@ static struct GNUNET_DNSSTUB_Context *dnsstub; | |||
252 | * @param rr request to clean up | 255 | * @param rr request to clean up |
253 | */ | 256 | */ |
254 | static void | 257 | static void |
255 | cleanup_rr(struct RequestRecord *rr) | 258 | cleanup_rr (struct RequestRecord *rr) |
256 | { | 259 | { |
257 | GNUNET_free_non_null(rr->payload); | 260 | GNUNET_free_non_null (rr->payload); |
258 | rr->payload = NULL; | 261 | rr->payload = NULL; |
259 | rr->payload_length = 0; | 262 | rr->payload_length = 0; |
260 | GNUNET_array_grow(rr->client_wait_list, | 263 | GNUNET_array_grow (rr->client_wait_list, |
261 | rr->client_wait_list_length, | 264 | rr->client_wait_list_length, |
262 | 0); | 265 | 0); |
263 | } | 266 | } |
264 | 267 | ||
265 | 268 | ||
@@ -269,28 +272,28 @@ cleanup_rr(struct RequestRecord *rr) | |||
269 | * @param cls unused | 272 | * @param cls unused |
270 | */ | 273 | */ |
271 | static void | 274 | static void |
272 | cleanup_task(void *cls GNUNET_UNUSED) | 275 | cleanup_task (void *cls GNUNET_UNUSED) |
273 | { | 276 | { |
274 | if (NULL != hijacker) | 277 | if (NULL != hijacker) |
275 | { | 278 | { |
276 | GNUNET_HELPER_stop(hijacker, GNUNET_NO); | 279 | GNUNET_HELPER_stop (hijacker, GNUNET_NO); |
277 | hijacker = NULL; | 280 | hijacker = NULL; |
278 | } | 281 | } |
279 | for (unsigned int i = 0; i < 8; i++) | 282 | for (unsigned int i = 0; i < 8; i++) |
280 | GNUNET_free_non_null(helper_argv[i]); | 283 | GNUNET_free_non_null (helper_argv[i]); |
281 | for (unsigned int i = 0; i <= UINT16_MAX; i++) | 284 | for (unsigned int i = 0; i <= UINT16_MAX; i++) |
282 | cleanup_rr(&requests[i]); | 285 | cleanup_rr (&requests[i]); |
283 | if (NULL != stats) | 286 | if (NULL != stats) |
284 | { | 287 | { |
285 | GNUNET_STATISTICS_destroy(stats, | 288 | GNUNET_STATISTICS_destroy (stats, |
286 | GNUNET_NO); | 289 | GNUNET_NO); |
287 | stats = NULL; | 290 | stats = NULL; |
288 | } | 291 | } |
289 | if (NULL != dnsstub) | 292 | if (NULL != dnsstub) |
290 | { | 293 | { |
291 | GNUNET_DNSSTUB_stop(dnsstub); | 294 | GNUNET_DNSSTUB_stop (dnsstub); |
292 | dnsstub = NULL; | 295 | dnsstub = NULL; |
293 | } | 296 | } |
294 | } | 297 | } |
295 | 298 | ||
296 | 299 | ||
@@ -300,56 +303,56 @@ cleanup_task(void *cls GNUNET_UNUSED) | |||
300 | * @param rr request send to the network or just clean up. | 303 | * @param rr request send to the network or just clean up. |
301 | */ | 304 | */ |
302 | static void | 305 | static void |
303 | request_done(struct RequestRecord *rr) | 306 | request_done (struct RequestRecord *rr) |
304 | { | 307 | { |
305 | struct GNUNET_MessageHeader *hdr; | 308 | struct GNUNET_MessageHeader *hdr; |
306 | size_t reply_len; | 309 | size_t reply_len; |
307 | uint16_t source_port; | 310 | uint16_t source_port; |
308 | uint16_t destination_port; | 311 | uint16_t destination_port; |
309 | 312 | ||
310 | GNUNET_array_grow(rr->client_wait_list, | 313 | GNUNET_array_grow (rr->client_wait_list, |
311 | rr->client_wait_list_length, | 314 | rr->client_wait_list_length, |
312 | 0); | 315 | 0); |
313 | if (RP_RESPONSE_MONITOR != rr->phase) | 316 | if (RP_RESPONSE_MONITOR != rr->phase) |
314 | { | 317 | { |
315 | /* no response, drop */ | 318 | /* no response, drop */ |
316 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 319 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
317 | "Got no response for request %llu, dropping\n", | 320 | "Got no response for request %llu, dropping\n", |
318 | (unsigned long long)rr->request_id); | 321 | (unsigned long long) rr->request_id); |
319 | cleanup_rr(rr); | 322 | cleanup_rr (rr); |
320 | return; | 323 | return; |
321 | } | 324 | } |
322 | 325 | ||
323 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 326 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
324 | "Transmitting response for request %llu\n", | 327 | "Transmitting response for request %llu\n", |
325 | (unsigned long long)rr->request_id); | 328 | (unsigned long long) rr->request_id); |
326 | /* send response via hijacker */ | 329 | /* send response via hijacker */ |
327 | reply_len = sizeof(struct GNUNET_MessageHeader); | 330 | reply_len = sizeof(struct GNUNET_MessageHeader); |
328 | reply_len += sizeof(struct GNUNET_TUN_Layer2PacketHeader); | 331 | reply_len += sizeof(struct GNUNET_TUN_Layer2PacketHeader); |
329 | switch (rr->src_addr.ss_family) | 332 | switch (rr->src_addr.ss_family) |
330 | { | 333 | { |
331 | case AF_INET: | 334 | case AF_INET: |
332 | reply_len += sizeof(struct GNUNET_TUN_IPv4Header); | 335 | reply_len += sizeof(struct GNUNET_TUN_IPv4Header); |
333 | break; | 336 | break; |
334 | 337 | ||
335 | case AF_INET6: | 338 | case AF_INET6: |
336 | reply_len += sizeof(struct GNUNET_TUN_IPv6Header); | 339 | reply_len += sizeof(struct GNUNET_TUN_IPv6Header); |
337 | break; | 340 | break; |
338 | 341 | ||
339 | default: | 342 | default: |
340 | GNUNET_break(0); | 343 | GNUNET_break (0); |
341 | cleanup_rr(rr); | 344 | cleanup_rr (rr); |
342 | return; | 345 | return; |
343 | } | 346 | } |
344 | reply_len += sizeof(struct GNUNET_TUN_UdpHeader); | 347 | reply_len += sizeof(struct GNUNET_TUN_UdpHeader); |
345 | reply_len += rr->payload_length; | 348 | reply_len += rr->payload_length; |
346 | if (reply_len >= GNUNET_MAX_MESSAGE_SIZE) | 349 | if (reply_len >= GNUNET_MAX_MESSAGE_SIZE) |
347 | { | 350 | { |
348 | /* response too big, drop */ | 351 | /* response too big, drop */ |
349 | GNUNET_break(0); /* how can this be? */ | 352 | GNUNET_break (0); /* how can this be? */ |
350 | cleanup_rr(rr); | 353 | cleanup_rr (rr); |
351 | return; | 354 | return; |
352 | } | 355 | } |
353 | { | 356 | { |
354 | char buf[reply_len] GNUNET_ALIGN; | 357 | char buf[reply_len] GNUNET_ALIGN; |
355 | size_t off; | 358 | size_t off; |
@@ -357,70 +360,72 @@ request_done(struct RequestRecord *rr) | |||
357 | struct GNUNET_TUN_IPv6Header ip6; | 360 | struct GNUNET_TUN_IPv6Header ip6; |
358 | 361 | ||
359 | /* first, GNUnet message header */ | 362 | /* first, GNUnet message header */ |
360 | hdr = (struct GNUNET_MessageHeader*)buf; | 363 | hdr = (struct GNUNET_MessageHeader*) buf; |
361 | hdr->type = htons(GNUNET_MESSAGE_TYPE_DNS_HELPER); | 364 | hdr->type = htons (GNUNET_MESSAGE_TYPE_DNS_HELPER); |
362 | hdr->size = htons((uint16_t)reply_len); | 365 | hdr->size = htons ((uint16_t) reply_len); |
363 | off = sizeof(struct GNUNET_MessageHeader); | 366 | off = sizeof(struct GNUNET_MessageHeader); |
364 | 367 | ||
365 | /* first, TUN header */ | 368 | /* first, TUN header */ |
366 | { | 369 | { |
367 | struct GNUNET_TUN_Layer2PacketHeader tun; | 370 | struct GNUNET_TUN_Layer2PacketHeader tun; |
368 | 371 | ||
369 | tun.flags = htons(0); | 372 | tun.flags = htons (0); |
370 | if (rr->src_addr.ss_family == AF_INET) | 373 | if (rr->src_addr.ss_family == AF_INET) |
371 | tun.proto = htons(ETH_P_IPV4); | 374 | tun.proto = htons (ETH_P_IPV4); |
372 | else | 375 | else |
373 | tun.proto = htons(ETH_P_IPV6); | 376 | tun.proto = htons (ETH_P_IPV6); |
374 | GNUNET_memcpy(&buf[off], | 377 | GNUNET_memcpy (&buf[off], |
375 | &tun, | 378 | &tun, |
376 | sizeof(struct GNUNET_TUN_Layer2PacketHeader)); | 379 | sizeof(struct GNUNET_TUN_Layer2PacketHeader)); |
377 | off += sizeof(struct GNUNET_TUN_Layer2PacketHeader); | 380 | off += sizeof(struct GNUNET_TUN_Layer2PacketHeader); |
378 | } | 381 | } |
379 | 382 | ||
380 | /* now IP header */ | 383 | /* now IP header */ |
381 | switch (rr->src_addr.ss_family) | 384 | switch (rr->src_addr.ss_family) |
385 | { | ||
386 | case AF_INET: | ||
382 | { | 387 | { |
383 | case AF_INET: | 388 | struct sockaddr_in *src = (struct sockaddr_in *) &rr->src_addr; |
384 | { | 389 | struct sockaddr_in *dst = (struct sockaddr_in *) &rr->dst_addr; |
385 | struct sockaddr_in *src = (struct sockaddr_in *)&rr->src_addr; | ||
386 | struct sockaddr_in *dst = (struct sockaddr_in *)&rr->dst_addr; | ||
387 | 390 | ||
388 | source_port = dst->sin_port; | 391 | source_port = dst->sin_port; |
389 | destination_port = src->sin_port; | 392 | destination_port = src->sin_port; |
390 | GNUNET_TUN_initialize_ipv4_header(&ip4, | 393 | GNUNET_TUN_initialize_ipv4_header (&ip4, |
391 | IPPROTO_UDP, | 394 | IPPROTO_UDP, |
392 | reply_len - off - sizeof(struct GNUNET_TUN_IPv4Header), | 395 | reply_len - off - sizeof(struct |
393 | &dst->sin_addr, | 396 | GNUNET_TUN_IPv4Header), |
394 | &src->sin_addr); | 397 | &dst->sin_addr, |
395 | GNUNET_memcpy(&buf[off], | 398 | &src->sin_addr); |
396 | &ip4, | 399 | GNUNET_memcpy (&buf[off], |
397 | sizeof(ip4)); | 400 | &ip4, |
401 | sizeof(ip4)); | ||
398 | off += sizeof(ip4); | 402 | off += sizeof(ip4); |
399 | } | 403 | } |
400 | break; | 404 | break; |
401 | 405 | ||
402 | case AF_INET6: | 406 | case AF_INET6: |
403 | { | 407 | { |
404 | struct sockaddr_in6 *src = (struct sockaddr_in6 *)&rr->src_addr; | 408 | struct sockaddr_in6 *src = (struct sockaddr_in6 *) &rr->src_addr; |
405 | struct sockaddr_in6 *dst = (struct sockaddr_in6 *)&rr->dst_addr; | 409 | struct sockaddr_in6 *dst = (struct sockaddr_in6 *) &rr->dst_addr; |
406 | 410 | ||
407 | source_port = dst->sin6_port; | 411 | source_port = dst->sin6_port; |
408 | destination_port = src->sin6_port; | 412 | destination_port = src->sin6_port; |
409 | GNUNET_TUN_initialize_ipv6_header(&ip6, | 413 | GNUNET_TUN_initialize_ipv6_header (&ip6, |
410 | IPPROTO_UDP, | 414 | IPPROTO_UDP, |
411 | reply_len - off - sizeof(struct GNUNET_TUN_IPv6Header), | 415 | reply_len - off - sizeof(struct |
412 | &dst->sin6_addr, | 416 | GNUNET_TUN_IPv6Header), |
413 | &src->sin6_addr); | 417 | &dst->sin6_addr, |
414 | GNUNET_memcpy(&buf[off], | 418 | &src->sin6_addr); |
415 | &ip6, | 419 | GNUNET_memcpy (&buf[off], |
416 | sizeof(ip6)); | 420 | &ip6, |
421 | sizeof(ip6)); | ||
417 | off += sizeof(ip6); | 422 | off += sizeof(ip6); |
418 | } | 423 | } |
419 | break; | 424 | break; |
420 | 425 | ||
421 | default: | 426 | default: |
422 | GNUNET_assert(0); | 427 | GNUNET_assert (0); |
423 | } | 428 | } |
424 | 429 | ||
425 | /* now UDP header */ | 430 | /* now UDP header */ |
426 | { | 431 | { |
@@ -428,40 +433,41 @@ request_done(struct RequestRecord *rr) | |||
428 | 433 | ||
429 | udp.source_port = source_port; | 434 | udp.source_port = source_port; |
430 | udp.destination_port = destination_port; | 435 | udp.destination_port = destination_port; |
431 | udp.len = htons(reply_len - off); | 436 | udp.len = htons (reply_len - off); |
432 | if (AF_INET == rr->src_addr.ss_family) | 437 | if (AF_INET == rr->src_addr.ss_family) |
433 | GNUNET_TUN_calculate_udp4_checksum(&ip4, | 438 | GNUNET_TUN_calculate_udp4_checksum (&ip4, |
434 | &udp, | 439 | &udp, |
435 | rr->payload, | 440 | rr->payload, |
436 | rr->payload_length); | 441 | rr->payload_length); |
437 | else | 442 | else |
438 | GNUNET_TUN_calculate_udp6_checksum(&ip6, | 443 | GNUNET_TUN_calculate_udp6_checksum (&ip6, |
439 | &udp, | 444 | &udp, |
440 | rr->payload, | 445 | rr->payload, |
441 | rr->payload_length); | 446 | rr->payload_length); |
442 | GNUNET_memcpy(&buf[off], | 447 | GNUNET_memcpy (&buf[off], |
443 | &udp, | 448 | &udp, |
444 | sizeof(udp)); | 449 | sizeof(udp)); |
445 | off += sizeof(udp); | 450 | off += sizeof(udp); |
446 | } | 451 | } |
447 | 452 | ||
448 | /* now DNS payload */ | 453 | /* now DNS payload */ |
449 | { | 454 | { |
450 | GNUNET_memcpy(&buf[off], rr->payload, rr->payload_length); | 455 | GNUNET_memcpy (&buf[off], rr->payload, rr->payload_length); |
451 | off += rr->payload_length; | 456 | off += rr->payload_length; |
452 | } | 457 | } |
453 | /* final checks & sending */ | 458 | /* final checks & sending */ |
454 | GNUNET_assert(off == reply_len); | 459 | GNUNET_assert (off == reply_len); |
455 | (void)GNUNET_HELPER_send(hijacker, | 460 | (void) GNUNET_HELPER_send (hijacker, |
456 | hdr, | 461 | hdr, |
457 | GNUNET_YES, | 462 | GNUNET_YES, |
458 | NULL, NULL); | 463 | NULL, NULL); |
459 | GNUNET_STATISTICS_update(stats, | 464 | GNUNET_STATISTICS_update (stats, |
460 | gettext_noop("# DNS requests answered via TUN interface"), | 465 | gettext_noop ( |
461 | 1, GNUNET_NO); | 466 | "# DNS requests answered via TUN interface"), |
467 | 1, GNUNET_NO); | ||
462 | } | 468 | } |
463 | /* clean up, we're done */ | 469 | /* clean up, we're done */ |
464 | cleanup_rr(rr); | 470 | cleanup_rr (rr); |
465 | } | 471 | } |
466 | 472 | ||
467 | 473 | ||
@@ -473,31 +479,32 @@ request_done(struct RequestRecord *rr) | |||
473 | * @param cr client to send the response to | 479 | * @param cr client to send the response to |
474 | */ | 480 | */ |
475 | static void | 481 | static void |
476 | send_request_to_client(struct RequestRecord *rr, | 482 | send_request_to_client (struct RequestRecord *rr, |
477 | struct ClientRecord *cr) | 483 | struct ClientRecord *cr) |
478 | { | 484 | { |
479 | struct GNUNET_MQ_Envelope *env; | 485 | struct GNUNET_MQ_Envelope *env; |
480 | struct GNUNET_DNS_Request *req; | 486 | struct GNUNET_DNS_Request *req; |
481 | 487 | ||
482 | if (sizeof(struct GNUNET_DNS_Request) + rr->payload_length >= GNUNET_MAX_MESSAGE_SIZE) | 488 | if (sizeof(struct GNUNET_DNS_Request) + rr->payload_length >= |
483 | { | 489 | GNUNET_MAX_MESSAGE_SIZE) |
484 | GNUNET_break(0); | 490 | { |
485 | cleanup_rr(rr); | 491 | GNUNET_break (0); |
486 | return; | 492 | cleanup_rr (rr); |
487 | } | 493 | return; |
488 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 494 | } |
489 | "Sending information about request %llu to local client\n", | 495 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
490 | (unsigned long long)rr->request_id); | 496 | "Sending information about request %llu to local client\n", |
491 | env = GNUNET_MQ_msg_extra(req, | 497 | (unsigned long long) rr->request_id); |
492 | rr->payload_length, | 498 | env = GNUNET_MQ_msg_extra (req, |
493 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST); | 499 | rr->payload_length, |
494 | req->reserved = htonl(0); | 500 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST); |
501 | req->reserved = htonl (0); | ||
495 | req->request_id = rr->request_id; | 502 | req->request_id = rr->request_id; |
496 | GNUNET_memcpy(&req[1], | 503 | GNUNET_memcpy (&req[1], |
497 | rr->payload, | 504 | rr->payload, |
498 | rr->payload_length); | 505 | rr->payload_length); |
499 | GNUNET_MQ_send(cr->mq, | 506 | GNUNET_MQ_send (cr->mq, |
500 | env); | 507 | env); |
501 | } | 508 | } |
502 | 509 | ||
503 | 510 | ||
@@ -510,9 +517,9 @@ send_request_to_client(struct RequestRecord *rr, | |||
510 | * @param r number of bytes in dns | 517 | * @param r number of bytes in dns |
511 | */ | 518 | */ |
512 | static void | 519 | static void |
513 | process_dns_result(void *cls, | 520 | process_dns_result (void *cls, |
514 | const struct GNUNET_TUN_DnsHeader *dns, | 521 | const struct GNUNET_TUN_DnsHeader *dns, |
515 | size_t r); | 522 | size_t r); |
516 | 523 | ||
517 | 524 | ||
518 | /** | 525 | /** |
@@ -522,138 +529,139 @@ process_dns_result(void *cls, | |||
522 | * @param rr request to process further | 529 | * @param rr request to process further |
523 | */ | 530 | */ |
524 | static void | 531 | static void |
525 | next_phase(struct RequestRecord *rr) | 532 | next_phase (struct RequestRecord *rr) |
526 | { | 533 | { |
527 | struct ClientRecord *cr; | 534 | struct ClientRecord *cr; |
528 | int nz; | 535 | int nz; |
529 | 536 | ||
530 | if (rr->phase == RP_DROP) | 537 | if (rr->phase == RP_DROP) |
531 | { | 538 | { |
532 | cleanup_rr(rr); | 539 | cleanup_rr (rr); |
533 | return; | 540 | return; |
534 | } | 541 | } |
535 | nz = -1; | 542 | nz = -1; |
536 | for (unsigned int j = 0; j < rr->client_wait_list_length; j++) | 543 | for (unsigned int j = 0; j < rr->client_wait_list_length; j++) |
544 | { | ||
545 | if (NULL != rr->client_wait_list[j]) | ||
537 | { | 546 | { |
538 | if (NULL != rr->client_wait_list[j]) | 547 | nz = (int) j; |
539 | { | 548 | break; |
540 | nz = (int)j; | ||
541 | break; | ||
542 | } | ||
543 | } | 549 | } |
550 | } | ||
544 | if (-1 != nz) | 551 | if (-1 != nz) |
545 | { | 552 | { |
546 | send_request_to_client(rr, | 553 | send_request_to_client (rr, |
547 | rr->client_wait_list[nz]); | 554 | rr->client_wait_list[nz]); |
548 | return; | 555 | return; |
549 | } | 556 | } |
550 | /* done with current phase, advance! */ | 557 | /* done with current phase, advance! */ |
551 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 558 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
552 | "Request %llu now in phase %d\n", | 559 | "Request %llu now in phase %d\n", |
553 | rr->request_id, | 560 | rr->request_id, |
554 | rr->phase); | 561 | rr->phase); |
555 | switch (rr->phase) | 562 | switch (rr->phase) |
563 | { | ||
564 | case RP_INIT: | ||
565 | rr->phase = RP_REQUEST_MONITOR; | ||
566 | for (cr = clients_head; NULL != cr; cr = cr->next) | ||
556 | { | 567 | { |
557 | case RP_INIT: | 568 | if (0 != (cr->flags & GNUNET_DNS_FLAG_REQUEST_MONITOR)) |
558 | rr->phase = RP_REQUEST_MONITOR; | 569 | GNUNET_array_append (rr->client_wait_list, |
559 | for (cr = clients_head; NULL != cr; cr = cr->next) | 570 | rr->client_wait_list_length, |
560 | { | 571 | cr); |
561 | if (0 != (cr->flags & GNUNET_DNS_FLAG_REQUEST_MONITOR)) | 572 | } |
562 | GNUNET_array_append(rr->client_wait_list, | 573 | next_phase (rr); |
563 | rr->client_wait_list_length, | 574 | return; |
564 | cr); | ||
565 | } | ||
566 | next_phase(rr); | ||
567 | return; | ||
568 | 575 | ||
569 | case RP_REQUEST_MONITOR: | 576 | case RP_REQUEST_MONITOR: |
570 | rr->phase = RP_QUERY; | 577 | rr->phase = RP_QUERY; |
571 | for (cr = clients_head; NULL != cr; cr = cr->next) | 578 | for (cr = clients_head; NULL != cr; cr = cr->next) |
572 | { | 579 | { |
573 | if (0 != (cr->flags & GNUNET_DNS_FLAG_PRE_RESOLUTION)) | 580 | if (0 != (cr->flags & GNUNET_DNS_FLAG_PRE_RESOLUTION)) |
574 | GNUNET_array_append(rr->client_wait_list, | 581 | GNUNET_array_append (rr->client_wait_list, |
575 | rr->client_wait_list_length, | 582 | rr->client_wait_list_length, |
576 | cr); | 583 | cr); |
577 | } | 584 | } |
578 | next_phase(rr); | 585 | next_phase (rr); |
579 | return; | 586 | return; |
580 | 587 | ||
581 | case RP_QUERY: | 588 | case RP_QUERY: |
582 | #if 0 | 589 | #if 0 |
583 | /* TODO: optionally, use this to forward DNS requests to the | 590 | /* TODO: optionally, use this to forward DNS requests to the |
584 | * original* DNS server instead of the one we have configured... | 591 | * original* DNS server instead of the one we have configured... |
585 | (but then we need to create a fresh dnsstub for each request | 592 | (but then we need to create a fresh dnsstub for each request |
586 | * and* manage the timeout) */ | 593 | * and* manage the timeout) */ |
587 | switch (rr->dst_addr.ss_family) | 594 | switch (rr->dst_addr.ss_family) |
588 | { | 595 | { |
589 | case AF_INET: | 596 | case AF_INET: |
590 | salen = sizeof(struct sockaddr_in); | 597 | salen = sizeof(struct sockaddr_in); |
591 | sa = (const struct sockaddr *)&rr->dst_addr; | 598 | sa = (const struct sockaddr *) &rr->dst_addr; |
592 | break; | 599 | break; |
593 | 600 | ||
594 | case AF_INET6: | 601 | case AF_INET6: |
595 | salen = sizeof(struct sockaddr_in6); | 602 | salen = sizeof(struct sockaddr_in6); |
596 | sa = (const struct sockaddr *)&rr->dst_addr; | 603 | sa = (const struct sockaddr *) &rr->dst_addr; |
597 | break; | 604 | break; |
598 | 605 | ||
599 | default: | 606 | default: |
600 | GNUNET_assert(0); | 607 | GNUNET_assert (0); |
601 | } | 608 | } |
602 | #endif | 609 | #endif |
603 | rr->phase = RP_INTERNET_DNS; | 610 | rr->phase = RP_INTERNET_DNS; |
604 | rr->rs = GNUNET_DNSSTUB_resolve(dnsstub, | 611 | rr->rs = GNUNET_DNSSTUB_resolve (dnsstub, |
605 | rr->payload, | 612 | rr->payload, |
606 | rr->payload_length, | 613 | rr->payload_length, |
607 | &process_dns_result, | 614 | &process_dns_result, |
608 | NULL); | 615 | NULL); |
609 | if (NULL == rr->rs) | 616 | if (NULL == rr->rs) |
610 | { | 617 | { |
611 | GNUNET_STATISTICS_update(stats, | 618 | GNUNET_STATISTICS_update (stats, |
612 | gettext_noop("# DNS exit failed (failed to open socket)"), | 619 | gettext_noop ( |
613 | 1, | 620 | "# DNS exit failed (failed to open socket)"), |
614 | GNUNET_NO); | 621 | 1, |
615 | cleanup_rr(rr); | 622 | GNUNET_NO); |
616 | return; | 623 | cleanup_rr (rr); |
617 | } | ||
618 | return; | 624 | return; |
625 | } | ||
626 | return; | ||
619 | 627 | ||
620 | case RP_INTERNET_DNS: | 628 | case RP_INTERNET_DNS: |
621 | rr->phase = RP_MODIFY; | 629 | rr->phase = RP_MODIFY; |
622 | for (cr = clients_head; NULL != cr; cr = cr->next) | 630 | for (cr = clients_head; NULL != cr; cr = cr->next) |
623 | { | 631 | { |
624 | if (0 != (cr->flags & GNUNET_DNS_FLAG_POST_RESOLUTION)) | 632 | if (0 != (cr->flags & GNUNET_DNS_FLAG_POST_RESOLUTION)) |
625 | GNUNET_array_append(rr->client_wait_list, | 633 | GNUNET_array_append (rr->client_wait_list, |
626 | rr->client_wait_list_length, | 634 | rr->client_wait_list_length, |
627 | cr); | 635 | cr); |
628 | } | 636 | } |
629 | next_phase(rr); | 637 | next_phase (rr); |
630 | return; | 638 | return; |
631 | 639 | ||
632 | case RP_MODIFY: | 640 | case RP_MODIFY: |
633 | rr->phase = RP_RESPONSE_MONITOR; | 641 | rr->phase = RP_RESPONSE_MONITOR; |
634 | for (cr = clients_head; NULL != cr; cr = cr->next) | 642 | for (cr = clients_head; NULL != cr; cr = cr->next) |
635 | { | 643 | { |
636 | if (0 != (cr->flags & GNUNET_DNS_FLAG_RESPONSE_MONITOR)) | 644 | if (0 != (cr->flags & GNUNET_DNS_FLAG_RESPONSE_MONITOR)) |
637 | GNUNET_array_append(rr->client_wait_list, | 645 | GNUNET_array_append (rr->client_wait_list, |
638 | rr->client_wait_list_length, | 646 | rr->client_wait_list_length, |
639 | cr); | 647 | cr); |
640 | } | 648 | } |
641 | next_phase(rr); | 649 | next_phase (rr); |
642 | return; | 650 | return; |
643 | 651 | ||
644 | case RP_RESPONSE_MONITOR: | 652 | case RP_RESPONSE_MONITOR: |
645 | request_done(rr); | 653 | request_done (rr); |
646 | break; | 654 | break; |
647 | 655 | ||
648 | case RP_DROP: | 656 | case RP_DROP: |
649 | cleanup_rr(rr); | 657 | cleanup_rr (rr); |
650 | break; | 658 | break; |
651 | 659 | ||
652 | default: | 660 | default: |
653 | GNUNET_break(0); | 661 | GNUNET_break (0); |
654 | cleanup_rr(rr); | 662 | cleanup_rr (rr); |
655 | break; | 663 | break; |
656 | } | 664 | } |
657 | } | 665 | } |
658 | 666 | ||
659 | 667 | ||
@@ -666,18 +674,18 @@ next_phase(struct RequestRecord *rr) | |||
666 | * @return our `struct ClientRecord` | 674 | * @return our `struct ClientRecord` |
667 | */ | 675 | */ |
668 | static void * | 676 | static void * |
669 | client_connect_cb(void *cls, | 677 | client_connect_cb (void *cls, |
670 | struct GNUNET_SERVICE_Client *client, | 678 | struct GNUNET_SERVICE_Client *client, |
671 | struct GNUNET_MQ_Handle *mq) | 679 | struct GNUNET_MQ_Handle *mq) |
672 | { | 680 | { |
673 | struct ClientRecord *cr = cls; | 681 | struct ClientRecord *cr = cls; |
674 | 682 | ||
675 | cr = GNUNET_new(struct ClientRecord); | 683 | cr = GNUNET_new (struct ClientRecord); |
676 | cr->client = client; | 684 | cr->client = client; |
677 | cr->mq = mq; | 685 | cr->mq = mq; |
678 | GNUNET_CONTAINER_DLL_insert(clients_head, | 686 | GNUNET_CONTAINER_DLL_insert (clients_head, |
679 | clients_tail, | 687 | clients_tail, |
680 | cr); | 688 | cr); |
681 | return cr; | 689 | return cr; |
682 | } | 690 | } |
683 | 691 | ||
@@ -690,31 +698,31 @@ client_connect_cb(void *cls, | |||
690 | * @param app_ctx our `struct ClientRecord` | 698 | * @param app_ctx our `struct ClientRecord` |
691 | */ | 699 | */ |
692 | static void | 700 | static void |
693 | client_disconnect_cb(void *cls, | 701 | client_disconnect_cb (void *cls, |
694 | struct GNUNET_SERVICE_Client *client, | 702 | struct GNUNET_SERVICE_Client *client, |
695 | void *app_ctx) | 703 | void *app_ctx) |
696 | { | 704 | { |
697 | struct ClientRecord *cr = app_ctx; | 705 | struct ClientRecord *cr = app_ctx; |
698 | struct RequestRecord *rr; | 706 | struct RequestRecord *rr; |
699 | 707 | ||
700 | GNUNET_CONTAINER_DLL_remove(clients_head, | 708 | GNUNET_CONTAINER_DLL_remove (clients_head, |
701 | clients_tail, | 709 | clients_tail, |
702 | cr); | 710 | cr); |
703 | for (unsigned int i = 0; i < UINT16_MAX; i++) | 711 | for (unsigned int i = 0; i < UINT16_MAX; i++) |
712 | { | ||
713 | rr = &requests[i]; | ||
714 | if (0 == rr->client_wait_list_length) | ||
715 | continue; /* not in use */ | ||
716 | for (unsigned int j = 0; j < rr->client_wait_list_length; j++) | ||
704 | { | 717 | { |
705 | rr = &requests[i]; | 718 | if (rr->client_wait_list[j] == cr) |
706 | if (0 == rr->client_wait_list_length) | 719 | { |
707 | continue; /* not in use */ | 720 | rr->client_wait_list[j] = NULL; |
708 | for (unsigned int j = 0; j < rr->client_wait_list_length; j++) | 721 | next_phase (rr); |
709 | { | 722 | } |
710 | if (rr->client_wait_list[j] == cr) | ||
711 | { | ||
712 | rr->client_wait_list[j] = NULL; | ||
713 | next_phase(rr); | ||
714 | } | ||
715 | } | ||
716 | } | 723 | } |
717 | GNUNET_free(cr); | 724 | } |
725 | GNUNET_free (cr); | ||
718 | } | 726 | } |
719 | 727 | ||
720 | 728 | ||
@@ -727,39 +735,40 @@ client_disconnect_cb(void *cls, | |||
727 | * @param r number of bytes in dns | 735 | * @param r number of bytes in dns |
728 | */ | 736 | */ |
729 | static void | 737 | static void |
730 | process_dns_result(void *cls, | 738 | process_dns_result (void *cls, |
731 | const struct GNUNET_TUN_DnsHeader *dns, | 739 | const struct GNUNET_TUN_DnsHeader *dns, |
732 | size_t r) | 740 | size_t r) |
733 | { | 741 | { |
734 | struct RequestRecord *rr; | 742 | struct RequestRecord *rr; |
735 | 743 | ||
736 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
737 | "Processing DNS result from stub resolver\n"); | 745 | "Processing DNS result from stub resolver\n"); |
738 | GNUNET_assert(NULL == cls); | 746 | GNUNET_assert (NULL == cls); |
739 | if (NULL == dns) | 747 | if (NULL == dns) |
740 | return; /* ignore */ | 748 | return; /* ignore */ |
741 | 749 | ||
742 | rr = &requests[dns->id]; | 750 | rr = &requests[dns->id]; |
743 | if (rr->phase != RP_INTERNET_DNS) | 751 | if (rr->phase != RP_INTERNET_DNS) |
744 | { | 752 | { |
745 | /* unexpected / bogus reply */ | 753 | /* unexpected / bogus reply */ |
746 | GNUNET_STATISTICS_update(stats, | 754 | GNUNET_STATISTICS_update (stats, |
747 | gettext_noop("# External DNS response discarded (no matching request)"), | 755 | gettext_noop ( |
748 | 1, GNUNET_NO); | 756 | "# External DNS response discarded (no matching request)"), |
749 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 757 | 1, GNUNET_NO); |
750 | "Received DNS reply that does not match any pending request. Dropping.\n"); | 758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
751 | return; | 759 | "Received DNS reply that does not match any pending request. Dropping.\n"); |
752 | } | 760 | return; |
753 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 761 | } |
754 | "Got a response from the stub resolver for DNS request %llu intercepted locally!\n", | 762 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
755 | (unsigned long long)rr->request_id); | 763 | "Got a response from the stub resolver for DNS request %llu intercepted locally!\n", |
756 | GNUNET_free_non_null(rr->payload); | 764 | (unsigned long long) rr->request_id); |
757 | rr->payload = GNUNET_malloc(r); | 765 | GNUNET_free_non_null (rr->payload); |
758 | GNUNET_memcpy(rr->payload, | 766 | rr->payload = GNUNET_malloc (r); |
759 | dns, | 767 | GNUNET_memcpy (rr->payload, |
760 | r); | 768 | dns, |
769 | r); | ||
761 | rr->payload_length = r; | 770 | rr->payload_length = r; |
762 | next_phase(rr); | 771 | next_phase (rr); |
763 | } | 772 | } |
764 | 773 | ||
765 | 774 | ||
@@ -770,13 +779,13 @@ process_dns_result(void *cls, | |||
770 | * @param reg the init message | 779 | * @param reg the init message |
771 | */ | 780 | */ |
772 | static void | 781 | static void |
773 | handle_client_init(void *cls, | 782 | handle_client_init (void *cls, |
774 | const struct GNUNET_DNS_Register *reg) | 783 | const struct GNUNET_DNS_Register *reg) |
775 | { | 784 | { |
776 | struct ClientRecord *cr = cls; | 785 | struct ClientRecord *cr = cls; |
777 | 786 | ||
778 | cr->flags = (enum GNUNET_DNS_Flags)ntohl(reg->flags); | 787 | cr->flags = (enum GNUNET_DNS_Flags) ntohl (reg->flags); |
779 | GNUNET_SERVICE_client_continue(cr->client); | 788 | GNUNET_SERVICE_client_continue (cr->client); |
780 | } | 789 | } |
781 | 790 | ||
782 | 791 | ||
@@ -788,8 +797,8 @@ handle_client_init(void *cls, | |||
788 | * @return #GNUNET_OK (always fine) | 797 | * @return #GNUNET_OK (always fine) |
789 | */ | 798 | */ |
790 | static int | 799 | static int |
791 | check_client_response(void *cls, | 800 | check_client_response (void *cls, |
792 | const struct GNUNET_DNS_Response *resp) | 801 | const struct GNUNET_DNS_Response *resp) |
793 | { | 802 | { |
794 | return GNUNET_OK; /* any payload is acceptable */ | 803 | return GNUNET_OK; /* any payload is acceptable */ |
795 | } | 804 | } |
@@ -802,89 +811,93 @@ check_client_response(void *cls, | |||
802 | * @param resp the response | 811 | * @param resp the response |
803 | */ | 812 | */ |
804 | static void | 813 | static void |
805 | handle_client_response(void *cls, | 814 | handle_client_response (void *cls, |
806 | const struct GNUNET_DNS_Response *resp) | 815 | const struct GNUNET_DNS_Response *resp) |
807 | { | 816 | { |
808 | struct ClientRecord *cr = cls; | 817 | struct ClientRecord *cr = cls; |
809 | struct RequestRecord *rr; | 818 | struct RequestRecord *rr; |
810 | uint16_t msize; | 819 | uint16_t msize; |
811 | uint16_t off; | 820 | uint16_t off; |
812 | 821 | ||
813 | msize = ntohs(resp->header.size); | 822 | msize = ntohs (resp->header.size); |
814 | off = (uint16_t)resp->request_id; | 823 | off = (uint16_t) resp->request_id; |
815 | rr = &requests[off]; | 824 | rr = &requests[off]; |
816 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 825 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
817 | "Received DNS response with ID %llu from local client!\n", | 826 | "Received DNS response with ID %llu from local client!\n", |
818 | (unsigned long long)resp->request_id); | 827 | (unsigned long long) resp->request_id); |
819 | if (rr->request_id != resp->request_id) | 828 | if (rr->request_id != resp->request_id) |
820 | { | 829 | { |
821 | GNUNET_STATISTICS_update(stats, | 830 | GNUNET_STATISTICS_update (stats, |
822 | gettext_noop("# Client response discarded (no matching request)"), | 831 | gettext_noop ( |
823 | 1, | 832 | "# Client response discarded (no matching request)"), |
824 | GNUNET_NO); | 833 | 1, |
825 | GNUNET_SERVICE_client_continue(cr->client); | 834 | GNUNET_NO); |
826 | return; | 835 | GNUNET_SERVICE_client_continue (cr->client); |
827 | } | 836 | return; |
837 | } | ||
828 | for (unsigned int i = 0; i < rr->client_wait_list_length; i++) | 838 | for (unsigned int i = 0; i < rr->client_wait_list_length; i++) |
839 | { | ||
840 | if (NULL == rr->client_wait_list[i]) | ||
841 | continue; | ||
842 | if (rr->client_wait_list[i] != cr) | ||
843 | continue; | ||
844 | rr->client_wait_list[i] = NULL; | ||
845 | switch (ntohl (resp->drop_flag)) | ||
829 | { | 846 | { |
830 | if (NULL == rr->client_wait_list[i]) | 847 | case 0: /* drop */ |
831 | continue; | 848 | rr->phase = RP_DROP; |
832 | if (rr->client_wait_list[i] != cr) | 849 | break; |
833 | continue; | 850 | |
834 | rr->client_wait_list[i] = NULL; | 851 | case 1: /* no change */ |
835 | switch (ntohl(resp->drop_flag)) | 852 | break; |
836 | { | 853 | |
837 | case 0: /* drop */ | 854 | case 2: /* update */ |
838 | rr->phase = RP_DROP; | 855 | msize -= sizeof(struct GNUNET_DNS_Response); |
839 | break; | 856 | if ((sizeof(struct GNUNET_TUN_DnsHeader) > msize) || |
840 | 857 | (RP_REQUEST_MONITOR == rr->phase) || | |
841 | case 1: /* no change */ | 858 | (RP_RESPONSE_MONITOR == rr->phase)) |
842 | break; | 859 | { |
843 | 860 | GNUNET_break (0); | |
844 | case 2: /* update */ | 861 | GNUNET_SERVICE_client_drop (cr->client); |
845 | msize -= sizeof(struct GNUNET_DNS_Response); | 862 | next_phase (rr); |
846 | if ((sizeof(struct GNUNET_TUN_DnsHeader) > msize) || | 863 | return; |
847 | (RP_REQUEST_MONITOR == rr->phase) || | 864 | } |
848 | (RP_RESPONSE_MONITOR == rr->phase)) | 865 | GNUNET_free_non_null (rr->payload); |
849 | { | 866 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
850 | GNUNET_break(0); | 867 | "Changing DNS reply according to client specifications\n"); |
851 | GNUNET_SERVICE_client_drop(cr->client); | 868 | rr->payload = GNUNET_malloc (msize); |
852 | next_phase(rr); | 869 | rr->payload_length = msize; |
853 | return; | 870 | GNUNET_memcpy (rr->payload, &resp[1], msize); |
854 | } | 871 | if (rr->phase == RP_QUERY) |
855 | GNUNET_free_non_null(rr->payload); | 872 | { |
856 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 873 | /* clear wait list, we're moving to MODIFY phase next */ |
857 | "Changing DNS reply according to client specifications\n"); | 874 | GNUNET_array_grow (rr->client_wait_list, |
858 | rr->payload = GNUNET_malloc(msize); | 875 | rr->client_wait_list_length, |
859 | rr->payload_length = msize; | 876 | 0); |
860 | GNUNET_memcpy(rr->payload, &resp[1], msize); | 877 | } |
861 | if (rr->phase == RP_QUERY) | 878 | /* if query changed to answer, move past DNS resolution phase... */ |
862 | { | 879 | if ((RP_QUERY == rr->phase) && |
863 | /* clear wait list, we're moving to MODIFY phase next */ | 880 | (rr->payload_length > sizeof(struct GNUNET_TUN_DnsHeader)) && |
864 | GNUNET_array_grow(rr->client_wait_list, | 881 | ( ((struct GNUNET_TUN_DnsFlags*) &(((struct |
865 | rr->client_wait_list_length, | 882 | GNUNET_TUN_DnsHeader*) rr-> |
866 | 0); | 883 | payload)->flags))-> |
867 | } | 884 | query_or_response == 1) ) |
868 | /* if query changed to answer, move past DNS resolution phase... */ | 885 | { |
869 | if ((RP_QUERY == rr->phase) && | 886 | rr->phase = RP_INTERNET_DNS; |
870 | (rr->payload_length > sizeof(struct GNUNET_TUN_DnsHeader)) && | 887 | GNUNET_array_grow (rr->client_wait_list, |
871 | ((struct GNUNET_TUN_DnsFlags*)&(((struct GNUNET_TUN_DnsHeader*)rr->payload)->flags))->query_or_response == 1) | 888 | rr->client_wait_list_length, |
872 | { | 889 | 0); |
873 | rr->phase = RP_INTERNET_DNS; | 890 | } |
874 | GNUNET_array_grow(rr->client_wait_list, | 891 | break; |
875 | rr->client_wait_list_length, | ||
876 | 0); | ||
877 | } | ||
878 | break; | ||
879 | } | ||
880 | next_phase(rr); | ||
881 | GNUNET_SERVICE_client_continue(cr->client); | ||
882 | return; | ||
883 | } | 892 | } |
893 | next_phase (rr); | ||
894 | GNUNET_SERVICE_client_continue (cr->client); | ||
895 | return; | ||
896 | } | ||
884 | /* odd, client was not on our list for the request, that ought | 897 | /* odd, client was not on our list for the request, that ought |
885 | to be an error */ | 898 | to be an error */ |
886 | GNUNET_break(0); | 899 | GNUNET_break (0); |
887 | GNUNET_SERVICE_client_drop(cr->client); | 900 | GNUNET_SERVICE_client_drop (cr->client); |
888 | } | 901 | } |
889 | 902 | ||
890 | 903 | ||
@@ -896,8 +909,8 @@ handle_client_response(void *cls, | |||
896 | * @param message the actual message, a DNS request we should handle | 909 | * @param message the actual message, a DNS request we should handle |
897 | */ | 910 | */ |
898 | static int | 911 | static int |
899 | process_helper_messages(void *cls, | 912 | process_helper_messages (void *cls, |
900 | const struct GNUNET_MessageHeader *message) | 913 | const struct GNUNET_MessageHeader *message) |
901 | { | 914 | { |
902 | uint16_t msize; | 915 | uint16_t msize; |
903 | const struct GNUNET_TUN_Layer2PacketHeader *tun; | 916 | const struct GNUNET_TUN_Layer2PacketHeader *tun; |
@@ -911,95 +924,103 @@ process_helper_messages(void *cls, | |||
911 | struct sockaddr_in *dsta4; | 924 | struct sockaddr_in *dsta4; |
912 | struct sockaddr_in6 *dsta6; | 925 | struct sockaddr_in6 *dsta6; |
913 | 926 | ||
914 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 927 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
915 | "Intercepted message via DNS hijacker\n"); | 928 | "Intercepted message via DNS hijacker\n"); |
916 | msize = ntohs(message->size); | 929 | msize = ntohs (message->size); |
917 | if (msize < sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct GNUNET_TUN_IPv4Header)) | 930 | if (msize < sizeof(struct GNUNET_MessageHeader) + sizeof(struct |
918 | { | 931 | GNUNET_TUN_Layer2PacketHeader) |
919 | /* non-IP packet received on TUN!? */ | 932 | + sizeof(struct GNUNET_TUN_IPv4Header)) |
920 | GNUNET_break(0); | 933 | { |
921 | return GNUNET_OK; | 934 | /* non-IP packet received on TUN!? */ |
922 | } | 935 | GNUNET_break (0); |
936 | return GNUNET_OK; | ||
937 | } | ||
923 | msize -= sizeof(struct GNUNET_MessageHeader); | 938 | msize -= sizeof(struct GNUNET_MessageHeader); |
924 | tun = (const struct GNUNET_TUN_Layer2PacketHeader *)&message[1]; | 939 | tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; |
925 | msize -= sizeof(struct GNUNET_TUN_Layer2PacketHeader); | 940 | msize -= sizeof(struct GNUNET_TUN_Layer2PacketHeader); |
926 | switch (ntohs(tun->proto)) | 941 | switch (ntohs (tun->proto)) |
942 | { | ||
943 | case ETH_P_IPV4: | ||
944 | ip4 = (const struct GNUNET_TUN_IPv4Header *) &tun[1]; | ||
945 | ip6 = NULL; /* make compiler happy */ | ||
946 | if ((msize < sizeof(struct GNUNET_TUN_IPv4Header)) || | ||
947 | (ip4->version != 4) || | ||
948 | (ip4->header_length != sizeof(struct GNUNET_TUN_IPv4Header) / 4) || | ||
949 | (ntohs (ip4->total_length) != msize) || | ||
950 | (ip4->protocol != IPPROTO_UDP)) | ||
927 | { | 951 | { |
928 | case ETH_P_IPV4: | 952 | /* non-IP/UDP packet received on TUN (or with options) */ |
929 | ip4 = (const struct GNUNET_TUN_IPv4Header *)&tun[1]; | 953 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
930 | ip6 = NULL; /* make compiler happy */ | 954 | _ ("Received malformed IPv4-UDP packet on TUN interface.\n")); |
931 | if ((msize < sizeof(struct GNUNET_TUN_IPv4Header)) || | ||
932 | (ip4->version != 4) || | ||
933 | (ip4->header_length != sizeof(struct GNUNET_TUN_IPv4Header) / 4) || | ||
934 | (ntohs(ip4->total_length) != msize) || | ||
935 | (ip4->protocol != IPPROTO_UDP)) | ||
936 | { | ||
937 | /* non-IP/UDP packet received on TUN (or with options) */ | ||
938 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
939 | _("Received malformed IPv4-UDP packet on TUN interface.\n")); | ||
940 | return GNUNET_OK; | ||
941 | } | ||
942 | udp = (const struct GNUNET_TUN_UdpHeader*)&ip4[1]; | ||
943 | msize -= sizeof(struct GNUNET_TUN_IPv4Header); | ||
944 | break; | ||
945 | |||
946 | case ETH_P_IPV6: | ||
947 | ip4 = NULL; /* make compiler happy */ | ||
948 | ip6 = (const struct GNUNET_TUN_IPv6Header *)&tun[1]; | ||
949 | if ((msize < sizeof(struct GNUNET_TUN_IPv6Header)) || | ||
950 | (ip6->version != 6) || | ||
951 | (ntohs(ip6->payload_length) != msize - sizeof(struct GNUNET_TUN_IPv6Header)) || | ||
952 | (ip6->next_header != IPPROTO_UDP)) | ||
953 | { | ||
954 | /* non-IP/UDP packet received on TUN (or with extensions) */ | ||
955 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
956 | _("Received malformed IPv6-UDP packet on TUN interface.\n")); | ||
957 | return GNUNET_OK; | ||
958 | } | ||
959 | udp = (const struct GNUNET_TUN_UdpHeader *)&ip6[1]; | ||
960 | msize -= sizeof(struct GNUNET_TUN_IPv6Header); | ||
961 | break; | ||
962 | |||
963 | default: | ||
964 | /* non-IP packet received on TUN!? */ | ||
965 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
966 | _("Got non-IP packet with %u bytes and protocol %u from TUN\n"), | ||
967 | (unsigned int)msize, | ||
968 | ntohs(tun->proto)); | ||
969 | return GNUNET_OK; | 955 | return GNUNET_OK; |
970 | } | 956 | } |
971 | if ((msize <= sizeof(struct GNUNET_TUN_UdpHeader) + sizeof(struct GNUNET_TUN_DnsHeader)) || | 957 | udp = (const struct GNUNET_TUN_UdpHeader*) &ip4[1]; |
972 | (DNS_PORT != ntohs(udp->destination_port))) | 958 | msize -= sizeof(struct GNUNET_TUN_IPv4Header); |
959 | break; | ||
960 | |||
961 | case ETH_P_IPV6: | ||
962 | ip4 = NULL; /* make compiler happy */ | ||
963 | ip6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1]; | ||
964 | if ((msize < sizeof(struct GNUNET_TUN_IPv6Header)) || | ||
965 | (ip6->version != 6) || | ||
966 | (ntohs (ip6->payload_length) != msize - sizeof(struct | ||
967 | GNUNET_TUN_IPv6Header)) | ||
968 | || | ||
969 | (ip6->next_header != IPPROTO_UDP)) | ||
973 | { | 970 | { |
974 | /* non-DNS packet received on TUN, ignore */ | 971 | /* non-IP/UDP packet received on TUN (or with extensions) */ |
975 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 972 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
976 | _("DNS interceptor got non-DNS packet (dropped)\n")); | 973 | _ ("Received malformed IPv6-UDP packet on TUN interface.\n")); |
977 | GNUNET_STATISTICS_update(stats, | ||
978 | gettext_noop("# Non-DNS UDP packet received via TUN interface"), | ||
979 | 1, GNUNET_NO); | ||
980 | return GNUNET_OK; | 974 | return GNUNET_OK; |
981 | } | 975 | } |
976 | udp = (const struct GNUNET_TUN_UdpHeader *) &ip6[1]; | ||
977 | msize -= sizeof(struct GNUNET_TUN_IPv6Header); | ||
978 | break; | ||
979 | |||
980 | default: | ||
981 | /* non-IP packet received on TUN!? */ | ||
982 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
983 | _ ( | ||
984 | "Got non-IP packet with %u bytes and protocol %u from TUN\n"), | ||
985 | (unsigned int) msize, | ||
986 | ntohs (tun->proto)); | ||
987 | return GNUNET_OK; | ||
988 | } | ||
989 | if ((msize <= sizeof(struct GNUNET_TUN_UdpHeader) + sizeof(struct | ||
990 | GNUNET_TUN_DnsHeader)) | ||
991 | || | ||
992 | (DNS_PORT != ntohs (udp->destination_port))) | ||
993 | { | ||
994 | /* non-DNS packet received on TUN, ignore */ | ||
995 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
996 | _ ("DNS interceptor got non-DNS packet (dropped)\n")); | ||
997 | GNUNET_STATISTICS_update (stats, | ||
998 | gettext_noop ( | ||
999 | "# Non-DNS UDP packet received via TUN interface"), | ||
1000 | 1, GNUNET_NO); | ||
1001 | return GNUNET_OK; | ||
1002 | } | ||
982 | msize -= sizeof(struct GNUNET_TUN_UdpHeader); | 1003 | msize -= sizeof(struct GNUNET_TUN_UdpHeader); |
983 | dns = (const struct GNUNET_TUN_DnsHeader*)&udp[1]; | 1004 | dns = (const struct GNUNET_TUN_DnsHeader*) &udp[1]; |
984 | rr = &requests[dns->id]; | 1005 | rr = &requests[dns->id]; |
985 | 1006 | ||
986 | /* clean up from previous request */ | 1007 | /* clean up from previous request */ |
987 | GNUNET_free_non_null(rr->payload); | 1008 | GNUNET_free_non_null (rr->payload); |
988 | rr->payload = NULL; | 1009 | rr->payload = NULL; |
989 | GNUNET_array_grow(rr->client_wait_list, | 1010 | GNUNET_array_grow (rr->client_wait_list, |
990 | rr->client_wait_list_length, | 1011 | rr->client_wait_list_length, |
991 | 0); | 1012 | 0); |
992 | 1013 | ||
993 | /* setup new request */ | 1014 | /* setup new request */ |
994 | rr->phase = RP_INIT; | 1015 | rr->phase = RP_INIT; |
995 | switch (ntohs(tun->proto)) | 1016 | switch (ntohs (tun->proto)) |
996 | { | 1017 | { |
997 | case ETH_P_IPV4: | 1018 | case ETH_P_IPV4: |
998 | { | 1019 | { |
999 | srca4 = (struct sockaddr_in*)&rr->src_addr; | 1020 | srca4 = (struct sockaddr_in*) &rr->src_addr; |
1000 | dsta4 = (struct sockaddr_in*)&rr->dst_addr; | 1021 | dsta4 = (struct sockaddr_in*) &rr->dst_addr; |
1001 | memset(srca4, 0, sizeof(struct sockaddr_in)); | 1022 | memset (srca4, 0, sizeof(struct sockaddr_in)); |
1002 | memset(dsta4, 0, sizeof(struct sockaddr_in)); | 1023 | memset (dsta4, 0, sizeof(struct sockaddr_in)); |
1003 | srca4->sin_family = AF_INET; | 1024 | srca4->sin_family = AF_INET; |
1004 | dsta4->sin_family = AF_INET; | 1025 | dsta4->sin_family = AF_INET; |
1005 | srca4->sin_addr = ip4->source_address; | 1026 | srca4->sin_addr = ip4->source_address; |
@@ -1013,12 +1034,12 @@ process_helper_messages(void *cls, | |||
1013 | } | 1034 | } |
1014 | break; | 1035 | break; |
1015 | 1036 | ||
1016 | case ETH_P_IPV6: | 1037 | case ETH_P_IPV6: |
1017 | { | 1038 | { |
1018 | srca6 = (struct sockaddr_in6*)&rr->src_addr; | 1039 | srca6 = (struct sockaddr_in6*) &rr->src_addr; |
1019 | dsta6 = (struct sockaddr_in6*)&rr->dst_addr; | 1040 | dsta6 = (struct sockaddr_in6*) &rr->dst_addr; |
1020 | memset(srca6, 0, sizeof(struct sockaddr_in6)); | 1041 | memset (srca6, 0, sizeof(struct sockaddr_in6)); |
1021 | memset(dsta6, 0, sizeof(struct sockaddr_in6)); | 1042 | memset (dsta6, 0, sizeof(struct sockaddr_in6)); |
1022 | srca6->sin6_family = AF_INET6; | 1043 | srca6->sin6_family = AF_INET6; |
1023 | dsta6->sin6_family = AF_INET6; | 1044 | dsta6->sin6_family = AF_INET6; |
1024 | srca6->sin6_addr = ip6->source_address; | 1045 | srca6->sin6_addr = ip6->source_address; |
@@ -1032,22 +1053,23 @@ process_helper_messages(void *cls, | |||
1032 | } | 1053 | } |
1033 | break; | 1054 | break; |
1034 | 1055 | ||
1035 | default: | 1056 | default: |
1036 | GNUNET_assert(0); | 1057 | GNUNET_assert (0); |
1037 | } | 1058 | } |
1038 | rr->payload = GNUNET_malloc(msize); | 1059 | rr->payload = GNUNET_malloc (msize); |
1039 | rr->payload_length = msize; | 1060 | rr->payload_length = msize; |
1040 | GNUNET_memcpy(rr->payload, dns, msize); | 1061 | GNUNET_memcpy (rr->payload, dns, msize); |
1041 | rr->request_id = dns->id | (request_id_gen << 16); | 1062 | rr->request_id = dns->id | (request_id_gen << 16); |
1042 | request_id_gen++; | 1063 | request_id_gen++; |
1043 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1064 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1044 | "Creating new DNS request %llu\n", | 1065 | "Creating new DNS request %llu\n", |
1045 | (unsigned long long)rr->request_id); | 1066 | (unsigned long long) rr->request_id); |
1046 | GNUNET_STATISTICS_update(stats, | 1067 | GNUNET_STATISTICS_update (stats, |
1047 | gettext_noop("# DNS requests received via TUN interface"), | 1068 | gettext_noop ( |
1048 | 1, GNUNET_NO); | 1069 | "# DNS requests received via TUN interface"), |
1070 | 1, GNUNET_NO); | ||
1049 | /* start request processing state machine */ | 1071 | /* start request processing state machine */ |
1050 | next_phase(rr); | 1072 | next_phase (rr); |
1051 | return GNUNET_OK; | 1073 | return GNUNET_OK; |
1052 | } | 1074 | } |
1053 | 1075 | ||
@@ -1058,9 +1080,9 @@ process_helper_messages(void *cls, | |||
1058 | * @param service the initialized service | 1080 | * @param service the initialized service |
1059 | */ | 1081 | */ |
1060 | static void | 1082 | static void |
1061 | run(void *cls, | 1083 | run (void *cls, |
1062 | const struct GNUNET_CONFIGURATION_Handle *cfg_, | 1084 | const struct GNUNET_CONFIGURATION_Handle *cfg_, |
1063 | struct GNUNET_SERVICE_Handle *service) | 1085 | struct GNUNET_SERVICE_Handle *service) |
1064 | { | 1086 | { |
1065 | char *ifc_name; | 1087 | char *ifc_name; |
1066 | char *ipv4addr; | 1088 | char *ipv4addr; |
@@ -1072,126 +1094,126 @@ run(void *cls, | |||
1072 | int nortsetup; | 1094 | int nortsetup; |
1073 | 1095 | ||
1074 | cfg = cfg_; | 1096 | cfg = cfg_; |
1075 | stats = GNUNET_STATISTICS_create("dns", cfg); | 1097 | stats = GNUNET_STATISTICS_create ("dns", cfg); |
1076 | GNUNET_SCHEDULER_add_shutdown(&cleanup_task, | 1098 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, |
1077 | cls); | 1099 | cls); |
1078 | dnsstub = GNUNET_DNSSTUB_start(128); | 1100 | dnsstub = GNUNET_DNSSTUB_start (128); |
1079 | /* TODO: support multiple DNS_EXIT servers being configured */ | 1101 | /* TODO: support multiple DNS_EXIT servers being configured */ |
1080 | /* TODO: see above TODO on using DNS server from original packet. | 1102 | /* TODO: see above TODO on using DNS server from original packet. |
1081 | Not sure which is best... */ | 1103 | Not sure which is best... */ |
1082 | dns_exit = NULL; | 1104 | dns_exit = NULL; |
1083 | if ((GNUNET_OK != | 1105 | if ((GNUNET_OK != |
1084 | GNUNET_CONFIGURATION_get_value_string(cfg, | 1106 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1085 | "dns", | 1107 | "dns", |
1086 | "DNS_EXIT", | 1108 | "DNS_EXIT", |
1087 | &dns_exit)) || | 1109 | &dns_exit)) || |
1088 | (GNUNET_OK != | 1110 | (GNUNET_OK != |
1089 | GNUNET_DNSSTUB_add_dns_ip(dnsstub, | 1111 | GNUNET_DNSSTUB_add_dns_ip (dnsstub, |
1090 | dns_exit))) | 1112 | dns_exit))) |
1091 | { | 1113 | { |
1092 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 1114 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
1093 | "dns", | 1115 | "dns", |
1094 | "DNS_EXIT", | 1116 | "DNS_EXIT", |
1095 | _("need a valid IPv4 or IPv6 address\n")); | 1117 | _ ("need a valid IPv4 or IPv6 address\n")); |
1096 | GNUNET_free_non_null(dns_exit); | 1118 | GNUNET_free_non_null (dns_exit); |
1097 | } | 1119 | } |
1098 | binary = GNUNET_OS_get_suid_binary_path(cfg, "gnunet-helper-dns"); | 1120 | binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-dns"); |
1099 | 1121 | ||
1100 | if (GNUNET_YES != | 1122 | if (GNUNET_YES != |
1101 | GNUNET_OS_check_helper_binary(binary, | 1123 | GNUNET_OS_check_helper_binary (binary, |
1102 | GNUNET_YES, | 1124 | GNUNET_YES, |
1103 | NULL)) // TODO: once we have a windows-testcase, add test parameters here | 1125 | NULL)) // TODO: once we have a windows-testcase, add test parameters here |
1104 | { | 1126 | { |
1105 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1127 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1106 | _("`%s' is not SUID or the path is invalid, " | 1128 | _ ("`%s' is not SUID or the path is invalid, " |
1107 | "will not run DNS interceptor\n"), | 1129 | "will not run DNS interceptor\n"), |
1108 | binary); | 1130 | binary); |
1109 | global_ret = 1; | 1131 | global_ret = 1; |
1110 | GNUNET_free(binary); | 1132 | GNUNET_free (binary); |
1111 | return; | 1133 | return; |
1112 | } | 1134 | } |
1113 | GNUNET_free(binary); | 1135 | GNUNET_free (binary); |
1114 | 1136 | ||
1115 | helper_argv[0] = GNUNET_strdup("gnunet-dns"); | 1137 | helper_argv[0] = GNUNET_strdup ("gnunet-dns"); |
1116 | if (GNUNET_SYSERR == | 1138 | if (GNUNET_SYSERR == |
1117 | GNUNET_CONFIGURATION_get_value_string(cfg, | 1139 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1118 | "dns", | 1140 | "dns", |
1119 | "IFNAME", | 1141 | "IFNAME", |
1120 | &ifc_name)) | 1142 | &ifc_name)) |
1121 | { | 1143 | { |
1122 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1123 | "No entry 'IFNAME' in configuration!\n"); | 1145 | "No entry 'IFNAME' in configuration!\n"); |
1124 | GNUNET_free(binary); | 1146 | GNUNET_free (binary); |
1125 | GNUNET_SCHEDULER_shutdown(); | 1147 | GNUNET_SCHEDULER_shutdown (); |
1126 | return; | 1148 | return; |
1127 | } | 1149 | } |
1128 | helper_argv[1] = ifc_name; | 1150 | helper_argv[1] = ifc_name; |
1129 | if ((GNUNET_SYSERR == | 1151 | if ((GNUNET_SYSERR == |
1130 | GNUNET_CONFIGURATION_get_value_string(cfg, | 1152 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1131 | "dns", | 1153 | "dns", |
1132 | "IPV6ADDR", | 1154 | "IPV6ADDR", |
1133 | &ipv6addr))) | 1155 | &ipv6addr))) |
1134 | { | 1156 | { |
1135 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1157 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1136 | "No entry 'IPV6ADDR' in configuration!\n"); | 1158 | "No entry 'IPV6ADDR' in configuration!\n"); |
1137 | GNUNET_free(binary); | 1159 | GNUNET_free (binary); |
1138 | GNUNET_SCHEDULER_shutdown(); | 1160 | GNUNET_SCHEDULER_shutdown (); |
1139 | return; | 1161 | return; |
1140 | } | 1162 | } |
1141 | helper_argv[2] = ipv6addr; | 1163 | helper_argv[2] = ipv6addr; |
1142 | if (GNUNET_SYSERR == | 1164 | if (GNUNET_SYSERR == |
1143 | GNUNET_CONFIGURATION_get_value_string(cfg, | 1165 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1144 | "dns", | 1166 | "dns", |
1145 | "IPV6PREFIX", | 1167 | "IPV6PREFIX", |
1146 | &ipv6prefix)) | 1168 | &ipv6prefix)) |
1147 | { | 1169 | { |
1148 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1149 | "No entry 'IPV6PREFIX' in configuration!\n"); | 1171 | "No entry 'IPV6PREFIX' in configuration!\n"); |
1150 | GNUNET_free(binary); | 1172 | GNUNET_free (binary); |
1151 | GNUNET_SCHEDULER_shutdown(); | 1173 | GNUNET_SCHEDULER_shutdown (); |
1152 | return; | 1174 | return; |
1153 | } | 1175 | } |
1154 | helper_argv[3] = ipv6prefix; | 1176 | helper_argv[3] = ipv6prefix; |
1155 | 1177 | ||
1156 | if (GNUNET_SYSERR == | 1178 | if (GNUNET_SYSERR == |
1157 | GNUNET_CONFIGURATION_get_value_string(cfg, | 1179 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1158 | "dns", | 1180 | "dns", |
1159 | "IPV4ADDR", | 1181 | "IPV4ADDR", |
1160 | &ipv4addr)) | 1182 | &ipv4addr)) |
1161 | { | 1183 | { |
1162 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1163 | "No entry 'IPV4ADDR' in configuration!\n"); | 1185 | "No entry 'IPV4ADDR' in configuration!\n"); |
1164 | GNUNET_free(binary); | 1186 | GNUNET_free (binary); |
1165 | GNUNET_SCHEDULER_shutdown(); | 1187 | GNUNET_SCHEDULER_shutdown (); |
1166 | return; | 1188 | return; |
1167 | } | 1189 | } |
1168 | helper_argv[4] = ipv4addr; | 1190 | helper_argv[4] = ipv4addr; |
1169 | if (GNUNET_SYSERR == | 1191 | if (GNUNET_SYSERR == |
1170 | GNUNET_CONFIGURATION_get_value_string(cfg, "dns", "IPV4MASK", | 1192 | GNUNET_CONFIGURATION_get_value_string (cfg, "dns", "IPV4MASK", |
1171 | &ipv4mask)) | 1193 | &ipv4mask)) |
1172 | { | 1194 | { |
1173 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1174 | "No entry 'IPV4MASK' in configuration!\n"); | 1196 | "No entry 'IPV4MASK' in configuration!\n"); |
1175 | GNUNET_free(binary); | 1197 | GNUNET_free (binary); |
1176 | GNUNET_SCHEDULER_shutdown(); | 1198 | GNUNET_SCHEDULER_shutdown (); |
1177 | return; | 1199 | return; |
1178 | } | 1200 | } |
1179 | helper_argv[5] = ipv4mask; | 1201 | helper_argv[5] = ipv4mask; |
1180 | 1202 | ||
1181 | nortsetup = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dns", | 1203 | nortsetup = GNUNET_CONFIGURATION_get_value_yesno (cfg, "dns", |
1182 | "SKIP_ROUTING_SETUP"); | 1204 | "SKIP_ROUTING_SETUP"); |
1183 | if (GNUNET_YES == nortsetup) | 1205 | if (GNUNET_YES == nortsetup) |
1184 | helper_argv[6] = GNUNET_strdup("1"); | 1206 | helper_argv[6] = GNUNET_strdup ("1"); |
1185 | else | 1207 | else |
1186 | helper_argv[6] = GNUNET_strdup("0"); | 1208 | helper_argv[6] = GNUNET_strdup ("0"); |
1187 | 1209 | ||
1188 | helper_argv[7] = NULL; | 1210 | helper_argv[7] = NULL; |
1189 | hijacker = GNUNET_HELPER_start(GNUNET_NO, | 1211 | hijacker = GNUNET_HELPER_start (GNUNET_NO, |
1190 | binary, | 1212 | binary, |
1191 | helper_argv, | 1213 | helper_argv, |
1192 | &process_helper_messages, | 1214 | &process_helper_messages, |
1193 | NULL, NULL); | 1215 | NULL, NULL); |
1194 | GNUNET_free(binary); | 1216 | GNUNET_free (binary); |
1195 | } | 1217 | } |
1196 | 1218 | ||
1197 | 1219 | ||
@@ -1205,15 +1227,15 @@ GNUNET_SERVICE_MAIN | |||
1205 | &client_connect_cb, | 1227 | &client_connect_cb, |
1206 | &client_disconnect_cb, | 1228 | &client_disconnect_cb, |
1207 | NULL, | 1229 | NULL, |
1208 | GNUNET_MQ_hd_fixed_size(client_init, | 1230 | GNUNET_MQ_hd_fixed_size (client_init, |
1209 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT, | 1231 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT, |
1210 | struct GNUNET_DNS_Register, | 1232 | struct GNUNET_DNS_Register, |
1211 | NULL), | 1233 | NULL), |
1212 | GNUNET_MQ_hd_var_size(client_response, | 1234 | GNUNET_MQ_hd_var_size (client_response, |
1213 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, | 1235 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, |
1214 | struct GNUNET_DNS_Response, | 1236 | struct GNUNET_DNS_Response, |
1215 | NULL), | 1237 | NULL), |
1216 | GNUNET_MQ_handler_end()); | 1238 | GNUNET_MQ_handler_end ()); |
1217 | 1239 | ||
1218 | 1240 | ||
1219 | /* FIXME: this might need a port on systems without 'getresgid' */ | 1241 | /* FIXME: this might need a port on systems without 'getresgid' */ |
@@ -1222,28 +1244,28 @@ GNUNET_SERVICE_MAIN | |||
1222 | * Enable use of SGID capabilities on POSIX | 1244 | * Enable use of SGID capabilities on POSIX |
1223 | */ | 1245 | */ |
1224 | void __attribute__ ((constructor)) | 1246 | void __attribute__ ((constructor)) |
1225 | GNUNET_DNS_init() | 1247 | GNUNET_DNS_init () |
1226 | { | 1248 | { |
1227 | gid_t rgid; | 1249 | gid_t rgid; |
1228 | gid_t egid; | 1250 | gid_t egid; |
1229 | gid_t sgid; | 1251 | gid_t sgid; |
1230 | 1252 | ||
1231 | if (-1 == getresgid(&rgid, | 1253 | if (-1 == getresgid (&rgid, |
1232 | &egid, | 1254 | &egid, |
1233 | &sgid)) | 1255 | &sgid)) |
1234 | { | 1256 | { |
1235 | fprintf(stderr, | 1257 | fprintf (stderr, |
1236 | "getresgid failed: %s\n", | 1258 | "getresgid failed: %s\n", |
1237 | strerror(errno)); | 1259 | strerror (errno)); |
1238 | } | 1260 | } |
1239 | else if (sgid != rgid) | 1261 | else if (sgid != rgid) |
1240 | { | 1262 | { |
1241 | if (-1 == setregid(sgid, | 1263 | if (-1 == setregid (sgid, |
1242 | sgid)) | 1264 | sgid)) |
1243 | fprintf(stderr, | 1265 | fprintf (stderr, |
1244 | "setregid failed: %s\n", | 1266 | "setregid failed: %s\n", |
1245 | strerror(errno)); | 1267 | strerror (errno)); |
1246 | } | 1268 | } |
1247 | } | 1269 | } |
1248 | #endif | 1270 | #endif |
1249 | 1271 | ||
diff --git a/src/dns/gnunet-zonewalk.c b/src/dns/gnunet-zonewalk.c index 2968d0209..91f8456df 100644 --- a/src/dns/gnunet-zonewalk.c +++ b/src/dns/gnunet-zonewalk.c | |||
@@ -31,7 +31,8 @@ | |||
31 | /** | 31 | /** |
32 | * Request we should make. | 32 | * Request we should make. |
33 | */ | 33 | */ |
34 | struct Request { | 34 | struct Request |
35 | { | ||
35 | /** | 36 | /** |
36 | * Requests are kept in a DLL. | 37 | * Requests are kept in a DLL. |
37 | */ | 38 | */ |
@@ -143,155 +144,155 @@ static struct GNUNET_SCHEDULER_Task *t; | |||
143 | * @param rec response | 144 | * @param rec response |
144 | */ | 145 | */ |
145 | static void | 146 | static void |
146 | process_record(struct Request *req, | 147 | process_record (struct Request *req, |
147 | struct GNUNET_DNSPARSER_Record *rec) | 148 | struct GNUNET_DNSPARSER_Record *rec) |
148 | { | 149 | { |
149 | char buf[INET6_ADDRSTRLEN]; | 150 | char buf[INET6_ADDRSTRLEN]; |
150 | 151 | ||
151 | records++; | 152 | records++; |
152 | switch (rec->type) | 153 | switch (rec->type) |
153 | { | 154 | { |
154 | case GNUNET_DNSPARSER_TYPE_A: | 155 | case GNUNET_DNSPARSER_TYPE_A: |
155 | fprintf(stdout, | 156 | fprintf (stdout, |
156 | "%s A %s\n", | 157 | "%s A %s\n", |
157 | req->hostname, | 158 | req->hostname, |
158 | inet_ntop(AF_INET, | 159 | inet_ntop (AF_INET, |
159 | rec->data.raw.data, | 160 | rec->data.raw.data, |
160 | buf, | 161 | buf, |
161 | sizeof(buf))); | 162 | sizeof(buf))); |
162 | break; | 163 | break; |
163 | 164 | ||
164 | case GNUNET_DNSPARSER_TYPE_AAAA: | 165 | case GNUNET_DNSPARSER_TYPE_AAAA: |
165 | fprintf(stdout, | 166 | fprintf (stdout, |
166 | "%s AAAA %s\n", | 167 | "%s AAAA %s\n", |
167 | req->hostname, | 168 | req->hostname, |
168 | inet_ntop(AF_INET6, | 169 | inet_ntop (AF_INET6, |
169 | rec->data.raw.data, | 170 | rec->data.raw.data, |
170 | buf, | 171 | buf, |
171 | sizeof(buf))); | 172 | sizeof(buf))); |
172 | break; | 173 | break; |
173 | 174 | ||
174 | case GNUNET_DNSPARSER_TYPE_NS: | 175 | case GNUNET_DNSPARSER_TYPE_NS: |
175 | fprintf(stdout, | 176 | fprintf (stdout, |
176 | "%s NS %s\n", | 177 | "%s NS %s\n", |
177 | req->hostname, | 178 | req->hostname, |
178 | rec->data.hostname); | 179 | rec->data.hostname); |
179 | break; | 180 | break; |
180 | 181 | ||
181 | case GNUNET_DNSPARSER_TYPE_CNAME: | 182 | case GNUNET_DNSPARSER_TYPE_CNAME: |
182 | fprintf(stdout, | 183 | fprintf (stdout, |
183 | "%s CNAME %s\n", | 184 | "%s CNAME %s\n", |
184 | req->hostname, | 185 | req->hostname, |
185 | rec->data.hostname); | 186 | rec->data.hostname); |
186 | break; | 187 | break; |
187 | 188 | ||
188 | case GNUNET_DNSPARSER_TYPE_MX: | 189 | case GNUNET_DNSPARSER_TYPE_MX: |
189 | fprintf(stdout, | 190 | fprintf (stdout, |
190 | "%s MX %u %s\n", | 191 | "%s MX %u %s\n", |
191 | req->hostname, | 192 | req->hostname, |
192 | (unsigned int)rec->data.mx->preference, | 193 | (unsigned int) rec->data.mx->preference, |
193 | rec->data.mx->mxhost); | 194 | rec->data.mx->mxhost); |
194 | break; | 195 | break; |
195 | 196 | ||
196 | case GNUNET_DNSPARSER_TYPE_SOA: | 197 | case GNUNET_DNSPARSER_TYPE_SOA: |
197 | fprintf(stdout, | 198 | fprintf (stdout, |
198 | "%s SOA %s %s %u %u %u %u %u\n", | 199 | "%s SOA %s %s %u %u %u %u %u\n", |
199 | req->hostname, | 200 | req->hostname, |
200 | rec->data.soa->mname, | 201 | rec->data.soa->mname, |
201 | rec->data.soa->rname, | 202 | rec->data.soa->rname, |
202 | (unsigned int)rec->data.soa->serial, | 203 | (unsigned int) rec->data.soa->serial, |
203 | (unsigned int)rec->data.soa->refresh, | 204 | (unsigned int) rec->data.soa->refresh, |
204 | (unsigned int)rec->data.soa->retry, | 205 | (unsigned int) rec->data.soa->retry, |
205 | (unsigned int)rec->data.soa->expire, | 206 | (unsigned int) rec->data.soa->expire, |
206 | (unsigned int)rec->data.soa->minimum_ttl); | 207 | (unsigned int) rec->data.soa->minimum_ttl); |
207 | break; | 208 | break; |
208 | 209 | ||
209 | case GNUNET_DNSPARSER_TYPE_SRV: | 210 | case GNUNET_DNSPARSER_TYPE_SRV: |
210 | fprintf(stdout, | 211 | fprintf (stdout, |
211 | "%s SRV %s %u %u %u\n", | 212 | "%s SRV %s %u %u %u\n", |
212 | req->hostname, | 213 | req->hostname, |
213 | rec->data.srv->target, | 214 | rec->data.srv->target, |
214 | rec->data.srv->priority, | 215 | rec->data.srv->priority, |
215 | rec->data.srv->weight, | 216 | rec->data.srv->weight, |
216 | rec->data.srv->port); | 217 | rec->data.srv->port); |
217 | break; | 218 | break; |
218 | 219 | ||
219 | case GNUNET_DNSPARSER_TYPE_PTR: | 220 | case GNUNET_DNSPARSER_TYPE_PTR: |
220 | fprintf(stdout, | 221 | fprintf (stdout, |
221 | "%s PTR %s\n", | 222 | "%s PTR %s\n", |
222 | req->hostname, | 223 | req->hostname, |
223 | rec->data.hostname); | 224 | rec->data.hostname); |
224 | break; | 225 | break; |
225 | 226 | ||
226 | case GNUNET_DNSPARSER_TYPE_TXT: | 227 | case GNUNET_DNSPARSER_TYPE_TXT: |
227 | fprintf(stdout, | 228 | fprintf (stdout, |
228 | "%s TXT %.*s\n", | 229 | "%s TXT %.*s\n", |
229 | req->hostname, | 230 | req->hostname, |
230 | (int)rec->data.raw.data_len, | 231 | (int) rec->data.raw.data_len, |
231 | (char *)rec->data.raw.data); | 232 | (char *) rec->data.raw.data); |
232 | break; | 233 | break; |
233 | 234 | ||
234 | case GNUNET_DNSPARSER_TYPE_DNAME: | 235 | case GNUNET_DNSPARSER_TYPE_DNAME: |
235 | fprintf(stdout, | 236 | fprintf (stdout, |
236 | "%s DNAME %s\n", | 237 | "%s DNAME %s\n", |
237 | req->hostname, | 238 | req->hostname, |
238 | rec->data.hostname); | 239 | rec->data.hostname); |
239 | break; | 240 | break; |
240 | 241 | ||
241 | /* obscure records */ | 242 | /* obscure records */ |
242 | case GNUNET_DNSPARSER_TYPE_AFSDB: | 243 | case GNUNET_DNSPARSER_TYPE_AFSDB: |
243 | case GNUNET_DNSPARSER_TYPE_NAPTR: | 244 | case GNUNET_DNSPARSER_TYPE_NAPTR: |
244 | case GNUNET_DNSPARSER_TYPE_APL: | 245 | case GNUNET_DNSPARSER_TYPE_APL: |
245 | case GNUNET_DNSPARSER_TYPE_DHCID: | 246 | case GNUNET_DNSPARSER_TYPE_DHCID: |
246 | case GNUNET_DNSPARSER_TYPE_HIP: | 247 | case GNUNET_DNSPARSER_TYPE_HIP: |
247 | case GNUNET_DNSPARSER_TYPE_LOC: | 248 | case GNUNET_DNSPARSER_TYPE_LOC: |
248 | case GNUNET_DNSPARSER_TYPE_RP: | 249 | case GNUNET_DNSPARSER_TYPE_RP: |
249 | case GNUNET_DNSPARSER_TYPE_TKEY: | 250 | case GNUNET_DNSPARSER_TYPE_TKEY: |
250 | case GNUNET_DNSPARSER_TYPE_TSIG: | 251 | case GNUNET_DNSPARSER_TYPE_TSIG: |
251 | case GNUNET_DNSPARSER_TYPE_URI: | 252 | case GNUNET_DNSPARSER_TYPE_URI: |
252 | case GNUNET_DNSPARSER_TYPE_TA: | 253 | case GNUNET_DNSPARSER_TYPE_TA: |
253 | 254 | ||
254 | /* DNSSEC */ | 255 | /* DNSSEC */ |
255 | case GNUNET_DNSPARSER_TYPE_DS: | 256 | case GNUNET_DNSPARSER_TYPE_DS: |
256 | case GNUNET_DNSPARSER_TYPE_RRSIG: | 257 | case GNUNET_DNSPARSER_TYPE_RRSIG: |
257 | case GNUNET_DNSPARSER_TYPE_NSEC: | 258 | case GNUNET_DNSPARSER_TYPE_NSEC: |
258 | case GNUNET_DNSPARSER_TYPE_DNSKEY: | 259 | case GNUNET_DNSPARSER_TYPE_DNSKEY: |
259 | case GNUNET_DNSPARSER_TYPE_NSEC3: | 260 | case GNUNET_DNSPARSER_TYPE_NSEC3: |
260 | case GNUNET_DNSPARSER_TYPE_NSEC3PARAM: | 261 | case GNUNET_DNSPARSER_TYPE_NSEC3PARAM: |
261 | case GNUNET_DNSPARSER_TYPE_CDS: | 262 | case GNUNET_DNSPARSER_TYPE_CDS: |
262 | case GNUNET_DNSPARSER_TYPE_CDNSKEY: | 263 | case GNUNET_DNSPARSER_TYPE_CDNSKEY: |
263 | 264 | ||
264 | /* DNSSEC payload */ | 265 | /* DNSSEC payload */ |
265 | case GNUNET_DNSPARSER_TYPE_CERT: | 266 | case GNUNET_DNSPARSER_TYPE_CERT: |
266 | case GNUNET_DNSPARSER_TYPE_SSHFP: | 267 | case GNUNET_DNSPARSER_TYPE_SSHFP: |
267 | case GNUNET_DNSPARSER_TYPE_IPSECKEY: | 268 | case GNUNET_DNSPARSER_TYPE_IPSECKEY: |
268 | case GNUNET_DNSPARSER_TYPE_TLSA: | 269 | case GNUNET_DNSPARSER_TYPE_TLSA: |
269 | case GNUNET_DNSPARSER_TYPE_OPENPGPKEY: | 270 | case GNUNET_DNSPARSER_TYPE_OPENPGPKEY: |
270 | 271 | ||
271 | /* obsolete records */ | 272 | /* obsolete records */ |
272 | case GNUNET_DNSPARSER_TYPE_SIG: | 273 | case GNUNET_DNSPARSER_TYPE_SIG: |
273 | case GNUNET_DNSPARSER_TYPE_KEY: | 274 | case GNUNET_DNSPARSER_TYPE_KEY: |
274 | case GNUNET_DNSPARSER_TYPE_KX: | 275 | case GNUNET_DNSPARSER_TYPE_KX: |
275 | { | 276 | { |
276 | char *base32; | 277 | char *base32; |
277 | 278 | ||
278 | base32 = GNUNET_STRINGS_data_to_string_alloc(rec->data.raw.data, | 279 | base32 = GNUNET_STRINGS_data_to_string_alloc (rec->data.raw.data, |
279 | rec->data.raw.data_len); | 280 | rec->data.raw.data_len); |
280 | fprintf(stdout, | 281 | fprintf (stdout, |
281 | "%s (%u) %s\n", | 282 | "%s (%u) %s\n", |
282 | req->hostname, | 283 | req->hostname, |
283 | rec->type, | 284 | rec->type, |
284 | base32); | 285 | base32); |
285 | GNUNET_free(base32); | 286 | GNUNET_free (base32); |
286 | } | 287 | } |
287 | break; | 288 | break; |
288 | 289 | ||
289 | default: | 290 | default: |
290 | fprintf(stderr, | 291 | fprintf (stderr, |
291 | "Unsupported type %u\n", | 292 | "Unsupported type %u\n", |
292 | (unsigned int)rec->type); | 293 | (unsigned int) rec->type); |
293 | break; | 294 | break; |
294 | } | 295 | } |
295 | } | 296 | } |
296 | 297 | ||
297 | 298 | ||
@@ -303,90 +304,90 @@ process_record(struct Request *req, | |||
303 | * @param dns_len number of bytes in @a dns | 304 | * @param dns_len number of bytes in @a dns |
304 | */ | 305 | */ |
305 | static void | 306 | static void |
306 | process_result(void *cls, | 307 | process_result (void *cls, |
307 | const struct GNUNET_TUN_DnsHeader *dns, | 308 | const struct GNUNET_TUN_DnsHeader *dns, |
308 | size_t dns_len) | 309 | size_t dns_len) |
309 | { | 310 | { |
310 | struct Request *req = cls; | 311 | struct Request *req = cls; |
311 | struct GNUNET_DNSPARSER_Packet *p; | 312 | struct GNUNET_DNSPARSER_Packet *p; |
312 | 313 | ||
313 | if (NULL == dns) | 314 | if (NULL == dns) |
315 | { | ||
316 | /* stub gave up */ | ||
317 | pending--; | ||
318 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
319 | "Stub gave up on DNS reply for `%s'\n", | ||
320 | req->hostname); | ||
321 | GNUNET_CONTAINER_DLL_remove (req_head, | ||
322 | req_tail, | ||
323 | req); | ||
324 | if (req->issue_num > MAX_RETRIES) | ||
314 | { | 325 | { |
315 | /* stub gave up */ | 326 | failures++; |
316 | pending--; | 327 | GNUNET_free (req->hostname); |
317 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 328 | GNUNET_free (req->raw); |
318 | "Stub gave up on DNS reply for `%s'\n", | 329 | GNUNET_free (req); |
319 | req->hostname); | ||
320 | GNUNET_CONTAINER_DLL_remove(req_head, | ||
321 | req_tail, | ||
322 | req); | ||
323 | if (req->issue_num > MAX_RETRIES) | ||
324 | { | ||
325 | failures++; | ||
326 | GNUNET_free(req->hostname); | ||
327 | GNUNET_free(req->raw); | ||
328 | GNUNET_free(req); | ||
329 | return; | ||
330 | } | ||
331 | GNUNET_CONTAINER_DLL_insert_tail(req_head, | ||
332 | req_tail, | ||
333 | req); | ||
334 | req->rs = NULL; | ||
335 | return; | 330 | return; |
336 | } | 331 | } |
332 | GNUNET_CONTAINER_DLL_insert_tail (req_head, | ||
333 | req_tail, | ||
334 | req); | ||
335 | req->rs = NULL; | ||
336 | return; | ||
337 | } | ||
337 | if (req->id != dns->id) | 338 | if (req->id != dns->id) |
338 | return; | 339 | return; |
339 | pending--; | 340 | pending--; |
340 | GNUNET_DNSSTUB_resolve_cancel(req->rs); | 341 | GNUNET_DNSSTUB_resolve_cancel (req->rs); |
341 | req->rs = NULL; | 342 | req->rs = NULL; |
342 | GNUNET_CONTAINER_DLL_remove(req_head, | 343 | GNUNET_CONTAINER_DLL_remove (req_head, |
343 | req_tail, | 344 | req_tail, |
344 | req); | 345 | req); |
345 | p = GNUNET_DNSPARSER_parse((const char *)dns, | 346 | p = GNUNET_DNSPARSER_parse ((const char *) dns, |
346 | dns_len); | 347 | dns_len); |
347 | if (NULL == p) | 348 | if (NULL == p) |
349 | { | ||
350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
351 | "Failed to parse DNS reply for `%s'\n", | ||
352 | req->hostname); | ||
353 | if (req->issue_num > MAX_RETRIES) | ||
348 | { | 354 | { |
349 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 355 | failures++; |
350 | "Failed to parse DNS reply for `%s'\n", | 356 | GNUNET_free (req->hostname); |
351 | req->hostname); | 357 | GNUNET_free (req->raw); |
352 | if (req->issue_num > MAX_RETRIES) | 358 | GNUNET_free (req); |
353 | { | ||
354 | failures++; | ||
355 | GNUNET_free(req->hostname); | ||
356 | GNUNET_free(req->raw); | ||
357 | GNUNET_free(req); | ||
358 | return; | ||
359 | } | ||
360 | GNUNET_CONTAINER_DLL_insert_tail(req_head, | ||
361 | req_tail, | ||
362 | req); | ||
363 | return; | 359 | return; |
364 | } | 360 | } |
361 | GNUNET_CONTAINER_DLL_insert_tail (req_head, | ||
362 | req_tail, | ||
363 | req); | ||
364 | return; | ||
365 | } | ||
365 | for (unsigned int i = 0; i < p->num_answers; i++) | 366 | for (unsigned int i = 0; i < p->num_answers; i++) |
366 | { | 367 | { |
367 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; | 368 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; |
368 | 369 | ||
369 | process_record(req, | 370 | process_record (req, |
370 | rs); | 371 | rs); |
371 | } | 372 | } |
372 | for (unsigned int i = 0; i < p->num_authority_records; i++) | 373 | for (unsigned int i = 0; i < p->num_authority_records; i++) |
373 | { | 374 | { |
374 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; | 375 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; |
375 | 376 | ||
376 | process_record(req, | 377 | process_record (req, |
377 | rs); | 378 | rs); |
378 | } | 379 | } |
379 | for (unsigned int i = 0; i < p->num_additional_records; i++) | 380 | for (unsigned int i = 0; i < p->num_additional_records; i++) |
380 | { | 381 | { |
381 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; | 382 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; |
382 | 383 | ||
383 | process_record(req, | 384 | process_record (req, |
384 | rs); | 385 | rs); |
385 | } | 386 | } |
386 | GNUNET_DNSPARSER_free_packet(p); | 387 | GNUNET_DNSPARSER_free_packet (p); |
387 | GNUNET_free(req->hostname); | 388 | GNUNET_free (req->hostname); |
388 | GNUNET_free(req->raw); | 389 | GNUNET_free (req->raw); |
389 | GNUNET_free(req); | 390 | GNUNET_free (req); |
390 | } | 391 | } |
391 | 392 | ||
392 | 393 | ||
@@ -400,31 +401,31 @@ process_result(void *cls, | |||
400 | * #GNUNET_SYSERR if we are at the rate limit | 401 | * #GNUNET_SYSERR if we are at the rate limit |
401 | */ | 402 | */ |
402 | static int | 403 | static int |
403 | submit_req(struct Request *req) | 404 | submit_req (struct Request *req) |
404 | { | 405 | { |
405 | static struct timeval last_request; | 406 | static struct timeval last_request; |
406 | struct timeval now; | 407 | struct timeval now; |
407 | 408 | ||
408 | if (NULL != req->rs) | 409 | if (NULL != req->rs) |
409 | return GNUNET_NO; /* already submitted */ | 410 | return GNUNET_NO; /* already submitted */ |
410 | gettimeofday(&now, | 411 | gettimeofday (&now, |
411 | NULL); | 412 | NULL); |
412 | if ((((now.tv_sec - last_request.tv_sec) == 0) && | 413 | if ((((now.tv_sec - last_request.tv_sec) == 0) && |
413 | ((now.tv_usec - last_request.tv_usec) < TIME_THRESH)) || | 414 | ((now.tv_usec - last_request.tv_usec) < TIME_THRESH)) || |
414 | (pending >= THRESH)) | 415 | (pending >= THRESH)) |
415 | return GNUNET_SYSERR; | 416 | return GNUNET_SYSERR; |
416 | GNUNET_assert(NULL == req->rs); | 417 | GNUNET_assert (NULL == req->rs); |
417 | req->rs = GNUNET_DNSSTUB_resolve(ctx, | 418 | req->rs = GNUNET_DNSSTUB_resolve (ctx, |
418 | req->raw, | 419 | req->raw, |
419 | req->raw_len, | 420 | req->raw_len, |
420 | &process_result, | 421 | &process_result, |
421 | req); | 422 | req); |
422 | GNUNET_assert(NULL != req->rs); | 423 | GNUNET_assert (NULL != req->rs); |
423 | req->issue_num++; | 424 | req->issue_num++; |
424 | last_request = now; | 425 | last_request = now; |
425 | lookups++; | 426 | lookups++; |
426 | pending++; | 427 | pending++; |
427 | req->time = time(NULL); | 428 | req->time = time (NULL); |
428 | return GNUNET_OK; | 429 | return GNUNET_OK; |
429 | } | 430 | } |
430 | 431 | ||
@@ -435,23 +436,23 @@ submit_req(struct Request *req) | |||
435 | * @param cls NULL | 436 | * @param cls NULL |
436 | */ | 437 | */ |
437 | static void | 438 | static void |
438 | process_queue(void *cls) | 439 | process_queue (void *cls) |
439 | { | 440 | { |
440 | (void)cls; | 441 | (void) cls; |
441 | t = NULL; | 442 | t = NULL; |
442 | for (struct Request *req = req_head; | 443 | for (struct Request *req = req_head; |
443 | NULL != req; | 444 | NULL != req; |
444 | req = req->next) | 445 | req = req->next) |
445 | { | 446 | { |
446 | if (GNUNET_SYSERR == submit_req(req)) | 447 | if (GNUNET_SYSERR == submit_req (req)) |
447 | break; | 448 | break; |
448 | } | 449 | } |
449 | if (NULL != req_head) | 450 | if (NULL != req_head) |
450 | t = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MILLISECONDS, | 451 | t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, |
451 | &process_queue, | 452 | &process_queue, |
452 | NULL); | 453 | NULL); |
453 | else | 454 | else |
454 | GNUNET_SCHEDULER_shutdown(); | 455 | GNUNET_SCHEDULER_shutdown (); |
455 | } | 456 | } |
456 | 457 | ||
457 | 458 | ||
@@ -461,15 +462,15 @@ process_queue(void *cls) | |||
461 | * @param cls NULL | 462 | * @param cls NULL |
462 | */ | 463 | */ |
463 | static void | 464 | static void |
464 | do_shutdown(void *cls) | 465 | do_shutdown (void *cls) |
465 | { | 466 | { |
466 | (void)cls; | 467 | (void) cls; |
467 | if (NULL != t) | 468 | if (NULL != t) |
468 | { | 469 | { |
469 | GNUNET_SCHEDULER_cancel(t); | 470 | GNUNET_SCHEDULER_cancel (t); |
470 | t = NULL; | 471 | t = NULL; |
471 | } | 472 | } |
472 | GNUNET_DNSSTUB_stop(ctx); | 473 | GNUNET_DNSSTUB_stop (ctx); |
473 | ctx = NULL; | 474 | ctx = NULL; |
474 | } | 475 | } |
475 | 476 | ||
@@ -481,14 +482,14 @@ do_shutdown(void *cls) | |||
481 | * @param cls NULL | 482 | * @param cls NULL |
482 | */ | 483 | */ |
483 | static void | 484 | static void |
484 | run(void *cls) | 485 | run (void *cls) |
485 | { | 486 | { |
486 | (void)cls; | 487 | (void) cls; |
487 | 488 | ||
488 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 489 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
490 | NULL); | ||
491 | t = GNUNET_SCHEDULER_add_now (&process_queue, | ||
489 | NULL); | 492 | NULL); |
490 | t = GNUNET_SCHEDULER_add_now(&process_queue, | ||
491 | NULL); | ||
492 | } | 493 | } |
493 | 494 | ||
494 | 495 | ||
@@ -498,7 +499,7 @@ run(void *cls) | |||
498 | * @param hostname name to resolve | 499 | * @param hostname name to resolve |
499 | */ | 500 | */ |
500 | static void | 501 | static void |
501 | queue(const char *hostname) | 502 | queue (const char *hostname) |
502 | { | 503 | { |
503 | struct GNUNET_DNSPARSER_Packet p; | 504 | struct GNUNET_DNSPARSER_Packet p; |
504 | struct GNUNET_DNSPARSER_Query q; | 505 | struct GNUNET_DNSPARSER_Query q; |
@@ -508,46 +509,46 @@ queue(const char *hostname) | |||
508 | int ret; | 509 | int ret; |
509 | 510 | ||
510 | if (GNUNET_OK != | 511 | if (GNUNET_OK != |
511 | GNUNET_DNSPARSER_check_name(hostname)) | 512 | GNUNET_DNSPARSER_check_name (hostname)) |
512 | { | 513 | { |
513 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 514 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
514 | "Refusing invalid hostname `%s'\n", | 515 | "Refusing invalid hostname `%s'\n", |
515 | hostname); | 516 | hostname); |
516 | return; | 517 | return; |
517 | } | 518 | } |
518 | q.name = (char *)hostname; | 519 | q.name = (char *) hostname; |
519 | q.type = GNUNET_DNSPARSER_TYPE_NS; | 520 | q.type = GNUNET_DNSPARSER_TYPE_NS; |
520 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 521 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
521 | 522 | ||
522 | memset(&p, | 523 | memset (&p, |
523 | 0, | 524 | 0, |
524 | sizeof(p)); | 525 | sizeof(p)); |
525 | p.num_queries = 1; | 526 | p.num_queries = 1; |
526 | p.queries = &q; | 527 | p.queries = &q; |
527 | p.id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, | 528 | p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
528 | UINT16_MAX); | 529 | UINT16_MAX); |
529 | ret = GNUNET_DNSPARSER_pack(&p, | 530 | ret = GNUNET_DNSPARSER_pack (&p, |
530 | UINT16_MAX, | 531 | UINT16_MAX, |
531 | &raw, | 532 | &raw, |
532 | &raw_size); | 533 | &raw_size); |
533 | if (GNUNET_OK != ret) | 534 | if (GNUNET_OK != ret) |
534 | { | 535 | { |
535 | if (GNUNET_NO == ret) | 536 | if (GNUNET_NO == ret) |
536 | GNUNET_free(raw); | 537 | GNUNET_free (raw); |
537 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 538 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
538 | "Failed to pack query for hostname `%s'\n", | 539 | "Failed to pack query for hostname `%s'\n", |
539 | hostname); | 540 | hostname); |
540 | return; | 541 | return; |
541 | } | 542 | } |
542 | 543 | ||
543 | req = GNUNET_new(struct Request); | 544 | req = GNUNET_new (struct Request); |
544 | req->hostname = strdup(hostname); | 545 | req->hostname = strdup (hostname); |
545 | req->raw = raw; | 546 | req->raw = raw; |
546 | req->raw_len = raw_size; | 547 | req->raw_len = raw_size; |
547 | req->id = p.id; | 548 | req->id = p.id; |
548 | GNUNET_CONTAINER_DLL_insert_tail(req_head, | 549 | GNUNET_CONTAINER_DLL_insert_tail (req_head, |
549 | req_tail, | 550 | req_tail, |
550 | req); | 551 | req); |
551 | } | 552 | } |
552 | 553 | ||
553 | 554 | ||
@@ -559,50 +560,50 @@ queue(const char *hostname) | |||
559 | * @return 0 on success | 560 | * @return 0 on success |
560 | */ | 561 | */ |
561 | int | 562 | int |
562 | main(int argc, | 563 | main (int argc, |
563 | char **argv) | 564 | char **argv) |
564 | { | 565 | { |
565 | char hn[256]; | 566 | char hn[256]; |
566 | 567 | ||
567 | if (2 != argc) | 568 | if (2 != argc) |
568 | { | 569 | { |
569 | fprintf(stderr, | 570 | fprintf (stderr, |
570 | "Missing required configuration argument\n"); | 571 | "Missing required configuration argument\n"); |
571 | return -1; | 572 | return -1; |
572 | } | 573 | } |
573 | ctx = GNUNET_DNSSTUB_start(256); | 574 | ctx = GNUNET_DNSSTUB_start (256); |
574 | if (NULL == ctx) | 575 | if (NULL == ctx) |
575 | { | 576 | { |
576 | fprintf(stderr, | 577 | fprintf (stderr, |
577 | "Failed to initialize GNUnet DNS STUB\n"); | 578 | "Failed to initialize GNUnet DNS STUB\n"); |
578 | return 1; | 579 | return 1; |
579 | } | 580 | } |
580 | if (GNUNET_OK != | 581 | if (GNUNET_OK != |
581 | GNUNET_DNSSTUB_add_dns_ip(ctx, | 582 | GNUNET_DNSSTUB_add_dns_ip (ctx, |
582 | argv[1])) | 583 | argv[1])) |
583 | { | 584 | { |
584 | fprintf(stderr, | 585 | fprintf (stderr, |
585 | "Failed to use `%s' for DNS resolver\n", | 586 | "Failed to use `%s' for DNS resolver\n", |
586 | argv[1]); | 587 | argv[1]); |
587 | return 1; | 588 | return 1; |
588 | } | 589 | } |
589 | 590 | ||
590 | while (NULL != | 591 | while (NULL != |
591 | fgets(hn, | 592 | fgets (hn, |
592 | sizeof(hn), | 593 | sizeof(hn), |
593 | stdin)) | 594 | stdin)) |
594 | { | 595 | { |
595 | if (strlen(hn) > 0) | 596 | if (strlen (hn) > 0) |
596 | hn[strlen(hn) - 1] = '\0'; /* eat newline */ | 597 | hn[strlen (hn) - 1] = '\0'; /* eat newline */ |
597 | queue(hn); | 598 | queue (hn); |
598 | } | 599 | } |
599 | GNUNET_SCHEDULER_run(&run, | 600 | GNUNET_SCHEDULER_run (&run, |
600 | NULL); | 601 | NULL); |
601 | fprintf(stderr, | 602 | fprintf (stderr, |
602 | "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n", | 603 | "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n", |
603 | lookups, | 604 | lookups, |
604 | records, | 605 | records, |
605 | failures, | 606 | failures, |
606 | pending); | 607 | pending); |
607 | return 0; | 608 | return 0; |
608 | } | 609 | } |
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index fd4d844c5..fc07a4073 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c | |||
@@ -54,37 +54,38 @@ | |||
54 | * by this @a type of block (this is not an error) | 54 | * by this @a type of block (this is not an error) |
55 | */ | 55 | */ |
56 | static struct GNUNET_BLOCK_Group * | 56 | static struct GNUNET_BLOCK_Group * |
57 | block_plugin_dns_create_group(void *cls, | 57 | block_plugin_dns_create_group (void *cls, |
58 | enum GNUNET_BLOCK_Type type, | 58 | enum GNUNET_BLOCK_Type type, |
59 | uint32_t nonce, | 59 | uint32_t nonce, |
60 | const void *raw_data, | 60 | const void *raw_data, |
61 | size_t raw_data_size, | 61 | size_t raw_data_size, |
62 | va_list va) | 62 | va_list va) |
63 | { | 63 | { |
64 | unsigned int bf_size; | 64 | unsigned int bf_size; |
65 | const char *guard; | 65 | const char *guard; |
66 | 66 | ||
67 | guard = va_arg(va, const char *); | 67 | guard = va_arg (va, const char *); |
68 | if (0 == strcmp(guard, | 68 | if (0 == strcmp (guard, |
69 | "seen-set-size")) | 69 | "seen-set-size")) |
70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), | 70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned |
71 | BLOOMFILTER_K); | 71 | int), |
72 | else if (0 == strcmp(guard, | 72 | BLOOMFILTER_K); |
73 | "filter-size")) | 73 | else if (0 == strcmp (guard, |
74 | bf_size = va_arg(va, unsigned int); | 74 | "filter-size")) |
75 | bf_size = va_arg (va, unsigned int); | ||
75 | else | 76 | else |
76 | { | 77 | { |
77 | GNUNET_break(0); | 78 | GNUNET_break (0); |
78 | bf_size = 8; | 79 | bf_size = 8; |
79 | } | 80 | } |
80 | GNUNET_break(NULL == va_arg(va, const char *)); | 81 | GNUNET_break (NULL == va_arg (va, const char *)); |
81 | return GNUNET_BLOCK_GROUP_bf_create(cls, | 82 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
82 | bf_size, | 83 | bf_size, |
83 | BLOOMFILTER_K, | 84 | BLOOMFILTER_K, |
84 | type, | 85 | type, |
85 | nonce, | 86 | nonce, |
86 | raw_data, | 87 | raw_data, |
87 | raw_data_size); | 88 | raw_data_size); |
88 | } | 89 | } |
89 | 90 | ||
90 | 91 | ||
@@ -105,72 +106,73 @@ block_plugin_dns_create_group(void *cls, | |||
105 | * @return characterization of result | 106 | * @return characterization of result |
106 | */ | 107 | */ |
107 | static enum GNUNET_BLOCK_EvaluationResult | 108 | static enum GNUNET_BLOCK_EvaluationResult |
108 | block_plugin_dns_evaluate(void *cls, | 109 | block_plugin_dns_evaluate (void *cls, |
109 | struct GNUNET_BLOCK_Context *ctx, | 110 | struct GNUNET_BLOCK_Context *ctx, |
110 | enum GNUNET_BLOCK_Type type, | 111 | enum GNUNET_BLOCK_Type type, |
111 | struct GNUNET_BLOCK_Group *bg, | 112 | struct GNUNET_BLOCK_Group *bg, |
112 | enum GNUNET_BLOCK_EvaluationOptions eo, | 113 | enum GNUNET_BLOCK_EvaluationOptions eo, |
113 | const struct GNUNET_HashCode * query, | 114 | const struct GNUNET_HashCode *query, |
114 | const void *xquery, | 115 | const void *xquery, |
115 | size_t xquery_size, | 116 | size_t xquery_size, |
116 | const void *reply_block, | 117 | const void *reply_block, |
117 | size_t reply_block_size) | 118 | size_t reply_block_size) |
118 | { | 119 | { |
119 | const struct GNUNET_DNS_Advertisement *ad; | 120 | const struct GNUNET_DNS_Advertisement *ad; |
120 | struct GNUNET_HashCode phash; | 121 | struct GNUNET_HashCode phash; |
121 | 122 | ||
122 | switch (type) | 123 | switch (type) |
124 | { | ||
125 | case GNUNET_BLOCK_TYPE_DNS: | ||
126 | if (0 != xquery_size) | ||
127 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
128 | |||
129 | if (NULL == reply_block) | ||
130 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
131 | |||
132 | if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size) | ||
133 | { | ||
134 | GNUNET_break_op (0); | ||
135 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
136 | } | ||
137 | ad = reply_block; | ||
138 | |||
139 | if (ntohl (ad->purpose.size) != | ||
140 | sizeof(struct GNUNET_DNS_Advertisement) | ||
141 | - sizeof(struct GNUNET_CRYPTO_EddsaSignature)) | ||
142 | { | ||
143 | GNUNET_break_op (0); | ||
144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
145 | } | ||
146 | if (0 == | ||
147 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh | ||
148 | (ad->expiration_time)). | ||
149 | rel_value_us) | ||
123 | { | 150 | { |
124 | case GNUNET_BLOCK_TYPE_DNS: | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
125 | if (0 != xquery_size) | 152 | "DNS advertisement has expired\n"); |
126 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 153 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
127 | |||
128 | if (NULL == reply_block) | ||
129 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
130 | |||
131 | if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size) | ||
132 | { | ||
133 | GNUNET_break_op(0); | ||
134 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
135 | } | ||
136 | ad = reply_block; | ||
137 | |||
138 | if (ntohl(ad->purpose.size) != | ||
139 | sizeof(struct GNUNET_DNS_Advertisement) - | ||
140 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)) | ||
141 | { | ||
142 | GNUNET_break_op(0); | ||
143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
144 | } | ||
145 | if (0 == | ||
146 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh | ||
147 | (ad->expiration_time)).rel_value_us) | ||
148 | { | ||
149 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "DNS advertisement has expired\n"); | ||
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
152 | } | ||
153 | if (GNUNET_OK != | ||
154 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
155 | &ad->purpose, | ||
156 | &ad->signature, | ||
157 | &ad->peer.public_key)) | ||
158 | { | ||
159 | GNUNET_break_op(0); | ||
160 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
161 | } | ||
162 | GNUNET_CRYPTO_hash(reply_block, | ||
163 | reply_block_size, | ||
164 | &phash); | ||
165 | if (GNUNET_YES == | ||
166 | GNUNET_BLOCK_GROUP_bf_test_and_set(bg, | ||
167 | &phash)) | ||
168 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
169 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
170 | |||
171 | default: | ||
172 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
173 | } | 154 | } |
155 | if (GNUNET_OK != | ||
156 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
157 | &ad->purpose, | ||
158 | &ad->signature, | ||
159 | &ad->peer.public_key)) | ||
160 | { | ||
161 | GNUNET_break_op (0); | ||
162 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
163 | } | ||
164 | GNUNET_CRYPTO_hash (reply_block, | ||
165 | reply_block_size, | ||
166 | &phash); | ||
167 | if (GNUNET_YES == | ||
168 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
169 | &phash)) | ||
170 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
171 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
172 | |||
173 | default: | ||
174 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
175 | } | ||
174 | } | 176 | } |
175 | 177 | ||
176 | 178 | ||
@@ -186,11 +188,11 @@ block_plugin_dns_evaluate(void *cls, | |||
186 | * (or if extracting a key from a block of this type does not work) | 188 | * (or if extracting a key from a block of this type does not work) |
187 | */ | 189 | */ |
188 | static int | 190 | static int |
189 | block_plugin_dns_get_key(void *cls, | 191 | block_plugin_dns_get_key (void *cls, |
190 | enum GNUNET_BLOCK_Type type, | 192 | enum GNUNET_BLOCK_Type type, |
191 | const void *block, | 193 | const void *block, |
192 | size_t block_size, | 194 | size_t block_size, |
193 | struct GNUNET_HashCode *key) | 195 | struct GNUNET_HashCode *key) |
194 | { | 196 | { |
195 | /* we cannot extract a key from a block of this type */ | 197 | /* we cannot extract a key from a block of this type */ |
196 | return GNUNET_SYSERR; | 198 | return GNUNET_SYSERR; |
@@ -201,16 +203,15 @@ block_plugin_dns_get_key(void *cls, | |||
201 | * Entry point for the plugin. | 203 | * Entry point for the plugin. |
202 | */ | 204 | */ |
203 | void * | 205 | void * |
204 | libgnunet_plugin_block_dns_init(void *cls) | 206 | libgnunet_plugin_block_dns_init (void *cls) |
205 | { | 207 | { |
206 | static enum GNUNET_BLOCK_Type types[] = | 208 | static enum GNUNET_BLOCK_Type types[] = { |
207 | { | ||
208 | GNUNET_BLOCK_TYPE_DNS, | 209 | GNUNET_BLOCK_TYPE_DNS, |
209 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 210 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
210 | }; | 211 | }; |
211 | struct GNUNET_BLOCK_PluginFunctions *api; | 212 | struct GNUNET_BLOCK_PluginFunctions *api; |
212 | 213 | ||
213 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); | 214 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
214 | api->evaluate = &block_plugin_dns_evaluate; | 215 | api->evaluate = &block_plugin_dns_evaluate; |
215 | api->get_key = &block_plugin_dns_get_key; | 216 | api->get_key = &block_plugin_dns_get_key; |
216 | api->create_group = &block_plugin_dns_create_group; | 217 | api->create_group = &block_plugin_dns_create_group; |
@@ -223,11 +224,11 @@ libgnunet_plugin_block_dns_init(void *cls) | |||
223 | * Exit point from the plugin. | 224 | * Exit point from the plugin. |
224 | */ | 225 | */ |
225 | void * | 226 | void * |
226 | libgnunet_plugin_block_dns_done(void *cls) | 227 | libgnunet_plugin_block_dns_done (void *cls) |
227 | { | 228 | { |
228 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 229 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
229 | 230 | ||
230 | GNUNET_free(api); | 231 | GNUNET_free (api); |
231 | return NULL; | 232 | return NULL; |
232 | } | 233 | } |
233 | 234 | ||