146686Sbrian/*- 246686Sbrian * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 346686Sbrian * All rights reserved. 446686Sbrian * 546686Sbrian * Redistribution and use in source and binary forms, with or without 646686Sbrian * modification, are permitted provided that the following conditions 746686Sbrian * are met: 846686Sbrian * 1. Redistributions of source code must retain the above copyright 946686Sbrian * notice, this list of conditions and the following disclaimer. 1046686Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1146686Sbrian * notice, this list of conditions and the following disclaimer in the 1246686Sbrian * documentation and/or other materials provided with the distribution. 1346686Sbrian * 1446686Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1546686Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1646686Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1746686Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1846686Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1946686Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2046686Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2146686Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2246686Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2346686Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2446686Sbrian * SUCH DAMAGE. 2546686Sbrian * 2650479Speter * $FreeBSD: releng/11.0/usr.sbin/ppp/sync.c 134789 2004-09-05 01:46:52Z brian $ 2746686Sbrian */ 2846686Sbrian 2946686Sbrian#include <sys/types.h> 3046686Sbrian 3146686Sbrian#include <stdio.h> 3246686Sbrian#include <termios.h> 3346686Sbrian 3446686Sbrian#include "layer.h" 3546686Sbrian#include "defs.h" 3646686Sbrian#include "mbuf.h" 3746686Sbrian#include "log.h" 3846686Sbrian#include "sync.h" 3946686Sbrian#include "timer.h" 4046686Sbrian#include "lqr.h" 4146686Sbrian#include "hdlc.h" 4246686Sbrian#include "throughput.h" 4346686Sbrian#include "fsm.h" 4446686Sbrian#include "lcp.h" 4546686Sbrian#include "ccp.h" 4646686Sbrian#include "link.h" 4746686Sbrian#include "async.h" 4846686Sbrian#include "descriptor.h" 4946686Sbrian#include "physical.h" 5046686Sbrian 5146686Sbrianstatic struct mbuf * 52134789Sbriansync_LayerPush(struct bundle *bundle __unused, struct link *l __unused, 53134789Sbrian struct mbuf *bp, int pri __unused, u_short *proto __unused) 5447061Sbrian{ 5547061Sbrian log_DumpBp(LogSYNC, "Write", bp); 5654912Sbrian m_settype(bp, MB_SYNCOUT); 57131327Sbrian bp->priv = 0; 5847061Sbrian return bp; 5947061Sbrian} 6047061Sbrian 6147061Sbrianstatic struct mbuf * 62134789Sbriansync_LayerPull(struct bundle *b __unused, struct link *l, struct mbuf *bp, 63134789Sbrian u_short *proto __unused) 6446686Sbrian{ 6546686Sbrian struct physical *p = link2physical(l); 66131327Sbrian int len; 6746686Sbrian 6846686Sbrian if (!p) 6946686Sbrian log_Printf(LogERROR, "Can't Pull a sync packet from a logical link\n"); 7046686Sbrian else { 7147061Sbrian log_DumpBp(LogSYNC, "Read", bp); 7247061Sbrian 7347061Sbrian /* Either done here or by the HDLC layer */ 74131327Sbrian len = m_length(bp); 75131327Sbrian p->hdlc.lqm.ifInOctets += len + 1; /* plus 1 flag octet! */ 76131327Sbrian p->hdlc.lqm.lqr.InGoodOctets += len + 1; /* plus 1 flag octet! */ 77131327Sbrian p->hdlc.lqm.ifInUniPackets++; 7854912Sbrian m_settype(bp, MB_SYNCIN); 7946686Sbrian } 8046686Sbrian 8146686Sbrian return bp; 8246686Sbrian} 8346686Sbrian 8447062Sbrianstruct layer synclayer = { LAYER_SYNC, "sync", sync_LayerPush, sync_LayerPull }; 85