GNUnet  0.10.x
Data Structures | Macros | Functions
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__)

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 135 of file plugin_transport_udp_broadcasting.c.

References _, address, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, 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(), UDP_Beacon_Message::header, LOG, mc, msg, MstContext::plugin, plugin, PLUGIN_NAME, UDP_Beacon_Message::sender, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, MstContext::udp_addr, MstContext::udp_addr_len, and udp_address_to_string().

Referenced by udp_broadcast_receive().

137 {
138  struct MstContext *mc = cls;
139  struct Plugin *plugin = mc->plugin;
141  const struct GNUNET_MessageHeader *hello;
142  const struct UDP_Beacon_Message *msg;
143 
144  msg = (const struct UDP_Beacon_Message *) message;
145 
147  ntohs (msg->header.type))
148  return GNUNET_OK;
150  "Received beacon with %u bytes from peer `%s' via address `%s'\n",
151  ntohs (msg->header.size),
152  GNUNET_i2s (&msg->sender),
153  udp_address_to_string (NULL,
154  mc->udp_addr,
155  mc->udp_addr_len));
156  hello = (struct GNUNET_MessageHeader *) &msg[1];
157  address = GNUNET_HELLO_address_allocate (&msg->sender,
158  PLUGIN_NAME,
159  mc->udp_addr,
160  mc->udp_addr_len,
162  plugin->env->receive (plugin->env->cls,
163  address,
164  NULL,
165  hello);
166  GNUNET_HELLO_address_free (address);
167  GNUNET_STATISTICS_update (plugin->env->stats,
168  _("# Multicast HELLO beacons received via UDP"),
169  1, GNUNET_NO);
170  return GNUNET_OK;
171 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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:73
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
Client-specific context for broadcast_mst_cb().
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:208
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define LOG(kind,...)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
struct GNUNET_MessageHeader header
Message header.
No additional information.
Handle for a plugin.
Definition: block.c:37
#define PLUGIN_NAME
An address for communicating with a peer.
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.
void * cls
Closure to use for callbacks.
Header for all communications.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON
Message send by a peer to notify the other to keep the session alive.
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_HELLO_address_free(addr)
Free an address.
const union UdpAddress * udp_addr
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:

◆ prepare_beacon()

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

Definition at line 211 of file plugin_transport_udp_broadcasting.c.

References Plugin::env, GNUNET_HELLO_size(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON, UDP_Beacon_Message::header, UDP_Beacon_Message::sender, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and UDP_MTU.

Referenced by udp_ipv4_broadcast_send(), and udp_ipv6_broadcast_send().

213 {
214  uint16_t hello_size;
215  uint16_t msg_size;
216 
217  const struct GNUNET_MessageHeader *hello;
218  hello = plugin->env->get_our_hello ();
219  if (NULL == hello)
220  return 0;
221  hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
222  msg_size = hello_size + sizeof (struct UDP_Beacon_Message);
223 
224  if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||
225  (msg_size > (UDP_MTU)))
226  return 0;
227 
228  msg->sender = *(plugin->env->my_identity);
229  msg->header.size = htons (msg_size);
231  GNUNET_memcpy (&msg[1], hello, hello_size);
232  return msg_size;
233 }
A HELLO message is used to exchange information about transports with other peers.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
#define UDP_MTU
MTU for fragmentation subsystem.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_memcpy(dst, src, n)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_MessageHeader header
Message header.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:649
Header for all communications.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON
Message send by a peer to notify the other to keep the session alive.
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 237 of file plugin_transport_udp_broadcasting.c.

References BroadcastAddress::addr, BroadcastAddress::addrlen, Plugin::broadcast_interval, 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, BroadcastAddress::plugin, plugin, Plugin::port, prepare_beacon(), GNUNET_TIME_Relative::rel_value_us, and Plugin::sockv4.

Referenced by iface_proc().

238 {
239  struct BroadcastAddress *baddr = cls;
240  struct Plugin *plugin = baddr->plugin;
241  int sent;
242  uint16_t msg_size;
243  char buf[65536] GNUNET_ALIGN;
244 
245  baddr->broadcast_task = NULL;
246 
247  msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
248  if (0 != msg_size)
249  {
250  struct sockaddr_in *addr = (struct sockaddr_in *) baddr->addr;
251 
252  addr->sin_port = htons (plugin->port);
253  sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, &buf, msg_size,
254  (const struct sockaddr *) addr,
255  baddr->addrlen);
256  if (sent == GNUNET_SYSERR)
257  {
258  if ((ENETUNREACH == errno) || (ENETDOWN == errno))
259  {
260  /* "Network unreachable" or "Network down"
261  *
262  * This indicates that we just do not have network connectivity
263  */
265  "Network connectivity is down, cannot send beacon!\n");
266  }
267  else
269  }
270  else
271  {
273  "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
274  GNUNET_a2s (baddr->addr, baddr->addrlen));
275  }
276  }
277 
278 #if LINUX
279  /*
280  * Cryogenic
281  */
282  if (NULL != baddr->cryogenic_fd)
283  {
284  baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*0.5;
285  baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*1.5;
286 
287  if (ioctl(baddr->cryogenic_fd->fd,
288  PM_SET_DELAY_AND_TIMEOUT,
289  &baddr->cryogenic_times) < 0)
290  {
292  baddr->broadcast_task =
294  &udp_ipv4_broadcast_send, baddr);
295  }
296  else
298  baddr->cryogenic_fd,
300  baddr);
301 
302  }
303  else
304 #endif
305  baddr->broadcast_task =
307  &udp_ipv4_broadcast_send, baddr);
308 }
uint64_t rel_value_us
The actual value.
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:1675
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
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:1246
#define LOG(kind,...)
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:968
static char buf[2048]
static unsigned int prepare_beacon(struct Plugin *plugin, struct UDP_Beacon_Message *msg)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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)...
static void udp_ipv4_broadcast_send(void *cls)
struct GNUNET_SCHEDULER_Task * broadcast_task
ID of select broadcast task.
struct GNUNET_TIME_Relative broadcast_interval
Broadcast interval.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
uint16_t port
Port used.
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 312 of file plugin_transport_udp_broadcasting.c.

