From owner-freebsd-net@FreeBSD.ORG Tue Mar 16 21:25:12 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7109F16A4CE for ; Tue, 16 Mar 2004 21:25:12 -0800 (PST) Received: from anduril.ncsa.uiuc.edu (cab-wireless-120.ncsa.uiuc.edu [141.142.102.120]) by mx1.FreeBSD.org (Postfix) with ESMTP id 32E6343D3F for ; Tue, 16 Mar 2004 21:25:12 -0800 (PST) (envelope-from jdugan@anduril.ncsa.uiuc.edu) Received: by anduril.ncsa.uiuc.edu (Postfix, from userid 501) id C16DA15956A; Tue, 16 Mar 2004 23:25:11 -0600 (CST) Date: Tue, 16 Mar 2004 23:25:11 -0600 From: Jon Dugan To: freebsd-net@freebsd.org Message-ID: <20040317052511.GA4664@ncsa.uiuc.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i Subject: UDP bind(2) on the same port using SO_REUSEADDR X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Mar 2004 05:25:12 -0000 Imagine two process, A & B. Process A which has a UDP socket bound to a specific address of the machine and a particular port (host:port, say 10.10.10.1:1234). If I set SO_REUSEADDR for the socket in Process B I am able to use the wildcard address (INADDR_ANY or 0.0.0.0) in Process B to bind to the same port (*:port, eg. *:1234). You can also do the converse, process A can bind to the wildcard address and process B can use a specific address). Unix Network Programming by W. Richard Stevens mentions this on pages 195-6 and actually says that using SO_REUSEADDR it is possible to bind to the same address:port tuple as another already running process. I was unable to do do that. Stevens goes on to say that the multiple binding is usually used for multicast, which makes sense. Should it be allowed at all for unicast? I am able to do this in 4.4-RELEASE, 4.9-RELEASE and 5.1-RELEASE. I'm not at all certain this is a bug, but it is certainly somewhat non-obvious behaviour. Is this a bug or and oddity? It came up because I am using rtg to poll many interfaces on a couple of routers on 5 second intervals (gotta love those Junipers, they don't even bat an eye). rtg uses the net-snmp library. The same machine also runs a radius server listening on the radius port (1812). radiusd bound to the socket using a specific address. rtg/net-snmp just ask for the next available port and use the wildcard address. Once in awhile (actually every 5-10 minutes) rtg/net-snmp would do an snmp get using port 1812 which the system had given to it, but radiusd would end up getting the results. This causes indigestion in radiusd... Since I spent quite a bit of time running this down today I figured I'd share with the class. Jon -- Jon Dugan | Senior Network Engineer, NCSA Network Research jdugan@ncsa.uiuc.edu | 269 CAB, 605 E Springfield, Champaign, IL 61820 217-244-7715 | http://www.ncsa.uiuc.edu/~jdugan/