GNUnet 0.21.1
Collaboration diagram for DNS service:

Typedefs

typedef void(* GNUNET_DNS_RequestHandler) (void *cls, struct GNUNET_DNS_RequestHandle *rh, size_t request_length, const char *request)
 Signature of a function that is called whenever the DNS service encounters a DNS request and needs to do something with it. More...
 

Enumerations

enum  GNUNET_DNS_Flags {
  GNUNET_DNS_FLAG_NEVER = 0 , GNUNET_DNS_FLAG_REQUEST_MONITOR = 1 , GNUNET_DNS_FLAG_PRE_RESOLUTION = 2 , GNUNET_DNS_FLAG_POST_RESOLUTION = 4 ,
  GNUNET_DNS_FLAG_RESPONSE_MONITOR = 8
}
 Flags that specify when to call the client's handler. More...
 

Functions

void GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh)
 If a GNUNET_DNS_RequestHandler calls this function, the client has no desire to interfer with the request and it should continue to be processed normally. More...
 
void GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh)
 If a GNUNET_DNS_RequestHandler calls this function, the request is to be dropped and no response should be generated. More...
 
void GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, uint16_t reply_length, const char *reply)
 If a GNUNET_DNS_RequestHandler calls this function, the request is supposed to be answered with the data provided to this call (with the modifications the function might have made). More...
 
struct GNUNET_DNS_HandleGNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_DNS_Flags flags, GNUNET_DNS_RequestHandler rh, void *rh_cls)
 Connect to the service-dns. More...
 
void GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh)
 Disconnect from the DNS service. More...
 

Detailed Description

See also
Documentation

Typedef Documentation

◆ GNUNET_DNS_RequestHandler

typedef void(* GNUNET_DNS_RequestHandler) (void *cls, struct GNUNET_DNS_RequestHandle *rh, size_t request_length, const char *request)

Signature of a function that is called whenever the DNS service encounters a DNS request and needs to do something with it.

The function has then the chance to generate or modify the response by calling one of the three "GNUNET_DNS_request_*" continuations.

When a request is intercepted, this function is called first to give the client a chance to do the complete address resolution; "rdata" will be NULL for this first call for a DNS request, unless some other client has already filled in a response.

If multiple clients exist, all of them are called before the global DNS. The global DNS is only called if all of the clients' functions call GNUNET_DNS_request_forward. Functions that call GNUNET_DNS_request_forward will be called again before a final response is returned to the application. If any of the clients' functions call GNUNET_DNS_request_drop, the response is dropped.

Parameters
clsclosure
rhrequest handle to user for reply
request_lengthnumber of bytes in request
requestudp payload of the DNS request

Definition at line 126 of file gnunet_dns_service.h.

Enumeration Type Documentation

◆ GNUNET_DNS_Flags

Flags that specify when to call the client's handler.

Enumerator
GNUNET_DNS_FLAG_NEVER 

Useless option: never call the client.

GNUNET_DNS_FLAG_REQUEST_MONITOR 

Set this flag to see all requests first prior to resolution (for monitoring).

Clients that set this flag must then call "GNUNET_DNS_request_forward" when they process a request for the first time. Calling "GNUNET_DNS_request_answer" is not allowed for MONITOR peers.

GNUNET_DNS_FLAG_PRE_RESOLUTION 

This client should be called on requests that have not yet been resolved as this client provides a resolution service.

Note that this does not guarantee that the client will see all requests as another client might be called first and that client might have already done the resolution, in which case other pre-resolution clients won't see the request anymore.

GNUNET_DNS_FLAG_POST_RESOLUTION 

This client wants to be called on the results of a DNS resolution (either resolved by PRE-RESOLUTION clients or the global DNS).

The client then has a chance to modify the answer (or cause it to be dropped). There is no guarantee that other POST-RESOLUTION client's won't modify (or drop) the answer afterwards.

GNUNET_DNS_FLAG_RESPONSE_MONITOR 

Set this flag to see all requests just before they are returned to the network.

Clients that set this flag must then call "GNUNET_DNS_request_forward" when they process a request for the last time. Calling "GNUNET_DNS_request_answer" is not allowed for MONITOR peers.

Definition at line 56 of file gnunet_dns_service.h.

