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

4.104.11
Last change on this file since b25b88e7 was b25b88e7, checked in by Ralf Corsepius <ralf.corsepius@…>, on Mar 28, 2010 at 5:50:29 AM

Add HAVE_CONFIG_H support to let files receive configure defines.

  • 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#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include "opt_tcpdebug.h"
38
39#ifdef TCPDEBUG
40/* load symbolic names */
41#define PRUREQUESTS
42#define TCPSTATES
43#define TCPTIMERS
44#define TANAMES
45#endif
46
47#include <sys/param.h>
48#include <rtems/bsd/sys/queue.h>
49#include <sys/systm.h>
50#include <sys/mbuf.h>
51#include <sys/socket.h>
52#include <sys/socketvar.h>
53#include <sys/protosw.h>
54#include <errno.h>
55
56#include <net/route.h>
57#include <net/if.h>
58
59#include <netinet/in.h>
60#include <netinet/in_systm.h>
61#include <netinet/ip.h>
62#include <netinet/in_pcb.h>
63#include <netinet/ip_var.h>
64#include <netinet/tcp.h>
65#include <netinet/tcp_fsm.h>
66#include <netinet/tcp_seq.h>
67#include <netinet/tcp_timer.h>
68#include <netinet/tcp_var.h>
69#include <netinet/tcpip.h>
70#include <netinet/tcp_debug.h>
71
72#ifdef TCPDEBUG
73static int      tcpconsdebug = 0; /* set to 1 to enable prints */
74#endif
75
76static struct tcp_debug tcp_debug[TCP_NDEBUG];
77static int      tcp_debx;
78
79/*
80 * Tcp debug routines
81 */
82void
83tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpiphdr *ti,
84        int req)
85{
86#ifdef TCPDEBUG
87        tcp_seq seq, ack;
88        int len, flags;
89#endif
90        struct tcp_debug *td = &tcp_debug[tcp_debx++];
91
92        if (tcp_debx == TCP_NDEBUG)
93                tcp_debx = 0;
94        td->td_time = iptime();
95        td->td_act = act;
96        td->td_ostate = ostate;
97        td->td_tcb = (caddr_t)tp;
98        if (tp)
99                td->td_cb = *tp;
100        else
101                bzero((caddr_t)&td->td_cb, sizeof (*tp));
102        if (ti)
103                td->td_ti = *ti;
104        else
105                bzero((caddr_t)&td->td_ti, sizeof (*ti));
106        td->td_req = req;
107#ifdef TCPDEBUG
108        if (tcpconsdebug == 0)
109                return;
110        if (tp)
111                printf("%p %s:", tp, tcpstates[ostate]);
112        else
113                printf("???????? ");
114        printf("%s ", tanames[act]);
115        switch (act) {
116
117        case TA_INPUT:
118        case TA_OUTPUT:
119        case TA_DROP:
120                if (ti == 0)
121                        break;
122                seq = ti->ti_seq;
123                ack = ti->ti_ack;
124                len = ti->ti_len;
125                if (act == TA_OUTPUT) {
126                        seq = ntohl(seq);
127                        ack = ntohl(ack);
128                        len = ntohs((u_short)len);
129                }
130                if (act == TA_OUTPUT)
131                        len -= sizeof (struct tcphdr);
132                if (len)
133                        printf("[%x..%x)", seq, seq+len);
134                else
135                        printf("%x", seq);
136                printf("@%x, urp=%x", ack, ti->ti_urp);
137                flags = ti->ti_flags;
138                if (flags) {
139                        char *cp = "<";
140#define pf(f) {                                 \
141        if (ti->ti_flags & TH_##f) {            \
142                printf("%s%s", cp, #f);         \
143                cp = ",";                       \
144        }                                       \
145}
146                        pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
147                        printf(">");
148                }
149                break;
150
151        case TA_USER:
152                printf("%s", prurequests[req&0xff]);
153                if ((req & 0xff) == PRU_SLOWTIMO)
154                        printf("<%s>", tcptimers[req>>8]);
155                break;
156        }
157        if (tp)
158                printf(" -> %s", tcpstates[tp->t_state]);
159        /* print out internal state of tp !?! */
160        printf("\n");
161        if (tp == 0)
162                return;
163        printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
164            tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
165            tp->snd_max);
166        printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
167            tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
168#endif /* TCPDEBUG */
169}
Note: See TracBrowser for help on using the repository browser.