Skip to contentSkip to conversation

Add length flag to set initial MTU.

PATCH New John Heffner 1 participant 2 messages Mar 24, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add length flag to set initial MTU.

---
 tracepath.c  |   10 ++++++++--
 tracepath6.c |   10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
tracepath.c +8 -2
index c3f6f74..1f901ba 100644
@@ -265,7 +265,7 @@ static void usage(void) __attribute((noreturn));
 
 static void usage(void)
 {
-	fprintf(stderr, "Usage: tracepath [-n] <destination>[/<port>]\n");
+	fprintf(stderr, "Usage: tracepath [-n] [-l <len>] <destination>[/<port>]\n");
 	exit(-1);
 }
 
@@ -279,11 +279,17 @@ main(int argc, char **argv)
 	char *p;
 	int ch;
 
-	while ((ch = getopt(argc, argv, "nh?")) != EOF) {
+	while ((ch = getopt(argc, argv, "nh?l:")) != EOF) {
 		switch(ch) {
 		case 'n':	
 			no_resolve = 1;
 			break;
+		case 'l':
+			if ((mtu = atoi(optarg)) <= overhead) {
+				fprintf(stderr, "Error: length must be >= %d\n", overhead);
+				exit(1);
+			}
+			break;
 		default:
 			usage();
 		}
tracepath6.c +8 -2
index 23d6a8c..d65230d 100644
@@ -280,7 +280,7 @@ static void usage(void) __attribute((noreturn));
 
 static void usage(void)
 {
-	fprintf(stderr, "Usage: tracepath6 [-n] [-b] <destination>[/<port>]\n");
+	fprintf(stderr, "Usage: tracepath6 [-n] [-b] [-l <len>] <destination>[/<port>]\n");
 	exit(-1);
 }
 
@@ -297,7 +297,7 @@ int main(int argc, char **argv)
 	int gai;
 	char pbuf[NI_MAXSERV];
 
-	while ((ch = getopt(argc, argv, "nbh?")) != EOF) {
+	while ((ch = getopt(argc, argv, "nbh?l:")) != EOF) {
 		switch(ch) {
 		case 'n':	
 			no_resolve = 1;
@@ -305,6 +305,12 @@ int main(int argc, char **argv)
 		case 'b':	
 			show_both = 1;
 			break;
+		case 'l':
+			if ((mtu = atoi(optarg)) <= overhead) {
+				fprintf(stderr, "Error: length must be >= %d\n", overhead);
+				exit(1);
+			}
+			break;
 		default:
 			usage();
 		}
Signature · 1 line
1.5.0.2.gc260-dirty
#1 lore raw

PATCH 2/2 Use PMTUDISC_PROBE mode if it exists.

---
 tracepath.c  |   10 ++++++++--
 tracepath6.c |   10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
tracepath.c +8 -2
index 1f901ba..a562d88 100644
@@ -24,6 +24,10 @@
 #include <sys/uio.h>
 #include <arpa/inet.h>
 
+#ifndef IP_PMTUDISC_PROBE
+#define IP_PMTUDISC_PROBE	3
+#endif
+
 struct hhistory
 {
 	int	hops;
@@ -322,8 +326,10 @@ main(int argc, char **argv)
 	}
 	memcpy(&target.sin_addr, he->h_addr, 4);
 
-	on = IP_PMTUDISC_DO;
-	if (setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &on, sizeof(on))) {
+	on = IP_PMTUDISC_PROBE;
+	if (setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &on, sizeof(on)) &&
+	    (on = IP_PMTUDISC_DO,
+	     setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &on, sizeof(on)))) {
 		perror("IP_MTU_DISCOVER");
 		exit(1);
 	}
tracepath6.c +8 -2
index d65230d..6f13a51 100644
@@ -30,6 +30,10 @@
 #define SOL_IPV6 IPPROTO_IPV6
 #endif
 
+#ifndef IPV6_PMTUDISC_PROBE
+#define IPV6_PMTUDISC_PROBE	3
+#endif
+
 int overhead = 48;
 int mtu = 128000;
 int hops_to = -1;
@@ -369,8 +373,10 @@ int main(int argc, char **argv)
 		mapped = 1;
 	}
 
-	on = IPV6_PMTUDISC_DO;
-	if (setsockopt(fd, SOL_IPV6, IPV6_MTU_DISCOVER, &on, sizeof(on))) {
+	on = IPV6_PMTUDISC_PROBE;
+	if (setsockopt(fd, SOL_IPV6, IPV6_MTU_DISCOVER, &on, sizeof(on)) &&
+	    (on = IPV6_PMTUDISC_DO,
+	     setsockopt(fd, SOL_IPV6, IPV6_MTU_DISCOVER, &on, sizeof(on)))) {
 		perror("IPV6_MTU_DISCOVER");
 		exit(1);
 	}
Signature · 1 line
1.5.0.2.gc260-dirty