spx_debug.c revision 139823
1139823Simp/*-
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
3511819Sjulian */
3611819Sjulian
37116189Sobrien#include <sys/cdefs.h>
38116189Sobrien__FBSDID("$FreeBSD: head/sys/netipx/spx_debug.c 139823 2005-01-07 01:45:51Z imp $");
39116189Sobrien
4032350Seivind#include "opt_inet.h"
4130806Sbde#include "opt_tcpdebug.h"
4230806Sbde
4311819Sjulian#include <sys/param.h>
4411819Sjulian#include <sys/systm.h>
4511819Sjulian#include <sys/protosw.h>
4611819Sjulian
4711819Sjulian#include <netinet/in_systm.h>
4811819Sjulian#include <netinet/tcp_fsm.h>
4911819Sjulian
5011819Sjulian#include <netipx/ipx.h>
5130806Sbde#include <netipx/ipx_var.h>
5211819Sjulian#include <netipx/spx.h>
5311819Sjulian#define SPXTIMERS
5411819Sjulian#include <netipx/spx_timer.h>
5511819Sjulian#define	SANAMES
5611819Sjulian#include <netipx/spx_debug.h>
5711819Sjulian
5815239Sbde#ifdef TCPDEBUG
5925652Sjhaystatic	int spxconsdebug = 0;
6025652Sjhaystatic	struct spx_debug spx_debug[SPX_NDEBUG];
6125652Sjhaystatic	int spx_debx;
6215239Sbde#endif
6315239Sbde
6411819Sjulian/*
6511819Sjulian * spx debug routines
6611819Sjulian */
6711819Sjulianvoid
6811819Sjulianspx_trace(act, ostate, sp, si, req)
6911819Sjulian	short act;
7011819Sjulian	u_char ostate;
7111819Sjulian	struct spxpcb *sp;
7211819Sjulian	struct spx *si;
7311819Sjulian	int req;
7411819Sjulian{
7511819Sjulian#ifdef INET
7611819Sjulian#ifdef TCPDEBUG
7711819Sjulian	u_short seq, ack, len, alo;
7811819Sjulian	int flags;
7911819Sjulian	struct spx_debug *sd = &spx_debug[spx_debx++];
8011819Sjulian
8111819Sjulian	if (spx_debx == SPX_NDEBUG)
8211819Sjulian		spx_debx = 0;
8311819Sjulian	sd->sd_time = iptime();
8411819Sjulian	sd->sd_act = act;
8511819Sjulian	sd->sd_ostate = ostate;
8611819Sjulian	sd->sd_cb = (caddr_t)sp;
8725652Sjhay	if (sp != NULL)
8811819Sjulian		sd->sd_sp = *sp;
8911819Sjulian	else
9025652Sjhay		bzero((caddr_t)&sd->sd_sp, sizeof(*sp));
9125652Sjhay	if (si != NULL)
9211819Sjulian		sd->sd_si = *si;
9311819Sjulian	else
9425652Sjhay		bzero((caddr_t)&sd->sd_si, sizeof(*si));
9511819Sjulian	sd->sd_req = req;
9611819Sjulian	if (spxconsdebug == 0)
9711819Sjulian		return;
9825652Sjhay	if (ostate >= TCP_NSTATES)
9925652Sjhay		ostate = 0;
10025652Sjhay	if (act >= SA_DROP)
10125652Sjhay		act = SA_DROP;
10225652Sjhay	if (sp != NULL)
10338373Sbde		printf("%p %s:", (void *)sp, tcpstates[ostate]);
10411819Sjulian	else
10511819Sjulian		printf("???????? ");
10614093Swollman	printf("%s ", spxnames[act]);
10711819Sjulian	switch (act) {
10811819Sjulian
10911819Sjulian	case SA_RESPOND:
11011819Sjulian	case SA_INPUT:
11111819Sjulian	case SA_OUTPUT:
11211819Sjulian	case SA_DROP:
11325652Sjhay		if (si == NULL)
11411819Sjulian			break;
11511819Sjulian		seq = si->si_seq;
11611819Sjulian		ack = si->si_ack;
11711819Sjulian		alo = si->si_alo;
11811819Sjulian		len = si->si_len;
11911819Sjulian		if (act == SA_OUTPUT) {
12011819Sjulian			seq = ntohs(seq);
12111819Sjulian			ack = ntohs(ack);
12211819Sjulian			alo = ntohs(alo);
12311819Sjulian			len = ntohs(len);
12411819Sjulian		}
12511819Sjulian#ifndef lint
12611819Sjulian#define p1(f)  { printf("%s = %x, ", "f", f); }
12711819Sjulian		p1(seq); p1(ack); p1(alo); p1(len);
12811819Sjulian#endif
12911819Sjulian		flags = si->si_cc;
13011819Sjulian		if (flags) {
13111819Sjulian			char *cp = "<";
13211819Sjulian#ifndef lint
13311819Sjulian#define pf(f) { if (flags & SPX_ ## f) { printf("%s%s", cp, "f"); cp = ","; } }
13411819Sjulian			pf(SP); pf(SA); pf(OB); pf(EM);
13511819Sjulian#else
13611819Sjulian			cp = cp;
13711819Sjulian#endif
13811819Sjulian			printf(">");
13911819Sjulian		}
14011819Sjulian#ifndef lint
14111819Sjulian#define p2(f)  { printf("%s = %x, ", "f", si->si_ ## f); }
14211819Sjulian		p2(sid);p2(did);p2(dt);p2(pt);
14311819Sjulian#endif
14411819Sjulian		ipx_printhost(&si->si_sna);
14511819Sjulian		ipx_printhost(&si->si_dna);
14611819Sjulian
14725652Sjhay		if (act == SA_RESPOND) {
14811819Sjulian			printf("ipx_len = %x, ",
14911819Sjulian				((struct ipx *)si)->ipx_len);
15011819Sjulian		}
15111819Sjulian		break;
15211819Sjulian
15311819Sjulian	case SA_USER:
15411819Sjulian		printf("%s", prurequests[req&0xff]);
15511819Sjulian		if ((req & 0xff) == PRU_SLOWTIMO)
15611819Sjulian			printf("<%s>", spxtimers[req>>8]);
15711819Sjulian		break;
15811819Sjulian	}
15911819Sjulian	if (sp)
16011819Sjulian		printf(" -> %s", tcpstates[sp->s_state]);
16111819Sjulian	/* print out internal state of sp !?! */
16211819Sjulian	printf("\n");
16311819Sjulian	if (sp == 0)
16411819Sjulian		return;
16511819Sjulian#ifndef lint
16611819Sjulian#define p3(f)  { printf("%s = %x, ", "f", sp->s_ ## f); }
16711819Sjulian	printf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); printf("\n");
16811819Sjulian#endif
16911819Sjulian#endif
17011819Sjulian#endif
17111819Sjulian}
172