link.c (50867) | link.c (54912) |
---|---|
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 unchanged lines hidden (view full) --- 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 unchanged lines hidden (view full) --- 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 * |
26 * $FreeBSD: head/usr.sbin/ppp/link.c 50867 1999-09-04 00:00:21Z brian $ | 26 * $FreeBSD: head/usr.sbin/ppp/link.c 54912 1999-12-20 20:29:47Z brian $ |
27 * 28 */ 29 30#include <sys/types.h> 31#include <netinet/in_systm.h> 32#include <sys/un.h> 33#include <netinet/in.h> 34#include <netinet/ip.h> --- 48 unchanged lines hidden (view full) --- 83link_SequenceQueue(struct link *l) 84{ 85 struct mqueue *queue, *highest; 86 87 log_Printf(LogDEBUG, "link_SequenceQueue\n"); 88 89 highest = LINK_HIGHQ(l); 90 for (queue = l->Queue; queue < highest; queue++) | 27 * 28 */ 29 30#include <sys/types.h> 31#include <netinet/in_systm.h> 32#include <sys/un.h> 33#include <netinet/in.h> 34#include <netinet/ip.h> --- 48 unchanged lines hidden (view full) --- 83link_SequenceQueue(struct link *l) 84{ 85 struct mqueue *queue, *highest; 86 87 log_Printf(LogDEBUG, "link_SequenceQueue\n"); 88 89 highest = LINK_HIGHQ(l); 90 for (queue = l->Queue; queue < highest; queue++) |
91 while (queue->qlen) 92 mbuf_Enqueue(highest, mbuf_Dequeue(queue)); | 91 while (queue->len) 92 m_enqueue(highest, m_dequeue(queue)); |
93} 94 95void 96link_DeleteQueue(struct link *l) 97{ 98 struct mqueue *queue, *highest; 99 100 highest = LINK_HIGHQ(l); 101 for (queue = l->Queue; queue <= highest; queue++) 102 while (queue->top) | 93} 94 95void 96link_DeleteQueue(struct link *l) 97{ 98 struct mqueue *queue, *highest; 99 100 highest = LINK_HIGHQ(l); 101 for (queue = l->Queue; queue <= highest; queue++) 102 while (queue->top) |
103 mbuf_Free(mbuf_Dequeue(queue)); | 103 m_freem(m_dequeue(queue)); |
104} 105 | 104} 105 |
106int | 106size_t |
107link_QueueLen(struct link *l) 108{ | 107link_QueueLen(struct link *l) 108{ |
109 int i, len; | 109 int i; 110 size_t len; |
110 111 for (i = 0, len = 0; i < LINK_QUEUES(l); i++) | 111 112 for (i = 0, len = 0; i < LINK_QUEUES(l); i++) |
112 len += l->Queue[i].qlen; | 113 len += l->Queue[i].len; |
113 114 return len; 115} 116 | 114 115 return len; 116} 117 |
117int | 118size_t |
118link_QueueBytes(struct link *l) 119{ | 119link_QueueBytes(struct link *l) 120{ |
120 int i, len, bytes; | 121 int i; 122 size_t len, bytes; |
121 struct mbuf *m; 122 123 bytes = 0; 124 for (i = 0, len = 0; i < LINK_QUEUES(l); i++) { | 123 struct mbuf *m; 124 125 bytes = 0; 126 for (i = 0, len = 0; i < LINK_QUEUES(l); i++) { |
125 len = l->Queue[i].qlen; | 127 len = l->Queue[i].len; |
126 m = l->Queue[i].top; 127 while (len--) { | 128 m = l->Queue[i].top; 129 while (len--) { |
128 bytes += mbuf_Length(m); 129 m = m->pnext; | 130 bytes += m_length(m); 131 m = m->m_nextpkt; |
130 } 131 } 132 133 return bytes; 134} 135 136struct mbuf * 137link_Dequeue(struct link *l) 138{ 139 int pri; 140 struct mbuf *bp; 141 142 for (bp = NULL, pri = LINK_QUEUES(l) - 1; pri >= 0; pri--) | 132 } 133 } 134 135 return bytes; 136} 137 138struct mbuf * 139link_Dequeue(struct link *l) 140{ 141 int pri; 142 struct mbuf *bp; 143 144 for (bp = NULL, pri = LINK_QUEUES(l) - 1; pri >= 0; pri--) |
143 if (l->Queue[pri].qlen) { 144 bp = mbuf_Dequeue(l->Queue + pri); | 145 if (l->Queue[pri].len) { 146 bp = m_dequeue(l->Queue + pri); |
145 log_Printf(LogDEBUG, "link_Dequeue: Dequeued from queue %d," | 147 log_Printf(LogDEBUG, "link_Dequeue: Dequeued from queue %d," |
146 " containing %d more packets\n", pri, l->Queue[pri].qlen); | 148 " containing %lu more packets\n", pri, 149 (u_long)l->Queue[pri].len); |
147 break; 148 } 149 150 return bp; 151} 152 153static struct protostatheader { 154 u_short number; --- 62 unchanged lines hidden (view full) --- 217 if(pri < 0 || pri >= LINK_QUEUES(l)) 218 pri = 0; 219 220 for (layer = l->nlayers; layer && bp; layer--) 221 if (l->layer[layer - 1]->push != NULL) 222 bp = (*l->layer[layer - 1]->push)(b, l, bp, pri, &proto); 223 224 if (bp) { | 150 break; 151 } 152 153 return bp; 154} 155 156static struct protostatheader { 157 u_short number; --- 62 unchanged lines hidden (view full) --- 220 if(pri < 0 || pri >= LINK_QUEUES(l)) 221 pri = 0; 222 223 for (layer = l->nlayers; layer && bp; layer--) 224 if (l->layer[layer - 1]->push != NULL) 225 bp = (*l->layer[layer - 1]->push)(b, l, bp, pri, &proto); 226 227 if (bp) { |
225 link_AddOutOctets(l, mbuf_Length(bp)); | 228 link_AddOutOctets(l, m_length(bp)); |
226 log_Printf(LogDEBUG, "link_PushPacket: Transmit proto 0x%04x\n", proto); | 229 log_Printf(LogDEBUG, "link_PushPacket: Transmit proto 0x%04x\n", proto); |
227 mbuf_Enqueue(l->Queue + pri, mbuf_Contiguous(bp)); | 230 m_enqueue(l->Queue + pri, m_pullup(bp)); |
228 } 229} 230 231void 232link_PullPacket(struct link *l, char *buf, size_t len, struct bundle *b) 233{ 234 struct mbuf *bp, *lbp[LAYER_MAX], *next; 235 u_short lproto[LAYER_MAX], proto; 236 int layer; 237 238 /* 239 * When we ``pull'' a packet from the link, it gets processed by the 240 * ``pull'' function in each layer starting at the bottom. 241 * Each ``pull'' may produce multiple packets, chained together using | 231 } 232} 233 234void 235link_PullPacket(struct link *l, char *buf, size_t len, struct bundle *b) 236{ 237 struct mbuf *bp, *lbp[LAYER_MAX], *next; 238 u_short lproto[LAYER_MAX], proto; 239 int layer; 240 241 /* 242 * When we ``pull'' a packet from the link, it gets processed by the 243 * ``pull'' function in each layer starting at the bottom. 244 * Each ``pull'' may produce multiple packets, chained together using |
242 * bp->pnext. | 245 * bp->m_nextpkt. |
243 * Each packet that results from each pull has to be pulled through 244 * all of the higher layers before the next resulting packet is pulled 245 * through anything; this ensures that packets that depend on the 246 * fsm state resulting from the receipt of the previous packet aren't 247 * surprised. 248 */ 249 250 link_AddInOctets(l, len); 251 252 memset(lbp, '\0', sizeof lbp); | 246 * Each packet that results from each pull has to be pulled through 247 * all of the higher layers before the next resulting packet is pulled 248 * through anything; this ensures that packets that depend on the 249 * fsm state resulting from the receipt of the previous packet aren't 250 * surprised. 251 */ 252 253 link_AddInOctets(l, len); 254 255 memset(lbp, '\0', sizeof lbp); |
253 lbp[0] = mbuf_Alloc(len, MB_UNKNOWN); | 256 lbp[0] = m_get(len, MB_UNKNOWN); |
254 memcpy(MBUF_CTOP(lbp[0]), buf, len); 255 lproto[0] = 0; 256 layer = 0; 257 258 while (layer || lbp[layer]) { 259 if (lbp[layer] == NULL) { 260 layer--; 261 continue; 262 } 263 bp = lbp[layer]; | 257 memcpy(MBUF_CTOP(lbp[0]), buf, len); 258 lproto[0] = 0; 259 layer = 0; 260 261 while (layer || lbp[layer]) { 262 if (lbp[layer] == NULL) { 263 layer--; 264 continue; 265 } 266 bp = lbp[layer]; |
264 lbp[layer] = bp->pnext; 265 bp->pnext = NULL; | 267 lbp[layer] = bp->m_nextpkt; 268 bp->m_nextpkt = NULL; |
266 proto = lproto[layer]; 267 268 if (l->layer[layer]->pull != NULL) 269 bp = (*l->layer[layer]->pull)(b, l, bp, &proto); 270 271 if (layer == l->nlayers - 1) { 272 /* We've just done the top layer, despatch the packet(s) */ 273 while (bp) { | 269 proto = lproto[layer]; 270 271 if (l->layer[layer]->pull != NULL) 272 bp = (*l->layer[layer]->pull)(b, l, bp, &proto); 273 274 if (layer == l->nlayers - 1) { 275 /* We've just done the top layer, despatch the packet(s) */ 276 while (bp) { |
274 next = bp->pnext; 275 bp->pnext = NULL; | 277 next = bp->m_nextpkt; 278 bp->m_nextpkt = NULL; |
276 log_Printf(LogDEBUG, "link_PullPacket: Despatch proto 0x%04x\n", proto); 277 Despatch(b, l, bp, proto); 278 bp = next; 279 } 280 } else { 281 lbp[++layer] = bp; 282 lproto[layer] = proto; 283 } --- 47 unchanged lines hidden (view full) --- 331 } 332 333 if (bp) { 334 struct physical *p = link2physical(l); 335 336 log_Printf(LogPHASE, "%s protocol 0x%04x (%s)\n", 337 f == DSIZE ? "Unknown" : "Unexpected", proto, 338 hdlc_Protocol2Nam(proto)); | 279 log_Printf(LogDEBUG, "link_PullPacket: Despatch proto 0x%04x\n", proto); 280 Despatch(b, l, bp, proto); 281 bp = next; 282 } 283 } else { 284 lbp[++layer] = bp; 285 lproto[layer] = proto; 286 } --- 47 unchanged lines hidden (view full) --- 334 } 335 336 if (bp) { 337 struct physical *p = link2physical(l); 338 339 log_Printf(LogPHASE, "%s protocol 0x%04x (%s)\n", 340 f == DSIZE ? "Unknown" : "Unexpected", proto, 341 hdlc_Protocol2Nam(proto)); |
339 bp = mbuf_Contiguous(proto_Prepend(bp, proto, 0, 0)); 340 lcp_SendProtoRej(&l->lcp, MBUF_CTOP(bp), bp->cnt); | 342 bp = m_pullup(proto_Prepend(bp, proto, 0, 0)); 343 lcp_SendProtoRej(&l->lcp, MBUF_CTOP(bp), bp->m_len); |
341 if (p) { 342 p->hdlc.lqm.SaveInDiscards++; 343 p->hdlc.stats.unknownproto++; 344 } | 344 if (p) { 345 p->hdlc.lqm.SaveInDiscards++; 346 p->hdlc.stats.unknownproto++; 347 } |
345 mbuf_Free(bp); | 348 m_freem(bp); |
346 } 347} 348 349int 350link_ShowLayers(struct cmdargs const *arg) 351{ 352 struct link *l = command_ChooseLink(arg); 353 int layer; 354 355 for (layer = l->nlayers; layer; layer--) 356 prompt_Printf(arg->prompt, "%s%s", layer == l->nlayers ? "" : ", ", 357 l->layer[layer - 1]->name); 358 if (l->nlayers) 359 prompt_Printf(arg->prompt, "\n"); 360 361 return 0; 362} | 349 } 350} 351 352int 353link_ShowLayers(struct cmdargs const *arg) 354{ 355 struct link *l = command_ChooseLink(arg); 356 int layer; 357 358 for (layer = l->nlayers; layer; layer--) 359 prompt_Printf(arg->prompt, "%s%s", layer == l->nlayers ? "" : ", ", 360 l->layer[layer - 1]->name); 361 if (l->nlayers) 362 prompt_Printf(arg->prompt, "\n"); 363 364 return 0; 365} |