multicast.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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/Stream.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
19int
20mcastSetTtl(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 int xerrno = errno;
27 debugs(50, DBG_IMPORTANT, "mcastSetTtl: FD " << fd << ", TTL: " << mcast_ttl << ": " << xstrerr(xerrno));
28 }
29#endif
30
31 return 0;
32}
33
34void
36{
37#ifdef IP_MULTICAST_TTL
38 struct ip_mreq mr;
39
40 if (ia == nullptr) {
41 debugs(7, DBG_CRITICAL, "ERROR: comm_join_mcast_groups: Unknown host");
42 return;
43 }
44
45 for (const auto &ip: ia->goodAndBad()) { // TODO: Consider using just good().
46 debugs(7, 9, "Listening for ICP requests on " << ip);
47
48 if (!ip.isIPv4()) {
49 debugs(7, 9, "ERROR: IPv6 Multicast Listen has not been implemented!");
50 continue;
51 }
52
53 ip.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=" << ip);
59
60 char c = 0;
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 }
65 }
66
67#endif
68}
69
IpsSelector< IpsIterator > goodAndBad() const
all IPs
Definition: ipcache.h:249
encapsulates DNS lookup results
Definition: LookupDetails.h:23
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
Comm::ConnectionPointer icpIncomingConn
Definition: icp_v2.cc:99
int mcastSetTtl(int fd, int mcast_ttl)
Definition: multicast.cc:20
void mcastJoinGroups(const ipcache_addrs *ia, const Dns::LookupDetails &, void *)
Definition: multicast.cc:35
const char * xstrerr(int error)
Definition: xstrerror.cc:83

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors