GNUnet  0.10.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 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. 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 {
54 
59 
68 
79 
88 
97 
98 };
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 247 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().

248 {
249  struct GNUNET_MQ_Envelope *env;
250  struct GNUNET_DNS_Response *resp;
251 
252  GNUNET_assert (0 < rh->dh->pending_requests--);
253  if (rh->generation != rh->dh->generation)
254  {
255  GNUNET_free (rh);
256  return;
257  }
258  env = GNUNET_MQ_msg (resp,
260  resp->drop_flag = htonl (1);
261  resp->request_id = rh->request_id;
262  GNUNET_MQ_send (rh->dh->mq,
263  env);
264  GNUNET_free (rh);
265 }
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:50
#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:89
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:64
struct GNUNET_DNS_Handle * dh
Handle to DNS API.
Definition: dns_api.c:40
#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:77
#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:100
uint64_t request_id
Stored in network byte order (as for us, it is just a random number).
Definition: dns_api.c:45
uint64_t request_id
Unique request ID.
Definition: dns.h:92
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:87
#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 275 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().

276 {
277  struct GNUNET_MQ_Envelope *env;
278  struct GNUNET_DNS_Response *resp;
279 
280  GNUNET_assert (0 < rh->dh->pending_requests--);
281  if (rh->generation != rh->dh->generation)
282  {
283  GNUNET_free (rh);
284  return;
285  }
286  env = GNUNET_MQ_msg (resp,
288  resp->request_id = rh->request_id;
289  resp->drop_flag = htonl (0);
290  GNUNET_MQ_send (rh->dh->mq,
291  env);
292  GNUNET_free (rh);
293 }
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:50
#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:89
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:64
struct GNUNET_DNS_Handle * dh
Handle to DNS API.
Definition: dns_api.c:40
#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:77
#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:100
uint64_t request_id
Stored in network byte order (as for us, it is just a random number).
Definition: dns_api.c:45
uint64_t request_id
Unique request ID.
Definition: dns.h:92
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:87
#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 306 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().

309 {
310  struct GNUNET_MQ_Envelope *env;
311  struct GNUNET_DNS_Response *resp;
312 
313  GNUNET_assert (0 < rh->dh->pending_requests--);
314  if (rh->generation != rh->dh->generation)
315  {
316  GNUNET_free (rh);
317  return;
318  }
319  if (reply_length + sizeof (struct GNUNET_DNS_Response)
321  {
322  GNUNET_break (0);
323  GNUNET_free (rh);
324  return;
325  }
326  env = GNUNET_MQ_msg_extra (resp,
327  reply_length,
329  resp->drop_flag = htonl (2);
330  resp->request_id = rh->request_id;
331  GNUNET_memcpy (&resp[1],
332  reply,
333  reply_length);
334  GNUNET_MQ_send (rh->dh->mq,
335  env);
336  GNUNET_free (rh);
337 }
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:50
#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:89
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:64
struct GNUNET_DNS_Handle * dh
Handle to DNS API.
Definition: dns_api.c:40
Message from client to DNS service: here is my reply.
Definition: dns.h:77
#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.
#define GNUNET_memcpy(dst, src, n)
unsigned int pending_requests
Number of GNUNET_DNS_RequestHandles we have outstanding.
Definition: dns_api.c:100
uint64_t request_id
Stored in network byte order (as for us, it is just a random number).
Definition: dns_api.c:45
uint64_t request_id
Unique request ID.
Definition: dns.h:92
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:87
#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 350 of file dns_api.c.

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

354 {
355  struct GNUNET_DNS_Handle *dh;
356 
357  dh = GNUNET_new (struct GNUNET_DNS_Handle);
358  dh->cfg = cfg;
359  dh->flags = flags;
360  dh->rh = rh;
361  dh->rh_cls = rh_cls;
363  return dh;
364 }
static void reconnect(void *cls)
Reconnect to the DNS service.
Definition: dns_api.c:206
void * rh_cls
Closure for rh.
Definition: dns_api.c:79
enum GNUNET_DNS_Flags flags
Flags for events we care about.
Definition: dns_api.c:94
#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:84
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:1273
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
DNS handle.
Definition: dns_api.c:58
GNUNET_DNS_RequestHandler rh
Function to call to get replies.
Definition: dns_api.c:74
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:69
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 373 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().

374 {
375  if (NULL != dh->mq)
376  {
377  GNUNET_MQ_destroy (dh->mq);
378  dh->mq = NULL;
379  }
380  if (NULL != dh->reconnect_task)
381  {
383  dh->reconnect_task = NULL;
384  }
385  /* make sure client has no pending requests left over! */
386  GNUNET_break (0 == dh->pending_requests);
387  GNUNET_free (dh);
388 }
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:64
#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:84
unsigned int pending_requests
Number of GNUNET_DNS_RequestHandles we have outstanding.
Definition: dns_api.c:100
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:965
Here is the call graph for this function:
Here is the caller graph for this function: