From owner-freebsd-sparc64@FreeBSD.ORG Wed Aug 4 11:03:39 2004 Return-Path: Delivered-To: freebsd-sparc64@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F2E4D16A4CE for ; Wed, 4 Aug 2004 11:03:38 +0000 (GMT) Received: from ns.kt-is.co.kr (ns.kt-is.co.kr [211.218.149.125]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5123B43D5C for ; Wed, 4 Aug 2004 11:03:38 +0000 (GMT) (envelope-from yongari@kt-is.co.kr) Received: from michelle.kt-is.co.kr (ns2.kt-is.co.kr [220.76.118.193]) (authenticated bits=128) by ns.kt-is.co.kr (8.12.10/8.12.10) with ESMTP id i74B2AAh016730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 4 Aug 2004 20:02:10 +0900 (KST) Received: from michelle.kt-is.co.kr (localhost.kt-is.co.kr [127.0.0.1]) by michelle.kt-is.co.kr (8.12.10/8.12.10) with ESMTP id i74B3EiH009760 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 4 Aug 2004 20:03:15 +0900 (KST) (envelope-from yongari@kt-is.co.kr) Received: (from yongari@localhost) by michelle.kt-is.co.kr (8.12.10/8.12.10/Submit) id i74B3Eoo009759 for sparc64@freebsd.org; Wed, 4 Aug 2004 20:03:14 +0900 (KST) (envelope-from yongari@kt-is.co.kr) Date: Wed, 4 Aug 2004 20:03:14 +0900 From: Pyun YongHyeon To: sparc64@freebsd.org Message-ID: <20040804110314.GA9602@kt-is.co.kr> References: <20040731061132.GC19761@kt-is.co.kr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="FCuugMFkClbJLl1L" Content-Disposition: inline In-Reply-To: <20040731061132.GC19761@kt-is.co.kr> User-Agent: Mutt/1.4.1i X-Filter-Version: 1.11a (ns.kt-is.co.kr) Subject: Re: ifconfig(8) mediaopt bug and temporary fix X-BeenThere: freebsd-sparc64@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: yongari@kt-is.co.kr List-Id: Porting FreeBSD to the Sparc List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Aug 2004 11:03:39 -0000 --FCuugMFkClbJLl1L Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Jul 31, 2004 at 03:11:32PM +0900, To sparc64@freebsd.org wrote: > Hi, > > Normally, users with hme(4) + DP83840 PHY forcly set media type to > full-duplex since that combination lacks auto-negotiation. However, > this has side-effect of bind(2) problem. Typical phenomenon is > binding error(EADDRNOTAVAIL) for locally assgined address.(INADDR_ANY > works though). I guess this issue had been there for a long time and > triggered by ifconfig mediaopt command in big-endian arch. > > The root cause of the problem seems to be in ifconfig(8) itself. > When ifconfig(8) sets media with user-supplied one, it also sets > its internal global variable(ifr_media) in 'struct ifreq ifr' to > selected one. Since the member variable ifr_media in 'struct ifreq ifr' > is shared with all other attributes, subsequent evaluation of > 'ifr.ifr_addr.sa_family' is wrong. Under Ultra2, usually I see > "atalk 0.0 range 0-0 phase 2" message when I try to set media with command > "ifconfig hme0 media 100baseTX mediaopt full-duplex".(i.e. ifconfig(8) > thinks I had set AF_APPLETALK.) I guess this affects little-endian > machine too. But due to its endian-nature it's not triggered. > > Here is temporary fix for that issue. Since ifconfig(8) is too complex > and very difficult to verify correct operations, I patched domediaopt() > which is *not* correct fix. > I'd like to see correct fix from commiters with thorough knowledge > of ifconfig(8). > Here is better patch. This should fix the two bugs of ifconfig(8) on big-endian machines. bug #1 When mediaopt full-duplex was set, global variable ifr.ifr_media is set to selected media option. Therefore the next reference to "ifr.ifr_addr.sa_family" is wrong since the value was overwritten by selected media option. bug #2 According to bug #1, "ifr.ifr_addr.sa_family" now has the value AF_APPLETALK. So checkatrange() is called and "addreq.ifra_addr" is modified. Now if ifconfig(8) has a new address to set, it incorrectly use the corrupted "addreq". This yield bind(2) error(EADDRNOTAVAIL) for assigned IP address. Thanks. Regards, Pyun YongHyeon -- Pyun YongHyeon --FCuugMFkClbJLl1L Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ifconfig.patch" --- ifconfig.c.orig Mon Aug 2 10:24:34 2004 +++ ifconfig.c Wed Aug 4 19:33:32 2004 @@ -653,14 +653,15 @@ int ifconfig(int argc, char *const *argv, const struct afswtch *afp) { - int s; + int af, s; if (afp == NULL) afp = &afs[0]; ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af; + af = afp->af_af; strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); - if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0) + if ((s = socket(af, SOCK_DGRAM, 0)) < 0) err(1, "socket"); while (argc > 0) { @@ -690,7 +691,7 @@ argc--, argv++; } #ifdef INET6 - if (ifr.ifr_addr.sa_family == AF_INET6 && explicit_prefix == 0) { + if (af == AF_INET6 && explicit_prefix == 0) { /* Aggregatable address architecture defines all prefixes are 64. So, it is convenient to set prefixlen to 64 if it is not specified. */ @@ -699,7 +700,7 @@ } #endif #ifndef NO_IPX - if (setipdst && ifr.ifr_addr.sa_family == AF_IPX) { + if (setipdst && af == AF_IPX) { struct ipxip_req rq; int size = sizeof(rq); @@ -710,7 +711,7 @@ Perror("Encapsulation Routing"); } #endif - if (ifr.ifr_addr.sa_family == AF_APPLETALK) + if (af == AF_APPLETALK) checkatrange((struct sockaddr_at *) &addreq.ifra_addr); if (clearaddr) { if (afp->af_ridreq == NULL || afp->af_difaddr == 0) { --FCuugMFkClbJLl1L--