GNUnet  0.10.x
Data Structures | Macros | Functions
plugin_transport_udp.h File Reference

Implementation of the UDP transport protocol. More...

#include "platform.h"
#include "gnunet_hello_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_fragmentation_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_resolver_service.h"
#include "gnunet_signatures.h"
#include "gnunet_constants.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_transport_plugin.h"
#include "transport.h"
Include dependency graph for plugin_transport_udp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  IPv4UdpAddress
 Network format for IPv4 addresses. More...
 
struct  IPv6UdpAddress
 Network format for IPv6 addresses. More...
 
union  UdpAddress
 Either an IPv4 or IPv6 UDP address. More...
 
struct  Plugin
 Handle for a plugin. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
 
#define PLUGIN_NAME   "udp"
 
#define DEBUG_UDP   GNUNET_NO
 
#define DEBUG_UDP_BROADCASTING   GNUNET_NO
 
#define UDP_MTU   1400
 MTU for fragmentation subsystem. More...
 

Functions

const char * udp_address_to_string (void *cls, const void *addr, size_t addrlen)
 Function called for a quick conversion of the binary address to a numeric address. More...
 
void udp_broadcast_receive (struct Plugin *plugin, const char *buf, ssize_t size, const union UdpAddress *udp_addr, size_t udp_addr_len, enum GNUNET_NetworkType network_type)
 We received a broadcast message. More...
 
void setup_broadcast (struct Plugin *plugin, struct sockaddr_in6 *server_addrv6, struct sockaddr_in *server_addrv4)
 Setup broadcasting subsystem. More...
 
void stop_broadcast (struct Plugin *plugin)
 Stop broadcasting subsystem. More...
 

Detailed Description

Implementation of the UDP transport protocol.

Author
Christian Grothoff
Nathan Evans
Matthias Wachs

Definition in file plugin_transport_udp.h.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)

Definition at line 44 of file plugin_transport_udp.h.

◆ PLUGIN_NAME

#define PLUGIN_NAME   "udp"

Definition at line 46 of file plugin_transport_udp.h.

◆ DEBUG_UDP

#define DEBUG_UDP   GNUNET_NO

Definition at line 48 of file plugin_transport_udp.h.

◆ DEBUG_UDP_BROADCASTING

#define DEBUG_UDP_BROADCASTING   GNUNET_NO

Definition at line 50 of file plugin_transport_udp.h.

◆ UDP_MTU

#define UDP_MTU   1400

MTU for fragmentation subsystem.

Should be conservative since all communicating peers MUST work with this MTU.

Definition at line 56 of file plugin_transport_udp.h.

Referenced by prepare_beacon(), read_process_fragment(), and udp_plugin_send().

Function Documentation

◆ udp_address_to_string()

const char* udp_address_to_string ( void *  cls,
const void *  addr,
size_t  addrlen 
)

Function called for a quick conversion of the binary address to a numeric address.

Note that the caller must not free the address and that the next call to this function is allowed to override the address again.

Parameters
clsclosure
addrbinary address (a union UdpAddress)
addrlenlength of the addr
Returns
string representing the same address

Definition at line 888 of file plugin_transport_udp.c.

References buf, GNUNET_break_op, GNUNET_snprintf(), IPv4UdpAddress::ipv4_addr, IPv6UdpAddress::ipv6_addr, options, IPv4UdpAddress::options, IPv6UdpAddress::options, PLUGIN_NAME, port, t4, t6, IPv4UdpAddress::u4_port, and IPv6UdpAddress::u6_port.

Referenced by ack_proc(), broadcast_mst_cb(), libgnunet_plugin_transport_udp_init(), read_process_ack(), read_process_fragment(), udp_disconnect_session(), udp_plugin_create_session(), udp_plugin_lookup_session(), and udp_plugin_send().

