source: rtems/cpukit/libnetworking/netinet/tcp_debug.c @ b3f8c9e1

4.104.11
Last change on this file since b3f8c9e1 was b3f8c9e1, checked in by Ralf Corsepius <ralf.corsepius@…>, on Dec 22, 2008 at 7:47:28 AM

Include <errno.h> (POSIX,C99) instead of <sys/errno.h> (BSD'ism).

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 1982, 1986, 1993
3 *      The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *      @(#)tcp_debug.c 8.1 (Berkeley) 6/10/93
30 * $Id$
31 */
32
33#include "opt_tcpdebug.h"
34
35#ifdef TCPDEBUG
36/* load symbolic names */
37#define PRUREQUESTS
38#define TCPSTATES
39#define TCPTIMERS
40#define TANAMES
41#endif
42
43#include <sys/param.h>
44#include <rtems/bsd/sys/queue.h>
45#include <sys/systm.h>
46#include <sys/mbuf.h>
47#include <sys/socket.h>
48#include <sys/socketvar.h>
49#include <sys/protosw.h>
50#include <errno.h>
51
52#include <net/route.h>
53#include <net/if.h>
54
55#include <netinet/in.h>
56#include <netinet/in_systm.h>
57#include <netinet/ip.h>
58#include <netinet/in_pcb.h>
59#include <netinet/ip_var.h>
60#include <netinet/tcp.h>
61#include <netinet/tcp_fsm.h>
62#include <netinet/tcp_seq.h>
63#include <netinet/tcp_timer.h>
64#include <netinet/tcp_var.h>
65#include <netinet/tcpip.h>
66#include <netinet/tcp_debug.h>
67
68#ifdef TCPDEBUG
69static int      tcpconsdebug = 0; /* set to 1 to enable prints */
70#endif
71
72static struct tcp_debug tcp_debug[TCP_NDEBUG];
73static int      tcp_debx;
74
75/*
76 * Tcp debug routines
77 */
78void
79tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpiphdr *ti,
80        int req)
81{
82#ifdef TCPDEBUG
83        tcp_seq seq, ack;
84        int len, flags;
85#endif
86        struct tcp_debug *td = &tcp_debug[tcp_debx++];
87
88        if (tcp_debx == TCP_NDEBUG)
89                tcp_debx = 0;
90        td->td_time = iptime();
91        td->td_act = act;
92        td->td_ostate = ostate;
93        td->td_tcb = (caddr_t)tp;
94        if (tp)
95                td->td_cb = *tp;
96        else
97                bzero((caddr_t)&td->td_cb, sizeof (*tp));
98        if (ti)
99                td->td_ti = *ti;
100        else
101                bzero((caddr_t)&td->td_ti, sizeof (*ti));
102        td->td_req = req;
103#ifdef TCPDEBUG
104        if (tcpconsdebug == 0)
105                return;
106        if (tp)
107                printf("%p %s:", tp, tcpstates[ostate]);
108        else
109                printf("???????? ");
110        printf("%s ", tanames[act]);
111        switch (act) {
112
113        case TA_INPUT:
114        case TA_OUTPUT:
115        case TA_DROP:
116                if (ti == 0)
117                        break;
118                seq = ti->ti_seq;
119                ack = ti->ti_ack;
120                len = ti->ti_len;
121                if (act == TA_OUTPUT) {
122                        seq = ntohl(seq);
123                        ack = ntohl(ack);
124                        len = ntohs((u_short)len);
125                }
126                if (act == TA_OUTPUT)
127                        len -= sizeof (struct tcphdr);
128                if (len)
129                        printf("[%x..%x)", seq, seq+len);
130                else
131                        printf("%x", seq);
132                printf("@%x, urp=%x", ack, ti->ti_urp);
133                flags = ti->ti_flags;
134                if (flags) {
135                        char *cp = "<";
136#define pf(f) {                                 \
137        if (ti->ti_flags & TH_##f) {            \
138                printf("%s%s", cp, #f);         \
139                cp = ",";                       \
140        }                                       \
141}
142                        pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
143                        printf(">");
144                }
145                break;
146
147        case TA_USER:
148                printf("%s", prurequests[req&0xff]);
149                if ((req & 0xff) == PRU_SLOWTIMO)
150                        printf("<%s>", tcptimers[req>>8]);
151                break;
152        }
153        if (tp)
154                printf(" -> %s", tcpstates[tp->t_state]);
155        /* print out internal state of tp !?! */
156        printf("\n");
157        if (tp == 0)
158                return;
159        printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
160            tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
161            tp->snd_max);
162        printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
163            tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
164#endif /* TCPDEBUG */
165}
Note: See TracBrowser for help on using the repository browser.