GNUnet  0.20.0
plugin_transport_udp_broadcasting.c File Reference

Neighbour discovery with UDP. More...

#include "platform.h"
#include "plugin_transport_udp.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_broadcasting.c:

Go to the source code of this file.

Data Structures

struct  UDP_Beacon_Message
 
struct  BroadcastAddress
 
struct  MstContext
 Client-specific context for broadcast_mst_cb(). More...
 

Macros

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

Functions

static int broadcast_mst_cb (void *cls, const struct GNUNET_MessageHeader *message)
 Parse broadcast message received. 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...
 
static unsigned int prepare_beacon (struct Plugin *plugin, struct UDP_Beacon_Message *msg)
 
static void udp_ipv4_broadcast_send (void *cls)
 
static void udp_ipv6_broadcast_send (void *cls)
 
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. 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

Neighbour discovery with UDP.

Author
Christian Grothoff
Matthias Wachs

Definition in file plugin_transport_udp_broadcasting.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 41 of file plugin_transport_udp_broadcasting.c.

Function Documentation

◆ broadcast_mst_cb()

static int broadcast_mst_cb ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Parse broadcast message received.

Parameters
clsthe struct Plugin
clientthe struct MstContext with sender address
messagethe message we received
Returns
GNUNET_OK (always)

Definition at line 136 of file plugin_transport_udp_broadcasting.c.

138 {
139  struct MstContext *mc = cls;
140  struct Plugin *plugin = mc->plugin;
142  const struct GNUNET_MessageHeader *hello;
143  const struct UDP_Beacon_Message *msg;
144 
145  msg = (const struct UDP_Beacon_Message *) message;
146 
148  ntohs (msg->header.type))
149  return GNUNET_OK;
151  "Received beacon with %u bytes from peer `%s' via address `%s'\n",
152  ntohs (msg->header.size),
153  GNUNET_i2s (&msg->sender),
154  udp_address_to_string (NULL,
155  mc->udp_addr,
156  mc->udp_addr_len));
157  hello = (struct GNUNET_MessageHeader *) &msg[1];
159  PLUGIN_NAME,
160  mc->udp_addr,
161  mc->udp_addr_len,
163  plugin->env->receive (plugin->env->cls,
164  address,
165  NULL,
166  hello);
168  GNUNET_STATISTICS_update (plugin->env->stats,
169  _ ("# Multicast HELLO beacons received via UDP"),
170  1, GNUNET_NO);
171  return GNUNET_OK;
172 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct TestcasePlugin * plugin
The process handle to the testbed service.
static char * address
GNS address for this phone.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:63
#define GNUNET_HELLO_address_free(addr)
Free an address.
@ GNUNET_HELLO_ADDRESS_INFO_NONE
No additional information.
@ GNUNET_OK
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON
Message send by a peer to notify the other to keep the session alive.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define PLUGIN_NAME
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.
#define LOG(kind,...)
An address for communicating with a peer.
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Client-specific context for broadcast_mst_cb().
Handle for a plugin.
Definition: block.c:38

References _, address, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_i2s(), GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), LOG, mc, msg, plugin, PLUGIN_NAME, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and udp_address_to_string().

Referenced by udp_broadcast_receive().

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.

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 }
static char buf[2048]
enum GNUNET_GenericReturnValue 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:101
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:404
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:86
static unsigned int size
Size of the "table".
Definition: peer.c:68
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:45
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:

◆ prepare_beacon()

static unsigned int prepare_beacon ( struct Plugin plugin,
struct UDP_Beacon_Message msg 
)
static

Definition at line 212 of file plugin_transport_udp_broadcasting.c.

