2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * rx_knet.c - RX kernel send, receive and timer routines.
13 * Linux implementation.
15 #include "../afs/param.h"
16 #ifdef AFS_LINUX22_ENV
17 #include "../rx/rx_kcommon.h"
18 #if defined(AFS_LINUX24_ENV)
19 #include "../h/smp_lock.h"
21 #include <asm/uaccess.h>
24 * open and bind RX socket
26 struct osi_socket *rxk_NewSocket(short aport)
29 struct sockaddr_in myaddr;
33 code = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &sockp);
38 myaddr.sin_family = AF_INET;
39 myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
40 myaddr.sin_port = aport;
41 code = sockp->ops->bind(sockp, (struct sockaddr*)&myaddr, sizeof(myaddr));
44 #if defined(AFS_LINUX24_ENV)
45 printk("sock_release(rx_socket) FIXME\n");
52 return (struct osi_socket*)sockp;
56 /* free socket allocated by osi_NetSocket */
57 int rxk_FreeSocket(asocket)
58 register struct socket *asocket;
60 AFS_STATCNT(osi_FreeSocket);
71 int osi_NetSend(struct socket *sop, struct sockaddr_in *to,
72 struct iovec *iov, int iovcnt, int size, int istack)
77 struct iovec tmpvec[RX_MAXWVECS+2];
79 if (iovcnt > RX_MAXWVECS+2) {
80 osi_Panic("Too many (%d) iovecs passed to osi_NetSend\n", iovcnt);
83 if (iovcnt <= 2) { /* avoid pointless uiomove */
84 tmpvec[0].iov_base = iov[0].iov_base;
85 tmpvec[0].iov_len = size;
89 memcpy(tmpvec, iov, iovcnt * sizeof(struct iovec));
90 msg.msg_iovlen = iovcnt;
94 msg.msg_namelen = sizeof(*to);
95 msg.msg_control = NULL;
96 msg.msg_controllen = 0;
100 code = sock_sendmsg(sop, &msg, size);
102 return (code<0) ? code : 0;
107 * OS dependent part of kernel RX listener thread.
110 * so socket to receive on, typically rx_socket
111 * from pointer to a sockaddr_in.
112 * iov array of iovecs to fill in.
113 * iovcnt how many iovecs there are.
114 * lengthp IN/OUT in: total space available in iovecs. out: size of read.
118 * error code (such as EINTER) if not
121 * Note that the maximum number of iovecs is 2 + RX_MAXWVECS. This is
122 * so we have a little space to look for packets larger than
125 int rxk_lastSocketError;
126 int rxk_nSocketErrors;
127 int osi_NetReceive(osi_socket so, struct sockaddr_in *from,
128 struct iovec *iov, int iovcnt, int *lengthp)
133 struct iovec tmpvec[RX_MAXWVECS+2];
134 struct socket *sop = (struct socket*)so;
136 if (iovcnt > RX_MAXWVECS+2) {
137 osi_Panic("Too many (%d) iovecs passed to osi_NetReceive\n", iovcnt);
139 memcpy(tmpvec, iov, iovcnt * sizeof(struct iovec));
141 msg.msg_iov = tmpvec;
142 msg.msg_iovlen = iovcnt;
143 msg.msg_control = NULL;
144 msg.msg_controllen = 0;
148 code = sock_recvmsg(sop, &msg, *lengthp, 0);
152 /* Clear the error before using the socket again.
153 * Oh joy, Linux has hidden header files as well. It appears we can
154 * simply call again and have it clear itself via sock_error().
156 #ifdef AFS_LINUX22_ENV
157 flush_signals(current); /* We don't want no stinkin' signals. */
159 current->signal = 0; /* We don't want no stinkin' signals. */
161 rxk_lastSocketError = code;
162 rxk_nSocketErrors ++ ;
172 void osi_StopListener(void)
174 extern int (*sys_killp)();
175 extern int rxk_ListenerPid;
177 if (rxk_ListenerPid) {
178 (void) (*sys_killp)(rxk_ListenerPid, 9);
179 #ifdef AFS_LINUX24_ENV
180 afs_osi_Sleep(&rxk_ListenerPid);
185 sock_release(rx_socket);
189 #endif /* AFS_LINUX22_ENV */