Pull SYN_cache_branch down into the main line.

This commit is contained in:
thorpej 1997-07-23 21:26:40 +00:00
parent 70e9bf3e24
commit efa8881dbe
9 changed files with 952 additions and 188 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: in.c,v 1.34 1997/03/15 18:12:36 is Exp $ */
/* $NetBSD: in.c,v 1.35 1997/07/23 21:26:40 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1991, 1993
@ -128,6 +128,32 @@ in_socktrim(ap)
}
}
/*
* Maintain the "in_maxmtu" variable, which is the largest
* mtu for non-local interfaces with AF_INET addresses assigned
* to them that are up.
*/
unsigned long in_maxmtu;
void
in_setmaxmtu()
{
register struct in_ifaddr *ia;
register struct ifnet *ifp;
unsigned long maxmtu = 0;
for (ia = in_ifaddr.tqh_first; ia != 0; ia = ia->ia_list.tqe_next) {
if ((ifp = ia->ia_ifp) == 0)
continue;
if ((ifp->if_flags & (IFF_UP|IFF_LOOPBACK)) != IFF_UP)
continue;
if (ifp->if_mtu > maxmtu)
maxmtu = ifp->if_mtu;
}
if (maxmtu)
in_maxmtu = maxmtu;
}
int in_interfaces; /* number of external internet interfaces */
/*
@ -305,6 +331,7 @@ in_control(so, cmd, data, ifp, p)
TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
TAILQ_REMOVE(&in_ifaddr, ia, ia_list);
IFAFREE((&ia->ia_ifa));
in_setmaxmtu();
break;
#ifdef MROUTING
@ -316,7 +343,9 @@ in_control(so, cmd, data, ifp, p)
default:
if (ifp == 0 || ifp->if_ioctl == 0)
return (EOPNOTSUPP);
return ((*ifp->if_ioctl)(ifp, cmd, data));
error = (*ifp->if_ioctl)(ifp, cmd, data);
in_setmaxmtu();
return(error);
}
return (0);
}
@ -373,6 +402,7 @@ in_ifinit(ifp, ia, sin, scrub)
in_ifscrub(ifp, ia);
ia->ia_ifa.ifa_addr = sintosa(&ia->ia_addr);
}
if (IN_CLASSA(i))
ia->ia_netmask = IN_CLASSA_NET;
else if (IN_CLASSB(i))
@ -389,9 +419,12 @@ in_ifinit(ifp, ia, sin, scrub)
ia->ia_sockmask.sin_addr.s_addr = ia->ia_subnetmask;
} else
ia->ia_netmask &= ia->ia_subnetmask;
ia->ia_net = i & ia->ia_netmask;
ia->ia_subnet = i & ia->ia_subnetmask;
in_socktrim(&ia->ia_sockmask);
/* re-calculate the "in_maxmtu" value */
in_setmaxmtu();
/*
* Add route for the network.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_pcb.c,v 1.36 1996/12/10 11:38:42 mycroft Exp $ */
/* $NetBSD: in_pcb.c,v 1.37 1997/07/23 21:26:42 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1991, 1993
@ -403,7 +403,7 @@ in_setpeeraddr(inp, nam)
*
* Must be called at splsoftnet.
*/
void
int
in_pcbnotify(table, faddr, fport_arg, laddr, lport_arg, errno, notify)
struct inpcbtable *table;
struct in_addr faddr, laddr;
@ -414,19 +414,24 @@ in_pcbnotify(table, faddr, fport_arg, laddr, lport_arg, errno, notify)
struct inpcbhead *head;
register struct inpcb *inp, *ninp;
u_int16_t fport = fport_arg, lport = lport_arg;
int nmatch;
if (in_nullhost(faddr) || notify == 0)
return;
return (0);
nmatch = 0;
head = INPCBHASH_CONNECT(table, faddr, fport, laddr, lport);
for (inp = head->lh_first; inp != NULL; inp = ninp) {
ninp = inp->inp_hash.le_next;
if (in_hosteq(inp->inp_faddr, faddr) &&
inp->inp_fport == fport &&
inp->inp_lport == lport &&
in_hosteq(inp->inp_laddr, laddr))
in_hosteq(inp->inp_laddr, laddr)) {
(*notify)(inp, errno);
nmatch++;
}
}
return (nmatch);
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_pcb.h,v 1.19 1997/01/11 05:21:09 thorpej Exp $ */
/* $NetBSD: in_pcb.h,v 1.20 1997/07/23 21:26:44 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993
@ -105,7 +105,7 @@ struct inpcb *
struct inpcb *
in_pcblookup_connect __P((struct inpcbtable *,
struct in_addr, u_int, struct in_addr, u_int));
void in_pcbnotify __P((struct inpcbtable *, struct in_addr, u_int,
int in_pcbnotify __P((struct inpcbtable *, struct in_addr, u_int,
struct in_addr, u_int, int, void (*)(struct inpcb *, int)));
void in_pcbnotifyall __P((struct inpcbtable *, struct in_addr, int,
void (*)(struct inpcb *, int)));

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_proto.c,v 1.16 1996/10/10 23:04:26 christos Exp $ */
/* $NetBSD: in_proto.c,v 1.17 1997/07/23 21:26:46 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -197,3 +197,15 @@ struct domain hydomain =
{ AF_HYLINK, "hy", 0, 0, 0, hysw, &hysw[sizeof (hysw)/sizeof(hysw[0])] };
#endif
#endif
#define TCP_SYN_HASH_SIZE 293
#define TCP_SYN_BUCKET_SIZE 35
int tcp_syn_cache_size = TCP_SYN_HASH_SIZE;
int tcp_syn_cache_limit = TCP_SYN_HASH_SIZE*TCP_SYN_BUCKET_SIZE;
int tcp_syn_bucket_limit = 3*TCP_SYN_BUCKET_SIZE;
struct syn_cache_head tcp_syn_cache[TCP_SYN_HASH_SIZE];
struct syn_cache_head *tcp_syn_cache_first;
int tcp_syn_cache_interval = 8; /* runs timer every 4 seconds */
int tcp_syn_cache_timeo = TCPTV_KEEP_INIT;

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_var.h,v 1.17 1996/05/22 13:55:28 mycroft Exp $ */
/* $NetBSD: in_var.h,v 1.18 1997/07/23 21:26:47 thorpej Exp $ */
/*
* Copyright (c) 1985, 1986, 1993
@ -210,6 +210,7 @@ int in_ifinit __P((struct ifnet *,
struct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
void in_delmulti __P((struct in_multi *));
void in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
void in_setmaxmtu __P ((void));
int in_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
struct proc *));
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_subr.c,v 1.26 1997/06/24 02:26:06 thorpej Exp $ */
/* $NetBSD: tcp_subr.c,v 1.27 1997/07/23 21:26:51 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
@ -44,6 +44,7 @@
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <net/route.h>
#include <net/if.h>
@ -136,7 +137,7 @@ tcp_template(tp)
* In any case the ack and sequence number of the transmitted
* segment are as specified by the parameters.
*/
void
int
tcp_respond(tp, ti, m, ack, seq, flags)
struct tcpcb *tp;
register struct tcpiphdr *ti;
@ -155,7 +156,7 @@ tcp_respond(tp, ti, m, ack, seq, flags)
if (m == 0) {
m = m_gethdr(M_DONTWAIT, MT_HEADER);
if (m == NULL)
return;
return (ENOBUFS);
#ifdef TCP_COMPAT_42
tlen = 1;
#else
@ -176,27 +177,31 @@ tcp_respond(tp, ti, m, ack, seq, flags)
xchg(ti->ti_dport, ti->ti_sport, u_int16_t);
#undef xchg
}
ti->ti_len = htons((u_int16_t)(sizeof (struct tcphdr) + tlen));
tlen += sizeof (struct tcpiphdr);
m->m_len = tlen;
m->m_pkthdr.len = tlen;
m->m_pkthdr.rcvif = (struct ifnet *) 0;
bzero(ti->ti_x1, sizeof ti->ti_x1);
ti->ti_seq = htonl(seq);
ti->ti_ack = htonl(ack);
ti->ti_x2 = 0;
ti->ti_off = sizeof (struct tcphdr) >> 2;
if ((flags & TH_SYN) == 0) {
if (tp)
ti->ti_win = htons((u_int16_t) (win >> tp->rcv_scale));
else
ti->ti_win = htons((u_int16_t)win);
ti->ti_off = sizeof (struct tcphdr) >> 2;
tlen += sizeof (struct tcphdr);
} else
tlen += ti->ti_off << 2;
ti->ti_len = htons((u_int16_t)tlen);
tlen += sizeof (struct ip);
m->m_len = tlen;
m->m_pkthdr.len = tlen;
m->m_pkthdr.rcvif = (struct ifnet *) 0;
ti->ti_flags = flags;
if (tp)
ti->ti_win = htons((u_int16_t) (win >> tp->rcv_scale));
else
ti->ti_win = htons((u_int16_t)win);
ti->ti_urp = 0;
ti->ti_sum = 0;
ti->ti_sum = in_cksum(m, tlen);
((struct ip *)ti)->ip_len = tlen;
((struct ip *)ti)->ip_ttl = ip_defttl;
(void) ip_output(m, NULL, ro, 0, NULL);
return ip_output(m, NULL, ro, 0, NULL);
}
/*
@ -410,6 +415,7 @@ tcp_ctlinput(cmd, sa, v)
extern int inetctlerrmap[];
void (*notify) __P((struct inpcb *, int)) = tcp_notify;
int errno;
int nmatch;
if ((unsigned)cmd >= PRC_NCMDS)
return NULL;
@ -424,10 +430,15 @@ tcp_ctlinput(cmd, sa, v)
return NULL;
if (ip) {
th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
in_pcbnotify(&tcbtable, satosin(sa)->sin_addr, th->th_dport,
ip->ip_src, th->th_sport, errno, notify);
nmatch = in_pcbnotify(&tcbtable, satosin(sa)->sin_addr,
th->th_dport, ip->ip_src, th->th_sport, errno, notify);
if (nmatch == 0 && syn_cache_count &&
(inetctlerrmap[cmd] == EHOSTUNREACH ||
inetctlerrmap[cmd] == ENETUNREACH ||
inetctlerrmap[cmd] == EHOSTDOWN))
syn_cache_unreach(ip, th);
} else
in_pcbnotifyall(&tcbtable, satosin(sa)->sin_addr, errno,
(void)in_pcbnotifyall(&tcbtable, satosin(sa)->sin_addr, errno,
notify);
return NULL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_timer.c,v 1.17 1996/12/10 18:20:24 mycroft Exp $ */
/* $NetBSD: tcp_timer.c,v 1.18 1997/07/23 21:26:52 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
@ -102,6 +102,8 @@ tcp_slowtimo()
register struct tcpcb *tp;
int s;
register long i;
static int syn_cache_last = 0;
extern int tcp_syn_cache_interval;
s = splsoftnet();
tcp_maxidle = TCPTV_KEEPCNT * tcp_keepintvl;
@ -143,6 +145,10 @@ tpgone:
tcp_iss = 0; /* XXX */
#endif
tcp_now++; /* for timestamps */
if (++syn_cache_last >= tcp_syn_cache_interval) {
syn_cache_timer(syn_cache_last);
syn_cache_last = 0;
}
splx(s);
}
#ifndef TUBA_INCLUDE
@ -301,11 +307,13 @@ tcp_timers(tp, timer)
* The keepalive packet must have nonzero length
* to get a 4.2 host to respond.
*/
tcp_respond(tp, tp->t_template, (struct mbuf *)NULL,
tp->rcv_nxt - 1, tp->snd_una - 1, 0);
(void)tcp_respond(tp, tp->t_template,
(struct mbuf *)NULL, tp->rcv_nxt - 1,
tp->snd_una - 1, 0);
#else
tcp_respond(tp, tp->t_template, (struct mbuf *)NULL,
tp->rcv_nxt, tp->snd_una - 1, 0);
(void)tcp_respond(tp, tp->t_template,
(struct mbuf *)NULL, tp->rcv_nxt,
tp->snd_una - 1, 0);
#endif
tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
} else

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_var.h,v 1.19 1996/12/10 18:20:26 mycroft Exp $ */
/* $NetBSD: tcp_var.h,v 1.20 1997/07/23 21:26:54 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1993, 1994
@ -129,6 +129,45 @@ struct tcpcb {
caddr_t t_tuba_pcb; /* next level down pcb for TCP over z */
};
/*
* Handy way of passing around TCP option info.
*/
struct tcp_opt_info {
int ts_present;
u_int32_t ts_val;
u_int32_t ts_ecr;
u_int16_t maxseg;
};
/*
* This structure should not exceed 32 bytes.
* XXX On the Alpha, it's already 36-bytes, which rounds to 40.
* XXX Need to eliminate the pointer.
*/
struct syn_cache {
struct syn_cache *sc_next;
u_int32_t sc_tstmp : 1,
sc_hash : 31;
struct in_addr sc_src;
struct in_addr sc_dst;
tcp_seq sc_irs;
tcp_seq sc_iss;
u_int16_t sc_sport;
u_int16_t sc_dport;
u_int16_t sc_peermaxseg;
u_int8_t sc_timer;
u_int8_t sc_request_r_scale : 4,
sc_requested_s_scale : 4;
};
struct syn_cache_head {
struct syn_cache *sch_first; /* First entry in the bucket */
struct syn_cache *sch_last; /* Last entry in the bucket */
struct syn_cache_head *sch_headq; /* The next non-empty bucket */
int16_t sch_timer_sum; /* Total time in this bucket */
u_int16_t sch_length; /* @ # elements in bucket */
};
#define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
#define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
@ -221,6 +260,21 @@ struct tcpstat {
u_long tcps_pcbhashmiss; /* input packets missing pcb hash */
u_long tcps_noport; /* no socket on port */
u_long tcps_badsyn; /* received ack for which we have
no SYN in compressed state */
/* These statistics deal with the SYN cache. */
u_long tcps_sc_added; /* # of entries added */
u_long tcps_sc_completed; /* # of connections completed */
u_long tcps_sc_timed_out; /* # of entries timed out */
u_long tcps_sc_overflowed; /* # dropped due to overflow */
u_long tcps_sc_reset; /* # dropped due to RST */
u_long tcps_sc_unreach; /* # dropped due to ICMP unreach */
u_long tcps_sc_bucketoverflow; /* # dropped due to bucket overflow */
u_long tcps_sc_aborted; /* # of entries aborted (no mem) */
u_long tcps_sc_dupesyn; /* # of duplicate SYNs received */
u_long tcps_sc_dropped; /* # of SYNs dropped (no route/mem) */
u_long tcps_sc_collisions; /* # of hash collisions */
};
/*
@ -241,6 +295,11 @@ struct tcpstat tcpstat; /* tcp statistics */
u_int32_t tcp_now; /* for RFC 1323 timestamps */
extern int tcp_do_rfc1323; /* enabled/disabled? */
int tcp_syn_cache_size;
int tcp_syn_cache_timeo;
struct syn_cache_head tcp_syn_cache[], *tcp_syn_cache_first;
u_long syn_cache_count;
int tcp_attach __P((struct socket *));
void tcp_canceltimers __P((struct tcpcb *));
struct tcpcb *
@ -252,7 +311,7 @@ struct tcpcb *
struct tcpcb *
tcp_drop __P((struct tcpcb *, int));
void tcp_dooptions __P((struct tcpcb *,
u_char *, int, struct tcpiphdr *, int *, u_int32_t *, u_int32_t *));
u_char *, int, struct tcpiphdr *, struct tcp_opt_info *));
void tcp_drain __P((void));
void tcp_fasttimo __P((void));
void tcp_init __P((void));
@ -266,7 +325,7 @@ void tcp_pulloutofband __P((struct socket *,
struct tcpiphdr *, struct mbuf *));
void tcp_quench __P((struct inpcb *, int));
int tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *));
void tcp_respond __P((struct tcpcb *,
int tcp_respond __P((struct tcpcb *,
struct tcpiphdr *, struct mbuf *, tcp_seq, tcp_seq, int));
void tcp_setpersist __P((struct tcpcb *));
void tcp_slowtimo __P((void));
@ -281,4 +340,20 @@ int tcp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
int tcp_usrreq __P((struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *));
void tcp_xmit_timer __P((struct tcpcb *, int));
int syn_cache_add __P((struct socket *, struct mbuf *, u_char *,
int, struct tcp_opt_info *));
void syn_cache_unreach __P((struct ip *, struct tcphdr *));
struct socket *
syn_cache_get __P((struct socket *so, struct mbuf *));
void syn_cache_insert __P((struct syn_cache *, struct syn_cache ***,
struct syn_cache_head **));
struct syn_cache *
syn_cache_lookup __P((struct tcpiphdr *, struct syn_cache ***,
struct syn_cache_head **));
void syn_cache_reset __P((struct tcpiphdr *));
int syn_cache_respond __P((struct syn_cache *, struct mbuf *,
register struct tcpiphdr *, long, u_long));
void syn_cache_timer __P((int));
#endif