* Compress/encrypt a packet and put the result in a new mbuf at *resultp. * The original mbuf is not free'd. */
| 474 | * The original mbuf is not free'd. |
| 475 | */ |
| 476 | static int |
| 477 | ng_mppc_compress(node_p node, struct mbuf **datap) |
| 478 | { |
| 479 | const priv_p priv = NG_NODE_PRIVATE(node); |
| 480 | struct ng_mppc_dir *const d = &priv->xmit; |
| 481 | u_int16_t header; |
| 482 | struct mbuf *m = *datap; |
| 483 | |
| 484 | /* We must own the mbuf chain exclusively to modify it. */ |
| 485 | m = m_unshare(m, M_NOWAIT); |
| 486 | if (m == NULL) |
| 487 | return (ENOMEM); |
| 488 | |
| 489 | /* Initialize */ |
| 490 | header = d->cc; |
| 491 | |
| 492 | /* Always set the flushed bit in stateless mode */ |
| 493 | if (d->flushed || ((d->cfg.bits & MPPE_STATELESS) != 0)) { |
| 494 | header |= MPPC_FLAG_FLUSHED; |
| 495 | d->flushed = 0; |
| 496 | } |
| 497 | |
| 498 | /* Compress packet (if compression enabled) */ |
| 499 | #ifdef NETGRAPH_MPPC_COMPRESSION |
| 500 | if ((d->cfg.bits & MPPC_BIT) != 0) { |
| 501 | u_short flags = MPPC_MANDATORY_COMPRESS_FLAGS; |
| 502 | u_char *inbuf, *outbuf; |
| 503 | int outlen, inlen, ina; |
| 504 | u_char *source, *dest; |
| 505 | u_long sourceCnt, destCnt; |
| 506 | int rtn; |
| 507 | |
| 508 | /* Work with contiguous regions of memory. */ |
| 509 | inlen = m->m_pkthdr.len; |
| 510 | if (m->m_next == NULL) { |
| 511 | inbuf = mtod(m, u_char *); |
| 512 | ina = 0; |
| 513 | } else { |
| 514 | inbuf = malloc(inlen, M_NETGRAPH_MPPC, M_NOWAIT); |
| 515 | if (inbuf == NULL) |
| 516 | goto err1; |
| 517 | m_copydata(m, 0, inlen, (caddr_t)inbuf); |
| 518 | ina = 1; |
| 519 | } |
| 520 | |
| 521 | outlen = MPPC_MAX_BLOWUP(inlen); |
| 522 | outbuf = malloc(outlen, M_NETGRAPH_MPPC, M_NOWAIT); |
| 523 | if (outbuf == NULL) { |
| 524 | if (ina) |
| 525 | free(inbuf, M_NETGRAPH_MPPC); |
| 526 | err1: |
| 527 | m_freem(m); |
| 528 | MPPC_InitCompressionHistory(d->history); |
| 529 | d->flushed = 1; |
| 530 | return (ENOMEM); |
| 531 | } |
| 532 | |
| 533 | /* Prepare to compress */ |
no test coverage detected