Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Mar 2009 13:32:31 -0700
From:      Julian Elischer <julian@elischer.org>
To:        Rick Macklem <rmacklem@uoguelph.ca>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: getting a callback ip address for nfsv4 client
Message-ID:  <49D27DDF.9@elischer.org>
In-Reply-To: <Pine.GSO.4.63.0903311604100.15846@muncher.cs.uoguelph.ca>
References:  <Pine.GSO.4.63.0903301733120.17182@muncher.cs.uoguelph.ca> <49D13E9C.8010005@elischer.org> <Pine.GSO.4.63.0903311604100.15846@muncher.cs.uoguelph.ca>

next in thread | previous in thread | raw e-mail | index | archive | help
Rick Macklem wrote:
> 
> 
> On Mon, 30 Mar 2009, Julian Elischer wrote:
> 
>>
>> So you want to do a route lookup so use rtalloc or friends
>> (see route.c).
>>
> 
> First off, I should say that, if there is a better mailing list for
> this kind of thing, please let me know. Also, if this fails, it is
> not the end of the world. All that happens is that the server doesn't
> issue delegations to the client, since the callbacks aren't working.

possibly freebsd-net@ might be a bit better.

> 
> Given that I'd like to avoid having code in nfs fiddling
> with *inp's and such, since it would have to worry about what global
> vars it can use, locking on them, etc., I haven't worried about what
> Max Laier mentioned and just used rtalloc().
> 
> Would someone like to review this function and see what you think?

looks about right (without doing great analysis).

You may be able to make it a bit simpler by calling rtalloc1() 
directly.. also, on might eventually think about the case where
one might want to select a different routing table for NFS as
one uses for other stuff..  but that can be ignored for now.

As there are possibly many addresses on an interface, one needs
to look for the one that has the same network as the gateway..(if
it's not p2p). e.g. if you have 10.2.2.2/24 and 10.3.3.3/24 on
an interface and the gateway is 10.3.3.1, then you obviously
need to select the second address on that interface.


> 
> nfscl_getmyip(struct nfsmount *nmp, int *isinet6p)
> {
>     struct route ro;
>     struct sockaddr_in *sin, *rsin;
>     struct rtentry *rt;
>     u_int8_t *retp = NULL;
>     static struct in_addr laddr;
> 
>     *isinet6p = 0;
>     /*
>      * Loop up a route for the destination address.
>      */
>     if (nmp->nm_nam->sa_family == AF_INET) {
>         bzero(&ro, sizeof (ro));
>         rsin = (struct sockaddr_in *)&ro.ro_dst;
>         sin = (struct sockaddr_in *)nmp->nm_nam;
>         rsin->sin_family = AF_INET;
>         rsin->sin_len = sizeof (struct sockaddr_in);
>         rsin->sin_addr = sin->sin_addr;
>         rtalloc(&ro);
>         rt = ro.ro_rt;
>         if (rt != NULL) {
>             if (rt->rt_ifp != NULL &&
>                 rt->rt_ifa != NULL &&
>                 ((rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0) &&
>                 rt->rt_ifa->ifa_addr->sa_family == AF_INET) {
>                 sin = (struct sockaddr_in *)
>                     rt->rt_ifa->ifa_addr;
>                 laddr = sin->sin_addr;
>                 retp = (u_int8_t *)&laddr;
>             }
>             RTFREE(rt);
>         }
> #ifdef INET6
>     } else if (nmp->nm_nam->sa_family == AF_INET6) {
>         struct sockaddr_in6 *sin6, *rsin6;
>         struct route_in6 ro6;
>         static struct in6_addr laddr6;
> 
>         bzero(&ro6, sizeof (ro6));
>         rsin6 = (struct sockaddr_in6 *)&ro6.ro_dst;
>         sin6 = (struct sockaddr_in6 *)nmp->nm_nam;
>         rsin6->sin6_family = AF_INET6;
>         rsin6->sin6_len = sizeof (struct sockaddr_in6);
>         rsin6->sin6_addr = sin6->sin6_addr;
>         rtalloc((struct route *)&ro6);
>         rt = ro6.ro_rt;
>         if (rt != NULL) {
>             if (rt->rt_ifp != NULL &&
>                 rt->rt_ifa != NULL &&
>                 ((rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0) &&
>                 rt->rt_ifa->ifa_addr->sa_family == AF_INET6) {
>                 sin6 = (struct sockaddr_in6 *)
>                     rt->rt_ifa->ifa_addr;
>                 laddr6 = sin6->sin6_addr;
>                 retp = (u_int8_t *)&laddr6;
>                 *isinet6p = 1;
>             }
>             RTFREE(rt);
>         }
> #endif
>     }
>     return (retp);
> }
> 
> Thanks everyone, for your help sofar, rick
> 
> 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49D27DDF.9>