aboutsummaryrefslogtreecommitdiff
path: root/networking/traceroute.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/traceroute.c')
-rw-r--r--networking/traceroute.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 3b590630c..c4f050abb 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -196,12 +196,15 @@
196 * Tue Dec 20 03:50:13 PST 1988 196 * Tue Dec 20 03:50:13 PST 1988
197 */ 197 */
198 198
199#undef CONFIG_FEATURE_TRACEROUTE_VERBOSE 199#define TRACEROUTE_SO_DEBUG 0
200
201/* TODO: undefs were uncommented - ??! we have config system for that! */
202/* probably ok to remove altogether */
203//#undef CONFIG_FEATURE_TRACEROUTE_VERBOSE
200//#define CONFIG_FEATURE_TRACEROUTE_VERBOSE 204//#define CONFIG_FEATURE_TRACEROUTE_VERBOSE
201#undef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG /* not in documentation man */ 205//#undef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
202#undef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
203//#define CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 206//#define CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
204#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 207//#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP
205//#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP 208//#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP
206 209
207#include "inet_common.h" 210#include "inet_common.h"
@@ -284,17 +287,17 @@ struct IFADDRLIST {
284static const char route[] = "/proc/net/route"; 287static const char route[] = "/proc/net/route";
285 288
286/* last inbound (icmp) packet */ 289/* last inbound (icmp) packet */
287static unsigned char packet[512] ATTRIBUTE_ALIGNED(32); 290static unsigned char packet[512] ATTRIBUTE_ALIGNED(32);
288 291
289static struct ip *outip; /* last output (udp) packet */ 292static struct ip *outip; /* last output (udp) packet */
290static struct udphdr *outudp; /* last output (udp) packet */ 293static struct udphdr *outudp; /* last output (udp) packet */
291static struct outdata *outdata; /* last output (udp) packet */ 294static struct outdata *outdata; /* last output (udp) packet */
292 295
293#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 296#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
294static struct icmp *outicmp; /* last output (icmp) packet */ 297static struct icmp *outicmp; /* last output (icmp) packet */
295#endif 298#endif
296 299
297#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 300#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
298/* Maximum number of gateways (include room for one noop) */ 301/* Maximum number of gateways (include room for one noop) */
299#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t))) 302#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t)))
300/* loose source route gateway list (including room for final destination) */ 303/* loose source route gateway list (including room for final destination) */
@@ -320,16 +323,16 @@ static int waittime = 5; /* time to wait for response (in seconds)
320static int nflag; /* print addresses numerically */ 323static int nflag; /* print addresses numerically */
321static int doipcksum = 1; /* calculate ip checksums by default */ 324static int doipcksum = 1; /* calculate ip checksums by default */
322 325
323#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 326#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
324static int optlen; /* length of ip options */ 327static int optlen; /* length of ip options */
325#else 328#else
326#define optlen 0 329#define optlen 0
327#endif 330#endif
328 331
329#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 332#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
330static int useicmp; /* use icmp echo instead of udp packets */ 333static int useicmp; /* use icmp echo instead of udp packets */
331#endif 334#endif
332#ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE 335#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
333static int verbose; 336static int verbose;
334#endif 337#endif
335 338
@@ -596,14 +599,14 @@ send_probe(int seq, int ttl, struct timeval *tp)
596 outdata->ttl = ttl; 599 outdata->ttl = ttl;
597 memcpy(&outdata->tv, tp, sizeof(outdata->tv)); 600 memcpy(&outdata->tv, tp, sizeof(outdata->tv));
598 601
599#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 602#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
600 if (useicmp) 603 if (useicmp)
601 outicmp->icmp_seq = htons(seq); 604 outicmp->icmp_seq = htons(seq);
602 else 605 else
603#endif 606#endif
604 outudp->dest = htons(port + seq); 607 outudp->dest = htons(port + seq);
605 608
606#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 609#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
607 if (useicmp) { 610 if (useicmp) {
608 /* Always calculate checksum for icmp packets */ 611 /* Always calculate checksum for icmp packets */
609 outicmp->icmp_cksum = 0; 612 outicmp->icmp_cksum = 0;
@@ -631,7 +634,7 @@ send_probe(int seq, int ttl, struct timeval *tp)
631 *outip = tip; 634 *outip = tip;
632 } 635 }
633 636
634#ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE 637#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
635 /* XXX undocumented debugging hack */ 638 /* XXX undocumented debugging hack */
636 if (verbose > 1) { 639 if (verbose > 1) {
637 const u_short *sp; 640 const u_short *sp;
@@ -684,7 +687,7 @@ deltaT(struct timeval *t1p, struct timeval *t2p)
684 return dt; 687 return dt;
685} 688}
686 689
687#ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE 690#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
688/* 691/*
689 * Convert an ICMP "type" field to a printable string. 692 * Convert an ICMP "type" field to a printable string.
690 */ 693 */
@@ -717,7 +720,7 @@ packet_ok(unsigned char *buf, int cc, struct sockaddr_in *from, int seq)
717 ip = (struct ip *) buf; 720 ip = (struct ip *) buf;
718 hlen = ip->ip_hl << 2; 721 hlen = ip->ip_hl << 2;
719 if (cc < hlen + ICMP_MINLEN) { 722 if (cc < hlen + ICMP_MINLEN) {
720#ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE 723#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
721 if (verbose) 724 if (verbose)
722 printf("packet too short (%d bytes) from %s\n", cc, 725 printf("packet too short (%d bytes) from %s\n", cc,
723 inet_ntoa(from->sin_addr)); 726 inet_ntoa(from->sin_addr));
@@ -741,7 +744,7 @@ packet_ok(unsigned char *buf, int cc, struct sockaddr_in *from, int seq)
741 744
742 hip = &icp->icmp_ip; 745 hip = &icp->icmp_ip;
743 hlen = hip->ip_hl << 2; 746 hlen = hip->ip_hl << 2;
744#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 747#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
745 if (useicmp) { 748 if (useicmp) {
746 struct icmp *hicmp; 749 struct icmp *hicmp;
747 750
@@ -770,7 +773,7 @@ packet_ok(unsigned char *buf, int cc, struct sockaddr_in *from, int seq)
770 return (type == ICMP_TIMXCEED ? -1 : code + 1); 773 return (type == ICMP_TIMXCEED ? -1 : code + 1);
771 } 774 }
772 } 775 }
773#ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE 776#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
774 if (verbose) { 777 if (verbose) {
775 int i; 778 int i;
776 u_int32_t *lp = (u_int32_t *)&icp->icmp_ip; 779 u_int32_t *lp = (u_int32_t *)&icp->icmp_ip;
@@ -821,7 +824,7 @@ print(unsigned char *buf, int cc, struct sockaddr_in *from)
821 cc -= hlen; 824 cc -= hlen;
822 825
823 inetname(from); 826 inetname(from);
824#ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE 827#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
825 if (verbose) 828 if (verbose)
826 printf(" %d bytes to %s", cc, inet_ntoa (ip->ip_dst)); 829 printf(" %d bytes to %s", cc, inet_ntoa (ip->ip_dst));
827#endif 830#endif
@@ -869,7 +872,7 @@ freehostinfo(struct hostinfo *hi)
869 free((char *)hi); 872 free((char *)hi);
870} 873}
871 874
872#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 875#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
873static void 876static void
874getaddr(u_int32_t *ap, const char *host) 877getaddr(u_int32_t *ap, const char *host)
875{ 878{
@@ -899,7 +902,7 @@ traceroute_main(int argc, char *argv[])
899 char *source = NULL; 902 char *source = NULL;
900 unsigned long op; 903 unsigned long op;
901 904
902#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 905#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
903 int lsrr = 0; 906 int lsrr = 0;
904#endif 907#endif
905 u_short off = 0; 908 u_short off = 0;
@@ -915,12 +918,12 @@ traceroute_main(int argc, char *argv[])
915 char *pausemsecs_str = NULL; 918 char *pausemsecs_str = NULL;
916 int first_ttl = 1; 919 int first_ttl = 1;
917 char *first_ttl_str = NULL; 920 char *first_ttl_str = NULL;
918#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 921#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
919 llist_t *sourse_route_list = NULL; 922 llist_t *sourse_route_list = NULL;
920#endif 923#endif
921 924
922 opterr = 0; 925 opterr = 0;
923#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 926#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
924 opt_complementary = "x-x:g::"; 927 opt_complementary = "x-x:g::";
925#else 928#else
926 opt_complementary = "x-x"; 929 opt_complementary = "x-x";
@@ -936,23 +939,23 @@ traceroute_main(int argc, char *argv[])
936#define USAGE_OP_VERBOSE (1<<6) /* v */ 939#define USAGE_OP_VERBOSE (1<<6) /* v */
937#define USAGE_OP_IP_CHKSUM (1<<7) /* x */ 940#define USAGE_OP_IP_CHKSUM (1<<7) /* x */
938 941
939#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 942#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
940 "g:" 943 "g:"
941#endif 944#endif
942 , &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str, 945 , &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str,
943 &source, &waittime_str, &pausemsecs_str, &first_ttl_str 946 &source, &waittime_str, &pausemsecs_str, &first_ttl_str
944#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 947#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
945 , &sourse_route_list 948 , &sourse_route_list
946#endif 949#endif
947 ); 950 );
948 951
949 if (op & USAGE_OP_DONT_FRAGMNT) 952 if (op & USAGE_OP_DONT_FRAGMNT)
950 off = IP_DF; 953 off = IP_DF;
951#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 954#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
952 useicmp = op & USAGE_OP_USE_ICMP; 955 useicmp = op & USAGE_OP_USE_ICMP;
953#endif 956#endif
954 nflag = op & USAGE_OP_ADDR_NUM; 957 nflag = op & USAGE_OP_ADDR_NUM;
955#ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE 958#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
956 verbose = op & USAGE_OP_VERBOSE; 959 verbose = op & USAGE_OP_VERBOSE;
957#endif 960#endif
958 if (op & USAGE_OP_IP_CHKSUM) { 961 if (op & USAGE_OP_IP_CHKSUM) {
@@ -981,7 +984,7 @@ traceroute_main(int argc, char *argv[])
981 if (first_ttl_str) 984 if (first_ttl_str)
982 first_ttl = xatoul_range(first_ttl_str, 1, 255); 985 first_ttl = xatoul_range(first_ttl_str, 1, 255);
983 986
984#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 987#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
985 if (sourse_route_list) { 988 if (sourse_route_list) {
986 llist_t *l_sr; 989 llist_t *l_sr;
987 990
@@ -1006,7 +1009,7 @@ traceroute_main(int argc, char *argv[])
1006 1009
1007 minpacket = sizeof(*outip) + sizeof(*outdata) + optlen; 1010 minpacket = sizeof(*outip) + sizeof(*outdata) + optlen;
1008 1011
1009#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 1012#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
1010 if (useicmp) 1013 if (useicmp)
1011 minpacket += 8; /* XXX magic number */ 1014 minpacket += 8; /* XXX magic number */
1012 else 1015 else
@@ -1044,7 +1047,7 @@ traceroute_main(int argc, char *argv[])
1044 1047
1045 s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP); 1048 s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
1046 1049
1047#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG 1050#if TRACEROUTE_SO_DEBUG
1048 if (op & USAGE_OP_DEBUG) 1051 if (op & USAGE_OP_DEBUG)
1049 (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on, 1052 (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on,
1050 sizeof(on)); 1053 sizeof(on));
@@ -1055,7 +1058,7 @@ traceroute_main(int argc, char *argv[])
1055 1058
1056 sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); 1059 sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
1057 1060
1058#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 1061#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
1059#if defined(IP_OPTIONS) 1062#if defined(IP_OPTIONS)
1060 if (lsrr > 0) { 1063 if (lsrr > 0) {
1061 unsigned char optlist[MAX_IPOPTLEN]; 1064 unsigned char optlist[MAX_IPOPTLEN];
@@ -1101,7 +1104,7 @@ traceroute_main(int argc, char *argv[])
1101 } 1104 }
1102#endif 1105#endif
1103#endif 1106#endif
1104#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG 1107#if TRACEROUTE_SO_DEBUG
1105 if (op & USAGE_OP_DEBUG) 1108 if (op & USAGE_OP_DEBUG)
1106 (void)setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on, 1109 (void)setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on,
1107 sizeof(on)); 1110 sizeof(on));
@@ -1126,7 +1129,7 @@ traceroute_main(int argc, char *argv[])
1126 1129
1127 outip->ip_hl = (outp - (unsigned char *)outip) >> 2; 1130 outip->ip_hl = (outp - (unsigned char *)outip) >> 2;
1128 ident = (getpid() & 0xffff) | 0x8000; 1131 ident = (getpid() & 0xffff) | 0x8000;
1129#ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP 1132#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
1130 if (useicmp) { 1133 if (useicmp) {
1131 outip->ip_p = IPPROTO_ICMP; 1134 outip->ip_p = IPPROTO_ICMP;
1132 1135