From ru@ucb.crimea.ua  Mon Jan  4 05:21:23 1999
Received: from relay.ucb.crimea.ua (relay.ucb.crimea.ua [194.93.177.113])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id FAA12676
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 4 Jan 1999 05:21:13 -0800 (PST)
          (envelope-from ru@ucb.crimea.ua)
Received: (from ru@localhost)
	by relay.ucb.crimea.ua (8.8.8/8.8.8) id PAA05806;
	Mon, 4 Jan 1999 15:20:13 +0200 (EET)
	(envelope-from ru)
Message-Id: <199901041320.PAA05806@relay.ucb.crimea.ua>
Date: Mon, 4 Jan 1999 15:20:13 +0200 (EET)
From: Ruslan Ermilov <ru@ucb.crimea.ua>
Reply-To: ru@ucb.crimea.ua
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] ip_divert.c bug
X-Send-Pr-Version: 3.2

>Number:         9309
>Category:       kern
>Synopsis:       [PATCH] ip_divert.c bug
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    julian@freebsd.org
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan  4 05:30:01 PST 1999
>Closed-Date:    Mon Feb 8 00:35:06 PST 1999
>Last-Modified:  Mon Feb  8 00:36:03 PST 1999
>Originator:     Ruslan Ermilov
>Release:        FreeBSD 2.2.8-STABLE i386
>Organization:
United Commercial Bank
>Environment:

	Kernel built with divert(4) support.

>Description:

	Attempt to write the packet as incoming to the divert socket,
	with sin_port set to the rule number and interface supplied in
	sin_addr, rather than in sin_zero[], causes EADDRNOTAVAIL error.

	The problem first appeared in revision 1.1.2.12, when the
	following line of code was deleted (by Julian Elischer):

	sin->sin_port = 0;

	The removal of this line causes ifa_ifwithaddr() to fail
	when sin_port is set to any non-zero value.

>How-To-Repeat:

	I have a small program, which can be used to implement
	IP over UDP tunneling (http://www.ucb.crimea.ua/~ru/FreeBSD/).
	It worked fine until 2.2.7.  It uses old logic, i.e. sin_port
	is used to avoid firewall checker loops.  Now it fails with
	``Can't assing requested address'' when trying to write an
	incoming packet to the divert socket.

	Thanks to: kseel <kseel@utcorp.com>, who pointed out
	the problem.


>Fix:
	
	 Try the following patch (both RELENG_2_2 and HEAD):

Index: ip_divert.c
===================================================================
RCS file: /usr/FreeBSD-CVS/src/sys/netinet/ip_divert.c,v
retrieving revision 1.1.2.12
diff -u -r1.1.2.12 ip_divert.c
--- ip_divert.c	1998/07/06 08:48:38	1.1.2.12
+++ ip_divert.c	1999/01/04 12:48:00
@@ -317,6 +317,7 @@
 		struct	ifaddr *ifa;
 
 		/* If no luck with the name above, check by IP address.  */
+		sin->sin_port = 0;
 		if (m->m_pkthdr.rcvif == NULL) {
 			if (!(ifa = ifa_ifwithaddr((struct sockaddr *) sin))) {
 				error = EADDRNOTAVAIL;

>Release-Note:
>Audit-Trail:

From: Julian Elischer <julian@whistle.com>
To: freebsd-gnats-submit@freebsd.org, ru@ucb.crimea.ua
Cc:  
Subject: Re: kern/9309: [PATCH] ip_divert.c bug
Date: Sun, 07 Feb 1999 21:45:08 -0800

 Equivalent patch committed to 2.2.x and 4.0.
 I will commit it to 3.1 if allowed. (code freeze in effect)
 --julian
Responsible-Changed-From-To: freebsd-bugs->julian@freebsd.org 
Responsible-Changed-By: julian 
Responsible-Changed-When: Sun Feb 7 22:06:35 PST 1999 
Responsible-Changed-Why:  
I am handling it 
State-Changed-From-To: open->closed 
State-Changed-By: julian 
State-Changed-When: Mon Feb 8 00:35:06 PST 1999 
State-Changed-Why:  
patch committed to all active branches. 
>Unformatted:
