Fix to ensure that the correct MSS is advertised for loopback

TCP connections by using the MTU of the interface.  Also added
a knob, mss_ifmtu, to force all connections to use the MTU of
the interface to calculate the advertised MSS.
This commit is contained in:
kml 1998-04-13 21:18:19 +00:00
parent 77a346fea2
commit fcf0227962
7 changed files with 53 additions and 21 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: sysctl.3,v 1.23 1998/02/05 18:48:01 perry Exp $
.\" $NetBSD: sysctl.3,v 1.24 1998/04/13 21:24:49 kml Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@ -499,6 +499,7 @@ The currently defined protocols and names are:
.It tcp syn_bucket_limit integer yes
.It tcp syn_cache_interval integer yes
.It tcp init_win integer yes
.It tcp mss_ifmtu integer yes
.It udp checksum integer yes
.It udp sendspace integer yes
.It udp recvspace integer yes
@ -555,6 +556,11 @@ Returns the TCP compressed state engine's timer interval.
If greater than 0, returns the number of segments used for the inital
slow start congestion window. A value of 0 indicates that an experimental
auto-tuning algorithm is being used to compute the initial window.
.It Li tcp.mss_ifmtu
If greater than 0, calculate the outgoing MSS based on the MTU of
the appropriate interface. Otherwise, calculate it based on
the greater of the MTU of the interface, and the largest (non-loopback)
interface MTU on the system.
.It Li udp.checksum
Returns 1 when UDP checksums are being computed and checked.
Disabling UDP checksums is strongly discouraged.

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_input.c,v 1.50 1998/04/07 05:09:19 thorpej Exp $ */
/* $NetBSD: tcp_input.c,v 1.51 1998/04/13 21:18:19 kml Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -2160,7 +2160,8 @@ syn_cache_add(so, m, optp, optlen, oi)
sc->sc_irs = ti->ti_seq;
sc->sc_iss = tcp_new_iss(sc, sizeof(struct syn_cache), 0);
sc->sc_peermaxseg = oi->maxseg;
sc->sc_ourmaxseg = tcp_mss_to_advertise(tp);
sc->sc_ourmaxseg = tcp_mss_to_advertise(m->m_flags & M_PKTHDR ?
m->m_pkthdr.rcvif : NULL);
if (tcp_do_rfc1323 && (tb.t_flags & TF_RCVD_TSTMP))
sc->sc_flags |= SCF_TIMESTAMP;
if ((tb.t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_output.c,v 1.33 1998/04/01 22:15:52 thorpej Exp $ */
/* $NetBSD: tcp_output.c,v 1.34 1998/04/13 21:18:19 kml Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -394,8 +394,11 @@ send:
optlen = 0;
hdrlen = sizeof (struct tcpiphdr);
if (flags & TH_SYN) {
struct rtentry *rt = in_pcbrtentry(tp->t_inpcb);
tp->snd_nxt = tp->iss;
tp->t_ourmss = tcp_mss_to_advertise(tp);
tp->t_ourmss = tcp_mss_to_advertise(rt != NULL ?
rt->rt_ifp : NULL);
if ((tp->t_flags & TF_NOOPT) == 0) {
opt[0] = TCPOPT_MAXSEG;
opt[1] = 4;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_subr.c,v 1.46 1998/03/31 22:49:10 thorpej Exp $ */
/* $NetBSD: tcp_subr.c,v 1.47 1998/04/13 21:18:19 kml Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -110,6 +110,7 @@ int tcp_mssdflt = TCP_MSS;
int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
int tcp_do_rfc1323 = 1;
int tcp_init_win = 1;
int tcp_mss_ifmtu = 0;
#ifndef TCBHASHSIZE
#define TCBHASHSIZE 128
@ -589,25 +590,38 @@ tcp_mtudisc(inp, errno)
* socket. If we are the client (we initiated connection), we
* are called witht he TCPCB for the actual connection.
*/
int
tcp_mss_to_advertise(tp)
const struct tcpcb *tp;
u_long
tcp_mss_to_advertise(ifp)
const struct ifnet *ifp;
{
extern u_long in_maxmtu;
struct inpcb *inp;
struct socket *so;
int mss;
inp = tp->t_inpcb;
so = inp->inp_socket;
u_long mss = 0;
/*
* In order to avoid defeating path MTU discovery on the peer,
* we advertise the max MTU of all attached networks as our MSS,
* per RFC 1191, section 3.1.
*
* We provide the option to advertise just the MTU of
* the interface on which we hope this connection will
* be receiving. If we are responding to a SYN, we
* will have a pretty good idea about this, but when
* initiating a connection there is a bit more doubt.
*
* We also need to ensure that loopback has a large enough
* MSS, as the loopback MTU is never included in in_maxmtu.
*/
mss = in_maxmtu - sizeof(struct tcpiphdr);
if (ifp != NULL)
mss = ifp->if_mtu;
if (tcp_mss_ifmtu == 0)
mss = max(in_maxmtu, mss);
if (mss > sizeof(struct tcpiphdr))
mss -= sizeof(struct tcpiphdr);
mss = max(tcp_mssdflt, mss);
return (mss);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_usrreq.c,v 1.34 1998/02/19 02:36:44 thorpej Exp $ */
/* $NetBSD: tcp_usrreq.c,v 1.35 1998/04/13 21:18:20 kml Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -635,6 +635,9 @@ tcp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
case TCPCTL_INIT_WIN:
return (sysctl_int(oldp, oldlenp, newp, newlen,
&tcp_init_win));
case TCPCTL_MSS_IFMTU:
return (sysctl_int(oldp, oldlenp, newp, newlen,
&tcp_mss_ifmtu));
default:
return (ENOPROTOOPT);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_var.h,v 1.40 1998/04/07 05:09:20 thorpej Exp $ */
/* $NetBSD: tcp_var.h,v 1.41 1998/04/13 21:18:20 kml Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -373,7 +373,8 @@ struct tcpstat {
#define TCPCTL_SYN_BUCKET_LIMIT 6 /* max size of hash bucket */
#define TCPCTL_SYN_CACHE_INTER 7 /* interval of comp. state timer */
#define TCPCTL_INIT_WIN 8 /* initial window */
#define TCPCTL_MAXID 9
#define TCPCTL_MSS_IFMTU 9 /* mss from interface, not in_maxmtu */
#define TCPCTL_MAXID 10
#define TCPCTL_NAMES { \
{ 0, 0 }, \
@ -385,6 +386,7 @@ struct tcpstat {
{ "syn_bucket_limit", CTLTYPE_INT }, \
{ "syn_cache_interval", CTLTYPE_INT },\
{ "init_win", CTLTYPE_INT }, \
{ "mss_ifmtu", CTLTYPE_INT }, \
}
#ifdef _KERNEL
@ -394,6 +396,7 @@ u_int32_t tcp_now; /* for RFC 1323 timestamps */
extern int tcp_do_rfc1323; /* enabled/disabled? */
extern int tcp_mssdflt; /* default seg size */
extern int tcp_init_win; /* initial window */
extern int tcp_mss_ifmtu; /* take MSS from interface, not in_maxmtu */
extern int tcp_syn_cache_limit; /* max entries for compressed state engine */
extern int tcp_syn_bucket_limit;/* max entries per hash bucket */
extern int tcp_syn_cache_interval; /* compressed state timer */
@ -420,7 +423,7 @@ void tcp_established __P((struct tcpcb *));
void tcp_fasttimo __P((void));
void tcp_init __P((void));
void tcp_input __P((struct mbuf *, ...));
int tcp_mss_to_advertise __P((const struct tcpcb *));
u_long tcp_mss_to_advertise __P((const struct ifnet *));
void tcp_mss_from_peer __P((struct tcpcb *, int));
void tcp_mtudisc __P((struct inpcb *, int));
struct tcpcb *

View File

@ -1,4 +1,4 @@
.\" $NetBSD: sysctl.8,v 1.19 1998/02/06 06:23:56 perry Exp $
.\" $NetBSD: sysctl.8,v 1.20 1998/04/13 21:21:13 kml Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@ -153,6 +153,8 @@ privilege can change the value.
.It net.inet.tcp.syn_bucket_limit integer yes
.It net.inet.tcp.syn_cache_interval integer yes
.It net.inet.tcp.init_win integer yes
.It net.inet.tcp.init_win integer yes
.It net.inet.tcp.mss_ifmtu integer yes
.It net.inet.udp.checksum integer yes
.It net.inet.udp.sendspace integer yes
.It net.inet.udp.recvspace integer yes