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 #ifdef AFS_SUN511_ENV
448 VOP_CLOSE(vp, FREAD|FWRITE, 1, (offset_t)0, CRED(), NULL);
450 VOP_CLOSE(vp, FREAD|FWRITE, 1, (offset_t)0, CRED());
458 osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
459 int nvecs, afs_int32 asize, int istack)
461 struct sonode *so = (struct sonode *)asocket;
464 struct iovec iov[RX_MAXIOVECS];
468 if (nvecs > RX_MAXIOVECS) {
469 osi_Panic("osi_NetSend: %d: Too many iovecs.\n", nvecs);
472 msg.msg_name = (struct sockaddr *)addr;
473 msg.msg_namelen = sizeof(struct sockaddr_in);
475 msg.msg_iovlen = nvecs;
476 msg.msg_control = NULL;
477 msg.msg_controllen = 0;
480 for (i = 0; i < nvecs; i++) {
481 iov[i].iov_base = dvec[i].iov_base;
482 iov[i].iov_len = dvec[i].iov_len;
484 uio.uio_iov = &iov[0];
485 uio.uio_iovcnt = nvecs;
487 uio.uio_segflg = UIO_SYSSPACE;
488 uio.uio_fmode = FREAD | FWRITE;
490 uio.uio_resid = asize;
492 error = sockfs_sosendmsg(so, &msg, &uio);
498 osi_NetReceive(osi_socket so, struct sockaddr_in *addr, struct iovec *dvec,
499 int nvecs, int *alength)
501 struct sonode *asocket = (struct sonode *)so;
504 struct iovec iov[RX_MAXIOVECS];
508 if (nvecs > RX_MAXIOVECS) {
509 osi_Panic("osi_NetSend: %d: Too many iovecs.\n", nvecs);
513 msg.msg_namelen = sizeof(struct sockaddr_in);
516 msg.msg_control = NULL;
517 msg.msg_controllen = 0;
520 for (i = 0; i < nvecs; i++) {
521 iov[i].iov_base = dvec[i].iov_base;
522 iov[i].iov_len = dvec[i].iov_len;
524 uio.uio_iov = &iov[0];
525 uio.uio_iovcnt = nvecs;
527 uio.uio_segflg = UIO_SYSSPACE;
530 uio.uio_resid = *alength;
532 error = sockfs_sorecvmsg(asocket, &msg, &uio);
534 if (msg.msg_name == NULL) {
537 memcpy(addr, msg.msg_name, msg.msg_namelen);
538 kmem_free(msg.msg_name, msg.msg_namelen);
539 *alength = *alength - uio.uio_resid;
543 if (error == EINTR && ISSIG(curthread, FORREAL)) {
544 klwp_t *lwp = ttolwp(curthread);
545 proc_t *p = ttoproc(curthread);
546 int sig = lwp->lwp_cursig;
548 if (sig == SIGKILL) {
549 mutex_enter(&p->p_lock);
550 p->p_flag &= ~SKILLED;
551 mutex_exit(&p->p_lock);
554 if (lwp->lwp_curinfo) {
555 siginfofree(lwp->lwp_curinfo);
556 lwp->lwp_curinfo = NULL;
563 #if defined(AFS_SUN510_ENV)
564 /* How often afs collects interface info. Tunable via /etc/system: */
565 /* set afs:afs_if_poll_interval = integer (value is in seconds) */
566 static int afs_if_poll_interval = 30;
568 /* Global array which holds the interface info for consumers */
569 struct afs_ifinfo afsifinfo[ADDRSPERSITE];
572 osi_StartNetIfPoller()
574 (void) ddi_taskq_dispatch(afs_taskq, (void(*) (void*)) osi_NetIfPoller,
587 struct lifreq *lifrp;
588 struct sockaddr_in *sin4_local;
589 struct sockaddr_in *sin4_dst;
592 int i, count, error, rv;
599 if (afs_termState == AFSOP_STOP_NETIF) {
600 afs_warn("NetIfPoller... ");
601 rw_destroy(&afsifinfo_lock);
602 ddi_taskq_destroy(afs_taskq);
603 afs_termState = AFSOP_STOP_COMPLETE;
604 osi_rxWakeup(&afs_termState);
607 /* Get our permissions */
610 /* Initialize and open /dev/udp for receiving ioctls */
611 udpmajor = ddi_name_to_major(UDP_MOD_NAME);
613 error = ldi_ident_from_major(udpmajor, &li);
615 cmn_err(CE_PANIC, "osi_NetIfPoller: ldi_ident_from_major failed: %d",
618 error = ldi_open_by_name(UDP_DEV_NAME, FREAD, cr, &lh, li);
621 "osi_NetIfPoller: ldi_open_by_name failed: %d", error);
624 /* First, how many interfaces do we have? */
625 (void) bzero((void *)&lifn, sizeof(struct lifnum));
626 lifn.lifn_family = AF_INET;
628 error = ldi_ioctl(lh, SIOCGLIFNUM, (intptr_t)&lifn,
632 "osi_NetIfPoller: ldi_ioctl: SIOCGLIFNUM failed: %d", error);
634 ifcount = lifn.lifn_count;
636 /* Set up some stuff for storing the results of SIOCGLIFCONF */
637 (void) bzero((void *)&lifc, sizeof(struct lifconf));
639 lifcbuf = kmem_zalloc(ifcount * sizeof(struct lifreq), KM_SLEEP);
641 lifc.lifc_family = AF_INET;
642 lifc.lifc_flags = IFF_UP;
643 lifc.lifc_len = ifcount * sizeof(struct lifreq);
644 lifc.lifc_buf = lifcbuf;
646 /* Get info on each of our available interfaces. */
647 error = ldi_ioctl(lh, SIOCGLIFCONF, (intptr_t)&lifc,
651 "osi_NetIfPoller: ldi_ioctl: SIOCGLIFCONF failed: %d", error);
653 lifrp = lifc.lifc_req;
657 /* Loop through our interfaces and pick out the info we want */
658 for (i = lifc.lifc_len / sizeof(struct lifreq);
659 i > 0; i--, lifrp++) {
661 if (count >= ADDRSPERSITE)
664 (void) bzero((void *)&lifr, sizeof(struct lifreq));
666 (void) strncpy(lifr.lifr_name, lifrp->lifr_name,
667 sizeof(lifr.lifr_name));
669 /* Get this interface's Flags */
670 error = ldi_ioctl(lh, SIOCGLIFFLAGS, (intptr_t)&lifr,
674 "osi_NetIfPoller: ldi_ioctl: SIOCGLIFFLAGS failed: %d",
677 /* Ignore plumbed but down interfaces. */
678 if ((lifr.lifr_flags & IFF_UP) == 0)
681 flags = lifr.lifr_flags;
683 /* Get this interface's MTU */
684 error = ldi_ioctl(lh, SIOCGLIFMTU, (intptr_t)&lifr,
690 mtu = lifr.lifr_metric;
693 /* Get this interface's Metric */
694 error = ldi_ioctl(lh, SIOCGLIFMETRIC, (intptr_t)&lifr,
700 metric = lifr.lifr_metric;
703 sin4_local = (struct sockaddr_in *) &lifrp->lifr_addr;
704 sin4_dst = (struct sockaddr_in *) &lifrp->lifr_dstaddr;
706 /* Acquire global array write lock */
707 (void) rw_enter(&afsifinfo_lock, RW_WRITER);
709 /* Copy our collected data into the global array */
710 (void) strncpy(afsifinfo[count].ifname, lifrp->lifr_name,
711 sizeof(afsifinfo[count].ifname));
712 afsifinfo[count].ipaddr = ntohl(sin4_local->sin_addr.s_addr);
713 afsifinfo[count].mtu = mtu;
714 afsifinfo[count].netmask = lifrp->lifr_addrlen;
715 afsifinfo[count].flags = flags;
716 afsifinfo[count].metric = metric;
717 afsifinfo[count].dstaddr = ntohl(sin4_dst->sin_addr.s_addr);
719 /* Release global array write lock */
720 (void) rw_exit(&afsifinfo_lock);
724 } /* Bottom of loop: for each interface ... */
726 kmem_free(lifcbuf, ifcount * sizeof(struct lifreq));
728 /* End of thread. Time to clean up */
729 (void) ldi_close(lh, FREAD, cr);
730 (void) ldi_ident_release(li);
732 /* Schedule this to run again after afs_if_poll_interval seconds */
733 (void) timeout((void(*) (void *)) osi_StartNetIfPoller, NULL,
734 drv_usectohz((clock_t)afs_if_poll_interval * MICROSEC));
737 #endif /* AFS_SUN510_ENV */
740 shutdown_rxkernel(void)
745 osi_StopListener(void)
747 osi_FreeSocket(rx_socket);
750 #else /* AFS_SUN56_ENV */
752 #include "inet/common.h"
753 #include "sys/tiuser.h"
754 #include "sys/t_kuser.h"
755 #include "sys/ioctl.h"
756 #include "sys/stropts.h"
757 #include "sys/stream.h"
758 #include "sys/strsubr.h"
759 #include "sys/vnode.h"
760 #include "sys/stropts.h"
761 #include "sys/tihdr.h"
762 #include "sys/timod.h"
763 #include "sys/fcntl.h"
764 #include "sys/debug.h"
765 #include "inet/common.h"
767 #include "netinet/udp.h"
769 extern dev_t afs_udp_rdev;
779 /* rxi_NewSocket, rxi_FreeSocket and osi_NetSend are from the now defunct
783 dev_t afs_udp_rdev = (dev_t) 0;
785 /* Allocate a new socket at specified port in network byte order. */
787 rxk_NewSocketHost(afs_uint32 ahost, short aport)
790 struct t_bind *reqp, *rspp;
792 struct sockaddr_in *myaddrp;
796 AFS_STATCNT(osi_NewSocket);
797 afs_udp_rdev = makedevice(11 /*CLONE*/, ddi_name_to_major("udp"));
798 code = t_kopen(NULL, afs_udp_rdev, FREAD | FWRITE, &udp_tiptr, CRED());
800 return (osi_socket *)0;
803 code = t_kalloc(udp_tiptr, T_BIND, T_ADDR, (char **)&reqp);
805 t_kclose(udp_tiptr, 0);
807 code = t_kalloc(udp_tiptr, T_BIND, T_ADDR, (char **)&rspp);
809 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
810 t_kclose(udp_tiptr, 0);
811 return (osi_socket *)0;
814 reqp->addr.len = sizeof(struct sockaddr_in);
815 myaddrp = (struct sockaddr_in *)reqp->addr.buf;
816 myaddrp->sin_family = AF_INET;
817 myaddrp->sin_port = aport;
818 myaddrp->sin_addr.s_addr = ahost; /* byteswap? */
820 code = t_kbind(udp_tiptr, reqp, rspp);
822 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
823 t_kfree(udp_tiptr, (char *)rspp, T_BIND);
824 t_kclose(udp_tiptr, 0);
825 return (osi_socket *)0;
827 if (memcmp(reqp->addr.buf, rspp->addr.buf, rspp->addr.len)) {
828 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
829 t_kfree(udp_tiptr, (char *)rspp, T_BIND);
830 t_kclose(udp_tiptr, 0);
831 return (osi_socket *)0;
833 t_kfree(udp_tiptr, (char *)reqp, T_BIND);
834 t_kfree(udp_tiptr, (char *)rspp, T_BIND);
837 * Set the send and receive buffer sizes.
839 stp = udp_tiptr->fp->f_vnode->v_stream;
841 q->q_hiwat = rx_UdpBufSize;
842 q->q_next->q_hiwat = rx_UdpBufSize;
843 RD(q)->q_hiwat = rx_UdpBufSize;
845 return (osi_socket *)udp_tiptr;
849 rxk_NewSocket(short aport)
851 return rxk_NewSocketHost(htonl(INADDR_ANY), aport);
855 osi_FreeSocket(register osi_socket *asocket)
857 extern int rxk_ListenerPid;
858 TIUSER *udp_tiptr = (TIUSER *) asocket;
859 AFS_STATCNT(osi_FreeSocket);
861 if (rxk_ListenerPid) {
862 kill(rxk_ListenerPid, SIGUSR1);
863 afs_osi_Sleep(&rxk_ListenerPid);
870 osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
871 int nvecs, afs_int32 asize, int istack)
875 TIUSER *udp_tiptr = (TIUSER *) asocket;
876 struct t_kunitdata *udreq;
877 struct sockaddr_in sin;
882 * XXX We don't do any checking on the family since it's assumed to be
885 sin.sin_family = AF_INET;
886 sin.sin_addr.s_addr = addr->sin_addr.s_addr;
887 sin.sin_port = addr->sin_port;
890 * Get a buffer for the RX header
893 osi_Panic("osi_NetSend, nvecs=%d\n", nvecs);
895 while (!(bp = allocb(dvec[0].iov_len, BPRI_LO))) {
896 if (strwaitbuf(dvec[i].iov_len, BPRI_LO)) {
901 /* Copy the data into the buffer */
902 memcpy((char *)bp->b_wptr, (char *)dvec[0].iov_base, dvec[0].iov_len);
903 bp->b_datap->db_type = M_DATA;
904 bp->b_wptr += dvec[0].iov_len;
907 * Append each element in the iovec to the buffer
909 for (i = 1; i < nvecs; i++) {
910 /* Get a buffer for the next chunk */
911 while (!(dbp = allocb(dvec[i].iov_len, BPRI_LO))) {
912 if (strwaitbuf(dvec[i].iov_len, BPRI_LO)) {
918 /* Copy the data into the buffer */
919 memcpy((char *)dbp->b_wptr, (char *)dvec[i].iov_base,
921 dbp->b_datap->db_type = M_DATA;
922 dbp->b_wptr += dvec[i].iov_len;
924 /* Append it to the message buffer */
929 * Allocate and format the unitdata structure.
931 code = t_kalloc(udp_tiptr, T_UNITDATA, T_UDATA, (char **)&udreq);
934 printf("osi_NetSend: t_kalloc failed %d\n", code);
937 udreq->addr.len = sizeof(struct sockaddr_in);
938 udreq->addr.maxlen = sizeof(struct sockaddr_in);
940 (char *)kmem_alloc(sizeof(struct sockaddr_in), KM_SLEEP);
942 udreq->opt.maxlen = 0;
943 memcpy(udreq->addr.buf, (char *)&sin, sizeof(struct sockaddr_in));
944 udreq->udata.udata_mp = bp;
945 udreq->udata.len = asize;
947 code = t_ksndudata(udp_tiptr, udreq, NULL);
949 printf("osi_NetSend: t_ksndudata failed %d\n", code);
952 t_kfree(udp_tiptr, (caddr_t) udreq, T_UNITDATA);
958 osi_NetReceive(osi_socket *asocket, struct sockaddr_in *addr,
959 struct iovec *dvec, int nvecs, int *alength)
962 TIUSER *udp_tiptr = (TIUSER *) asocket;
963 struct t_kunitdata *udreq;
977 * Allocate the unitdata structure.
979 code = t_kalloc(udp_tiptr, T_UNITDATA, T_UDATA, (char **)&udreq);
981 printf("osi_NetReceive: t_kalloc failed %d\n", code);
984 udreq->addr.len = sizeof(struct sockaddr_in);
985 udreq->addr.maxlen = sizeof(struct sockaddr_in);
987 (char *)kmem_alloc(sizeof(struct sockaddr_in), KM_SLEEP);
989 udreq->opt.maxlen = 0;
992 * Loop until we get an error or receive some data.
996 * Wait until there is something to do
998 code = t_kspoll(udp_tiptr, -1, READWAIT, &events);
1000 osi_Panic("osi_NetReceive, infinite t_kspoll timed out\n");
1003 * If there is a message then read it in
1006 code = t_krcvudata(udp_tiptr, udreq, &type, &error);
1010 * Block attempts to kill this thread
1012 if (code == EINTR && ISSIG(curthread, FORREAL)) {
1013 klwp_t *lwp = ttolwp(curthread);
1014 proc_t *p = ttoproc(curthread);
1015 int sig = lwp->lwp_cursig;
1017 if (sig == SIGKILL) {
1018 mutex_enter(&p->p_lock);
1019 p->p_flag &= ~SKILLED;
1020 mutex_exit(&p->p_lock);
1022 lwp->lwp_cursig = 0;
1023 if (lwp->lwp_curinfo) {
1024 kmem_free((caddr_t) lwp->lwp_curinfo,
1025 sizeof(*lwp->lwp_curinfo));
1026 lwp->lwp_curinfo = NULL;
1035 * Ignore non-data message types
1037 if (type != T_DATA) {
1042 * Save the source address
1044 memcpy((char *)addr, udreq->addr.buf, sizeof(struct sockaddr_in));
1047 * Copy out the message buffers, take care not to overflow
1050 dbp = udreq->udata.udata_mp;
1052 for (i = 0; dbp != NULL && length > 0 && i < nvecs; i++) {
1053 tlen = dvec[i].iov_len;
1054 tbase = dvec[i].iov_base;
1055 if (tlen > length) {
1058 while (dbp != NULL && tlen > 0) {
1059 blen = dbp->b_wptr - dbp->b_rptr;
1061 memcpy(tbase, (char *)dbp->b_rptr, tlen);
1063 dbp->b_rptr += tlen;
1066 memcpy(tbase, (char *)dbp->b_rptr, blen);
1074 *alength = *alength - length;
1078 t_kfree(udp_tiptr, (caddr_t) udreq, T_UNITDATA);
1084 osi_StopListener(void)
1086 osi_FreeSocket(rx_socket);
1091 shutdown_rxkernel(void)
1096 #endif /* AFS_SUN56_ENV */
1097 #endif /* AFS_SUN5_ENV */