plugin_transport_udp_broadcasting.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2010, 2011 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file transport/plugin_transport_udp_broadcasting.c
  18. * @brief Neighbour discovery with UDP
  19. * @author Christian Grothoff
  20. * @author Matthias Wachs
  21. */
  22. #include "platform.h"
  23. #include "plugin_transport_udp.h"
  24. #include "gnunet_hello_lib.h"
  25. #include "gnunet_util_lib.h"
  26. #include "gnunet_fragmentation_lib.h"
  27. #include "gnunet_protocols.h"
  28. #include "gnunet_resolver_service.h"
  29. #include "gnunet_signatures.h"
  30. #include "gnunet_constants.h"
  31. #include "gnunet_statistics_service.h"
  32. #include "gnunet_transport_service.h"
  33. #include "gnunet_transport_plugin.h"
  34. #include "transport.h"
  35. #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
  36. /* *********** Cryogenic ********** */
  37. #if LINUX
  38. #include <sys/stat.h>
  39. #include <fcntl.h>
  40. #include <sys/ioctl.h>
  41. #include <sys/select.h>
  42. #include <sys/time.h>
  43. #define PM_MAGIC 'k'
  44. #define PM_SET_DELAY_AND_TIMEOUT _IOW(PM_MAGIC, 1, struct pm_times)
  45. struct pm_times {
  46. unsigned long delay_msecs;
  47. unsigned long timeout_msecs;
  48. };
  49. #endif
  50. /************************************/
  51. struct UDP_Beacon_Message
  52. {
  53. /**
  54. * Message header.
  55. */
  56. struct GNUNET_MessageHeader header;
  57. /**
  58. * What is the identity of the sender
  59. */
  60. struct GNUNET_PeerIdentity sender;
  61. };
  62. struct BroadcastAddress
  63. {
  64. struct BroadcastAddress *next;
  65. struct BroadcastAddress *prev;
  66. /**
  67. * ID of select broadcast task
  68. */
  69. struct GNUNET_SCHEDULER_Task * broadcast_task;
  70. struct Plugin *plugin;
  71. struct sockaddr *addr;
  72. socklen_t addrlen;
  73. #if LINUX
  74. /**
  75. * Cryogenic handle.
  76. */
  77. struct GNUNET_DISK_FileHandle *cryogenic_fd;
  78. /**
  79. * Time out for cryogenic.
  80. */
  81. struct pm_times cryogenic_times;
  82. #endif
  83. };
  84. /**
  85. * Client-specific context for #broadcast_mst_cb().
  86. */
  87. struct MstContext
  88. {
  89. struct Plugin *plugin;
  90. const union UdpAddress *udp_addr;
  91. size_t udp_addr_len;
  92. /**
  93. * ATS network type.
  94. */
  95. enum GNUNET_NetworkType ats_address_network_type;
  96. };
  97. /**
  98. * Parse broadcast message received.
  99. *
  100. * @param cls the `struct Plugin`
  101. * @param client the `struct MstContext` with sender address
  102. * @param message the message we received
  103. * @return #GNUNET_OK (always)
  104. */
  105. static int
  106. broadcast_mst_cb (void *cls,
  107. const struct GNUNET_MessageHeader *message)
  108. {
  109. struct MstContext *mc = cls;
  110. struct Plugin *plugin = mc->plugin;
  111. struct GNUNET_HELLO_Address *address;
  112. const struct GNUNET_MessageHeader *hello;
  113. const struct UDP_Beacon_Message *msg;
  114. msg = (const struct UDP_Beacon_Message *) message;
  115. if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON !=
  116. ntohs (msg->header.type))
  117. return GNUNET_OK;
  118. LOG (GNUNET_ERROR_TYPE_DEBUG,
  119. "Received beacon with %u bytes from peer `%s' via address `%s'\n",
  120. ntohs (msg->header.size),
  121. GNUNET_i2s (&msg->sender),
  122. udp_address_to_string (NULL,
  123. mc->udp_addr,
  124. mc->udp_addr_len));
  125. hello = (struct GNUNET_MessageHeader *) &msg[1];
  126. address = GNUNET_HELLO_address_allocate (&msg->sender,
  127. PLUGIN_NAME,
  128. mc->udp_addr,
  129. mc->udp_addr_len,
  130. GNUNET_HELLO_ADDRESS_INFO_NONE);
  131. plugin->env->receive (plugin->env->cls,
  132. address,
  133. NULL,
  134. hello);
  135. GNUNET_HELLO_address_free (address);
  136. GNUNET_STATISTICS_update (plugin->env->stats,
  137. _("# Multicast HELLO beacons received via UDP"),
  138. 1, GNUNET_NO);
  139. return GNUNET_OK;
  140. }
  141. /**
  142. * We received a broadcast message. Process it and all subsequent
  143. * messages in the same packet.
  144. *
  145. * @param plugin the UDP plugin
  146. * @param buf the buffer with the message(s)
  147. * @param size number of bytes in @a buf
  148. * @param udp_addr address of the sender
  149. * @param udp_addr_len number of bytes in @a udp_addr
  150. * @param network_type network type of the sender's address
  151. */
  152. void
  153. udp_broadcast_receive (struct Plugin *plugin,
  154. const char *buf,
  155. ssize_t size,
  156. const union UdpAddress *udp_addr,
  157. size_t udp_addr_len,
  158. enum GNUNET_NetworkType network_type)
  159. {
  160. struct GNUNET_MessageStreamTokenizer *broadcast_mst;
  161. struct MstContext mc;
  162. broadcast_mst = GNUNET_MST_create (&broadcast_mst_cb,
  163. &mc);
  164. mc.plugin = plugin;
  165. mc.udp_addr = udp_addr;
  166. mc.udp_addr_len = udp_addr_len;
  167. mc.ats_address_network_type = network_type;
  168. GNUNET_MST_from_buffer (broadcast_mst,
  169. buf, size,
  170. GNUNET_NO,
  171. GNUNET_NO);
  172. GNUNET_MST_destroy (broadcast_mst);
  173. }
  174. static unsigned int
  175. prepare_beacon (struct Plugin *plugin,
  176. struct UDP_Beacon_Message *msg)
  177. {
  178. uint16_t hello_size;
  179. uint16_t msg_size;
  180. const struct GNUNET_MessageHeader *hello;
  181. hello = plugin->env->get_our_hello ();
  182. if (NULL == hello)
  183. return 0;
  184. hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
  185. msg_size = hello_size + sizeof (struct UDP_Beacon_Message);
  186. if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||
  187. (msg_size > (UDP_MTU)))
  188. return 0;
  189. msg->sender = *(plugin->env->my_identity);
  190. msg->header.size = htons (msg_size);
  191. msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
  192. GNUNET_memcpy (&msg[1], hello, hello_size);
  193. return msg_size;
  194. }
  195. static void
  196. udp_ipv4_broadcast_send (void *cls)
  197. {
  198. struct BroadcastAddress *baddr = cls;
  199. struct Plugin *plugin = baddr->plugin;
  200. int sent;
  201. uint16_t msg_size;
  202. char buf[65536] GNUNET_ALIGN;
  203. baddr->broadcast_task = NULL;
  204. msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
  205. if (0 != msg_size)
  206. {
  207. struct sockaddr_in *addr = (struct sockaddr_in *) baddr->addr;
  208. addr->sin_port = htons (plugin->port);
  209. sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, &buf, msg_size,
  210. (const struct sockaddr *) addr,
  211. baddr->addrlen);
  212. if (sent == GNUNET_SYSERR)
  213. {
  214. if ((ENETUNREACH == errno) || (ENETDOWN == errno))
  215. {
  216. /* "Network unreachable" or "Network down"
  217. *
  218. * This indicates that we just do not have network connectivity
  219. */
  220. GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING,
  221. "Network connectivity is down, cannot send beacon!\n");
  222. }
  223. else
  224. GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
  225. }
  226. else
  227. {
  228. LOG (GNUNET_ERROR_TYPE_DEBUG,
  229. "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
  230. GNUNET_a2s (baddr->addr, baddr->addrlen));
  231. }
  232. }
  233. #if LINUX
  234. /*
  235. * Cryogenic
  236. */
  237. if (NULL != baddr->cryogenic_fd)
  238. {
  239. baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*0.5;
  240. baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*1.5;
  241. if (ioctl(baddr->cryogenic_fd->fd,
  242. PM_SET_DELAY_AND_TIMEOUT,
  243. &baddr->cryogenic_times) < 0)
  244. {
  245. GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl");
  246. baddr->broadcast_task =
  247. GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
  248. &udp_ipv4_broadcast_send, baddr);
  249. }
  250. else
  251. GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
  252. baddr->cryogenic_fd,
  253. &udp_ipv4_broadcast_send,
  254. baddr);
  255. }
  256. else
  257. #endif
  258. baddr->broadcast_task =
  259. GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
  260. &udp_ipv4_broadcast_send, baddr);
  261. }
  262. static void
  263. udp_ipv6_broadcast_send (void *cls)
  264. {
  265. struct BroadcastAddress *baddr = cls;
  266. struct Plugin *plugin = baddr->plugin;
  267. ssize_t sent;
  268. uint16_t msg_size;
  269. char buf[65536] GNUNET_ALIGN;
  270. const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) baddr->addr;
  271. baddr->broadcast_task = NULL;
  272. msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
  273. /* Note: unclear if this actually works to limit the multicast to
  274. the specified interface as we're not (necessarily) using a
  275. link-local multicast group and the kernel suggests that the
  276. scope ID is only respected for link-local addresses; however,
  277. if the scope ID is ignored, the kernel should just multicast
  278. on ALL interfaces, which is merely slightly less efficient;
  279. in that case, we might want to revert to only doing this
  280. once, and not per interface (hard to test...) */
  281. plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id;
  282. sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size,
  283. (const struct sockaddr *)
  284. &plugin->ipv6_multicast_address,
  285. sizeof (struct sockaddr_in6));
  286. plugin->ipv6_multicast_address.sin6_scope_id = 0;
  287. if (sent == GNUNET_SYSERR)
  288. {
  289. if ((ENETUNREACH == errno) || (ENETDOWN == errno))
  290. {
  291. /* "Network unreachable" or "Network down"
  292. *
  293. * This indicates that this system is IPv6 enabled, but does not
  294. * have a valid global IPv6 address assigned
  295. */
  296. GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING,
  297. "Network connectivity is down, cannot send beacon!\n");
  298. }
  299. else
  300. GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
  301. }
  302. else
  303. {
  304. LOG (GNUNET_ERROR_TYPE_DEBUG,
  305. "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n",
  306. (int) sent,
  307. GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address,
  308. sizeof (struct sockaddr_in6)));
  309. }
  310. #if LINUX
  311. /*
  312. * Cryogenic
  313. */
  314. if (NULL != baddr->cryogenic_fd)
  315. {
  316. baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*0.5;
  317. baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*1.5;
  318. if (ioctl(baddr->cryogenic_fd->fd,
  319. PM_SET_DELAY_AND_TIMEOUT,
  320. &baddr->cryogenic_times) < 0)
  321. {
  322. GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl");
  323. baddr->broadcast_task =
  324. GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
  325. &udp_ipv6_broadcast_send, baddr);
  326. }
  327. else
  328. GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
  329. baddr->cryogenic_fd,
  330. &udp_ipv6_broadcast_send,
  331. baddr);
  332. }
  333. else
  334. #endif
  335. baddr->broadcast_task =
  336. GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
  337. &udp_ipv6_broadcast_send, baddr);
  338. }
  339. /**
  340. * Callback function invoked for each interface found.
  341. *
  342. * @param cls closure with the `struct Plugin`
  343. * @param name name of the interface (can be NULL for unknown)
  344. * @param isDefault is this presumably the default interface
  345. * @param addr address of this interface (can be NULL for unknown or unassigned)
  346. * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
  347. * @param netmask the network mask (can be NULL for unknown or unassigned)
  348. * @param addrlen length of the address
  349. * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
  350. */
  351. static int
  352. iface_proc (void *cls,
  353. const char *name,
  354. int isDefault,
  355. const struct sockaddr *addr,
  356. const struct sockaddr *broadcast_addr,
  357. const struct sockaddr *netmask, socklen_t addrlen)
  358. {
  359. struct Plugin *plugin = cls;
  360. struct BroadcastAddress *ba;
  361. enum GNUNET_NetworkType network;
  362. if (NULL == addr)
  363. return GNUNET_OK;
  364. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  365. "address %s for interface %s %p\n ",
  366. GNUNET_a2s (addr, addrlen), name, addr);
  367. if (NULL == broadcast_addr)
  368. return GNUNET_OK;
  369. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  370. "broadcast address %s for interface %s %p\n ",
  371. GNUNET_a2s (broadcast_addr, addrlen), name, broadcast_addr);
  372. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ",
  373. GNUNET_a2s (netmask, addrlen), name, netmask);
  374. network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr, addrlen);
  375. if (GNUNET_NT_LOOPBACK == network)
  376. {
  377. /* Broadcasting on loopback does not make sense */
  378. return GNUNET_YES;
  379. }
  380. ba = GNUNET_new (struct BroadcastAddress);
  381. ba->plugin = plugin;
  382. ba->addr = GNUNET_malloc (addrlen);
  383. GNUNET_memcpy (ba->addr, broadcast_addr, addrlen);
  384. ba->addrlen = addrlen;
  385. if ( (GNUNET_YES == plugin->enable_ipv4) &&
  386. (NULL != plugin->sockv4) &&
  387. (addrlen == sizeof (struct sockaddr_in)) )
  388. {
  389. #if LINUX
  390. /*
  391. * setup Cryogenic FD for ipv4 broadcasting
  392. */
  393. char *filename;
  394. GNUNET_asprintf (&filename,
  395. "/dev/cryogenic/%s",
  396. name);
  397. if (0 == ACCESS (name, R_OK))
  398. {
  399. ba->cryogenic_fd =
  400. GNUNET_DISK_file_open (filename,
  401. GNUNET_DISK_OPEN_WRITE,
  402. GNUNET_DISK_PERM_NONE);
  403. }
  404. GNUNET_free (filename);
  405. #endif
  406. ba->broadcast_task =
  407. GNUNET_SCHEDULER_add_now (&udp_ipv4_broadcast_send, ba);
  408. }
  409. if ((GNUNET_YES == plugin->enable_ipv6) &&
  410. (NULL != plugin->sockv6) &&
  411. (addrlen == sizeof (struct sockaddr_in6)))
  412. {
  413. /* Create IPv6 multicast request */
  414. struct ipv6_mreq multicastRequest;
  415. const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) broadcast_addr;
  416. multicastRequest.ipv6mr_multiaddr =
  417. plugin->ipv6_multicast_address.sin6_addr;
  418. /* http://tools.ietf.org/html/rfc2553#section-5.2:
  419. *
  420. * IPV6_JOIN_GROUP
  421. *
  422. * Join a multicast group on a specified local interface. If the
  423. * interface index is specified as 0, the kernel chooses the local
  424. * interface. For example, some kernels look up the multicast
  425. * group in the normal IPv6 routing table and using the resulting
  426. * interface; we do this for each interface, so no need to use
  427. * zero (anymore...).
  428. */
  429. multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
  430. /* Join the multicast group */
  431. if (GNUNET_OK !=
  432. GNUNET_NETWORK_socket_setsockopt
  433. (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP,
  434. &multicastRequest, sizeof (multicastRequest)))
  435. {
  436. LOG (GNUNET_ERROR_TYPE_WARNING,
  437. "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n");
  438. }
  439. else
  440. {
  441. #if LINUX
  442. /*
  443. * setup Cryogenic FD for ipv6 broadcasting
  444. */
  445. char *filename;
  446. GNUNET_asprintf (&filename,
  447. "/dev/cryogenic/%s",
  448. name);
  449. if (0 == ACCESS (name, R_OK))
  450. {
  451. ba->cryogenic_fd =
  452. GNUNET_DISK_file_open (filename,
  453. GNUNET_DISK_OPEN_WRITE,
  454. GNUNET_DISK_PERM_NONE);
  455. }
  456. GNUNET_free (filename);
  457. #endif
  458. ba->broadcast_task =
  459. GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, ba);
  460. }
  461. }
  462. GNUNET_CONTAINER_DLL_insert (plugin->broadcast_head,
  463. plugin->broadcast_tail, ba);
  464. return GNUNET_OK;
  465. }
  466. /**
  467. * Setup broadcasting subsystem.
  468. *
  469. * @param plugin
  470. * @param server_addrv6
  471. * @param server_addrv4
  472. */
  473. void
  474. setup_broadcast (struct Plugin *plugin,
  475. struct sockaddr_in6 *server_addrv6,
  476. struct sockaddr_in *server_addrv4)
  477. {
  478. if (GNUNET_YES ==
  479. GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
  480. "topology",
  481. "FRIENDS-ONLY"))
  482. {
  483. LOG (GNUNET_ERROR_TYPE_WARNING,
  484. _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
  485. return;
  486. }
  487. if (GNUNET_YES != plugin->enable_broadcasting)
  488. return; /* We do not send, just receive */
  489. /* create IPv4 broadcast socket */
  490. if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
  491. {
  492. static int yes = 1;
  493. if (GNUNET_NETWORK_socket_setsockopt
  494. (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes,
  495. sizeof (int)) != GNUNET_OK)
  496. {
  497. LOG (GNUNET_ERROR_TYPE_WARNING,
  498. _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
  499. ntohs (server_addrv4->sin_port));
  500. }
  501. }
  502. /* create IPv6 multicast socket */
  503. if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
  504. {
  505. memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6));
  506. GNUNET_assert (1 ==
  507. inet_pton (AF_INET6, "FF05::13B",
  508. &plugin->ipv6_multicast_address.sin6_addr));
  509. plugin->ipv6_multicast_address.sin6_family = AF_INET6;
  510. plugin->ipv6_multicast_address.sin6_port = htons (plugin->port);
  511. }
  512. GNUNET_OS_network_interfaces_list (&iface_proc, plugin);
  513. }
  514. /**
  515. * Stop broadcasting subsystem.
  516. *
  517. * @param plugin
  518. */
  519. void
  520. stop_broadcast (struct Plugin *plugin)
  521. {
  522. if (GNUNET_YES == plugin->enable_broadcasting)
  523. {
  524. /* Disable broadcasting */
  525. while (plugin->broadcast_head != NULL)
  526. {
  527. struct BroadcastAddress *p = plugin->broadcast_head;
  528. if (p->broadcast_task != NULL)
  529. {
  530. GNUNET_SCHEDULER_cancel (p->broadcast_task);
  531. p->broadcast_task = NULL;
  532. }
  533. if ((GNUNET_YES == plugin->enable_ipv6) &&
  534. (NULL != plugin->sockv6) &&
  535. (p->addrlen == sizeof (struct sockaddr_in6)))
  536. {
  537. /* Create IPv6 multicast request */
  538. struct ipv6_mreq multicastRequest;
  539. const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr;
  540. multicastRequest.ipv6mr_multiaddr =
  541. plugin->ipv6_multicast_address.sin6_addr;
  542. multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
  543. /* Leave the multicast group */
  544. if (GNUNET_OK ==
  545. GNUNET_NETWORK_socket_setsockopt
  546. (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
  547. &multicastRequest, sizeof (multicastRequest)))
  548. {
  549. GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
  550. }
  551. else
  552. {
  553. LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
  554. }
  555. }
  556. #if LINUX
  557. GNUNET_DISK_file_close(p->cryogenic_fd);
  558. #endif
  559. GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head,
  560. plugin->broadcast_tail, p);
  561. GNUNET_free (p->addr);
  562. GNUNET_free (p);
  563. }
  564. }
  565. }
  566. /* end of plugin_transport_udp_broadcasting.c */