References BroadcastAddress::addr, Plugin::broadcast_interval, 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, Plugin::ipv6_multicast_address, LOG, BroadcastAddress::plugin, plugin, prepare_beacon(), GNUNET_TIME_Relative::rel_value_us, and Plugin::sockv6.

Referenced by iface_proc().

313 {
314  struct BroadcastAddress *baddr = cls;
315  struct Plugin *plugin = baddr->plugin;
316  ssize_t sent;
317  uint16_t msg_size;
318  char buf[65536] GNUNET_ALIGN;
319  const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) baddr->addr;
320 
321  baddr->broadcast_task = NULL;
322 
323  msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
324  /* Note: unclear if this actually works to limit the multicast to
325  the specified interface as we're not (necessarily) using a
326  link-local multicast group and the kernel suggests that the
327  scope ID is only respected for link-local addresses; however,
328  if the scope ID is ignored, the kernel should just multicast
329  on ALL interfaces, which is merely slightly less efficient;
330  in that case, we might want to revert to only doing this
331  once, and not per interface (hard to test...) */
332  plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id;
333  sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size,
334  (const struct sockaddr *)
335  &plugin->ipv6_multicast_address,
336  sizeof (struct sockaddr_in6));
337  plugin->ipv6_multicast_address.sin6_scope_id = 0;
338  if (sent == GNUNET_SYSERR)
339  {
340  if ((ENETUNREACH == errno) || (ENETDOWN == errno))
341  {
342  /* "Network unreachable" or "Network down"
343  *
344  * This indicates that this system is IPv6 enabled, but does not
345  * have a valid global IPv6 address assigned
346  */
348  "Network connectivity is down, cannot send beacon!\n");
349  }
350  else
352  }
353  else
354  {
356  "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n",
357  (int) sent,
358  GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address,
359  sizeof (struct sockaddr_in6)));
360  }
361 #if LINUX
362  /*
363  * Cryogenic
364  */
365  if (NULL != baddr->cryogenic_fd)
366  {
367  baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*0.5;
368  baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*1.5;
369 
370  if (ioctl(baddr->cryogenic_fd->fd,
371  PM_SET_DELAY_AND_TIMEOUT,
372  &baddr->cryogenic_times) < 0)
373  {
375  baddr->broadcast_task =
377  &udp_ipv6_broadcast_send, baddr);
378  }
379  else
381  baddr->cryogenic_fd,
383  baddr);
384  }
385  else
386 #endif
387  baddr->broadcast_task =
389  &udp_ipv6_broadcast_send, baddr);
390 }
uint64_t rel_value_us
The actual value.
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:1675
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
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:1246
#define LOG(kind,...)
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:968
static char buf[2048]
static unsigned int prepare_beacon(struct Plugin *plugin, struct UDP_Beacon_Message *msg)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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)...
struct GNUNET_SCHEDULER_Task * broadcast_task
ID of select broadcast task.
struct GNUNET_TIME_Relative broadcast_interval
Broadcast interval.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
static void udp_ipv6_broadcast_send(void *cls)
struct sockaddr_in6 ipv6_multicast_address
IPv6 multicast address.
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 406 of file plugin_transport_udp_broadcasting.c.

References ACCESS, BroadcastAddress::addr, BroadcastAddress::addrlen, Plugin::broadcast_head, Plugin::broadcast_tail, BroadcastAddress::broadcast_task, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::enable_ipv4, Plugin::enable_ipv6, Plugin::env, 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, Plugin::ipv6_multicast_address, LOG, BroadcastAddress::plugin, plugin, Plugin::sockv4, Plugin::sockv6, udp_ipv4_broadcast_send(), and udp_ipv6_broadcast_send().

