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