57{
62
71
82
91
100};
@ GNUNET_DNS_FLAG_RESPONSE_MONITOR
Set this flag to see all requests just before they are returned to the network.
@ GNUNET_DNS_FLAG_REQUEST_MONITOR
Set this flag to see all requests first prior to resolution (for monitoring).
@ GNUNET_DNS_FLAG_NEVER
Useless option: never call the client.
@ GNUNET_DNS_FLAG_PRE_RESOLUTION
This client should be called on requests that have not yet been resolved as this client provides a re...
@ GNUNET_DNS_FLAG_POST_RESOLUTION
This client wants to be called on the results of a DNS resolution (either resolved by PRE-RESOLUTION ...

Function Documentation

◆ GNUNET_DNS_request_forward()

void GNUNET_DNS_request_forward ( struct GNUNET_DNS_RequestHandle rh)

If a GNUNET_DNS_RequestHandler calls this function, the client has no desire to interfer with the request and it should continue to be processed normally.

Parameters
rhrequest that should now be forwarded

If a GNUNET_DNS_RequestHandler calls this function, the client has no desire to interfer with the request and it should continue to be processed normally.

Once a global response has been obtained, the request handler is AGAIN called to give it a chance to observe and modify the response after the "normal" resolution. It is not legal for the request handler to call this function if a response is already present.

Parameters
rhrequest that should now be forwarded

Definition at line 237 of file dns_api.c.

238{
239 struct GNUNET_MQ_Envelope *env;
240 struct GNUNET_DNS_Response *resp;
241
242 GNUNET_assert (0 < rh->dh->pending_requests--);
243 if (rh->generation != rh->dh->generation)
244 {
245 GNUNET_free (rh);
246 return;
247 }
248 env = GNUNET_MQ_msg (resp,
250 resp->drop_flag = htonl (1);
251 resp->request_id = rh->request_id;
252 GNUNET_MQ_send (rh->dh->mq,
253 env);
254 GNUNET_free (rh);
255}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE
Type of messages between the gnunet-helper-dns and the service.
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:86
unsigned int pending_requests
Number of GNUNET_DNS_RequestHandles we have outstanding.
Definition: dns_api.c:97
struct GNUNET_DNS_Handle * dh
Handle to DNS API.
Definition: dns_api.c:39
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:49
uint64_t request_id
Stored in network byte order (as for us, it is just a random number).
Definition: dns_api.c:44
Message from client to DNS service: here is my reply.
Definition: dns.h:77
uint32_t drop_flag
Zero to drop, 1 for no change (no payload), 2 for update (message has payload).
Definition: dns.h:86
uint64_t request_id
Unique request ID.
Definition: dns.h:91

References GNUNET_DNS_RequestHandle::dh, GNUNET_DNS_Response::drop_flag, env, GNUNET_DNS_RequestHandle::generation, GNUNET_DNS_Handle::generation, GNUNET_assert, GNUNET_free, GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_DNS_Handle::mq, GNUNET_DNS_Handle::pending_requests, GNUNET_DNS_Response::request_id, and GNUNET_DNS_RequestHandle::request_id.

Referenced by display_request(), dns_post_request_handler(), handle_dns_request(), and modify_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNS_request_drop()

void GNUNET_DNS_request_drop ( struct GNUNET_DNS_RequestHandle rh)

If a GNUNET_DNS_RequestHandler calls this function, the request is to be dropped and no response should be generated.

Parameters
rhrequest that should now be dropped

Definition at line 265 of file dns_api.c.

266{
267 struct GNUNET_MQ_Envelope *env;
268 struct GNUNET_DNS_Response *resp;
269
270 GNUNET_assert (0 < rh->dh->pending_requests--);
271 if (rh->generation != rh->dh->generation)
272 {
273 GNUNET_free (rh);
274 return;
275 }
276 env = GNUNET_MQ_msg (resp,
278 resp->request_id = rh->request_id;
279 resp->drop_flag = htonl (0);
280 GNUNET_MQ_send (rh->dh->mq,
281 env);
282 GNUNET_free (rh);
283}

References GNUNET_DNS_RequestHandle::dh, GNUNET_DNS_Response::drop_flag, env, GNUNET_DNS_RequestHandle::generation, GNUNET_DNS_Handle::generation, GNUNET_assert, GNUNET_free, GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_DNS_Handle::mq, GNUNET_DNS_Handle::pending_requests, GNUNET_DNS_Response::request_id, and GNUNET_DNS_RequestHandle::request_id.

Referenced by abort_all_requests(), dns_post_request_handler(), dns_pre_request_handler(), finish_request(), GNS_interceptor_done(), timeout_request(), and vpn_allocation_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNS_request_answer()

void GNUNET_DNS_request_answer ( struct GNUNET_DNS_RequestHandle rh,
uint16_t  reply_length,
const char *  reply 
)

If a GNUNET_DNS_RequestHandler calls this function, the request is supposed to be answered with the data provided to this call (with the modifications the function might have made).

The reply given must always be a valid DNS reply and not a mutated DNS request.

Parameters
rhrequest that should now be answered
reply_lengthsize of reply (uint16_t to force sane size)
replyreply data
rhrequest that should now be answered
reply_lengthsize of reply (uint16_t to force sane size)
replyreply data

Definition at line 296 of file dns_api.c.

299{
300 struct GNUNET_MQ_Envelope *env;
301 struct GNUNET_DNS_Response *resp;
302
303 GNUNET_assert (0 < rh->dh->pending_requests--);
304 if (rh->generation != rh->dh->generation)
305 {
306 GNUNET_free (rh);
307 return;
308 }
309 if (reply_length + sizeof(struct GNUNET_DNS_Response)
311 {
312 GNUNET_break (0);
313 GNUNET_free (rh);
314 return;
315 }
316 env = GNUNET_MQ_msg_extra (resp,
317 reply_length,
319 resp->drop_flag = htonl (2);
320 resp->request_id = rh->request_id;
321 GNUNET_memcpy (&resp[1],
322 reply,
323 reply_length);
324 GNUNET_MQ_send (rh->dh->mq,
325 env);
326 GNUNET_free (rh);
327}
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63

References GNUNET_DNS_RequestHandle::dh, GNUNET_DNS_Response::drop_flag, env, GNUNET_DNS_RequestHandle::generation, GNUNET_DNS_Handle::generation, GNUNET_assert, GNUNET_break, GNUNET_free, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_DNS_Handle::mq, GNUNET_DNS_Handle::pending_requests, GNUNET_DNS_Response::request_id, and GNUNET_DNS_RequestHandle::request_id.

Referenced by finish_request(), handle_dns_response(), modify_request(), and reply_to_dns().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNS_connect()

struct GNUNET_DNS_Handle * GNUNET_DNS_connect ( const struct GNUNET_CONFIGURATION_Handle cfg,
enum GNUNET_DNS_Flags  flags,
GNUNET_DNS_RequestHandler  rh,
void *  rh_cls 
)

Connect to the service-dns.

Parameters
cfgconfiguration to use
flagswhen to call rh
rhfunction to call with DNS requests
rh_clsclosure to pass to rh
Returns
DNS handle

Definition at line 340 of file dns_api.c.

344{
345 struct GNUNET_DNS_Handle *dh;
346
347 dh = GNUNET_new (struct GNUNET_DNS_Handle);
348 dh->cfg = cfg;
349 dh->flags = flags;
350 dh->rh = rh;
351 dh->rh_cls = rh_cls;
353 return dh;
354}
static void reconnect(void *cls)
Reconnect to the DNS service.
Definition: dns_api.c:196
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
DNS handle.
Definition: dns_api.c:57
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
GNUNET_DNS_RequestHandler rh
Function to call to get replies.
Definition: dns_api.c:71
enum GNUNET_DNS_Flags flags
Flags for events we care about.
Definition: dns_api.c:91
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:66
void * rh_cls
Closure for rh.
Definition: dns_api.c:76

References cfg, GNUNET_DNS_Handle::cfg, GNUNET_DNS_Handle::flags, GNUNET_new, GNUNET_SCHEDULER_add_now(), reconnect(), GNUNET_DNS_Handle::reconnect_task, GNUNET_DNS_Handle::rh, and GNUNET_DNS_Handle::rh_cls.

Referenced by GNS_interceptor_init(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNS_disconnect()

void GNUNET_DNS_disconnect ( struct GNUNET_DNS_Handle dh)

Disconnect from the DNS service.

Parameters
dhDNS handle

Definition at line 363 of file dns_api.c.

364{
365 if (NULL != dh->mq)
366 {
367 GNUNET_MQ_destroy (dh->mq);
368 dh->mq = NULL;
369 }
370 if (NULL != dh->reconnect_task)
371 {
373 dh->reconnect_task = NULL;
374 }
375 /* make sure client has no pending requests left over! */
377 GNUNET_free (dh);
378}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981

References GNUNET_break, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_DNS_Handle::mq, GNUNET_DNS_Handle::pending_requests, and GNUNET_DNS_Handle::reconnect_task.

Referenced by cleanup(), do_disconnect(), and GNS_interceptor_done().

Here is the call graph for this function:
Here is the caller graph for this function: