From 55ac2b7aa7da8ead2b3457781d9d60958bfad6be Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 29 Nov 2008 18:55:25 +0000 Subject: [PATCH] netrestrict-netinfo-20081129 LICENSE MIT Rename rxi_getAllAddrMaskMtu to rx_getAllAddrMaskMtu. Implement rx_getAllAddrMaskMtu for Windows. Add rx_getAllAddrMaskMtu to the libafsrpc exports list. Remove restrictions on use of NetRestrict / NetInfo files from all services on Windows. --- src/bozo/bosserver.c | 2 -- src/budb/server.c | 2 -- src/butc/tcmain.c | 2 -- src/kauth/kaserver.c | 2 -- src/libafsrpc/afsrpc.def | 1 + src/ptserver/ptserver.c | 2 -- src/rx/rx_getaddr.c | 8 ++++---- src/rx/rx_prototypes.h | 2 +- src/rx/rx_user.c | 37 +++++++++++++++++++++++++++++++++++-- src/ubik/beacon.c | 5 ----- src/update/server.c | 2 -- src/util/NTMakefile | 2 ++ src/util/netutils.c | 12 ++++++++---- src/viced/viced.c | 2 -- src/volser/volmain.c | 2 -- 15 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/bozo/bosserver.c b/src/bozo/bosserver.c index 4f54953cf..f29ba8f0a 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -1041,7 +1041,6 @@ main(int argc, char **argv, char **envp) if (rxBind) { afs_int32 ccode; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; @@ -1050,7 +1049,6 @@ main(int argc, char **argv, char **envp) AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else -#endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } diff --git a/src/budb/server.c b/src/budb/server.c index 1da790052..b92930575 100644 --- a/src/budb/server.c +++ b/src/budb/server.c @@ -542,7 +542,6 @@ main(argc, argv) if (rxBind) { afs_int32 ccode; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; @@ -551,7 +550,6 @@ main(argc, argv) AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else -#endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } diff --git a/src/butc/tcmain.c b/src/butc/tcmain.c index c9bb6c0bc..935aea406 100644 --- a/src/butc/tcmain.c +++ b/src/butc/tcmain.c @@ -1034,7 +1034,6 @@ WorkerBee(struct cmd_syndesc *as, void *arock) if (rxBind) { afs_int32 ccode; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; @@ -1043,7 +1042,6 @@ WorkerBee(struct cmd_syndesc *as, void *arock) AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else -#endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } diff --git a/src/kauth/kaserver.c b/src/kauth/kaserver.c index 396830c63..9c22ba27a 100644 --- a/src/kauth/kaserver.c +++ b/src/kauth/kaserver.c @@ -390,7 +390,6 @@ main(argc, argv) if (rxBind) { afs_int32 ccode; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; @@ -399,7 +398,6 @@ main(argc, argv) AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else -#endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } diff --git a/src/libafsrpc/afsrpc.def b/src/libafsrpc/afsrpc.def index 2cf4b9f90..640961838 100644 --- a/src/libafsrpc/afsrpc.def +++ b/src/libafsrpc/afsrpc.def @@ -236,6 +236,7 @@ EXPORTS rx_SetRxDeadTime @241 rx_GetMinUdpBufSize @242 rx_SetUdpBufSize @243 + rx_getAllAddrMaskMtu @244 ; for performance testing rx_TSFPQGlobSize @2001 DATA diff --git a/src/ptserver/ptserver.c b/src/ptserver/ptserver.c index 9b33ecf29..d2ee0771e 100644 --- a/src/ptserver/ptserver.c +++ b/src/ptserver/ptserver.c @@ -515,7 +515,6 @@ main(int argc, char **argv) if (rxBind) { afs_int32 ccode; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; @@ -524,7 +523,6 @@ main(int argc, char **argv) AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else -#endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } diff --git a/src/rx/rx_getaddr.c b/src/rx/rx_getaddr.c index c1475a806..b15dfcdaa 100644 --- a/src/rx/rx_getaddr.c +++ b/src/rx/rx_getaddr.c @@ -225,8 +225,8 @@ rx_getAllAddr_internal(afs_uint32 buffer[], int maxSize, int loopbacks) } int -rxi_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], - afs_uint32 mtuBuffer[], int maxSize) +rx_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], + afs_uint32 mtuBuffer[], int maxSize) { int s; @@ -424,8 +424,8 @@ rx_getAllAddr(afs_uint32 buffer[], int maxSize) * by afsi_SetServerIPRank(). */ int -rxi_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], - afs_uint32 mtuBuffer[], int maxSize) +rx_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], + afs_uint32 mtuBuffer[], int maxSize) { int s; int i, len, count = 0; diff --git a/src/rx/rx_prototypes.h b/src/rx/rx_prototypes.h index b0c3652ca..97c57bdf1 100644 --- a/src/rx/rx_prototypes.h +++ b/src/rx/rx_prototypes.h @@ -334,7 +334,7 @@ extern int rxevent_RaiseEvents(struct clock *next); extern void rxi_setaddr(afs_uint32 x); extern afs_uint32 rxi_getaddr(void); extern int rx_getAllAddr(afs_uint32 * buffer, int maxSize); -extern int rxi_getAllAddrMaskMtu(afs_uint32 addrBuffer[], +extern int rx_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], afs_uint32 mtuBuffer[], int maxSize); diff --git a/src/rx/rx_user.c b/src/rx/rx_user.c index 45375592b..efd5f22ae 100644 --- a/src/rx/rx_user.c +++ b/src/rx/rx_user.c @@ -308,14 +308,14 @@ rx_getAllAddr(afs_uint32 * buffer, int maxSize) /* The IP address list can change so we must query for it */ rx_GetIFInfo(); -#ifndef AFS_NT40_ENV +#ifdef AFS_DJGPP_ENV /* we don't want to use the loopback adapter which is first */ /* this is a bad bad hack. * and doesn't hold true on Windows. */ if ( rxi_numNetAddrs > 1 ) offset = 1; -#endif /* AFS_NT40_ENV */ +#endif /* AFS_DJGPP_ENV */ for (count = 0; offset < rxi_numNetAddrs && maxSize > 0; count++, offset++, maxSize--) @@ -323,6 +323,39 @@ rx_getAllAddr(afs_uint32 * buffer, int maxSize) return count; } + +/* this function returns the total number of interface addresses + * the buffer has to be passed in by the caller. It also returns + * the matching interface mask and mtu. All values are returned + * in network byte order. + */ +int +rx_getAllAddrMaskMtu(afs_uint32 addrBuffer[], afs_uint32 maskBuffer[], + afs_uint32 mtuBuffer[], int maxSize) +{ + int count = 0, offset = 0; + + /* The IP address list can change so we must query for it */ + rx_GetIFInfo(); + +#ifdef AFS_DJGPP_ENV + /* we don't want to use the loopback adapter which is first */ + /* this is a bad bad hack. + * and doesn't hold true on Windows. + */ + if ( rxi_numNetAddrs > 1 ) + offset = 1; +#endif /* AFS_DJGPP_ENV */ + + for (count = 0; + offset < rxi_numNetAddrs && maxSize > 0; + count++, offset++, maxSize--) { + addrBuffer[count] = htonl(rxi_NetAddrs[offset]); + maskBuffer[count] = htonl(myNetMasks[offset]); + mtuBuffer[count] = htonl(myNetMTUs[offset]); + } + return count; +} #endif #ifdef AFS_NT40_ENV diff --git a/src/ubik/beacon.c b/src/ubik/beacon.c index 9a996c78b..c2e3c41fa 100644 --- a/src/ubik/beacon.c +++ b/src/ubik/beacon.c @@ -528,10 +528,6 @@ verifyInterfaceAddress(ame, info, aservers) totalServers++; } -#ifdef AFS_NT40_ENV - /* get all my interface addresses in net byte order */ - count = rx_getAllAddr(myAddr, UBIK_MAX_INTERFACE_ADDR); -#else if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { /* * Find addresses we are supposed to register as per the netrestrict file @@ -554,7 +550,6 @@ verifyInterfaceAddress(ame, info, aservers) /* get all my interface addresses in net byte order */ count = rx_getAllAddr(myAddr, UBIK_MAX_INTERFACE_ADDR); } -#endif if (count <= 0) { /* no address found */ ubik_print("ubik: No network addresses found, aborting.."); diff --git a/src/update/server.c b/src/update/server.c index f66edc0ce..b91c9a105 100644 --- a/src/update/server.c +++ b/src/update/server.c @@ -278,7 +278,6 @@ main(int argc, char *argv[]) if (rxBind) { afs_int32 ccode; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; @@ -287,7 +286,6 @@ main(int argc, char *argv[]) AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else -#endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } diff --git a/src/util/NTMakefile b/src/util/NTMakefile index e63ea76e8..cdcbf79be 100644 --- a/src/util/NTMakefile +++ b/src/util/NTMakefile @@ -19,6 +19,7 @@ INCFILES =\ $(INCFILEDIR)\errors.h \ $(INCFILEDIR)\itc.h \ $(INCFILEDIR)\vice.h \ + $(INCFILEDIR)\netutils.h \ $(INCFILEDIR)\pthread_glock.h \ $(INCFILEDIR)\pthread_nosigs.h \ $(INCFILEDIR)\errmap_nt.h \ @@ -45,6 +46,7 @@ LIBOBJS = \ $(OUT)\isathing.obj \ $(OUT)\kreltime.obj \ $(OUT)\ktime.obj \ + $(OUT)\netutils.obj \ $(OUT)\regex.obj \ $(OUT)\readdir_nt.obj \ $(OUT)\serverLog.obj \ diff --git a/src/util/netutils.c b/src/util/netutils.c index 63d2995d4..5f807c29c 100644 --- a/src/util/netutils.c +++ b/src/util/netutils.c @@ -30,13 +30,17 @@ RCSID #include "afs/sysincludes.h" #include "afsincludes.h" #else +#ifdef AFS_NT40_ENV +#include +#else #ifdef __FreeBSD__ #include #endif #include -#include #include #endif +#include +#endif #include "assert.h" #include "afsutil.h" @@ -116,7 +120,7 @@ extract_Addr(char *line, int maxSize) * caller can choose to ignore the entire file but should write * something to a log file). * - * All addresses should be in NBO (as returned by rx_getAllAddr() and + * All addresses should be in NBO (as returned by rx_getAllAddrMaskMtu() and * parsed by extract_Addr(). */ /* @@ -154,7 +158,7 @@ parseNetRestrictFile_int(afs_uint32 outAddrs[], afs_uint32 * mask, strcpy(reason, ""); /* get all network interfaces from the kernel */ - neaddrs = rxi_getAllAddrMaskMtu(eAddrs, eMask, eMtu, MAXIPADDRS); + neaddrs = rx_getAllAddrMaskMtu(eAddrs, eMask, eMtu, MAXIPADDRS); if (neaddrs <= 0) { sprintf(reason, "No existing IP interfaces found"); return -1; @@ -269,7 +273,7 @@ ParseNetInfoFile_int(afs_uint32 * final, afs_uint32 * mask, afs_uint32 * mtu, /* get all network interfaces from the kernel */ existNu = - rxi_getAllAddrMaskMtu(existingAddr, existingMask, existingMtu, + rx_getAllAddrMaskMtu(existingAddr, existingMask, existingMtu, MAXIPADDRS); if (existNu < 0) return existNu; diff --git a/src/viced/viced.c b/src/viced/viced.c index 4c8f00644..c8fee2025 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -1812,7 +1812,6 @@ SetupVL() extern int rxi_numNetAddrs; extern afs_uint32 rxi_NetAddrs[]; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { /* * Find addresses we are supposed to register as per the netrestrict @@ -1830,7 +1829,6 @@ SetupVL() } FS_HostAddr_cnt = (afs_uint32) code; } else -#endif { FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE); } diff --git a/src/volser/volmain.c b/src/volser/volmain.c index bb9cd9214..5181abf9a 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -450,7 +450,6 @@ main(int argc, char **argv) rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */ if (rxBind) { afs_int32 ccode; -#ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; @@ -459,7 +458,6 @@ main(int argc, char **argv) AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else -#endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } -- 2.39.5