From owner-freebsd-arch@FreeBSD.ORG Sun Apr 5 17:28:57 2009 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49F1210656D6 for ; Sun, 5 Apr 2009 17:28:57 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 246768FC1A for ; Sun, 5 Apr 2009 17:28:57 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [65.122.17.41]) by cyrus.watson.org (Postfix) with ESMTPS id CFE2B46B58; Sun, 5 Apr 2009 13:28:56 -0400 (EDT) Date: Sun, 5 Apr 2009 18:28:56 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Rick Macklem In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-arch@freebsd.org Subject: Re: getting a callback ip address for nfsv4 client X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Apr 2009 17:28:58 -0000 On Mon, 30 Mar 2009, Rick Macklem wrote: > Well, since the last one turned out to be too easy, here's one I think is a > little tougher... > > The nfsv4 client needs to know an ip address for the machine, that can be > used by servers to do callbacks on the client. I currently use the > following, which I know isn't correct, but usually works ok: > > loopb = htonl(INADDR_LOOPBACK); > TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) { > if (IA_SIN(ia)->sin_addr.s_addr != loopb) > return (&(IA_SIN(ia)->sin_addr.s_addr)); > } > return (NULL); > > Now, I could just make it a constant set by an rc script (argument to the > callback daemon or a sysctl variable), but that's a bother for laptops using > dhcp and similar. I think allowing an argument to the callback daemon is a > good fallback, but it would be nice if it didn't normally have to be set for > things to work ok. > > Any ideas on how to do this? > > Thanks in advance for any help, rick ps: Part of the reason that the above > loop doesn't seem to be good > enough is that it requires "options VIMAGE_GLOBALS" to build. One possibility is to connect() a socket to the server address, then call getsockaddr() to query what address the network stack is using. If the connection completed, then the address could at least send packets to the server, even if it isn't reachable from the server. (Obviously, kernel versions of the above...) Robert N M Watson Computer Laboratory University of Cambridge