1*ce7279d8Sjsg /* $OpenBSD: traceroute.h,v 1.8 2024/05/21 05:00:48 jsg Exp $ */ 2baf808a4Sbenno /* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */ 3baf808a4Sbenno 4baf808a4Sbenno /* 5baf808a4Sbenno * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6baf808a4Sbenno * All rights reserved. 7baf808a4Sbenno * 8baf808a4Sbenno * Redistribution and use in source and binary forms, with or without 9baf808a4Sbenno * modification, are permitted provided that the following conditions 10baf808a4Sbenno * are met: 11baf808a4Sbenno * 1. Redistributions of source code must retain the above copyright 12baf808a4Sbenno * notice, this list of conditions and the following disclaimer. 13baf808a4Sbenno * 2. Redistributions in binary form must reproduce the above copyright 14baf808a4Sbenno * notice, this list of conditions and the following disclaimer in the 15baf808a4Sbenno * documentation and/or other materials provided with the distribution. 16baf808a4Sbenno * 3. Neither the name of the project nor the names of its contributors 17baf808a4Sbenno * may be used to endorse or promote products derived from this software 18baf808a4Sbenno * without specific prior written permission. 19baf808a4Sbenno * 20baf808a4Sbenno * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21baf808a4Sbenno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22baf808a4Sbenno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23baf808a4Sbenno * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24baf808a4Sbenno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25baf808a4Sbenno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26baf808a4Sbenno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27baf808a4Sbenno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28baf808a4Sbenno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29baf808a4Sbenno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30baf808a4Sbenno * SUCH DAMAGE. 31baf808a4Sbenno */ 32baf808a4Sbenno 33baf808a4Sbenno /*- 34baf808a4Sbenno * Copyright (c) 1990, 1993 35baf808a4Sbenno * The Regents of the University of California. All rights reserved. 36baf808a4Sbenno * 37baf808a4Sbenno * This code is derived from software contributed to Berkeley by 38baf808a4Sbenno * Van Jacobson. 39baf808a4Sbenno * 40baf808a4Sbenno * Redistribution and use in source and binary forms, with or without 41baf808a4Sbenno * modification, are permitted provided that the following conditions 42baf808a4Sbenno * are met: 43baf808a4Sbenno * 1. Redistributions of source code must retain the above copyright 44baf808a4Sbenno * notice, this list of conditions and the following disclaimer. 45baf808a4Sbenno * 2. Redistributions in binary form must reproduce the above copyright 46baf808a4Sbenno * notice, this list of conditions and the following disclaimer in the 47baf808a4Sbenno * documentation and/or other materials provided with the distribution. 48baf808a4Sbenno * 3. Neither the name of the University nor the names of its contributors 49baf808a4Sbenno * may be used to endorse or promote products derived from this software 50baf808a4Sbenno * without specific prior written permission. 51baf808a4Sbenno * 52baf808a4Sbenno * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 53baf808a4Sbenno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54baf808a4Sbenno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55baf808a4Sbenno * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56baf808a4Sbenno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57baf808a4Sbenno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58baf808a4Sbenno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59baf808a4Sbenno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60baf808a4Sbenno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61baf808a4Sbenno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62baf808a4Sbenno * SUCH DAMAGE. 63baf808a4Sbenno */ 64baf808a4Sbenno 650e1de0b3Sflorian #include <sys/types.h> 66baf808a4Sbenno 67baf808a4Sbenno #include <netinet/ip_var.h> 68baf808a4Sbenno #include <netmpls/mpls.h> 69baf808a4Sbenno 7021b3e878Sflorian #define ICMP_CODE 0; 7121b3e878Sflorian 72baf808a4Sbenno #define DUMMY_PORT 10010 73baf808a4Sbenno 74baf808a4Sbenno #define MAX_LSRR ((MAX_IPOPTLEN - 4) / 4) 75baf808a4Sbenno 76baf808a4Sbenno #define MPLS_LABEL(m) ((m & MPLS_LABEL_MASK) >> MPLS_LABEL_OFFSET) 77baf808a4Sbenno #define MPLS_EXP(m) ((m & MPLS_EXP_MASK) >> MPLS_EXP_OFFSET) 78baf808a4Sbenno 79baf808a4Sbenno /* 80baf808a4Sbenno * Format of the data in a (udp) probe packet. 81baf808a4Sbenno */ 82baf808a4Sbenno struct packetdata { 83baf808a4Sbenno u_char seq; /* sequence number of this packet */ 84baf808a4Sbenno u_int8_t ttl; /* ttl packet left with */ 85baf808a4Sbenno u_char pad[2]; 86baf808a4Sbenno u_int32_t sec; /* time packet left */ 87baf808a4Sbenno u_int32_t usec; 88baf808a4Sbenno } __packed; 89baf808a4Sbenno 908f55caaaSbenno struct tr_conf { 9195bc1d9bSbenno int first_ttl; /* Set the first TTL or hop limit */ 9295bc1d9bSbenno u_char proto; /* IP payload protocol to use */ 9395bc1d9bSbenno u_int8_t max_ttl; /* Set the maximum TTL / hop limit */ 9495bc1d9bSbenno int nprobes; 9595bc1d9bSbenno u_int16_t port; /* start udp dest port */ 9695bc1d9bSbenno int waittime; /* time to wait for a response */ 9795bc1d9bSbenno int Aflag; /* lookup ASN */ 988f55caaaSbenno int dflag; /* set SO_DEBUG */ 998f55caaaSbenno int dump; 10095bc1d9bSbenno int lsrr; /* Loose Source Record Route */ 10195bc1d9bSbenno struct in_addr gateway[MAX_LSRR + 1]; 10295bc1d9bSbenno int lsrrlen; 1038f55caaaSbenno int protoset; 1048f55caaaSbenno int ttl_flag; /* display ttl on returned packet */ 1058f55caaaSbenno int nflag; /* print addresses numerically */ 1068f55caaaSbenno char *source; 1078f55caaaSbenno int sump; 1088f55caaaSbenno int tos; 1098f55caaaSbenno int tflag; /* tos value was set */ 11021b3e878Sflorian int xflag; /* show ICMP extension header */ 11195bc1d9bSbenno int verbose; 1128f55caaaSbenno u_int rtableid; /* Set the routing table */ 11395bc1d9bSbenno u_short ident; 11421b3e878Sflorian int expected_responses; 1158f55caaaSbenno }; 1168f55caaaSbenno 11721b3e878Sflorian struct tr_result { 11821b3e878Sflorian int seq; 11921b3e878Sflorian int row; 12021b3e878Sflorian int dup; 12121b3e878Sflorian int timeout; 12221b3e878Sflorian uint8_t ttl; 12321b3e878Sflorian uint8_t resp_ttl; 12421b3e878Sflorian char hbuf[NI_MAXHOST]; 12521b3e878Sflorian char inetname[NI_MAXHOST]; 12621b3e878Sflorian char *asn; 12721b3e878Sflorian char *exthdr; 12821b3e878Sflorian char to[NI_MAXHOST]; 12921b3e878Sflorian int cc; 13021b3e878Sflorian struct timeval t1; 13121b3e878Sflorian struct timeval t2; 13221b3e878Sflorian char icmp_code[sizeof("!<255>")]; 13321b3e878Sflorian char tos[sizeof(" (TOS=255!)")]; 13421b3e878Sflorian int got_there; 13521b3e878Sflorian int unreachable; 13621b3e878Sflorian int inetname_done; 13721b3e878Sflorian int asn_done; 13821b3e878Sflorian }; 13921b3e878Sflorian 14021b3e878Sflorian extern int *waiting_ttls; 141baf808a4Sbenno extern int32_t sec_perturb; 142baf808a4Sbenno extern int32_t usec_perturb; 143baf808a4Sbenno 144baf808a4Sbenno extern u_char packet[512]; 145baf808a4Sbenno extern u_char *outpacket; /* last inbound (icmp) packet */ 146baf808a4Sbenno 14721b3e878Sflorian void send_probe(struct tr_conf *, int, u_int8_t, struct sockaddr *); 14821b3e878Sflorian int packet_ok(struct tr_conf *, int, struct msghdr *, int, int *); 14921b3e878Sflorian void icmp_code(int, int, int *, int *, struct tr_result *); 15021b3e878Sflorian void check_tos(struct ip*, int *, struct tr_result *); 151baf808a4Sbenno int map_tos(char *, int *); 15221b3e878Sflorian void print(struct tr_conf *, struct sockaddr *, int, const char *, 15321b3e878Sflorian struct tr_result *); 15421b3e878Sflorian void print_exthdr(u_char *, int, struct tr_result *); 155baf808a4Sbenno void gettime(struct timeval *); 156baf808a4Sbenno 15721b3e878Sflorian void catchup_result_rows(struct tr_result *, struct tr_conf *); 15821b3e878Sflorian 159baf808a4Sbenno extern int sndsock; /* send (udp) socket file descriptor */ 160baf808a4Sbenno 161baf808a4Sbenno extern int rcvhlim; 162baf808a4Sbenno extern struct in6_pktinfo *rcvpktinfo; 163baf808a4Sbenno 164baf808a4Sbenno extern int datalen; /* How much data */ 165baf808a4Sbenno 166baf808a4Sbenno extern char *hostname; 167baf808a4Sbenno 168baf808a4Sbenno extern u_int16_t srcport; 169baf808a4Sbenno 170baf808a4Sbenno extern char *__progname; 171