1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * 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 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * 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 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
70int 71link_QueueLen(struct link *l) 72{ 73 int i, len; 74 75 for (i = 0, len = 0; i < LINK_QUEUES; i++) 76 len += l->Queue[i].qlen; 77 78 return len; 79} 80 81int 82link_QueueBytes(struct link *l) 83{ 84 int i, len, bytes; 85 struct mbuf *m; 86 87 bytes = 0; 88 for (i = 0, len = 0; i < LINK_QUEUES; i++) { 89 len = l->Queue[i].qlen; 90 m = l->Queue[i].top; 91 while (len--) { 92 bytes += mbuf_Length(m); 93 m = m->pnext; 94 } 95 } 96 97 return bytes; 98} 99 100struct mbuf * 101link_Dequeue(struct link *l) 102{ 103 int pri; 104 struct mbuf *bp; 105 106 for (bp = (struct mbuf *)0, pri = LINK_QUEUES - 1; pri >= 0; pri--) 107 if (l->Queue[pri].qlen) { 108 bp = mbuf_Dequeue(l->Queue + pri); 109 log_Printf(LogDEBUG, "link_Dequeue: Dequeued from queue %d," 110 " containing %d more packets\n", pri, l->Queue[pri].qlen); 111 break; 112 } 113 114 return bp; 115} 116 117/* 118 * Write to the link. Actualy, requested packets are queued, and go out 119 * at some later time depending on the physical link implementation. 120 */ 121void 122link_Write(struct link *l, int pri, const char *ptr, int count) 123{ 124 struct mbuf *bp; 125 126 if(pri < 0 || pri >= LINK_QUEUES) 127 pri = 0; 128 129 bp = mbuf_Alloc(count, MB_LINK); 130 memcpy(MBUF_CTOP(bp), ptr, count); 131 132 mbuf_Enqueue(l->Queue + pri, bp); 133} 134 135void 136link_Output(struct link *l, int pri, struct mbuf *bp) 137{ 138 struct mbuf *wp; 139 int len; 140 141 if(pri < 0 || pri >= LINK_QUEUES) 142 pri = 0; 143 144 len = mbuf_Length(bp); 145 wp = mbuf_Alloc(len, MB_LINK); 146 mbuf_Read(bp, MBUF_CTOP(wp), len); 147 mbuf_Enqueue(l->Queue + pri, wp); 148} 149 150static struct protostatheader { 151 u_short number; 152 const char *name; 153} ProtocolStat[NPROTOSTAT] = { 154 { PROTO_IP, "IP" }, 155 { PROTO_VJUNCOMP, "VJ_UNCOMP" }, 156 { PROTO_VJCOMP, "VJ_COMP" }, 157 { PROTO_COMPD, "COMPD" }, 158 { PROTO_ICOMPD, "ICOMPD" }, 159 { PROTO_LCP, "LCP" }, 160 { PROTO_IPCP, "IPCP" }, 161 { PROTO_CCP, "CCP" }, 162 { PROTO_PAP, "PAP" }, 163 { PROTO_LQR, "LQR" }, 164 { PROTO_CHAP, "CHAP" }, 165 { PROTO_MP, "MULTILINK" }, 166 { 0, "Others" } 167}; 168 169void 170link_ProtocolRecord(struct link *l, u_short proto, int type) 171{ 172 int i; 173 174 for (i = 0; i < NPROTOSTAT; i++) 175 if (ProtocolStat[i].number == proto) 176 break; 177 178 if (type == PROTO_IN) 179 l->proto_in[i]++; 180 else 181 l->proto_out[i]++; 182} 183 184void 185link_ReportProtocolStatus(struct link *l, struct prompt *prompt) 186{ 187 int i; 188 189 prompt_Printf(prompt, " Protocol in out " 190 "Protocol in out\n"); 191 for (i = 0; i < NPROTOSTAT; i++) { 192 prompt_Printf(prompt, " %-9s: %8lu, %8lu", 193 ProtocolStat[i].name, l->proto_in[i], l->proto_out[i]); 194 if ((i % 2) == 0) 195 prompt_Printf(prompt, "\n"); 196 } 197 if (!(i % 2)) 198 prompt_Printf(prompt, "\n"); 199}
| 80int 81link_QueueLen(struct link *l) 82{ 83 int i, len; 84 85 for (i = 0, len = 0; i < LINK_QUEUES; i++) 86 len += l->Queue[i].qlen; 87 88 return len; 89} 90 91int 92link_QueueBytes(struct link *l) 93{ 94 int i, len, bytes; 95 struct mbuf *m; 96 97 bytes = 0; 98 for (i = 0, len = 0; i < LINK_QUEUES; i++) { 99 len = l->Queue[i].qlen; 100 m = l->Queue[i].top; 101 while (len--) { 102 bytes += mbuf_Length(m); 103 m = m->pnext; 104 } 105 } 106 107 return bytes; 108} 109 110struct mbuf * 111link_Dequeue(struct link *l) 112{ 113 int pri; 114 struct mbuf *bp; 115 116 for (bp = (struct mbuf *)0, pri = LINK_QUEUES - 1; pri >= 0; pri--) 117 if (l->Queue[pri].qlen) { 118 bp = mbuf_Dequeue(l->Queue + pri); 119 log_Printf(LogDEBUG, "link_Dequeue: Dequeued from queue %d," 120 " containing %d more packets\n", pri, l->Queue[pri].qlen); 121 break; 122 } 123 124 return bp; 125} 126 127/* 128 * Write to the link. Actualy, requested packets are queued, and go out 129 * at some later time depending on the physical link implementation. 130 */ 131void 132link_Write(struct link *l, int pri, const char *ptr, int count) 133{ 134 struct mbuf *bp; 135 136 if(pri < 0 || pri >= LINK_QUEUES) 137 pri = 0; 138 139 bp = mbuf_Alloc(count, MB_LINK); 140 memcpy(MBUF_CTOP(bp), ptr, count); 141 142 mbuf_Enqueue(l->Queue + pri, bp); 143} 144 145void 146link_Output(struct link *l, int pri, struct mbuf *bp) 147{ 148 struct mbuf *wp; 149 int len; 150 151 if(pri < 0 || pri >= LINK_QUEUES) 152 pri = 0; 153 154 len = mbuf_Length(bp); 155 wp = mbuf_Alloc(len, MB_LINK); 156 mbuf_Read(bp, MBUF_CTOP(wp), len); 157 mbuf_Enqueue(l->Queue + pri, wp); 158} 159 160static struct protostatheader { 161 u_short number; 162 const char *name; 163} ProtocolStat[NPROTOSTAT] = { 164 { PROTO_IP, "IP" }, 165 { PROTO_VJUNCOMP, "VJ_UNCOMP" }, 166 { PROTO_VJCOMP, "VJ_COMP" }, 167 { PROTO_COMPD, "COMPD" }, 168 { PROTO_ICOMPD, "ICOMPD" }, 169 { PROTO_LCP, "LCP" }, 170 { PROTO_IPCP, "IPCP" }, 171 { PROTO_CCP, "CCP" }, 172 { PROTO_PAP, "PAP" }, 173 { PROTO_LQR, "LQR" }, 174 { PROTO_CHAP, "CHAP" }, 175 { PROTO_MP, "MULTILINK" }, 176 { 0, "Others" } 177}; 178 179void 180link_ProtocolRecord(struct link *l, u_short proto, int type) 181{ 182 int i; 183 184 for (i = 0; i < NPROTOSTAT; i++) 185 if (ProtocolStat[i].number == proto) 186 break; 187 188 if (type == PROTO_IN) 189 l->proto_in[i]++; 190 else 191 l->proto_out[i]++; 192} 193 194void 195link_ReportProtocolStatus(struct link *l, struct prompt *prompt) 196{ 197 int i; 198 199 prompt_Printf(prompt, " Protocol in out " 200 "Protocol in out\n"); 201 for (i = 0; i < NPROTOSTAT; i++) { 202 prompt_Printf(prompt, " %-9s: %8lu, %8lu", 203 ProtocolStat[i].name, l->proto_in[i], l->proto_out[i]); 204 if ((i % 2) == 0) 205 prompt_Printf(prompt, "\n"); 206 } 207 if (!(i % 2)) 208 prompt_Printf(prompt, "\n"); 209}
|