]> git.ipfire.org Git - thirdparty/squid.git/blob - src/icmp/Icmp.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / icmp / Icmp.h
1 /*
2 * Copyright (C) 1996-2015 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 37 ICMP Routines */
10
11 #ifndef _INCLUDE_ICMP_H
12 #define _INCLUDE_ICMP_H
13
14 #include "ip/Address.h"
15
16 #define PINGER_PAYLOAD_SZ 8192
17
18 #define MAX_PAYLOAD 256 // WAS: SQUIDHOSTNAMELEN
19 #define MAX_PKT4_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmphdr) + 1)
20 #define MAX_PKT6_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmp6_hdr) + 1)
21
22 #if USE_ICMP
23
24 /* This is a line-data format struct. DO NOT alter. */
25 struct pingerEchoData {
26 Ip::Address to;
27 unsigned char opcode;
28 int psize;
29 char payload[PINGER_PAYLOAD_SZ];
30 };
31
32 /* This is a line-data format struct. DO NOT alter. */
33 struct pingerReplyData {
34 Ip::Address from;
35 unsigned char opcode;
36 int rtt;
37 int hops;
38 int psize;
39 char payload[PINGER_PAYLOAD_SZ];
40 };
41
42 struct icmpEchoData {
43 struct timeval tv;
44 unsigned char opcode;
45 char payload[MAX_PAYLOAD];
46 };
47
48 extern int icmp_pkts_sent;
49
50 #endif /* USE_ICMP */
51
52 /**
53 * Implements the squid interface to access ICMP operations
54 *
55 \par
56 * Child implementations define specific parts of these operations
57 * using these methods as a naming and parameter template.
58 *
59 * IcmpSquid - implements the squid side of squid-pinger interface
60 * IcmpPinger - implements the pinger side of the squid-pinger interface
61 * Icmpv4 - implements pinger helper for Icmpv4
62 * Icmpv6 - implements pinger helper for Icmpv6
63 */
64 class Icmp
65 {
66 public:
67 Icmp();
68 virtual ~Icmp() {};
69
70 /// Start pinger helper and initiate control channel
71 virtual int Open() =0;
72
73 /// Shutdown pinger helper and control channel
74 virtual void Close();
75
76 #if USE_ICMP
77
78 /**
79 * Construct and Send an ECHO request
80 *
81 \param to Destination address being 'pinged'
82 \param opcode Specific code for ECHO request, see RFC ????.
83 \param payload A payload MAY be sent in the ICMP message.
84 * Content longer than MAX_PAYLOAD will be truncated.
85 \param len Length of the payload in bytes if any is to be sent or 0.
86 */
87 virtual void SendEcho(Ip::Address &to, int opcode, const char *payload=NULL, int len=0) =0;
88
89 /// Handle ICMP responses.
90 virtual void Recv(void) =0;
91
92 protected:
93 /* shared internal methods */
94
95 /// Calculate a packet checksum
96 int CheckSum(unsigned short *ptr, int size);
97
98 /**
99 * Translate TTL to a hop distance
100 *
101 \param ttl negative : n > 33
102 \param ttl n(0...32) : 32 >= n >= 1
103 \param ttl n(33...62) : 32 >= n >= 1
104 \param ttl n(63...64) : 2 >= n >= 1
105 \param ttl n(65...128) : 64 >= n >= 1
106 \param ttl n(129...192) : 64 >= n >= 1
107 \param ttl n(193...) : n < 255
108 *
109 \bug BUG? ttl<0 can produce high hop values
110 \bug BUG? ttl>255 can produce zero or negative hop values
111 */
112 int ipHops(int ttl);
113
114 /// Log the packet.
115 void Log(const Ip::Address &addr, const uint8_t type, const char* pkt_str, const int rtt, const int hops);
116
117 /* no use wasting memory */
118 int icmp_sock;
119 int icmp_ident;
120 #endif /* USE_ICMP */
121 };
122
123 #endif
124