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 <afsconfig.h>
16 #include "afs/param.h"
21 #include <linux/version.h>
22 #ifdef AFS_LINUX22_ENV
23 #include "rx/rx_kcommon.h"
24 #if defined(AFS_LINUX24_ENV)
25 #include "h/smp_lock.h"
27 #include <asm/uaccess.h>
30 * open and bind RX socket
33 rxk_NewSocketHost(afs_uint32 ahost, short aport)
36 struct sockaddr_in myaddr;
39 int pmtu = IP_PMTUDISC_DONT;
42 /* We need a better test for this. if you need it back, tell us
45 #ifdef LINUX_KERNEL_SOCK_CREATE_V
46 code = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &sockp, 0);
48 code = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &sockp);
54 myaddr.sin_family = AF_INET;
55 myaddr.sin_addr.s_addr = ahost;
56 myaddr.sin_port = aport;
58 sockp->ops->bind(sockp, (struct sockaddr *)&myaddr, sizeof(myaddr));
61 #if defined(AFS_LINUX24_ENV)
62 printk("sock_release(rx_socket) FIXME\n");
70 sockp->ops->setsockopt(sockp, SOL_IP, IP_MTU_DISCOVER, (char *)&pmtu,
73 return (osi_socket *)sockp;
77 rxk_NewSocket(short aport)
79 return rxk_NewSocketHost(htonl(INADDR_ANY), aport);
82 /* free socket allocated by osi_NetSocket */
84 rxk_FreeSocket(register struct socket *asocket)
86 AFS_STATCNT(osi_FreeSocket);
98 osi_NetSend(osi_socket sop, struct sockaddr_in *to, struct iovec *iovec,
99 int iovcnt, afs_int32 size, int istack)
105 msg.msg_iovlen = iovcnt;
108 msg.msg_namelen = sizeof(*to);
109 msg.msg_control = NULL;
110 msg.msg_controllen = 0;
114 code = sock_sendmsg(sop, &msg, size);
116 return (code < 0) ? code : 0;
121 * OS dependent part of kernel RX listener thread.
124 * so socket to receive on, typically rx_socket
125 * from pointer to a sockaddr_in.
126 * iov array of iovecs to fill in.
127 * iovcnt how many iovecs there are.
128 * lengthp IN/OUT in: total space available in iovecs. out: size of read.
132 * error code (such as EINTER) if not
135 * Note that the maximum number of iovecs is 2 + RX_MAXWVECS. This is
136 * so we have a little space to look for packets larger than
139 int rxk_lastSocketError;
140 int rxk_nSocketErrors;
142 osi_NetReceive(osi_socket so, struct sockaddr_in *from, struct iovec *iov,
143 int iovcnt, int *lengthp)
148 struct iovec tmpvec[RX_MAXWVECS + 2];
149 struct socket *sop = (struct socket *)so;
151 if (iovcnt > RX_MAXWVECS + 2) {
152 osi_Panic("Too many (%d) iovecs passed to osi_NetReceive\n", iovcnt);
154 memcpy(tmpvec, iov, iovcnt * sizeof(struct iovec));
156 msg.msg_iov = tmpvec;
157 msg.msg_iovlen = iovcnt;
158 msg.msg_control = NULL;
159 msg.msg_controllen = 0;
163 code = sock_recvmsg(sop, &msg, *lengthp, 0);
167 #ifdef AFS_LINUX26_ENV
171 current->flags & PF_FREEZE
173 #if defined(STRUCT_TASK_STRUCT_HAS_TODO)
176 test_ti_thread_flag(current->thread_info, TIF_FREEZE)
180 #ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
181 refrigerator(PF_FREEZE);
185 set_current_state(TASK_INTERRUPTIBLE);
189 /* Clear the error before using the socket again.
190 * Oh joy, Linux has hidden header files as well. It appears we can
191 * simply call again and have it clear itself via sock_error().
193 #ifdef AFS_LINUX22_ENV
194 flush_signals(current); /* We don't want no stinkin' signals. */
196 current->signal = 0; /* We don't want no stinkin' signals. */
198 rxk_lastSocketError = code;
207 extern rwlock_t tasklist_lock __attribute__((weak));
209 osi_StopListener(void)
211 struct task_struct *listener;
212 extern int rxk_ListenerPid;
215 read_lock(&tasklist_lock);
216 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
220 listener = find_task_by_pid(rxk_ListenerPid);
222 read_unlock(&tasklist_lock);
223 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
227 while (rxk_ListenerPid) {
228 flush_signals(listener);
229 force_sig(SIGKILL, listener);
230 afs_osi_Sleep(&rxk_ListenerPid);
232 sock_release(rx_socket);
236 #endif /* AFS_LINUX22_ENV */