Lines Matching +full:magic +full:- +full:packet
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
67 u_int32_t magic; member
77 struct hdlc *hdlc = &link2physical(lcp->fsm.link)->hdlc; in SendEchoReq()
80 echo.magic = htonl(lcp->want_magic); in SendEchoReq()
82 echo.sequence = htonl(hdlc->lqm.echo.seq_sent); in SendEchoReq()
83 fsm_Output(&lcp->fsm, CODE_ECHOREQ, hdlc->lqm.echo.seq_sent++, in SendEchoReq()
90 struct hdlc *hdlc = &link2physical(fp->link)->hdlc; in lqr_RecvEcho()
97 lqr.magic = ntohl(lqr.magic); in lqr_RecvEcho()
101 /* Tolerate echo replies with either magic number */ in lqr_RecvEcho()
102 if (lqr.magic != 0 && lqr.magic != lcp->his_magic && in lqr_RecvEcho()
103 lqr.magic != lcp->want_magic) { in lqr_RecvEcho()
104 log_Printf(LogWARN, "%s: lqr_RecvEcho: Bad magic: expected 0x%08x," in lqr_RecvEcho()
105 " got 0x%08x\n", fp->link->name, lcp->his_magic, lqr.magic); in lqr_RecvEcho()
112 || lqr.signature == lcp->want_magic) { /* some implementations return the wrong magic */ in lqr_RecvEcho()
114 if ((hdlc->lqm.echo.seq_recv > (u_int32_t)0 - 5 && lqr.sequence < 5) || in lqr_RecvEcho()
115 (hdlc->lqm.echo.seq_recv <= (u_int32_t)0 - 5 && in lqr_RecvEcho()
116 lqr.sequence > hdlc->lqm.echo.seq_recv)) in lqr_RecvEcho()
117 hdlc->lqm.echo.seq_recv = lqr.sequence; in lqr_RecvEcho()
122 log_Printf(LogWARN, "lqr_RecvEcho: Got packet size %zd, expecting %ld !\n", in lqr_RecvEcho()
148 bp->m_len -= extra; in SendLqrData()
149 bp->m_offset += extra; in SendLqrData()
152 * Send on the highest priority queue. We send garbage - the real data in SendLqrData()
155 * highest priority queue, and factors out packet & octet values from in SendLqrData()
158 link_PushPacket(lcp->fsm.link, bp, lcp->fsm.bundle, in SendLqrData()
159 LINK_QUEUES(lcp->fsm.link) - 1, PROTO_LQR); in SendLqrData()
166 struct physical *p = link2physical(lcp->fsm.link); in SendLqrReport()
168 timer_Stop(&p->hdlc.lqm.timer); in SendLqrReport()
170 if (p->hdlc.lqm.method & LQM_LQR) { in SendLqrReport()
171 if (p->hdlc.lqm.lqr.resent > 5) { in SendLqrReport()
174 lcp->fsm.link->name); in SendLqrReport()
176 lcp->fsm.link->name); in SendLqrReport()
177 p->hdlc.lqm.method = 0; in SendLqrReport()
178 datalink_Down(p->dl, CLOSE_NORMAL); in SendLqrReport()
181 p->hdlc.lqm.lqr.resent++; in SendLqrReport()
183 } else if (p->hdlc.lqm.method & LQM_ECHO) { in SendLqrReport()
184 if ((p->hdlc.lqm.echo.seq_sent > 5 && in SendLqrReport()
185 p->hdlc.lqm.echo.seq_sent - 5 > p->hdlc.lqm.echo.seq_recv) || in SendLqrReport()
186 (p->hdlc.lqm.echo.seq_sent <= 5 && in SendLqrReport()
187 p->hdlc.lqm.echo.seq_sent > p->hdlc.lqm.echo.seq_recv + 5)) { in SendLqrReport()
189 lcp->fsm.link->name); in SendLqrReport()
191 lcp->fsm.link->name); in SendLqrReport()
192 p->hdlc.lqm.method = 0; in SendLqrReport()
193 datalink_Down(p->dl, CLOSE_NORMAL); in SendLqrReport()
197 if (p->hdlc.lqm.method && p->hdlc.lqm.timer.load) in SendLqrReport()
198 timer_Start(&p->hdlc.lqm.timer); in SendLqrReport()
205 struct lcp *lcp = p->hdlc.lqm.owner; in lqr_Input()
209 log_Printf(LogERROR, "lqr_Input: Not a physical link - dropped\n"); in lqr_Input()
216 log_Printf(LogWARN, "lqr_Input: Got packet size %d, expecting %ld !\n", in lqr_Input()
218 else if (!IsAccepted(l->lcp.cfg.lqr) && !(p->hdlc.lqm.method & LQM_LQR)) { in lqr_Input()
220 lcp_SendProtoRej(lcp, MBUF_CTOP(bp), bp->m_len); in lqr_Input()
226 if (ntohl(lqr->MagicNumber) != lcp->his_magic) in lqr_Input()
227 log_Printf(LogWARN, "lqr_Input: magic 0x%08lx is wrong," in lqr_Input()
229 (u_long)ntohl(lqr->MagicNumber), (u_long)lcp->his_magic); in lqr_Input()
233 memcpy(&lastlqr, &p->hdlc.lqm.lqr.peer, sizeof lastlqr); in lqr_Input()
234 lqr_ChangeOrder(lqr, &p->hdlc.lqm.lqr.peer); in lqr_Input()
235 lqr_Dump(l->name, "Input", &p->hdlc.lqm.lqr.peer); in lqr_Input()
237 p->hdlc.lqm.lqr.resent = 0; in lqr_Input()
239 /* Snapshot our state when the LQR packet was received */ in lqr_Input()
240 memcpy(&p->hdlc.lqm.lqr.prevSave, &p->hdlc.lqm.lqr.Save, in lqr_Input()
241 sizeof p->hdlc.lqm.lqr.prevSave); in lqr_Input()
242 p->hdlc.lqm.lqr.Save.InLQRs = ++p->hdlc.lqm.lqr.InLQRs; in lqr_Input()
243 p->hdlc.lqm.lqr.Save.InPackets = p->hdlc.lqm.ifInUniPackets; in lqr_Input()
244 p->hdlc.lqm.lqr.Save.InDiscards = p->hdlc.lqm.ifInDiscards; in lqr_Input()
245 p->hdlc.lqm.lqr.Save.InErrors = p->hdlc.lqm.ifInErrors; in lqr_Input()
246 p->hdlc.lqm.lqr.Save.InOctets = p->hdlc.lqm.lqr.InGoodOctets; in lqr_Input()
248 lqr_Analyse(&p->hdlc, &lastlqr, &p->hdlc.lqm.lqr.peer); in lqr_Input()
254 if (p->hdlc.lqm.timer.load == 0 || !(p->hdlc.lqm.method & LQM_LQR) || in lqr_Input()
256 lastlqr.PeerInLQRs == p->hdlc.lqm.lqr.peer.PeerInLQRs)) in lqr_Input()
270 struct physical *physical = link2physical(lcp->fsm.link); in lqr_Setup()
273 physical->hdlc.lqm.lqr.resent = 0; in lqr_Setup()
274 physical->hdlc.lqm.echo.seq_sent = 0; in lqr_Setup()
275 physical->hdlc.lqm.echo.seq_recv = 0; in lqr_Setup()
276 memset(&physical->hdlc.lqm.lqr.peer, '\0', in lqr_Setup()
277 sizeof physical->hdlc.lqm.lqr.peer); in lqr_Setup()
279 physical->hdlc.lqm.method = lcp->cfg.echo ? LQM_ECHO : 0; in lqr_Setup()
280 if (IsEnabled(lcp->cfg.lqr) && !REJECTED(lcp, TY_QUALPROTO)) in lqr_Setup()
281 physical->hdlc.lqm.method |= LQM_LQR; in lqr_Setup()
282 timer_Stop(&physical->hdlc.lqm.timer); in lqr_Setup()
284 physical->hdlc.lqm.lqr.peer_timeout = lcp->his_lqrperiod; in lqr_Setup()
285 if (lcp->his_lqrperiod) in lqr_Setup()
287 physical->link.name, lcp->his_lqrperiod / 100, in lqr_Setup()
288 lcp->his_lqrperiod % 100); in lqr_Setup()
290 period = lcp->want_lqrperiod ? in lqr_Setup()
291 lcp->want_lqrperiod : lcp->cfg.lqrperiod * 100; in lqr_Setup()
292 physical->hdlc.lqm.timer.func = SendLqrReport; in lqr_Setup()
293 physical->hdlc.lqm.timer.name = "lqm"; in lqr_Setup()
294 physical->hdlc.lqm.timer.arg = lcp; in lqr_Setup()
296 if (lcp->want_lqrperiod || physical->hdlc.lqm.method & LQM_ECHO) { in lqr_Setup()
298 physical->link.name, lcp->want_lqrperiod ? "LQR" : "LCP ECHO", in lqr_Setup()
300 physical->hdlc.lqm.timer.load = period * SECTICKS / 100; in lqr_Setup()
302 physical->hdlc.lqm.timer.load = 0; in lqr_Setup()
303 if (!lcp->his_lqrperiod) in lqr_Setup()
305 physical->link.name); in lqr_Setup()
312 struct physical *p = link2physical(lcp->fsm.link); in lqr_Start()
315 if (p->hdlc.lqm.timer.load) in lqr_Start()
322 struct physical *p = link2physical(lcp->fsm.link); in lqr_reStart()
325 if (p->hdlc.lqm.timer.load) in lqr_reStart()
326 timer_Start(&p->hdlc.lqm.timer); in lqr_reStart()
332 timer_Stop(&physical->hdlc.lqm.timer); in lqr_StopTimer()
340 physical->link.name); in lqr_Stop()
343 physical->link.name); in lqr_Stop()
344 physical->hdlc.lqm.method &= ~method; in lqr_Stop()
345 if (physical->hdlc.lqm.method) in lqr_Stop()
346 SendLqrReport(physical->hdlc.lqm.owner); in lqr_Stop()
348 timer_Stop(&physical->hdlc.lqm.timer); in lqr_Stop()
356 log_Printf(LogLQM, " Magic: %08x LastOutLQRs: %08x\n", in lqr_Dump()
357 lqr->MagicNumber, lqr->LastOutLQRs); in lqr_Dump()
359 lqr->LastOutPackets, lqr->LastOutOctets); in lqr_Dump()
361 lqr->PeerInLQRs, lqr->PeerInPackets); in lqr_Dump()
363 lqr->PeerInDiscards, lqr->PeerInErrors); in lqr_Dump()
365 lqr->PeerInOctets, lqr->PeerOutLQRs); in lqr_Dump()
367 lqr->PeerOutPackets, lqr->PeerOutOctets); in lqr_Dump()
377 if (!newlqr->PeerInLQRs) /* No analysis possible yet! */ in lqr_Analyse()
382 LQRs = (newlqr->LastOutLQRs - oldlqr->LastOutLQRs) - in lqr_Analyse()
383 (newlqr->PeerInLQRs - oldlqr->PeerInLQRs); in lqr_Analyse()
384 transitLQRs = hdlc->lqm.lqr.OutLQRs - newlqr->LastOutLQRs; in lqr_Analyse()
385 pkts = (newlqr->LastOutPackets - oldlqr->LastOutPackets) - in lqr_Analyse()
386 (newlqr->PeerInPackets - oldlqr->PeerInPackets); in lqr_Analyse()
387 octets = (newlqr->LastOutOctets - oldlqr->LastOutOctets) - in lqr_Analyse()
388 (newlqr->PeerInOctets - oldlqr->PeerInOctets); in lqr_Analyse()
389 log_Printf(LogLQM, " Outbound lossage: %d LQR%s (%d en route), %d packet%s," in lqr_Analyse()
394 pkts = (newlqr->PeerOutPackets - oldlqr->PeerOutPackets) - in lqr_Analyse()
395 (hdlc->lqm.lqr.Save.InPackets - hdlc->lqm.lqr.prevSave.InPackets); in lqr_Analyse()
396 octets = (newlqr->PeerOutOctets - oldlqr->PeerOutOctets) - in lqr_Analyse()
397 (hdlc->lqm.lqr.Save.InOctets - hdlc->lqm.lqr.prevSave.InOctets); in lqr_Analyse()
398 log_Printf(LogLQM, " Inbound lossage: %d packet%s, %d octet%s\n", in lqr_Analyse()
402 disc = newlqr->PeerInDiscards - oldlqr->PeerInDiscards; in lqr_Analyse()
403 err = newlqr->PeerInErrors - oldlqr->PeerInErrors; in lqr_Analyse()
424 /* Oops - can't happen :-] */ in lqr_LayerPush()
432 /*- in lqr_LayerPush()
436 * including the packet header, the information field, and any padding. in lqr_LayerPush()
449 p->hdlc.lqm.ifOutUniPackets++; in lqr_LayerPush()
450 p->hdlc.lqm.ifOutOctets += len + 1; /* plus 1 flag octet! */ in lqr_LayerPush()
451 for (layer = 0; layer < l->nlayers; layer++) in lqr_LayerPush()
452 switch (l->layer[layer]->type) { in lqr_LayerPush()
454 p->hdlc.lqm.ifOutOctets += acf_WrapperOctets(&l->lcp, *proto); in lqr_LayerPush()
457 /* Not included - see rfc1989 */ in lqr_LayerPush()
460 p->hdlc.lqm.ifOutOctets += hdlc_WrapperOctets(); in lqr_LayerPush()
463 layer = l->nlayers; in lqr_LayerPush()
466 p->hdlc.lqm.ifOutOctets += proto_WrapperOctets(&l->lcp, *proto); in lqr_LayerPush()
473 l->layer[layer]->name); in lqr_LayerPush()
478 /* Overwrite the entire packet (created in SendLqrData()) */ in lqr_LayerPush()
482 p->hdlc.lqm.lqr.OutLQRs++; in lqr_LayerPush()
486 * onto the highest priority queue by factoring out packet & octet in lqr_LayerPush()
492 lqr.MagicNumber = p->link.lcp.want_magic; in lqr_LayerPush()
493 lqr.LastOutLQRs = p->hdlc.lqm.lqr.peer.PeerOutLQRs; in lqr_LayerPush()
494 lqr.LastOutPackets = p->hdlc.lqm.lqr.peer.PeerOutPackets; in lqr_LayerPush()
495 lqr.LastOutOctets = p->hdlc.lqm.lqr.peer.PeerOutOctets; in lqr_LayerPush()
496 lqr.PeerInLQRs = p->hdlc.lqm.lqr.Save.InLQRs; in lqr_LayerPush()
497 lqr.PeerInPackets = p->hdlc.lqm.lqr.Save.InPackets; in lqr_LayerPush()
498 lqr.PeerInDiscards = p->hdlc.lqm.lqr.Save.InDiscards; in lqr_LayerPush()
499 lqr.PeerInErrors = p->hdlc.lqm.lqr.Save.InErrors; in lqr_LayerPush()
500 lqr.PeerInOctets = p->hdlc.lqm.lqr.Save.InOctets; in lqr_LayerPush()
501 lqr.PeerOutLQRs = p->hdlc.lqm.lqr.OutLQRs; in lqr_LayerPush()
502 lqr.PeerOutPackets = p->hdlc.lqm.ifOutUniPackets - pending_pkts; in lqr_LayerPush()
504 lqr.PeerOutOctets = p->hdlc.lqm.ifOutOctets - pending_octets - pending_pkts; in lqr_LayerPush()
505 lqr_Dump(l->name, "Output", &lqr); in lqr_LayerPush()