15d9e6103SBrian Somers /*- 25d9e6103SBrian Somers * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 35d9e6103SBrian Somers * All rights reserved. 45d9e6103SBrian Somers * 55d9e6103SBrian Somers * Redistribution and use in source and binary forms, with or without 65d9e6103SBrian Somers * modification, are permitted provided that the following conditions 75d9e6103SBrian Somers * are met: 85d9e6103SBrian Somers * 1. Redistributions of source code must retain the above copyright 95d9e6103SBrian Somers * notice, this list of conditions and the following disclaimer. 105d9e6103SBrian Somers * 2. Redistributions in binary form must reproduce the above copyright 115d9e6103SBrian Somers * notice, this list of conditions and the following disclaimer in the 125d9e6103SBrian Somers * documentation and/or other materials provided with the distribution. 135d9e6103SBrian Somers * 145d9e6103SBrian Somers * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 155d9e6103SBrian Somers * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 165d9e6103SBrian Somers * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 175d9e6103SBrian Somers * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 185d9e6103SBrian Somers * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 195d9e6103SBrian Somers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 205d9e6103SBrian Somers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 215d9e6103SBrian Somers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 225d9e6103SBrian Somers * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 235d9e6103SBrian Somers * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 245d9e6103SBrian Somers * SUCH DAMAGE. 255d9e6103SBrian Somers * 2697d92980SPeter Wemm * $FreeBSD$ 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 "defs.h" 355d9e6103SBrian Somers #include "layer.h" 365d9e6103SBrian Somers #include "timer.h" 375d9e6103SBrian Somers #include "fsm.h" 385d9e6103SBrian Somers #include "log.h" 395d9e6103SBrian Somers #include "mbuf.h" 405d9e6103SBrian Somers #include "acf.h" 415d9e6103SBrian Somers #include "proto.h" 425d9e6103SBrian Somers #include "lcp.h" 435d9e6103SBrian Somers #include "throughput.h" 445d9e6103SBrian Somers #include "lqr.h" 455d9e6103SBrian Somers #include "hdlc.h" 465d9e6103SBrian Somers #include "ccp.h" 475d9e6103SBrian Somers #include "link.h" 485d9e6103SBrian Somers #include "descriptor.h" 495d9e6103SBrian Somers #include "async.h" 505d9e6103SBrian Somers #include "physical.h" 515d9e6103SBrian Somers 525d9e6103SBrian Somers int 535d9e6103SBrian Somers acf_WrapperOctets(struct lcp *lcp, u_short proto) 545d9e6103SBrian Somers { 555d9e6103SBrian Somers return (proto == PROTO_LCP || lcp->his_acfcomp == 0) ? 2 : 0; 565d9e6103SBrian Somers } 575d9e6103SBrian Somers 585d9e6103SBrian Somers static struct mbuf * 595d9e6103SBrian Somers acf_LayerPush(struct bundle *b, struct link *l, struct mbuf *bp, 605d9e6103SBrian Somers int pri, u_short *proto) 615d9e6103SBrian Somers { 625d9e6103SBrian Somers const u_char cp[2] = { HDLC_ADDR, HDLC_UI }; 635d9e6103SBrian Somers 64411675baSBrian Somers if (*proto == PROTO_LCP || l->lcp.his_acfcomp == 0) { 6526af0ae9SBrian Somers bp = m_prepend(bp, cp, 2, 0); 6626af0ae9SBrian Somers m_settype(bp, MB_ACFOUT); 67411675baSBrian Somers } 685d9e6103SBrian Somers 695d9e6103SBrian Somers return bp; 705d9e6103SBrian Somers } 715d9e6103SBrian Somers 725d9e6103SBrian Somers static struct mbuf * 735d9e6103SBrian Somers acf_LayerPull(struct bundle *b, struct link *l, struct mbuf *bp, u_short *proto) 745d9e6103SBrian Somers { 755d9e6103SBrian Somers struct physical *p = link2physical(l); 765d9e6103SBrian Somers u_char cp[2]; 775d9e6103SBrian Somers 785d9e6103SBrian Somers if (!p) { 795d9e6103SBrian Somers log_Printf(LogERROR, "Can't Pull an acf packet from a logical link\n"); 805d9e6103SBrian Somers return bp; 815d9e6103SBrian Somers } 825d9e6103SBrian Somers 835d9e6103SBrian Somers if (mbuf_View(bp, cp, 2) == 2) { 845d9e6103SBrian Somers if (!p->link.lcp.want_acfcomp) { 855d9e6103SBrian Somers /* We expect the packet not to be compressed */ 865d9e6103SBrian Somers bp = mbuf_Read(bp, cp, 2); 875d9e6103SBrian Somers if (cp[0] != HDLC_ADDR) { 885d9e6103SBrian Somers p->hdlc.lqm.SaveInErrors++; 895d9e6103SBrian Somers p->hdlc.stats.badaddr++; 905d9e6103SBrian Somers log_Printf(LogDEBUG, "acf_LayerPull: addr 0x%02x\n", cp[0]); 9126af0ae9SBrian Somers m_freem(bp); 925d9e6103SBrian Somers return NULL; 935d9e6103SBrian Somers } 945d9e6103SBrian Somers if (cp[1] != HDLC_UI) { 955d9e6103SBrian Somers p->hdlc.lqm.SaveInErrors++; 965d9e6103SBrian Somers p->hdlc.stats.badcommand++; 975d9e6103SBrian Somers log_Printf(LogDEBUG, "acf_LayerPull: control 0x%02x\n", cp[1]); 9826af0ae9SBrian Somers m_freem(bp); 995d9e6103SBrian Somers return NULL; 1005d9e6103SBrian Somers } 10126af0ae9SBrian Somers m_settype(bp, MB_ACFIN); 1025d9e6103SBrian Somers } else if (cp[0] == HDLC_ADDR && cp[1] == HDLC_UI) { 1035d9e6103SBrian Somers /* 1045d9e6103SBrian Somers * We can receive compressed packets, but the peer still sends 1055d9e6103SBrian Somers * uncompressed packets (or maybe this is a PROTO_LCP packet) ! 1065d9e6103SBrian Somers */ 1075d9e6103SBrian Somers bp = mbuf_Read(bp, cp, 2); 10826af0ae9SBrian Somers m_settype(bp, MB_ACFIN); 1095d9e6103SBrian Somers } 1105d9e6103SBrian Somers } 1115d9e6103SBrian Somers 1125d9e6103SBrian Somers return bp; 1135d9e6103SBrian Somers } 1145d9e6103SBrian Somers 1155d9e6103SBrian Somers struct layer acflayer = { LAYER_ACF, "acf", acf_LayerPush, acf_LayerPull }; 116