aboutsummaryrefslogtreecommitdiff
path: root/networking/traceroute.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/traceroute.c')
-rw-r--r--networking/traceroute.c115
1 files changed, 54 insertions, 61 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 12ba614e8..642110c54 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -211,60 +211,62 @@
211 */ 211 */
212 212
213//usage:#define traceroute_trivial_usage 213//usage:#define traceroute_trivial_usage
214//usage: "[-"IF_TRACEROUTE6("46")"FIldnrv] [-f 1ST_TTL] [-m MAXTTL] [-p PORT] [-q PROBES]\n" 214//usage: "[-"IF_TRACEROUTE6("46")"FIlnrv] [-f 1ST_TTL] [-m MAXTTL] [-q PROBES] [-p PORT]\n"
215//usage: " [-s SRC_IP] [-t TOS] [-w WAIT_SEC] [-g GATEWAY] [-i IFACE]\n" 215//usage: " [-t TOS] [-w WAIT_SEC]"
216//usage: IF_FEATURE_TRACEROUTE_SOURCE_ROUTE(" [-g GATEWAY]")" [-s SRC_IP] [-i IFACE]\n"
216//usage: " [-z PAUSE_MSEC] HOST [BYTES]" 217//usage: " [-z PAUSE_MSEC] HOST [BYTES]"
217//usage:#define traceroute_full_usage "\n\n" 218//usage:#define traceroute_full_usage "\n\n"
218//usage: "Trace the route to HOST\n" 219//usage: "Trace the route to HOST\n"
219//usage: IF_TRACEROUTE6( 220//usage: IF_TRACEROUTE6(
220//usage: "\n -4,-6 Force IP or IPv6 name resolution" 221//usage: "\n -4,-6 Force IP or IPv6 name resolution"
221//usage: ) 222//usage: )
222//usage: "\n -F Set the don't fragment bit" 223//usage: "\n -F Set don't fragment bit"
224//usage: IF_FEATURE_TRACEROUTE_USE_ICMP(
223//usage: "\n -I Use ICMP ECHO instead of UDP datagrams" 225//usage: "\n -I Use ICMP ECHO instead of UDP datagrams"
224//usage: "\n -l Display the TTL value of the returned packet" 226//usage: )
225//usage: "\n -d Set SO_DEBUG options to socket" 227//usage: "\n -l Display TTL value of the returned packet"
228//Currently disabled (TRACEROUTE_SO_DEBUG==0)
229////usage: "\n -d Set SO_DEBUG options to socket"
226//usage: "\n -n Print numeric addresses" 230//usage: "\n -n Print numeric addresses"
227//usage: "\n -r Bypass routing tables, send directly to HOST" 231//usage: "\n -r Bypass routing tables, send directly to HOST"
232//usage: IF_FEATURE_TRACEROUTE_VERBOSE(
228//usage: "\n -v Verbose" 233//usage: "\n -v Verbose"
229//usage: "\n -m Max time-to-live (max number of hops)" 234//usage: )
230//usage: "\n -p Base UDP port number used in probes" 235//usage: "\n -f N First number of hops (default 1)"
236//usage: "\n -m N Max number of hops"
237//usage: "\n -q N Number of probes per hop (default 3)"
238//usage: "\n -p N Base UDP port number used in probes"
231//usage: "\n (default 33434)" 239//usage: "\n (default 33434)"
232//usage: "\n -q Number of probes per TTL (default 3)" 240//usage: "\n -s IP Source address"
233//usage: "\n -s IP address to use as the source address" 241//usage: "\n -i IFACE Source interface"
234//usage: "\n -t Type-of-service in probe packets (default 0)" 242//usage: "\n -t N Type-of-service in probe packets (default 0)"
235//usage: "\n -w Time in seconds to wait for a response (default 3)" 243//usage: "\n -w SEC Time to wait for a response (default 3)"
236//usage: "\n -g Loose source route gateway (8 max)" 244//usage: "\n -g IP Loose source route gateway (8 max)"
237//usage: 245//usage:
238//usage:#define traceroute6_trivial_usage 246//usage:#define traceroute6_trivial_usage
239//usage: "[-dnrv] [-m MAXTTL] [-p PORT] [-q PROBES]\n" 247//usage: "[-nrv] [-m MAXTTL] [-q PROBES] [-p PORT]\n"
240//usage: " [-s SRC_IP] [-t TOS] [-w WAIT_SEC] [-i IFACE]\n" 248//usage: " [-t TOS] [-w WAIT_SEC] [-s SRC_IP] [-i IFACE]\n"
241//usage: " HOST [BYTES]" 249//usage: " HOST [BYTES]"
242//usage:#define traceroute6_full_usage "\n\n" 250//usage:#define traceroute6_full_usage "\n\n"
243//usage: "Trace the route to HOST\n" 251//usage: "Trace the route to HOST\n"
244//usage: "\n -d Set SO_DEBUG options to socket" 252//Currently disabled (TRACEROUTE_SO_DEBUG==0)
253////usage: "\n -d Set SO_DEBUG options to socket"
245//usage: "\n -n Print numeric addresses" 254//usage: "\n -n Print numeric addresses"
246//usage: "\n -r Bypass routing tables, send directly to HOST" 255//usage: "\n -r Bypass routing tables, send directly to HOST"
256//usage: IF_FEATURE_TRACEROUTE_VERBOSE(
247//usage: "\n -v Verbose" 257//usage: "\n -v Verbose"
248//usage: "\n -m Max time-to-live (max number of hops)" 258//usage: )
249//usage: "\n -p Base UDP port number used in probes" 259//usage: "\n -m N Max number of hops"
250//usage: "\n (default is 33434)" 260//usage: "\n -q N Number of probes per hop (default 3)"
251//usage: "\n -q Number of probes per TTL (default 3)" 261//usage: "\n -p N Base UDP port number used in probes"
252//usage: "\n -s IP address to use as the source address" 262//usage: "\n (default 33434)"
253//usage: "\n -t Type-of-service in probe packets (default 0)" 263//usage: "\n -s IP Source address"
254//usage: "\n -w Time in seconds to wait for a response (default 3)" 264//usage: "\n -i IFACE Source interface"
265//usage: "\n -t N Type-of-service in probe packets (default 0)"
266//usage: "\n -w SEC Time wait for a response (default 3)"
255 267
256#define TRACEROUTE_SO_DEBUG 0 268#define TRACEROUTE_SO_DEBUG 0
257 269
258/* TODO: undefs were uncommented - ??! we have config system for that! */
259/* probably ok to remove altogether */
260//#undef CONFIG_FEATURE_TRACEROUTE_VERBOSE
261//#define CONFIG_FEATURE_TRACEROUTE_VERBOSE
262//#undef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
263//#define CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
264//#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP
265//#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP
266
267
268#include <net/if.h> 270#include <net/if.h>
269#include <arpa/inet.h> 271#include <arpa/inet.h>
270#include <netinet/in.h> 272#include <netinet/in.h>
@@ -471,18 +473,18 @@ send_probe(int seq, int ttl)
471 473
472#if ENABLE_TRACEROUTE6 474#if ENABLE_TRACEROUTE6
473 if (dest_lsa->u.sa.sa_family == AF_INET6) { 475 if (dest_lsa->u.sa.sa_family == AF_INET6) {
474 res = setsockopt(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)); 476 res = setsockopt_int(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, ttl);
475 if (res < 0) 477 if (res != 0)
476 bb_perror_msg_and_die("setsockopt UNICAST_HOPS %d", ttl); 478 bb_perror_msg_and_die("setsockopt(%s) %d", "UNICAST_HOPS", ttl);
477 out = outip; 479 out = outip;
478 len = packlen; 480 len = packlen;
479 } else 481 } else
480#endif 482#endif
481 { 483 {
482#if defined IP_TTL 484#if defined IP_TTL
483 res = setsockopt(sndsock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); 485 res = setsockopt_int(sndsock, IPPROTO_IP, IP_TTL, ttl);
484 if (res < 0) 486 if (res != 0)
485 bb_perror_msg_and_die("setsockopt ttl %d", ttl); 487 bb_perror_msg_and_die("setsockopt(%s) %d", "TTL", ttl);
486#endif 488#endif
487 out = outicmp; 489 out = outicmp;
488 len = packlen - sizeof(*outip); 490 len = packlen - sizeof(*outip);
@@ -900,13 +902,10 @@ common_traceroute_main(int op, char **argv)
900 if (af == AF_INET6) { 902 if (af == AF_INET6) {
901 xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock); 903 xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock);
902# ifdef IPV6_RECVPKTINFO 904# ifdef IPV6_RECVPKTINFO
903 setsockopt(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO, 905 setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO);
904 &const_int_1, sizeof(const_int_1)); 906 setsockopt_1(rcvsock, SOL_IPV6, IPV6_2292PKTINFO);
905 setsockopt(rcvsock, SOL_IPV6, IPV6_2292PKTINFO,
906 &const_int_1, sizeof(const_int_1));
907# else 907# else
908 setsockopt(rcvsock, SOL_IPV6, IPV6_PKTINFO, 908 setsockopt_1(rcvsock, SOL_IPV6, IPV6_PKTINFO);
909 &const_int_1, sizeof(const_int_1));
910# endif 909# endif
911 } else 910 } else
912#endif 911#endif
@@ -916,18 +915,15 @@ common_traceroute_main(int op, char **argv)
916 915
917#if TRACEROUTE_SO_DEBUG 916#if TRACEROUTE_SO_DEBUG
918 if (op & OPT_DEBUG) 917 if (op & OPT_DEBUG)
919 setsockopt(rcvsock, SOL_SOCKET, SO_DEBUG, 918 setsockopt_SOL_SOCKET_1(rcvsock, SO_DEBUG);
920 &const_int_1, sizeof(const_int_1));
921#endif 919#endif
922 if (op & OPT_BYPASS_ROUTE) 920 if (op & OPT_BYPASS_ROUTE)
923 setsockopt(rcvsock, SOL_SOCKET, SO_DONTROUTE, 921 setsockopt_SOL_SOCKET_1(rcvsock, SO_DONTROUTE);
924 &const_int_1, sizeof(const_int_1));
925 922
926#if ENABLE_TRACEROUTE6 923#if ENABLE_TRACEROUTE6
927 if (af == AF_INET6) { 924 if (af == AF_INET6) {
928 static const int two = 2; 925 if (setsockopt_int(rcvsock, SOL_RAW, IPV6_CHECKSUM, 2) != 0)
929 if (setsockopt(rcvsock, SOL_RAW, IPV6_CHECKSUM, &two, sizeof(two)) < 0) 926 bb_perror_msg_and_die("setsockopt(%s)", "IPV6_CHECKSUM");
930 bb_perror_msg_and_die("setsockopt RAW_CHECKSUM");
931 xmove_fd(xsocket(af, SOCK_DGRAM, 0), sndsock); 927 xmove_fd(xsocket(af, SOCK_DGRAM, 0), sndsock);
932 } else 928 } else
933#endif 929#endif
@@ -964,28 +960,25 @@ common_traceroute_main(int op, char **argv)
964 } 960 }
965 961
966#ifdef SO_SNDBUF 962#ifdef SO_SNDBUF
967 if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(packlen)) < 0) { 963 if (setsockopt_SOL_SOCKET_int(sndsock, SO_SNDBUF, packlen) != 0) {
968 bb_perror_msg_and_die("SO_SNDBUF"); 964 bb_perror_msg_and_die("setsockopt(%s)", "SO_SNDBUF");
969 } 965 }
970#endif 966#endif
971#ifdef IP_TOS 967#ifdef IP_TOS
972 if ((op & OPT_TOS) && setsockopt(sndsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) { 968 if ((op & OPT_TOS) && setsockopt_int(sndsock, IPPROTO_IP, IP_TOS, tos) != 0) {
973 bb_perror_msg_and_die("setsockopt tos %d", tos); 969 bb_perror_msg_and_die("setsockopt(%s) %d", "TOS", tos);
974 } 970 }
975#endif 971#endif
976#ifdef IP_DONTFRAG 972#ifdef IP_DONTFRAG
977 if (op & OPT_DONT_FRAGMNT) 973 if (op & OPT_DONT_FRAGMNT)
978 setsockopt(sndsock, IPPROTO_IP, IP_DONTFRAG, 974 setsockopt_1(sndsock, IPPROTO_IP, IP_DONTFRAG);
979 &const_int_1, sizeof(const_int_1));
980#endif 975#endif
981#if TRACEROUTE_SO_DEBUG 976#if TRACEROUTE_SO_DEBUG
982 if (op & OPT_DEBUG) 977 if (op & OPT_DEBUG)
983 setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, 978 setsockopt_SOL_SOCKET_1(sndsock, SO_DEBUG);
984 &const_int_1, sizeof(const_int_1));
985#endif 979#endif
986 if (op & OPT_BYPASS_ROUTE) 980 if (op & OPT_BYPASS_ROUTE)
987 setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, 981 setsockopt_SOL_SOCKET_1(sndsock, SO_DONTROUTE);
988 &const_int_1, sizeof(const_int_1));
989 982
990 outip = xzalloc(packlen); 983 outip = xzalloc(packlen);
991 984