GNUnet  0.11.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 864 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().

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

Referenced by udp_select_read().

193 {
194  struct GNUNET_MessageStreamTokenizer *broadcast_mst;
195  struct MstContext mc;
196 
197  broadcast_mst = GNUNET_MST_create (&broadcast_mst_cb,
198  &mc);
199  mc.plugin = plugin;
200  mc.udp_addr = udp_addr;
201  mc.udp_addr_len = udp_addr_len;
202  mc.ats_address_network_type = network_type;
203  GNUNET_MST_from_buffer (broadcast_mst,
204  buf, size,
205  GNUNET_NO,
206  GNUNET_NO);
207  GNUNET_MST_destroy (broadcast_mst);
208 }
#define GNUNET_NO
Definition: gnunet_common.h:78
Client-specific context for broadcast_mst_cb().
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:411
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:85
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:114
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static char * plugin
Solver plugin name as string.
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 542 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().

545 {
546  if (GNUNET_YES ==
548  "topology",
549  "FRIENDS-ONLY"))
550  {
552  _ (
553  "Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
554  return;
555  }
556 
557  if (GNUNET_YES != plugin->enable_broadcasting)
558  return; /* We do not send, just receive */
559 
560  /* create IPv4 broadcast socket */
561  if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
562  {
563  static int yes = 1;
564 
566  (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes,
567  sizeof(int)) != GNUNET_OK)
568  {
570  _ (
571  "Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
572  ntohs (server_addrv4->sin_port));
573  }
574  }
575  /* create IPv6 multicast socket */
576  if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
577  {
578  memset (&plugin->ipv6_multicast_address, 0, sizeof(struct sockaddr_in6));
579  GNUNET_assert (1 ==
580  inet_pton (AF_INET6, "FF05::13B",
581  &plugin->ipv6_multicast_address.sin6_addr));
582  plugin->ipv6_multicast_address.sin6_family = AF_INET6;
583  plugin->ipv6_multicast_address.sin6_port = htons (plugin->port);
584  }
586 }
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:883
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:396
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 595 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().

596 {
597  if (GNUNET_YES == plugin->enable_broadcasting)
598  {
599  /* Disable broadcasting */
600  while (plugin->broadcast_head != NULL)
601  {
602  struct BroadcastAddress *p = plugin->broadcast_head;
603 
604  if (p->broadcast_task != NULL)
605  {
607  p->broadcast_task = NULL;
608  }
609  if ((GNUNET_YES == plugin->enable_ipv6) &&
610  (NULL != plugin->sockv6) &&
611  (p->addrlen == sizeof(struct sockaddr_in6)))
612  {
613  /* Create IPv6 multicast request */
614  struct ipv6_mreq multicastRequest;
615  const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr;
616 
617  multicastRequest.ipv6mr_multiaddr =
618  plugin->ipv6_multicast_address.sin6_addr;
619  multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
620 
621  /* Leave the multicast group */
622  if (GNUNET_OK ==
624  (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
625  &multicastRequest, sizeof(multicastRequest)))
626  {
628  }
629  else
630  {
631  LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
632  }
633  }
634 
635 #if LINUX
636  GNUNET_DISK_file_close (p->cryogenic_fd);
637 #endif
639  plugin->broadcast_tail, p);
640  GNUNET_free (p->addr);
641  GNUNET_free (p);
642  }
643  }
644 }
#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:883
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:1345
#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:966
Here is the call graph for this function:
Here is the caller graph for this function: