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
10 #include <afsconfig.h>
11 #include "afs/param.h"
17 #include "rx/rx_kcommon.h"
22 #include "inet/common.h"
23 #include "sys/tiuser.h"
24 #include "sys/t_kuser.h"
25 #include "sys/stropts.h"
26 #include "sys/stream.h"
27 #include "sys/tihdr.h"
28 #include "sys/fcntl.h"
30 #include "netinet/ip6.h"
31 #define ipif_local_addr ipif_lcl_addr
33 #define V4_PART_OF_V6(v6) v6.s6_addr32[3]
37 #include "inet/ip_if.h"
38 #include "netinet/udp.h"
45 #include "h/cmn_err.h"
47 #include "netinet/in.h"
51 * Function pointers for kernel socket routines
53 struct sonode *(*sockfs_socreate)
54 (vnode_t *, int, int, int, int, struct sonode *, int *) = NULL;
55 struct vnode *(*sockfs_solookup)
56 (int, int, int, char *, int *) = NULL;
58 (struct sonode *, struct sockaddr *, int, int, int) = NULL;
59 int (*sockfs_sorecvmsg)
60 (struct sonode *, struct nmsghdr *, struct uio *) = NULL;
61 int (*sockfs_sosendmsg)
62 (struct sonode *, struct nmsghdr *, struct uio *) = NULL;
63 int (*sockfs_sosetsockopt)
64 (struct sonode *, int, int, void *, int) = NULL;
65 #ifndef AFS_SUN510_ENV
66 int (*sockfs_sounbind)
67 (struct sonode *, int);
68 void (*sockfs_sockfree)
72 static afs_uint32 myNetAddrs[ADDRSPERSITE];
73 static int myNetMTUs[ADDRSPERSITE];
74 static int numMyNetAddrs = 0;
81 #ifndef AFS_SUN510_ENV
86 int mtus[ADDRSPERSITE];
87 afs_uint32 addrs[ADDRSPERSITE];
90 memset(mtus, 0, sizeof(mtus));
91 memset(addrs, 0, sizeof(addrs));
94 (void) rw_enter(&afsifinfo_lock, RW_READER);
96 for (i = 0; (afsifinfo[i].ipaddr != NULL) && (i < ADDRSPERSITE); i++) {
98 /* Ignore addresses which are down.. */
99 if (!(afsifinfo[i].flags & IFF_UP))
102 /* Compute the Rx interface MTU */
103 rxmtu = (afsifinfo[i].mtu - RX_IPUDP_SIZE);
105 ifinaddr = afsifinfo[i].ipaddr;
106 if (myNetAddrs[i] != ifinaddr)
109 /* Copy interface MTU and address; adjust maxmtu */
111 rxmtu = rxi_AdjustIfMTU(rxmtu);
112 maxmtu = rxmtu * rxi_nRecvFrags +
113 ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
114 maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
117 if (ifinaddr != 0x7f000001 && maxmtu > rx_maxReceiveSize) {
118 rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu);
120 MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
125 (void) rw_exit(&afsifinfo_lock);
127 rx_maxJumboRecvSize =
128 RX_HEADER_SIZE + rxi_nDgramPackets * RX_JUMBOBUFFERSIZE +
129 (rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE;
130 rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize);
135 for (j = 0; j < i; j++) {
136 myNetMTUs[j] = mtus[j];
137 myNetAddrs[j] = addrs[j];
145 for (ill = ill_g_head; ill; ill = ill->ill_next) {
147 /* Make sure this is an IPv4 ILL */
152 /* Iterate over all the addresses on this ILL */
153 for (ipif = ill->ill_ipif; ipif; ipif = ipif->ipif_next) {
154 if (i >= ADDRSPERSITE)
157 /* Ignore addresses which are down.. */
158 if (!(ipif->ipif_flags & IFF_UP))
161 /* Compute the Rx interface MTU */
162 rxmtu = (ipif->ipif_mtu - RX_IPUDP_SIZE);
164 ifinaddr = ntohl(ipif->ipif_local_addr);
165 if (myNetAddrs[i] != ifinaddr)
168 /* Copy interface MTU and address; adjust maxmtu */
170 rxmtu = rxi_AdjustIfMTU(rxmtu);
172 rxmtu * rxi_nRecvFrags +
173 ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
174 maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
178 if (ifinaddr != 0x7f000001 && maxmtu > rx_maxReceiveSize) {
179 rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu);
181 MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
186 rx_maxJumboRecvSize =
187 RX_HEADER_SIZE + rxi_nDgramPackets * RX_JUMBOBUFFERSIZE +
188 (rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE;
189 rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize);
194 for (j = 0; j < i; j++) {
195 myNetMTUs[j] = mtus[j];
196 myNetAddrs[j] = addrs[j];
205 rxi_FindIfMTU(afs_uint32 addr)
207 afs_uint32 myAddr, netMask;
210 #ifdef AFS_SUN510_ENV
217 if (numMyNetAddrs == 0)
219 myAddr = ntohl(addr);
221 if (IN_CLASSA(myAddr))
222 netMask = IN_CLASSA_NET;
223 else if (IN_CLASSB(myAddr))
224 netMask = IN_CLASSB_NET;
225 else if (IN_CLASSC(myAddr))
226 netMask = IN_CLASSC_NET;
230 #ifdef AFS_SUN510_ENV
231 (void) rw_enter(&afsifinfo_lock, RW_READER);
233 for (i = 0; (afsifinfo[i].ipaddr != NULL) && (i < ADDRSPERSITE); i++) {
234 afs_uint32 thisAddr, subnetMask;
237 /* Ignore addresses which are down.. */
238 if ((afsifinfo[i].flags & IFF_UP) == 0)
241 thisAddr = afsifinfo[i].ipaddr;
242 subnetMask = afsifinfo[i].netmask;
243 thisMtu = afsifinfo[i].mtu;
245 if ((myAddr & netMask) == (thisAddr & netMask)) {
246 if ((myAddr & subnetMask) == (thisAddr & subnetMask)) {
247 if (myAddr == thisAddr) {
252 if (match_value < 3) {
258 if (match_value < 2) {
265 (void) rw_exit(&afsifinfo_lock);
270 for (ill = ill_g_head; ill; ill = ill->ill_next) {
272 /* Make sure this is an IPv4 ILL */
277 /* Iterate over all the addresses on this ILL */
278 for (ipif = ill->ill_ipif; ipif; ipif = ipif->ipif_next) {
279 afs_uint32 thisAddr, subnetMask;
282 thisAddr = ipif->ipif_local_addr;
283 subnetMask = ipif->ipif_net_mask;
284 thisMtu = ipif->ipif_mtu;
286 if ((myAddr & netMask) == (thisAddr & netMask)) {
287 if ((myAddr & subnetMask) == (thisAddr & subnetMask)) {
288 if (myAddr == thisAddr) {
293 if (match_value < 3) {
299 if (match_value < 2) {
311 /* rxi_NewSocket, rxi_FreeSocket and osi_NetSend are from the now defunct
315 struct sockaddr_in rx_sockaddr;
317 /* Allocate a new socket at specified port in network byte order. */
319 rxk_NewSocketHost(afs_uint32 ahost, short aport)
323 struct sockaddr_in addr;
327 AFS_STATCNT(osi_NewSocket);
329 if (sockfs_solookup == NULL) {
331 (struct vnode * (*)())modlookup("sockfs", "solookup");
332 if (sockfs_solookup == NULL) {
336 if (sockfs_socreate == NULL) {
338 (struct sonode * (*)())modlookup("sockfs", "socreate");
339 if (sockfs_socreate == NULL) {
343 if (sockfs_sobind == NULL) {
344 sockfs_sobind = (int (*)())modlookup("sockfs", "sobind");
345 if (sockfs_sobind == NULL) {
349 if (sockfs_sosetsockopt == NULL) {
350 sockfs_sosetsockopt = (int (*)())modlookup("sockfs", "sosetsockopt");
351 if (sockfs_sosetsockopt == NULL) {
355 if (sockfs_sosendmsg == NULL) {
356 sockfs_sosendmsg = (int (*)())modlookup("sockfs", "sosendmsg");
357 if (sockfs_sosendmsg == NULL) {
361 if (sockfs_sorecvmsg == NULL) {
362 sockfs_sorecvmsg = (int (*)())modlookup("sockfs", "sorecvmsg");
363 if (sockfs_sorecvmsg == NULL) {
367 #ifndef AFS_SUN510_ENV
368 if (sockfs_sounbind == NULL) {
369 sockfs_sounbind = (int (*)())modlookup("sockfs", "sounbind");
370 if (sockfs_sounbind == NULL)
373 if (sockfs_sockfree == NULL) {
374 sockfs_sockfree = (void (*)())modlookup("sockfs", "sockfree");
375 if (sockfs_sockfree == NULL)
380 accessvp = sockfs_solookup(AF_INET, SOCK_DGRAM, 0, "/dev/udp", &error);
381 if (accessvp == NULL) {
385 so = sockfs_socreate(accessvp, AF_INET, SOCK_DGRAM, 0, SOV_STREAM, NULL,
391 addr.sin_family = AF_INET;
392 addr.sin_port = aport;
393 addr.sin_addr.s_addr = ahost; /* I wonder what the odds are on
394 needing to unbyteswap this */
395 error = sockfs_sobind(so, (struct sockaddr *)&addr, sizeof(addr), 0, 0);
401 error = sockfs_sosetsockopt(so, SOL_SOCKET, SO_SNDBUF, &len, sizeof(len));
407 error = sockfs_sosetsockopt(so, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len));
412 return (osi_socket *)so;
416 rxk_NewSocket(short aport)
418 return rxk_NewSocketHost(htonl(INADDR_ANY), aport);
422 osi_FreeSocket(register osi_socket *asocket)
424 extern int rxk_ListenerPid;
425 struct sonode *so = (struct sonode *)asocket;
426 struct sockaddr_in taddr;
431 AFS_STATCNT(osi_FreeSocket);
433 taddr.sin_family = AF_INET;
434 taddr.sin_port = rx_port;
435 taddr.sin_addr.s_addr = htonl(0x7f000001);
440 while (rxk_ListenerPid) {
441 osi_NetSend(rx_socket, &taddr, &dvec, 1, 1, 0);
442 afs_osi_Sleep(&rxk_ListenerPid);
445 /* Was sockfs_sounbind(so, 0); sockfs_sockfree(so); That's wrong */
447 VOP_CLOSE(vp, FREAD|FWRITE, 1, (offset_t)0, CRED());
454 osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
455 int nvecs, afs_int32 asize, int istack)
457 struct sonode *so = (struct sonode *)asocket;
460 struct iovec iov[RX_MAXIOVECS];
464 if (nvecs > RX_MAXIOVECS) {
465 osi_Panic("osi_NetSend: %d: Too many iovecs.\n", nvecs);
468 msg.msg_name = (struct sockaddr *)addr;
469 msg.msg_namelen = sizeof(struct sockaddr_in);
471 msg.msg_iovlen = nvecs;
472 msg.msg_control = NULL;
473 msg.msg_controllen = 0;
476 for (i = 0; i < nvecs; i++) {
477 iov[i].iov_base = dvec[i].iov_base;
478 iov[i].iov_len = dvec[i].iov_len;
480 uio.uio_iov = &iov[0];
481 uio.uio_iovcnt = nvecs;
483 uio.uio_segflg = UIO_SYSSPACE;
484 uio.uio_fmode = FREAD | FWRITE;
486 uio.uio_resid = asize;
488 error = sockfs_sosendmsg(so, &msg, &uio);
494 osi_NetReceive(osi_socket so, struct sockaddr_in *addr, struct iovec *dvec,
495 int nvecs, int *alength)
497 struct sonode *asocket = (struct sonode *)so;
500 struct iovec iov[RX_MAXIOVECS];
504 if (nvecs > RX_MAXIOVECS) {
505 osi_Panic("osi_NetSend: %d: Too many iovecs.\n", nvecs);
509 msg.msg_namelen = sizeof(struct sockaddr_in);
512 msg.msg_control = NULL;
513 msg.msg_controllen = 0;
516 for (i = 0; i < nvecs; i++) {
517 iov[i].iov_base = dvec[i].iov_base;
518 iov[i].iov_len = dvec[i].iov_len;
520 uio.uio_iov = &iov[0];
521 uio.uio_iovcnt = nvecs;
523 uio.uio_segflg = UIO_SYSSPACE;
526 uio.uio_resid = *alength;
528 error = sockfs_sorecvmsg(asocket, &msg, &uio);
530 if (msg.msg_name == NULL) {
533 memcpy(addr, msg.msg_name, msg.msg_namelen);
534 kmem_free(msg.msg_name, msg.msg_namelen);
535 *alength = *alength - uio.uio_resid;
539 if (error == EINTR && ISSIG(curthread, FORREAL)) {
540 klwp_t *lwp = ttolwp(curthread);
541 proc_t *p = ttoproc(curthread);
542 int sig = lwp->lwp_cursig;
544 if (sig == SIGKILL) {
545 mutex_enter(&p->p_lock);
546 p->p_flag &= ~SKILLED;
547 mutex_exit(&p->p_lock);
550 if (lwp->lwp_curinfo) {
551 siginfofree(lwp->lwp_curinfo);
552 lwp->lwp_curinfo = NULL;
559 #if defined(AFS_SUN510_ENV)
560 /* How often afs collects interface info. Tunable via /etc/system: */
561 /* set afs:afs_if_poll_interval = integer (value is in seconds) */
562 static int afs_if_poll_interval = 30;
564 /* Global array which holds the interface info for consumers */
565 struct afs_ifinfo afsifinfo[ADDRSPERSITE];
568 osi_StartNetIfPoller()
570 (void) ddi_taskq_dispatch(afs_taskq, (void(*) (void*)) osi_NetIfPoller,
583 struct lifreq *lifrp;
584 struct sockaddr_in *sin4_local;
585 struct sockaddr_in *sin4_dst;
588 int i, count, error, rv;
595 if (afs_termState == AFSOP_STOP_NETIF) {
596 afs_warn("NetIfPoller... ");
597 rw_destroy(&afsifinfo_lock);
598 ddi_taskq_destroy(afs_taskq);
599 afs_termState = AFSOP_STOP_COMPLETE;
600 osi_rxWakeup(&afs_termState);
603 /* Get our permissions */
606 /* Initialize and open /dev/udp for receiving ioctls */
607 udpmajor = ddi_name_to_major(UDP_MOD_NAME);
609 error = ldi_ident_from_major(udpmajor, &li);
611 cmn_err(CE_PANIC, "osi_NetIfPoller: ldi_ident_from_major failed: %d",
614 error = ldi_open_by_name(UDP_DEV_NAME, FREAD, cr, &lh, li);
617 "osi_NetIfPoller: ldi_open_by_name failed: %d", error);
620 /* First, how many interfaces do we have? */
621 (void) bzero((void *)&lifn, sizeof(struct lifnum));
622 lifn.lifn_family = AF_INET;
624 error = ldi_ioctl(lh, SIOCGLIFNUM, (intptr_t)&lifn,
628 "osi_NetIfPoller: ldi_ioctl: SIOCGLIFNUM failed: %d", error);
630 ifcount = lifn.lifn_count;
632 /* Set up some stuff for storing the results of SIOCGLIFCONF */
633 (void) bzero((void *)&lifc, sizeof(struct lifconf));
635 lifcbuf = kmem_zalloc(ifcount * sizeof(struct lifreq), KM_SLEEP);
637 lifc.lifc_family = AF_INET;
638 lifc.lifc_flags = IFF_UP;
639 lifc.lifc_len = ifcount * sizeof(struct lifreq);
640 lifc.lifc_buf = lifcbuf;
642 /* Get info on each of our available interfaces. */
643 error = ldi_ioctl(lh, SIOCGLIFCONF, (intptr_t)&lifc,
647 "osi_NetIfPoller: ldi_ioctl: SIOCGLIFCONF failed: %d", error);
649 lifrp = lifc.lifc_req;
653 /* Loop through our interfaces and pick out the info we want */
654 for (i = lifc.lifc_len / sizeof(struct lifreq);
655 i > 0; i--, lifrp++) {
657 if (count >= ADDRSPERSITE)
660 (void) bzero((void *)&lifr, sizeof(struct lifreq));
662 (void) strncpy(lifr.lifr_name, lifrp->lifr_name,
663 sizeof(lifr.lifr_name));
665 /* Get this interface's Flags */
666 error = ldi_ioctl(lh, SIOCGLIFFLAGS, (intptr_t)&lifr,
670 "osi_NetIfPoller: ldi_ioctl: SIOCGLIFFLAGS failed: %d",
673 /* Ignore plumbed but down interfaces. */
674 if ((lifr.lifr_flags & IFF_UP) == 0)
677 flags = lifr.lifr_flags;
679 /* Get this interface's MTU */
680 error = ldi_ioctl(lh, SIOCGLIFMTU, (intptr_t)&lifr,
686 mtu = lifr.lifr_metric;
689 /* Get this interface's Metric */
690 error = ldi_ioctl(lh, SIOCGLIFMETRIC, (intptr_t)&lifr,
696 metric = lifr.lifr_metric;
699 sin4_local = (struct sockaddr_in *) &lifrp->lifr_addr;
700 sin4_dst = (struct sockaddr_in *) &lifrp->lifr_dstaddr;
702 /* Acquire global array write lock */
703 (void) rw_enter(&afsifinfo_lock, RW_WRITER);
705 /* Copy our collected data into the global array */
706 (void) strncpy(afsifinfo[count].ifname, lifrp->lifr_name,
707 sizeof(afsifinfo[count].ifname));
708 afsifinfo[count].ipaddr = ntohl(sin4_local->sin_addr.s_addr);
709 afsifinfo[count].mtu = mtu;
710 afsifinfo[count].netmask = lifrp->lifr_addrlen;
711 afsifinfo[count].flags = flags;
712 afsifinfo[count].metric = metric;
713 afsifinfo[count].dstaddr = ntohl(sin4_dst->sin_addr.s_addr);
715 /* Release global array write lock */
716 (void) rw_exit(&afsifinfo_lock);
720 } /* Bottom of loop: for each interface ... */
722 kmem_free(lifcbuf, ifcount * sizeof(struct lifreq));
724 /* End of thread. Time to clean up */
725 (void) ldi_close(lh, FREAD, cr);
726 (void) ldi_ident_release(li);
728 /* Schedule this to run again after afs_if_poll_interval seconds */
729 (void) timeout((void(*) (void *)) osi_StartNetIfPoller, NULL,
730 drv_usectohz((clock_t)afs_if_poll_interval * MICROSEC));
733 #endif /* AFS_SUN510_ENV */
736 shutdown_rxkernel(void)
741 osi_StopListener(void)
743 osi_FreeSocket(rx_socket);
746 #else /* AFS_SUN56_ENV */
748 #include "inet/common.h"
749 #include "sys/tiuser.h"
750 #include "sys/t_kuser.h"
751 #include "sys/ioctl.h"
752 #include "sys/stropts.h"
753 #include "sys/stream.h"
754 #include "sys/strsubr.h"
755 #include "sys/vnode.h"
756 #include "sys/stropts.h"
757 #include "sys/tihdr.h"
758 #include "sys/timod.h"
759 #include "sys/fcntl.h"
760 #include "sys/debug.h"
761 #include "inet/common.h"
763 #include "netinet/udp.h"
765 extern dev_t afs_udp_rdev;
775 /* rxi_NewSocket, rxi_FreeSocket and osi_NetSend are from the now defunct
779 dev_t afs_udp_rdev = (dev_t) 0;
781 /* Allocate a new socket at specified port in network byte order. */
783 rxk_NewSocketHost(afs_uint32 ahost, short aport)
786 struct t_bind *reqp, *rspp;
788 struct sockaddr_in *myaddrp;
792 AFS_STATCNT(osi_NewSocket);
793 afs_udp_rdev = makedevice(11 /*CLONE*/, ddi_name_to_major("udp"));
794 code = t_kopen(NULL, afs_udp_rdev, FREAD | FWRITE, &udp_tiptr, CRED());
796 return (osi_socket *)0;
799 code = t_kalloc(udp_tiptr, T_BIND, T_ADDR, (char **)&reqp);
801 t_kclose(udp_tiptr, 0);
803 code = t_kalloc(udp_tiptr, T_BIND, T_ADDR, (char **)&rspp);
805 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
806 t_kclose(udp_tiptr, 0);
807 return (osi_socket *)0;
810 reqp->addr.len = sizeof(struct sockaddr_in);
811 myaddrp = (struct sockaddr_in *)reqp->addr.buf;
812 myaddrp->sin_family = AF_INET;
813 myaddrp->sin_port = aport;
814 myaddrp->sin_addr.s_addr = ahost; /* byteswap? */
816 code = t_kbind(udp_tiptr, reqp, rspp);
818 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
819 t_kfree(udp_tiptr, (char *)rspp, T_BIND);
820 t_kclose(udp_tiptr, 0);
821 return (osi_socket *)0;
823 if (memcmp(reqp->addr.buf, rspp->addr.buf, rspp->addr.len)) {
824 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
825 t_kfree(udp_tiptr, (char *)rspp, T_BIND);
826 t_kclose(udp_tiptr, 0);
827 return (osi_socket *)0;
829 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
830 t_kfree(udp_tiptr, (char *)rspp, T_BIND);
833 * Set the send and receive buffer sizes.
835 stp = udp_tiptr->fp->f_vnode->v_stream;
837 q->q_hiwat = rx_UdpBufSize;
838 q->q_next->q_hiwat = rx_UdpBufSize;
839 RD(q)->q_hiwat = rx_UdpBufSize;
841 return (osi_socket *)udp_tiptr;
845 rxk_NewSocket(short aport)
847 return rxk_NewSocketHost(htonl(INADDR_ANY), aport);
851 osi_FreeSocket(register osi_socket *asocket)
853 extern int rxk_ListenerPid;
854 TIUSER *udp_tiptr = (TIUSER *) asocket;
855 AFS_STATCNT(osi_FreeSocket);
857 if (rxk_ListenerPid) {
858 kill(rxk_ListenerPid, SIGUSR1);
859 afs_osi_Sleep(&rxk_ListenerPid);
866 osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
867 int nvecs, afs_int32 asize, int istack)
871 TIUSER *udp_tiptr = (TIUSER *) asocket;
872 struct t_kunitdata *udreq;
873 struct sockaddr_in sin;
878 * XXX We don't do any checking on the family since it's assumed to be
881 sin.sin_family = AF_INET;
882 sin.sin_addr.s_addr = addr->sin_addr.s_addr;
883 sin.sin_port = addr->sin_port;
886 * Get a buffer for the RX header
889 osi_Panic("osi_NetSend, nvecs=%d\n", nvecs);
891 while (!(bp = allocb(dvec[0].iov_len, BPRI_LO))) {
892 if (strwaitbuf(dvec[i].iov_len, BPRI_LO)) {
897 /* Copy the data into the buffer */
898 memcpy((char *)bp->b_wptr, (char *)dvec[0].iov_base, dvec[0].iov_len);
899 bp->b_datap->db_type = M_DATA;
900 bp->b_wptr += dvec[0].iov_len;
903 * Append each element in the iovec to the buffer
905 for (i = 1; i < nvecs; i++) {
906 /* Get a buffer for the next chunk */
907 while (!(dbp = allocb(dvec[i].iov_len, BPRI_LO))) {
908 if (strwaitbuf(dvec[i].iov_len, BPRI_LO)) {
914 /* Copy the data into the buffer */
915 memcpy((char *)dbp->b_wptr, (char *)dvec[i].iov_base,
917 dbp->b_datap->db_type = M_DATA;
918 dbp->b_wptr += dvec[i].iov_len;
920 /* Append it to the message buffer */
925 * Allocate and format the unitdata structure.
927 code = t_kalloc(udp_tiptr, T_UNITDATA, T_UDATA, (char **)&udreq);
930 printf("osi_NetSend: t_kalloc failed %d\n", code);
933 udreq->addr.len = sizeof(struct sockaddr_in);
934 udreq->addr.maxlen = sizeof(struct sockaddr_in);
936 (char *)kmem_alloc(sizeof(struct sockaddr_in), KM_SLEEP);
938 udreq->opt.maxlen = 0;
939 memcpy(udreq->addr.buf, (char *)&sin, sizeof(struct sockaddr_in));
940 udreq->udata.udata_mp = bp;
941 udreq->udata.len = asize;
943 code = t_ksndudata(udp_tiptr, udreq, NULL);
945 printf("osi_NetSend: t_ksndudata failed %d\n", code);
948 t_kfree(udp_tiptr, (caddr_t) udreq, T_UNITDATA);
954 osi_NetReceive(osi_socket *asocket, struct sockaddr_in *addr,
955 struct iovec *dvec, int nvecs, int *alength)
958 TIUSER *udp_tiptr = (TIUSER *) asocket;
959 struct t_kunitdata *udreq;
973 * Allocate the unitdata structure.
975 code = t_kalloc(udp_tiptr, T_UNITDATA, T_UDATA, (char **)&udreq);
977 printf("osi_NetReceive: t_kalloc failed %d\n", code);
980 udreq->addr.len = sizeof(struct sockaddr_in);
981 udreq->addr.maxlen = sizeof(struct sockaddr_in);
983 (char *)kmem_alloc(sizeof(struct sockaddr_in), KM_SLEEP);
985 udreq->opt.maxlen = 0;
988 * Loop until we get an error or receive some data.
992 * Wait until there is something to do
994 code = t_kspoll(udp_tiptr, -1, READWAIT, &events);
996 osi_Panic("osi_NetReceive, infinite t_kspoll timed out\n");
999 * If there is a message then read it in
1002 code = t_krcvudata(udp_tiptr, udreq, &type, &error);
1006 * Block attempts to kill this thread
1008 if (code == EINTR && ISSIG(curthread, FORREAL)) {
1009 klwp_t *lwp = ttolwp(curthread);
1010 proc_t *p = ttoproc(curthread);
1011 int sig = lwp->lwp_cursig;
1013 if (sig == SIGKILL) {
1014 mutex_enter(&p->p_lock);
1015 p->p_flag &= ~SKILLED;
1016 mutex_exit(&p->p_lock);
1018 lwp->lwp_cursig = 0;
1019 if (lwp->lwp_curinfo) {
1020 kmem_free((caddr_t) lwp->lwp_curinfo,
1021 sizeof(*lwp->lwp_curinfo));
1022 lwp->lwp_curinfo = NULL;
1031 * Ignore non-data message types
1033 if (type != T_DATA) {
1038 * Save the source address
1040 memcpy((char *)addr, udreq->addr.buf, sizeof(struct sockaddr_in));
1043 * Copy out the message buffers, take care not to overflow
1046 dbp = udreq->udata.udata_mp;
1048 for (i = 0; dbp != NULL && length > 0 && i < nvecs; i++) {
1049 tlen = dvec[i].iov_len;
1050 tbase = dvec[i].iov_base;
1051 if (tlen > length) {
1054 while (dbp != NULL && tlen > 0) {
1055 blen = dbp->b_wptr - dbp->b_rptr;
1057 memcpy(tbase, (char *)dbp->b_rptr, tlen);
1059 dbp->b_rptr += tlen;
1062 memcpy(tbase, (char *)dbp->b_rptr, blen);
1070 *alength = *alength - length;
1074 t_kfree(udp_tiptr, (caddr_t) udreq, T_UNITDATA);
1080 osi_StopListener(void)
1082 osi_FreeSocket(rx_socket);
1087 shutdown_rxkernel(void)
1092 #endif /* AFS_SUN56_ENV */
1093 #endif /* AFS_SUN5_ENV */