MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_mppc_compress

Function ng_mppc_compress

freebsd/netgraph/ng_mppc.c:476–619  ·  view source on GitHub ↗

* Compress/encrypt a packet and put the result in a new mbuf at *resultp. * The original mbuf is not free'd. */

Source from the content-addressed store, hash-verified

474 * The original mbuf is not free'd.
475 */
476static int
477ng_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);
526err1:
527 m_freem(m);
528 MPPC_InitCompressionHistory(d->history);
529 d->flushed = 1;
530 return (ENOMEM);
531 }
532
533 /* Prepare to compress */

Callers 1

ng_mppc_rcvdataFunction · 0.85

Calls 13

m_unshareFunction · 0.85
mallocFunction · 0.85
m_copydataFunction · 0.85
MPPC_CompressFunction · 0.85
m_copybackFunction · 0.85
m_adjFunction · 0.85
ng_mppc_updatekeyFunction · 0.85
rc4_initFunction · 0.85
rc4_cryptFunction · 0.85
be16encFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected