GNUnet  0.11.x
Functions | Variables
plugin_gnsrecord_gns.c File Reference

gnsrecord plugin to provide the API for fundamental GNS records This includes the VPN record because GNS resolution is expected to understand VPN records and (if needed) map the result to A/AAAA. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_gnsrecord_plugin.h"
#include <inttypes.h>
Include dependency graph for plugin_gnsrecord_gns.c:

Go to the source code of this file.

Functions

static char * gns_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
 Convert the 'value' of a record to a string. More...
 
static int gns_string_to_value (void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of a 'value' of a record to the binary representation. More...
 
static uint32_t gns_typename_to_number (void *cls, const char *gns_typename)
 Convert a type name (i.e. More...
 
static const char * gns_number_to_typename (void *cls, uint32_t type)
 Convert a type number (i.e. More...
 
void * libgnunet_plugin_gnsrecord_gns_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_gnsrecord_gns_done (void *cls)
 Exit point from the plugin. More...
 

Variables

struct {
   const char *   name
 
   uint32_t   number
 
gns_name_map []
 Mapping of record type numbers to human-readable record type names. More...
 

Detailed Description

gnsrecord plugin to provide the API for fundamental GNS records This includes the VPN record because GNS resolution is expected to understand VPN records and (if needed) map the result to A/AAAA.

Author
Christian Grothoff

Definition in file plugin_gnsrecord_gns.c.

Function Documentation

◆ gns_value_to_string()

static char* gns_value_to_string ( void *  cls,
uint32_t  type,
const void *  data,
size_t  data_size 
)
static

Convert the 'value' of a record to a string.

Parameters
clsclosure, unused
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 47 of file plugin_gnsrecord_gns.c.

References data, GNUNET_asprintf(), GNUNET_break_op, GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_DNSPARSER_parse_name(), GNUNET_free, GNUNET_free_non_null, GNUNET_GNSRECORD_TYPE_BOX, GNUNET_GNSRECORD_TYPE_GNS2DNS, GNUNET_GNSRECORD_TYPE_LEHO, GNUNET_GNSRECORD_TYPE_NICK, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_GNSRECORD_TYPE_VPN, GNUNET_GNSRECORD_value_to_string(), GNUNET_i2s_full(), GNUNET_memcpy, GNUNET_strndup, ns, GNUNET_TUN_GnsVpnRecord::peer, GNUNET_TUN_GnsVpnRecord::proto, GNUNET_GNSRECORD_BoxRecord::protocol, GNUNET_GNSRECORD_BoxRecord::record_type, and GNUNET_GNSRECORD_BoxRecord::service.

Referenced by libgnunet_plugin_gnsrecord_gns_init().

51 {
52  const char *cdata;
53 
54  switch (type)
55  {
57  if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))
58  return NULL;
60 
62  return GNUNET_strndup (data, data_size);
63 
65  return GNUNET_strndup (data, data_size);
66 
68  char *ns;
69  char *ip;
70  size_t off;
71  char *nstr;
72 
73  off = 0;
76  if ((NULL == ns) || (NULL == ip) || (off != data_size))
77  {
78  GNUNET_break_op (0);
81  return NULL;
82  }
83  GNUNET_asprintf (&nstr, "%s@%s", ns, ip);
86  return nstr;
87  }
88 
90  struct GNUNET_TUN_GnsVpnRecord vpn;
91  char *vpn_str;
92 
93  cdata = data;
94  if ((data_size <= sizeof(vpn)) || ('\0' != cdata[data_size - 1]))
95  return NULL; /* malformed */
96  /* need to memcpy for alignment */
97  GNUNET_memcpy (&vpn, data, sizeof(vpn));
98  GNUNET_asprintf (&vpn_str,
99  "%u %s %s",
100  (unsigned int) ntohs (vpn.proto),
101  (const char *) GNUNET_i2s_full (&vpn.peer),
102  (const char *) &cdata[sizeof(vpn)]);
103  return vpn_str;
104  }
105 
107  struct GNUNET_GNSRECORD_BoxRecord box;
108  uint32_t rt;
109  char *box_str;
110  char *ival;
111 
112  cdata = data;
113  if (data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord))
114  return NULL; /* malformed */
115  GNUNET_memcpy (&box, data, sizeof(box));
116  rt = ntohl (box.record_type);
118  &cdata[sizeof(box)],
119  data_size - sizeof(box));
120  if (NULL == ival)
121  return NULL; /* malformed */
122  GNUNET_asprintf (&box_str,
123  "%u %u %u %s",
124  (unsigned int) ntohs (box.protocol),
125  (unsigned int) ntohs (box.service),
126  (unsigned int) rt,
127  ival);
128  GNUNET_free (ival);
129  return box_str;
130  }
131 
132  default:
133  return NULL;
134  }
135 }
Payload of GNS VPN record.
Record type used to box up SRV and TLSA records.
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:334
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_GNSRECORD_TYPE_BOX
Record type for a boxed record (see TLSA/SRV handling in GNS).
#define GNUNET_GNSRECORD_TYPE_NICK
Record type for GNS nick names ("NICK").
#define GNUNET_GNSRECORD_TYPE_VPN
Record type for VPN resolution.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_GNSRECORD_TYPE_GNS2DNS
Record type for delegation to DNS.
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:332
#define GNUNET_GNSRECORD_TYPE_LEHO
Record type for GNS legacy hostnames ("LEHO").
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:143
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gns_string_to_value()

