GNUnet  0.17.6
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...


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


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.

Christian Grothoff
Nathan Evans
Matthias Wachs

Definition in file plugin_transport_udp.h.

Macro Definition Documentation


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

Definition at line 44 of file plugin_transport_udp.h.


#define PLUGIN_NAME   "udp"

Definition at line 46 of file plugin_transport_udp.h.



Definition at line 48 of file plugin_transport_udp.h.



Definition at line 50 of file plugin_transport_udp.h.


#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.

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.

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

Definition at line 864 of file plugin_transport_udp.c.

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;
877  if (NULL == addr)
878  {
879  GNUNET_break_op (0);
880  return NULL;
881  }
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",
911  options,
912  buf,
913  port);
914  return rbuf;
915 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
static char buf[2048]
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
Network format for IPv4 addresses.
Network format for IPv6 addresses.

References buf, GNUNET_break_op, GNUNET_snprintf(), options, PLUGIN_NAME, port, t4, and t6.

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

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.

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.

193 {
194  struct GNUNET_MessageStreamTokenizer *broadcast_mst;
195  struct MstContext mc;
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,
206  GNUNET_NO);
207  GNUNET_MST_destroy (broadcast_mst);
208 }
struct Plugin * plugin
The process handle to the testbed service.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
Definition: gnunet_common.h:98
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:418
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
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 unsigned int size
Size of the "table".
Definition: peer.c:67
static int broadcast_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Parse broadcast message received.
Handle to a message stream tokenizer.
Definition: mst.c:44
Client-specific context for broadcast_mst_cb().
const union UdpAddress * udp_addr

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

Referenced by udp_select_read().

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.


Definition at line 542 of file plugin_transport_udp_broadcasting.c.

545 {
546  if (GNUNET_YES ==
548  "topology",
550  {
552  _ (
553  "Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
554  return;
555  }
558  return; /* We do not send, just receive */
560  /* create IPv4 broadcast socket */
561  if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
562  {
563  static int yes = 1;
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 }
enum GNUNET_GenericReturnValue 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".
Definition: gnunet_common.h:99
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:828
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:396
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#define LOG(kind,...)
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.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
int enable_ipv6
Is IPv6 enabled: GNUNET_YES or GNUNET_NO.
int enable_ipv4
Is IPv4 enabled: GNUNET_YES or GNUNET_NO.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
int enable_broadcasting
Is broadcasting enabled: GNUNET_YES or GNUNET_NO.
char * port
Port we bind to.
struct sockaddr_in6 ipv6_multicast_address
IPv6 multicast address.
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.

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, Plugin::port, Plugin::sockv4, and Plugin::sockv6.

Referenced by libgnunet_plugin_transport_udp_init().

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.


Definition at line 595 of file plugin_transport_udp_broadcasting.c.

596 {
598  {
599  /* Disable broadcasting */
600  while (plugin->broadcast_head != NULL)
601  {
604  if (p->broadcast_task != NULL)
605  {
606  GNUNET_SCHEDULER_cancel (p->broadcast_task);
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;
617  multicastRequest.ipv6mr_multiaddr =
618  plugin->ipv6_multicast_address.sin6_addr;
619  multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
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  }
635 #ifdef __linux__
636  GNUNET_DISK_file_close (p->cryogenic_fd);
637 #endif
640  GNUNET_free (p->addr);
641  GNUNET_free (p);
642  }
643  }
644 }
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#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 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:957
struct BroadcastAddress * broadcast_head
Tail of DLL of broadcast addresses.
struct BroadcastAddress * broadcast_tail
Head of DLL of broadcast addresses.