]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/icmp/Icmp.h
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 37 ICMP Routines */
11 #ifndef _INCLUDE_ICMP_H
12 #define _INCLUDE_ICMP_H
14 #include "ip/Address.h"
16 #define PINGER_PAYLOAD_SZ 8192
18 #define MAX_PAYLOAD 256 // WAS: SQUIDHOSTNAMELEN
19 #define MAX_PKT4_SZ (sizeof(struct icmphdr) + sizeof(struct icmpEchoData) + 1)
20 #define MAX_PKT6_SZ (sizeof(struct icmp6_hdr) + sizeof(struct icmpEchoData) + 1)
24 /* This is a line-data format struct. DO NOT alter. */
27 pingerEchoData() { memset(&payload
, 0, sizeof(payload
)); }
29 unsigned char opcode
= '\0';
31 char payload
[PINGER_PAYLOAD_SZ
];
34 /* This is a line-data format struct. DO NOT alter. */
35 struct pingerReplyData
{
36 pingerReplyData() { memset(&payload
, 0, sizeof(payload
)); }
38 unsigned char opcode
= '\0';
42 char payload
[PINGER_PAYLOAD_SZ
];
48 char payload
[MAX_PAYLOAD
];
51 extern int icmp_pkts_sent
;
56 * Implements the squid interface to access ICMP operations
59 * Child implementations define specific parts of these operations
60 * using these methods as a naming and parameter template.
62 * IcmpSquid - implements the squid side of squid-pinger interface
63 * IcmpPinger - implements the pinger side of the squid-pinger interface
64 * Icmpv4 - implements pinger helper for Icmpv4
65 * Icmpv6 - implements pinger helper for Icmpv6
73 /// Start pinger helper and initiate control channel
74 virtual int Open() =0;
76 /// Shutdown pinger helper and control channel
82 * Construct and Send an ECHO request
84 \param to Destination address being 'pinged'
85 \param opcode Specific code for ECHO request, see RFC ????.
86 \param payload A payload MAY be sent in the ICMP message.
87 * Content longer than MAX_PAYLOAD will be truncated.
88 \param len Length of the payload in bytes if any is to be sent or 0.
90 virtual void SendEcho(Ip::Address
&to
, int opcode
, const char *payload
=nullptr, int len
=0) =0;
92 /// Handle ICMP responses.
93 virtual void Recv(void) =0;
96 /* shared internal methods */
98 /// Calculate a packet checksum
99 int CheckSum(unsigned short *ptr
, int size
);
102 * Translate TTL to a hop distance
104 \param ttl negative : n > 33
105 \param ttl n(0...32) : 32 >= n >= 1
106 \param ttl n(33...62) : 32 >= n >= 1
107 \param ttl n(63...64) : 2 >= n >= 1
108 \param ttl n(65...128) : 64 >= n >= 1
109 \param ttl n(129...192) : 64 >= n >= 1
110 \param ttl n(193...) : n < 255
112 \bug BUG? ttl<0 can produce high hop values
113 \bug BUG? ttl>255 can produce zero or negative hop values
118 void Log(const Ip::Address
&addr
, const uint8_t type
, const char* pkt_str
, const int rtt
, const int hops
);
120 /* no use wasting memory */
123 #endif /* USE_ICMP */