From owner-svn-src-head@FreeBSD.ORG Wed Aug 7 01:01:58 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id CDCD0EFE; Wed, 7 Aug 2013 01:01:58 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A12012D83; Wed, 7 Aug 2013 01:01:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7711wSi042185; Wed, 7 Aug 2013 01:01:58 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7711wKk042184; Wed, 7 Aug 2013 01:01:58 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <201308070101.r7711wKk042184@svn.freebsd.org> From: Rui Paulo Date: Wed, 7 Aug 2013 01:01:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254019 - head/contrib/wpa/src/drivers X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Aug 2013 01:01:58 -0000 Author: rpaulo Date: Wed Aug 7 01:01:58 2013 New Revision: 254019 URL: http://svnweb.freebsd.org/changeset/base/254019 Log: Fix a timing issue with the wired driver. After configuring the interface, wait for the link to become active. Many ethernet drivers reset the chip when we set multicast filters (causing significant delays due to link re-negotiation) and, by the time we start sending packets, they are discared instead of going to the ether. Tested by: dumbbell Modified: head/contrib/wpa/src/drivers/driver_wired.c Modified: head/contrib/wpa/src/drivers/driver_wired.c ============================================================================== --- head/contrib/wpa/src/drivers/driver_wired.c Wed Aug 7 00:28:17 2013 (r254018) +++ head/contrib/wpa/src/drivers/driver_wired.c Wed Aug 7 01:01:58 2013 (r254019) @@ -17,6 +17,7 @@ #endif /* __linux__ */ #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) #include +#include #endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) */ #ifdef __sun__ #include @@ -453,6 +454,29 @@ static int wpa_driver_wired_set_ifflags( return 0; } +static int wpa_driver_wired_get_ifstatus(const char *ifname, int *status) +{ + struct ifmediareq ifmr; + int s; + + s = socket(PF_INET, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + return -1; + } + + os_memset(&ifmr, 0, sizeof(ifmr)); + os_strlcpy(ifmr.ifm_name, ifname, IFNAMSIZ); + if (ioctl(s, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0) { + perror("ioctl[SIOCGIFMEDIA]"); + close(s); + return -1; + } + close(s); + *status = ifmr.ifm_status & IFM_ACTIVE; + + return 0; +} static int wpa_driver_wired_multi(const char *ifname, const u8 *addr, int add) { @@ -511,7 +535,7 @@ static int wpa_driver_wired_multi(const static void * wpa_driver_wired_init(void *ctx, const char *ifname) { struct wpa_driver_wired_data *drv; - int flags; + int flags, status; drv = os_zalloc(sizeof(*drv)); if (drv == NULL) @@ -562,6 +586,11 @@ static void * wpa_driver_wired_init(void __func__); drv->iff_allmulti = 1; } + wpa_printf(MSG_DEBUG, "%s: waiting for link to become active", + __func__); + while (wpa_driver_wired_get_ifstatus(ifname, &status) == 0 && + status == 0) + sleep(1); return drv; }