15d9e6103SBrian Somers /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni *
45d9e6103SBrian Somers * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
55d9e6103SBrian Somers * All rights reserved.
65d9e6103SBrian Somers *
75d9e6103SBrian Somers * Redistribution and use in source and binary forms, with or without
85d9e6103SBrian Somers * modification, are permitted provided that the following conditions
95d9e6103SBrian Somers * are met:
105d9e6103SBrian Somers * 1. Redistributions of source code must retain the above copyright
115d9e6103SBrian Somers * notice, this list of conditions and the following disclaimer.
125d9e6103SBrian Somers * 2. Redistributions in binary form must reproduce the above copyright
135d9e6103SBrian Somers * notice, this list of conditions and the following disclaimer in the
145d9e6103SBrian Somers * documentation and/or other materials provided with the distribution.
155d9e6103SBrian Somers *
165d9e6103SBrian Somers * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
175d9e6103SBrian Somers * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
185d9e6103SBrian Somers * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
195d9e6103SBrian Somers * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
205d9e6103SBrian Somers * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
215d9e6103SBrian Somers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
225d9e6103SBrian Somers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
235d9e6103SBrian Somers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
245d9e6103SBrian Somers * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
255d9e6103SBrian Somers * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
265d9e6103SBrian Somers * SUCH DAMAGE.
275d9e6103SBrian Somers */
285d9e6103SBrian Somers
295d9e6103SBrian Somers #include <sys/types.h>
305d9e6103SBrian Somers
315d9e6103SBrian Somers #include <stdio.h>
325d9e6103SBrian Somers #include <termios.h>
335d9e6103SBrian Somers
345d9e6103SBrian Somers #include "layer.h"
355d9e6103SBrian Somers #include "defs.h"
365d9e6103SBrian Somers #include "mbuf.h"
375d9e6103SBrian Somers #include "log.h"
385d9e6103SBrian Somers #include "sync.h"
395d9e6103SBrian Somers #include "timer.h"
405d9e6103SBrian Somers #include "lqr.h"
415d9e6103SBrian Somers #include "hdlc.h"
425d9e6103SBrian Somers #include "throughput.h"
435d9e6103SBrian Somers #include "fsm.h"
445d9e6103SBrian Somers #include "lcp.h"
455d9e6103SBrian Somers #include "ccp.h"
465d9e6103SBrian Somers #include "link.h"
475d9e6103SBrian Somers #include "async.h"
485d9e6103SBrian Somers #include "descriptor.h"
495d9e6103SBrian Somers #include "physical.h"
505d9e6103SBrian Somers
515d9e6103SBrian Somers static struct mbuf *
sync_LayerPush(struct bundle * bundle __unused,struct link * l __unused,struct mbuf * bp,int pri __unused,u_short * proto __unused)52057f1760SBrian Somers sync_LayerPush(struct bundle *bundle __unused, struct link *l __unused,
53057f1760SBrian Somers struct mbuf *bp, int pri __unused, u_short *proto __unused)
546815097bSBrian Somers {
556815097bSBrian Somers log_DumpBp(LogSYNC, "Write", bp);
5626af0ae9SBrian Somers m_settype(bp, MB_SYNCOUT);
57a57095e7SBrian Somers bp->priv = 0;
586815097bSBrian Somers return bp;
596815097bSBrian Somers }
606815097bSBrian Somers
616815097bSBrian Somers static struct mbuf *
sync_LayerPull(struct bundle * b __unused,struct link * l,struct mbuf * bp,u_short * proto __unused)62057f1760SBrian Somers sync_LayerPull(struct bundle *b __unused, struct link *l, struct mbuf *bp,
63057f1760SBrian Somers u_short *proto __unused)
645d9e6103SBrian Somers {
655d9e6103SBrian Somers struct physical *p = link2physical(l);
66a57095e7SBrian Somers int len;
675d9e6103SBrian Somers
685d9e6103SBrian Somers if (!p)
695d9e6103SBrian Somers log_Printf(LogERROR, "Can't Pull a sync packet from a logical link\n");
705d9e6103SBrian Somers else {
716815097bSBrian Somers log_DumpBp(LogSYNC, "Read", bp);
726815097bSBrian Somers
736815097bSBrian Somers /* Either done here or by the HDLC layer */
74a57095e7SBrian Somers len = m_length(bp);
75a57095e7SBrian Somers p->hdlc.lqm.ifInOctets += len + 1; /* plus 1 flag octet! */
76a57095e7SBrian Somers p->hdlc.lqm.lqr.InGoodOctets += len + 1; /* plus 1 flag octet! */
77a57095e7SBrian Somers p->hdlc.lqm.ifInUniPackets++;
7826af0ae9SBrian Somers m_settype(bp, MB_SYNCIN);
795d9e6103SBrian Somers }
805d9e6103SBrian Somers
815d9e6103SBrian Somers return bp;
825d9e6103SBrian Somers }
835d9e6103SBrian Somers
84ef868a34SBrian Somers struct layer synclayer = { LAYER_SYNC, "sync", sync_LayerPush, sync_LayerPull };
85