]>
Commit | Line | Data |
---|---|---|
42cc2e53 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
e25c139f | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
42cc2e53 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 07 Multicast */ |
10 | ||
582c2af2 | 11 | #include "squid.h" |
e0d28505 | 12 | #include "comm/Connection.h" |
582c2af2 | 13 | #include "Debug.h" |
e0d28505 AJ |
14 | // XXX: for icpIncomingConn - need to pass it as a generic parameter. |
15 | #include "ICP.h" | |
714e68b7 | 16 | #include "ipcache.h" |
afabcc13 | 17 | #include "multicast.h" |
42cc2e53 | 18 | |
19 | int | |
20 | mcastSetTtl(int fd, int mcast_ttl) | |
21 | { | |
22 | #ifdef IP_MULTICAST_TTL | |
23 | char ttl = (char) mcast_ttl; | |
62e76326 | 24 | |
42cc2e53 | 25 | if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0) |
e0236918 | 26 | debugs(50, DBG_IMPORTANT, "comm_set_mcast_ttl: FD " << fd << ", TTL: " << mcast_ttl << ": " << xstrerror()); |
62e76326 | 27 | |
42cc2e53 | 28 | #endif |
62e76326 | 29 | |
42cc2e53 | 30 | return 0; |
31 | } | |
32 | ||
33 | void | |
4a3b98d7 | 34 | mcastJoinGroups(const ipcache_addrs *ia, const Dns::LookupDetails &, void *) |
42cc2e53 | 35 | { |
36 | #ifdef IP_MULTICAST_TTL | |
42cc2e53 | 37 | struct ip_mreq mr; |
38 | int i; | |
62e76326 | 39 | |
42cc2e53 | 40 | if (ia == NULL) { |
fa84c01d | 41 | debugs(7, DBG_CRITICAL, "comm_join_mcast_groups: Unknown host"); |
62e76326 | 42 | return; |
42cc2e53 | 43 | } |
62e76326 | 44 | |
95dc7ff4 | 45 | for (i = 0; i < (int) ia->count; ++i) { |
055421ee | 46 | debugs(7, 9, "Listening for ICP requests on " << ia->in_addrs[i] ); |
cc192b50 | 47 | |
4dd643d5 | 48 | if ( ! ia->in_addrs[i].isIPv4() ) { |
055421ee | 49 | debugs(7, 9, "ERROR: IPv6 Multicast Listen has not been implemented!"); |
cc192b50 | 50 | continue; |
51 | } | |
cc192b50 | 52 | |
4dd643d5 | 53 | ia->in_addrs[i].getInAddr(mr.imr_multiaddr); |
cc192b50 | 54 | |
62e76326 | 55 | mr.imr_interface.s_addr = INADDR_ANY; |
62e76326 | 56 | |
e0d28505 AJ |
57 | if (setsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mr, sizeof(struct ip_mreq)) < 0) |
58 | debugs(7, DBG_IMPORTANT, "ERROR: Join failed for " << icpIncomingConn << ", Multicast IP=" << ia->in_addrs[i]); | |
62e76326 | 59 | |
e0d28505 AJ |
60 | char c = 0; |
61 | if (setsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1) < 0) | |
62 | debugs(7, DBG_IMPORTANT, "ERROR: " << icpIncomingConn << " can't disable multicast loopback: " << xstrerror()); | |
42cc2e53 | 63 | } |
62e76326 | 64 | |
42cc2e53 | 65 | #endif |
66 | } | |
f53969cc | 67 |