]> git.ipfire.org Git - thirdparty/squid.git/blame - src/multicast.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / multicast.cc
CommitLineData
42cc2e53 1/*
5b74111a 2 * Copyright (C) 1996-2018 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
19int
20mcastSetTtl(int fd, int mcast_ttl)
21{
22#ifdef IP_MULTICAST_TTL
23 char ttl = (char) mcast_ttl;
62e76326 24
b69e9ffa
AJ
25 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0) {
26 int xerrno = errno;
27 debugs(50, DBG_IMPORTANT, "mcastSetTtl: FD " << fd << ", TTL: " << mcast_ttl << ": " << xstrerr(xerrno));
28 }
42cc2e53 29#endif
62e76326 30
42cc2e53 31 return 0;
32}
33
34void
4a3b98d7 35mcastJoinGroups(const ipcache_addrs *ia, const Dns::LookupDetails &, void *)
42cc2e53 36{
37#ifdef IP_MULTICAST_TTL
42cc2e53 38 struct ip_mreq mr;
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
fd9c47d1
AR
45 for (const auto ip: ia->goodAndBad()) { // TODO: Consider using just good().
46 debugs(7, 9, "Listening for ICP requests on " << ip);
cc192b50 47
fd9c47d1 48 if (!ip.isIPv4()) {
055421ee 49 debugs(7, 9, "ERROR: IPv6 Multicast Listen has not been implemented!");
cc192b50 50 continue;
51 }
cc192b50 52
fd9c47d1 53 ip.getInAddr(mr.imr_multiaddr);
cc192b50 54
62e76326 55 mr.imr_interface.s_addr = INADDR_ANY;
62e76326 56
e0d28505 57 if (setsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mr, sizeof(struct ip_mreq)) < 0)
fd9c47d1 58 debugs(7, DBG_IMPORTANT, "ERROR: Join failed for " << icpIncomingConn << ", Multicast IP=" << ip);
62e76326 59
e0d28505 60 char c = 0;
b69e9ffa
AJ
61 if (setsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1) < 0) {
62 int xerrno = errno;
63 debugs(7, DBG_IMPORTANT, "ERROR: " << icpIncomingConn << " can't disable multicast loopback: " << xstrerr(xerrno));
64 }
42cc2e53 65 }
62e76326 66
42cc2e53 67#endif
68}
f53969cc 69