891 {
892  static char rbuf[INET6_ADDRSTRLEN + 10];
893  char buf[INET6_ADDRSTRLEN];
894  const void *sb;
895  struct in_addr a4;
896  struct in6_addr a6;
897  const struct IPv4UdpAddress *t4;
898  const struct IPv6UdpAddress *t6;
899  int af;
900  uint16_t port;
901  uint32_t options;
902 
903  if (NULL == addr)
904  {
905  GNUNET_break_op (0);
906  return NULL;
907  }
908 
909  if (addrlen == sizeof(struct IPv6UdpAddress))
910  {
911  t6 = addr;
912  af = AF_INET6;
913  options = ntohl (t6->options);
914  port = ntohs (t6->u6_port);
915  a6 = t6->ipv6_addr;
916  sb = &a6;
917  }
918  else if (addrlen == sizeof(struct IPv4UdpAddress))
919  {
920  t4 = addr;
921  af = AF_INET;
922  options = ntohl (t4->options);
923  port = ntohs (t4->u4_port);
924  a4.s_addr = t4->ipv4_addr;
925  sb = &a4;
926  }
927  else
928  {
929  GNUNET_break_op (0);
930  return NULL;
931  }
932  inet_ntop (af,
933  sb,
934  buf,
935  INET6_ADDRSTRLEN);
936  GNUNET_snprintf (rbuf,
937  sizeof(rbuf),
938  (af == AF_INET6)
939  ? "%s.%u.[%s]:%u"
940  : "%s.%u.%s:%u",
941  PLUGIN_NAME,
942  options,
943  buf,
944  port);
945  return rbuf;
946 }
uint32_t options
Optional options and flags for this address.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
uint16_t u4_port
Port number, in network byte order.
struct in6_addr ipv6_addr
IPv6 address.
uint16_t u6_port
Port number, in network byte order.
Network format for IPv4 addresses.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint32_t ipv4_addr
IPv4 address, in network byte order.
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
static char buf[2048]
uint32_t options
Optional options and flags for this address.
Network format for IPv6 addresses.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
#define PLUGIN_NAME
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_broadcast_receive()

void udp_broadcast_receive ( struct Plugin plugin,
const char *  buf,
ssize_t  size,
const union UdpAddress udp_addr,
size_t  udp_addr_len,
enum GNUNET_NetworkType  network_type 
)

We received a broadcast message.

Process it and all subsequent messages in the same packet.

Parameters
pluginthe UDP plugin
bufthe buffer with the message(s)
sizenumber of bytes in buf
udp_addraddress of the sender
udp_addr_lennumber of bytes in udp_addr
network_typenetwork type of the sender's address

Definition at line 186 of file plugin_transport_udp_broadcasting.c.

References MstContext::ats_address_network_type, broadcast_mst_cb(), GNUNET_MST_create(), GNUNET_MST_destroy(), GNUNET_MST_from_buffer(), GNUNET_NO, MstContext::plugin, plugin, MstContext::udp_addr, and MstContext::udp_addr_len.

Referenced by udp_select_read().

192 {
193  struct GNUNET_MessageStreamTokenizer *broadcast_mst;
194  struct MstContext mc;
195 
196  broadcast_mst = GNUNET_MST_create (&broadcast_mst_cb,
197  &mc);
198  mc.plugin = plugin;
199  mc.udp_addr = udp_addr;
200  mc.udp_addr_len = udp_addr_len;
201  mc.ats_address_network_type = network_type;
202  GNUNET_MST_from_buffer (broadcast_mst,
203  buf, size,
204  GNUNET_NO,
205  GNUNET_NO);
206  GNUNET_MST_destroy (broadcast_mst);
207 }
#define GNUNET_NO
Definition: gnunet_common.h:81
Client-specific context for broadcast_mst_cb().
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:413
Handle to a message stream tokenizer.
Definition: mst.c:43
static char buf[2048]
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:87
static int broadcast_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Parse broadcast message received.
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:116
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static unsigned int size
Size of the "table".
Definition: peer.c:67
const union UdpAddress * udp_addr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_broadcast()

void setup_broadcast ( struct Plugin plugin,
struct sockaddr_in6 *  server_addrv6,
struct sockaddr_in *  server_addrv4 
)

Setup broadcasting subsystem.

Parameters
plugin
server_addrv6
server_addrv4

Definition at line 538 of file plugin_transport_udp_broadcasting.c.

References _, GNUNET_DATACACHE_PluginEnvironment::cfg, Plugin::enable_broadcasting, Plugin::enable_ipv4, Plugin::enable_ipv6, Plugin::env, GNUNET_assert, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_WARNING, GNUNET_NETWORK_socket_setsockopt(), GNUNET_OK, GNUNET_OS_network_interfaces_list(), GNUNET_YES, iface_proc(), inet_pton(), Plugin::ipv6_multicast_address, LOG, Plugin::port, Plugin::sockv4, and Plugin::sockv6.

