]> git.ipfire.org Git - thirdparty/squid.git/blob - src/icmp/Icmp.h
Merge from trunk. and Save Comm::Connection in IoCallback
[thirdparty/squid.git] / src / icmp / Icmp.h
1 /*
2 * DEBUG: section 37 ICMP Routines
3 * AUTHOR: Duane Wessels, Amos Jeffries
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32 #ifndef _INCLUDE_ICMP_H
33 #define _INCLUDE_ICMP_H
34
35 #include "ip/Address.h"
36
37 #define PINGER_PAYLOAD_SZ 8192
38
39 #define MAX_PAYLOAD 256 // WAS: SQUIDHOSTNAMELEN
40 #define MAX_PKT4_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmphdr) + 1)
41 #define MAX_PKT6_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmp6_hdr) + 1)
42
43 #if USE_ICMP
44
45 /* This is a line-data format struct. DO NOT alter. */
46 struct pingerEchoData {
47 Ip::Address to;
48 unsigned char opcode;
49 int psize;
50 char payload[PINGER_PAYLOAD_SZ];
51 };
52
53 /* This is a line-data format struct. DO NOT alter. */
54 struct pingerReplyData {
55 Ip::Address from;
56 unsigned char opcode;
57 int rtt;
58 int hops;
59 int psize;
60 char payload[PINGER_PAYLOAD_SZ];
61 };
62
63 struct icmpEchoData {
64 struct timeval tv;
65 unsigned char opcode;
66 char payload[MAX_PAYLOAD];
67 };
68
69 SQUIDCEXTERN int icmp_pkts_sent;
70
71 #endif /* USE_ICMP */
72
73
74 /**
75 * Implements the squid interface to access ICMP operations
76 *
77 \par
78 * Child implementations define specific parts of these operations
79 * using these methods as a naming and parameter template.
80 *
81 * IcmpSquid - implements the squid side of squid-pinger interface
82 * IcmpPinger - implements the pinger side of the squid-pinger interface
83 * Icmpv4 - implements pinger helper for Icmpv4
84 * Icmpv6 - implements pinger helper for Icmpv6
85 */
86 class Icmp
87 {
88 public:
89 Icmp();
90 virtual ~Icmp() {};
91
92 /// Start pinger helper and initiate control channel
93 virtual int Open() =0;
94
95 /// Shutdown pinger helper and control channel
96 virtual void Close();
97
98 #if USE_ICMP
99
100 /**
101 * Construct and Send an ECHO request
102 *
103 \param to Destination address being 'pinged'
104 \param opcode Specific code for ECHO request, see RFC ????.
105 \param payload A payload MAY be sent in the ICMP message.
106 * Content longer than MAX_PAYLOAD will be truncated.
107 \param len Length of the payload in bytes if any is to be sent or 0.
108 */
109 virtual void SendEcho(Ip::Address &to, int opcode, const char *payload=NULL, int len=0) =0;
110
111 /// Handle ICMP responses.
112 virtual void Recv(void) =0;
113
114 protected:
115 /* shared internal methods */
116
117 /// Calculate a packet checksum
118 int CheckSum(unsigned short *ptr, int size);
119
120 /**
121 * Translate TTL to a hop distance
122 *
123 \param ttl negative : n > 33
124 \param ttl n(0...32) : 32 >= n >= 1
125 \param ttl n(33...62) : 32 >= n >= 1
126 \param ttl n(63...64) : 2 >= n >= 1
127 \param ttl n(65...128) : 64 >= n >= 1
128 \param ttl n(129...192) : 64 >= n >= 1
129 \param ttl n(193...) : n < 255
130 *
131 \bug BUG? ttl<0 can produce high hop values
132 \bug BUG? ttl>255 can produce zero or negative hop values
133 */
134 int ipHops(int ttl);
135
136 /// Log the packet.
137 void Log(const Ip::Address &addr, const uint8_t type, const char* pkt_str, const int rtt, const int hops);
138
139 /* no use wasting memory */
140 int icmp_sock;
141 int icmp_ident;
142 #endif /* USE_ICMP */
143 };
144
145 #endif