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

4.104.114.95
Last change on this file since f5a2f211 was f5a2f211, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/01/08 at 06:26:20

Remove BSD "Add clause" (From FreeBSD).

  • 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 <sys/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(act, ostate, tp, ti, req)
80        short act, ostate;
81        struct tcpcb *tp;
82        struct tcpiphdr *ti;
83        int req;
84{
85#ifdef TCPDEBUG
86        tcp_seq seq, ack;
87        int len, flags;
88#endif
89        struct tcp_debug *td = &tcp_debug[tcp_debx++];
90
91        if (tcp_debx == TCP_NDEBUG)
92                tcp_debx = 0;
93        td->td_time = iptime();
94        td->td_act = act;
95        td->td_ostate = ostate;
96        td->td_tcb = (caddr_t)tp;
97        if (tp)
98                td->td_cb = *tp;
99        else
100                bzero((caddr_t)&td->td_cb, sizeof (*tp));
101        if (ti)
102                td->td_ti = *ti;
103        else
104                bzero((caddr_t)&td->td_ti, sizeof (*ti));
105        td->td_req = req;
106#ifdef TCPDEBUG
107        if (tcpconsdebug == 0)
108                return;
109        if (tp)
110                printf("%p %s:", tp, tcpstates[ostate]);
111        else
112                printf("???????? ");
113        printf("%s ", tanames[act]);
114        switch (act) {
115
116        case TA_INPUT:
117        case TA_OUTPUT:
118        case TA_DROP:
119                if (ti == 0)
120                        break;
121                seq = ti->ti_seq;
122                ack = ti->ti_ack;
123                len = ti->ti_len;
124                if (act == TA_OUTPUT) {
125                        seq = ntohl(seq);
126                        ack = ntohl(ack);
127                        len = ntohs((u_short)len);
128                }
129                if (act == TA_OUTPUT)
130                        len -= sizeof (struct tcphdr);
131                if (len)
132                        printf("[%x..%x)", seq, seq+len);
133                else
134                        printf("%x", seq);
135                printf("@%x, urp=%x", ack, ti->ti_urp);
136                flags = ti->ti_flags;
137                if (flags) {
138                        char *cp = "<";
139#define pf(f) {                                 \
140        if (ti->ti_flags & TH_##f) {            \
141                printf("%s%s", cp, #f);         \
142                cp = ",";                       \
143        }                                       \
144}
145                        pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
146                        printf(">");
147                }
148                break;
149
150        case TA_USER:
151                printf("%s", prurequests[req&0xff]);
152                if ((req & 0xff) == PRU_SLOWTIMO)
153                        printf("<%s>", tcptimers[req>>8]);
154                break;
155        }
156        if (tp)
157                printf(" -> %s", tcpstates[tp->t_state]);
158        /* print out internal state of tp !?! */
159        printf("\n");
160        if (tp == 0)
161                return;
162        printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
163            tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
164            tp->snd_max);
165        printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
166            tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
167#endif /* TCPDEBUG */
168}
Note: See TracBrowser for help on using the repository browser.