reindent-20030715
[openafs.git] / src / rx / DUX / rx_knet.c
index 54d2b6d..c569019 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
 #ifdef AFS_DUX40_ENV
 #include "rx/rx_kcommon.h"
 
 
 static struct protosw parent_proto;    /* udp proto switch */
-static void rxk_input (struct mbuf *am, int iphlen);
-static void rxk_fasttimo (void);
+static void rxk_input(struct mbuf *am, int iphlen);
+static void rxk_fasttimo(void);
 
 /* start intercepting basic calls */
-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++)
-      if (tpro->pr_protocol == IPPROTO_UDP) {
-       /* force UDP checksumming on for AFS    */
-        extern int udpcksum;
-        udpcksum = 1;  
-          memcpy(&parent_proto, tpro, sizeof(parent_proto));
-          tpro->pr_input = rxk_input;
-          tpro->pr_fasttimo = rxk_fasttimo;
-          /*
-           * don't bother with pr_drain and pr_ctlinput
-           * until we have something to do
-           */
-          rxk_initDone = 1;
-          return 0;
-      }
+       if (tpro->pr_protocol == IPPROTO_UDP) {
+           /* force UDP checksumming on for AFS    */
+           extern int udpcksum;
+           udpcksum = 1;
+           memcpy(&parent_proto, tpro, sizeof(parent_proto));
+           tpro->pr_input = rxk_input;
+           tpro->pr_fasttimo = rxk_fasttimo;
+           /*
+            * don't bother with pr_drain and pr_ctlinput
+            * until we have something to do
+            */
+           rxk_initDone = 1;
+           return 0;
+       }
     osi_Panic("inet:no udp");
 }
 
 
-static void rxk_input (struct mbuf *am, int iphlen)
+static void
+rxk_input(struct mbuf *am, int iphlen)
 {
-    void (*tproc)();
+    void (*tproc) ();
     register unsigned short *tsp;
     int hdr;
     struct udphdr *tu;
@@ -65,28 +69,28 @@ static void rxk_input (struct mbuf *am, int iphlen)
     NETPRI;
 
     /* make sure we have base ip and udp headers in first mbuf */
-    if (iphlen > sizeof (struct ip)) {
-        ip_stripoptions(am, NULL, NULL);
-        iphlen = sizeof (struct ip);
+    if (iphlen > sizeof(struct ip)) {
+       ip_stripoptions(am, NULL, NULL);
+       iphlen = sizeof(struct ip);
     }
 
     if (am->m_len < sizeof(struct udpiphdr)) {
-        am = m_pullup(am, sizeof(struct udpiphdr));
-        if (!am) {
+       am = m_pullup(am, sizeof(struct udpiphdr));
+       if (!am) {
            USERPRI;
            return;
-        }
+       }
     }
 
     ti = mtod(am, struct ip *);
     /* skip basic ip hdr */
-    tu = (struct udphdr *)(((char *)ti) + sizeof(struct ip)); 
-    
+    tu = (struct udphdr *)(((char *)ti) + sizeof(struct ip));
+
     /* now read the port out */
     port = tu->uh_dport;
 
     if (port) {
-       for(tsp=rxk_ports, i=0; i<MAXRXPORTS;i++) {
+       for (tsp = rxk_ports, i = 0; i < MAXRXPORTS; i++) {
            if (*tsp++ == port) {
                /* checksum the packet */
                /*
@@ -94,7 +98,7 @@ static void rxk_input (struct mbuf *am, int iphlen)
                 * If not enough data to reflect UDP length, drop.
                 */
                tvu = (struct udpiphdr *)ti;
-               tlen = ntohs((u_short)tvu->ui_ulen);
+               tlen = ntohs((u_short) tvu->ui_ulen);
                if ((int)ti->ip_len != tlen) {
                    if (tlen > (int)ti->ip_len) {
                        m_free(am);
@@ -104,33 +108,33 @@ static void rxk_input (struct mbuf *am, int iphlen)
                    m_adj(am, tlen - (int)ti->ip_len);
                }
                /* 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;
                taddr.sin_len = sizeof(taddr);
-               tvu = (struct udpiphdr *) ti;   /* virtual udp structure, for cksum */
+               tvu = (struct udpiphdr *)ti;    /* virtual udp structure, for cksum */
                /* 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 */
-               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
-                        * DMA hardware, etc!) is error-free. First, fill
-                        * in entire virtual ip header. */
-                       tvu->ui_i.fill[0] = 0;
-                       tvu->ui_i.fill[1] = 0;
-                       tvu->ui_x1 = 0;
-                       tvu->ui_len = tvu->ui_ulen;
-                       tlen = ntohs((unsigned short)(tvu->ui_ulen));
-                       if (in_cksum(am, sizeof(struct ip) + tlen)) {
-                           /* checksum, including cksum field, doesn't come out 0, so
-                              this packet is bad */
-                           m_freem(am);
-                           USERPRI;
-                           return;
-                       }
-                     }
+                * header (replacing it with the virtual one, which is the same size),
+                * so we must ensure we get everything out we need, first */
+               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
+                    * DMA hardware, etc!) is error-free. First, fill
+                    * in entire virtual ip header. */
+                   tvu->ui_i.fill[0] = 0;
+                   tvu->ui_i.fill[1] = 0;
+                   tvu->ui_x1 = 0;
+                   tvu->ui_len = tvu->ui_ulen;
+                   tlen = ntohs((unsigned short)(tvu->ui_ulen));
+                   if (in_cksum(am, sizeof(struct ip) + tlen)) {
+                       /* checksum, including cksum field, doesn't come out 0, so
+                        * this packet is bad */
+                       m_freem(am);
+                       USERPRI;
+                       return;
+                   }
+               }
 
                /*
                 * 28 is IP (20) + UDP (8) header.  ulen includes
@@ -140,25 +144,26 @@ static void rxk_input (struct mbuf *am, int iphlen)
                data_len = ntohs(tu->uh_ulen);
                data_len -= 8;
                AFS_RXGLOCK();
-               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,
-                                            rxk_portRocks[i], data_len);
-               }else m_freem(am);
+               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,
+                                                 rxk_portRocks[i], data_len);
+               } else
+                   m_freem(am);
                AFS_RXGUNLOCK();
                USERPRI;
                return;
-               }
            }
        }
+    }
 
     /* if we get here, try to deliver packet to udp */
-    if (tproc = parent_proto.pr_input) (*tproc)(am,iphlen);
+    if (tproc = parent_proto.pr_input)
+       (*tproc) (am, iphlen);
     USERPRI;
     return;
 }
@@ -169,14 +174,16 @@ static void rxk_input (struct mbuf *am, int iphlen)
  * Called about 5 times per second (at unknown priority?).  Must go to
  * splnet or obtain global lock before touching anything significant.
  */
-static void rxk_fasttimo (void)
+static void
+rxk_fasttimo(void)
 {
-    void (*tproc)();
+    void (*tproc) ();
     struct clock temp;
 
     /* do rx fasttimo processing here */
     rxevent_RaiseEvents(&temp);
-    if (tproc = parent_proto.pr_fasttimo) (*tproc)();
+    if (tproc = parent_proto.pr_fasttimo)
+       (*tproc) ();
 }
 
 
@@ -198,19 +205,21 @@ static void rxk_fasttimo (void)
 
 /* set lock on sockbuf sb; can't call sblock since we're at interrupt level
  * sometimes */
-static trysblock(sb)    
-register struct sockbuf *sb; {
+static
+trysblock(sb)
+     register struct sockbuf *sb;
+{
     AFS_STATCNT(trysblock);
-    if (sb->sb_flags & SB_LOCK){
-       return -1;  /* can't lock socket */
+    if (sb->sb_flags & SB_LOCK) {
+       return -1;              /* can't lock socket */
     }
     sb->sb_flags |= SB_LOCK;
     return 0;
 }
 
-int 
-osi_NetSend(osi_socket asocket, struct sockaddr_in *addr,
-           struct iovec *dvec, int nvec, afs_int32 asize, int istack)
+int
+osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
+           int nvec, afs_int32 asize, int istack)
 {
     register struct mbuf *tm, *um;
     register afs_int32 code;
@@ -220,7 +229,7 @@ osi_NetSend(osi_socket asocket, struct sockaddr_in *addr,
     int len;
     char *tdata;
     caddr_t tpa;
-    int i,tl,rlen;
+    int i, tl, rlen;
     int mlen;
     int haveGlock;
 
@@ -238,20 +247,21 @@ osi_NetSend(osi_socket asocket, struct sockaddr_in *addr,
     tl = dvec[i].iov_len;
     while (1) {
        mlen = MLEN;
-        if (top == 0) {
-            MGETHDR(m, M_DONTWAIT, MT_DATA);
-            if (!m) {
-                splx(s);
-                return 1;
-            }
-            mlen = MHLEN;
-            m->m_pkthdr.len = 0;
-            m->m_pkthdr.rcvif = NULL;
-        } else
-       MGET(m, M_DONTWAIT, MT_DATA);
+       if (top == 0) {
+           MGETHDR(m, M_DONTWAIT, MT_DATA);
+           if (!m) {
+               splx(s);
+               return 1;
+           }
+           mlen = MHLEN;
+           m->m_pkthdr.len = 0;
+           m->m_pkthdr.rcvif = NULL;
+       } else
+           MGET(m, M_DONTWAIT, MT_DATA);
        if (!m) {
            /* can't get an mbuf, give up */
-           if (top) m_freem(top);      /* free mbuf list we're building */
+           if (top)
+               m_freem(top);   /* free mbuf list we're building */
            splx(s);
            return 1;
        }
@@ -269,46 +279,46 @@ osi_NetSend(osi_socket asocket, struct sockaddr_in *addr,
            register struct mbuf *p;
 
            /* different algorithms for getting cluster mbuf */
-            MCLGET(m, M_DONTWAIT);
-            if ((m->m_flags & M_EXT) == 0)
-                goto nopages;
-            mlen = MCLBYTES;
+           MCLGET(m, M_DONTWAIT);
+           if ((m->m_flags & M_EXT) == 0)
+               goto nopages;
+           mlen = MCLBYTES;
 
            /* now compute usable size */
-            len = MIN(mlen, asize);
+           len = MIN(mlen, asize);
 /* Should I look at MAPPED_MBUFS??? */
        } else {
-nopages:
-            len = MIN(mlen, asize);
+         nopages:
+           len = MIN(mlen, asize);
        }
        m->m_len = 0;
-        *mp = m;       /* XXXX */
-        top->m_pkthdr.len += len;
+       *mp = m;                /* XXXX */
+       top->m_pkthdr.len += len;
        tpa = mtod(m, caddr_t);
        while (len) {
-         rlen = MIN(len, tl);
-         memcpy(tpa, tdata, rlen);
-         asize -= rlen;
-         len -= rlen;
-         tpa += rlen;
-         m->m_len += rlen;
-         tdata += rlen;
-         tl -= rlen;
-         if (tl <= 0) {
-           i++;
-           if (i > nvec) {
-             /* shouldn't come here! */
-             asize = 0;   /* so we make progress toward completion */
-             break;
+           rlen = MIN(len, tl);
+           memcpy(tpa, tdata, rlen);
+           asize -= rlen;
+           len -= rlen;
+           tpa += rlen;
+           m->m_len += rlen;
+           tdata += rlen;
+           tl -= rlen;
+           if (tl <= 0) {
+               i++;
+               if (i > nvec) {
+                   /* shouldn't come here! */
+                   asize = 0;  /* so we make progress toward completion */
+                   break;
+               }
+               tdata = dvec[i].iov_base;
+               tl = dvec[i].iov_len;
            }
-           tdata = dvec[i].iov_base;
-           tl = dvec[i].iov_len;
-         }
        }
        *mp = m;
        mp = &m->m_next;
        if (asize <= 0)
-         break;
+           break;
     }
     tm = top;
 
@@ -317,9 +327,10 @@ nopages:
     /* setup mbuf corresponding to destination address */
     um = m_get(M_DONTWAIT, MT_SONAME);
     if (!um) {
-       if (top) m_freem(top);  /* free mbuf chain */
+       if (top)
+           m_freem(top);       /* free mbuf chain */
        /* if this were vfs40, we'd do sbunlock(asocket, &asocket->so_snd), but
-          we don't do the locking at all for vfs40 systems */
+        * we don't do the locking at all for vfs40 systems */
        splx(s);
        return 1;
     }
@@ -332,7 +343,7 @@ nopages:
        AFS_GUNLOCK();
     }
     SOCKET_LOCK(asocket);
-    code = (*asocket->so_proto->pr_usrreq)(asocket, PRU_SEND, tm, um, 0);
+    code = (*asocket->so_proto->pr_usrreq) (asocket, PRU_SEND, tm, um, 0);
     SOCKET_UNLOCK(asocket);
     if (haveGlock) {
        AFS_GLOCK();