Referenced by libgnunet_plugin_transport_udp_init().

541 {
542  if (GNUNET_YES ==
544  "topology",
545  "FRIENDS-ONLY"))
546  {
548  _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
549  return;
550  }
551 
552  if (GNUNET_YES != plugin->enable_broadcasting)
553  return; /* We do not send, just receive */
554 
555  /* create IPv4 broadcast socket */
556  if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
557  {
558  static int yes = 1;
559 
561  (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes,
562  sizeof (int)) != GNUNET_OK)
563  {
565  _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
566  ntohs (server_addrv4->sin_port));
567  }
568  }
569  /* create IPv6 multicast socket */
570  if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
571  {
572  memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6));
573  GNUNET_assert (1 ==
574  inet_pton (AF_INET6, "FF05::13B",
575  &plugin->ipv6_multicast_address.sin6_addr));
576  plugin->ipv6_multicast_address.sin6_family = AF_INET6;
577  plugin->ipv6_multicast_address.sin6_port = htons (plugin->port);
578  }
580 }
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:1005
int enable_broadcasting
Is broadcasting enabled: GNUNET_YES or GNUNET_NO.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
int enable_ipv4
Is IPv4 enabled: GNUNET_YES or GNUNET_NO.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:388
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define LOG(kind,...)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
uint16_t port
Port used.
static int iface_proc(void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
Callback function invoked for each interface found.
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
struct sockaddr_in6 ipv6_multicast_address
IPv6 multicast address.
int enable_ipv6
Is IPv6 enabled: GNUNET_YES or GNUNET_NO.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_broadcast()

void stop_broadcast ( struct Plugin plugin)

Stop broadcasting subsystem.

Parameters
plugin

Definition at line 589 of file plugin_transport_udp_broadcasting.c.

References BroadcastAddress::addr, BroadcastAddress::addrlen, Plugin::broadcast_head, Plugin::broadcast_tail, BroadcastAddress::broadcast_task, Plugin::enable_broadcasting, Plugin::enable_ipv6, GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_file_close(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror, GNUNET_NETWORK_socket_setsockopt(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, Plugin::ipv6_multicast_address, LOG, p, and Plugin::sockv6.

Referenced by libgnunet_plugin_transport_udp_done().

590 {
591  if (GNUNET_YES == plugin->enable_broadcasting)
592  {
593  /* Disable broadcasting */
594  while (plugin->broadcast_head != NULL)
595  {
596  struct BroadcastAddress *p = plugin->broadcast_head;
597 
598  if (p->broadcast_task != NULL)
599  {
601  p->broadcast_task = NULL;
602  }
603  if ((GNUNET_YES == plugin->enable_ipv6) &&
604  (NULL != plugin->sockv6) &&
605  (p->addrlen == sizeof (struct sockaddr_in6)))
606  {
607  /* Create IPv6 multicast request */
608  struct ipv6_mreq multicastRequest;
609  const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr;
610 
611  multicastRequest.ipv6mr_multiaddr =
612  plugin->ipv6_multicast_address.sin6_addr;
613  multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
614 
615  /* Leave the multicast group */
616  if (GNUNET_OK ==
618  (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
619  &multicastRequest, sizeof (multicastRequest)))
620  {
622  }
623  else
624  {
625  LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
626  }
627  }
628 
629 #if LINUX
630  GNUNET_DISK_file_close(p->cryogenic_fd);
631 #endif
633  plugin->broadcast_tail, p);
634  GNUNET_free (p->addr);
635  GNUNET_free (p);
636  }
637  }
638 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:1005
int enable_broadcasting
Is broadcasting enabled: GNUNET_YES or GNUNET_NO.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define LOG(kind,...)
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
struct GNUNET_SCHEDULER_Task * broadcast_task
ID of select broadcast task.
struct BroadcastAddress * broadcast_head
Tail of DLL of broadcast addresses.
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct BroadcastAddress * broadcast_tail
Head of DLL of broadcast addresses.
struct sockaddr_in6 ipv6_multicast_address
IPv6 multicast address.
int enable_ipv6
Is IPv6 enabled: GNUNET_YES or GNUNET_NO.
#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: