multicast.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2025 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 "compat/socket.h"
14 #include "debug/Stream.h"
15 // XXX: for icpIncomingConn - need to pass it as a generic parameter.
16 #include "ICP.h"
17 #include "ipcache.h"
18 #include "multicast.h"
19 
20 int
21 mcastSetTtl(int fd, int mcast_ttl)
22 {
23 #ifdef IP_MULTICAST_TTL
24  char ttl = (char) mcast_ttl;
25 
26  if (xsetsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0) {
27  int xerrno = errno;
28  debugs(50, DBG_IMPORTANT, "mcastSetTtl: FD " << fd << ", TTL: " << mcast_ttl << ": " << xstrerr(xerrno));
29  }
30 #endif
31 
32  return 0;
33 }
34 
35 void
37 {
38 #ifdef IP_MULTICAST_TTL
39  struct ip_mreq mr;
40 
41  if (ia == nullptr) {
42  debugs(7, DBG_CRITICAL, "ERROR: comm_join_mcast_groups: Unknown host");
43  return;
44  }
45 
46  for (const auto &ip: ia->goodAndBad()) { // TODO: Consider using just good().
47  debugs(7, 9, "Listening for ICP requests on " << ip);
48 
49  if (!ip.isIPv4()) {
50  debugs(7, 9, "ERROR: IPv6 Multicast Listen has not been implemented!");
51  continue;
52  }
53 
54  ip.getInAddr(mr.imr_multiaddr);
55 
56  mr.imr_interface.s_addr = INADDR_ANY;
57 
58  if (xsetsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr, sizeof(struct ip_mreq)) < 0)
59  debugs(7, DBG_IMPORTANT, "ERROR: Join failed for " << icpIncomingConn << ", Multicast IP=" << ip);
60 
61  char c = 0;
62  if (xsetsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1) < 0) {
63  int xerrno = errno;
64  debugs(7, DBG_IMPORTANT, "ERROR: " << icpIncomingConn << " can't disable multicast loopback: " << xstrerr(xerrno));
65  }
66  }
67 
68 #endif
69 }
70 
const char * xstrerr(int error)
Definition: xstrerror.cc:83
#define DBG_CRITICAL
Definition: Stream.h:37
void mcastJoinGroups(const ipcache_addrs *ia, const Dns::LookupDetails &, void *)
Definition: multicast.cc:36
int xsetsockopt(int socketFd, int level, int option, const void *value, socklen_t valueLength)
POSIX setsockopt(2) equivalent.
Definition: socket.h:122
encapsulates DNS lookup results
Definition: LookupDetails.h:22
Comm::ConnectionPointer icpIncomingConn
Definition: icp_v2.cc:99
int mcastSetTtl(int fd, int mcast_ttl)
Definition: multicast.cc:21
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
IpsSelector< IpsIterator > goodAndBad() const
all IPs
Definition: ipcache.h:249

 

Introduction

Documentation

Support

Miscellaneous