Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Use proper ip protocol # field and tcp hdr on se...



details:   https://anonhg.NetBSD.org/src/rev/e6042d924704
branches:  trunk
changeset: 474667:e6042d924704
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Jul 14 22:37:13 1999 +0000

description:
Use proper ip protocol # field and tcp hdr on sending RST against SYN,
when ip header and tcp header are not adjacent to each other
(i.e. when ip6 options are attached).

To test this, try
        telnet @::1@::1 port
toward a port without responding server.  Prior to the fix, the kernel will
generate broken RST packet.

diffstat:

 sys/netinet/tcp_input.c |   8 ++++----
 sys/netinet/tcp_subr.c  |  10 +++++++---
 sys/netinet/tcp_timer.c |   6 +++---
 sys/netinet/tcp_var.h   |   6 +++---
 4 files changed, 17 insertions(+), 13 deletions(-)

diffs (117 lines):

diff -r 55cbfe0efed0 -r e6042d924704 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Wed Jul 14 22:35:20 1999 +0000
+++ b/sys/netinet/tcp_input.c   Wed Jul 14 22:37:13 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.85 1999/07/09 22:57:20 thorpej Exp $   */
+/*     $NetBSD: tcp_input.c,v 1.86 1999/07/14 22:37:13 itojun Exp $    */
 
 /*
 %%% portions-copyright-nrl-95
@@ -1989,11 +1989,11 @@
        }
     }
        if (tiflags & TH_ACK)
-               (void)tcp_respond(tp, m, m, (tcp_seq)0, th->th_ack, TH_RST);
+               (void)tcp_respond(tp, m, m, th, (tcp_seq)0, th->th_ack, TH_RST);
        else {
                if (tiflags & TH_SYN)
                        tlen++;
-               (void)tcp_respond(tp, m, m, th->th_seq + tlen, (tcp_seq)0,
+               (void)tcp_respond(tp, m, m, th, th->th_seq + tlen, (tcp_seq)0,
                    TH_RST|TH_ACK);
        }
        return;
@@ -2881,7 +2881,7 @@
        return (so);
 
 resetandabort:
-       (void) tcp_respond(NULL, m, m,
+       (void) tcp_respond(NULL, m, m, th,
                           th->th_seq + tlen, (tcp_seq)0, TH_RST|TH_ACK);
 abort:
        if (so != NULL)
diff -r 55cbfe0efed0 -r e6042d924704 sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c    Wed Jul 14 22:35:20 1999 +0000
+++ b/sys/netinet/tcp_subr.c    Wed Jul 14 22:37:13 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_subr.c,v 1.71 1999/07/14 22:08:52 drochner Exp $   */
+/*     $NetBSD: tcp_subr.c,v 1.72 1999/07/14 22:37:14 itojun Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -354,10 +354,11 @@
  * segment are as specified by the parameters.
  */
 int
-tcp_respond(tp, template, m, ack, seq, flags)
+tcp_respond(tp, template, m, th0, ack, seq, flags)
        struct tcpcb *tp;
-       struct mbuf *template;          /* XXX should be struct mbuf? */
+       struct mbuf *template;
        register struct mbuf *m;
+       struct tcphdr *th0;
        tcp_seq ack, seq;
        int flags;
 {
@@ -482,15 +483,18 @@
                        ip = mtod(m, struct ip *);
                        th = (struct tcphdr *)(ip + 1);
                        xchg(ip->ip_dst, ip->ip_src, struct in_addr);
+                       ip->ip_p = IPPROTO_TCP;
                        break;
 #ifdef INET6
                case AF_INET6:
                        ip6 = mtod(m, struct ip6_hdr *);
                        th = (struct tcphdr *)(ip6 + 1);
                        xchg(ip6->ip6_dst, ip6->ip6_src, struct in6_addr);
+                       ip6->ip6_nxt = IPPROTO_TCP;
                        break;
 #endif
                }
+               *th = *th0;
                xchg(th->th_dport, th->th_sport, u_int16_t);
 #undef xchg
        }
diff -r 55cbfe0efed0 -r e6042d924704 sys/netinet/tcp_timer.c
--- a/sys/netinet/tcp_timer.c   Wed Jul 14 22:35:20 1999 +0000
+++ b/sys/netinet/tcp_timer.c   Wed Jul 14 22:37:13 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_timer.c,v 1.44 1999/07/01 08:12:51 itojun Exp $    */
+/*     $NetBSD: tcp_timer.c,v 1.45 1999/07/14 22:37:15 itojun Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -493,11 +493,11 @@
                                 * length to get a 4.2 host to respond.
                                 */
                                (void)tcp_respond(tp, tp->t_template,
-                                   (struct mbuf *)NULL, tp->rcv_nxt - 1,
+                                   (struct mbuf *)NULL, NULL, tp->rcv_nxt - 1,
                                    tp->snd_una - 1, 0);
                        } else {
                                (void)tcp_respond(tp, tp->t_template,
-                                   (struct mbuf *)NULL, tp->rcv_nxt,
+                                   (struct mbuf *)NULL, NULL, tp->rcv_nxt,
                                    tp->snd_una - 1, 0);
                        }
                        TCP_TIMER_ARM(tp, TCPT_KEEP, tcp_keepintvl);
diff -r 55cbfe0efed0 -r e6042d924704 sys/netinet/tcp_var.h
--- a/sys/netinet/tcp_var.h     Wed Jul 14 22:35:20 1999 +0000
+++ b/sys/netinet/tcp_var.h     Wed Jul 14 22:37:13 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_var.h,v 1.62 1999/07/09 23:41:17 thorpej Exp $     */
+/*     $NetBSD: tcp_var.h,v 1.63 1999/07/14 22:37:15 itojun Exp $      */
 
 /*
 %%% portions-copyright-nrl-98
@@ -646,8 +646,8 @@
            struct tcphdr *, struct mbuf *));
 void    tcp_quench __P((struct inpcb *, int));
 int     tcp_reass __P((struct tcpcb *, struct tcphdr *, struct mbuf *, int *));
-int     tcp_respond __P((struct tcpcb *,
-           struct mbuf *, struct mbuf *, tcp_seq, tcp_seq, int));
+int     tcp_respond __P((struct tcpcb *, struct mbuf *, struct mbuf *,
+           struct tcphdr *, tcp_seq, tcp_seq, int));
 void    tcp_rmx_rtt __P((struct tcpcb *));
 void    tcp_setpersist __P((struct tcpcb *));
 void    tcp_slowtimo __P((void));



Home | Main Index | Thread Index | Old Index