spx_debug.c revision 32350
111819Sjulian/*
211819Sjulian * Copyright (c) 1995, Mike Mitchell
311819Sjulian * Copyright (c) 1984, 1985, 1986, 1987, 1993
411819Sjulian *	The Regents of the University of California.  All rights reserved.
511819Sjulian *
611819Sjulian * Redistribution and use in source and binary forms, with or without
711819Sjulian * modification, are permitted provided that the following conditions
811819Sjulian * are met:
911819Sjulian * 1. Redistributions of source code must retain the above copyright
1011819Sjulian *    notice, this list of conditions and the following disclaimer.
1111819Sjulian * 2. Redistributions in binary form must reproduce the above copyright
1211819Sjulian *    notice, this list of conditions and the following disclaimer in the
1311819Sjulian *    documentation and/or other materials provided with the distribution.
1411819Sjulian * 3. All advertising materials mentioning features or use of this software
1511819Sjulian *    must display the following acknowledgement:
1611819Sjulian *	This product includes software developed by the University of
1711819Sjulian *	California, Berkeley and its contributors.
1811819Sjulian * 4. Neither the name of the University nor the names of its contributors
1911819Sjulian *    may be used to endorse or promote products derived from this software
2011819Sjulian *    without specific prior written permission.
2111819Sjulian *
2211819Sjulian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2311819Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2411819Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2511819Sjulian * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2611819Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2711819Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2811819Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2911819Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3011819Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3111819Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3211819Sjulian * SUCH DAMAGE.
3311819Sjulian *
3412057Sjulian *	@(#)spx_debug.c
3512057Sjulian *
3632350Seivind * $Id: spx_debug.c,v 1.11 1997/10/28 12:24:26 bde Exp $
3711819Sjulian */
3811819Sjulian
3932350Seivind#include "opt_inet.h"
4030806Sbde#include "opt_tcpdebug.h"
4130806Sbde
4211819Sjulian#include <sys/param.h>
4311819Sjulian#include <sys/systm.h>
4411819Sjulian#include <sys/protosw.h>
4511819Sjulian
4611819Sjulian#include <netinet/in_systm.h>
4711819Sjulian#include <netinet/tcp_fsm.h>
4811819Sjulian
4911819Sjulian#include <netipx/ipx.h>
5030806Sbde#include <netipx/ipx_var.h>
5111819Sjulian#include <netipx/spx.h>
5211819Sjulian#define SPXTIMERS
5311819Sjulian#include <netipx/spx_timer.h>
5411819Sjulian#define	SANAMES
5511819Sjulian#include <netipx/spx_debug.h>
5611819Sjulian
5715239Sbde#ifdef TCPDEBUG
5825652Sjhaystatic	int spxconsdebug = 0;
5925652Sjhaystatic	struct spx_debug spx_debug[SPX_NDEBUG];
6025652Sjhaystatic	int spx_debx;
6115239Sbde#endif
6215239Sbde
6311819Sjulian/*
6411819Sjulian * spx debug routines
6511819Sjulian */
6611819Sjulianvoid
6711819Sjulianspx_trace(act, ostate, sp, si, req)
6811819Sjulian	short act;
6911819Sjulian	u_char ostate;
7011819Sjulian	struct spxpcb *sp;
7111819Sjulian	struct spx *si;
7211819Sjulian	int req;
7311819Sjulian{
7411819Sjulian#ifdef INET
7511819Sjulian#ifdef TCPDEBUG
7611819Sjulian	u_short seq, ack, len, alo;
7711819Sjulian	int flags;
7811819Sjulian	struct spx_debug *sd = &spx_debug[spx_debx++];
7911819Sjulian
8011819Sjulian	if (spx_debx == SPX_NDEBUG)
8111819Sjulian		spx_debx = 0;
8211819Sjulian	sd->sd_time = iptime();
8311819Sjulian	sd->sd_act = act;
8411819Sjulian	sd->sd_ostate = ostate;
8511819Sjulian	sd->sd_cb = (caddr_t)sp;
8625652Sjhay	if (sp != NULL)
8711819Sjulian		sd->sd_sp = *sp;
8811819Sjulian	else
8925652Sjhay		bzero((caddr_t)&sd->sd_sp, sizeof(*sp));
9025652Sjhay	if (si != NULL)
9111819Sjulian		sd->sd_si = *si;
9211819Sjulian	else
9325652Sjhay		bzero((caddr_t)&sd->sd_si, sizeof(*si));
9411819Sjulian	sd->sd_req = req;
9511819Sjulian	if (spxconsdebug == 0)
9611819Sjulian		return;
9725652Sjhay	if (ostate >= TCP_NSTATES)
9825652Sjhay		ostate = 0;
9925652Sjhay	if (act >= SA_DROP)
10025652Sjhay		act = SA_DROP;
10125652Sjhay	if (sp != NULL)
10211819Sjulian		printf("%x %s:", sp, tcpstates[ostate]);
10311819Sjulian	else
10411819Sjulian		printf("???????? ");
10514093Swollman	printf("%s ", spxnames[act]);
10611819Sjulian	switch (act) {
10711819Sjulian
10811819Sjulian	case SA_RESPOND:
10911819Sjulian	case SA_INPUT:
11011819Sjulian	case SA_OUTPUT:
11111819Sjulian	case SA_DROP:
11225652Sjhay		if (si == NULL)
11311819Sjulian			break;
11411819Sjulian		seq = si->si_seq;
11511819Sjulian		ack = si->si_ack;
11611819Sjulian		alo = si->si_alo;
11711819Sjulian		len = si->si_len;
11811819Sjulian		if (act == SA_OUTPUT) {
11911819Sjulian			seq = ntohs(seq);
12011819Sjulian			ack = ntohs(ack);
12111819Sjulian			alo = ntohs(alo);
12211819Sjulian			len = ntohs(len);
12311819Sjulian		}
12411819Sjulian#ifndef lint
12511819Sjulian#define p1(f)  { printf("%s = %x, ", "f", f); }
12611819Sjulian		p1(seq); p1(ack); p1(alo); p1(len);
12711819Sjulian#endif
12811819Sjulian		flags = si->si_cc;
12911819Sjulian		if (flags) {
13011819Sjulian			char *cp = "<";
13111819Sjulian#ifndef lint
13211819Sjulian#define pf(f) { if (flags & SPX_ ## f) { printf("%s%s", cp, "f"); cp = ","; } }
13311819Sjulian			pf(SP); pf(SA); pf(OB); pf(EM);
13411819Sjulian#else
13511819Sjulian			cp = cp;
13611819Sjulian#endif
13711819Sjulian			printf(">");
13811819Sjulian		}
13911819Sjulian#ifndef lint
14011819Sjulian#define p2(f)  { printf("%s = %x, ", "f", si->si_ ## f); }
14111819Sjulian		p2(sid);p2(did);p2(dt);p2(pt);
14211819Sjulian#endif
14311819Sjulian		ipx_printhost(&si->si_sna);
14411819Sjulian		ipx_printhost(&si->si_dna);
14511819Sjulian
14625652Sjhay		if (act == SA_RESPOND) {
14711819Sjulian			printf("ipx_len = %x, ",
14811819Sjulian				((struct ipx *)si)->ipx_len);
14911819Sjulian		}
15011819Sjulian		break;
15111819Sjulian
15211819Sjulian	case SA_USER:
15311819Sjulian		printf("%s", prurequests[req&0xff]);
15411819Sjulian		if ((req & 0xff) == PRU_SLOWTIMO)
15511819Sjulian			printf("<%s>", spxtimers[req>>8]);
15611819Sjulian		break;
15711819Sjulian	}
15811819Sjulian	if (sp)
15911819Sjulian		printf(" -> %s", tcpstates[sp->s_state]);
16011819Sjulian	/* print out internal state of sp !?! */
16111819Sjulian	printf("\n");
16211819Sjulian	if (sp == 0)
16311819Sjulian		return;
16411819Sjulian#ifndef lint
16511819Sjulian#define p3(f)  { printf("%s = %x, ", "f", sp->s_ ## f); }
16611819Sjulian	printf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); printf("\n");
16711819Sjulian#endif
16811819Sjulian#endif
16911819Sjulian#endif
17011819Sjulian}
171