Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) University of British Columbia, 1984 | |
3 | * Copyright (c) 1990 The Regents of the University of California. | |
4 | * All rights reserved. | |
5 | * | |
6 | * This code is derived from software contributed to Berkeley by | |
7 | * the Laboratory for Computation Vision and the Computer Science Department | |
8 | * of the University of British Columbia. | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | |
15 | * 2. Redistributions in binary form must reproduce the above copyright | |
16 | * notice, this list of conditions and the following disclaimer in the | |
17 | * documentation and/or other materials provided with the distribution. | |
18 | * 3. All advertising materials mentioning features or use of this software | |
19 | * must display the following acknowledgement: | |
20 | * This product includes software developed by the University of | |
21 | * California, Berkeley and its contributors. | |
22 | * 4. Neither the name of the University nor the names of its contributors | |
23 | * may be used to endorse or promote products derived from this software | |
24 | * without specific prior written permission. | |
25 | * | |
26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
36 | * SUCH DAMAGE. | |
37 | * | |
1cdffd64 | 38 | * from: @(#)pk_debug.c 7.7 (Berkeley) 5/9/91 |
fde1aeb2 | 39 | * $Id: pk_debug.c,v 1.3 1993/11/25 01:34:28 wollman Exp $ |
15637ed4 RG |
40 | */ |
41 | ||
42 | #include "param.h" | |
43 | #include "systm.h" | |
44 | #include "mbuf.h" | |
45 | #include "socket.h" | |
46 | #include "protosw.h" | |
47 | #include "socketvar.h" | |
48 | #include "errno.h" | |
49 | ||
50 | #include "../net/if.h" | |
51 | ||
52 | #include "x25.h" | |
53 | #include "pk.h" | |
54 | #include "pk_var.h" | |
55 | ||
fde1aeb2 | 56 | const char *const pk_state[] = { |
15637ed4 RG |
57 | "Listen", "Ready", "Received-Call", |
58 | "Sent-Call", "Data-Transfer","Received-Clear", | |
59 | "Sent-Clear", | |
60 | }; | |
61 | ||
fde1aeb2 | 62 | const char *const pk_name[] = { |
15637ed4 RG |
63 | "Call", "Call-Conf", "Clear", |
64 | "Clear-Conf", "Data", "Intr", "Intr-Conf", | |
65 | "Rr", "Rnr", "Reset", "Reset-Conf", | |
66 | "Restart", "Restart-Conf", "Reject", "Diagnostic", | |
67 | "Invalid" | |
68 | }; | |
69 | ||
4c45483e | 70 | void |
15637ed4 | 71 | pk_trace (xcp, m, dir) |
4c45483e GW |
72 | struct x25config *xcp; |
73 | register struct mbuf *m; | |
fde1aeb2 | 74 | const char *dir; |
15637ed4 RG |
75 | { |
76 | register char *s; | |
77 | struct x25_packet *xp = mtod(m, struct x25_packet *); | |
78 | register int i, len = 0, cnt = 0; | |
79 | ||
80 | if (xcp -> xc_ptrace == 0) | |
81 | return; | |
82 | ||
83 | i = pk_decode (xp) / MAXSTATES; | |
84 | for (; m; m = m -> m_next) { | |
85 | len = len + m -> m_len; | |
86 | ++cnt; | |
87 | } | |
88 | printf ("LCN=%d %s: %s #=%d, len=%d ", | |
89 | LCN(xp), dir, pk_name[i], cnt, len); | |
90 | for (s = (char *) xp, i = 0; i < 5; ++i, ++s) | |
91 | printf ("%x ", (int) * s & 0xff); | |
92 | printf ("\n"); | |
93 | } | |
94 | ||
4c45483e | 95 | void |
15637ed4 | 96 | mbuf_cache(c, m) |
4c45483e GW |
97 | register struct mbuf_cache *c; |
98 | struct mbuf *m; | |
15637ed4 RG |
99 | { |
100 | register struct mbuf **mp; | |
101 | ||
102 | if (c->mbc_size != c->mbc_oldsize) { | |
103 | unsigned zero_size, copy_size; | |
104 | unsigned new_size = c->mbc_size * sizeof(m); | |
105 | caddr_t cache = (caddr_t)c->mbc_cache; | |
106 | ||
107 | if (new_size) { | |
108 | c->mbc_cache = (struct mbuf **) | |
109 | malloc(new_size, M_MBUF, M_NOWAIT); | |
110 | if (c->mbc_cache == 0) { | |
111 | c->mbc_cache = (struct mbuf **)cache; | |
112 | return; | |
113 | } | |
114 | c->mbc_num %= c->mbc_size; | |
115 | } else | |
116 | c->mbc_cache = 0; | |
117 | if (c->mbc_size < c->mbc_oldsize) { | |
118 | register struct mbuf **mplim; | |
119 | mp = c->mbc_size + (struct mbuf **)cache; | |
120 | mplim = c->mbc_oldsize + (struct mbuf **)cache; | |
121 | while (mp < mplim) | |
122 | m_freem(*mp++); | |
123 | zero_size = 0; | |
124 | } else | |
125 | zero_size = (c->mbc_size - c->mbc_oldsize) * sizeof(m); | |
126 | copy_size = new_size - zero_size; | |
127 | c->mbc_oldsize = c->mbc_size; | |
128 | if (copy_size) | |
129 | bcopy(cache, (caddr_t)c->mbc_cache, copy_size); | |
130 | if (cache) | |
131 | free(cache, M_MBUF); | |
132 | if (zero_size) | |
133 | bzero(copy_size + (caddr_t)c->mbc_cache, zero_size); | |
134 | } | |
135 | if (c->mbc_size == 0) | |
136 | return; | |
137 | mp = c->mbc_cache + c->mbc_num; | |
138 | c->mbc_num = (1 + c->mbc_num) % c->mbc_size; | |
139 | if (*mp) | |
140 | m_freem(*mp); | |
141 | *mp = m_copym(m, 0, M_COPYALL, M_DONTWAIT); | |
142 | } |