Referenced by setup_broadcast().

412 {
413  struct Plugin *plugin = cls;
414  struct BroadcastAddress *ba;
415  enum GNUNET_NetworkType network;
416 
417  if (NULL == addr)
418  return GNUNET_OK;
420  "address %s for interface %s %p\n ",
422  if (NULL == broadcast_addr)
423  return GNUNET_OK;
425  "broadcast address %s for interface %s %p\n ",
426  GNUNET_a2s (broadcast_addr, addrlen), name, broadcast_addr);
427  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ",
428  GNUNET_a2s (netmask, addrlen), name, netmask);
429 
430  network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr, addrlen);
431  if (GNUNET_NT_LOOPBACK == network)
432  {
433  /* Broadcasting on loopback does not make sense */
434  return GNUNET_YES;
435  }
436 
437  ba = GNUNET_new (struct BroadcastAddress);
438  ba->plugin = plugin;
439  ba->addr = GNUNET_malloc (addrlen);
440  GNUNET_memcpy (ba->addr, broadcast_addr, addrlen);
441  ba->addrlen = addrlen;
442 
443  if ( (GNUNET_YES == plugin->enable_ipv4) &&
444  (NULL != plugin->sockv4) &&
445  (addrlen == sizeof (struct sockaddr_in)) )
446  {
447 #if LINUX
448  /*
449  * setup Cryogenic FD for ipv4 broadcasting
450  */
451  char *filename;
452 
453  GNUNET_asprintf (&filename,
454  "/dev/cryogenic/%s",
455  name);
456  if (0 == ACCESS (name, R_OK))
457  {
458  ba->cryogenic_fd =
459  GNUNET_DISK_file_open (filename,
462  }
463  GNUNET_free (filename);
464 #endif
465  ba->broadcast_task =
467  }
468  if ((GNUNET_YES == plugin->enable_ipv6) &&
469  (NULL != plugin->sockv6) &&
470  (addrlen == sizeof (struct sockaddr_in6)))
471  {
472  /* Create IPv6 multicast request */
473  struct ipv6_mreq multicastRequest;
474  const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) broadcast_addr;
475 
476  multicastRequest.ipv6mr_multiaddr =
477  plugin->ipv6_multicast_address.sin6_addr;
478  /* http://tools.ietf.org/html/rfc2553#section-5.2:
479  *
480  * IPV6_JOIN_GROUP
481  *
482  * Join a multicast group on a specified local interface. If the
483  * interface index is specified as 0, the kernel chooses the local
484  * interface. For example, some kernels look up the multicast
485  * group in the normal IPv6 routing table and using the resulting
486  * interface; we do this for each interface, so no need to use
487  * zero (anymore...).
488  */
489  multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
490 
491  /* Join the multicast group */
492  if (GNUNET_OK !=
494  (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP,
495  &multicastRequest, sizeof (multicastRequest)))
496  {
498  "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n");
499  }
500  else
501  {
502 #if LINUX
503  /*
504  * setup Cryogenic FD for ipv6 broadcasting
505  */
506  char *filename;
507 
508  GNUNET_asprintf (&filename,
509  "/dev/cryogenic/%s",
510  name);
511  if (0 == ACCESS (name, R_OK))
512  {
513  ba->cryogenic_fd =
514  GNUNET_DISK_file_open (filename,
517  }
518  GNUNET_free (filename);
519 #endif
520  ba->broadcast_task =
522  }
523  }
525  plugin->broadcast_tail, ba);
526  return GNUNET_OK;
527 }
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
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int enable_ipv4
Is IPv4 enabled: GNUNET_YES or GNUNET_NO.
Nobody is allowed to do anything to the file.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_memcpy(dst, src, n)
#define LOG(kind,...)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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:1273
static char * filename
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)...
static void udp_ipv4_broadcast_send(void *cls)
struct GNUNET_SCHEDULER_Task * broadcast_task
ID of select broadcast task.
struct BroadcastAddress * broadcast_head
Tail of DLL of broadcast addresses.
Open the file for writing.
const char * name
Loopback (same host).
Definition: gnunet_nt_lib.h:45
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void udp_ipv6_broadcast_send(void *cls)
struct BroadcastAddress * broadcast_tail
Head of DLL of broadcast addresses.
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:1673
#define ACCESS(p, m)
Definition: plibc.h:656
struct sockaddr_in6 ipv6_multicast_address
IPv6 multicast address.
#define GNUNET_malloc(size)
Wrapper around malloc.
int enable_ipv6
Is IPv6 enabled: GNUNET_YES or GNUNET_NO.
#define GNUNET_free(ptr)
Wrapper around free.
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 &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; 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: