Date: Fri, 16 Jun 2000 13:29:31 -0700 (PDT) From: kbyanc@posi.net To: FreeBSD-gnats-submit@freebsd.org Cc: billf@FreeBSD.org Subject: ports/19339: patch to fix IPv6 support in net/mtr port Message-ID: <200006162029.NAA13439@kbyanc.corp.ONElist.com>
next in thread | raw e-mail | index | archive | help
>Number: 19339 >Category: ports >Synopsis: patch to fix IPv6 support in net/mtr port >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-ports >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jun 16 13:30:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Kelly Yancey >Release: FreeBSD 4.0-STABLE i386 >Organization: eGroups.com -- http://www.eGroups.com/ >Environment: FreeBSD kbyanc.corp.ONElist.com 4.0-STABLE FreeBSD 4.0-STABLE #2: Thu Jun 15 19:53:20 PDT 2000 root@kbyanc.corp.ONElist.com:/usr/src/sys/compile/EGROUPS i386 >Description: The mtr port won't work on modern FreeBSDs unless IPv6 is compiled into the kernel. Mainly, net_preopen() fails if it cannot open both a IPv4 and an IPv6 raw socket, even when only one is needed. The workaround is to manually force the port to compile without IPv6 support and let the #ifdefs do the work. The attached patch actually tries to solve the problem. -Kelly >How-To-Repeat: Remove INET6 from your kernel config, build new kernel, try to run mtr. >Fix: The attached patch updates net/mtr/patches/patch-01 so mtr will work without IPV6 being compiled into the kernel (but not fail if it is). Since it also fixed a few potential bugs, I am also submitting this patch to Matt Kimball for a future mtr release. --- patch-01.orig Fri Sep 10 09:29:35 1999 +++ patches/patch-01 Fri Jun 16 13:12:49 2000 @@ -1,11 +1,229 @@ ---- net.c.orig Wed Jun 9 11:06:27 1999 -+++ net.c Wed Jul 14 02:03:23 1999 -@@ -213,7 +213,7 @@ - rv = sendto(sendsock, packet, packetsize, 0, - (struct sockaddr *)&remoteaddress, sizeof(remoteaddress)); +--- net.c.orig Fri Jun 16 12:19:01 2000 ++++ net.c Fri Jun 16 13:11:50 2000 +@@ -17,6 +17,7 @@ + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + 1999-08-13 ok Olav@okvittem.priv.no added -psize ++ 2000-06-16 kbyanc@egroups.net improved ipv6 support + + */ + +@@ -135,9 +136,9 @@ + static struct sequence sequence[MaxSequence]; + static struct timeval reset = { 0, 0 }; + +-static int sendsock4 = 0, recvsock4 = 0; ++static int sendsock4 = -1, recvsock4 = -1; + #ifdef ENABLE_IPV6 +-static int sendsock6 = 0, recvsock6 = 0; ++static int sendsock6 = -1, recvsock6 = -1; + #endif + static struct sockaddr_storage remoteaddress; + static int batch_at = 0; +@@ -206,6 +207,8 @@ + int rv; + static int first=1; + ++ if(sendsock4 < 0) return; ++ + if ( packetsize < MINPACKET ) packetsize = MINPACKET; + if ( packetsize > MAXPACKET ) packetsize = MAXPACKET; + memset(packet, 0, packetsize); +@@ -250,10 +253,14 @@ + #endif + ); if (rv >= 0) { - fprintf (stderr, "You've got a broken (FreeBSD?) system\n"); +/* fprintf (stderr, "You've got a broken (FreeBSD?) system\n"); */ BSDfix = 1; } } ++ if (rv < 0) { ++ perror("sendto"); ++ exit(1); ++ } + first = 0; + } + +@@ -268,6 +275,8 @@ + static int first=1; + int hops; + ++ if(sendsock6 < 0) return; ++ + if (packetsize < MINPACKET) packetsize = MINPACKET; + if (packetsize > MAXPACKET) packetsize = MAXPACKET; + memset(packet, 0, packetsize); +@@ -296,12 +305,10 @@ + remoteaddress.ss_len + #endif + ); +-#if 0 + if (rv < 0) { + perror("sendto"); + exit(1); + } +-#endif + first = 0; + } + #endif +@@ -325,6 +332,8 @@ + int index; + int totusec; + ++ if(sendsock4 < 0) return; ++ + if(seq < 0 || seq >= MaxSequence) + return; + +@@ -367,6 +376,8 @@ + int index; + int totusec; + ++ if(sendsock6 < 0) return; ++ + if(seq < 0 || seq >= MaxSequence) + return; + +@@ -416,6 +427,8 @@ + struct ICMPHeader *header; + struct timeval now; + ++ if(recvsock4 < 0) return; ++ + gettimeofday(&now, NULL); + + fromaddrsize = sizeof(fromaddr); +@@ -454,6 +467,8 @@ + struct icmp6_hdr *header; + struct timeval now; + ++ if(recvsock6 < 0) return; ++ + gettimeofday(&now, NULL); + + fromaddrsize = sizeof(fromaddr); +@@ -630,8 +645,6 @@ + int trueopt = 1; + + sendsock4 = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); +- if(sendsock4 < 0) +- return -1; + + #ifdef IP_HDRINCL + /* FreeBSD wants this to avoid sending out packets with protocol type RAW +@@ -639,21 +652,34 @@ + if(setsockopt(sendsock4, SOL_IP, IP_HDRINCL, &trueopt, sizeof(trueopt))) + { + perror("setsockopt(IP_HDRINCL,1)"); +- return -1; ++ sendsock4 = -1; + } + #endif + +- recvsock4 = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); +- if(recvsock4 < 0) +- return -1; ++ if(sendsock4 >= 0) ++ recvsock4 = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); ++ if(recvsock4 < 0) { ++ close(sendsock4); ++ sendsock4 = -1; ++ } + + #ifdef ENABLE_IPV6 + sendsock6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); +- if(sendsock6 < 0) +- return -1; + +- recvsock6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); +- if(recvsock6 < 0) ++ if(sendsock6 >= 0) ++ recvsock6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); ++ if(recvsock6 < 0) { ++ close(sendsock6); ++ sendsock6 = -1; ++ } ++ ++ /* Make sure we have either a valid IPV4 or IPV6 socket pair. */ ++ if(((recvsock4 < 0) || (sendsock4 < 0)) && ++ ((recvsock6 < 0) || (sendsock6 < 0))) ++ return -1; ++#else ++ /* Make sure we have either a valid IPV4 socket pair. */ ++ if((recvsock4 < 0) || (sendsock4 < 0)) + return -1; + #endif + +@@ -662,14 +688,17 @@ + + int net4_open(int addr) { + struct sockaddr_in *sin; ++ ++ if(sendsock4 < 0) return(-1); ++ + net_reset(); + #if 0 +- if (sendsock6) ++ if (sendsock6 >= 0) + close(sendsock6); +- sendsock6 = 0; +- if (recvsock6) ++ sendsock6 = -1; ++ if (recvsock6 >= 0) + close(recvsock6); +- recvsock6 = 0; ++ recvsock6 = -1; + #endif + + memset(&remoteaddress, 0, sizeof(remoteaddress)); +@@ -706,14 +735,17 @@ + #ifdef ENABLE_IPV6 + int net6_open(struct in6_addr *addr) { + struct sockaddr_in6 *sin6; ++ ++ if(sendsock6 < 0) return(-1); ++ + net_reset(); + #if 0 +- if (sendsock4) ++ if (sendsock4 >= 0) + close(sendsock4); +- sendsock4 = 0; +- if (recvsock4) ++ sendsock4 = -1; ++ if (recvsock4 >= 0) + close(recvsock4); +- recvsock4 = 0; ++ recvsock4 = -1; + #endif + + memset(&remoteaddress, 0, sizeof(remoteaddress)); +@@ -731,6 +763,8 @@ + struct sockaddr_in6 *sin6; + int at; + ++ if(sendsock6 < 0) return; ++ + for(at = 0; at < MaxHost; at++) { + memset(&host[at], 0, sizeof(host[at])); + } +@@ -775,14 +809,14 @@ + } + + void net_close() { +- if (sendsock4) ++ if (sendsock4 >= 0) + close(sendsock4); +- if (recvsock4) ++ if (recvsock4 >= 0) + close(recvsock4); + #ifdef ENABLE_IPV6 +- if (sendsock6) ++ if (sendsock6 >= 0) + close(sendsock6); +- if (recvsock6) ++ if (recvsock6 >= 0) + close(recvsock6); + #endif + } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006162029.NAA13439>