network - Add debugging assertions
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 12 Sep 2010 20:14:23 +0000 (13:14 -0700)
committerMatthew Dillon <dillon@laptop2.(none)>
Sun, 12 Sep 2010 20:14:23 +0000 (13:14 -0700)
* Add some assertions to try to catch failure cases earlier.

sys/dev/netif/iwn/if_iwn.c
sys/kern/uipc_socket.c
sys/kern/uipc_socket2.c
sys/net/rtsock.c
sys/sys/socketvar.h

index 07db23a..981a363 100644 (file)
@@ -3381,6 +3381,7 @@ iwn_start_locked(struct ifnet *ifp)
                m = ifq_dequeue(&ifp->if_snd, NULL);
                if (m == NULL)
                        break;
+               KKASSERT(M_TRAILINGSPACE(m) >= 0);
                ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
                pri = M_WME_GETAC(m);
                txq = &sc->txq[pri];
index 60a9487..aa6b113 100644 (file)
@@ -322,6 +322,7 @@ sofree(struct socket *so)
                return;
 
        KKASSERT(so->so_pcb == NULL && (so->so_state & SS_NOFDREF));
+       KKASSERT((so->so_state & SS_ASSERTINPROG) == 0);
 
        /*
         * We're done, clean up
@@ -698,7 +699,7 @@ restart:
                            so->so_options &= ~SO_DONTROUTE;
                    clen = 0;
                    control = 0;
-                   top = 0;
+                   top = NULL;
                    mp = &top;
                    if (error)
                            goto release;
index 9abd2ae..3b4fa37 100644 (file)
@@ -241,10 +241,10 @@ soisconnected(struct socket *so)
                lwkt_gettoken(&head->so_rcv.ssb_token);
                TAILQ_REMOVE(&head->so_incomp, so, so_list);
                head->so_incqlen--;
-               soclrstate(so, SS_INCOMP);
                TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
                head->so_qlen++;
                sosetstate(so, SS_COMP);
+               soclrstate(so, SS_INCOMP);
                lwkt_reltoken(&head->so_rcv.ssb_token);
 
                sorwakeup(head);
@@ -337,7 +337,7 @@ sonewconn(struct socket *head, int connstatus)
         * NOTE: Clearing NOFDREF implies referencing the so with
         *       soreference().
         */
-       so->so_state = head->so_state | SS_NOFDREF;
+       so->so_state = head->so_state | SS_NOFDREF | SS_ASSERTINPROG;
        so->so_proto = head->so_proto;
        so->so_cred = crhold(head->so_cred);
        ai.sb_rlimit = NULL;
@@ -352,6 +352,7 @@ sonewconn(struct socket *head, int connstatus)
                      head->so_rcv.ssb_hiwat, NULL) ||
            (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, &ai)) {
                so->so_head = NULL;
+               soclrstate(so, SS_ASSERTINPROG);
                sofree(so);             /* remove implied pcb ref */
                return (NULL);
        }
@@ -390,6 +391,7 @@ sonewconn(struct socket *head, int connstatus)
                wakeup((caddr_t)&head->so_timeo);
                sosetstate(so, connstatus);
        }
+       soclrstate(so, SS_ASSERTINPROG);
        return (so);
 }
 
index 4dea0fd..2783b81 100644 (file)
@@ -1228,11 +1228,13 @@ rt_ieee80211msg(struct ifnet *ifp, int what, void *data, size_t data_len)
         * NB: we assume m is a single mbuf.
         */
        if (data_len > M_TRAILINGSPACE(m)) {
+               /* XXX use m_getb(data_len, MB_DONTWAIT, MT_DATA, 0); */
                struct mbuf *n = m_get(MB_DONTWAIT, MT_DATA);
                if (n == NULL) {
                        m_freem(m);
                        return;
                }
+               KKASSERT(data_len <= M_TRAILINGSPACE(n));
                bcopy(data, mtod(n, void *), data_len);
                n->m_len = data_len;
                m->m_next = n;
index afe7bb9..de6ec7b 100644 (file)
@@ -169,7 +169,7 @@ struct socket {
 #define        SS_CANTRCVMORE          0x0020  /* can't receive more data from peer */
 #define        SS_RCVATMARK            0x0040  /* at mark on input */
 
-#define        SS_UNUSED0100           0x0100
+#define        SS_ASSERTINPROG         0x0100  /* sonewconn race debugging */
 #define        SS_ASYNC                0x0200  /* async i/o notify */
 #define        SS_ISCONFIRMING         0x0400  /* deciding to accept connection req */