static int gns_string_to_value ( void *  cls,
uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)
static

Convert human-readable version of a 'value' of a record to the binary representation.

Parameters
clsclosure, unused
typetype of the record
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 150 of file plugin_gnsrecord_gns.c.

References _, GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_DNSPARSER_builder_add_name(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_string_to_value(), GNUNET_GNSRECORD_TYPE_BOX, GNUNET_GNSRECORD_TYPE_GNS2DNS, GNUNET_GNSRECORD_TYPE_LEHO, GNUNET_GNSRECORD_TYPE_NICK, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_GNSRECORD_TYPE_VPN, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, GNUNET_TUN_GnsVpnRecord::peer, proto, GNUNET_TUN_GnsVpnRecord::proto, GNUNET_GNSRECORD_BoxRecord::protocol, GNUNET_PeerIdentity::public_key, GNUNET_GNSRECORD_BoxRecord::record_type, service, and GNUNET_GNSRECORD_BoxRecord::service.

Referenced by libgnunet_plugin_gnsrecord_gns_init().

155 {
157 
158  if (NULL == s)
159  return GNUNET_SYSERR;
160  switch (type)
161  {
163  if (GNUNET_OK !=
165  {
167  _ ("Unable to parse PKEY record `%s'\n"),
168  s);
169  return GNUNET_SYSERR;
170  }
172  GNUNET_memcpy (*data, &pkey, sizeof(pkey));
173  *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
174  return GNUNET_OK;
175 
177  *data = GNUNET_strdup (s);
178  *data_size = strlen (s);
179  return GNUNET_OK;
180 
182  *data = GNUNET_strdup (s);
183  *data_size = strlen (s);
184  return GNUNET_OK;
185 
187  char nsbuf[514];
188  char *cpy;
189  char *at;
190  size_t off;
191 
192  cpy = GNUNET_strdup (s);
193  at = strchr (cpy, '@');
194  if (NULL == at)
195  {
197  _ ("Unable to parse GNS2DNS record `%s'\n"),
198  s);
199  GNUNET_free (cpy);
200  return GNUNET_SYSERR;
201  }
202  *at = '\0';
203  at++;
204 
205  off = 0;
207  sizeof(nsbuf),
208  &off,
209  cpy)) ||
210  (GNUNET_OK !=
211  GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, at)))
212  {
214  _ ("Failed to serialize GNS2DNS record with value `%s'\n"),
215  s);
216  GNUNET_free (cpy);
217  return GNUNET_SYSERR;
218  }
219  GNUNET_free (cpy);
220  *data_size = off;
221  *data = GNUNET_malloc (off);
222  GNUNET_memcpy (*data, nsbuf, off);
223  return GNUNET_OK;
224  }
225 
227  struct GNUNET_TUN_GnsVpnRecord *vpn;
228  char s_peer[103 + 1];
229  char s_serv[253 + 1];
230  unsigned int proto;
231 
232  if (3 != sscanf (s, "%u %103s %253s", &proto, s_peer, s_serv))
233  {
235  _ ("Unable to parse VPN record string `%s'\n"),
236  s);
237  return GNUNET_SYSERR;
238  }
239  *data_size = sizeof(struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
240  *data = vpn = GNUNET_malloc (*data_size);
241  if (GNUNET_OK !=
243  strlen (s_peer),
244  &vpn->peer.public_key))
245  {
246  GNUNET_free (vpn);
247  *data_size = 0;
248  return GNUNET_SYSERR;
249  }
250  vpn->proto = htons ((uint16_t) proto);
251  strcpy ((char *) &vpn[1], s_serv);
252  return GNUNET_OK;
253  }
254 
256  struct GNUNET_GNSRECORD_BoxRecord *box;
257  size_t rest;
258  unsigned int protocol;
259  unsigned int service;
260  unsigned int record_type;
261  void *bval;
262  size_t bval_size;
263 
264  if (3 != sscanf (s, "%u %u %u ", &protocol, &service, &record_type))
265  {
267  _ ("Unable to parse BOX record string `%s'\n"),
268  s);
269  return GNUNET_SYSERR;
270  }
271  rest = snprintf (NULL, 0, "%u %u %u ", protocol, service, record_type);
272  if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record_type,
273  &s[rest],
274  &bval,
275  &bval_size))
276  return GNUNET_SYSERR;
277  *data_size = sizeof(struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
278  *data = box = GNUNET_malloc (*data_size);
279  box->protocol = htons (protocol);
280  box->service = htons (service);
281  box->record_type = htonl (record_type);
282  GNUNET_memcpy (&box[1], bval, bval_size);
283  GNUNET_free (bval);
284  return GNUNET_OK;
285  }
286 
287  default:
288  return GNUNET_SYSERR;
289  }
290 }
Payload of GNS VPN record.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
uint16_t service
Service of the boxed record (aka port number), in NBO.
Record type used to box up SRV and TLSA records.
static char * pkey
Public key of the zone to look in, in ASCII.
static uint8_t proto
Protocol to use.
Definition: gnunet-nat.c:60
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_GNSRECORD_TYPE_BOX
Record type for a boxed record (see TLSA/SRV handling in GNS).
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_GNSRECORD_TYPE_NICK
Record type for GNS nick names ("NICK").
#define GNUNET_GNSRECORD_TYPE_VPN
Record type for VPN resolution.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
#define GNUNET_GNSRECORD_TYPE_GNS2DNS
Record type for delegation to DNS.
uint16_t protocol
Protocol of the boxed record (6 = TCP, 17 = UDP, etc.).
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a &#39;value&#39; of a record to the binary representation.
Definition: gnsrecord.c:175
struct GNUNET_PeerIdentity peer
The peer to contact.
uint16_t proto
The protocol to use.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint32_t record_type
GNS record type of the boxed record.
#define GNUNET_GNSRECORD_TYPE_LEHO
Record type for GNS legacy hostnames ("LEHO").
int GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:499
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:466
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
Definition: dnsparser.c:889
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gns_typename_to_number()

static uint32_t gns_typename_to_number ( void *  cls,
const char *  gns_typename 
)
static

Convert a type name (i.e.

"AAAA") to the corresponding number.

Parameters
clsclosure, unused
gns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 318 of file plugin_gnsrecord_gns.c.

References gns_name_map, and name.

Referenced by libgnunet_plugin_gnsrecord_gns_init().

319 {
320  unsigned int i;
321 
322  i = 0;
323  while ((NULL != gns_name_map[i].name) &&
324  (0 != strcasecmp (gns_typename, gns_name_map[i].name)))
325  i++;
326  return gns_name_map[i].number;
327 }
static struct @22 gns_name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
Here is the caller graph for this function:

◆ gns_number_to_typename()

static const char* gns_number_to_typename ( void *  cls,
uint32_t  type 
)
static

Convert a type number (i.e.

1) to the corresponding type string (i.e. "A")

Parameters
clsclosure, unused
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 338 of file plugin_gnsrecord_gns.c.

References gns_name_map, name, and number.

Referenced by libgnunet_plugin_gnsrecord_gns_init().

339 {
340  unsigned int i;
341 
342  i = 0;
343  while ((NULL != gns_name_map[i].name) && (type != gns_name_map[i].number))
344  i++;
345  return gns_name_map[i].name;
346 }
static struct @22 gns_name_map[]
Mapping of record type numbers to human-readable record type names.
uint32_t number
const char * name
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the caller graph for this function:

◆ libgnunet_plugin_gnsrecord_gns_init()

void* libgnunet_plugin_gnsrecord_gns_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 356 of file plugin_gnsrecord_gns.c.

References gns_number_to_typename(), gns_string_to_value(), gns_typename_to_number(), gns_value_to_string(), GNUNET_new, GNUNET_GNSRECORD_PluginFunctions::number_to_typename, GNUNET_GNSRECORD_PluginFunctions::string_to_value, GNUNET_GNSRECORD_PluginFunctions::typename_to_number, and GNUNET_GNSRECORD_PluginFunctions::value_to_string.

357 {
359 
365  return api;
366 }
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static uint32_t gns_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (i.e.
static char * gns_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
static const char * gns_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
static int gns_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a &#39;value&#39; of a record to the binary representation.
Here is the call graph for this function:

◆ libgnunet_plugin_gnsrecord_gns_done()

void* libgnunet_plugin_gnsrecord_gns_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init()
Returns
NULL

Definition at line 376 of file plugin_gnsrecord_gns.c.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

377 {
379 
380  GNUNET_free (api);
381  return NULL;
382 }
void * cls
Closure for all of the callbacks.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_free(ptr)
Wrapper around free.

Variable Documentation

◆ name

const char* name

Definition at line 299 of file plugin_gnsrecord_gns.c.

Referenced by gns_number_to_typename(), and gns_typename_to_number().

◆ number

uint32_t number

Definition at line 300 of file plugin_gnsrecord_gns.c.

Referenced by gns_number_to_typename().

◆ gns_name_map

struct { ... } gns_name_map[]
Initial value:
{ NULL, UINT32_MAX } }
#define GNUNET_GNSRECORD_TYPE_BOX
Record type for a boxed record (see TLSA/SRV handling in GNS).
#define GNUNET_GNSRECORD_TYPE_NICK
Record type for GNS nick names ("NICK").
#define GNUNET_GNSRECORD_TYPE_VPN
Record type for VPN resolution.
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
#define GNUNET_GNSRECORD_TYPE_GNS2DNS
Record type for delegation to DNS.
#define GNUNET_GNSRECORD_TYPE_LEHO
Record type for GNS legacy hostnames ("LEHO").

Mapping of record type numbers to human-readable record type names.

Referenced by gns_number_to_typename(), and gns_typename_to_number().