| File: | rx/rx_kcommon.c |
| Location: | line 573, column 7 |
| Description: | Value stored to 'match_value' is never read |
| 1 | /* |
| 2 | * Copyright 2000, International Business Machines Corporation and others. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This software has been released under the terms of the IBM Public |
| 6 | * License. For details, see the LICENSE file in the top-level source |
| 7 | * directory or online at http://www.openafs.org/dl/license10.html |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * rx_kcommon.c - Common kernel RX code for all system types. |
| 12 | */ |
| 13 | |
| 14 | #include <afsconfig.h> |
| 15 | #include <afs/param.h> |
| 16 | |
| 17 | |
| 18 | #include "rx/rx_kcommon.h" |
| 19 | #include "rx_atomic.h" |
| 20 | #include "rx_stats.h" |
| 21 | |
| 22 | #ifdef AFS_HPUX110_ENV |
| 23 | #include "h/tihdr.h" |
| 24 | #include <xti.h> |
| 25 | #endif |
| 26 | #include "afsint.h" |
| 27 | |
| 28 | #ifndef RXK_LISTENER_ENV1 |
| 29 | int (*rxk_PacketArrivalProc) (struct rx_packet * ahandle, struct sockaddr_in * afrom, struct socketusr_socket *arock, afs_int32 asize); /* set to packet allocation procedure */ |
| 30 | int (*rxk_GetPacketProc) (struct rx_packet **ahandle, int asize); |
| 31 | #endif |
| 32 | |
| 33 | osi_socket *rxk_NewSocketHost(afs_uint32 ahost, short aport); |
| 34 | extern struct interfaceAddr afs_cb_interface; |
| 35 | |
| 36 | rxk_ports_t rxk_ports; |
| 37 | rxk_portRocks_t rxk_portRocks; |
| 38 | |
| 39 | int rxk_initDone = 0; |
| 40 | |
| 41 | #if !defined(AFS_SUN5_ENV) && !defined(AFS_SGI62_ENV) |
| 42 | #define ADDRSPERSITE16 16 |
| 43 | static afs_uint32 myNetAddrs[ADDRSPERSITE16]; |
| 44 | static int myNetMTUs[ADDRSPERSITE16]; |
| 45 | static int numMyNetAddrs = 0; |
| 46 | #endif |
| 47 | |
| 48 | #if defined(AFS_DARWIN80_ENV) |
| 49 | #define sobind sock_bind |
| 50 | #define soclose sock_close |
| 51 | #endif |
| 52 | |
| 53 | /* add a port to the monitored list, port # is in network order */ |
| 54 | static int |
| 55 | rxk_AddPort(u_short aport, char *arock) |
| 56 | { |
| 57 | int i; |
| 58 | unsigned short *tsp, ts; |
| 59 | int zslot; |
| 60 | |
| 61 | zslot = -1; /* look for an empty slot simultaneously */ |
| 62 | for (i = 0, tsp = rxk_ports; i < MAXRXPORTS20; i++, tsp++) { |
| 63 | if (((ts = *tsp) == 0) && (zslot == -1)) |
| 64 | zslot = i; |
| 65 | if (ts == aport) { |
| 66 | return 0; |
| 67 | } |
| 68 | } |
| 69 | /* otherwise allocate a new port slot */ |
| 70 | if (zslot < 0) |
| 71 | return E2BIG7; /* all full */ |
| 72 | rxk_ports[zslot] = aport; |
| 73 | rxk_portRocks[zslot] = arock; |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | /* remove as port from the monitored list, port # is in network order */ |
| 78 | int |
| 79 | rxk_DelPort(u_short aport) |
| 80 | { |
| 81 | int i; |
| 82 | unsigned short *tsp; |
| 83 | |
| 84 | for (i = 0, tsp = rxk_ports; i < MAXRXPORTS20; i++, tsp++) { |
| 85 | if (*tsp == aport) { |
| 86 | /* found it, adjust ref count and free the port reference if all gone */ |
| 87 | *tsp = 0; |
| 88 | return 0; |
| 89 | } |
| 90 | } |
| 91 | /* otherwise port not found */ |
| 92 | return ENOENT2; |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | rxk_shutdownPorts(void) |
| 97 | { |
| 98 | int i; |
| 99 | for (i = 0; i < MAXRXPORTS20; i++) { |
| 100 | if (rxk_ports[i]) { |
| 101 | rxk_ports[i] = 0; |
| 102 | #if ! defined(AFS_SUN5_ENV) && ! defined(UKERNEL1) && ! defined(RXK_LISTENER_ENV1) |
| 103 | soclose((struct socketusr_socket *)rxk_portRocks[i]); |
| 104 | #endif |
| 105 | rxk_portRocks[i] = NULL((void *)0); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | osi_socket |
| 111 | rxi_GetHostUDPSocket(u_int host, u_short port) |
| 112 | { |
| 113 | osi_socket *sockp; |
| 114 | sockp = (osi_socket *)rxk_NewSocketHost(host, port); |
| 115 | if (sockp == (osi_socket *)0) |
| 116 | return OSI_NULLSOCKET((osi_socket) 0); |
| 117 | rxk_AddPort(port, (char *)sockp); |
| 118 | return (osi_socket) sockp; |
| 119 | } |
| 120 | |
| 121 | osi_socket |
| 122 | rxi_GetUDPSocket(u_short port) |
| 123 | { |
| 124 | return rxi_GetHostUDPSocket(htonl(INADDR_ANY)(__builtin_constant_p((u_int32_t)0x00000000) ? ((((__uint32_t )((u_int32_t)0x00000000)) >> 24) | ((((__uint32_t)((u_int32_t )0x00000000)) & (0xff << 16)) >> 8) | ((((__uint32_t )((u_int32_t)0x00000000)) & (0xff << 8)) << 8 ) | (((__uint32_t)((u_int32_t)0x00000000)) << 24)) : __bswap32_var ((u_int32_t)0x00000000)), port); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * osi_utoa() - write the NUL-terminated ASCII decimal form of the given |
| 129 | * unsigned long value into the given buffer. Returns 0 on success, |
| 130 | * and a value less than 0 on failure. The contents of the buffer is |
| 131 | * defined only on success. |
| 132 | */ |
| 133 | |
| 134 | int |
| 135 | osi_utoa(char *bufusr_buf, size_t len, unsigned long val) |
| 136 | { |
| 137 | long k; /* index of first byte of string value */ |
| 138 | |
| 139 | /* we definitely need room for at least one digit and NUL */ |
| 140 | |
| 141 | if (len < 2) { |
| 142 | return -1; |
| 143 | } |
| 144 | |
| 145 | /* compute the string form from the high end of the buffer */ |
| 146 | |
| 147 | bufusr_buf[len - 1] = '\0'; |
| 148 | for (k = len - 2; k >= 0; k--) { |
| 149 | bufusr_buf[k] = val % 10 + '0'; |
| 150 | val /= 10; |
| 151 | |
| 152 | if (val == 0) |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | /* did we finish converting val to string form? */ |
| 157 | |
| 158 | if (val != 0) { |
| 159 | return -2; |
| 160 | } |
| 161 | |
| 162 | /* this should never happen */ |
| 163 | |
| 164 | if (k < 0) { |
| 165 | return -3; |
| 166 | } |
| 167 | |
| 168 | /* this should never happen */ |
| 169 | |
| 170 | if (k >= len) { |
| 171 | return -4; |
| 172 | } |
| 173 | |
| 174 | /* if necessary, relocate string to beginning of buf[] */ |
| 175 | |
| 176 | if (k > 0) { |
| 177 | |
| 178 | /* |
| 179 | * We need to achieve the effect of calling |
| 180 | * |
| 181 | * memmove(buf, &buf[k], len - k); |
| 182 | * |
| 183 | * However, since memmove() is not available in all |
| 184 | * kernels, we explicitly do an appropriate copy. |
| 185 | */ |
| 186 | |
| 187 | char *dst = bufusr_buf; |
| 188 | char *src = bufusr_buf + k; |
| 189 | |
| 190 | while ((*dst++ = *src++) != '\0') |
| 191 | continue; |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | #ifndef AFS_LINUX26_ENV |
| 198 | /* |
| 199 | * osi_AssertFailK() -- used by the osi_Assert() macro. |
| 200 | * |
| 201 | * It essentially does |
| 202 | * |
| 203 | * osi_Panic("assertion failed: %s, file: %s, line: %d", expr, file, line); |
| 204 | * |
| 205 | * Since the kernel version of osi_Panic() only passes its first |
| 206 | * argument to the native panic(), we construct a single string and hand |
| 207 | * that to osi_Panic(). |
| 208 | */ |
| 209 | void |
| 210 | osi_AssertFailK(const char *expr, const char *fileusr_file, int line) |
| 211 | { |
| 212 | static const char msg0[] = "assertion failed: "; |
| 213 | static const char msg1[] = ", file: "; |
| 214 | static const char msg2[] = ", line: "; |
| 215 | static const char msg3[] = "\n"; |
| 216 | |
| 217 | /* |
| 218 | * These buffers add up to 1K, which is a pleasantly nice round |
| 219 | * value, but probably not vital. |
| 220 | */ |
| 221 | char bufusr_buf[1008]; |
| 222 | char linebuf[16]; |
| 223 | |
| 224 | /* check line number conversion */ |
| 225 | |
| 226 | if (osi_utoa(linebuf, sizeof linebuf, line) < 0) { |
| 227 | osi_Panic("osi_AssertFailK: error in osi_utoa()\n"); |
| 228 | } |
| 229 | |
| 230 | /* okay, panic */ |
| 231 | |
| 232 | #define ADDBUF(BUF, STR) \ |
| 233 | if (strlen(BUF) + strlen((char *)(STR)) + 1 <= sizeof BUF) { \ |
| 234 | strcat(BUF, (char *)(STR)); \ |
| 235 | } |
| 236 | |
| 237 | bufusr_buf[0] = '\0'; |
| 238 | ADDBUF(bufusr_buf, msg0); |
| 239 | ADDBUF(bufusr_buf, expr); |
| 240 | ADDBUF(bufusr_buf, msg1); |
| 241 | ADDBUF(bufusr_buf, fileusr_file); |
| 242 | ADDBUF(bufusr_buf, msg2); |
| 243 | ADDBUF(bufusr_buf, linebuf); |
| 244 | ADDBUF(bufusr_buf, msg3); |
| 245 | |
| 246 | #undef ADDBUF |
| 247 | |
| 248 | osi_Panic("%s", bufusr_buf); |
| 249 | } |
| 250 | #endif |
| 251 | |
| 252 | #ifndef UKERNEL1 |
| 253 | /* This is the server process request loop. Kernel server |
| 254 | * processes never become listener threads */ |
| 255 | void * |
| 256 | rx_ServerProc(void *unused) |
| 257 | { |
| 258 | int threadID; |
| 259 | |
| 260 | rxi_MorePackets(rx_maxReceiveWindow + 2); /* alloc more packets */ |
| 261 | MUTEX_ENTER(&rx_quota_mutex)do{if (!(pthread_mutex_lock(&rx_quota_mutex) == 0)) AssertionFailed ("/home/wollman/openafs/src/rx/rx_kcommon.c", 261);}while(0); |
| 262 | rxi_dataQuota += rx_initSendWindow; /* Reserve some pkts for hard times */ |
| 263 | /* threadID is used for making decisions in GetCall. Get it by bumping |
| 264 | * number of threads handling incoming calls */ |
| 265 | threadID = rxi_availProcs++; |
| 266 | MUTEX_EXIT(&rx_quota_mutex)do{if (!(pthread_mutex_unlock(&rx_quota_mutex) == 0)) AssertionFailed ("/home/wollman/openafs/src/rx/rx_kcommon.c", 266);}while(0); |
| 267 | |
| 268 | #ifdef RX_ENABLE_LOCKS1 |
| 269 | AFS_GUNLOCK()do { do { if (!(pthread_self() == afs_global_owner)) { osi_Panic ("afs global lock not held"); } } while(0); memset(&afs_global_owner , 0, sizeof(pthread_t)); do{if (!(pthread_mutex_unlock(&afs_global_lock ) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c" , 269);}while(0); } while(0); |
| 270 | #endif /* RX_ENABLE_LOCKS */ |
| 271 | rxi_ServerProc(threadID, NULL((void *)0), NULL((void *)0)); |
| 272 | #ifdef RX_ENABLE_LOCKS1 |
| 273 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 273);}while(0); afs_global_owner = pthread_self(); } while(0 ); |
| 274 | #endif /* RX_ENABLE_LOCKS */ |
| 275 | |
| 276 | return NULL((void *)0); |
| 277 | } |
| 278 | #endif /* !UKERNEL */ |
| 279 | |
| 280 | #ifndef RXK_LISTENER_ENV1 |
| 281 | /* asize includes the Rx header */ |
| 282 | static int |
| 283 | MyPacketProc(struct rx_packet **ahandle, int asize) |
| 284 | { |
| 285 | struct rx_packet *tp; |
| 286 | |
| 287 | /* If this is larger than we expected, increase rx_maxReceiveDataSize */ |
| 288 | /* If we can't scrounge enough cbufs, then we have to drop the packet, |
| 289 | * but we should set a flag so we magic up some more at our leisure. |
| 290 | */ |
| 291 | |
| 292 | if ((asize >= 0) && (asize <= RX_MAX_PACKET_SIZE16384)) { |
| 293 | tp = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE0); |
| 294 | if (tp && (tp->length + RX_HEADER_SIZEsizeof (struct rx_header)) < asize) { |
| 295 | if (0 < |
| 296 | rxi_AllocDataBuf(tp, asize - (tp->length + RX_HEADER_SIZEsizeof (struct rx_header)), |
| 297 | RX_PACKET_CLASS_RECV_CBUF3)) { |
| 298 | rxi_FreePacket(tp); |
| 299 | tp = NULL((void *)0); |
| 300 | if (rx_stats_active) { |
| 301 | rx_atomic_inc(&rx_stats.noPacketBuffersOnRead); |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | } else { |
| 306 | /* |
| 307 | * XXX if packet is too long for our buffer, |
| 308 | * should do this at a higher layer and let other |
| 309 | * end know we're losing. |
| 310 | */ |
| 311 | if (rx_stats_active) { |
| 312 | rx_atomic_inc(&rx_stats.bogusPacketOnRead); |
| 313 | } |
| 314 | /* I DON"T LIKE THIS PRINTF -- PRINTFS MAKE THINGS VERY VERY SLOOWWW */ |
| 315 | dpf(("rx: packet dropped: bad ulen=%d\n", asize)); |
| 316 | tp = NULL((void *)0); |
| 317 | } |
| 318 | |
| 319 | if (!tp) |
| 320 | return -1; |
| 321 | /* otherwise we have a packet, set appropriate values */ |
| 322 | *ahandle = tp; |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static int |
| 327 | MyArrivalProc(struct rx_packet *ahandle, |
| 328 | struct sockaddr_in *afrom, |
| 329 | struct socketusr_socket *arock, |
| 330 | afs_int32 asize) |
| 331 | { |
| 332 | /* handle basic rx packet */ |
| 333 | ahandle->length = asize - RX_HEADER_SIZEsizeof (struct rx_header); |
| 334 | rxi_DecodePacketHeader(ahandle); |
| 335 | ahandle = |
| 336 | rxi_ReceivePacket(ahandle, arock, |
| 337 | afrom->sin_addr.s_addr, afrom->sin_port, NULL((void *)0), |
| 338 | NULL((void *)0)); |
| 339 | |
| 340 | /* free the packet if it has been returned */ |
| 341 | if (ahandle) |
| 342 | rxi_FreePacket(ahandle); |
| 343 | return 0; |
| 344 | } |
| 345 | #endif /* !RXK_LISTENER_ENV */ |
| 346 | |
| 347 | void |
| 348 | rxi_StartListener(void) |
| 349 | { |
| 350 | #if !defined(RXK_LISTENER_ENV1) && !defined(RXK_UPCALL_ENV) |
| 351 | /* if kernel, give name of appropriate procedures */ |
| 352 | rxk_GetPacketProc = MyPacketProc; |
| 353 | rxk_PacketArrivalProc = MyArrivalProc; |
| 354 | rxk_init(); |
| 355 | #endif |
| 356 | } |
| 357 | |
| 358 | /* Called from rxi_FindPeer, when initializing a clear rx_peer structure, |
| 359 | to get interesting information. */ |
| 360 | void |
| 361 | rxi_InitPeerParams(struct rx_peer *pp) |
| 362 | { |
| 363 | u_short rxmtu; |
| 364 | |
| 365 | #ifdef ADAPT_MTU |
| 366 | # ifndef AFS_SUN5_ENV |
| 367 | # ifdef AFS_USERSPACE_IP_ADDR1 |
| 368 | afs_int32 i; |
| 369 | afs_int32 mtu; |
| 370 | |
| 371 | i = rxi_Findcbi(pp->host); |
| 372 | if (i == -1) { |
| 373 | rx_rto_setPeerTimeoutSecs(pp, 3); |
| 374 | pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE, rx_MyMaxSendSize)((((1500 - RX_IPUDP_SIZE))<(rx_MyMaxSendSize))?((1500 - RX_IPUDP_SIZE )):(rx_MyMaxSendSize)); |
| 375 | } else { |
| 376 | rx_rto_setPeerTimeoutSecs(pp, 2); |
| 377 | pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize)(((16384)<(rx_MyMaxSendSize))?(16384):(rx_MyMaxSendSize)); |
| 378 | mtu = ntohl(afs_cb_interface.mtu[i])(__builtin_constant_p(afs_cb_interface.mtu[i]) ? ((((__uint32_t )(afs_cb_interface.mtu[i])) >> 24) | ((((__uint32_t)(afs_cb_interface .mtu[i])) & (0xff << 16)) >> 8) | ((((__uint32_t )(afs_cb_interface.mtu[i])) & (0xff << 8)) << 8) | (((__uint32_t)(afs_cb_interface.mtu[i])) << 24)) : __bswap32_var(afs_cb_interface.mtu[i])); |
| 379 | /* Diminish the packet size to one based on the MTU given by |
| 380 | * the interface. */ |
| 381 | if (mtu > (RX_IPUDP_SIZE + RX_HEADER_SIZEsizeof (struct rx_header))) { |
| 382 | rxmtu = mtu - RX_IPUDP_SIZE; |
| 383 | if (rxmtu < pp->ifMTU) |
| 384 | pp->ifMTU = rxmtu; |
| 385 | } |
| 386 | } |
| 387 | # else /* AFS_USERSPACE_IP_ADDR */ |
| 388 | rx_ifnet_tstruct usr_ifnet * ifn; |
| 389 | |
| 390 | # if !defined(AFS_SGI62_ENV) |
| 391 | if (numMyNetAddrs == 0) |
| 392 | (void)rxi_GetIFInfo(); |
| 393 | # endif |
| 394 | |
| 395 | ifn = rxi_FindIfnet(pp->host, NULL((void *)0)); |
| 396 | if (ifn) { |
| 397 | rx_rto_setPeerTimeoutSecs(pp, 2); |
| 398 | pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize)(((16384)<(rx_MyMaxSendSize))?(16384):(rx_MyMaxSendSize)); |
| 399 | # ifdef IFF_POINTOPOINT0x10 |
| 400 | if (rx_ifnet_flags(ifn)(ifn?(ifn)->if_flags:0) & IFF_POINTOPOINT0x10) { |
| 401 | /* wish we knew the bit rate and the chunk size, sigh. */ |
| 402 | rx_rto_setPeerTimeoutSecs(pp, 4); |
| 403 | pp->ifMTU = RX_PP_PACKET_SIZE(576 - RX_IPUDP_SIZE); |
| 404 | } |
| 405 | # endif /* IFF_POINTOPOINT */ |
| 406 | /* Diminish the packet size to one based on the MTU given by |
| 407 | * the interface. */ |
| 408 | if (rx_ifnet_mtu(ifn)(ifn)->if_mtu > (RX_IPUDP_SIZE + RX_HEADER_SIZEsizeof (struct rx_header))) { |
| 409 | rxmtu = rx_ifnet_mtu(ifn)(ifn)->if_mtu - RX_IPUDP_SIZE; |
| 410 | if (rxmtu < pp->ifMTU) |
| 411 | pp->ifMTU = rxmtu; |
| 412 | } |
| 413 | } else { /* couldn't find the interface, so assume the worst */ |
| 414 | rx_rto_setPeerTimeoutSecs(pp, 3); |
| 415 | pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE, rx_MyMaxSendSize)((((1500 - RX_IPUDP_SIZE))<(rx_MyMaxSendSize))?((1500 - RX_IPUDP_SIZE )):(rx_MyMaxSendSize)); |
| 416 | } |
| 417 | # endif /* else AFS_USERSPACE_IP_ADDR */ |
| 418 | # else /* AFS_SUN5_ENV */ |
| 419 | afs_int32 mtu; |
| 420 | |
| 421 | mtu = rxi_FindIfMTU(pp->host); |
| 422 | |
| 423 | if (mtu <= 0) { |
| 424 | rx_rto_setPeerTimeoutSecs(pp, 3); |
| 425 | pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE, rx_MyMaxSendSize)((((1500 - RX_IPUDP_SIZE))<(rx_MyMaxSendSize))?((1500 - RX_IPUDP_SIZE )):(rx_MyMaxSendSize)); |
| 426 | } else { |
| 427 | rx_rto_setPeerTimeoutSecs(pp, 2); |
| 428 | pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize)(((16384)<(rx_MyMaxSendSize))?(16384):(rx_MyMaxSendSize)); |
| 429 | |
| 430 | /* Diminish the packet size to one based on the MTU given by |
| 431 | * the interface. */ |
| 432 | if (mtu > (RX_IPUDP_SIZE + RX_HEADER_SIZEsizeof (struct rx_header))) { |
| 433 | rxmtu = mtu - RX_IPUDP_SIZE; |
| 434 | if (rxmtu < pp->ifMTU) |
| 435 | pp->ifMTU = rxmtu; |
| 436 | } |
| 437 | } |
| 438 | # endif /* AFS_SUN5_ENV */ |
| 439 | #else /* ADAPT_MTU */ |
| 440 | pp->rateFlag = 2; /* start timing after two full packets */ |
| 441 | rx_rto_setPeerTimeoutSecs(pp, 2); |
| 442 | pp->ifMTU = OLD_MAX_PACKET_SIZE(1500 - RX_IPUDP_SIZE); |
| 443 | #endif /* else ADAPT_MTU */ |
| 444 | pp->ifMTU = rxi_AdjustIfMTU(pp->ifMTU); |
| 445 | pp->maxMTU = OLD_MAX_PACKET_SIZE(1500 - RX_IPUDP_SIZE); /* for compatibility with old guys */ |
| 446 | pp->natMTU = MIN(pp->ifMTU, OLD_MAX_PACKET_SIZE)(((pp->ifMTU)<((1500 - RX_IPUDP_SIZE)))?(pp->ifMTU): ((1500 - RX_IPUDP_SIZE))); |
| 447 | pp->ifDgramPackets = |
| 448 | MIN(rxi_nDgramPackets,(((rxi_nDgramPackets)<(rxi_AdjustDgramPackets(rxi_nSendFrags , pp->ifMTU)))?(rxi_nDgramPackets):(rxi_AdjustDgramPackets (rxi_nSendFrags, pp->ifMTU))) |
| 449 | rxi_AdjustDgramPackets(rxi_nSendFrags, pp->ifMTU))(((rxi_nDgramPackets)<(rxi_AdjustDgramPackets(rxi_nSendFrags , pp->ifMTU)))?(rxi_nDgramPackets):(rxi_AdjustDgramPackets (rxi_nSendFrags, pp->ifMTU))); |
| 450 | pp->maxDgramPackets = 1; |
| 451 | |
| 452 | /* Initialize slow start parameters */ |
| 453 | pp->MTU = MIN(pp->natMTU, pp->maxMTU)(((pp->natMTU)<(pp->maxMTU))?(pp->natMTU):(pp-> maxMTU)); |
| 454 | pp->cwind = 1; |
| 455 | pp->nDgramPackets = 1; |
| 456 | pp->congestSeq = 0; |
| 457 | } |
| 458 | |
| 459 | |
| 460 | /* The following code is common to several system types, but not all. The |
| 461 | * separate ones are found in the system specific subdirectories. |
| 462 | */ |
| 463 | |
| 464 | |
| 465 | #if ! defined(AFS_AIX_ENV) && ! defined(AFS_SUN5_ENV) && ! defined(UKERNEL1) && ! defined(AFS_LINUX20_ENV) && !defined (AFS_DARWIN_ENV) && !defined (AFS_XBSD_ENV) |
| 466 | /* Routine called during the afsd "-shutdown" process to put things back to |
| 467 | * the initial state. |
| 468 | */ |
| 469 | static struct protosw parent_proto; /* udp proto switch */ |
| 470 | |
| 471 | void |
| 472 | shutdown_rxkernel(void) |
| 473 | { |
| 474 | struct protosw *tpro, *last; |
| 475 | last = inetdomain.dom_protoswNPROTOSW; |
| 476 | for (tpro = inetdomain.dom_protosw; tpro < last; tpro++) |
| 477 | if (tpro->pr_protocol == IPPROTO_UDP17) { |
| 478 | /* restore original udp protocol switch */ |
| 479 | memcpy((void *)tpro, (void *)&parent_proto, sizeof(parent_proto)); |
| 480 | memset((void *)&parent_proto, 0, sizeof(parent_proto)); |
| 481 | rxk_initDone = 0; |
| 482 | rxk_shutdownPorts(); |
| 483 | return; |
| 484 | } |
| 485 | dpf(("shutdown_rxkernel: no udp proto\n")); |
| 486 | } |
| 487 | #endif /* !AIX && !SUN && !NCR && !UKERNEL */ |
| 488 | |
| 489 | #if !defined(AFS_SUN5_ENV) && !defined(AFS_SGI62_ENV) |
| 490 | /* Determine what the network interfaces are for this machine. */ |
| 491 | |
| 492 | #ifdef AFS_USERSPACE_IP_ADDR1 |
| 493 | int |
| 494 | rxi_GetcbiInfo(void) |
| 495 | { |
| 496 | int i, j, different = 0, num = ADDRSPERSITE16; |
| 497 | int rxmtu, maxmtu; |
| 498 | afs_uint32 ifinaddr; |
| 499 | afs_uint32 addrs[ADDRSPERSITE16]; |
| 500 | int mtus[ADDRSPERSITE16]; |
| 501 | |
| 502 | memset((void *)addrs, 0, sizeof(addrs)); |
| 503 | memset((void *)mtus, 0, sizeof(mtus)); |
| 504 | |
| 505 | if (afs_cb_interface.numberOfInterfaces < num) |
| 506 | num = afs_cb_interface.numberOfInterfaces; |
| 507 | for (i = 0; i < num; i++) { |
| 508 | if (!afs_cb_interface.mtu[i]) |
| 509 | afs_cb_interface.mtu[i] = htonl(1500)(__builtin_constant_p(1500) ? ((((__uint32_t)(1500)) >> 24) | ((((__uint32_t)(1500)) & (0xff << 16)) >> 8) | ((((__uint32_t)(1500)) & (0xff << 8)) << 8) | (((__uint32_t)(1500)) << 24)) : __bswap32_var(1500 )); |
| 510 | rxmtu = (ntohl(afs_cb_interface.mtu[i])(__builtin_constant_p(afs_cb_interface.mtu[i]) ? ((((__uint32_t )(afs_cb_interface.mtu[i])) >> 24) | ((((__uint32_t)(afs_cb_interface .mtu[i])) & (0xff << 16)) >> 8) | ((((__uint32_t )(afs_cb_interface.mtu[i])) & (0xff << 8)) << 8) | (((__uint32_t)(afs_cb_interface.mtu[i])) << 24)) : __bswap32_var(afs_cb_interface.mtu[i])) - RX_IPUDP_SIZE); |
| 511 | ifinaddr = ntohl(afs_cb_interface.addr_in[i])(__builtin_constant_p(afs_cb_interface.addr_in[i]) ? ((((__uint32_t )(afs_cb_interface.addr_in[i])) >> 24) | ((((__uint32_t )(afs_cb_interface.addr_in[i])) & (0xff << 16)) >> 8) | ((((__uint32_t)(afs_cb_interface.addr_in[i])) & (0xff << 8)) << 8) | (((__uint32_t)(afs_cb_interface.addr_in [i])) << 24)) : __bswap32_var(afs_cb_interface.addr_in[ i])); |
| 512 | if (myNetAddrs[i] != ifinaddr) |
| 513 | different++; |
| 514 | |
| 515 | mtus[i] = rxmtu; |
| 516 | rxmtu = rxi_AdjustIfMTU(rxmtu); |
| 517 | maxmtu = |
| 518 | rxmtu * rxi_nRecvFrags + ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE8); |
| 519 | maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu); |
| 520 | addrs[i++] = ifinaddr; |
| 521 | if (!rx_IsLoopbackAddr(ifinaddr) && (maxmtu > rx_maxReceiveSize)) { |
| 522 | rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu)(((16384)<(maxmtu))?(16384):(maxmtu)); |
| 523 | rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser)(((rx_maxReceiveSize)<(rx_maxReceiveSizeUser))?(rx_maxReceiveSize ):(rx_maxReceiveSizeUser)); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | rx_maxJumboRecvSize = |
| 528 | RX_HEADER_SIZEsizeof (struct rx_header) + (rxi_nDgramPackets * RX_JUMBOBUFFERSIZE1412) + |
| 529 | ((rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE4); |
| 530 | rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize)(((rx_maxJumboRecvSize)>(rx_maxReceiveSize))?(rx_maxJumboRecvSize ):(rx_maxReceiveSize)); |
| 531 | |
| 532 | if (different) { |
| 533 | for (j = 0; j < i; j++) { |
| 534 | myNetMTUs[j] = mtus[j]; |
| 535 | myNetAddrs[j] = addrs[j]; |
| 536 | } |
| 537 | } |
| 538 | return different; |
| 539 | } |
| 540 | |
| 541 | |
| 542 | /* Returns the afs_cb_interface inxex which best matches address. |
| 543 | * If none is found, we return -1. |
| 544 | */ |
| 545 | afs_int32 |
| 546 | rxi_Findcbi(afs_uint32 addr) |
| 547 | { |
| 548 | int j; |
| 549 | afs_uint32 myAddr, thisAddr, netMask, subnetMask; |
| 550 | afs_int32 rvalue = -1; |
| 551 | int match_value = 0; |
| 552 | |
| 553 | if (numMyNetAddrs == 0) |
| 554 | (void)rxi_GetcbiInfo(); |
| 555 | |
| 556 | myAddr = ntohl(addr)(__builtin_constant_p(addr) ? ((((__uint32_t)(addr)) >> 24) | ((((__uint32_t)(addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(addr)) & (0xff << 8)) << 8) | (((__uint32_t)(addr)) << 24)) : __bswap32_var(addr )); |
| 557 | |
| 558 | if (IN_CLASSA(myAddr)(((u_int32_t)(myAddr) & 0x80000000) == 0)) |
| 559 | netMask = IN_CLASSA_NET0xff000000; |
| 560 | else if (IN_CLASSB(myAddr)(((u_int32_t)(myAddr) & 0xc0000000) == 0x80000000)) |
| 561 | netMask = IN_CLASSB_NET0xffff0000; |
| 562 | else if (IN_CLASSC(myAddr)(((u_int32_t)(myAddr) & 0xe0000000) == 0xc0000000)) |
| 563 | netMask = IN_CLASSC_NET0xffffff00; |
| 564 | else |
| 565 | netMask = 0; |
| 566 | |
| 567 | for (j = 0; j < afs_cb_interface.numberOfInterfaces; j++) { |
| 568 | thisAddr = ntohl(afs_cb_interface.addr_in[j])(__builtin_constant_p(afs_cb_interface.addr_in[j]) ? ((((__uint32_t )(afs_cb_interface.addr_in[j])) >> 24) | ((((__uint32_t )(afs_cb_interface.addr_in[j])) & (0xff << 16)) >> 8) | ((((__uint32_t)(afs_cb_interface.addr_in[j])) & (0xff << 8)) << 8) | (((__uint32_t)(afs_cb_interface.addr_in [j])) << 24)) : __bswap32_var(afs_cb_interface.addr_in[ j])); |
| 569 | subnetMask = ntohl(afs_cb_interface.subnetmask[j])(__builtin_constant_p(afs_cb_interface.subnetmask[j]) ? ((((__uint32_t )(afs_cb_interface.subnetmask[j])) >> 24) | ((((__uint32_t )(afs_cb_interface.subnetmask[j])) & (0xff << 16)) >> 8) | ((((__uint32_t)(afs_cb_interface.subnetmask[j])) & ( 0xff << 8)) << 8) | (((__uint32_t)(afs_cb_interface .subnetmask[j])) << 24)) : __bswap32_var(afs_cb_interface .subnetmask[j])); |
| 570 | if ((myAddr & netMask) == (thisAddr & netMask)) { |
| 571 | if ((myAddr & subnetMask) == (thisAddr & subnetMask)) { |
| 572 | if (myAddr == thisAddr) { |
| 573 | match_value = 4; |
Value stored to 'match_value' is never read | |
| 574 | rvalue = j; |
| 575 | break; |
| 576 | } |
| 577 | if (match_value < 3) { |
| 578 | match_value = 3; |
| 579 | rvalue = j; |
| 580 | } |
| 581 | } else { |
| 582 | if (match_value < 2) { |
| 583 | match_value = 2; |
| 584 | rvalue = j; |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | return (rvalue); |
| 591 | } |
| 592 | |
| 593 | #else /* AFS_USERSPACE_IP_ADDR */ |
| 594 | |
| 595 | #if !defined(AFS_AIX41_ENV) && !defined(AFS_DUX40_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) |
| 596 | #define IFADDR2SA(f) (&((f)->ifa_addr)) |
| 597 | #else /* AFS_AIX41_ENV */ |
| 598 | #define IFADDR2SA(f) ((f)->ifa_addr) |
| 599 | #endif |
| 600 | |
| 601 | int |
| 602 | rxi_GetIFInfo(void) |
| 603 | { |
| 604 | int i = 0; |
| 605 | int different = 0; |
| 606 | |
| 607 | int rxmtu, maxmtu; |
| 608 | afs_uint32 addrs[ADDRSPERSITE16]; |
| 609 | int mtus[ADDRSPERSITE16]; |
| 610 | afs_uint32 ifinaddr; |
| 611 | #if defined(AFS_DARWIN80_ENV) |
| 612 | errno_t t; |
| 613 | unsigned int count; |
| 614 | int cnt=0, m, j; |
| 615 | rx_ifaddr_tstruct usr_ifaddr * *ifads; |
| 616 | rx_ifnet_tstruct usr_ifnet * *ifns; |
| 617 | struct sockaddr sout; |
| 618 | struct sockaddr_in *sin; |
| 619 | struct in_addr pin; |
| 620 | #else |
| 621 | rx_ifaddr_tstruct usr_ifaddr * ifad; /* ifnet points to a if_addrlist of ifaddrs */ |
| 622 | rx_ifnet_tstruct usr_ifnet * ifn; |
| 623 | #endif |
| 624 | |
| 625 | memset(addrs, 0, sizeof(addrs)); |
| 626 | memset(mtus, 0, sizeof(mtus)); |
| 627 | |
| 628 | #if defined(AFS_DARWIN80_ENV) |
| 629 | if (!ifnet_list_get(AF_INET2, &ifns, &count)) { |
| 630 | for (m = 0; m < count; m++) { |
| 631 | if (!ifnet_get_address_list(ifns[m], &ifads)) { |
| 632 | for (j = 0; ifads[j] != NULL((void *)0) && cnt < ADDRSPERSITE16; j++) { |
| 633 | if ((t = ifaddr_address(ifads[j], &sout, sizeof(struct sockaddr))) == 0) { |
| 634 | sin = (struct sockaddr_in *)&sout; |
| 635 | rxmtu = rx_ifnet_mtu(rx_ifaddr_ifnet(ifads[j]))((ifads[j]?(ifads[j])->ifa_ifp:0))->if_mtu - RX_IPUDP_SIZE; |
| 636 | ifinaddr = ntohl(sin->sin_addr.s_addr)(__builtin_constant_p(sin->sin_addr.s_addr) ? ((((__uint32_t )(sin->sin_addr.s_addr)) >> 24) | ((((__uint32_t)(sin ->sin_addr.s_addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(sin->sin_addr.s_addr)) & (0xff << 8)) << 8) | (((__uint32_t)(sin->sin_addr.s_addr)) << 24)) : __bswap32_var(sin->sin_addr.s_addr)); |
| 637 | if (myNetAddrs[i] != ifinaddr) { |
| 638 | different++; |
| 639 | } |
| 640 | mtus[i] = rxmtu; |
| 641 | rxmtu = rxi_AdjustIfMTU(rxmtu); |
| 642 | maxmtu = |
| 643 | rxmtu * rxi_nRecvFrags + |
| 644 | ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE8); |
| 645 | maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu); |
| 646 | addrs[i++] = ifinaddr; |
| 647 | if (!rx_IsLoopbackAddr(ifinaddr) && |
| 648 | (maxmtu > rx_maxReceiveSize)) { |
| 649 | rx_maxReceiveSize = |
| 650 | MIN(RX_MAX_PACKET_SIZE, maxmtu)(((16384)<(maxmtu))?(16384):(maxmtu)); |
| 651 | rx_maxReceiveSize = |
| 652 | MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser)(((rx_maxReceiveSize)<(rx_maxReceiveSizeUser))?(rx_maxReceiveSize ):(rx_maxReceiveSizeUser)); |
| 653 | } |
| 654 | cnt++; |
| 655 | } |
| 656 | } |
| 657 | ifnet_free_address_list(ifads); |
| 658 | } |
| 659 | } |
| 660 | ifnet_list_free(ifns); |
| 661 | } |
| 662 | #else |
| 663 | #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) |
| 664 | #if defined(AFS_FBSD80_ENV) |
| 665 | TAILQ_FOREACH(ifn, &V_ifnet, if_link)for ((ifn) = (((&V_ifnet))->tqh_first); (ifn); (ifn) = (((ifn))->if_link.tqe_next)) { |
| 666 | #else |
| 667 | TAILQ_FOREACH(ifn, &ifnet, if_link)for ((ifn) = (((&usr_ifnet))->tqh_first); (ifn); (ifn) = (((ifn))->if_link.tqe_next)) { |
| 668 | #endif |
| 669 | if (i >= ADDRSPERSITE16) |
| 670 | break; |
| 671 | #elif defined(AFS_OBSD_ENV) || defined(AFS_NBSD_ENV) |
| 672 | for (ifn = ifnetusr_ifnet.tqh_first; i < ADDRSPERSITE16 && ifn != NULL((void *)0); |
| 673 | ifn = ifn->if_list.tqe_next) { |
| 674 | #else |
| 675 | for (ifn = ifnetusr_ifnet; ifn != NULL((void *)0) && i < ADDRSPERSITE16; ifn = ifn->if_next) { |
| 676 | #endif |
| 677 | rxmtu = (ifn->if_mtu - RX_IPUDP_SIZE); |
| 678 | #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) |
| 679 | TAILQ_FOREACH(ifad, &ifn->if_addrhead, ifa_link)for ((ifad) = (((&ifn->if_addrhead))->tqh_first); ( ifad); (ifad) = (((ifad))->ifa_link.tqe_next)) { |
| 680 | if (i >= ADDRSPERSITE16) |
| 681 | break; |
| 682 | #elif defined(AFS_OBSD_ENV) || defined(AFS_NBSD_ENV) |
| 683 | for (ifad = ifn->if_addrlist.tqh_first; |
| 684 | ifad != NULL((void *)0) && i < ADDRSPERSITE16; |
| 685 | ifad = ifad->ifa_list.tqe_next) { |
| 686 | #else |
| 687 | for (ifad = ifn->if_addrlist; ifad != NULL((void *)0) && i < ADDRSPERSITE16; |
| 688 | ifad = ifad->ifa_next) { |
| 689 | #endif |
| 690 | if (IFADDR2SA(ifad)->sa_family == AF_INET2) { |
| 691 | ifinaddr = |
| 692 | ntohl(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr.(__builtin_constant_p(((struct sockaddr_in *)IFADDR2SA(ifad)) ->sin_addr. s_addr) ? ((((__uint32_t)(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr. s_addr)) >> 24) | ((( (__uint32_t)(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr . s_addr)) & (0xff << 16)) >> 8) | ((((__uint32_t )(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr. s_addr )) & (0xff << 8)) << 8) | (((__uint32_t)(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr. s_addr)) << 24)) : __bswap32_var(((struct sockaddr_in *)IFADDR2SA(ifad)) ->sin_addr. s_addr)) |
| 693 | s_addr)(__builtin_constant_p(((struct sockaddr_in *)IFADDR2SA(ifad)) ->sin_addr. s_addr) ? ((((__uint32_t)(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr. s_addr)) >> 24) | ((( (__uint32_t)(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr . s_addr)) & (0xff << 16)) >> 8) | ((((__uint32_t )(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr. s_addr )) & (0xff << 8)) << 8) | (((__uint32_t)(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr. s_addr)) << 24)) : __bswap32_var(((struct sockaddr_in *)IFADDR2SA(ifad)) ->sin_addr. s_addr)); |
| 694 | if (myNetAddrs[i] != ifinaddr) { |
| 695 | different++; |
| 696 | } |
| 697 | mtus[i] = rxmtu; |
| 698 | rxmtu = rxi_AdjustIfMTU(rxmtu); |
| 699 | maxmtu = |
| 700 | rxmtu * rxi_nRecvFrags + |
| 701 | ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE8); |
| 702 | maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu); |
| 703 | addrs[i++] = ifinaddr; |
| 704 | if (!rx_IsLoopbackAddr(ifinaddr) && (maxmtu > rx_maxReceiveSize)) { |
| 705 | rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu)(((16384)<(maxmtu))?(16384):(maxmtu)); |
| 706 | rx_maxReceiveSize = |
| 707 | MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser)(((rx_maxReceiveSize)<(rx_maxReceiveSizeUser))?(rx_maxReceiveSize ):(rx_maxReceiveSizeUser)); |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | #endif |
| 713 | |
| 714 | rx_maxJumboRecvSize = |
| 715 | RX_HEADER_SIZEsizeof (struct rx_header) + rxi_nDgramPackets * RX_JUMBOBUFFERSIZE1412 + |
| 716 | (rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE4; |
| 717 | rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize)(((rx_maxJumboRecvSize)>(rx_maxReceiveSize))?(rx_maxJumboRecvSize ):(rx_maxReceiveSize)); |
| 718 | |
| 719 | if (different) { |
| 720 | int l; |
| 721 | for (l = 0; l < i; l++) { |
| 722 | myNetMTUs[l] = mtus[l]; |
| 723 | myNetAddrs[l] = addrs[l]; |
| 724 | } |
| 725 | } |
| 726 | return different; |
| 727 | } |
| 728 | |
| 729 | #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) |
| 730 | /* Returns ifnet which best matches address */ |
| 731 | rx_ifnet_tstruct usr_ifnet * |
| 732 | rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp) |
| 733 | { |
| 734 | struct sockaddr_in s, sr; |
| 735 | rx_ifaddr_tstruct usr_ifaddr * ifad; |
| 736 | |
| 737 | s.sin_family = AF_INET2; |
| 738 | s.sin_addr.s_addr = addr; |
| 739 | ifad = rx_ifaddr_withnet((struct sockaddr *)&s)ifa_ifwithnet((struct sockaddr *)&s); |
| 740 | |
| 741 | if (ifad && maskp) { |
| 742 | rx_ifaddr_netmask(ifad, (struct sockaddr *)&sr, sizeof(sr))memcpy((struct sockaddr *)&sr, (ifad)->ifa_netmask, sizeof (sr)); |
| 743 | *maskp = sr.sin_addr.s_addr; |
| 744 | } |
| 745 | return (ifad ? rx_ifaddr_ifnet(ifad)(ifad?(ifad)->ifa_ifp:0) : NULL((void *)0)); |
| 746 | } |
| 747 | |
| 748 | #else /* DARWIN || XBSD */ |
| 749 | |
| 750 | /* Returns ifnet which best matches address */ |
| 751 | rx_ifnet_tstruct usr_ifnet * |
| 752 | rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp) |
| 753 | { |
| 754 | int match_value = 0; |
| 755 | extern struct in_ifaddrusr_in_ifaddr *in_ifaddrusr_in_ifaddr; |
| 756 | struct in_ifaddrusr_in_ifaddr *ifa, *ifad = NULL((void *)0); |
| 757 | |
| 758 | addr = ntohl(addr)(__builtin_constant_p(addr) ? ((((__uint32_t)(addr)) >> 24) | ((((__uint32_t)(addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(addr)) & (0xff << 8)) << 8) | (((__uint32_t)(addr)) << 24)) : __bswap32_var(addr )); |
| 759 | |
| 760 | #if defined(AFS_DARWIN_ENV) |
| 761 | for (ifa = TAILQ_FIRST(&in_ifaddrhead)((&in_ifaddrhead)->tqh_first); ifa; |
| 762 | ifa = TAILQ_NEXT(ifa, ia_link)((ifa)->ia_link.tqe_next)) { |
| 763 | #else |
| 764 | for (ifa = in_ifaddrusr_in_ifaddr; ifa; ifa = ifa->ia_next) { |
| 765 | #endif |
| 766 | if ((addr & ifa->ia_netmask) == ifa->ia_net) { |
| 767 | if ((addr & ifa->ia_subnetmask) == ifa->ia_subnet) { |
| 768 | if (IA_SIN(ifa)(&(ifa)->ia_addr)->sin_addr.s_addr == addr) { /* ie, ME!!! */ |
| 769 | match_value = 4; |
| 770 | ifad = ifa; |
| 771 | goto done; |
| 772 | } |
| 773 | if (match_value < 3) { |
| 774 | ifad = ifa; |
| 775 | match_value = 3; |
| 776 | } |
| 777 | } else { |
| 778 | if (match_value < 2) { |
| 779 | ifad = ifa; |
| 780 | match_value = 2; |
| 781 | } |
| 782 | } |
| 783 | } /* if net matches */ |
| 784 | } /* for all in_ifaddrs */ |
| 785 | |
| 786 | done: |
| 787 | if (ifad && maskp) |
| 788 | *maskp = ifad->ia_subnetmask; |
| 789 | return (ifad ? ifad->ia_ifp : NULL((void *)0)); |
| 790 | } |
| 791 | #endif /* else DARWIN || XBSD */ |
| 792 | #endif /* else AFS_USERSPACE_IP_ADDR */ |
| 793 | #endif /* !SUN5 && !SGI62 */ |
| 794 | |
| 795 | |
| 796 | /* rxk_NewSocket, rxk_FreeSocket and osi_NetSend are from the now defunct |
| 797 | * afs_osinet.c. One could argue that rxi_NewSocket could go into the |
| 798 | * system specific subdirectories for all systems. But for the moment, |
| 799 | * most of it is simple to follow common code. |
| 800 | */ |
| 801 | #if !defined(UKERNEL1) |
| 802 | #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) |
| 803 | /* rxk_NewSocket creates a new socket on the specified port. The port is |
| 804 | * in network byte order. |
| 805 | */ |
| 806 | osi_socket * |
| 807 | rxk_NewSocketHost(afs_uint32 ahost, short aport) |
| 808 | { |
| 809 | afs_int32 code; |
| 810 | #ifdef AFS_DARWIN80_ENV |
| 811 | socket_t newSocket; |
| 812 | #else |
| 813 | struct socketusr_socket *newSocket; |
| 814 | #endif |
| 815 | #if (!defined(AFS_HPUX1122_ENV) && !defined(AFS_FBSD_ENV)) |
| 816 | struct mbuf *nam; |
| 817 | #endif |
| 818 | struct sockaddr_in myaddr; |
| 819 | #ifdef AFS_HPUX110_ENV |
| 820 | /* prototype copied from kernel source file streams/str_proto.h */ |
| 821 | extern MBLKP allocb_wait(int, int); |
| 822 | MBLKP bindnam; |
| 823 | int addrsize = sizeof(struct sockaddr_in); |
| 824 | struct fileusr_file *fp; |
| 825 | extern struct fileopsusr_fileops socketops; |
| 826 | #endif |
| 827 | #ifdef AFS_SGI65_ENV |
| 828 | bhv_desc_t bhv; |
| 829 | #endif |
| 830 | |
| 831 | AFS_STATCNT(osi_NewSocket)((afs_cmstats.callInfo.C_osi_NewSocket)++); |
| 832 | #if (defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)) && defined(KERNEL_FUNNEL) |
| 833 | thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL); |
| 834 | #endif |
| 835 | AFS_ASSERT_GLOCK()do { if (!(pthread_self() == afs_global_owner)) { osi_Panic("afs global lock not held" ); } } while(0); |
| 836 | AFS_GUNLOCK()do { do { if (!(pthread_self() == afs_global_owner)) { osi_Panic ("afs global lock not held"); } } while(0); memset(&afs_global_owner , 0, sizeof(pthread_t)); do{if (!(pthread_mutex_unlock(&afs_global_lock ) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c" , 836);}while(0); } while(0); |
| 837 | #if defined(AFS_HPUX102_ENV) |
| 838 | #if defined(AFS_HPUX110_ENV) |
| 839 | /* we need a file associated with the socket so sosend in NetSend |
| 840 | * will not fail */ |
| 841 | /* blocking socket */ |
| 842 | code = socreate(AF_INET2, &newSocket, SOCK_DGRAM2, 0, 0); |
| 843 | fp = falloc(); |
| 844 | if (!fp) |
| 845 | goto bad; |
| 846 | fp->f_flag = FREAD0x0001 | FWRITE0x0800; |
| 847 | fp->f_type = DTYPE_SOCKET2; |
| 848 | fp->f_ops = &socketops; |
| 849 | |
| 850 | fp->f_data = (void *)newSocket; |
| 851 | newSocket->so_fp = (void *)fp; |
| 852 | |
| 853 | #else /* AFS_HPUX110_ENV */ |
| 854 | code = socreate(AF_INET2, &newSocket, SOCK_DGRAM2, 0, SS_NOWAIT); |
| 855 | #endif /* else AFS_HPUX110_ENV */ |
| 856 | #elif defined(AFS_SGI65_ENV) || defined(AFS_OBSD_ENV) |
| 857 | code = socreate(AF_INET2, &newSocket, SOCK_DGRAM2, IPPROTO_UDP17); |
| 858 | #elif defined(AFS_FBSD_ENV) |
| 859 | code = socreate(AF_INET2, &newSocket, SOCK_DGRAM2, IPPROTO_UDP17, |
| 860 | afs_osi_credp, curthread); |
| 861 | #elif defined(AFS_DARWIN80_ENV) |
| 862 | #ifdef RXK_LISTENER_ENV1 |
| 863 | code = sock_socket(AF_INET2, SOCK_DGRAM2, IPPROTO_UDP17, NULL((void *)0), NULL((void *)0), &newSocket); |
| 864 | #else |
| 865 | code = sock_socket(AF_INET2, SOCK_DGRAM2, IPPROTO_UDP17, rx_upcall, NULL((void *)0), &newSocket); |
| 866 | #endif |
| 867 | #elif defined(AFS_NBSD50_ENV) |
| 868 | code = socreate(AF_INET2, &newSocket, SOCK_DGRAM2, 0, osi_curproc(), NULL((void *)0)); |
| 869 | #elif defined(AFS_NBSD40_ENV) |
| 870 | code = socreate(AF_INET2, &newSocket, SOCK_DGRAM2, 0, osi_curproc()); |
| 871 | #else |
| 872 | code = socreate(AF_INET2, &newSocket, SOCK_DGRAM2, 0); |
| 873 | #endif /* AFS_HPUX102_ENV */ |
| 874 | if (code) |
| 875 | goto bad; |
| 876 | |
| 877 | memset(&myaddr, 0, sizeof myaddr); |
| 878 | myaddr.sin_family = AF_INET2; |
| 879 | myaddr.sin_port = aport; |
| 880 | myaddr.sin_addr.s_addr = ahost; |
| 881 | #ifdef STRUCT_SOCKADDR_HAS_SA_LEN1 |
| 882 | myaddr.sin_len = sizeof(myaddr); |
| 883 | #endif |
| 884 | |
| 885 | #ifdef AFS_HPUX110_ENV |
| 886 | bindnam = allocb_wait((addrsize + SO_MSGOFFSET + 1), BPRI_MED); |
| 887 | if (!bindnam) { |
| 888 | setuerror(ENOBUFS)get_user_struct()->u_error = (55); |
| 889 | goto bad; |
| 890 | } |
| 891 | memcpy((caddr_t) bindnam->b_rptr + SO_MSGOFFSET, (caddr_t) & myaddr, |
| 892 | addrsize); |
| 893 | bindnam->b_wptr = bindnam->b_rptr + (addrsize + SO_MSGOFFSET + 1); |
| 894 | #if defined(AFS_NBSD40_ENV) |
| 895 | code = sobind(newSocket, bindnam, addrsize, osi_curproc()); |
| 896 | #else |
| 897 | code = sobind(newSocket, bindnam, addrsize); |
| 898 | #endif |
| 899 | if (code) { |
| 900 | soclose(newSocket); |
| 901 | #if !defined(AFS_HPUX1122_ENV) |
| 902 | m_freemusr_m_freem(nam); |
| 903 | #endif |
| 904 | goto bad; |
| 905 | } |
| 906 | |
| 907 | freeb(bindnam); |
| 908 | #else /* AFS_HPUX110_ENV */ |
| 909 | #if defined(AFS_DARWIN80_ENV) |
| 910 | { |
| 911 | int buflen = 50000; |
| 912 | int i,code2; |
| 913 | for (i=0;i<2;i++) { |
| 914 | code = sock_setsockopt(newSocket, SOL_SOCKET0xffff, SO_SNDBUF0x1001, |
| 915 | &buflen, sizeof(buflen)); |
| 916 | code2 = sock_setsockopt(newSocket, SOL_SOCKET0xffff, SO_RCVBUF0x1002, |
| 917 | &buflen, sizeof(buflen)); |
| 918 | if (!code && !code2) |
| 919 | break; |
| 920 | if (i == 2) |
| 921 | osi_Panic("osi_NewSocket: last attempt to reserve 32K failed!\n"); |
| 922 | buflen = 32766; |
| 923 | } |
| 924 | } |
| 925 | #else |
| 926 | #if defined(AFS_NBSD_ENV) |
| 927 | solock(newSocket); |
| 928 | #endif |
| 929 | code = soreserve(newSocket, 50000, 50000); |
| 930 | if (code) { |
| 931 | code = soreserve(newSocket, 32766, 32766); |
| 932 | if (code) |
| 933 | osi_Panic("osi_NewSocket: last attempt to reserve 32K failed!\n"); |
| 934 | } |
| 935 | #if defined(AFS_NBSD_ENV) |
| 936 | sounlock(newSocket); |
| 937 | #endif |
| 938 | #endif |
| 939 | #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) |
| 940 | #if defined(AFS_FBSD_ENV) |
| 941 | code = sobind(newSocket, (struct sockaddr *)&myaddr, curthread); |
| 942 | #else |
| 943 | code = sobind(newSocket, (struct sockaddr *)&myaddr); |
| 944 | #endif |
| 945 | if (code) { |
| 946 | dpf(("sobind fails (%d)\n", (int)code)); |
| 947 | soclose(newSocket); |
| 948 | goto bad; |
| 949 | } |
| 950 | #else /* defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) */ |
| 951 | #ifdef AFS_OSF_ENV |
| 952 | nam = m_getclr(M_WAIT, MT_SONAME); |
| 953 | #else /* AFS_OSF_ENV */ |
| 954 | nam = m_get(M_WAIT, MT_SONAME); |
| 955 | #endif |
| 956 | if (nam == NULL((void *)0)) { |
| 957 | #if defined(KERNEL_HAVE_UERROR) |
| 958 | setuerror(ENOBUFS)get_user_struct()->u_error = (55); |
| 959 | #endif |
| 960 | goto bad; |
| 961 | } |
| 962 | nam->m_len = sizeof(myaddr); |
| 963 | memcpy(mtod(nam, caddr_t)((caddr_t)((nam)->m_data)), &myaddr, sizeof(myaddr)); |
| 964 | #if defined(AFS_SGI65_ENV) |
| 965 | BHV_PDATA(&bhv) = (void *)newSocket; |
| 966 | code = sobind(&bhv, nam); |
| 967 | m_freemusr_m_freem(nam); |
| 968 | #elif defined(AFS_OBSD44_ENV) || defined(AFS_NBSD40_ENV) |
| 969 | code = sobind(newSocket, nam, osi_curproc()); |
| 970 | #else |
| 971 | code = sobind(newSocket, nam); |
| 972 | #endif |
| 973 | if (code) { |
| 974 | dpf(("sobind fails (%d)\n", (int)code)); |
| 975 | soclose(newSocket); |
| 976 | #ifndef AFS_SGI65_ENV |
| 977 | m_freemusr_m_freem(nam); |
| 978 | #endif |
| 979 | goto bad; |
| 980 | } |
| 981 | #endif /* else AFS_DARWIN_ENV */ |
| 982 | #endif /* else AFS_HPUX110_ENV */ |
| 983 | |
| 984 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 984);}while(0); afs_global_owner = pthread_self(); } while(0 ); |
| 985 | #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL) |
| 986 | thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL); |
| 987 | #endif |
| 988 | return (osi_socket *)newSocket; |
| 989 | |
| 990 | bad: |
| 991 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 991);}while(0); afs_global_owner = pthread_self(); } while(0 ); |
| 992 | #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL) |
| 993 | thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL); |
| 994 | #endif |
| 995 | return (osi_socket *)0; |
| 996 | } |
| 997 | |
| 998 | osi_socket * |
| 999 | rxk_NewSocket(short aport) |
| 1000 | { |
| 1001 | return rxk_NewSocketHost(0, aport); |
| 1002 | } |
| 1003 | |
| 1004 | /* free socket allocated by rxk_NewSocket */ |
| 1005 | int |
| 1006 | rxk_FreeSocket(struct socketusr_socket *asocket) |
| 1007 | { |
| 1008 | AFS_STATCNT(osi_FreeSocket)((afs_cmstats.callInfo.C_osi_FreeSocket)++); |
| 1009 | #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL) |
| 1010 | thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL); |
| 1011 | #endif |
| 1012 | #ifdef AFS_HPUX110_ENV |
| 1013 | if (asocket->so_fp) { |
| 1014 | struct fileusr_file *fp = asocket->so_fp; |
| 1015 | #if !defined(AFS_HPUX1123_ENV) |
| 1016 | /* 11.23 still has falloc, but not FPENTRYFREE ! |
| 1017 | * so for now if we shutdown, we will waist a file |
| 1018 | * structure */ |
| 1019 | FPENTRYFREE(fp); |
| 1020 | asocket->so_fp = NULL((void *)0); |
| 1021 | #endif |
| 1022 | } |
| 1023 | #endif /* AFS_HPUX110_ENV */ |
| 1024 | soclose(asocket); |
| 1025 | #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL) |
| 1026 | thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL); |
| 1027 | #endif |
| 1028 | return 0; |
| 1029 | } |
| 1030 | #endif /* !SUN5 && !LINUX20 */ |
| 1031 | |
| 1032 | #if defined(RXK_LISTENER_ENV1) || defined(AFS_SUN5_ENV) || defined(RXK_UPCALL_ENV) |
| 1033 | #ifdef RXK_TIMEDSLEEP_ENV |
| 1034 | /* Shutting down should wake us up, as should an earlier event. */ |
| 1035 | void |
| 1036 | rxi_ReScheduleEvents0(void) |
| 1037 | { |
| 1038 | /* needed to allow startup */ |
| 1039 | int glock = ISAFS_GLOCK()(pthread_self() == afs_global_owner); |
| 1040 | if (!glock) |
| 1041 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 1041);}while(0); afs_global_owner = pthread_self(); } while( 0); |
| 1042 | osi_rxWakeup(&afs_termState)if (afs_osi_Wakeup(&afs_termState) == 0) (((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event2(afs_iclSetp , (701087898L), (1<<24)+((4)<<18)+((7)<<12) , (long)("/home/wollman/openafs/src/rx/rx_kcommon.c"), (long) (1042)) : 0); |
| 1043 | if (!glock) |
| 1044 | AFS_GUNLOCK()do { do { if (!(pthread_self() == afs_global_owner)) { osi_Panic ("afs global lock not held"); } } while(0); memset(&afs_global_owner , 0, sizeof(pthread_t)); do{if (!(pthread_mutex_unlock(&afs_global_lock ) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c" , 1044);}while(0); } while(0); |
| 1045 | } |
| 1046 | #endif |
| 1047 | /* |
| 1048 | * Run RX event daemon every second (5 times faster than rest of systems) |
| 1049 | */ |
| 1050 | void |
| 1051 | afs_rxevent_daemon(void) |
| 1052 | { |
| 1053 | struct clock temp; |
| 1054 | SPLVAR; |
| 1055 | |
| 1056 | while (1) { |
| 1057 | #ifdef RX_ENABLE_LOCKS1 |
| 1058 | AFS_GUNLOCK()do { do { if (!(pthread_self() == afs_global_owner)) { osi_Panic ("afs global lock not held"); } } while(0); memset(&afs_global_owner , 0, sizeof(pthread_t)); do{if (!(pthread_mutex_unlock(&afs_global_lock ) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c" , 1058);}while(0); } while(0); |
| 1059 | #endif /* RX_ENABLE_LOCKS */ |
| 1060 | NETPRI; |
| 1061 | rxevent_RaiseEvents(&temp); |
| 1062 | USERPRI; |
| 1063 | #ifdef RX_ENABLE_LOCKS1 |
| 1064 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 1064);}while(0); afs_global_owner = pthread_self(); } while( 0); |
| 1065 | #endif /* RX_ENABLE_LOCKS */ |
| 1066 | #ifdef RX_KERNEL_TRACE |
| 1067 | afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("before afs_osi_Wait()")) : 0) |
| 1068 | "before afs_osi_Wait()")(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("before afs_osi_Wait()")) : 0); |
| 1069 | #endif |
| 1070 | #ifdef RXK_TIMEDSLEEP_ENV |
| 1071 | afs_osi_TimedSleep(&afs_termState, MAX(500, ((temp.sec * 1000) +(((500)>(((temp.sec * 1000) + (temp.usec / 1000))))?(500): (((temp.sec * 1000) + (temp.usec / 1000)))) |
| 1072 | (temp.usec / 1000)))(((500)>(((temp.sec * 1000) + (temp.usec / 1000))))?(500): (((temp.sec * 1000) + (temp.usec / 1000)))), 0); |
| 1073 | #else |
| 1074 | afs_osi_Wait(500, NULL((void *)0), 0); |
| 1075 | #endif |
| 1076 | #ifdef RX_KERNEL_TRACE |
| 1077 | afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("after afs_osi_Wait()")) : 0) |
| 1078 | "after afs_osi_Wait()")(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("after afs_osi_Wait()")) : 0); |
| 1079 | #endif |
| 1080 | if (afs_termState == AFSOP_STOP_RXEVENT214) { |
| 1081 | #ifdef RXK_LISTENER_ENV1 |
| 1082 | afs_termState = AFSOP_STOP_RXK_LISTENER217; |
| 1083 | #elif defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV) |
| 1084 | afs_termState = AFSOP_STOP_NETIF219; |
| 1085 | #else |
| 1086 | afs_termState = AFSOP_STOP_COMPLETE215; |
| 1087 | #endif |
| 1088 | osi_rxWakeup(&afs_termState)if (afs_osi_Wakeup(&afs_termState) == 0) (((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event2(afs_iclSetp , (701087898L), (1<<24)+((4)<<18)+((7)<<12) , (long)("/home/wollman/openafs/src/rx/rx_kcommon.c"), (long) (1088)) : 0); |
| 1089 | return; |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | #endif |
| 1094 | |
| 1095 | #ifdef RXK_LISTENER_ENV1 |
| 1096 | |
| 1097 | /* rxk_ReadPacket returns 1 if valid packet, 0 on error. */ |
| 1098 | int |
| 1099 | rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port) |
| 1100 | { |
| 1101 | int code; |
| 1102 | struct sockaddr_in from; |
| 1103 | int nbytes; |
| 1104 | afs_int32 rlen; |
| 1105 | afs_int32 tlen; |
| 1106 | afs_int32 savelen; /* was using rlen but had aliasing problems */ |
| 1107 | rx_computelen(p, tlen){ unsigned int i; for (tlen=0, i=1; i < p->niovecs; i++ ) tlen += p->wirevec[i].iov_len; }; |
| 1108 | rx_SetDataSize(p, tlen)((p)->length = (tlen)); /* this is the size of the user data area */ |
| 1109 | |
| 1110 | tlen += RX_HEADER_SIZEsizeof (struct rx_header); /* now this is the size of the entire packet */ |
| 1111 | rlen = rx_maxJumboRecvSize; /* this is what I am advertising. Only check |
| 1112 | * it once in order to avoid races. */ |
| 1113 | tlen = rlen - tlen; |
| 1114 | if (tlen > 0) { |
| 1115 | tlen = rxi_AllocDataBuf(p, tlen, RX_PACKET_CLASS_RECV_CBUF3); |
| 1116 | if (tlen > 0) { |
| 1117 | tlen = rlen - tlen; |
| 1118 | } else |
| 1119 | tlen = rlen; |
| 1120 | } else |
| 1121 | tlen = rlen; |
| 1122 | |
| 1123 | /* add some padding to the last iovec, it's just to make sure that the |
| 1124 | * read doesn't return more data than we expect, and is done to get around |
| 1125 | * our problems caused by the lack of a length field in the rx header. */ |
| 1126 | savelen = p->wirevec[p->niovecs - 1].iov_len; |
| 1127 | p->wirevec[p->niovecs - 1].iov_len = savelen + RX_EXTRABUFFERSIZE4; |
| 1128 | |
| 1129 | nbytes = tlen + sizeof(afs_int32); |
| 1130 | #ifdef RX_KERNEL_TRACE |
| 1131 | if (ICL_SETACTIVE(afs_iclSetp)((afs_iclSetp) && (afs_iclSetp->states & 2))) { |
| 1132 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 1132);}while(0); afs_global_owner = pthread_self(); } while( 0); |
| 1133 | afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("before osi_NetRecive()")) : 0) |
| 1134 | "before osi_NetRecive()")(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("before osi_NetRecive()")) : 0); |
| 1135 | AFS_GUNLOCK()do { do { if (!(pthread_self() == afs_global_owner)) { osi_Panic ("afs global lock not held"); } } while(0); memset(&afs_global_owner , 0, sizeof(pthread_t)); do{if (!(pthread_mutex_unlock(&afs_global_lock ) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c" , 1135);}while(0); } while(0); |
| 1136 | } |
| 1137 | #endif |
| 1138 | code = osi_NetReceive(rx_socket, &from, p->wirevec, p->niovecs, &nbytes); |
| 1139 | |
| 1140 | #ifdef RX_KERNEL_TRACE |
| 1141 | if (ICL_SETACTIVE(afs_iclSetp)((afs_iclSetp) && (afs_iclSetp->states & 2))) { |
| 1142 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 1142);}while(0); afs_global_owner = pthread_self(); } while( 0); |
| 1143 | afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("after osi_NetRecive()")) : 0) |
| 1144 | "after osi_NetRecive()")(((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event1(afs_iclSetp, (701087896L), (1<<24)+((4) <<18), (long)("after osi_NetRecive()")) : 0); |
| 1145 | AFS_GUNLOCK()do { do { if (!(pthread_self() == afs_global_owner)) { osi_Panic ("afs global lock not held"); } } while(0); memset(&afs_global_owner , 0, sizeof(pthread_t)); do{if (!(pthread_mutex_unlock(&afs_global_lock ) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c" , 1145);}while(0); } while(0); |
| 1146 | } |
| 1147 | #endif |
| 1148 | /* restore the vec to its correct state */ |
| 1149 | p->wirevec[p->niovecs - 1].iov_len = savelen; |
| 1150 | |
| 1151 | if (!code) { |
| 1152 | p->length = nbytes - RX_HEADER_SIZEsizeof (struct rx_header);; |
| 1153 | if ((nbytes > tlen) || (p->length & 0x8000)) { /* Bogus packet */ |
| 1154 | if (nbytes <= 0) { |
| 1155 | if (rx_stats_active) { |
| 1156 | MUTEX_ENTER(&rx_stats_mutex)do{if (!(pthread_mutex_lock(&rx_stats_mutex) == 0)) AssertionFailed ("/home/wollman/openafs/src/rx/rx_kcommon.c", 1156);}while(0); |
| 1157 | rx_atomic_inc(&rx_stats.bogusPacketOnRead); |
| 1158 | rx_stats.bogusHost = from.sin_addr.s_addr; |
| 1159 | MUTEX_EXIT(&rx_stats_mutex)do{if (!(pthread_mutex_unlock(&rx_stats_mutex) == 0)) AssertionFailed ("/home/wollman/openafs/src/rx/rx_kcommon.c", 1159);}while(0); |
| 1160 | } |
| 1161 | dpf(("B: bogus packet from [%x,%d] nb=%d\n", |
| 1162 | from.sin_addr.s_addr, from.sin_port, nbytes)); |
| 1163 | } |
| 1164 | return -1; |
| 1165 | } else { |
| 1166 | /* Extract packet header. */ |
| 1167 | rxi_DecodePacketHeader(p); |
| 1168 | |
| 1169 | *host = from.sin_addr.s_addr; |
| 1170 | *port = from.sin_port; |
| 1171 | if (p->header.type > 0 && p->header.type < RX_N_PACKET_TYPES13) { |
| 1172 | if (rx_stats_active) { |
| 1173 | rx_atomic_inc(&rx_stats.packetsRead[p->header.type - 1]); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | #ifdef RX_TRIMDATABUFS |
| 1178 | /* Free any empty packet buffers at the end of this packet */ |
| 1179 | rxi_TrimDataBufs(p, 1); |
| 1180 | #endif |
| 1181 | return 0; |
| 1182 | } |
| 1183 | } else |
| 1184 | return code; |
| 1185 | } |
| 1186 | |
| 1187 | /* rxk_Listener() |
| 1188 | * |
| 1189 | * Listen for packets on socket. This thread is typically started after |
| 1190 | * rx_Init has called rxi_StartListener(), but nevertheless, ensures that |
| 1191 | * the start state is set before proceeding. |
| 1192 | * |
| 1193 | * Note that this thread is outside the AFS global lock for much of |
| 1194 | * it's existence. |
| 1195 | * |
| 1196 | * In many OS's, the socket receive code sleeps interruptibly. That's not what |
| 1197 | * we want here. So we need to either block all signals (including SIGKILL |
| 1198 | * and SIGSTOP) or reset the thread's signal state to unsignalled when the |
| 1199 | * OS's socket receive routine returns as a result of a signal. |
| 1200 | */ |
| 1201 | int rxk_ListenerPid; /* Used to signal process to wakeup at shutdown */ |
| 1202 | #ifdef AFS_LINUX20_ENV |
| 1203 | struct task_struct *rxk_ListenerTask; |
| 1204 | #endif |
| 1205 | |
| 1206 | void |
| 1207 | rxk_Listener(void) |
| 1208 | { |
| 1209 | struct rx_packet *rxp = NULL((void *)0); |
| 1210 | int code; |
| 1211 | int host, port; |
| 1212 | |
| 1213 | #ifdef AFS_LINUX20_ENV |
| 1214 | rxk_ListenerPid = current->pid; |
| 1215 | rxk_ListenerTask = current; |
| 1216 | #endif |
| 1217 | #ifdef AFS_SUN5_ENV |
| 1218 | rxk_ListenerPid = 1; /* No PID, just a flag that we're alive */ |
| 1219 | #endif /* AFS_SUN5_ENV */ |
| 1220 | #ifdef AFS_XBSD_ENV |
| 1221 | rxk_ListenerPid = curproc->p_pid; |
| 1222 | #endif /* AFS_FBSD_ENV */ |
| 1223 | #ifdef AFS_DARWIN80_ENV |
| 1224 | rxk_ListenerPid = proc_selfpid(); |
| 1225 | #elif defined(AFS_DARWIN_ENV) |
| 1226 | rxk_ListenerPid = current_proc()->p_pid; |
| 1227 | #endif |
| 1228 | #ifdef RX_ENABLE_LOCKS1 |
| 1229 | AFS_GUNLOCK()do { do { if (!(pthread_self() == afs_global_owner)) { osi_Panic ("afs global lock not held"); } } while(0); memset(&afs_global_owner , 0, sizeof(pthread_t)); do{if (!(pthread_mutex_unlock(&afs_global_lock ) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c" , 1229);}while(0); } while(0); |
| 1230 | #endif /* RX_ENABLE_LOCKS */ |
| 1231 | while (afs_termState != AFSOP_STOP_RXK_LISTENER217) { |
| 1232 | /* See if a check for additional packets was issued */ |
| 1233 | rx_CheckPackets(); |
| 1234 | |
| 1235 | if (rxp) { |
| 1236 | rxi_RestoreDataBufs(rxp); |
| 1237 | } else { |
| 1238 | rxp = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE0); |
| 1239 | if (!rxp) |
| 1240 | osi_Panic("rxk_Listener: No more Rx buffers!\n"); |
| 1241 | } |
| 1242 | if (!(code = rxk_ReadPacket(rx_socket, rxp, &host, &port))) { |
| 1243 | rxp = rxi_ReceivePacket(rxp, rx_socket, host, port, 0, 0); |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | #ifdef RX_ENABLE_LOCKS1 |
| 1248 | AFS_GLOCK()do { do{if (!(pthread_mutex_lock(&afs_global_lock) == 0)) AssertionFailed("/home/wollman/openafs/src/rx/rx_kcommon.c", 1248);}while(0); afs_global_owner = pthread_self(); } while( 0); |
| 1249 | #endif /* RX_ENABLE_LOCKS */ |
| 1250 | if (afs_termState == AFSOP_STOP_RXK_LISTENER217) { |
| 1251 | #ifdef AFS_SUN510_ENV |
| 1252 | afs_termState = AFSOP_STOP_NETIF219; |
| 1253 | #else |
| 1254 | afs_termState = AFSOP_STOP_COMPLETE215; |
| 1255 | #endif |
| 1256 | osi_rxWakeup(&afs_termState)if (afs_osi_Wakeup(&afs_termState) == 0) (((afs_iclSetp) && (afs_iclSetp->states & 2)) ? afs_icl_Event2(afs_iclSetp , (701087898L), (1<<24)+((4)<<18)+((7)<<12) , (long)("/home/wollman/openafs/src/rx/rx_kcommon.c"), (long) (1256)) : 0); |
| 1257 | } |
| 1258 | rxk_ListenerPid = 0; |
| 1259 | #ifdef AFS_LINUX20_ENV |
| 1260 | rxk_ListenerTask = 0; |
| 1261 | osi_rxWakeup(&rxk_ListenerTask)if (afs_osi_Wakeup(&rxk_ListenerTask) == 0) (((afs_iclSetp ) && (afs_iclSetp->states & 2)) ? afs_icl_Event2 (afs_iclSetp, (701087898L), (1<<24)+((4)<<18)+((7 )<<12), (long)("/home/wollman/openafs/src/rx/rx_kcommon.c" ), (long)(1261)) : 0); |
| 1262 | #endif |
| 1263 | #if defined(AFS_SUN5_ENV) || defined(AFS_FBSD_ENV) |
| 1264 | osi_rxWakeup(&rxk_ListenerPid)if (afs_osi_Wakeup(&rxk_ListenerPid) == 0) (((afs_iclSetp ) && (afs_iclSetp->states & 2)) ? afs_icl_Event2 (afs_iclSetp, (701087898L), (1<<24)+((4)<<18)+((7 )<<12), (long)("/home/wollman/openafs/src/rx/rx_kcommon.c" ), (long)(1264)) : 0); |
| 1265 | #endif |
| 1266 | } |
| 1267 | |
| 1268 | #if !defined(AFS_LINUX20_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) |
| 1269 | /* The manner of stopping the rx listener thread may vary. Most unix's should |
| 1270 | * be able to call soclose. |
| 1271 | */ |
| 1272 | void |
| 1273 | osi_StopListener(void) |
| 1274 | { |
| 1275 | soclose(rx_socket); |
| 1276 | } |
| 1277 | #endif |
| 1278 | #endif /* RXK_LISTENER_ENV */ |
| 1279 | #endif /* !NCR && !UKERNEL */ |
| 1280 | |
| 1281 | #if !defined(AFS_LINUX26_ENV) |
| 1282 | void |
| 1283 | #if defined(AFS_AIX_ENV) |
| 1284 | osi_Panic(char *msg, void *a1, void *a2, void *a3) |
| 1285 | #else |
| 1286 | osi_Panic(char *msg, ...) |
| 1287 | #endif |
| 1288 | { |
| 1289 | #ifdef AFS_AIX_ENV |
| 1290 | if (!msg) |
| 1291 | msg = "Unknown AFS panic"; |
| 1292 | /* |
| 1293 | * we should probably use the errsave facility here. it is not |
| 1294 | * varargs-aware |
| 1295 | */ |
| 1296 | |
| 1297 | printf(msg, a1, a2, a3); |
| 1298 | panic(msg)do{fprintf(__stderrp, "%s", msg);do{if (!(0)) AssertionFailed ("/home/wollman/openafs/src/rx/rx_kcommon.c", 1298);}while(0) ;}while(0); |
| 1299 | #elif defined(AFS_SGI_ENV) |
| 1300 | va_list ap; |
| 1301 | |
| 1302 | /* Solaris has vcmn_err, Sol10 01/06 may have issues. Beware. */ |
| 1303 | if (!msg) { |
| 1304 | cmn_err(CE_PANIC, "Unknown AFS panic"); |
| 1305 | } else { |
| 1306 | va_start(ap, msg)__builtin_va_start((ap), (msg)); |
| 1307 | icmn_err(CE_PANIC, msg, ap); |
| 1308 | va_end(ap)__builtin_va_end(ap); |
| 1309 | } |
| 1310 | #elif defined(AFS_DARWIN80_ENV) || (defined(AFS_LINUX22_ENV) && !defined(AFS_LINUX_26_ENV)) |
| 1311 | char bufusr_buf[256]; |
| 1312 | va_list ap; |
| 1313 | if (!msg) |
| 1314 | msg = "Unknown AFS panic"; |
| 1315 | |
| 1316 | va_start(ap, msg)__builtin_va_start((ap), (msg)); |
| 1317 | vsnprintf(bufusr_buf, sizeof(bufusr_buf), msg, ap); |
| 1318 | va_end(ap)__builtin_va_end(ap); |
| 1319 | printf("%s", bufusr_buf); |
| 1320 | panic(buf)do{fprintf(__stderrp, "%s", usr_buf);do{if (!(0)) AssertionFailed ("/home/wollman/openafs/src/rx/rx_kcommon.c", 1320);}while(0) ;}while(0); |
| 1321 | #else |
| 1322 | va_list ap; |
| 1323 | if (!msg) |
| 1324 | msg = "Unknown AFS panic"; |
| 1325 | |
| 1326 | va_start(ap, msg)__builtin_va_start((ap), (msg)); |
| 1327 | vprintf(msg, ap); |
| 1328 | va_end(ap)__builtin_va_end(ap); |
| 1329 | # ifdef AFS_LINUX20_ENV |
| 1330 | * ((char *) 0) = 0; |
| 1331 | # else |
| 1332 | panic(msg)do{fprintf(__stderrp, "%s", msg);do{if (!(0)) AssertionFailed ("/home/wollman/openafs/src/rx/rx_kcommon.c", 1332);}while(0) ;}while(0); |
| 1333 | # endif |
| 1334 | #endif |
| 1335 | } |
| 1336 | #endif |