ng_deflate.c (166019) | ng_deflate.c (187405) |
---|---|
1/*- 2 * Copyright (c) 2006 Alexander Motin <mav@alkar.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * | 1/*- 2 * Copyright (c) 2006 Alexander Motin <mav@alkar.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/sys/netgraph/ng_deflate.c 166019 2007-01-15 05:55:56Z glebius $ | 27 * $FreeBSD: head/sys/netgraph/ng_deflate.c 187405 2009-01-18 19:25:36Z mav $ |
28 */ 29 30/* 31 * Deflate PPP compression netgraph node type. 32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> --- 418 unchanged lines hidden (view full) --- 454 priv->stats.InOctets+=inlen; 455 456 if (inlen > DEFLATE_BUF_SIZE) { 457 priv->stats.Errors++; 458 NG_FREE_M(m); 459 return (ENOMEM); 460 } 461 | 28 */ 29 30/* 31 * Deflate PPP compression netgraph node type. 32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> --- 418 unchanged lines hidden (view full) --- 454 priv->stats.InOctets+=inlen; 455 456 if (inlen > DEFLATE_BUF_SIZE) { 457 priv->stats.Errors++; 458 NG_FREE_M(m); 459 return (ENOMEM); 460 } 461 |
462 /* We must own the mbuf chain exclusively to modify it. */ 463 m = m_unshare(m, M_DONTWAIT); 464 if (m == NULL) { 465 priv->stats.Errors++; 466 return (ENOMEM); 467 } 468 |
|
462 /* Work with contiguous regions of memory. */ 463 m_copydata(m, 0, inlen, (caddr_t)priv->inbuf); 464 outlen = DEFLATE_BUF_SIZE; 465 466 /* Compress "inbuf" into "outbuf". */ 467 /* Prepare to compress. */ 468 if (priv->inbuf[0] != 0) { 469 priv->cx.next_in = priv->inbuf; --- 22 unchanged lines hidden (view full) --- 492 493 /* If we can't compress this packet, send it as-is. */ 494 if (outlen > inlen) { 495 /* Return original packet uncompressed. */ 496 *resultp = m; 497 priv->stats.FramesUncomp++; 498 priv->stats.OutOctets+=inlen; 499 } else { | 469 /* Work with contiguous regions of memory. */ 470 m_copydata(m, 0, inlen, (caddr_t)priv->inbuf); 471 outlen = DEFLATE_BUF_SIZE; 472 473 /* Compress "inbuf" into "outbuf". */ 474 /* Prepare to compress. */ 475 if (priv->inbuf[0] != 0) { 476 priv->cx.next_in = priv->inbuf; --- 22 unchanged lines hidden (view full) --- 499 500 /* If we can't compress this packet, send it as-is. */ 501 if (outlen > inlen) { 502 /* Return original packet uncompressed. */ 503 *resultp = m; 504 priv->stats.FramesUncomp++; 505 priv->stats.OutOctets+=inlen; 506 } else { |
500 NG_FREE_M(m); 501 | |
502 /* Install header. */ 503 ((u_int16_t *)priv->outbuf)[0] = htons(PROT_COMPD); 504 ((u_int16_t *)priv->outbuf)[1] = htons(priv->seqnum); 505 506 /* Return packet in an mbuf. */ | 507 /* Install header. */ 508 ((u_int16_t *)priv->outbuf)[0] = htons(PROT_COMPD); 509 ((u_int16_t *)priv->outbuf)[1] = htons(priv->seqnum); 510 511 /* Return packet in an mbuf. */ |
507 *resultp = m_devget((caddr_t)priv->outbuf, outlen, 0, NULL, 508 NULL); 509 if (*resultp == NULL) { | 512 m_copyback(m, 0, outlen, (caddr_t)priv->outbuf); 513 if (m->m_pkthdr.len < outlen) { 514 m_freem(m); |
510 priv->stats.Errors++; 511 return (ENOMEM); | 515 priv->stats.Errors++; 516 return (ENOMEM); |
512 }; | 517 } else if (outlen < m->m_pkthdr.len) 518 m_adj(m, outlen - m->m_pkthdr.len); 519 *resultp = m; |
513 priv->stats.FramesComp++; 514 priv->stats.OutOctets+=outlen; 515 } 516 517 /* Update sequence number. */ 518 priv->seqnum++; 519 520 return (0); --- 20 unchanged lines hidden (view full) --- 541 542 if (inlen > DEFLATE_BUF_SIZE) { 543 priv->stats.Errors++; 544 NG_FREE_M(m); 545 priv->seqnum = 0; 546 return (ENOMEM); 547 } 548 | 520 priv->stats.FramesComp++; 521 priv->stats.OutOctets+=outlen; 522 } 523 524 /* Update sequence number. */ 525 priv->seqnum++; 526 527 return (0); --- 20 unchanged lines hidden (view full) --- 548 549 if (inlen > DEFLATE_BUF_SIZE) { 550 priv->stats.Errors++; 551 NG_FREE_M(m); 552 priv->seqnum = 0; 553 return (ENOMEM); 554 } 555 |
556 /* We must own the mbuf chain exclusively to modify it. */ 557 m = m_unshare(m, M_DONTWAIT); 558 if (m == NULL) { 559 priv->stats.Errors++; 560 return (ENOMEM); 561 } 562 |
|
549 /* Work with contiguous regions of memory. */ 550 m_copydata(m, 0, inlen, (caddr_t)priv->inbuf); 551 552 /* Separate proto. */ 553 if ((priv->inbuf[0] & 0x01) != 0) { 554 proto = priv->inbuf[0]; 555 offset = 1; 556 } else { --- 48 unchanged lines hidden (view full) --- 605 default: 606 return (EINVAL); 607 } 608 } 609 610 /* Calculate resulting size. */ 611 outlen -= priv->cx.avail_out; 612 | 563 /* Work with contiguous regions of memory. */ 564 m_copydata(m, 0, inlen, (caddr_t)priv->inbuf); 565 566 /* Separate proto. */ 567 if ((priv->inbuf[0] & 0x01) != 0) { 568 proto = priv->inbuf[0]; 569 offset = 1; 570 } else { --- 48 unchanged lines hidden (view full) --- 619 default: 620 return (EINVAL); 621 } 622 } 623 624 /* Calculate resulting size. */ 625 outlen -= priv->cx.avail_out; 626 |
613 NG_FREE_M(m); 614 | |
615 /* Decompress protocol. */ 616 if ((priv->outbuf[1] & 0x01) != 0) { 617 priv->outbuf[0] = 0; 618 /* Return packet in an mbuf. */ | 627 /* Decompress protocol. */ 628 if ((priv->outbuf[1] & 0x01) != 0) { 629 priv->outbuf[0] = 0; 630 /* Return packet in an mbuf. */ |
619 *resultp = m_devget((caddr_t)priv->outbuf, outlen, 0, 620 NULL, NULL); | 631 m_copyback(m, 0, outlen, (caddr_t)priv->outbuf); |
621 } else { 622 outlen--; 623 /* Return packet in an mbuf. */ | 632 } else { 633 outlen--; 634 /* Return packet in an mbuf. */ |
624 *resultp = m_devget((caddr_t)(priv->outbuf + 1), 625 outlen, 0, NULL, NULL); | 635 m_copyback(m, 0, outlen, (caddr_t)(priv->outbuf + 1)); |
626 } | 636 } |
627 if (*resultp == NULL) { | 637 if (m->m_pkthdr.len < outlen) { 638 m_freem(m); |
628 priv->stats.Errors++; 629 priv->seqnum = 0; 630 return (ENOMEM); | 639 priv->stats.Errors++; 640 priv->seqnum = 0; 641 return (ENOMEM); |
631 }; | 642 } else if (outlen < m->m_pkthdr.len) 643 m_adj(m, outlen - m->m_pkthdr.len); 644 *resultp = m; |
632 priv->stats.FramesPlain++; 633 priv->stats.OutOctets+=outlen; 634 635 } else { /* Packet is not compressed, just update dictionary. */ 636 priv->stats.FramesUncomp++; 637 if (priv->inbuf[0] == 0) { 638 priv->cx.next_in = priv->inbuf + 1; /* compress protocol */ 639 priv->cx.avail_in = inlen - 1; --- 45 unchanged lines hidden --- | 645 priv->stats.FramesPlain++; 646 priv->stats.OutOctets+=outlen; 647 648 } else { /* Packet is not compressed, just update dictionary. */ 649 priv->stats.FramesUncomp++; 650 if (priv->inbuf[0] == 0) { 651 priv->cx.next_in = priv->inbuf + 1; /* compress protocol */ 652 priv->cx.avail_in = inlen - 1; --- 45 unchanged lines hidden --- |