reindent-20030715
[openafs.git] / src / rx / HPUX / rx_knet.c
index 312f4e0..7a4f1aa 100644 (file)
@@ -5,7 +5,8 @@
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
 #include "h/types.h"
 #include "h/param.h"
@@ -27,7 +28,7 @@ lock_t *rx_sleepLock;
 
 /* CKO_PSEUDO : Account for pseudo_header in the checksum              */
 #ifndef        CKO_SUM_MASK
-#define        CKO_SUM_MASK        0xffff      /* sum is in lower 16 bits      */
+#define        CKO_SUM_MASK        0xffff      /* sum is in lower 16 bits      */
 #endif
 
 #ifndef        CKO_PSEUDO
@@ -43,19 +44,22 @@ lock_t *rx_sleepLock;
 static struct protosw parent_proto;    /* udp proto switch */
 
 /* rx_kern.c */
-static int rxk_fasttimo (void)
+static int
+rxk_fasttimo(void)
 {
     int code;
-    int (*tproc)();
+    int (*tproc) ();
     struct clock temp;
 
     SPLVAR;
     NETPRI;
     /* do rx fasttimo processing here */
     rxevent_RaiseEvents(&temp);
-    USERPRI; /* should this be after the call to tproc? */
-    if (tproc = parent_proto.pr_fasttimo) code = (*tproc)();
-    else code = 0;
+    USERPRI;                   /* should this be after the call to tproc? */
+    if (tproc = parent_proto.pr_fasttimo)
+       code = (*tproc) ();
+    else
+       code = 0;
     return code;
 }
 
@@ -64,9 +68,11 @@ static int rxk_fasttimo (void)
 #if !defined(RXK_LISTENER_ENV)
 /* start intercepting basic calls */
 int
-rxk_init() {
+rxk_init()
+{
     register struct protosw *tpro, *last;
-    if (rxk_initDone) return 0;
+    if (rxk_initDone)
+       return 0;
 
     last = inetdomain.dom_protoswNPROTOSW;
     for (tpro = inetdomain.dom_protosw; tpro < last; tpro++) {
@@ -85,9 +91,10 @@ rxk_init() {
 }
 
 /* basic packet handling routine called at splnet from softnet loop */
-static struct mbuf *rxk_input (register struct mbuf *am, struct ifnet *aif)
+static struct mbuf *
+rxk_input(register struct mbuf *am, struct ifnet *aif)
 {
-    int (*tproc)();
+    int (*tproc) ();
     register unsigned short *tsp;
     int hdr;
     struct udphdr *tu;
@@ -108,42 +115,43 @@ static struct mbuf *rxk_input (register struct mbuf *am, struct ifnet *aif)
     if (am->m_off > MMAXOFF || am->m_len < 28) {
        am = m_pullup(am, 28);
        USERPRI;
-       if (!am) return NULL;
+       if (!am)
+           return NULL;
     }
     hdr = (mtod(am, struct ip *))->ip_hl;
     if (hdr > 5) {
        /* pull up more, the IP hdr is bigger than usual */
-       if (am->m_len < (8 + (hdr<<2))) {
-           am = m_pullup(am, 8+(hdr<<2));
+       if (am->m_len < (8 + (hdr << 2))) {
+           am = m_pullup(am, 8 + (hdr << 2));
            USERPRI;
-           if (!am) return NULL;
+           if (!am)
+               return NULL;
        }
-       ti = mtod(am, struct ip *); /* recompute, since m_pullup allocates new mbuf */
-       tu = (struct udphdr *)(((char *)ti) + (hdr<<2)); /* skip ip hdr */
-    }
-    else {
+       ti = mtod(am, struct ip *);     /* recompute, since m_pullup allocates new mbuf */
+       tu = (struct udphdr *)(((char *)ti) + (hdr << 2));      /* skip ip hdr */
+    } else {
        ti = mtod(am, struct ip *);
-       tu = (struct udphdr *)(((char *)ti) + 20);      /* skip basic ip hdr */
+       tu = (struct udphdr *)(((char *)ti) + 20);      /* skip basic ip hdr */
     }
     /* now read the port out */
     port = tu->uh_dport;
-    
+
     if (port) {
-       for(tsp=ports, i=0; i<MAXRXPORTS;i++) {
+       for (tsp = ports, i = 0; i < MAXRXPORTS; i++) {
            if (*tsp++ == port) {
                /* checksum the packet */
-               ip_stripoptions(ti,     NULL); /* get rid of anything we don't need */
+               ip_stripoptions(ti, NULL);      /* get rid of anything we don't need */
                /* deliver packet to rx */
-               taddr.sin_family = AF_INET;         /* compute source address */
+               taddr.sin_family = AF_INET;     /* compute source address */
                taddr.sin_port = tu->uh_sport;
                taddr.sin_addr.s_addr = ti->ip_src.s_addr;
-               
+
                /* handle the checksum.  Note that this code damages the actual ip
-                  header (replacing it with the virtual one, which is the same 
-                  size), so we must ensure we get everything out we need, first */
-               tvu = (struct udpiphdr *) ti;   /* virtual udp structure, for ck
-                                                  sum */
-               if ( tu->uh_sum != 0) {
+                * header (replacing it with the virtual one, which is the same 
+                * size), so we must ensure we get everything out we need, first */
+               tvu = (struct udpiphdr *)ti;    /* virtual udp structure, for ck
+                                                * sum */
+               if (tu->uh_sum != 0) {
                    /* if the checksum is there, always check it. It's crazy not
                     * to, unless you can really be sure that your
                     * underlying network (and interfaces and drivers and
@@ -159,17 +167,17 @@ static struct mbuf *rxk_input (register struct mbuf *am, struct ifnet *aif)
                        CKO_PSEUDO(comp_sum, am, tvu);
                    } else {
                        struct mbuf *m1;
-                       
+
                        comp_sum = in_cksum(am, sizeof(struct ip) + tlen);
                        for (m1 = am; m1; m1 = m1->m_next)
                            m1->m_flags &= ~MF_NOACC;
                    }
                    if (comp_sum) {
                        /* checksum, including cksum field, doesn't come out 0, so
-                          this packet is bad */
+                        * this packet is bad */
                        m_freem(am);
                        USERPRI;
-                       return(NULL);
+                       return (NULL);
                    }
                }
                /*
@@ -179,38 +187,39 @@ static struct mbuf *rxk_input (register struct mbuf *am, struct ifnet *aif)
                 */
                data_len = ntohs(tu->uh_ulen);
                data_len -= 8;
-                  
-               if (!(*rxk_GetPacketProc)(&phandle, data_len)) {
+
+               if (!(*rxk_GetPacketProc) (&phandle, data_len)) {
                    if (rx_mb_to_packet(am, m_freem, 28, data_len, phandle)) {
                        /* XXX should just increment counter here.. */
                        printf("rx: truncated UDP packet\n");
                        rxi_FreePacket(phandle);
-                   }
-                   else 
-                       (*rxk_PacketArrivalProc)(phandle, &taddr,
-                                                portRocks[i], data_len);
-               }
-               else m_freem(am);
+                   } else
+                       (*rxk_PacketArrivalProc) (phandle, &taddr,
+                                                 portRocks[i], data_len);
+               } else
+                   m_freem(am);
                USERPRI;
-               return(NULL);
+               return (NULL);
            }
        }
     }
 
     /* if we get here, try to deliver packet to udp */
     if (tproc = parent_proto.pr_input) {
-      code = (*tproc)(am,aif);
-      USERPRI;
-      return code;
+       code = (*tproc) (am, aif);
+       USERPRI;
+       return code;
     }
     USERPRI;
-    return(NULL);
+    return (NULL);
 }
 #endif /* ! RXK_LISTENER_ENV */
 
 /* steal decl from sgi_65 */
-int osi_NetSend(register struct socket *asocket, struct sockaddr_in *addr, 
-       struct iovec *dvec, int nvec, register afs_int32 asize, int istack)
+int
+osi_NetSend(register struct socket *asocket, struct sockaddr_in *addr,
+           struct iovec *dvec, int nvec, register afs_int32 asize,
+           int istack)
 {
     struct uio uio;
     MBLKP bp;
@@ -219,20 +228,21 @@ int osi_NetSend(register struct socket *asocket, struct sockaddr_in *addr,
     int size = sizeof(struct sockaddr_in);
 
     /* Guess based on rxk_NewSocket */
-    bp = allocb((size+SO_MSGOFFSET+1), BPRI_MED);
-    if (!bp) return ENOBUFS;        
-    memcpy((caddr_t)bp->b_rptr+SO_MSGOFFSET, (caddr_t)addr, size);
-    bp->b_wptr = bp->b_rptr + (size+SO_MSGOFFSET+1);
+    bp = allocb((size + SO_MSGOFFSET + 1), BPRI_MED);
+    if (!bp)
+       return ENOBUFS;
+    memcpy((caddr_t) bp->b_rptr + SO_MSGOFFSET, (caddr_t) addr, size);
+    bp->b_wptr = bp->b_rptr + (size + SO_MSGOFFSET + 1);
+
+    memcpy((caddr_t) temp, (caddr_t) dvec, nvec * sizeof(struct iovec));
 
-    memcpy((caddr_t)temp, (caddr_t)dvec, nvec * sizeof(struct iovec));
-    
     /* devresource.hp.com/Drivers/Docs/Refs/11i/ddRef/Chap02R.pdf has details
-       on use of uio */
-    memset((caddr_t)&uio, 0, sizeof(uio));
-    uio.uio_resid   = asize;
-    uio.uio_iov     = temp;         
-    uio.uio_iovcnt  = nvec;
-    uio.uio_seg     = UIOSEG_KERNEL;
+     * on use of uio */
+    memset((caddr_t) & uio, 0, sizeof(uio));
+    uio.uio_resid = asize;
+    uio.uio_iov = temp;
+    uio.uio_iovcnt = nvec;
+    uio.uio_seg = UIOSEG_KERNEL;
 
     code = sosend(asocket, bp, &uio, 0, 0, 0, size);
     return code;
@@ -240,40 +250,45 @@ int osi_NetSend(register struct socket *asocket, struct sockaddr_in *addr,
 
 /* pattern from IRIX */
 #if defined(RXK_LISTENER_ENV)
-int osi_NetReceive(osi_socket so, struct sockaddr_in *addr, struct iovec *dvec,         
-        int nvecs, int *alength)
-{   
-    int          code;
-    struct uio   tuio;
-    struct iovec tmpvec[RX_MAXWVECS+2];
-    int          flags = 0;
+int
+osi_NetReceive(osi_socket so, struct sockaddr_in *addr, struct iovec *dvec,
+              int nvecs, int *alength)
+{
+    int code;
+    struct uio tuio;
+    struct iovec tmpvec[RX_MAXWVECS + 2];
+    int flags = 0;
     MBLKP bp, sp;
 
-    if (nvecs > RX_MAXWVECS+2) {
-        osi_Panic("Too many (%d) iovecs passed to osi_NetReceive\n", nvecs);
+    if (nvecs > RX_MAXWVECS + 2) {
+       osi_Panic("Too many (%d) iovecs passed to osi_NetReceive\n", nvecs);
     }
-    memcpy(tmpvec, (char*)dvec, nvecs/*(RX_MAXWVECS+1)*/ * sizeof(struct iovec));
-    tuio.uio_iov     = tmpvec;
-    tuio.uio_iovcnt  = nvecs;
+    memcpy(tmpvec, (char *)dvec,
+          nvecs /*(RX_MAXWVECS+1) */  * sizeof(struct iovec));
+    tuio.uio_iov = tmpvec;
+    tuio.uio_iovcnt = nvecs;
     tuio.uio_fpflags = 0;
-    tuio.uio_offset  = 0;
-    tuio.uio_seg     = UIOSEG_KERNEL;
-    tuio.uio_resid   = *alength;
+    tuio.uio_offset = 0;
+    tuio.uio_seg = UIOSEG_KERNEL;
+    tuio.uio_resid = *alength;
 
-    code = soreceive(so, &bp, &tuio, &flags, &sp, (MBLKPP)NULL);
+    code = soreceive(so, &bp, &tuio, &flags, &sp, (MBLKPP) NULL);
     if (!code) {
-        *alength = *alength - tuio.uio_resid;
-        if (bp) {
-            memcpy((char*)addr, (char*)bp->b_rptr, sizeof(struct sockaddr_in));
-        } else {
-            code = -1;
-        }
+       *alength = *alength - tuio.uio_resid;
+       if (bp) {
+           memcpy((char *)addr, (char *)bp->b_rptr,
+                  sizeof(struct sockaddr_in));
+       } else {
+           code = -1;
+       }
     } else {
-        so->so_error = 0;
+       so->so_error = 0;
     }
 
-    if (bp) freeb(bp); 
-    if (sp) freeb(sp);
+    if (bp)
+       freeb(bp);
+    if (sp)
+       freeb(sp);
     return code;
 }
 #endif