From nobody@FreeBSD.org  Fri Mar  8 23:26:16 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 8927CDAB
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  8 Mar 2013 23:26:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 622B4F3D
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  8 Mar 2013 23:26:16 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r28NQFeC063318
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 8 Mar 2013 23:26:15 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r28NQF69063317;
	Fri, 8 Mar 2013 23:26:15 GMT
	(envelope-from nobody)
Message-Id: <201303082326.r28NQF69063317@red.freebsd.org>
Date: Fri, 8 Mar 2013 23:26:15 GMT
From: Keith Reynolds <keith.reynolds@tidalscale.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: user-mode netgraph node hangs when replying to control message
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         176771
>Category:       kern
>Synopsis:       [libnetgraph] [patch] user-mode netgraph node hangs when replying to control message
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 08 23:30:00 UTC 2013
>Closed-Date:    Mon Jun 24 09:23:53 UTC 2013
>Last-Modified:  Mon Jun 24 09:30:00 UTC 2013
>Originator:     Keith Reynolds
>Release:        10.0-CURRENT
>Organization:
TidalScale
>Environment:
FreeBSD ts_bhyve1.local 10.0-CURRENT FreeBSD 10.0-CURRENT #1 r245569: Tue Mar  5 14:24:01 PST 2013     root@ts_bhyve1.local:/usr/obj/usr/src/sys/TS  amd64
>Description:
When a netgraph client calls NgSendReplyMsg() to reply to a netgraph
control message that is marked as having a reply
(msg->header.cmd & NGM_HASREPLY), the library blocks waiting for a
reply that will never come, because the message that's being sent *IS*
the reply. It doesn't account for the possibility that the user-mode
client is replying to a netgraph control message rather than originating
one.
>How-To-Repeat:
Write a user-mode netgraph client that responds to the
NGM_GENERIC_COOKIE/NGM_TEXT_STATUS control message, which is marked as
NGM_HASREPLY, and use "ngctl status <node_path>" to query it. The call
to NgSendReplyMsg() will block until another control message comes in,
which won't happen until you use ngctl to send another request.
>Fix:
See the attached patch to lib/libnetgraph/msg.c. The change checks
msg->header.flags & NGF_RESP to determine if the message being sent is
the expected reply before blocking to wait for one.

Patch attached with submission follows:

Index: msg.c
===================================================================
--- msg.c	(revision 245569)
+++ msg.c	(working copy)
@@ -234,7 +234,7 @@
 	}
 
 	/* Wait for reply if there should be one. */
-	if (msg->header.cmd & NGM_HASREPLY) {
+	if (msg->header.cmd & NGM_HASREPLY && !(msg->header.flags & NGF_RESP)) {
 		struct pollfd rfds;
 		int n;
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Mar 10 02:21:57 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=176771 
State-Changed-From-To: open->patched 
State-Changed-By: glebius 
State-Changed-When: Mon Mar 11 12:59:12 UTC 2013 
State-Changed-Why:  
Committed. Thanks for submission! 


Responsible-Changed-From-To: freebsd-net->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Mon Mar 11 12:59:12 UTC 2013 
Responsible-Changed-Why:  
Committed. Thanks for submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=176771 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/176771: commit references a PR
Date: Mon, 11 Mar 2013 13:05:25 +0000 (UTC)

 Author: glebius
 Date: Mon Mar 11 13:05:11 2013
 New Revision: 248159
 URL: http://svnweb.freebsd.org/changeset/base/248159
 
 Log:
   Fix for quite a special case when userland emulates a netgraph node, and
   userland can reply to a message with NGM_HASREPLY bit set. In this case
   we should not wait for a response to a responce.
   
   PR:		176771
   Submitted by:	Keith Reynolds <keith.reynolds tidalscale.com>
 
 Modified:
   head/lib/libnetgraph/msg.c
 
 Modified: head/lib/libnetgraph/msg.c
 ==============================================================================
 --- head/lib/libnetgraph/msg.c	Mon Mar 11 12:22:44 2013	(r248158)
 +++ head/lib/libnetgraph/msg.c	Mon Mar 11 13:05:11 2013	(r248159)
 @@ -234,7 +234,7 @@ NgDeliverMsg(int cs, const char *path,
  	}
  
  	/* Wait for reply if there should be one. */
 -	if (msg->header.cmd & NGM_HASREPLY) {
 +	if (msg->header.cmd & NGM_HASREPLY && !(msg->header.flags & NGF_RESP)) {
  		struct pollfd rfds;
  		int n;
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: glebius 
State-Changed-When: Mon Jun 24 09:23:41 UTC 2013 
State-Changed-Why:  
Merged to stable/9. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=176771 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/176771: commit references a PR
Date: Mon, 24 Jun 2013 09:25:51 +0000 (UTC)

 Author: glebius
 Date: Mon Jun 24 09:25:38 2013
 New Revision: 252151
 URL: http://svnweb.freebsd.org/changeset/base/252151
 
 Log:
   Merge r248159:
     Fix for quite a special case when userland emulates a netgraph node, and
     userland can reply to a message with NGM_HASREPLY bit set. In this case
     we should not wait for a response to a responce.
   
     PR:           176771
     Submitted by: Keith Reynolds <keith.reynolds tidalscale.com>
 
 Modified:
   stable/9/lib/libnetgraph/msg.c
 Directory Properties:
   stable/9/lib/libnetgraph/   (props changed)
 
 Modified: stable/9/lib/libnetgraph/msg.c
 ==============================================================================
 --- stable/9/lib/libnetgraph/msg.c	Mon Jun 24 09:23:24 2013	(r252150)
 +++ stable/9/lib/libnetgraph/msg.c	Mon Jun 24 09:25:38 2013	(r252151)
 @@ -234,7 +234,7 @@ NgDeliverMsg(int cs, const char *path,
  	}
  
  	/* Wait for reply if there should be one. */
 -	if (msg->header.cmd & NGM_HASREPLY) {
 +	if (msg->header.cmd & NGM_HASREPLY && !(msg->header.flags & NGF_RESP)) {
  		struct pollfd rfds;
  		int n;
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
