GNUnet  0.11.x
Typedefs | Enumerations | Functions
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 123 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. Caling "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. Caling "GNUNET_DNS_request_answer" is not allowed for MONITOR peers.

Definition at line 52 of file gnunet_dns_service.h.

53 {
58 
67 
78 
87 
96 };
This client wants to be called on the results of a DNS resolution (either resolved by PRE-RESOLUTION ...
Set this flag to see all requests just before they are returned to the network.
Set this flag to see all requests first prior to resolution (for monitoring).
This client should be called on requests that have not yet been resolved as this client provides a re...
Useless option: never call the client.

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 243 of file dns_api.c.

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_RequestHandle::request_id, and GNUNET_DNS_Response::request_id.

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

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

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_RequestHandle::request_id, and GNUNET_DNS_Response::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().

272 {
273  struct GNUNET_MQ_Envelope *env;
274  struct GNUNET_DNS_Response *resp;
275 
276  GNUNET_assert (0 < rh->dh->pending_requests--);
277  if (rh->generation != rh->dh->generation)
278  {
279  GNUNET_free (rh);
280  return;
281  }
282  env = GNUNET_MQ_msg (resp,
284  resp->request_id = rh->request_id;
285  resp->drop_flag = htonl (0);
286  GNUNET_MQ_send (rh->dh->mq,
287  env);
288  GNUNET_free (rh);
289 }
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:49
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:86
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
struct GNUNET_DNS_Handle * dh
Handle to DNS API.
Definition: dns_api.c:39
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Message from client to DNS service: here is my reply.
Definition: dns.h:76
#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE
Type of messages between the gnunet-helper-dns and the service.
unsigned int pending_requests
Number of GNUNET_DNS_RequestHandles we have outstanding.
Definition: dns_api.c:97
uint64_t request_id
Stored in network byte order (as for us, it is just a random number).
Definition: dns_api.c:44
uint64_t request_id
Unique request ID.
Definition: dns.h:91
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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:353
uint32_t drop_flag
Zero to drop, 1 for no change (no payload), 2 for update (message has payload).
Definition: dns.h:86
#define GNUNET_free(ptr)
Wrapper around free.
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 302 of file dns_api.c.

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_RequestHandle::request_id, and GNUNET_DNS_Response::request_id.

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

305 {
306  struct GNUNET_MQ_Envelope *env;
307  struct GNUNET_DNS_Response *resp;
308 
309  GNUNET_assert (0 < rh->dh->pending_requests--);
310  if (rh->generation != rh->dh->generation)
311  {
312  GNUNET_free (rh);
313  return;
314  }
315  if (reply_length + sizeof(struct GNUNET_DNS_Response)
317  {
318  GNUNET_break (0);
319  GNUNET_free (rh);
320  return;
321  }
322  env = GNUNET_MQ_msg_extra (resp,
323  reply_length,
325  resp->drop_flag = htonl (2);
326  resp->request_id = rh->request_id;
327  GNUNET_memcpy (&resp[1],
328  reply,
329  reply_length);
330  GNUNET_MQ_send (rh->dh->mq,
331  env);
332  GNUNET_free (rh);
333 }
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:49
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:86
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
struct GNUNET_DNS_Handle * dh
Handle to DNS API.
Definition: dns_api.c:39
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Message from client to DNS service: here is my reply.
Definition: dns.h:76
#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:52
#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE
Type of messages between the gnunet-helper-dns and the service.
unsigned int pending_requests
Number of GNUNET_DNS_RequestHandles we have outstanding.
Definition: dns_api.c:97
uint64_t request_id
Stored in network byte order (as for us, it is just a random number).
Definition: dns_api.c:44
uint64_t request_id
Unique request ID.
Definition: dns.h:91
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
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:353
uint32_t drop_flag
Zero to drop, 1 for no change (no payload), 2 for update (message has payload).
Definition: dns.h:86
#define GNUNET_free(ptr)
Wrapper around free.
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 346 of file dns_api.c.

References cfg, GNUNET_DNS_Handle::cfg, GNUNET_DNS_RequestHandle::dh, 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().

350 {
351  struct GNUNET_DNS_Handle *dh;
352 
353  dh = GNUNET_new (struct GNUNET_DNS_Handle);
354  dh->cfg = cfg;
355  dh->flags = flags;
356  dh->rh = rh;
357  dh->rh_cls = rh_cls;
359  return dh;
360 }
static void reconnect(void *cls)
Reconnect to the DNS service.
Definition: dns_api.c:202
void * rh_cls
Closure for rh.
Definition: dns_api.c:76
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
enum GNUNET_DNS_Flags flags
Flags for events we care about.
Definition: dns_api.c:91
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
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:1280
DNS handle.
Definition: dns_api.c:56
GNUNET_DNS_RequestHandler rh
Function to call to get replies.
Definition: dns_api.c:71
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:66
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 369 of file dns_api.c.

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().

370 {
371  if (NULL != dh->mq)
372  {
373  GNUNET_MQ_destroy (dh->mq);
374  dh->mq = NULL;
375  }
376  if (NULL != dh->reconnect_task)
377  {
379  dh->reconnect_task = NULL;
380  }
381  /* make sure client has no pending requests left over! */
382  GNUNET_break (0 == dh->pending_requests);
383  GNUNET_free (dh);
384 }
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
unsigned int pending_requests
Number of GNUNET_DNS_RequestHandles we have outstanding.
Definition: dns_api.c:97
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function: