Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/rpcbind When merging addresses, and no direct match...



details:   https://anonhg.NetBSD.org/src/rev/c3fc3f16eef4
branches:  trunk
changeset: 495684:c3fc3f16eef4
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Thu Aug 03 00:04:30 2000 +0000

description:
When merging addresses, and no direct match is found, pick the first
configured interface that is preferably not local or point to point.
This appears to be what Solaris does as well.

diffstat:

 usr.sbin/rpcbind/util.c |  32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diffs (60 lines):

diff -r 471703cc0998 -r c3fc3f16eef4 usr.sbin/rpcbind/util.c
--- a/usr.sbin/rpcbind/util.c   Thu Aug 03 00:01:53 2000 +0000
+++ b/usr.sbin/rpcbind/util.c   Thu Aug 03 00:04:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.3 2000/06/22 10:59:55 fvdl Exp $    */
+/*     $NetBSD: util.c,v 1.4 2000/08/03 00:04:30 fvdl Exp $    */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -108,7 +108,7 @@
 addrmerge(struct netbuf *caller, char *serv_uaddr, char *clnt_uaddr,
          char *netid)
 {
-       struct ifaddrs *ifap, *ifp;
+       struct ifaddrs *ifap, *ifp, *bestif;
 #ifdef INET6
        struct sockaddr_in6 *servsin6, *sin6mask, *clntsin6, *ifsin6, *realsin6;
        struct sockaddr_in6 *newsin6;
@@ -131,6 +131,12 @@
        if (nconf == NULL)
                return NULL;
 
+       /*
+        * Local merge, just return a duplicate.
+        */
+       if (clnt_uaddr != NULL && strncmp(clnt_uaddr, "0.0.0.0.", 8) == 0)
+               return strdup(clnt_uaddr);
+
        serv_nbp = uaddr2taddr(nconf, serv_uaddr);
        if (serv_nbp == NULL)
                return NULL;
@@ -236,6 +242,28 @@
                        goto freeit;
                }
        }
+       /*
+        * Didn't find anything. Get the first possibly useful interface,
+        * preferring "normal" interfaces to point-to-point and loopback
+        * ones.
+        */
+       bestif = NULL;
+       for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) {
+               if (ifap->ifa_addr->sa_family != clnt->sa_family ||
+                   !(ifap->ifa_flags & IFF_UP))
+                       continue;
+               if (!(ifap->ifa_flags & IFF_LOOPBACK) &&
+                   !(ifap->ifa_flags & IFF_POINTOPOINT)) {
+                       bestif = ifap;
+                       break;
+               }
+               if (bestif == NULL)
+                       bestif = ifap;
+               else if ((bestif->ifa_flags & IFF_LOOPBACK) &&
+                   !(ifap->ifa_flags & IFF_LOOPBACK))
+                       bestif = ifap;
+       }
+       ifap = bestif;
 found:
        if (ifap != NULL)
                ret = taddr2uaddr(nconf, &tbuf);



Home | Main Index | Thread Index | Old Index