25 static const char *icmpPktStr[] = {
29 "Destination Unreachable",
48 snprintf(buf,
sizeof(buf),
"ICMP %u (invalid)", v);
90 size_t icmp_pktsize =
sizeof(
struct icmphdr);
91 struct addrinfo *S =
nullptr;
93 static_assert(
sizeof(*icmp) +
sizeof(*echo) <=
sizeof(pkt),
"our custom ICMPv4 Echo payload fits the packet buffer");
97 icmp = (
struct icmphdr *) (
void *) pkt;
110 icmp->icmp_cksum = 0;
116 echo =
reinterpret_cast<icmpEchoData *
>(
reinterpret_cast<char *
>(pkt) +
sizeof(*icmp));
117 echo->
opcode = (
unsigned char) opcode;
120 icmp_pktsize +=
sizeof(
struct timeval) + sizeof(char);
126 memcpy(echo->
payload, payload, len);
131 icmp->icmp_cksum =
CheckSum((
unsigned short *) icmp, icmp_pktsize);
134 ((sockaddr_in*)S->ai_addr)->sin_port = 0;
137 debugs(42, 5,
"Send ICMP packet to " << to <<
".");
151 Log(to,
' ',
nullptr, 0, 0);
159 struct addrinfo *from =
nullptr;
160 int iphdrlen =
sizeof(
iphdr);
161 struct iphdr *ip =
nullptr;
162 struct icmphdr *icmp =
nullptr;
163 static char *pkt =
nullptr;
192#if GETTIMEOFDAY_NO_TZP
198 gettimeofday(&
now,
nullptr);
202 debugs(42, 8, n <<
" bytes from " << preply.
from);
204 ip = (
struct iphdr *) (
void *) pkt;
206#if HAVE_STRUCT_IPHDR_IP_HL
208 iphdrlen = ip->ip_hl << 2;
213 iphdrlen = (ip->ip_vhl >> 4) << 2;
217 iphdrlen = (ip->ip_vhl & 0xF) << 2;
222 icmp = (
struct icmphdr *) (
void *) (pkt + iphdrlen);
236 preply.
opcode = echo->opcode;
241 memcpy(&tv, &echo->tv,
sizeof(
struct timeval));
246 if (preply.
psize < 0) {
static const char * IcmpPacketType(uint8_t v)
IcmpPinger control
pinger helper contains one of these as a global object.
void SendEcho(Ip::Address &, int, const char *, int) override
void Recv(void) override
Handle ICMP responses.
int Open() override
Start pinger helper and initiate control channel.
void SendResult(pingerReplyData &preply, int len)
Send ICMP results back to squid.
virtual void Close()
Shutdown pinger helper and control channel.
int CheckSum(unsigned short *ptr, int size)
Calculate a packet checksum.
void Log(const Ip::Address &addr, const uint8_t type, const char *pkt_str, const int rtt, const int hops)
Log the packet.
static void InitAddr(struct addrinfo *&ai)
static void FreeAddr(struct addrinfo *&ai)
void getAddrInfo(struct addrinfo *&ai, int force=AF_UNSPEC) const
#define debugs(SECTION, LEVEL, CONTENT)
#define LOCAL_ARRAY(type, name, size)
char payload[MAX_PAYLOAD]
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
int tvSubMsec(struct timeval t1, struct timeval t2)
const char * xstrerr(int error)