]>
Commit | Line | Data |
---|---|---|
cc192b50 | 1 | /* |
cc192b50 | 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 "config.h" | |
96d89ea0 | 36 | #include "ip/Address.h" |
cc192b50 | 37 | |
38 | #define PINGER_PAYLOAD_SZ 8192 | |
39 | ||
40 | #define MAX_PAYLOAD 256 // WAS: SQUIDHOSTNAMELEN | |
41 | #define MAX_PKT4_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmphdr) + 1) | |
42 | #if USE_IPV6 | |
43 | #define MAX_PKT6_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmp6_hdr) + 1) | |
44 | #endif | |
45 | ||
46 | #if USE_ICMP | |
47 | ||
48 | /* This is a line-data format struct. DO NOT alter. */ | |
26ac0430 | 49 | struct pingerEchoData { |
b7ac5457 | 50 | Ip::Address to; |
cc192b50 | 51 | unsigned char opcode; |
52 | int psize; | |
53 | char payload[PINGER_PAYLOAD_SZ]; | |
54 | }; | |
55 | ||
56 | /* This is a line-data format struct. DO NOT alter. */ | |
26ac0430 | 57 | struct pingerReplyData { |
b7ac5457 | 58 | Ip::Address from; |
cc192b50 | 59 | unsigned char opcode; |
60 | int rtt; | |
61 | int hops; | |
62 | int psize; | |
63 | char payload[PINGER_PAYLOAD_SZ]; | |
64 | }; | |
65 | ||
26ac0430 | 66 | struct icmpEchoData { |
cc192b50 | 67 | struct timeval tv; |
68 | unsigned char opcode; | |
69 | char payload[MAX_PAYLOAD]; | |
70 | }; | |
71 | ||
72 | SQUIDCEXTERN int icmp_pkts_sent; | |
73 | ||
74 | #endif /* USE_ICMP */ | |
75 | ||
76 | ||
77 | /** | |
78 | * Implements the squid interface to access ICMP operations | |
79 | * | |
80 | \par | |
81 | * Child implementations define specific parts of these operations | |
82 | * using these methods as a naming and parameter template. | |
83 | * | |
b826ffb5 AJ |
84 | * IcmpSquid - implements the squid side of squid-pinger interface |
85 | * IcmpPinger - implements the pinger side of the squid-pinger interface | |
86 | * Icmpv4 - implements pinger helper for Icmpv4 | |
87 | * Icmpv6 - implements pinger helper for Icmpv6 | |
cc192b50 | 88 | */ |
b826ffb5 | 89 | class Icmp |
cc192b50 | 90 | { |
91 | public: | |
b826ffb5 AJ |
92 | Icmp(); |
93 | virtual ~Icmp() {}; | |
cc192b50 | 94 | |
95 | /// Start pinger helper and initiate control channel | |
96 | virtual int Open() =0; | |
97 | ||
98 | /// Shutdown pinger helper and control channel | |
99 | virtual void Close(); | |
100 | ||
101 | #if USE_ICMP | |
102 | ||
103 | /** | |
104 | * Construct and Send an ECHO request | |
105 | * | |
106 | \param to Destination address being 'pinged' | |
107 | \param opcode Specific code for ECHO request, see RFC ????. | |
108 | \param payload A payload MAY be sent in the ICMP message. | |
109 | * Content longer than MAX_PAYLOAD will be truncated. | |
110 | \param len Length of the payload in bytes if any is to be sent or 0. | |
111 | */ | |
b7ac5457 | 112 | virtual void SendEcho(Ip::Address &to, int opcode, const char *payload=NULL, int len=0) =0; |
cc192b50 | 113 | |
114 | /// Handle ICMP responses. | |
115 | virtual void Recv(void) =0; | |
116 | ||
117 | protected: | |
118 | /* shared internal methods */ | |
119 | ||
120 | /// Calculate a packet checksum | |
121 | int CheckSum(unsigned short *ptr, int size); | |
122 | ||
123 | /** | |
124 | * Translate TTL to a hop distance | |
26ac0430 | 125 | * |
cc192b50 | 126 | \param ttl negative : n > 33 |
127 | \param ttl n(0...32) : 32 >= n >= 1 | |
128 | \param ttl n(33...62) : 32 >= n >= 1 | |
129 | \param ttl n(63...64) : 2 >= n >= 1 | |
130 | \param ttl n(65...128) : 64 >= n >= 1 | |
131 | \param ttl n(129...192) : 64 >= n >= 1 | |
132 | \param ttl n(193...) : n < 255 | |
133 | * | |
134 | \bug BUG? ttl<0 can produce high hop values | |
135 | \bug BUG? ttl>255 can produce zero or negative hop values | |
136 | */ | |
137 | int ipHops(int ttl); | |
138 | ||
139 | /// Log the packet. | |
b7ac5457 | 140 | void Log(const Ip::Address &addr, const u_int8_t type, const char* pkt_str, const int rtt, const int hops); |
cc192b50 | 141 | |
142 | /* no use wasting memory */ | |
143 | int icmp_sock; | |
144 | int icmp_ident; | |
145 | #endif /* USE_ICMP */ | |
146 | }; | |
147 | ||
148 | #endif |