From 563894500fa0a108aeec400077b57b062b7db96c Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Thu, 29 Jul 2004 03:46:48 +0000 Subject: [PATCH] rx-provide-binding-version-of-init-20040728 i should be dragged away and beaten for this first pass at interface to allow bound Rx sockets ==================== This delta was composed from multiple commits as part of the CVS->Git migration. The checkin message with each commit was inconsistent. The following are the additional commit messages. ==================== i should be dragged away and beaten for this ==================== i should be dragged away and beaten for this first pass at interface to allow bound Rx sockets ==================== i should be dragged away and beaten for this first pass at interface to allow bound Rx sockets ==================== i should be dragged away and beaten for this first pass at interface to allow bound Rx sockets ==================== i should be dragged away and beaten for this first pass at interface to allow bound Rx sockets ==================== i should be dragged away and beaten for this first pass at interface to allow bound Rx sockets ==================== i should be dragged away and beaten for this first pass at interface to allow bound Rx sockets --- src/afs/afs_call.c | 16 +++++++++++++++- src/afsd/afsd.c | 16 +++++++++++++--- src/rx/LINUX/rx_knet.c | 9 +++++++-- src/rx/SOLARIS/rx_knet.c | 20 ++++++++++++++++---- src/rx/UKERNEL/rx_knet.c | 8 +++++++- src/rx/rx.c | 13 +++++++++---- src/rx/rx.h | 1 + src/rx/rx_kcommon.c | 19 +++++++++++++++---- src/rx/rx_prototypes.h | 1 + src/rx/rx_user.c | 10 ++++++++-- 10 files changed, 92 insertions(+), 21 deletions(-) diff --git a/src/afs/afs_call.c b/src/afs/afs_call.c index a1d82ca5e..c5c613b1b 100644 --- a/src/afs/afs_call.c +++ b/src/afs/afs_call.c @@ -46,6 +46,7 @@ char afs_zeros[AFS_ZEROS]; char afs_rootVolumeName[64] = ""; struct afs_icl_set *afs_iclSetp = (struct afs_icl_set *)0; struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set *)0; +afs_uint32 rx_bindhost; #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) kmutex_t afs_global_lock; @@ -128,7 +129,7 @@ afs_InitSetup(int preallocs) /* start RX */ rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */ - code = rx_Init(htons(7001)); + code = rx_InitHost(rx_bindhost, htons(7001)); if (code) { printf("AFS: RX failed to initialize %d).\n", code); return code; @@ -700,6 +701,7 @@ afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6) cacheNumEntries : 1)); } else if (parm == AFSOP_ADVISEADDR) { /* pass in the host address to the rx package */ + int rxbind = 0; afs_int32 count = parm2; afs_int32 *buffer = afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); @@ -709,6 +711,13 @@ afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6) afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); int i; + /* Bind, but only if there's only one address configured */ + if ( count & 0x80000000) { + count &= ~0x80000000; + if (count == 1) + rxbind=1; + } + if (count > AFS_MAX_INTERFACE_ADDR) { code = ENOMEM; count = AFS_MAX_INTERFACE_ADDR; @@ -743,6 +752,11 @@ afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6) } afs_uuid_create(&afs_cb_interface.uuid); rxi_setaddr(buffer[0]); + if (rxbind) + rx_bindhost = buffer[0]; + else + rx_bindhost = htonl(INADDR_ANY); + afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 6954bd60d..4e68f9dab 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -221,6 +221,7 @@ struct in_addr_42 { /* * Global configuration variables. */ +afs_int32 enable_rxbind = 0; afs_int32 afs_shutdown = 0; afs_int32 cacheBlocks; /*Num blocks in the cache */ afs_int32 cacheFiles = 1000; /*Optimal # of files in workstation cache */ @@ -1496,7 +1497,12 @@ mainproc(as, arock) /* -backuptree */ enable_backuptree = 1; } + if (as->parms[31].items) { + /* -rxbind */ + enable_rxbind = 1; + } + /* * Pull out all the configuration info for the workstation's AFS cache and * the cellular community we're willing to let our users see. @@ -1667,9 +1673,11 @@ mainproc(as, arock) parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason, AFSDIR_CLIENT_NETINFO_FILEPATH, AFSDIR_CLIENT_NETRESTRICT_FILEPATH); - if (code > 0) + if (code > 0) { + if (enable_rxbind) + code = code | 0x80000000; call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf); - else + } else printf("ADVISEADDR: Error in specifying interface addresses:%s\n", reason); } @@ -2168,6 +2176,7 @@ main(argc, argv) cmd_AddParm(ts, "-nomount", CMD_FLAG, CMD_OPTIONAL, "Do not mount AFS"); cmd_AddParm(ts, "-backuptree", CMD_FLAG, CMD_OPTIONAL, "Prefer backup volumes for mointpoints in backup volumes"); + cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL, "Bind the Rx socket (one interface only)"); return (cmd_Dispatch(argc, argv)); } @@ -2271,7 +2280,8 @@ call_syscall(param1, param2, param3, param4, param5, param6, param7) long eparm[4]; struct afsprocdata syscall_data; int fd = open(PROC_SYSCALL_FNAME,O_RDWR); - + if (fd < 0) + fd = open(PROC_SYSCALL_ARLA_FNAME,O_RDWR); eparm[0] = param4; eparm[1] = param5; eparm[2] = param6; diff --git a/src/rx/LINUX/rx_knet.c b/src/rx/LINUX/rx_knet.c index 1cfb38d81..800ca0225 100644 --- a/src/rx/LINUX/rx_knet.c +++ b/src/rx/LINUX/rx_knet.c @@ -30,7 +30,7 @@ RCSID * open and bind RX socket */ struct osi_socket * -rxk_NewSocket(short aport) +rxk_NewSocketHost(afs_uint32 ahost, short aport) { struct socket *sockp; struct sockaddr_in myaddr; @@ -47,7 +47,7 @@ rxk_NewSocket(short aport) /* Bind socket */ myaddr.sin_family = AF_INET; - myaddr.sin_addr.s_addr = htonl(INADDR_ANY); + myaddr.sin_addr.s_addr = ahost; myaddr.sin_port = aport; code = sockp->ops->bind(sockp, (struct sockaddr *)&myaddr, sizeof(myaddr)); @@ -64,6 +64,11 @@ rxk_NewSocket(short aport) return (struct osi_socket *)sockp; } +struct osi_socket * +rxk_NewSocket(short aport) +{ + return rxk_NewSocketHost(htonl(INADDR_ANY), aport); +} /* free socket allocated by osi_NetSocket */ int diff --git a/src/rx/SOLARIS/rx_knet.c b/src/rx/SOLARIS/rx_knet.c index d8c192ca4..7c247e7f5 100644 --- a/src/rx/SOLARIS/rx_knet.c +++ b/src/rx/SOLARIS/rx_knet.c @@ -222,7 +222,7 @@ struct sockaddr_in rx_sockaddr; /* Allocate a new socket at specified port in network byte order. */ struct osi_socket * -rxk_NewSocket(short aport) +rxk_NewSocketHost(afs_uint32 ahost, short aport) { vnode_t *accessvp; struct sonode *so; @@ -296,7 +296,8 @@ rxk_NewSocket(short aport) addr.sin_family = AF_INET; addr.sin_port = aport; - addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_addr.s_addr = ahost; /* I wonder what the odds are on + needing to unbyteswap this */ error = sockfs_sobind(so, (struct sockaddr *)&addr, sizeof(addr), 0, 0); if (error != 0) { return NULL; @@ -317,6 +318,12 @@ rxk_NewSocket(short aport) return (struct osi_socket *)so; } +struct osi_socket * +rxk_NewSocket(short aport) +{ + return rxk_NewSocketHost(htonl(INADDR_ANY), aport); +} + int osi_FreeSocket(register struct osi_socket *asocket) { @@ -503,7 +510,7 @@ dev_t afs_udp_rdev = (dev_t) 0; /* Allocate a new socket at specified port in network byte order. */ struct osi_socket * -rxk_NewSocket(short aport) +rxk_NewSocketHost(afs_uint32 ahost, short aport) { TIUSER *udp_tiptr; struct t_bind *reqp, *rspp; @@ -534,7 +541,7 @@ rxk_NewSocket(short aport) myaddrp = (struct sockaddr_in *)reqp->addr.buf; myaddrp->sin_family = AF_INET; myaddrp->sin_port = aport; - myaddrp->sin_addr.s_addr = INADDR_ANY; /* XXX Was 0 XXX */ + myaddrp->sin_addr.s_addr = ahost; /* byteswap? */ code = t_kbind(udp_tiptr, reqp, rspp); if (code) { @@ -564,6 +571,11 @@ rxk_NewSocket(short aport) return (struct osi_socket *)udp_tiptr; } +struct osi_socket * +rxk_NewSocket(short aport) +{ + return rxk_NewSocketHost(htonl(INADDR_ANY), aport); +} int osi_FreeSocket(register struct osi_socket *asocket) diff --git a/src/rx/UKERNEL/rx_knet.c b/src/rx/UKERNEL/rx_knet.c index bf00f864b..f7af535e0 100644 --- a/src/rx/UKERNEL/rx_knet.c +++ b/src/rx/UKERNEL/rx_knet.c @@ -170,7 +170,7 @@ rx_ServerProc(void) * we start the receiver threads. */ struct osi_socket * -rxk_NewSocket(short aport) +rxk_NewSocketHost(afs_uint32 ahost, short aport) { struct usr_socket *usockp; @@ -182,6 +182,12 @@ rxk_NewSocket(short aport) return (struct osi_socket *)usockp; } +struct osi_socket * +rxk_NewSocket(short aport) +{ + return rxk_NewSocketHost(htonl(INADDR_ANY), aport); +} + /* * This routine is called from rxk_Listener. By this time rx_port * is set to 7001 and rx_socket points to the socket buffer diff --git a/src/rx/rx.c b/src/rx/rx.c index 11b7e5d2c..a4833f356 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -370,8 +370,8 @@ static int rxinit_status = 1; #define UNLOCK_RX_INIT #endif -int -rx_Init(u_int port) +int +rx_InitHost(u_int host, u_int port) { #ifdef KERNEL osi_timeval_t tv; @@ -407,7 +407,7 @@ rx_Init(u_int port) /* Allocate and initialize a socket for client and perhaps server * connections. */ - rx_socket = rxi_GetUDPSocket((u_short) port); + rx_socket = rxi_GetHostUDPSocket(host, (u_short) port); if (rx_socket == OSI_NULLSOCKET) { UNLOCK_RX_INIT return RX_ADDRINUSE; } @@ -534,6 +534,11 @@ rx_Init(u_int port) UNLOCK_RX_INIT return tmp_status; } +int rx_Init(u_int port) +{ + return rx_InitHost(htonl(INADDR_ANY), port); +} + /* called with unincremented nRequestsRunning to see if it is OK to start * a new thread in this service. Could be "no" for two reasons: over the * max quota, or would prevent others from reaching their min quota. @@ -1247,7 +1252,7 @@ rx_NewService(u_short port, u_short serviceId, char *serviceName, if (socket == OSI_NULLSOCKET) { /* If we don't already have a socket (from another * service on same port) get a new one */ - socket = rxi_GetUDPSocket(port); + socket = rxi_GetHostUDPSocket(htonl(INADDR_ANY), port); if (socket == OSI_NULLSOCKET) { AFS_RXGUNLOCK(); USERPRI; diff --git a/src/rx/rx.h b/src/rx/rx.h index deaac980a..c4da3756a 100644 --- a/src/rx/rx.h +++ b/src/rx/rx.h @@ -96,6 +96,7 @@ #ifndef KERNEL typedef void (*rx_destructor_t) (void *); int rx_KeyCreate(rx_destructor_t); +osi_socket rxi_GetHostUDPSocket(u_int host, u_short port); osi_socket rxi_GetUDPSocket(u_short port); #endif /* KERNEL */ diff --git a/src/rx/rx_kcommon.c b/src/rx/rx_kcommon.c index 3c33865c7..c1b487298 100644 --- a/src/rx/rx_kcommon.c +++ b/src/rx/rx_kcommon.c @@ -30,6 +30,7 @@ int (*rxk_PacketArrivalProc) (register struct rx_packet * ahandle, register stru int (*rxk_GetPacketProc) (char **ahandle, int asize); #endif +struct osi_socket *rxk_NewSocketHost(afs_uint32 ahost, short aport); extern struct interfaceAddr afs_cb_interface; rxk_ports_t rxk_ports; @@ -102,16 +103,21 @@ rxk_shutdownPorts(void) } osi_socket -rxi_GetUDPSocket(u_short port) +rxi_GetHostUDPSocket(u_int host, u_short port) { struct osi_socket *sockp; - sockp = (struct osi_socket *)rxk_NewSocket(port); + sockp = (struct osi_socket *)rxk_NewSocketHost(host, port); if (sockp == (struct osi_socket *)0) return OSI_NULLSOCKET; rxk_AddPort(port, (char *)sockp); return (osi_socket) sockp; } +osi_socket +rxi_GetUDPSocket(u_short port) +{ + return rxi_GetHostUDPSocket(htonl(INADDR_ANY), port); +} void osi_Panic(msg, a1, a2, a3) @@ -756,7 +762,7 @@ rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp) * in network byte order. */ struct osi_socket * -rxk_NewSocket(short aport) +rxk_NewSocketHost(afs_uint32 ahost, short aport) { register afs_int32 code; struct socket *newSocket; @@ -816,7 +822,7 @@ rxk_NewSocket(short aport) memset(&myaddr, 0, sizeof myaddr); myaddr.sin_family = AF_INET; myaddr.sin_port = aport; - myaddr.sin_addr.s_addr = 0; + myaddr.sin_addr.s_addr = ahost; #ifdef STRUCT_SOCKADDR_HAS_SA_LEN myaddr.sin_len = sizeof(myaddr); #endif @@ -908,6 +914,11 @@ rxk_NewSocket(short aport) return (struct osi_socket *)0; } +struct osi_socket * +rxk_NewSocket(short aport) +{ + return rxk_NewSocketHost(0, aport); +} /* free socket allocated by rxk_NewSocket */ int diff --git a/src/rx/rx_prototypes.h b/src/rx/rx_prototypes.h index a8f071fba..f06ec425d 100644 --- a/src/rx/rx_prototypes.h +++ b/src/rx/rx_prototypes.h @@ -313,6 +313,7 @@ extern int rxk_initDone; extern int rxk_DelPort(u_short aport); extern void rxk_shutdownPorts(void); extern osi_socket rxi_GetUDPSocket(u_short port); +extern osi_socket rxi_GetHostUDPSocket(u_int host, u_short port); extern void osi_Panic(); extern int osi_utoa(char *buf, size_t len, unsigned long val); extern void rxi_InitPeerParams(register struct rx_peer *pp); diff --git a/src/rx/rx_user.c b/src/rx/rx_user.c index 7d8cbe3e3..afa229219 100644 --- a/src/rx/rx_user.c +++ b/src/rx/rx_user.c @@ -94,7 +94,7 @@ pthread_mutex_t rx_if_mutex; * failure. Port must be in network byte order. */ osi_socket -rxi_GetUDPSocket(u_short port) +rxi_GetHostUDPSocket(u_int ahost, u_short port) { int binds, code = 0; osi_socket socketFd = OSI_NULLSOCKET; @@ -121,7 +121,7 @@ rxi_GetUDPSocket(u_short port) goto error; } - taddr.sin_addr.s_addr = INADDR_ANY; + taddr.sin_addr.s_addr = ahost; taddr.sin_family = AF_INET; taddr.sin_port = (u_short) port; #ifdef STRUCT_SOCKADDR_HAS_SA_LEN @@ -201,6 +201,12 @@ rxi_GetUDPSocket(u_short port) return OSI_NULLSOCKET; } +osi_socket +rxi_GetUDPSocket(u_short port) +{ + return rxi_GetHostUDPSocket(htonl(INADDR_ANY), port); +} + void osi_Panic(char *msg, int a1, int a2, int a3) { -- 2.39.5