From ari@guinness.syncrontech.com  Fri Sep 12 04:31:12 2003
Return-Path: <ari@guinness.syncrontech.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B547916A4BF
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 12 Sep 2003 04:31:12 -0700 (PDT)
Received: from cocoa.syncrontech.com (cocoa-e0.syncrontech.com [62.71.8.66])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E23DD43FEC
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 12 Sep 2003 04:31:08 -0700 (PDT)
	(envelope-from ari@guinness.syncrontech.com)
Received: from guinness.syncrontech.com (guinness.syncrontech.com [62.71.8.19])
	by cocoa.syncrontech.com (8.12.8p1/8.12.8) with ESMTP id h8CBV4HR067055
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 12 Sep 2003 14:31:06 +0300 (EEST)
	(envelope-from ari@guinness.syncrontech.com)
Received: from guinness.syncrontech.com (localhost [127.0.0.1])
	by guinness.syncrontech.com (8.12.8p1/8.12.8) with ESMTP id h8CBUOk6018584
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 12 Sep 2003 14:30:24 +0300 (EEST)
	(envelope-from ari@guinness.syncrontech.com)
Received: (from ari@localhost)
	by guinness.syncrontech.com (8.12.8p1/8.12.8/Submit) id h8CBUNa7018580;
	Fri, 12 Sep 2003 14:30:23 +0300 (EEST)
Message-Id: <200309121130.h8CBUNa7018580@guinness.syncrontech.com>
Date: Fri, 12 Sep 2003 14:30:23 +0300 (EEST)
From: ari.suutari@syncrontech.com
Reply-To: ari.suutari@syncrontech.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ifconfig fails if interfaces are being created during it's execution
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         56732
>Category:       bin
>Synopsis:       ifconfig fails if interfaces are being created during it's execution
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    ambrisko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 12 04:40:15 PDT 2003
>Closed-Date:    Fri Apr 30 15:34:46 PDT 2004
>Last-Modified:  Fri Apr 30 15:34:46 PDT 2004
>Originator:     Ari Suutari
>Release:        FreeBSD 4.8-RELEASE i386
>Organization:
Syncron Tech Oy
>Environment:
System: FreeBSD guinness.syncrontech.com 4.8-RELEASE FreeBSD 4.8-RELEASE #9: Mon Apr 7 12:36:25 EEST 2003 root@pommac.syncrontech.com:/usr/obj/usr/src/sys/GUINNESS i386


>Description:
	ifconfig fails with 'actual retrieval of interface table' when
	interfaces are being dynamically created at same time 
	when ifconfig executes. This can happen for example when using
	vtund server, which receives multiple connections during
	startup (which causes multiple tun devices to be created and
	ifconfigured at same time).

	
>How-To-Repeat:
	Run a program that creates network interfaces at same time
	when you use ifconfig.
>Fix:

	I think that ifconfig should check if sysctl call for
	interface table returns an error code which means
	that buffer size was too small and perform call
	again until buffer is large enough.

I think this should fix it.  We've seen this locally on 4.9.  We
are testing this.

Index: sbin/ifconfig/ifconfig.c
===================================================================
RCS file: /usr/local/cvsroot/freebsd/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.51.2.19
diff -u -r1.51.2.19 ifconfig.c
--- sbin/ifconfig/ifconfig.c	28 Jan 2003 11:02:56 -0000	1.51.2.19
+++ sbin/ifconfig/ifconfig.c	17 Mar 2004 21:56:43 -0000
@@ -427,7 +427,7 @@
 {
 	int c;
 	int all, namesonly, downonly, uponly;
-	int foundit = 0, need_nl = 0;
+	int foundit = 0, need_nl = 0, count = 0;
 	const struct afswtch *afp = 0;
 	int addrcount;
 	struct	if_msghdr *ifm, *nextifm;
@@ -551,6 +551,7 @@
 			afp = NULL;	/* not a family, NULL */
 	}
 
+retry:
 	mib[0] = CTL_NET;
 	mib[1] = PF_ROUTE;
 	mib[2] = 0;
@@ -566,8 +567,14 @@
 		errx(1, "iflist-sysctl-estimate");
 	if ((buf = malloc(needed)) == NULL)
 		errx(1, "malloc");
-	if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+	if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
+		if (errno == 12 && count++ < 10) {
+			warnx("Routing table grew, retrying");
+			sleep(1);
+			goto retry;
+		}
 		errx(1, "actual retrieval of interface table");
+	}
 	lim = buf + needed;
 
 	next = buf;

Fixed in ifconfig and route for -current.  They both had similar issues.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ambrisko 
Responsible-Changed-By: ambrisko 
Responsible-Changed-When: Wed Mar 17 15:14:36 PST 2004 
Responsible-Changed-Why:  
I've seen this local so I'm going to take it.  I think I have a fix 
to work around the race condition by retrying a few times. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=56732 
State-Changed-From-To: open->closed 
State-Changed-By: ambrisko 
State-Changed-When: Fri Apr 30 15:28:29 PDT 2004 
State-Changed-Why:  
Fixed this bug in -current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=56732 
>Unformatted:
