hdlc.c (32381) | hdlc.c (32663) |
---|---|
1/* 2 * PPP High Level Link Control (HDLC) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * PPP High Level Link Control (HDLC) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: hdlc.c,v 1.26 1998/01/06 00:58:31 brian Exp $ | 20 * $Id: hdlc.c,v 1.27 1998/01/10 01:55:10 brian Exp $ |
21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25#include <netinet/in.h> 26 27#include <stdio.h> 28#include <string.h> --- 15 unchanged lines hidden (view full) --- 44#include "lcp.h" 45#include "async.h" 46#include "lqr.h" 47#include "loadalias.h" 48#include "vars.h" 49#include "modem.h" 50#include "ccp.h" 51 | 21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25#include <netinet/in.h> 26 27#include <stdio.h> 28#include <string.h> --- 15 unchanged lines hidden (view full) --- 44#include "lcp.h" 45#include "async.h" 46#include "lqr.h" 47#include "loadalias.h" 48#include "vars.h" 49#include "modem.h" 50#include "ccp.h" 51 |
52struct hdlcstat { | 52static struct hdlcstat { |
53 int badfcs; 54 int badaddr; 55 int badcommand; 56 int unknownproto; 57} HdlcStat; 58 59static int ifOutPackets; 60static int ifOutOctets; 61static int ifOutLQRs; | 53 int badfcs; 54 int badaddr; 55 int badcommand; 56 int unknownproto; 57} HdlcStat; 58 59static int ifOutPackets; 60static int ifOutOctets; 61static int ifOutLQRs; |
62static int ifInPackets; 63static int ifInOctets; | |
64 | 62 |
65struct protostat { | 63static struct protostat { |
66 u_short number; 67 const char *name; 68 u_long in_count; 69 u_long out_count; 70} ProtocolStat[] = { 71 { PROTO_IP, "IP" }, 72 { PROTO_VJUNCOMP, "VJ_UNCOMP" }, 73 { PROTO_VJCOMP, "VJ_COMP" }, --- 42 unchanged lines hidden (view full) --- 116 /* f8 */ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 117}; 118 119u_char EscMap[33]; 120 121void 122HdlcInit() 123{ | 64 u_short number; 65 const char *name; 66 u_long in_count; 67 u_long out_count; 68} ProtocolStat[] = { 69 { PROTO_IP, "IP" }, 70 { PROTO_VJUNCOMP, "VJ_UNCOMP" }, 71 { PROTO_VJCOMP, "VJ_COMP" }, --- 42 unchanged lines hidden (view full) --- 114 /* f8 */ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 115}; 116 117u_char EscMap[33]; 118 119void 120HdlcInit() 121{ |
124 ifInOctets = ifOutOctets = 0; 125 ifInPackets = ifOutPackets = 0; | 122 ifOutOctets = 0; 123 ifOutPackets = 0; |
126 ifOutLQRs = 0; 127} 128 129/* 130 * HDLC FCS computation. Read RFC 1171 Appendix B and CCITT X.25 section 131 * 2.27 for further details. 132 */ 133inline u_short 134HdlcFcs(u_short fcs, u_char * cp, int len) 135{ 136 while (len--) 137 fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; 138 return (fcs); 139} 140 | 124 ifOutLQRs = 0; 125} 126 127/* 128 * HDLC FCS computation. Read RFC 1171 Appendix B and CCITT X.25 section 129 * 2.27 for further details. 130 */ 131inline u_short 132HdlcFcs(u_short fcs, u_char * cp, int len) 133{ 134 while (len--) 135 fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; 136 return (fcs); 137} 138 |
141inline u_short | 139static inline u_short |
142HdlcFcsBuf(u_short fcs, struct mbuf *m) 143{ 144 int len; 145 u_char *pos, *end; 146 147 len = plength(m); 148 pos = MBUF_CTOP(m); 149 end = pos + m->cnt; --- 18 unchanged lines hidden (view full) --- 168 u_short fcs; 169 170 if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */ 171 if (CcpFsm.state == ST_OPENED) 172 if (CcpOutput(pri, proto, bp)) 173 return; 174 175 if (DEV_IS_SYNC) | 140HdlcFcsBuf(u_short fcs, struct mbuf *m) 141{ 142 int len; 143 u_char *pos, *end; 144 145 len = plength(m); 146 pos = MBUF_CTOP(m); 147 end = pos + m->cnt; --- 18 unchanged lines hidden (view full) --- 166 u_short fcs; 167 168 if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */ 169 if (CcpFsm.state == ST_OPENED) 170 if (CcpOutput(pri, proto, bp)) 171 return; 172 173 if (DEV_IS_SYNC) |
176 mfcs = NULLBUFF; | 174 mfcs = NULL; |
177 else 178 mfcs = mballoc(2, MB_HDLCOUT); 179 180 mhp = mballoc(4, MB_HDLCOUT); 181 mhp->cnt = 0; 182 cp = MBUF_CTOP(mhp); 183 if (proto == PROTO_LCP || LcpInfo.his_acfcomp == 0) { 184 *cp++ = HDLC_ADDR; --- 181 unchanged lines hidden (view full) --- 366 for (f = 0; f < NPROTOCOLS; f++) 367 if (proto >= protocols[f].from && proto <= protocols[f].to) 368 return protocols[f].name; 369 else if (proto < protocols[f].from) 370 break; 371 return "unrecognised protocol"; 372} 373 | 175 else 176 mfcs = mballoc(2, MB_HDLCOUT); 177 178 mhp = mballoc(4, MB_HDLCOUT); 179 mhp->cnt = 0; 180 cp = MBUF_CTOP(mhp); 181 if (proto == PROTO_LCP || LcpInfo.his_acfcomp == 0) { 182 *cp++ = HDLC_ADDR; --- 181 unchanged lines hidden (view full) --- 364 for (f = 0; f < NPROTOCOLS; f++) 365 if (proto >= protocols[f].from && proto <= protocols[f].to) 366 return protocols[f].name; 367 else if (proto < protocols[f].from) 368 break; 369 return "unrecognised protocol"; 370} 371 |
374void | 372static void |
375DecodePacket(u_short proto, struct mbuf * bp) 376{ 377 u_char *cp; 378 379 LogPrintf(LogDEBUG, "DecodePacket: proto = 0x%04x\n", proto); 380 381 /* 382 * If proto isn't PROTO_COMPD, we still want to pass it to the --- 18 unchanged lines hidden (view full) --- 401 LqrInput(bp); 402 break; 403 case PROTO_CHAP: 404 ChapInput(bp); 405 break; 406 case PROTO_VJUNCOMP: 407 case PROTO_VJCOMP: 408 bp = VjCompInput(bp, proto); | 373DecodePacket(u_short proto, struct mbuf * bp) 374{ 375 u_char *cp; 376 377 LogPrintf(LogDEBUG, "DecodePacket: proto = 0x%04x\n", proto); 378 379 /* 380 * If proto isn't PROTO_COMPD, we still want to pass it to the --- 18 unchanged lines hidden (view full) --- 399 LqrInput(bp); 400 break; 401 case PROTO_CHAP: 402 ChapInput(bp); 403 break; 404 case PROTO_VJUNCOMP: 405 case PROTO_VJCOMP: 406 bp = VjCompInput(bp, proto); |
409 if (bp == NULLBUFF) { | 407 if (bp == NULL) { |
410 break; 411 } 412 /* fall down */ 413 case PROTO_IP: 414 IpInput(bp); 415 break; 416 case PROTO_IPCP: 417 IpcpInput(bp); --- 95 unchanged lines hidden (view full) --- 513 bp->cnt -= 2; /* discard FCS part */ 514 515 if (bp->cnt < 2) { /* XXX: raise this bar ? */ 516 pfree(bp); 517 return; 518 } 519 cp = MBUF_CTOP(bp); 520 | 408 break; 409 } 410 /* fall down */ 411 case PROTO_IP: 412 IpInput(bp); 413 break; 414 case PROTO_IPCP: 415 IpcpInput(bp); --- 95 unchanged lines hidden (view full) --- 511 bp->cnt -= 2; /* discard FCS part */ 512 513 if (bp->cnt < 2) { /* XXX: raise this bar ? */ 514 pfree(bp); 515 return; 516 } 517 cp = MBUF_CTOP(bp); 518 |
521 ifInPackets++; 522 ifInOctets += bp->cnt; 523 | |
524 if (!LcpInfo.want_acfcomp) { 525 526 /* 527 * We expect that packet is not compressed. 528 */ 529 addr = *cp++; 530 if (addr != HDLC_ADDR) { 531 HisLqrSave.SaveInErrors++; --- 50 unchanged lines hidden --- | 519 if (!LcpInfo.want_acfcomp) { 520 521 /* 522 * We expect that packet is not compressed. 523 */ 524 addr = *cp++; 525 if (addr != HDLC_ADDR) { 526 HisLqrSave.SaveInErrors++; --- 50 unchanged lines hidden --- |