From owner-freebsd-net Mon Oct 14 11:35:46 2002 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 2F4A737B401 for ; Mon, 14 Oct 2002 11:35:45 -0700 (PDT) Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by mx1.FreeBSD.org (Postfix) with SMTP id F2C1343EAF for ; Mon, 14 Oct 2002 11:35:43 -0700 (PDT) (envelope-from iedowse@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 14 Oct 2002 19:35:42 +0100 (BST) To: freebsd-net@freebsd.org Subject: IP_SENDSRCADDR implementation Date: Mon, 14 Oct 2002 19:35:42 +0100 From: Ian Dowse Message-ID: <200210141935.aa83883@salmon.maths.tcd.ie> Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org It was discussed here some time ago that we should have an IP_SENDSRCADDR ancillary data type to match the IP_RECVDSTADDR socket option. This permits a server process binding to a wildcard UDP socket to select the IP address from which outgoing packets are sent on a per-datagram basis. When combined with IP_RECVDSTADDR, such server processes can guarantee to reply to a request using the same source IP address as the destination IP address of the request, without having to open one socket per server IP address. Thomas Moestl did an initial implementation of this feature, and the patch presented here is based on his work and some discussions that followed. One approach would be to add to mess in udp_output() where we temporarily block input and connect the wildcard-bound socket to the destination address while sending, and do something similar with binding the source address. The approach taken here was to instead separate each of in_pcbbind() and in_pcbconnect() into a *_setup() version of the function that only performs the port allocation (but does not change the PCB), and an outer wrapper with the original name that calls the *_setup() version and then commits the changes to the PCB. Now udp_output() can use the *_setup() versions to perform the port and address allocation, so it does not need the temporary connect() hack any more. The IP_SENDSRCADDR change consists of adding a control-message reading loop to udp_output(), and doing an in_pcbbind_setup() to determine what source address to use for the datagram. The patch is at: http://www.maths.tcd.ie/~iedowse/FreeBSD/sendsrcaddr.diff Unfortunately it is relatively extensive. I've been running it for about 4 months now, but that does not rule out the possibility of bugs and unintended side-effects. Any comments, reviews or suggestions welcome. Is this something that is useful enough to commit now, or should it be deferred until after 5.0? Ian To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message