214 {
215  uint16_t hello_size;
216  uint16_t msg_size;
217 
218  const struct GNUNET_MessageHeader *hello;
219 
220  hello = plugin->env->get_our_hello ();
221  if (NULL == hello)
222  return 0;
223  hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
224  msg_size = hello_size + sizeof(struct UDP_Beacon_Message);
225 
226  if ((hello_size < (sizeof(struct GNUNET_MessageHeader))) ||
227  (msg_size > (UDP_MTU)))
228  return 0;
229 
230  msg->sender = *(plugin->env->my_identity);
231  msg->header.size = htons (msg_size);
233  GNUNET_memcpy (&msg[1], hello, hello_size);
234  return msg_size;
235 }
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:630
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define UDP_MTU
MTU for fragmentation subsystem.
A HELLO message is used to exchange information about transports with other peers.

References GNUNET_HELLO_size(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON, msg, plugin, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and UDP_MTU.

Referenced by udp_ipv4_broadcast_send(), and udp_ipv6_broadcast_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_ipv4_broadcast_send()

static void udp_ipv4_broadcast_send ( void *  cls)
static

Definition at line 239 of file plugin_transport_udp_broadcasting.c.

240 {
241  struct BroadcastAddress *baddr = cls;
242  struct Plugin *plugin = baddr->plugin;
243  int sent;
244  uint16_t msg_size;
245  char buf[65536] GNUNET_ALIGN;
246 
247  baddr->broadcast_task = NULL;
248 
249  msg_size = prepare_beacon (plugin, (struct UDP_Beacon_Message *) &buf);
250  if (0 != msg_size)
251  {
252  struct sockaddr_in *addr = (struct sockaddr_in *) baddr->addr;
253 
254  addr->sin_port = htons (plugin->port);
255  sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, &buf, msg_size,
256  (const struct sockaddr *) addr,
257  baddr->addrlen);
258  if (sent == GNUNET_SYSERR)
259  {
260  if ((ENETUNREACH == errno) || (ENETDOWN == errno))
261  {
262  /* "Network unreachable" or "Network down"
263  *
264  * This indicates that we just do not have network connectivity
265  */
267  "Network connectivity is down, cannot send beacon!\n");
268  }
269  else
271  }
272  else
273  {
275  "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
276  GNUNET_a2s (baddr->addr, baddr->addrlen));
277  }
278  }
279 
280 #ifdef __linux__
281  /*
282  * Cryogenic
283  */
284  if (NULL != baddr->cryogenic_fd)
285  {
286  baddr->cryogenic_times.delay_msecs =
287  (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5;
288  baddr->cryogenic_times.timeout_msecs =
289  (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5;
290 
291  if (ioctl (baddr->cryogenic_fd->fd,
292  PM_SET_DELAY_AND_TIMEOUT,
293  &baddr->cryogenic_times) < 0)
294  {
296  baddr->broadcast_task =
297  GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
298  &udp_ipv4_broadcast_send, baddr);
299  }
300  else
302  baddr->cryogenic_fd,
304  baddr);
305  }
306  else
307 #endif
308  baddr->broadcast_task =
309  GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
310  &udp_ipv4_broadcast_send, baddr);
311 }
#define GNUNET_log(kind,...)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
@ GNUNET_SYSERR
#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...
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_BULK
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:771
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1689
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static unsigned int prepare_beacon(struct Plugin *plugin, struct UDP_Beacon_Message *msg)
static void udp_ipv4_broadcast_send(void *cls)
struct GNUNET_SCHEDULER_Task * broadcast_task
ID of select broadcast task.

References BroadcastAddress::addr, BroadcastAddress::addrlen, BroadcastAddress::broadcast_task, buf, GNUNET_a2s(), GNUNET_ALIGN, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_sendto(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_write_file(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, LOG, plugin, BroadcastAddress::plugin, and prepare_beacon().

Referenced by iface_proc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_ipv6_broadcast_send()

static void udp_ipv6_broadcast_send ( void *  cls)
static

Definition at line 315 of file plugin_transport_udp_broadcasting.c.

316 {
317  struct BroadcastAddress *baddr = cls;
318  struct Plugin *plugin = baddr->plugin;
319  ssize_t sent;
320  uint16_t msg_size;
321  char buf[65536] GNUNET_ALIGN;
322  const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) baddr->addr;
323 
324  baddr->broadcast_task = NULL;
325 
326  msg_size = prepare_beacon (plugin, (struct UDP_Beacon_Message *) &buf);
327  /* Note: unclear if this actually works to limit the multicast to
328  the specified interface as we're not (necessarily) using a
329  link-local multicast group and the kernel suggests that the
330  scope ID is only respected for link-local addresses; however,
331  if the scope ID is ignored, the kernel should just multicast
332  on ALL interfaces, which is merely slightly less efficient;
333  in that case, we might want to revert to only doing this
334  once, and not per interface (hard to test...) */plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id;
335  sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size,
336  (const struct sockaddr *)
337  &plugin->ipv6_multicast_address,
338  sizeof(struct sockaddr_in6));
339  plugin->ipv6_multicast_address.sin6_scope_id = 0;
340  if (sent == GNUNET_SYSERR)
341  {
342  if ((ENETUNREACH == errno) || (ENETDOWN == errno))
343  {
344  /* "Network unreachable" or "Network down"
345  *
346  * This indicates that this system is IPv6 enabled, but does not
347  * have a valid global IPv6 address assigned
349  "Network connectivity is down, cannot send beacon!\n");
350  }
351  else
353  }
354  else
355  {
357  "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n",
358  (int) sent,
359  GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address,
360  sizeof(struct sockaddr_in6)));
361  }
362 #ifdef __linux__
363  /*
364  * Cryogenic
365  */
366  if (NULL != baddr->cryogenic_fd)
367  {
368  baddr->cryogenic_times.delay_msecs =
369  (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5;
370  baddr->cryogenic_times.timeout_msecs =
371  (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5;
372 
373  if (ioctl (baddr->cryogenic_fd->fd,
374  PM_SET_DELAY_AND_TIMEOUT,
375  &baddr->cryogenic_times) < 0)
376  {
378  baddr->broadcast_task =
379  GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
380  &udp_ipv6_broadcast_send, baddr);
381  }
382  else
384  baddr->cryogenic_fd,
386  baddr);
387  }
388  else
389 #endif
390  baddr->broadcast_task =
391  GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
392  &udp_ipv6_broadcast_send, baddr);
393 }
static void udp_ipv6_broadcast_send(void *cls)

References BroadcastAddress::addr, BroadcastAddress::broadcast_task, buf, GNUNET_a2s(), GNUNET_ALIGN, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_sendto(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_write_file(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, LOG, plugin, BroadcastAddress::plugin, and prepare_beacon().

Referenced by iface_proc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iface_proc()

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 
)
static

Callback function invoked for each interface found.

Parameters
clsclosure with the struct Plugin
namename of the interface (can be NULL for unknown)
isDefaultis this presumably the default interface
addraddress of this interface (can be NULL for unknown or unassigned)
broadcast_addrthe broadcast address (can be NULL for unknown or unassigned)
netmaskthe network mask (can be NULL for unknown or unassigned)
addrlenlength of the address
Returns
GNUNET_OK to continue iteration, GNUNET_SYSERR to abort

Definition at line 409 of file plugin_transport_udp_broadcasting.c.

415 {
416  struct Plugin *plugin = cls;
417  struct BroadcastAddress *ba;
418  enum GNUNET_NetworkType network;
419 
420  if (NULL == addr)
421  return GNUNET_OK;
423  "address %s for interface %s %p\n ",
425  if (NULL == broadcast_addr)
426  return GNUNET_OK;
428  "broadcast address %s for interface %s %p\n ",
429  GNUNET_a2s (broadcast_addr, addrlen), name, broadcast_addr);
430  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ",
431  GNUNET_a2s (netmask, addrlen), name, netmask);
432 
433  network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr,
434  addrlen);
435  if (GNUNET_NT_LOOPBACK == network)
436  {
437  /* Broadcasting on loopback does not make sense */
438  return GNUNET_YES;
439  }
440 
441  ba = GNUNET_new (struct BroadcastAddress);
442  ba->plugin = plugin;
443  ba->addr = GNUNET_malloc (addrlen);
444  GNUNET_memcpy (ba->addr, broadcast_addr, addrlen);
445  ba->addrlen = addrlen;
446 
447  if ((GNUNET_YES == plugin->enable_ipv4) &&
448  (NULL != plugin->sockv4) &&
449  (addrlen == sizeof(struct sockaddr_in)))
450  {
451 #ifdef __linux__
452  /*
453  * setup Cryogenic FD for ipv4 broadcasting
454  */
455  char *filename;
456 
458  "/dev/cryogenic/%s",
459  name);
460  if (0 == access (name, R_OK))
461  {
462  ba->cryogenic_fd =
466  }
468 #endif
469  ba->broadcast_task =
471  }
472  if ((GNUNET_YES == plugin->enable_ipv6) &&
473  (NULL != plugin->sockv6) &&
474  (addrlen == sizeof(struct sockaddr_in6)))
475  {
476  /* Create IPv6 multicast request */
477  struct ipv6_mreq multicastRequest;
478  const struct sockaddr_in6 *s6 = (const struct
479  sockaddr_in6 *) broadcast_addr;
480 
481  multicastRequest.ipv6mr_multiaddr =
482  plugin->ipv6_multicast_address.sin6_addr;
483  /* http://tools.ietf.org/html/rfc2553#section-5.2:
484  *
485  * IPV6_JOIN_GROUP
486  *
487  * Join a multicast group on a specified local interface. If the
488  * interface index is specified as 0, the kernel chooses the local
489  * interface. For example, some kernels look up the multicast
490  * group in the normal IPv6 routing table and using the resulting
491  * interface; we do this for each interface, so no need to use
492  * zero (anymore...).
493  */multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
494 
495  /* Join the multicast group */
496  if (GNUNET_OK !=
498  (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP,
499  &multicastRequest, sizeof(multicastRequest)))
500  {
502  "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n");
503  }
504  else
505  {
506 #ifdef __linux__
507  /*
508  * setup Cryogenic FD for ipv6 broadcasting
509  */
510  char *filename;
511 
513  "/dev/cryogenic/%s",
514  name);
515  if (0 == access (name, R_OK))
516  {
517  ba->cryogenic_fd =
521  }
523 #endif
524  ba->broadcast_task =
526  }
527  }
528  GNUNET_CONTAINER_DLL_insert (plugin->broadcast_head,
529  plugin->broadcast_tail, ba);
530  return GNUNET_OK;
531 }
static char * filename
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
@ GNUNET_YES
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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:805
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:39
@ GNUNET_NT_LOOPBACK
Loopback (same host).
Definition: gnunet_nt_lib.h:48
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299
const char * name

References BroadcastAddress::addr, BroadcastAddress::addrlen, BroadcastAddress::broadcast_task, filename, GNUNET_a2s(), GNUNET_asprintf(), GNUNET_CONTAINER_DLL_insert, GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_socket_setsockopt(), GNUNET_new, GNUNET_NT_LOOPBACK, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_YES, LOG, name, plugin, BroadcastAddress::plugin, udp_ipv4_broadcast_send(), and udp_ipv6_broadcast_send().

Referenced by setup_broadcast().

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.

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 }
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".
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:397
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.

References _, 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(), LOG, and plugin.

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.

Parameters
plugin

Definition at line 595 of file plugin_transport_udp_broadcasting.c.

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  {
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;
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 #ifdef __linux__
636  GNUNET_DISK_file_close (p->cryogenic_fd);
637 #endif
638  GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head,
639  plugin->broadcast_tail, p);
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:38
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975