| 1 |
/* |
| 2 |
*Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. |
| 3 |
* |
| 4 |
*All right reserved |
| 5 |
* |
| 6 |
*File Name:traceRouteCtlTable.h |
| 7 |
*File Description:The head file of traceRouteCtlTable.c |
| 8 |
* |
| 9 |
*Current Version:1.0 |
| 10 |
*Author:ChenJing |
| 11 |
*Date:2004.8.20 |
| 12 |
*/ |
| 13 |
|
| 14 |
|
| 15 |
/* |
| 16 |
* Note: this file originally auto-generated by mib2c using |
| 17 |
* : mib2c.create-dataset.conf,v 5.3 2002/12/05 00:29:45 hardaker Exp $ |
| 18 |
*/ |
| 19 |
#ifndef TRACEROUTECTLTABLE_H |
| 20 |
#define TRACEROUTECTLTABLE_H |
| 21 |
|
| 22 |
|
| 23 |
config_require(header_complex); |
| 24 |
|
| 25 |
struct traceRouteCtlTable_data { |
| 26 |
char *traceRouteCtlOwnerIndex; /* string */ |
| 27 |
size_t traceRouteCtlOwnerIndexLen; |
| 28 |
|
| 29 |
char *traceRouteCtlTestName; /* string */ |
| 30 |
size_t traceRouteCtlTestNameLen; |
| 31 |
|
| 32 |
|
| 33 |
long traceRouteCtlTargetAddressType; |
| 34 |
|
| 35 |
char *traceRouteCtlTargetAddress; |
| 36 |
size_t traceRouteCtlTargetAddressLen; |
| 37 |
|
| 38 |
long traceRouteCtlByPassRouteTable; |
| 39 |
|
| 40 |
unsigned long traceRouteCtlDataSize; |
| 41 |
|
| 42 |
unsigned long traceRouteCtlTimeOut; |
| 43 |
|
| 44 |
unsigned long traceRouteCtlProbesPerHop; |
| 45 |
|
| 46 |
unsigned long traceRouteCtlPort; |
| 47 |
|
| 48 |
unsigned long traceRouteCtlMaxTtl; |
| 49 |
|
| 50 |
unsigned long traceRouteCtlDSField; |
| 51 |
|
| 52 |
long traceRouteCtlSourceAddressType; |
| 53 |
|
| 54 |
char *traceRouteCtlSourceAddress; |
| 55 |
size_t traceRouteCtlSourceAddressLen; |
| 56 |
|
| 57 |
long traceRouteCtlIfIndex; |
| 58 |
|
| 59 |
char *traceRouteCtlMiscOptions; |
| 60 |
size_t traceRouteCtlMiscOptionsLen; |
| 61 |
|
| 62 |
unsigned long traceRouteCtlMaxFailures; |
| 63 |
|
| 64 |
long traceRouteCtlDontFragment; |
| 65 |
|
| 66 |
unsigned long traceRouteCtlInitialTtl; |
| 67 |
|
| 68 |
unsigned long traceRouteCtlFrequency; |
| 69 |
|
| 70 |
long traceRouteCtlStorageType; |
| 71 |
|
| 72 |
long traceRouteCtlAdminStatus; |
| 73 |
|
| 74 |
char *traceRouteCtlDescr; |
| 75 |
size_t traceRouteCtlDescrLen; |
| 76 |
|
| 77 |
unsigned long traceRouteCtlMaxRows; |
| 78 |
|
| 79 |
char *traceRouteCtlTrapGeneration; |
| 80 |
size_t traceRouteCtlTrapGenerationLen; |
| 81 |
|
| 82 |
long traceRouteCtlCreateHopsEntries; |
| 83 |
|
| 84 |
oid *traceRouteCtlType; |
| 85 |
size_t traceRouteCtlTypeLen; |
| 86 |
|
| 87 |
long traceRouteCtlRowStatus; |
| 88 |
|
| 89 |
|
| 90 |
int storageType; |
| 91 |
u_long timer_id; |
| 92 |
unsigned long traceRouteProbeHistoryMaxIndex; |
| 93 |
|
| 94 |
struct traceRouteResultsTable_data *traceRouteResults; |
| 95 |
struct traceRouteProbeHistoryTable_data *traceRouteProbeHis; |
| 96 |
struct traceRouteHopsTable_data *traceRouteHops; |
| 97 |
|
| 98 |
}; |
| 99 |
|
| 100 |
struct traceRouteResultsTable_data { |
| 101 |
/* struct pingResultsTable_data *next; */ |
| 102 |
char *traceRouteCtlOwnerIndex; /* string */ |
| 103 |
size_t traceRouteCtlOwnerIndexLen; |
| 104 |
|
| 105 |
char *traceRouteCtlTestName; /* string */ |
| 106 |
size_t traceRouteCtlTestNameLen; |
| 107 |
|
| 108 |
long traceRouteResultsOperStatus; |
| 109 |
unsigned long traceRouteResultsCurHopCount; |
| 110 |
unsigned long traceRouteResultsCurProbeCount; |
| 111 |
long traceRouteResultsIpTgtAddrType; |
| 112 |
char *traceRouteResultsIpTgtAddr; |
| 113 |
size_t traceRouteResultsIpTgtAddrLen; |
| 114 |
unsigned long traceRouteResultsTestAttempts; |
| 115 |
unsigned long traceRouteResultsTestSuccesses; |
| 116 |
u_char *traceRouteResultsLastGoodPath; |
| 117 |
size_t traceRouteResultsLastGoodPathLen; |
| 118 |
time_t traceRouteResultsLastGoodPath_time; |
| 119 |
|
| 120 |
int storageType; |
| 121 |
|
| 122 |
}; |
| 123 |
|
| 124 |
struct traceRouteProbeHistoryTable_data { |
| 125 |
struct traceRouteProbeHistoryTable_data *next; |
| 126 |
/* index */ |
| 127 |
char *traceRouteCtlOwnerIndex; /* string */ |
| 128 |
size_t traceRouteCtlOwnerIndexLen; |
| 129 |
|
| 130 |
char *traceRouteCtlTestName; /* string */ |
| 131 |
size_t traceRouteCtlTestNameLen; |
| 132 |
unsigned long traceRouteProbeHistoryIndex; |
| 133 |
unsigned long traceRouteProbeHistoryHopIndex; |
| 134 |
unsigned long traceRouteProbeHistoryProbeIndex; |
| 135 |
/* index */ |
| 136 |
long traceRouteProbeHistoryHAddrType; |
| 137 |
char *traceRouteProbeHistoryHAddr; |
| 138 |
size_t traceRouteProbeHistoryHAddrLen; |
| 139 |
unsigned long traceRouteProbeHistoryResponse; |
| 140 |
long traceRouteProbeHistoryStatus; |
| 141 |
long traceRouteProbeHistoryLastRC; |
| 142 |
u_char *traceRouteProbeHistoryTime; |
| 143 |
size_t traceRouteProbeHistoryTimeLen; |
| 144 |
time_t traceRouteProbeHistoryTime_time; |
| 145 |
|
| 146 |
int storageType; |
| 147 |
|
| 148 |
}; |
| 149 |
|
| 150 |
struct traceRouteHopsTable_data { |
| 151 |
struct traceRouteHopsTable_data *next; |
| 152 |
|
| 153 |
char *traceRouteCtlOwnerIndex; /* string */ |
| 154 |
size_t traceRouteCtlOwnerIndexLen; |
| 155 |
|
| 156 |
char *traceRouteCtlTestName; /* string */ |
| 157 |
size_t traceRouteCtlTestNameLen; |
| 158 |
|
| 159 |
unsigned long traceRouteHopsHopIndex; |
| 160 |
long traceRouteHopsIpTgtAddressType; |
| 161 |
char *traceRouteHopsIpTgtAddress; |
| 162 |
size_t traceRouteHopsIpTgtAddressLen; |
| 163 |
|
| 164 |
unsigned long traceRouteHopsMinRtt; |
| 165 |
unsigned long traceRouteHopsMaxRtt; |
| 166 |
unsigned long traceRouteHopsAverageRtt; |
| 167 |
unsigned long traceRouteHopsRttSumOfSquares; |
| 168 |
unsigned long traceRouteHopsSentProbes; |
| 169 |
unsigned long traceRouteHopsProbeResponses; |
| 170 |
u_char *traceRouteHopsLastGoodProbe; |
| 171 |
size_t traceRouteHopsLastGoodProbeLen; |
| 172 |
time_t traceRouteHopsLastGoodProbe_time; |
| 173 |
|
| 174 |
int storageType; |
| 175 |
}; |
| 176 |
/* |
| 177 |
* function declarations |
| 178 |
*/ |
| 179 |
void init_traceRouteCtlTable(void); |
| 180 |
FindVarMethod var_traceRouteCtlTable; |
| 181 |
void parse_traceRouteCtlTable(const char *, char *); |
| 182 |
SNMPCallback store_traceRouteCtlTable; |
| 183 |
void init_trResultsTable(struct traceRouteCtlTable_data *); |
| 184 |
|
| 185 |
WriteMethod write_traceRouteCtlTargetAddressType; |
| 186 |
WriteMethod write_traceRouteCtlTargetAddress; |
| 187 |
WriteMethod write_traceRouteCtlByPassRouteTable; |
| 188 |
WriteMethod write_traceRouteCtlDataSize; |
| 189 |
WriteMethod write_traceRouteCtlTimeOut; |
| 190 |
WriteMethod write_traceRouteCtlProbesPerHop; |
| 191 |
WriteMethod write_traceRouteCtlPort; |
| 192 |
WriteMethod write_traceRouteCtlMaxTtl; |
| 193 |
WriteMethod write_traceRouteCtlDSField; |
| 194 |
WriteMethod write_traceRouteCtlSourceAddressType; |
| 195 |
WriteMethod write_traceRouteCtlSourceAddress; |
| 196 |
WriteMethod write_traceRouteCtlIfIndex; |
| 197 |
WriteMethod write_traceRouteCtlMiscOptions; |
| 198 |
WriteMethod write_traceRouteCtlMaxFailures; |
| 199 |
WriteMethod write_traceRouteCtlDontFragment; |
| 200 |
WriteMethod write_traceRouteCtlInitialTtl; |
| 201 |
WriteMethod write_traceRouteCtlFrequency; |
| 202 |
WriteMethod write_traceRouteCtlStorageType; |
| 203 |
WriteMethod write_traceRouteCtlAdminStatus; |
| 204 |
WriteMethod write_traceRouteCtlDescr; |
| 205 |
WriteMethod write_traceRouteCtlMaxRows; |
| 206 |
WriteMethod write_traceRouteCtlTrapGeneration; |
| 207 |
WriteMethod write_traceRouteCtlCreateHopsEntries; |
| 208 |
WriteMethod write_traceRouteCtlType; |
| 209 |
|
| 210 |
WriteMethod write_traceRouteCtlRowStatus; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
#define TRACEROUTETRAPGENERATION_PATHCHANGE 0x80 |
| 215 |
#define TRACEROUTETRAPGENERATION_TESTFAILED 0x40 |
| 216 |
#define TRACEROUTETRAPGENERATION_TESTCOMPLETED 0x20 |
| 217 |
#define TRACEROUTETRAPGENERATION_NULL 0x00 |
| 218 |
|
| 219 |
|
| 220 |
/* |
| 221 |
* column number definitions for table traceRouteCtlTable |
| 222 |
*/ |
| 223 |
#define COLUMN_TRACEROUTECTLOWNERINDEX 1 |
| 224 |
#define COLUMN_TRACEROUTECTLTESTNAME 2 |
| 225 |
#define COLUMN_TRACEROUTECTLTARGETADDRESSTYPE 3 |
| 226 |
#define COLUMN_TRACEROUTECTLTARGETADDRESS 4 |
| 227 |
#define COLUMN_TRACEROUTECTLBYPASSROUTETABLE 5 |
| 228 |
#define COLUMN_TRACEROUTECTLDATASIZE 6 |
| 229 |
#define COLUMN_TRACEROUTECTLTIMEOUT 7 |
| 230 |
#define COLUMN_TRACEROUTECTLPROBESPERHOP 8 |
| 231 |
#define COLUMN_TRACEROUTECTLPORT 9 |
| 232 |
#define COLUMN_TRACEROUTECTLMAXTTL 10 |
| 233 |
#define COLUMN_TRACEROUTECTLDSFIELD 11 |
| 234 |
#define COLUMN_TRACEROUTECTLSOURCEADDRESSTYPE 12 |
| 235 |
#define COLUMN_TRACEROUTECTLSOURCEADDRESS 13 |
| 236 |
#define COLUMN_TRACEROUTECTLIFINDEX 14 |
| 237 |
#define COLUMN_TRACEROUTECTLMISCOPTIONS 15 |
| 238 |
#define COLUMN_TRACEROUTECTLMAXFAILURES 16 |
| 239 |
#define COLUMN_TRACEROUTECTLDONTFRAGMENT 17 |
| 240 |
#define COLUMN_TRACEROUTECTLINITIALTTL 18 |
| 241 |
#define COLUMN_TRACEROUTECTLFREQUENCY 19 |
| 242 |
#define COLUMN_TRACEROUTECTLSTORAGETYPE 20 |
| 243 |
#define COLUMN_TRACEROUTECTLADMINSTATUS 21 |
| 244 |
#define COLUMN_TRACEROUTECTLDESCR 22 |
| 245 |
#define COLUMN_TRACEROUTECTLMAXROWS 23 |
| 246 |
#define COLUMN_TRACEROUTECTLTRAPGENERATION 24 |
| 247 |
#define COLUMN_TRACEROUTECTLCREATEHOPSENTRIES 25 |
| 248 |
#define COLUMN_TRACEROUTECTLTYPE 26 |
| 249 |
#define COLUMN_TRACEROUTECTLROWSTATUS 27 |
| 250 |
#endif /* TRACEROUTECTLTABLE_H */ |
| 251 |
|
| 252 |
/* |
| 253 |
* Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000 |
| 254 |
* The Regents of the University of California. All rights reserved. |
| 255 |
* |
| 256 |
* Redistribution and use in source and binary forms, with or without |
| 257 |
* modification, are permitted provided that: (1) source code distributions |
| 258 |
* retain the above copyright notice and this paragraph in its entirety, (2) |
| 259 |
* distributions including binary code include the above copyright notice and |
| 260 |
* this paragraph in its entirety in the documentation or other materials |
| 261 |
* provided with the distribution, and (3) all advertising materials mentioning |
| 262 |
* features or use of this software display the following acknowledgement: |
| 263 |
* ``This product includes software developed by the University of California, |
| 264 |
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
| 265 |
* the University nor the names of its contributors may be used to endorse |
| 266 |
* or promote products derived from this software without specific prior |
| 267 |
* written permission. |
| 268 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 269 |
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 270 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 271 |
*/ |
| 272 |
|
| 273 |
#ifndef lint |
| 274 |
static const char copyright[] = |
| 275 |
"@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000\n\ |
| 276 |
The Regents of the University of California. All rights reserved.\n"; |
| 277 |
#endif |
| 278 |
|
| 279 |
/* |
| 280 |
* traceroute host - trace the route ip packets follow going to "host". |
| 281 |
* |
| 282 |
* Attempt to trace the route an ip packet would follow to some |
| 283 |
* internet host. We find out intermediate hops by launching probe |
| 284 |
* packets with a small ttl (time to live) then listening for an |
| 285 |
* icmp "time exceeded" reply from a gateway. We start our probes |
| 286 |
* with a ttl of one and increase by one until we get an icmp "port |
| 287 |
* unreachable" (which means we got to "host") or hit a max (which |
| 288 |
* defaults to 30 hops & can be changed with the -m flag). Three |
| 289 |
* probes (change with -q flag) are sent at each ttl setting and a |
| 290 |
* line is printed showing the ttl, address of the gateway and |
| 291 |
* round trip time of each probe. If the probe answers come from |
| 292 |
* different gateways, the address of each responding system will |
| 293 |
* be printed. If there is no response within a 5 sec. timeout |
| 294 |
* interval (changed with the -w flag), a "*" is printed for that |
| 295 |
* probe. |
| 296 |
* |
| 297 |
* Probe packets are UDP format. We don't want the destination |
| 298 |
* host to process them so the destination port is set to an |
| 299 |
* unlikely value (if some clod on the destination is using that |
| 300 |
* value, it can be changed with the -p flag). |
| 301 |
* |
| 302 |
* A sample use might be: |
| 303 |
* |
| 304 |
* [yak 71]% traceroute nis.nsf.net. |
| 305 |
* traceroute to nis.nsf.net (35.1.1.48), 30 hops max, 56 byte packet |
| 306 |
* 1 helios.ee.lbl.gov (128.3.112.1) 19 ms 19 ms 0 ms |
| 307 |
* 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms |
| 308 |
* 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms |
| 309 |
* 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 39 ms 40 ms 39 ms |
| 310 |
* 5 ccn-nerif22.Berkeley.EDU (128.32.168.22) 39 ms 39 ms 39 ms |
| 311 |
* 6 128.32.197.4 (128.32.197.4) 40 ms 59 ms 59 ms |
| 312 |
* 7 131.119.2.5 (131.119.2.5) 59 ms 59 ms 59 ms |
| 313 |
* 8 129.140.70.13 (129.140.70.13) 99 ms 99 ms 80 ms |
| 314 |
* 9 129.140.71.6 (129.140.71.6) 139 ms 239 ms 319 ms |
| 315 |
* 10 129.140.81.7 (129.140.81.7) 220 ms 199 ms 199 ms |
| 316 |
* 11 nic.merit.edu (35.1.1.48) 239 ms 239 ms 239 ms |
| 317 |
* |
| 318 |
* Note that lines 2 & 3 are the same. This is due to a buggy |
| 319 |
* kernel on the 2nd hop system -- lbl-csam.arpa -- that forwards |
| 320 |
* packets with a zero ttl. |
| 321 |
* |
| 322 |
* A more interesting example is: |
| 323 |
* |
| 324 |
* [yak 72]% traceroute allspice.lcs.mit.edu. |
| 325 |
* traceroute to allspice.lcs.mit.edu (18.26.0.115), 30 hops max |
| 326 |
* 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms |
| 327 |
* 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 19 ms 19 ms |
| 328 |
* 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 19 ms |
| 329 |
* 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 19 ms 39 ms 39 ms |
| 330 |
* 5 ccn-nerif22.Berkeley.EDU (128.32.168.22) 20 ms 39 ms 39 ms |
| 331 |
* 6 128.32.197.4 (128.32.197.4) 59 ms 119 ms 39 ms |
| 332 |
* 7 131.119.2.5 (131.119.2.5) 59 ms 59 ms 39 ms |
| 333 |
* 8 129.140.70.13 (129.140.70.13) 80 ms 79 ms 99 ms |
| 334 |
* 9 129.140.71.6 (129.140.71.6) 139 ms 139 ms 159 ms |
| 335 |
* 10 129.140.81.7 (129.140.81.7) 199 ms 180 ms 300 ms |
| 336 |
* 11 129.140.72.17 (129.140.72.17) 300 ms 239 ms 239 ms |
| 337 |
* 12 * * * |
| 338 |
* 13 128.121.54.72 (128.121.54.72) 259 ms 499 ms 279 ms |
| 339 |
* 14 * * * |
| 340 |
* 15 * * * |
| 341 |
* 16 * * * |
| 342 |
* 17 * * * |
| 343 |
* 18 ALLSPICE.LCS.MIT.EDU (18.26.0.115) 339 ms 279 ms 279 ms |
| 344 |
* |
| 345 |
* (I start to see why I'm having so much trouble with mail to |
| 346 |
* MIT.) Note that the gateways 12, 14, 15, 16 & 17 hops away |
| 347 |
* either don't send ICMP "time exceeded" messages or send them |
| 348 |
* with a ttl too small to reach us. 14 - 17 are running the |
| 349 |
* MIT C Gateway code that doesn't send "time exceeded"s. God |
| 350 |
* only knows what's going on with 12. |
| 351 |
* |
| 352 |
* The silent gateway 12 in the above may be the result of a bug in |
| 353 |
* the 4.[23]BSD network code (and its derivatives): 4.x (x <= 3) |
| 354 |
* sends an unreachable message using whatever ttl remains in the |
| 355 |
* original datagram. Since, for gateways, the remaining ttl is |
| 356 |
* zero, the icmp "time exceeded" is guaranteed to not make it back |
| 357 |
* to us. The behavior of this bug is slightly more interesting |
| 358 |
* when it appears on the destination system: |
| 359 |
* |
| 360 |
* 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms |
| 361 |
* 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 39 ms |
| 362 |
* 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 39 ms 19 ms |
| 363 |
* 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 39 ms 40 ms 19 ms |
| 364 |
* 5 ccn-nerif35.Berkeley.EDU (128.32.168.35) 39 ms 39 ms 39 ms |
| 365 |
* 6 csgw.Berkeley.EDU (128.32.133.254) 39 ms 59 ms 39 ms |
| 366 |
* 7 * * * |
| 367 |
* 8 * * * |
| 368 |
* 9 * * * |
| 369 |
* 10 * * * |
| 370 |
* 11 * * * |
| 371 |
* 12 * * * |
| 372 |
* 13 rip.Berkeley.EDU (128.32.131.22) 59 ms ! 39 ms ! 39 ms ! |
| 373 |
* |
| 374 |
* Notice that there are 12 "gateways" (13 is the final |
| 375 |
* destination) and exactly the last half of them are "missing". |
| 376 |
* What's really happening is that rip (a Sun-3 running Sun OS3.5) |
| 377 |
* is using the ttl from our arriving datagram as the ttl in its |
| 378 |
* icmp reply. So, the reply will time out on the return path |
| 379 |
* (with no notice sent to anyone since icmp's aren't sent for |
| 380 |
* icmp's) until we probe with a ttl that's at least twice the path |
| 381 |
* length. I.e., rip is really only 7 hops away. A reply that |
| 382 |
* returns with a ttl of 1 is a clue this problem exists. |
| 383 |
* Traceroute prints a "!" after the time if the ttl is <= 1. |
| 384 |
* Since vendors ship a lot of obsolete (DEC's Ultrix, Sun 3.x) or |
| 385 |
* non-standard (HPUX) software, expect to see this problem |
| 386 |
* frequently and/or take care picking the target host of your |
| 387 |
* probes. |
| 388 |
* |
| 389 |
* Other possible annotations after the time are !H, !N, !P (got a host, |
| 390 |
* network or protocol unreachable, respectively), !S or !F (source |
| 391 |
* route failed or fragmentation needed -- neither of these should |
| 392 |
* ever occur and the associated gateway is busted if you see one). If |
| 393 |
* almost all the probes result in some kind of unreachable, traceroute |
| 394 |
* will give up and exit. |
| 395 |
* |
| 396 |
* Notes |
| 397 |
* ----- |
| 398 |
* This program must be run by root or be setuid. (I suggest that |
| 399 |
* you *don't* make it setuid -- casual use could result in a lot |
| 400 |
* of unnecessary traffic on our poor, congested nets.) |
| 401 |
* |
| 402 |
* This program requires a kernel mod that does not appear in any |
| 403 |
* system available from Berkeley: A raw ip socket using proto |
| 404 |
* IPPROTO_RAW must interpret the data sent as an ip datagram (as |
| 405 |
* opposed to data to be wrapped in a ip datagram). See the README |
| 406 |
* file that came with the source to this program for a description |
| 407 |
* of the mods I made to /sys/netinet/raw_ip.c. Your mileage may |
| 408 |
* vary. But, again, ANY 4.x (x < 4) BSD KERNEL WILL HAVE TO BE |
| 409 |
* MODIFIED TO RUN THIS PROGRAM. |
| 410 |
* |
| 411 |
* The udp port usage may appear bizarre (well, ok, it is bizarre). |
| 412 |
* The problem is that an icmp message only contains 8 bytes of |
| 413 |
* data from the original datagram. 8 bytes is the size of a udp |
| 414 |
* header so, if we want to associate replies with the original |
| 415 |
* datagram, the necessary information must be encoded into the |
| 416 |
* udp header (the ip id could be used but there's no way to |
| 417 |
* interlock with the kernel's assignment of ip id's and, anyway, |
| 418 |
* it would have taken a lot more kernel hacking to allow this |
| 419 |
* code to set the ip id). So, to allow two or more users to |
| 420 |
* use traceroute simultaneously, we use this task's pid as the |
| 421 |
* source port (the high bit is set to move the port number out |
| 422 |
* of the "likely" range). To keep track of which probe is being |
| 423 |
* replied to (so times and/or hop counts don't get confused by a |
| 424 |
* reply that was delayed in transit), we increment the destination |
| 425 |
* port number before each probe. |
| 426 |
* |
| 427 |
* Don't use this as a coding example. I was trying to find a |
| 428 |
* routing problem and this code sort-of popped out after 48 hours |
| 429 |
* without sleep. I was amazed it ever compiled, much less ran. |
| 430 |
* |
| 431 |
* I stole the idea for this program from Steve Deering. Since |
| 432 |
* the first release, I've learned that had I attended the right |
| 433 |
* IETF working group meetings, I also could have stolen it from Guy |
| 434 |
* Almes or Matt Mathis. I don't know (or care) who came up with |
| 435 |
* the idea first. I envy the originators' perspicacity and I'm |
| 436 |
* glad they didn't keep the idea a secret. |
| 437 |
* |
| 438 |
* Tim Seaver, Ken Adelman and C. Philip Wood provided bug fixes and/or |
| 439 |
* enhancements to the original distribution. |
| 440 |
* |
| 441 |
* I've hacked up a round-trip-route version of this that works by |
| 442 |
* sending a loose-source-routed udp datagram through the destination |
| 443 |
* back to yourself. Unfortunately, SO many gateways botch source |
| 444 |
* routing, the thing is almost worthless. Maybe one day... |
| 445 |
* |
| 446 |
* -- Van Jacobson ([email protected]) |
| 447 |
* Tue Dec 20 03:50:13 PST 1988 |
| 448 |
*/ |
| 449 |
|
| 450 |
#include <sys/param.h> |
| 451 |
#include <sys/file.h> |
| 452 |
#include <sys/ioctl.h> |
| 453 |
#ifdef HAVE_SYS_SELECT_H |
| 454 |
#include <sys/select.h> |
| 455 |
#endif |
| 456 |
#include <sys/socket.h> |
| 457 |
#include <sys/time.h> |
| 458 |
|
| 459 |
|
| 460 |
#include <netinet/in_systm.h> |
| 461 |
#include <netinet/in.h> |
| 462 |
#include <netinet/ip.h> |
| 463 |
#include <netinet/ip_icmp.h> |
| 464 |
#include <netinet/udp.h> |
| 465 |
|
| 466 |
#include <netinet/ip6.h> |
| 467 |
#include <netinet/icmp6.h> |
| 468 |
|
| 469 |
#include <arpa/inet.h> |
| 470 |
|
| 471 |
#include <ctype.h> |
| 472 |
#include <errno.h> |
| 473 |
#include <fcntl.h> |
| 474 |
#ifdef HAVE_MALLOC_H |
| 475 |
#include <malloc.h> |
| 476 |
#endif |
| 477 |
#include <memory.h> |
| 478 |
#include <netdb.h> |
| 479 |
#include <stdio.h> |
| 480 |
#include <stdlib.h> |
| 481 |
#include <string.h> |
| 482 |
#include <unistd.h> |
| 483 |
|
| 484 |
#ifdef HAVE_OS_PROTO_H |
| 485 |
#include "os-proto.h" |
| 486 |
#endif |
| 487 |
|
| 488 |
#include <net/if.h> |
| 489 |
|
| 490 |
#if __linux__ |
| 491 |
#include <endian.h> |
| 492 |
#endif |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
/* |
| 497 |
* rfc1716 |
| 498 |
*/ |
| 499 |
#ifndef ICMP_UNREACH_FILTER_PROHIB |
| 500 |
#define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohibited filter */ |
| 501 |
#endif |
| 502 |
#ifndef ICMP_UNREACH_HOST_PRECEDENCE |
| 503 |
#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host precedence violation */ |
| 504 |
#endif |
| 505 |
#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF |
| 506 |
#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ |
| 507 |
#endif |
| 508 |
|
| 509 |
#define MAXPACKET 65535 |
| 510 |
|
| 511 |
/* |
| 512 |
* Maximum number of gateways (include room for one noop) |
| 513 |
*/ |
| 514 |
#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t))) |
| 515 |
|
| 516 |
#ifndef MAXHOSTNAMELEN |
| 517 |
#define MAXHOSTNAMELEN 64 |
| 518 |
#endif |
| 519 |
|
| 520 |
#ifndef FD_SET |
| 521 |
#define NFDBITS (8*sizeof(fd_set)) |
| 522 |
#define FD_SETSIZE NFDBITS |
| 523 |
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) |
| 524 |
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) |
| 525 |
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) |
| 526 |
#define FD_ZERO(p) memset((p), '\0', sizeof(*(p))) |
| 527 |
#endif |
| 528 |
|
| 529 |
#define Fprintf (void)fprintf |
| 530 |
#define Printf (void)printf |
| 531 |
|
| 532 |
/* |
| 533 |
* Host name and address list |
| 534 |
*/ |
| 535 |
struct hostinfo { |
| 536 |
char *name; |
| 537 |
int n; |
| 538 |
u_int32_t *addrs; |
| 539 |
}; |
| 540 |
|
| 541 |
/* |
| 542 |
* Data section of the probe packet |
| 543 |
*/ |
| 544 |
struct outdata { |
| 545 |
u_char seq; /* sequence number of this packet */ |
| 546 |
u_char ttl; /* ttl packet left with */ |
| 547 |
struct timeval tv; /* time packet left */ |
| 548 |
}; |
| 549 |
|
| 550 |
#ifndef HAVE_ICMP_NEXTMTU |
| 551 |
/* |
| 552 |
* Path MTU Discovery (RFC1191) |
| 553 |
*/ |
| 554 |
struct my_pmtu { |
| 555 |
u_short ipm_void; |
| 556 |
u_short ipm_nextmtu; |
| 557 |
}; |
| 558 |
#endif |
| 559 |
|
| 560 |
struct ifaddrlist { |
| 561 |
u_int32_t addr; |
| 562 |
char *device; |
| 563 |
}; |
| 564 |
|
| 565 |
|
| 566 |
struct pkt_format { |
| 567 |
u_int32_t ident; |
| 568 |
u_int32_t seq; |
| 569 |
struct timeval tv; |
| 570 |
}; |
| 571 |
|
| 572 |
|
| 573 |
/* |
| 574 |
* Forwards |
| 575 |
*/ |
| 576 |
unsigned long deltaT(struct timeval *, struct timeval *); |
| 577 |
void freehostinfo(struct hostinfo *); |
| 578 |
void getaddr(u_int32_t *, char *); |
| 579 |
struct hostinfo *gethostinfo(char *); |
| 580 |
u_short in_checksum(u_short *, int); |
| 581 |
void run_traceRoute(unsigned int, void *); |
| 582 |
int packet_ok(u_char *, int, struct sockaddr_in *, int, |
| 583 |
u_short, int, u_short); |
| 584 |
char *pr_type(u_char); |
| 585 |
/* void print(u_char *, int, struct sockaddr_in *); */ |
| 586 |
void send_probe(struct sockaddr_in *, int, int, |
| 587 |
struct timeval *, struct ip *, struct udphdr *, |
| 588 |
int, int, char *, u_short, int, u_short, |
| 589 |
struct outdata *); |
| 590 |
int str2val(const char *, const char *, int, int); |
| 591 |
void tvsub(struct timeval *, struct timeval *); |
| 592 |
int wait_for_reply(int, struct sockaddr_in *, |
| 593 |
const struct timeval *, u_char *, int); |
| 594 |
#ifndef HAVE_USLEEP |
| 595 |
int usleep(u_int); |
| 596 |
#endif |
| 597 |
void setsin(struct sockaddr_in *, u_int32_t); |
| 598 |
int ifaddrlist(struct ifaddrlist **, char *); |
| 599 |
struct addrinfo *host_serv_tr(const char *, const char *, int, int); |
| 600 |
char *sock_ntop_host_tr(const struct sockaddr *, socklen_t); |
| 601 |
|
| 602 |
void send_probe_v6(int, int, char *, pid_t, struct timezone *, |
| 603 |
int, int, struct sockaddr_in6 *, char *); |
| 604 |
int wait_for_reply_v6(int, struct sockaddr_in6 *, int, int, |
| 605 |
int, u_char *); |
| 606 |
int packet_ok_v6(u_char *, int, struct sockaddr_in6 *, int, |
| 607 |
struct timeval *, pid_t); |
| 608 |
void print_v6(unsigned char *, int, struct sockaddr_in6 *); |