inpcb: Factor out ASSERT_INP_NOTINHASH
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 3 Oct 2014 12:42:02 +0000 (20:42 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 3 Oct 2014 12:42:02 +0000 (20:42 +0800)
sys/netinet/in_pcb.c
sys/netinet/in_pcb.h
sys/netinet/tcp_usrreq.c

index ab03d19..ba763a4 100644 (file)
@@ -1663,8 +1663,7 @@ in_pcbinsconnhash(struct inpcb *inp)
 
        KASSERT(&curthread->td_msgport == netisr_cpuport(pcbinfo->cpu),
            ("not in the correct netisr"));
-       KASSERT(!(inp->inp_flags & INP_WILDCARD), ("already on wildcardhash"));
-       KASSERT(!(inp->inp_flags & INP_CONNECTED), ("already on connhash"));
+       ASSERT_INP_NOTINHASH(inp);
        inp->inp_flags |= INP_CONNECTED;
 
        /*
@@ -2025,10 +2024,7 @@ in_pcbinswildcardhash(struct inpcb *inp)
 
        KASSERT(&curthread->td_msgport == netisr_cpuport(pcbinfo->cpu),
            ("not in correct netisr"));
-       KASSERT(!(inp->inp_flags & INP_CONNECTED),
-               ("already on connhash"));
-       KASSERT(!(inp->inp_flags & INP_WILDCARD),
-               ("already on wildcardhash"));
+       ASSERT_INP_NOTINHASH(inp);
        inp->inp_flags |= INP_WILDCARD;
 
        in_pcbinswildcardhash_oncpu(inp, pcbinfo);
index cfbe1ae..416206d 100644 (file)
@@ -465,6 +465,18 @@ do { \
 #define ASSERT_PCBINFO_TOKEN_HELD(pcbinfo)
 #endif /* INVARIANTS */
 
+#ifdef INVARIANTS
+#define ASSERT_INP_NOTINHASH(inp) \
+do { \
+       KASSERT(!((inp)->inp_flags & INP_CONNECTED), \
+           ("already on connhash")); \
+       KASSERT(!((inp)->inp_flags & INP_WILDCARD), \
+           ("already on wildcardhash")); \
+} while (0)
+#else  /* !INVARIANTS */
+#define ASSERT_INP_NOTINHASH(inp)
+#endif /* INVARIANTS */
+
 extern int     ipport_lowfirstauto;
 extern int     ipport_lowlastauto;
 extern int     ipport_firstauto;
index 2be1bf0..184d232 100644 (file)
@@ -436,11 +436,7 @@ tcp_usr_listen(netmsg_t msg)
                /*
                 * Put this inpcb into wildcard hash on other cpus.
                 */
-               KASSERT(!(inp->inp_flags & INP_CONNECTED),
-                       ("already on connhash"));
-               KASSERT(!(inp->inp_flags & INP_WILDCARD),
-                       ("already on wildcardhash"));
-
+               ASSERT_INP_NOTINHASH(inp);
                netmsg_init(&nm.base, NULL, &curthread->td_msgport,
                            MSGF_PRIORITY, in_pcbinswildcardhash_handler);
                nm.nm_inp = inp;
@@ -485,14 +481,10 @@ tcp6_usr_listen(netmsg_t msg)
                /*
                 * Put this inpcb into wildcard hash on other cpus.
                 */
-               KASSERT(!(inp->inp_flags & INP_CONNECTED),
-                       ("already on connhash"));
-               KASSERT(!(inp->inp_flags & INP_WILDCARD),
-                       ("already on wildcardhash"));
-
                KKASSERT(so->so_port == netisr_cpuport(0));
                KKASSERT(&curthread->td_msgport == netisr_cpuport(0));
                KKASSERT(inp->inp_pcbinfo == &tcbinfo[0]);
+               ASSERT_INP_NOTINHASH(inp);
 
                netmsg_init(&nm.base, NULL, &curthread->td_msgport,
                            MSGF_PRIORITY, in_pcbinswildcardhash_handler);