sync with OpenBSD -current

This commit is contained in:
purplerain 2024-04-11 04:04:03 +00:00
parent 2d743fc5aa
commit 0e1b66badd
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
34 changed files with 418 additions and 480 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tcp_debug.c,v 1.31 2024/01/11 13:49:49 bluhm Exp $ */
/* $OpenBSD: tcp_debug.c,v 1.32 2024/04/10 22:24:07 bluhm Exp $ */
/* $NetBSD: tcp_debug.c,v 1.10 1996/02/13 23:43:36 christos Exp $ */
/*
@ -79,6 +79,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/mutex.h>
#include <sys/socket.h>
#include <net/route.h>
@ -98,12 +99,23 @@
#include <netinet/ip6.h>
#endif /* INET6 */
#ifdef TCPDEBUG
#include <sys/protosw.h>
#endif
/*
* Locks used to protect struct members in this file:
* D TCP debug global mutex
*/
struct mutex tcp_debug_mtx = MUTEX_INITIALIZER(IPL_SOFTNET);
#ifdef TCPDEBUG
int tcpconsdebug = 0;
#endif
struct tcp_debug tcp_debug[TCP_NDEBUG];
int tcp_debx;
struct tcp_debug tcp_debug[TCP_NDEBUG]; /* [D] */
int tcp_debx; /* [D] */
/*
* Tcp debug routines
@ -113,14 +125,20 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp,
caddr_t headers, int req, int len)
{
#ifdef TCPDEBUG
struct tcphdr *th;
tcp_seq seq, ack;
int flags;
#endif
int pf = PF_UNSPEC;
struct tcp_debug *td = &tcp_debug[tcp_debx++];
struct tcpiphdr *ti = (struct tcpiphdr *)headers;
struct tcpipv6hdr *ti6 = (struct tcpipv6hdr *)headers;
struct tcphdr *th;
struct tcp_debug *td;
struct tcpiphdr *ti;
struct tcpipv6hdr *ti6;
mtx_enter(&tcp_debug_mtx);
td = &tcp_debug[tcp_debx++];
ti = (struct tcpiphdr *)headers;
ti6 = (struct tcpipv6hdr *)headers;
if (tcp_debx == TCP_NDEBUG)
tcp_debx = 0;
@ -153,13 +171,17 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp,
switch (pf) {
#ifdef INET6
case PF_INET6:
#ifdef TCPDEBUG
th = &ti6->ti6_t;
#endif
td->td_ti6 = *ti6;
td->td_ti6.ti6_plen = len;
break;
#endif /* INET6 */
case PF_INET:
#ifdef TCPDEBUG
th = &ti->ti_t;
#endif
td->td_ti = *ti;
td->td_ti.ti_len = len;
break;
@ -172,7 +194,7 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp,
td->td_req = req;
#ifdef TCPDEBUG
if (tcpconsdebug == 0)
return;
goto done;
if (otp)
printf("%p %s:", otp, tcpstates[ostate]);
else
@ -218,11 +240,14 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp,
/* print out internal state of tp !?! */
printf("\n");
if (tp == NULL)
return;
goto done;
printf("\trcv_(nxt,wnd,up) (%x,%lx,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
tp->snd_max);
printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%lx)\n",
tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
done:
#endif /* TCPDEBUG */
mtx_leave(&tcp_debug_mtx);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tcp_input.c,v 1.401 2024/02/13 12:22:09 bluhm Exp $ */
/* $OpenBSD: tcp_input.c,v 1.402 2024/04/10 22:10:03 bluhm Exp $ */
/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
/*
@ -100,8 +100,6 @@
#include <net/pfvar.h>
#endif
struct tcpiphdr tcp_saveti;
int tcp_mss_adv(struct mbuf *, int);
int tcp_flush_queue(struct tcpcb *);
@ -109,8 +107,6 @@ int tcp_flush_queue(struct tcpcb *);
#include <netinet6/in6_var.h>
#include <netinet6/nd6.h>
struct tcpipv6hdr tcp_saveti6;
/* for the packet header length in the mbuf */
#define M_PH_LEN(m) (((struct mbuf *)(m))->m_pkthdr.len)
#define M_V6_LEN(m) (M_PH_LEN(m) - sizeof(struct ip6_hdr))
@ -373,7 +369,13 @@ tcp_input(struct mbuf **mp, int *offp, int proto, int af)
int todrop, acked, ourfinisacked;
int hdroptlen = 0;
short ostate;
caddr_t saveti;
union {
struct tcpiphdr tcpip;
#ifdef INET6
struct tcpipv6hdr tcpip6;
#endif
char caddr;
} saveti;
tcp_seq iss, *reuse = NULL;
uint64_t now;
u_long tiwin;
@ -672,15 +674,13 @@ findpcb:
switch (af) {
#ifdef INET6
case AF_INET6:
saveti = (caddr_t) &tcp_saveti6;
memcpy(&tcp_saveti6.ti6_i, ip6, sizeof(*ip6));
memcpy(&tcp_saveti6.ti6_t, th, sizeof(*th));
saveti.tcpip6.ti6_i = *ip6;
saveti.tcpip6.ti6_t = *th;
break;
#endif
case AF_INET:
saveti = (caddr_t) &tcp_saveti;
memcpy(&tcp_saveti.ti_i, ip, sizeof(*ip));
memcpy(&tcp_saveti.ti_t, th, sizeof(*th));
memcpy(&saveti.tcpip.ti_i, ip, sizeof(*ip));
saveti.tcpip.ti_t = *th;
break;
}
}
@ -2031,7 +2031,7 @@ dodata: /* XXX */
}
}
if (otp)
tcp_trace(TA_INPUT, ostate, tp, otp, saveti, 0, tlen);
tcp_trace(TA_INPUT, ostate, tp, otp, &saveti.caddr, 0, tlen);
/*
* Return any desired output.
@ -2110,7 +2110,7 @@ drop:
* Drop space held by incoming segment and return.
*/
if (otp)
tcp_trace(TA_DROP, ostate, tp, otp, saveti, 0, tlen);
tcp_trace(TA_DROP, ostate, tp, otp, &saveti.caddr, 0, tlen);
m_freem(m);
in_pcbunref(inp);