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

858 {
859  static char rbuf[INET6_ADDRSTRLEN + 10];
860  char buf[INET6_ADDRSTRLEN];
861  const void *sb;
862  struct in_addr a4;
863  struct in6_addr a6;
864  const struct IPv4UdpAddress *t4;
865  const struct IPv6UdpAddress *t6;
866  int af;
867  uint16_t port;
868  uint32_t options;
869 
870  if (NULL == addr)
871  {
872  GNUNET_break_op(0);
873  return NULL;
874  }
875 
876  if (addrlen == sizeof(struct IPv6UdpAddress))
877  {
878  t6 = addr;
879  af = AF_INET6;
880  options = ntohl(t6->options);
881  port = ntohs(t6->u6_port);
882  a6 = t6->ipv6_addr;
883  sb = &a6;
884  }
885  else if (addrlen == sizeof(struct IPv4UdpAddress))
886  {
887  t4 = addr;
888  af = AF_INET;
889  options = ntohl(t4->options);
890  port = ntohs(t4->u4_port);
891  a4.s_addr = t4->ipv4_addr;
892  sb = &a4;
893  }
894  else
895  {
896  GNUNET_break_op(0);
897  return NULL;
898  }
899  inet_ntop(af, sb, buf, INET6_ADDRSTRLEN);
900  GNUNET_snprintf(rbuf,
901  sizeof(rbuf),
902  (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
903  PLUGIN_NAME,
904  options,
905  buf,
906  port);
907  return rbuf;
908 }
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:81
#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 183 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().

189 {
190  struct GNUNET_MessageStreamTokenizer *broadcast_mst;
191  struct MstContext mc;
192 
193  broadcast_mst = GNUNET_MST_create(&broadcast_mst_cb,
194  &mc);
195  mc.plugin = plugin;
196  mc.udp_addr = udp_addr;
197  mc.udp_addr_len = udp_addr_len;
198  mc.ats_address_network_type = network_type;
199  GNUNET_MST_from_buffer(broadcast_mst,
200  buf, size,
201  GNUNET_NO,
202  GNUNET_NO);
203  GNUNET_MST_destroy(broadcast_mst);
204 }
#define GNUNET_NO
Definition: gnunet_common.h:78
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:410
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:84
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:113
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static unsigned int size
Size of the "table".
Definition: peer.c:66
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 535 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(), Plugin::ipv6_multicast_address, LOG, Plugin::port, Plugin::sockv4, and Plugin::sockv6.

Referenced by libgnunet_plugin_transport_udp_init().

538 {
539  if (GNUNET_YES ==
541  "topology",
542  "FRIENDS-ONLY"))
543  {
545  _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
546  return;
547  }
548 
549  if (GNUNET_YES != plugin->enable_broadcasting)
550  return; /* We do not send, just receive */
551 
552  /* create IPv4 broadcast socket */
553  if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
554  {
555  static int yes = 1;
556 
558  (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes,
559  sizeof(int)) != GNUNET_OK)
560  {
562  _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
563  ntohs(server_addrv4->sin_port));
564  }
565  }
566  /* create IPv6 multicast socket */
567  if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
568  {
569  memset(&plugin->ipv6_multicast_address, 0, sizeof(struct sockaddr_in6));
570  GNUNET_assert(1 ==
571  inet_pton(AF_INET6, "FF05::13B",
572  &plugin->ipv6_multicast_address.sin6_addr));
573  plugin->ipv6_multicast_address.sin6_family = AF_INET6;
574  plugin->ipv6_multicast_address.sin6_port = htons(plugin->port);
575  }
577 }
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:871
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:75
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:181
#define LOG(kind,...)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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:77
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 586 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().

587 {
588  if (GNUNET_YES == plugin->enable_broadcasting)
589  {
590  /* Disable broadcasting */
591  while (plugin->broadcast_head != NULL)
592  {
593  struct BroadcastAddress *p = plugin->broadcast_head;
594 
595  if (p->broadcast_task != NULL)
596  {
598  p->broadcast_task = NULL;
599  }
600  if ((GNUNET_YES == plugin->enable_ipv6) &&
601  (NULL != plugin->sockv6) &&
602  (p->addrlen == sizeof(struct sockaddr_in6)))
603  {
604  /* Create IPv6 multicast request */
605  struct ipv6_mreq multicastRequest;
606  const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)p->addr;
607 
608  multicastRequest.ipv6mr_multiaddr =
609  plugin->ipv6_multicast_address.sin6_addr;
610  multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
611 
612  /* Leave the multicast group */
613  if (GNUNET_OK ==
615  (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
616  &multicastRequest, sizeof(multicastRequest)))
617  {
619  }
620  else
621  {
622  LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
623  }
624  }
625 
626 #if LINUX
627  GNUNET_DISK_file_close(p->cryogenic_fd);
628 #endif
630  plugin->broadcast_tail, p);
631  GNUNET_free(p->addr);
632  GNUNET_free(p);
633  }
634  }
635 }
#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:871
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:1339
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:77
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:956
Here is the call graph for this function:
Here is the caller graph for this function: