From 421cdc04de9716f994f3bdba17ad4d69494868a5 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Thu, 8 Jul 2010 15:37:48 -0500 Subject: [PATCH] Consolidate loopback address tests Many different places were testing if an address is a loopback address. Consolidate these into one function to make it easier to alter. Change-Id: I9c4465f3bdc4e840c83d69456504caaac1c544e7 Reviewed-on: http://gerrit.openafs.org/2375 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/afs/afs_server.c | 4 ++-- src/libadmin/test/vos.c | 2 +- src/rx/IRIX/rx_knet.c | 2 +- src/rx/SOLARIS/rx_knet.c | 4 ++-- src/rx/rx.h | 6 ++++++ src/rx/rx_getaddr.c | 8 ++++---- src/rx/rx_kcommon.c | 6 +++--- src/rx/rx_user.c | 4 ++-- src/util/netutils.c | 6 +----- src/volser/vos.c | 2 +- 10 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/afs/afs_server.c b/src/afs/afs_server.c index 32c2891d8..c00dd2166 100644 --- a/src/afs/afs_server.c +++ b/src/afs/afs_server.c @@ -1358,7 +1358,7 @@ afs_SetServerPrefs(struct srvAddr *sa) #ifdef notdef if (!s) { - if (afsifinfo[i].ipaddr != 0x7f000001) { /* ignore loopback */ + if (!rx_IsLoopbackAddr(afsifinfo[i].ipaddr)) { /* ignore loopback */ *cnt += 1; if (*cnt > 16) return; @@ -1421,7 +1421,7 @@ afs_SetServerPrefs(struct srvAddr *sa) net = ipif->ipif_local_addr & netmask; #ifdef notdef if (!s) { - if (ipif->ipif_local_addr != 0x7f000001) { /* ignore loopback */ + if (!rx_IsLoopbackAddr(ipif->ipif_local_addr)) { /* ignore loopback */ *cnt += 1; if (*cnt > 16) return; diff --git a/src/libadmin/test/vos.c b/src/libadmin/test/vos.c index 2c7db4cec..533b58b57 100644 --- a/src/libadmin/test/vos.c +++ b/src/libadmin/test/vos.c @@ -1643,7 +1643,7 @@ GetServer(char *aname) memcpy(&addr, th->h_addr, sizeof(addr)); } - if (addr == htonl(0x7f000001)) { /* local host */ + if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */ code = gethostname(hostname, MAXHOSTCHARS); if (code) return 0; diff --git a/src/rx/IRIX/rx_knet.c b/src/rx/IRIX/rx_knet.c index c6a00c1f3..67d0a2ed7 100644 --- a/src/rx/IRIX/rx_knet.c +++ b/src/rx/IRIX/rx_knet.c @@ -374,7 +374,7 @@ rxi_EnumGetIfInfo(struct hashbucket *h, caddr_t key, caddr_t arg1, *(int *)arg1 = different; } rxmtu = rxmtu * rxi_nRecvFrags + ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE); - if ((ifinaddr != 0x7f000001) && (rxmtu > rx_maxReceiveSize)) { + if (!rx_IsLoopbackAddr(ifinaddr) && (rxmtu > rx_maxReceiveSize)) { rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, rxmtu); rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser); } diff --git a/src/rx/SOLARIS/rx_knet.c b/src/rx/SOLARIS/rx_knet.c index 22c85a6eb..97a153a6f 100644 --- a/src/rx/SOLARIS/rx_knet.c +++ b/src/rx/SOLARIS/rx_knet.c @@ -123,7 +123,7 @@ rxi_GetIFInfo() maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu); addrs[i] = ifinaddr; - if (ifinaddr != 0x7f000001 && maxmtu > rx_maxReceiveSize) { + if (!rx_IsLoopbackAddr(ifinaddr) && maxmtu > rx_maxReceiveSize) { rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu); rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser); @@ -184,7 +184,7 @@ rxi_GetIFInfo() addrs[i] = ifinaddr; i++; - if (ifinaddr != 0x7f000001 && maxmtu > rx_maxReceiveSize) { + if (!rx_IsLoopbackAddr(ifinaddr) && maxmtu > rx_maxReceiveSize) { rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu); rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser); diff --git a/src/rx/rx.h b/src/rx/rx.h index 990dc865e..3e4621832 100644 --- a/src/rx/rx.h +++ b/src/rx/rx.h @@ -122,6 +122,12 @@ int ntoh_syserr_conv(int error); #define rx_SecurityClassOf(conn) ((conn)->securityIndex) #define rx_SecurityObjectOf(conn) ((conn)->securityObject) +static_inline int +rx_IsLoopbackAddr(afs_uint32 addr) +{ + return (addr == 0x7f000001); +} + /******************* * Macros callable by the user to further define attributes of a * service. Must be called before rx_StartServer diff --git a/src/rx/rx_getaddr.c b/src/rx/rx_getaddr.c index 9a5104da7..15a13c3cd 100644 --- a/src/rx/rx_getaddr.c +++ b/src/rx/rx_getaddr.c @@ -240,7 +240,7 @@ rx_getAllAddr_internal(afs_uint32 buffer[], int maxSize, int loopbacks) if (count >= maxSize) /* no more space */ dpf(("Too many interfaces..ignoring 0x%x\n", a->sin_addr.s_addr)); - else if (!loopbacks && a->sin_addr.s_addr == htonl(0x7f000001)) { + else if (!loopbacks && rx_IsLoopbackAddr(ntohl(a->sin_addr.s_addr))) { addrcount--; continue; /* skip loopback address as well. */ } else if (loopbacks && ifm->ifm_flags & IFF_LOOPBACK) { @@ -329,7 +329,7 @@ rx_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], } a = (struct sockaddr_in *) info.rti_info[RTAX_IFA]; - if (a->sin_addr.s_addr != htonl(0x7f000001) ) { + if (!rx_IsLoopbackAddr(ntohl(a->sin_addr.s_addr))) ) { if (count >= maxSize) { /* no more space */ dpf(("Too many interfaces..ignoring 0x%x\n", a->sin_addr.s_addr)); @@ -430,7 +430,7 @@ rx_getAllAddr_internal(afs_uint32 buffer[], int maxSize, int loopbacks) } if (a->sin_addr.s_addr != 0) { if (!loopbacks) { - if (a->sin_addr.s_addr == htonl(0x7f000001)) + if (rx_IsLoopbackAddr(ntohl(a->sin_addr.s_addr))) continue; /* skip loopback address as well. */ } else { if (ifr->ifr_flags & IFF_LOOPBACK) @@ -517,7 +517,7 @@ rx_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], continue; /* ignore this address */ } - if (a->sin_addr.s_addr == htonl(0x7f000001) ) + if (rx_IsLoopbackAddr(ntohl(a->sin_addr.s_addr))) continue; /* skip loopback address as well. */ if (count >= maxSize) { /* no more space */ diff --git a/src/rx/rx_kcommon.c b/src/rx/rx_kcommon.c index a88213f9e..f14cf271c 100644 --- a/src/rx/rx_kcommon.c +++ b/src/rx/rx_kcommon.c @@ -532,7 +532,7 @@ rxi_GetcbiInfo(void) rxmtu * rxi_nRecvFrags + ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE); maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu); addrs[i++] = ifinaddr; - if ((ifinaddr != 0x7f000001) && (maxmtu > rx_maxReceiveSize)) { + if (!rx_IsLoopbackAddr(ifinaddr) && (maxmtu > rx_maxReceiveSize)) { rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu); rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser); } @@ -658,7 +658,7 @@ rxi_GetIFInfo(void) ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE); maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu); addrs[i++] = ifinaddr; - if ((ifinaddr != 0x7f000001) && + if (!rx_IsLoopbackAddr(ifinaddr) && (maxmtu > rx_maxReceiveSize)) { rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu); @@ -711,7 +711,7 @@ rxi_GetIFInfo(void) ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE); maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu); addrs[i++] = ifinaddr; - if ((ifinaddr != 0x7f000001) && (maxmtu > rx_maxReceiveSize)) { + if (!rx_IsLoopbackAddr(ifinaddr) && (maxmtu > rx_maxReceiveSize)) { rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu); rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser); diff --git a/src/rx/rx_user.c b/src/rx/rx_user.c index 9712120a3..b4b729db6 100644 --- a/src/rx/rx_user.c +++ b/src/rx/rx_user.c @@ -541,7 +541,7 @@ rx_GetIFInfo(void) if (a->sin_family != AF_INET) continue; rxi_NetAddrs[rxi_numNetAddrs] = ntohl(a->sin_addr.s_addr); - if (rxi_NetAddrs[rxi_numNetAddrs] == 0x7f000001) { + if (rx_IsLoopbackAddr(rxi_NetAddrs[rxi_numNetAddrs])) { /* we don't really care about "localhost" */ continue; } @@ -634,7 +634,7 @@ rx_GetIFInfo(void) #endif } - if (rxi_NetAddrs[rxi_numNetAddrs] != 0x7f000001) { /* ignore lo0 */ + if (!rx_IsLoopbackAddr(rxi_NetAddrs[rxi_numNetAddrs])) { /* ignore lo0 */ int maxsize; maxsize = rxi_nRecvFrags * (myNetMTUs[rxi_numNetAddrs] - RX_IP_SIZE); diff --git a/src/util/netutils.c b/src/util/netutils.c index 03a90e3b6..14f2f1721 100644 --- a/src/util/netutils.c +++ b/src/util/netutils.c @@ -51,10 +51,6 @@ #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 - int ParseNetInfoFile_int(afs_uint32 *, afs_uint32 *, afs_uint32 *, int, char reason[], const char *, int); @@ -412,7 +408,7 @@ filterAddrs(afs_uint32 addr1[], afs_uint32 addr2[], afs_uint32 mask1[], } /* Always mask loopback address */ - if (found && addr1[i] == INADDR_LOOPBACK) + if (found && rx_IsLoopbackAddr(addr1[i])) found = 0; if (found) { diff --git a/src/volser/vos.c b/src/volser/vos.c index 69b52440a..bf55a1ca5 100644 --- a/src/volser/vos.c +++ b/src/volser/vos.c @@ -236,7 +236,7 @@ GetServer(char *aname) memcpy(&addr, th->h_addr, sizeof(addr)); } - if (addr == htonl(0x7f000001)) { /* local host */ + if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */ code = gethostname(hostname, MAXHOSTCHARS); if (code) return 0; -- 2.39.5