From luoqi@chen.ml.org  Mon May 18 03:39:49 1998
Received: from chen.ml.org (luoqi.watermarkgroup.com [207.202.73.170])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id DAA24890
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 18 May 1998 03:39:47 -0700 (PDT)
          (envelope-from luoqi@chen.ml.org)
Received: (from root@localhost)
	by chen.ml.org (8.8.8/8.8.8) id GAA02762;
	Mon, 18 May 1998 06:39:48 -0400 (EDT)
	(envelope-from luoqi)
Message-Id: <199805181039.GAA02762@chen.ml.org>
Date: Mon, 18 May 1998 06:39:48 -0400 (EDT)
From: Luoqi Chen <luoqi@chen.ml.org>
Reply-To: luoqi@chen.ml.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: natd doesn't respond to SIGTERM
X-Send-Pr-Version: 3.2

>Number:         6676
>Category:       bin
>Synopsis:       [PATCH] natd doesn't respond to signals when there is no traffic
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 18 03:40:01 PDT 1998
>Closed-Date:    Thu Sep 2 08:17:44 PDT 1999
>Last-Modified:  Thu Sep  2 08:19:21 PDT 1999
>Originator:     Luoqi Chen
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:

	3.0-current as of 5/16/98

>Description:

	When all of the following conditions are true,
	    o same in & out divert port (default)
	    o alias_address is used instead of an interface name
	    o there is no ip divert traffic (e.g. ipfw divert rule is removed)
	natd won't respond to SIGTERM. I have a natd shutdown script which
	removes ipfw divert rule first, then terminate natd with kill -TERM.
	I could reverse the order, kill natd first, then removes divert rule,
	since natd has a 10 sec grace period before shutdown, but this is
	nevertheless a bug.

	The cause of the problem is that by default signal handlers are
	installed with SA_RESTART flag set, under aforementioned conditions,
	recvfrom() syscall in DoAliasing() will block forever.

>How-To-Repeat:

	Start natd with alias_address option, e.g.
		natd -alias_address ${public_ip_address}

	Now in my shutdown script, I first removes ipfw divert rule, then
		killall natd
	natd won't go away.

>Fix:
	
	Set SIGTERM interruptable. (There's similar problem with SIGHUP,
	in this case, refresh of address is delayed and the first packet
	after an address change might be mistranslated.)

Index: natd.c
===================================================================
RCS file: /fun/cvs/src/usr.sbin/natd/natd.c,v
retrieving revision 1.8
diff -u -r1.8 natd.c
--- natd.c	1997/12/27 19:31:11	1.8
+++ natd.c	1998/05/18 10:09:32
@@ -243,6 +243,8 @@
  * Catch signals to manage shutdown and
  * refresh of interface address.
  */
+	siginterrupt (SIGHUP, 1);
+	siginterrupt (SIGALRM, 1);
 	signal (SIGTERM, InitiateShutdown);
 	signal (SIGHUP, RefreshAddr);
 /*

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Tue May 19 02:09:10 PDT 1998 
State-Changed-Why:  
ready for committer 
State-Changed-From-To: suspended->closed 
State-Changed-By: ru 
State-Changed-When: Thu Sep 2 08:17:44 PDT 1999 
State-Changed-Why:  
Fixed in CURRENT, thanks! 
>Unformatted:
