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 | * | |
78ed81a3 | 38 | * from: @(#)pk_debug.c 7.7 (Berkeley) 5/9/91 |
39 | * $Id$ | |
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 | ||
56 | char *pk_state[] = { | |
57 | "Listen", "Ready", "Received-Call", | |
58 | "Sent-Call", "Data-Transfer","Received-Clear", | |
59 | "Sent-Clear", | |
60 | }; | |
61 | ||
62 | char *pk_name[] = { | |
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 | ||
70 | pk_trace (xcp, m, dir) | |
71 | struct x25config *xcp; | |
72 | register struct mbuf *m; | |
73 | char *dir; | |
74 | { | |
75 | register char *s; | |
76 | struct x25_packet *xp = mtod(m, struct x25_packet *); | |
77 | register int i, len = 0, cnt = 0; | |
78 | ||
79 | if (xcp -> xc_ptrace == 0) | |
80 | return; | |
81 | ||
82 | i = pk_decode (xp) / MAXSTATES; | |
83 | for (; m; m = m -> m_next) { | |
84 | len = len + m -> m_len; | |
85 | ++cnt; | |
86 | } | |
87 | printf ("LCN=%d %s: %s #=%d, len=%d ", | |
88 | LCN(xp), dir, pk_name[i], cnt, len); | |
89 | for (s = (char *) xp, i = 0; i < 5; ++i, ++s) | |
90 | printf ("%x ", (int) * s & 0xff); | |
91 | printf ("\n"); | |
92 | } | |
93 | ||
94 | mbuf_cache(c, m) | |
95 | register struct mbuf_cache *c; | |
96 | struct mbuf *m; | |
97 | { | |
98 | register struct mbuf **mp; | |
99 | ||
100 | if (c->mbc_size != c->mbc_oldsize) { | |
101 | unsigned zero_size, copy_size; | |
102 | unsigned new_size = c->mbc_size * sizeof(m); | |
103 | caddr_t cache = (caddr_t)c->mbc_cache; | |
104 | ||
105 | if (new_size) { | |
106 | c->mbc_cache = (struct mbuf **) | |
107 | malloc(new_size, M_MBUF, M_NOWAIT); | |
108 | if (c->mbc_cache == 0) { | |
109 | c->mbc_cache = (struct mbuf **)cache; | |
110 | return; | |
111 | } | |
112 | c->mbc_num %= c->mbc_size; | |
113 | } else | |
114 | c->mbc_cache = 0; | |
115 | if (c->mbc_size < c->mbc_oldsize) { | |
116 | register struct mbuf **mplim; | |
117 | mp = c->mbc_size + (struct mbuf **)cache; | |
118 | mplim = c->mbc_oldsize + (struct mbuf **)cache; | |
119 | while (mp < mplim) | |
120 | m_freem(*mp++); | |
121 | zero_size = 0; | |
122 | } else | |
123 | zero_size = (c->mbc_size - c->mbc_oldsize) * sizeof(m); | |
124 | copy_size = new_size - zero_size; | |
125 | c->mbc_oldsize = c->mbc_size; | |
126 | if (copy_size) | |
127 | bcopy(cache, (caddr_t)c->mbc_cache, copy_size); | |
128 | if (cache) | |
129 | free(cache, M_MBUF); | |
130 | if (zero_size) | |
131 | bzero(copy_size + (caddr_t)c->mbc_cache, zero_size); | |
132 | } | |
133 | if (c->mbc_size == 0) | |
134 | return; | |
135 | mp = c->mbc_cache + c->mbc_num; | |
136 | c->mbc_num = (1 + c->mbc_num) % c->mbc_size; | |
137 | if (*mp) | |
138 | m_freem(*mp); | |
139 | *mp = m_copym(m, 0, M_COPYALL, M_DONTWAIT); | |
140 | } |