spx_debug.c revision 25652
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 *
3625652Sjhay * $Id: spx_debug.c,v 1.8 1997/02/22 09:41:58 peter Exp $
3711819Sjulian */
3811819Sjulian
3911819Sjulian#include <sys/param.h>
4014546Sdg#include <sys/queue.h>
4111819Sjulian#include <sys/systm.h>
4211819Sjulian#include <sys/mbuf.h>
4311819Sjulian#include <sys/socket.h>
4411819Sjulian#include <sys/socketvar.h>
4511819Sjulian#include <sys/protosw.h>
4611819Sjulian#include <sys/errno.h>
4711819Sjulian
4811819Sjulian#include <net/route.h>
4911819Sjulian#include <net/if.h>
5011819Sjulian#include <netinet/in_systm.h>
5111819Sjulian#include <netinet/tcp_fsm.h>
5211819Sjulian
5311819Sjulian#include <netipx/ipx.h>
5411819Sjulian#include <netipx/ipx_error.h>
5511819Sjulian#include <netipx/ipx_pcb.h>
5611819Sjulian#include <netipx/ipx.h>
5711819Sjulian#include <netipx/ipx_var.h>
5811819Sjulian#include <netipx/spx.h>
5911819Sjulian#define SPXTIMERS
6011819Sjulian#include <netipx/spx_timer.h>
6111819Sjulian#include <netipx/spx_var.h>
6211819Sjulian#define	SANAMES
6311819Sjulian#include <netipx/spx_debug.h>
6411819Sjulian
6515239Sbde#ifdef TCPDEBUG
6625652Sjhaystatic	int spxconsdebug = 0;
6725652Sjhaystatic	struct spx_debug spx_debug[SPX_NDEBUG];
6825652Sjhaystatic	int spx_debx;
6915239Sbde#endif
7015239Sbde
7111819Sjulian/*
7211819Sjulian * spx debug routines
7311819Sjulian */
7411819Sjulianvoid
7511819Sjulianspx_trace(act, ostate, sp, si, req)
7611819Sjulian	short act;
7711819Sjulian	u_char ostate;
7811819Sjulian	struct spxpcb *sp;
7911819Sjulian	struct spx *si;
8011819Sjulian	int req;
8111819Sjulian{
8211819Sjulian#ifdef INET
8311819Sjulian#ifdef TCPDEBUG
8411819Sjulian	u_short seq, ack, len, alo;
8511819Sjulian	int flags;
8611819Sjulian	struct spx_debug *sd = &spx_debug[spx_debx++];
8711819Sjulian
8811819Sjulian	if (spx_debx == SPX_NDEBUG)
8911819Sjulian		spx_debx = 0;
9011819Sjulian	sd->sd_time = iptime();
9111819Sjulian	sd->sd_act = act;
9211819Sjulian	sd->sd_ostate = ostate;
9311819Sjulian	sd->sd_cb = (caddr_t)sp;
9425652Sjhay	if (sp != NULL)
9511819Sjulian		sd->sd_sp = *sp;
9611819Sjulian	else
9725652Sjhay		bzero((caddr_t)&sd->sd_sp, sizeof(*sp));
9825652Sjhay	if (si != NULL)
9911819Sjulian		sd->sd_si = *si;
10011819Sjulian	else
10125652Sjhay		bzero((caddr_t)&sd->sd_si, sizeof(*si));
10211819Sjulian	sd->sd_req = req;
10311819Sjulian	if (spxconsdebug == 0)
10411819Sjulian		return;
10525652Sjhay	if (ostate >= TCP_NSTATES)
10625652Sjhay		ostate = 0;
10725652Sjhay	if (act >= SA_DROP)
10825652Sjhay		act = SA_DROP;
10925652Sjhay	if (sp != NULL)
11011819Sjulian		printf("%x %s:", sp, tcpstates[ostate]);
11111819Sjulian	else
11211819Sjulian		printf("???????? ");
11314093Swollman	printf("%s ", spxnames[act]);
11411819Sjulian	switch (act) {
11511819Sjulian
11611819Sjulian	case SA_RESPOND:
11711819Sjulian	case SA_INPUT:
11811819Sjulian	case SA_OUTPUT:
11911819Sjulian	case SA_DROP:
12025652Sjhay		if (si == NULL)
12111819Sjulian			break;
12211819Sjulian		seq = si->si_seq;
12311819Sjulian		ack = si->si_ack;
12411819Sjulian		alo = si->si_alo;
12511819Sjulian		len = si->si_len;
12611819Sjulian		if (act == SA_OUTPUT) {
12711819Sjulian			seq = ntohs(seq);
12811819Sjulian			ack = ntohs(ack);
12911819Sjulian			alo = ntohs(alo);
13011819Sjulian			len = ntohs(len);
13111819Sjulian		}
13211819Sjulian#ifndef lint
13311819Sjulian#define p1(f)  { printf("%s = %x, ", "f", f); }
13411819Sjulian		p1(seq); p1(ack); p1(alo); p1(len);
13511819Sjulian#endif
13611819Sjulian		flags = si->si_cc;
13711819Sjulian		if (flags) {
13811819Sjulian			char *cp = "<";
13911819Sjulian#ifndef lint
14011819Sjulian#define pf(f) { if (flags & SPX_ ## f) { printf("%s%s", cp, "f"); cp = ","; } }
14111819Sjulian			pf(SP); pf(SA); pf(OB); pf(EM);
14211819Sjulian#else
14311819Sjulian			cp = cp;
14411819Sjulian#endif
14511819Sjulian			printf(">");
14611819Sjulian		}
14711819Sjulian#ifndef lint
14811819Sjulian#define p2(f)  { printf("%s = %x, ", "f", si->si_ ## f); }
14911819Sjulian		p2(sid);p2(did);p2(dt);p2(pt);
15011819Sjulian#endif
15111819Sjulian		ipx_printhost(&si->si_sna);
15211819Sjulian		ipx_printhost(&si->si_dna);
15311819Sjulian
15425652Sjhay		if (act == SA_RESPOND) {
15511819Sjulian			printf("ipx_len = %x, ",
15611819Sjulian				((struct ipx *)si)->ipx_len);
15711819Sjulian		}
15811819Sjulian		break;
15911819Sjulian
16011819Sjulian	case SA_USER:
16111819Sjulian		printf("%s", prurequests[req&0xff]);
16211819Sjulian		if ((req & 0xff) == PRU_SLOWTIMO)
16311819Sjulian			printf("<%s>", spxtimers[req>>8]);
16411819Sjulian		break;
16511819Sjulian	}
16611819Sjulian	if (sp)
16711819Sjulian		printf(" -> %s", tcpstates[sp->s_state]);
16811819Sjulian	/* print out internal state of sp !?! */
16911819Sjulian	printf("\n");
17011819Sjulian	if (sp == 0)
17111819Sjulian		return;
17211819Sjulian#ifndef lint
17311819Sjulian#define p3(f)  { printf("%s = %x, ", "f", sp->s_ ## f); }
17411819Sjulian	printf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); printf("\n");
17511819Sjulian#endif
17611819Sjulian#endif
17711819Sjulian#endif
17811819Sjulian}
179