new syslog
[unix-history] / usr / src / sys / deprecated / netimp / if_imphost.c
index d4a8d36..23ead64 100644 (file)
@@ -1,18 +1,30 @@
-/*     if_imphost.c    4.16    82/12/14        */
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)if_imphost.c        6.7 (Berkeley) %G%
+ */
 
 #include "imp.h"
 #if NIMP > 0
 /*
  * Host table manipulation routines.
  * Only needed when shipping stuff through an IMP.
 
 #include "imp.h"
 #if NIMP > 0
 /*
  * Host table manipulation routines.
  * Only needed when shipping stuff through an IMP.
+ *
+ * Everything in here is called at splimp from
+ * from the IMP protocol code (if_imp.c), or
+ * interlocks with the code at splimp.
  */
  */
+#include "param.h"
+#include "mbuf.h"
+#include "syslog.h"
 
 
-#include "../h/param.h"
-#include "../h/mbuf.h"
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
-#include "../netimp/if_imp.h"
-#include "../netimp/if_imphost.h"
+
+#include "if_imp.h"
+#include "if_imphost.h"
 
 /*
  * Head of host table hash chains.
 
 /*
  * Head of host table hash chains.
@@ -30,19 +42,15 @@ hostlookup(addr)
        register struct host *hp;
        register struct mbuf *m;
        register int hash = HOSTHASH(addr);
        register struct host *hp;
        register struct mbuf *m;
        register int hash = HOSTHASH(addr);
-       int s = splnet();
 
        for (m = hosts; m; m = m->m_next) {
                hp = &mtod(m, struct hmbuf *)->hm_hosts[hash];
                if (hp->h_addr.s_addr == addr.s_addr) {
                        hp->h_flags |= HF_INUSE;
 
        for (m = hosts; m; m = m->m_next) {
                hp = &mtod(m, struct hmbuf *)->hm_hosts[hash];
                if (hp->h_addr.s_addr == addr.s_addr) {
                        hp->h_flags |= HF_INUSE;
-                       goto found;
+                       return (hp);
                }
        }
                }
        }
-       hp = 0;
-found:
-       splx(s);
-       return (hp);
+       return ((struct host *)0);
 }
 
 /*
 }
 
 /*
@@ -57,7 +65,6 @@ hostenter(addr)
        register struct mbuf *m, **mprev;
        register struct host *hp, *hp0 = 0;
        register int hash = HOSTHASH(addr);
        register struct mbuf *m, **mprev;
        register struct host *hp, *hp0 = 0;
        register int hash = HOSTHASH(addr);
-       int s = splnet();
 
        mprev = &hosts;
        while (m = *mprev) {
 
        mprev = &hosts;
        while (m = *mprev) {
@@ -81,10 +88,8 @@ hostenter(addr)
         */
        if (hp0 == 0) {
                m = m_getclr(M_DONTWAIT, MT_HTABLE);
         */
        if (hp0 == 0) {
                m = m_getclr(M_DONTWAIT, MT_HTABLE);
-               if (m == 0) {
-                       splx(s);
-                       return (0);
-               }
+               if (m == NULL)
+                       return ((struct host *)0);
                *mprev = m;
                hp0 = &mtod(m, struct hmbuf *)->hm_hosts[hash];
        }
                *mprev = m;
                hp0 = &mtod(m, struct hmbuf *)->hm_hosts[hash];
        }
@@ -96,7 +101,6 @@ hostenter(addr)
 
 foundhost:
        hp->h_flags |= HF_INUSE;
 
 foundhost:
        hp->h_flags |= HF_INUSE;
-       splx(s);
        return (hp);
 }
 
        return (hp);
 }
 
@@ -107,44 +111,41 @@ foundhost:
 hostfree(hp)                               
        register struct host *hp;
 {
 hostfree(hp)                               
        register struct host *hp;
 {
-       int s = splnet();
 
        hp->h_flags &= ~HF_INUSE;
        hp->h_timer = HOSTTIMER;
        hp->h_rfnm = 0;
 
        hp->h_flags &= ~HF_INUSE;
        hp->h_timer = HOSTTIMER;
        hp->h_rfnm = 0;
-       splx(s);
 }
 
 /*
  * Reset a given network's host entries.
  */
 hostreset(net)     
 }
 
 /*
  * Reset a given network's host entries.
  */
 hostreset(net)     
-       int net;
+       u_long net;
 {
        register struct mbuf *m;
        register struct host *hp, *lp;
        struct hmbuf *hm;
 {
        register struct mbuf *m;
        register struct host *hp, *lp;
        struct hmbuf *hm;
-       int s = splnet();
+       struct mbuf *mnext;
 
 
-       for (m = hosts; m; m = m->m_next) {
+       for (m = hosts; m; m = mnext) {
+               mnext = m->m_next;
                hm = mtod(m, struct hmbuf *);
                hp = hm->hm_hosts; 
                lp = hp + HPMBUF;
                while (hm->hm_count > 0 && hp < lp) {
                hm = mtod(m, struct hmbuf *);
                hp = hm->hm_hosts; 
                lp = hp + HPMBUF;
                while (hm->hm_count > 0 && hp < lp) {
-                       if (hp->h_addr.s_net == net) {
+                       if (in_netof(hp->h_addr) == net) {
                                hp->h_flags &= ~HF_INUSE;
                                hostrelease(hp);
                        }
                        hp++;
                }
        }
                                hp->h_flags &= ~HF_INUSE;
                                hostrelease(hp);
                        }
                        hp++;
                }
        }
-       splx(s);
 }
 
 /*
  * Remove a host structure and release
  * any resources it's accumulated.
 }
 
 /*
  * Remove a host structure and release
  * any resources it's accumulated.
- * This routine is always called at splnet.
  */
 hostrelease(hp)
        register struct host *hp;
  */
 hostrelease(hp)
        register struct host *hp;
@@ -165,6 +166,7 @@ hostrelease(hp)
                hp->h_q = 0;
        }
        hp->h_flags = 0;
                hp->h_q = 0;
        }
        hp->h_flags = 0;
+       hp->h_rfnm = 0;
        if (--mtod(mh, struct hmbuf *)->hm_count)
                return;
        mprev = &hosts;
        if (--mtod(mh, struct hmbuf *)->hm_count)
                return;
        mprev = &hosts;
@@ -204,18 +206,24 @@ hostslowtimo()
        register struct mbuf *m;
        register struct host *hp, *lp;
        struct hmbuf *hm;
        register struct mbuf *m;
        register struct host *hp, *lp;
        struct hmbuf *hm;
-       int s = splnet();
+       struct mbuf *mnext;
+       int s = splimp();
 
 
-       for (m = hosts; m; m = m->m_next) {
+       for (m = hosts; m; m = mnext) {
+               mnext = m->m_next;
                hm = mtod(m, struct hmbuf *);
                hp = hm->hm_hosts; 
                lp = hp + HPMBUF;
                for (; hm->hm_count > 0 && hp < lp; hp++) {
                hm = mtod(m, struct hmbuf *);
                hp = hm->hm_hosts; 
                lp = hp + HPMBUF;
                for (; hm->hm_count > 0 && hp < lp; hp++) {
-                       if (hp->h_flags & HF_INUSE)
-                               continue;
-                       if (hp->h_timer && --hp->h_timer == 0)
+                       if (hp->h_timer && --hp->h_timer == 0) {
+                               if (hp->h_rfnm)
+                                   log(LOG_WARNING,
+                                       "imp?: host %x, lost %d rfnms\n",
+                                       ntohl(hp->h_addr.s_addr), hp->h_rfnm);
                                hostrelease(hp);
                                hostrelease(hp);
+                       }
                }
        }
        splx(s);
 }
                }
        }
        splx(s);
 }
+#endif