]> git.ipfire.org Git - thirdparty/squid.git/blob - src/multicast.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / multicast.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 07 Multicast */
10
11 #include "squid.h"
12 #include "comm/Connection.h"
13 #include "Debug.h"
14 // XXX: for icpIncomingConn - need to pass it as a generic parameter.
15 #include "ICP.h"
16 #include "ipcache.h"
17 #include "multicast.h"
18
19 int
20 mcastSetTtl(int fd, int mcast_ttl)
21 {
22 #ifdef IP_MULTICAST_TTL
23 char ttl = (char) mcast_ttl;
24
25 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0)
26 debugs(50, DBG_IMPORTANT, "comm_set_mcast_ttl: FD " << fd << ", TTL: " << mcast_ttl << ": " << xstrerror());
27
28 #endif
29
30 return 0;
31 }
32
33 void
34 mcastJoinGroups(const ipcache_addrs *ia, const DnsLookupDetails &, void *)
35 {
36 #ifdef IP_MULTICAST_TTL
37 struct ip_mreq mr;
38 int i;
39
40 if (ia == NULL) {
41 debugs(7, DBG_CRITICAL, "comm_join_mcast_groups: Unknown host");
42 return;
43 }
44
45 for (i = 0; i < (int) ia->count; ++i) {
46 debugs(7, 9, "Listening for ICP requests on " << ia->in_addrs[i] );
47
48 if ( ! ia->in_addrs[i].isIPv4() ) {
49 debugs(7, 9, "ERROR: IPv6 Multicast Listen has not been implemented!");
50 continue;
51 }
52
53 ia->in_addrs[i].getInAddr(mr.imr_multiaddr);
54
55 mr.imr_interface.s_addr = INADDR_ANY;
56
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]);
59
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());
63 }
64
65 #endif
66 }
67