diff options
Diffstat (limited to 'src/transport/plugin_transport_udp_broadcasting.c')
-rw-r--r-- | src/transport/plugin_transport_udp_broadcasting.c | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index 35c2a0ea5..61ac3d10e 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c | |||
@@ -612,6 +612,10 @@ setup_broadcast (struct Plugin *plugin, | |||
612 | GNUNET_SERVER_mst_create (&broadcast_ipv4_mst_cb, plugin); | 612 | GNUNET_SERVER_mst_create (&broadcast_ipv4_mst_cb, plugin); |
613 | plugin->broadcast_ipv6_mst = | 613 | plugin->broadcast_ipv6_mst = |
614 | GNUNET_SERVER_mst_create (&broadcast_ipv6_mst_cb, plugin); | 614 | GNUNET_SERVER_mst_create (&broadcast_ipv6_mst_cb, plugin); |
615 | |||
616 | if (GNUNET_YES != plugin->enable_broadcasting) | ||
617 | return; /* We do not send, just receive */ | ||
618 | |||
615 | /* create IPv4 broadcast socket */ | 619 | /* create IPv4 broadcast socket */ |
616 | if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) | 620 | if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) |
617 | { | 621 | { |
@@ -626,6 +630,7 @@ setup_broadcast (struct Plugin *plugin, | |||
626 | ntohs (server_addrv4->sin_port)); | 630 | ntohs (server_addrv4->sin_port)); |
627 | } | 631 | } |
628 | } | 632 | } |
633 | /* create IPv6 multicast socket */ | ||
629 | if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL)) | 634 | if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL)) |
630 | { | 635 | { |
631 | memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6)); | 636 | memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6)); |
@@ -642,49 +647,55 @@ setup_broadcast (struct Plugin *plugin, | |||
642 | void | 647 | void |
643 | stop_broadcast (struct Plugin *plugin) | 648 | stop_broadcast (struct Plugin *plugin) |
644 | { | 649 | { |
645 | while (plugin->broadcast_head != NULL) | 650 | if (GNUNET_YES == plugin->enable_broadcasting) |
646 | { | 651 | { |
647 | struct BroadcastAddress *p = plugin->broadcast_head; | 652 | /* Disable broadcasting */ |
648 | 653 | while (plugin->broadcast_head != NULL) | |
649 | if (p->broadcast_task != GNUNET_SCHEDULER_NO_TASK) | ||
650 | { | 654 | { |
651 | GNUNET_SCHEDULER_cancel (p->broadcast_task); | 655 | struct BroadcastAddress *p = plugin->broadcast_head; |
652 | p->broadcast_task = GNUNET_SCHEDULER_NO_TASK; | ||
653 | } | ||
654 | if ((GNUNET_YES == plugin->enable_ipv6) && | ||
655 | (NULL != plugin->sockv6) && | ||
656 | (p->addrlen == sizeof (struct sockaddr_in6))) | ||
657 | { | ||
658 | /* Create IPv6 multicast request */ | ||
659 | struct ipv6_mreq multicastRequest; | ||
660 | const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr; | ||
661 | 656 | ||
662 | multicastRequest.ipv6mr_multiaddr = | 657 | if (p->broadcast_task != GNUNET_SCHEDULER_NO_TASK) |
663 | plugin->ipv6_multicast_address.sin6_addr; | ||
664 | multicastRequest.ipv6mr_interface = s6->sin6_scope_id; | ||
665 | |||
666 | /* Leave the multicast group */ | ||
667 | if (GNUNET_OK == | ||
668 | GNUNET_NETWORK_socket_setsockopt | ||
669 | (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP, | ||
670 | &multicastRequest, sizeof (multicastRequest))) | ||
671 | { | 658 | { |
672 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, setsockopt); | 659 | GNUNET_SCHEDULER_cancel (p->broadcast_task); |
660 | p->broadcast_task = GNUNET_SCHEDULER_NO_TASK; | ||
673 | } | 661 | } |
674 | else | 662 | if ((GNUNET_YES == plugin->enable_ipv6) && |
663 | (NULL != plugin->sockv6) && | ||
664 | (p->addrlen == sizeof (struct sockaddr_in6))) | ||
675 | { | 665 | { |
676 | LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n"); | 666 | /* Create IPv6 multicast request */ |
667 | struct ipv6_mreq multicastRequest; | ||
668 | const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr; | ||
669 | |||
670 | multicastRequest.ipv6mr_multiaddr = | ||
671 | plugin->ipv6_multicast_address.sin6_addr; | ||
672 | multicastRequest.ipv6mr_interface = s6->sin6_scope_id; | ||
673 | |||
674 | /* Leave the multicast group */ | ||
675 | if (GNUNET_OK == | ||
676 | GNUNET_NETWORK_socket_setsockopt | ||
677 | (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP, | ||
678 | &multicastRequest, sizeof (multicastRequest))) | ||
679 | { | ||
680 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, setsockopt); | ||
681 | } | ||
682 | else | ||
683 | { | ||
684 | LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n"); | ||
685 | } | ||
677 | } | 686 | } |
678 | } | ||
679 | 687 | ||
680 | #if LINUX | 688 | #if LINUX |
681 | GNUNET_DISK_file_close(p->cryogenic_fd); | 689 | GNUNET_DISK_file_close(p->cryogenic_fd); |
682 | #endif | 690 | #endif |
683 | GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head, | 691 | GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head, |
684 | plugin->broadcast_tail, p); | 692 | plugin->broadcast_tail, p); |
685 | GNUNET_free (p->addr); | 693 | GNUNET_free (p->addr); |
686 | GNUNET_free (p); | 694 | GNUNET_free (p); |
695 | } | ||
687 | } | 696 | } |
697 | |||
698 | /* Destroy MSTs */ | ||
688 | if (NULL != plugin->broadcast_ipv4_mst) | 699 | if (NULL != plugin->broadcast_ipv4_mst) |
689 | { | 700 | { |
690 | GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv4_mst); | 701 | GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv4_mst); |