Hi,

Simplify tcp_input() by using the address family passed by pr_input.

ok?

bluhm

Index: netinet/tcp_input.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.339
diff -u -p -r1.339 tcp_input.c
--- netinet/tcp_input.c 14 Apr 2017 20:46:31 -0000      1.339
+++ netinet/tcp_input.c 16 Apr 2017 15:44:55 -0000
@@ -359,7 +359,7 @@ tcp_input(struct mbuf **mp, int *offp, i
 {
        struct mbuf *m = *mp;
        int iphlen = *offp;
-       struct ip *ip;
+       struct ip *ip = NULL;
        struct inpcb *inp = NULL;
        u_int8_t *optp = NULL;
        int optlen = 0;
@@ -399,51 +399,9 @@ tcp_input(struct mbuf **mp, int *offp, i
                goto drop;
 
        /*
-        * Before we do ANYTHING, we have to figure out if it's TCP/IPv6 or
-        * TCP/IPv4.
-        */
-       switch (mtod(m, struct ip *)->ip_v) {
-#ifdef INET6
-       case 6:
-               af = AF_INET6;
-               break;
-#endif
-       case 4:
-               af = AF_INET;
-               break;
-       default:
-               m_freem(m);
-               return IPPROTO_DONE;
-       }
-
-       /*
         * Get IP and TCP header together in first mbuf.
         * Note: IP leaves IP header in first mbuf.
         */
-       switch (af) {
-       case AF_INET:
-#ifdef DIAGNOSTIC
-               if (iphlen < sizeof(struct ip)) {
-                       m_freem(m);
-                       return IPPROTO_DONE;
-               }
-#endif /* DIAGNOSTIC */
-               break;
-#ifdef INET6
-       case AF_INET6:
-#ifdef DIAGNOSTIC
-               if (iphlen < sizeof(struct ip6_hdr)) {
-                       m_freem(m);
-                       return IPPROTO_DONE;
-               }
-#endif /* DIAGNOSTIC */
-               break;
-#endif
-       default:
-               m_freem(m);
-               return IPPROTO_DONE;
-       }
-
        IP6_EXTHDR_GET(th, struct tcphdr *, m, iphlen, sizeof(*th));
        if (!th) {
                tcpstat_inc(tcps_rcvshort);
@@ -451,10 +409,6 @@ tcp_input(struct mbuf **mp, int *offp, i
        }
 
        tlen = m->m_pkthdr.len - iphlen;
-       ip = NULL;
-#ifdef INET6
-       ip6 = NULL;
-#endif
        switch (af) {
        case AF_INET:
                ip = mtod(m, struct ip *);
@@ -497,6 +451,8 @@ tcp_input(struct mbuf **mp, int *offp, i
                }
                break;
 #endif
+       default:
+               unhandled_af(af);
        }
 
        /*

Reply via email to