From nobody@FreeBSD.org  Fri Jan  6 15:43:45 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CBEE816A420
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  6 Jan 2006 15:43:45 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 90A8043D45
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  6 Jan 2006 15:43:45 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k06FhjMp065446
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 6 Jan 2006 15:43:45 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k06Fhj7j065445;
	Fri, 6 Jan 2006 15:43:45 GMT
	(envelope-from nobody)
Message-Id: <200601061543.k06Fhj7j065445@www.freebsd.org>
Date: Fri, 6 Jan 2006 15:43:45 GMT
From: Spencer Minear <minear@securecomputing.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: The setifmediacallback function is not returning the saved media data before making the ioctl call
X-Send-Pr-Version: www-2.3

>Number:         91399
>Category:       bin
>Synopsis:       ifconfig(8): the setifmediacallback function is not returning the saved media data before making the ioctl call
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ambrisko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 06 15:50:06 GMT 2006
>Closed-Date:    Wed Jan 11 22:41:29 GMT 2006
>Last-Modified:  Wed Jan 11 22:41:29 GMT 2006
>Originator:     Spencer Minear
>Release:        FreeBSD 6.0 RELEASE
>Organization:
Secure Computing Corp.
>Environment:
FreeBSD freebe1.scur.com 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Thu Nov  3 09:36:13 UTC 2005     root@x64.samsco.home:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
The 1.19 version of ifconfig/ifmedia.c added the use of setifmediacallback
so that media setting gets done only once at the end of the sequence of changes.

The change carefully made sure the that new media value was saved in the ifmr
structure which is held in the callback structure.

However the new setifmediacallback structure fails to return media information
saved in the ifmr structure to the ifr structure before the ioctl call is made.
This depending on the order of parameters on the ifconfig command this can
result in making a SIOCSIFMEDIA call with parameters from a previous operation.

>How-To-Repeat:
Use a command like:

ifconfig <IF> inet <addr> netmask <mask> media <mediasetting> mtu 1500

In this case the mtu ioctl gets done before the media ioctl.  In this case
the medial ioctl call contains the 1500 left over from the mtu ioctl call
and returns an ENXIO error.
>Fix:
I think the fix is simple.  Add

		ifr.ifr_media = ifmr->ifm_current;
following line 242.

The code should look like:

	if (!did_it) {
		ifr.ifr_media = ifmr->ifm_current;
		if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0)

It isn't quite this simple since that will nuke the media setting.
The problem appears to be the SIOCSIFMEDIA is not just looking at the
media settings like it should ... it should ignore the other attributes.

I agree this is a side-effect of my change since before everything
was banged into the NIC one at a time which caused its own problems
when the media didn't really changed but it forced the NIC to change
it.  This requires more digging to see if this is a problem in the
ifmedia ioctl to prevent gross hacking of ifconfig.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ambrisko 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Tue Jan 10 13:26:55 UTC 2006 
Responsible-Changed-Why:  
Looks like Doug's change has introduced this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=91399 
State-Changed-From-To: open->closed 
State-Changed-By: ambrisko 
State-Changed-When: Wed Jan 11 22:38:14 UTC 2006 
State-Changed-Why:  
You were right.  It's been a while since I worked in this.  Yes 
I forgot to put the modified value into the global structure. 
I probably thought ifmr and ifr were the same :-( 

Thanks for the fix. 

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