From: Derrick Brashear Date: Thu, 26 Aug 2004 06:15:57 +0000 (+0000) Subject: allow-loopback-interfaces-to-be-advertised-20040826 X-Git-Tag: BP-disconnected~255 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=ce6d83d6aa2af4da6a3010bad10ff2dbcb44fcf2;p=packages%2Fo%2Fopenafs.git allow-loopback-interfaces-to-be-advertised-20040826 some software network adapters use instances of lo but are real network adapters. allow them to be advertised. the modified functions are called only in the process of collecting a list to advertise. at the same time, make sure we mask 127.0.0.1. i wonder if that's a mistake. --- diff --git a/src/rx/rx_getaddr.c b/src/rx/rx_getaddr.c index 3d0847a1b..870946997 100644 --- a/src/rx/rx_getaddr.c +++ b/src/rx/rx_getaddr.c @@ -118,9 +118,7 @@ rxi_getaddr(void) #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) static void -rt_xaddrs(cp, cplim, rtinfo) - caddr_t cp, cplim; - struct rt_addrinfo *rtinfo; +rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo) { struct sockaddr *sa; int i; @@ -141,9 +139,7 @@ rt_xaddrs(cp, cplim, rtinfo) */ #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) int -rx_getAllAddr(buffer, maxSize) - afs_int32 buffer[]; - int maxSize; /* sizeof of buffer in afs_int32 units */ +rx_getAllAddr(afs_int32 buffer[], int maxSize) { size_t needed; int mib[6]; @@ -221,11 +217,8 @@ rx_getAllAddr(buffer, maxSize) } int -rxi_getAllAddrMaskMtu(addrBuffer, maskBuffer, mtuBuffer, maxSize) - afs_int32 addrBuffer[]; /* the network addrs in net byte order */ - afs_int32 maskBuffer[]; /* the subnet masks */ - afs_int32 mtuBuffer[]; /* the MTU sizes */ - int maxSize; /* sizeof of buffer in afs_int32 units */ +rxi_getAllAddrMaskMtu(afs_int32 addrBuffer[], afs_int32 maskBuffer[], + afs_int32 mtuBuffer[], int maxSize) { int s; @@ -279,9 +272,6 @@ rxi_getAllAddrMaskMtu(addrBuffer, maskBuffer, mtuBuffer, maxSize) } if ((ifm->ifm_flags & IFF_UP) == 0) continue; /* not up */ - if (ifm->ifm_flags & IFF_LOOPBACK) { - continue; /* skip aliased loopbacks as well. */ - } while (addrcount > 0) { struct sockaddr_in *a; @@ -322,13 +312,9 @@ rxi_getAllAddrMaskMtu(addrBuffer, maskBuffer, mtuBuffer, maxSize) free(buf); return count; } - - #else -int -rx_getAllAddr(buffer, maxSize) - afs_int32 buffer[]; - int maxSize; /* sizeof of buffer in afs_int32 units */ +static int +rx_getAllAddr_internal(afs_int32 buffer[], int maxSize, int loopbacks) { int s; int i, len, count = 0; @@ -381,7 +367,7 @@ rx_getAllAddr(buffer, maxSize) continue; /* ignore this address */ } if (a->sin_addr.s_addr != 0) { - if (ifr->ifr_flags & IFF_LOOPBACK) { + if (!loopbacks && (ifr->ifr_flags & IFF_LOOPBACK)) { continue; /* skip aliased loopbacks as well. */ } if (count >= maxSize) /* no more space */ @@ -395,6 +381,12 @@ rx_getAllAddr(buffer, maxSize) return count; } +int +rx_getAllAddr(afs_int32 buffer[], int maxSize) +{ + return rx_getAllAddr_internal(buffer, maxSize, 0); +} + /* this function returns the total number of interface addresses * the buffer has to be passed in by the caller. It also returns * the interface mask. If AFS_USERSPACE_IP_ADDR is defined, it @@ -402,11 +394,8 @@ rx_getAllAddr(buffer, maxSize) * by afsi_SetServerIPRank(). */ int -rxi_getAllAddrMaskMtu(addrBuffer, maskBuffer, mtuBuffer, maxSize) - afs_int32 addrBuffer[]; /* the network addrs in net byte order */ - afs_int32 maskBuffer[]; /* the subnet masks */ - afs_int32 mtuBuffer[]; /* the MTU sizes */ - int maxSize; /* sizeof of buffer in afs_int32 units */ +rxi_getAllAddrMaskMtu(afs_int32 addrBuffer[], afs_int32 maskBuffer[], + afs_int32 mtuBuffer[], int maxSize) { int s; int i, len, count = 0; @@ -418,7 +407,7 @@ rxi_getAllAddrMaskMtu(addrBuffer, maskBuffer, mtuBuffer, maxSize) #endif #if !defined(AFS_USERSPACE_IP_ADDR) - count = rx_getAllAddr(addrBuffer, 1024); + count = rx_getAllAddr_internal(addrBuffer, 1024, 1); for (i = 0; i < count; i++) { maskBuffer[i] = htonl(0xffffffff); mtuBuffer[i] = htonl(1500); @@ -458,9 +447,6 @@ rxi_getAllAddrMaskMtu(addrBuffer, maskBuffer, mtuBuffer, maxSize) perror("SIOCGIFFLAGS"); continue; /* ignore this address */ } - if (ifr->ifr_flags & IFF_LOOPBACK) { - continue; /* skip aliased loopbacks as well. */ - } if (count >= maxSize) { /* no more space */ printf("Too many interfaces..ignoring 0x%x\n", diff --git a/src/util/netutils.c b/src/util/netutils.c index 316f84e71..50c692614 100644 --- a/src/util/netutils.c +++ b/src/util/netutils.c @@ -53,6 +53,10 @@ RCSID #define MAX_NETFILE_LINE 2048 /* length of a line in the netrestrict file */ #define MAXIPADDRS 1024 /* from afsd.c */ +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK (afs_uint32)0x7f000001 +#endif + /* * The line parameter is a pointer to a buffer containing a string of * bytes of the form @@ -382,6 +386,11 @@ filterAddrs(afs_uint32 addr1[], afs_uint32 addr2[], afs_uint32 mask1[], break; } } + + /* Always mask loopback address */ + if (found && addr1[i] == INADDR_LOOPBACK) + found = 0; + if (found) { taddr[count] = addr1[i]; tmask[count] = mask1[i];