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

Function ng_pred1_decompress

freebsd/netgraph/ng_pred1.c:464–564  ·  view source on GitHub ↗

* Decompress/decrypt 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

462 * The original mbuf is not free'd.
463 */
464static int
465ng_pred1_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
466{
467 const priv_p priv = NG_NODE_PRIVATE(node);
468 int inlen;
469 uint16_t len, len1, cf, lenn;
470 uint16_t fcs;
471
472 /* Initialize. */
473 *resultp = NULL;
474
475 inlen = m->m_pkthdr.len;
476
477 if (inlen > PRED1_BUF_SIZE) {
478 priv->stats.Errors++;
479 NG_FREE_M(m);
480 return (ENOMEM);
481 }
482
483 /* We must own the mbuf chain exclusively to modify it. */
484 m = m_unshare(m, M_NOWAIT);
485 if (m == NULL) {
486 priv->stats.Errors++;
487 return (ENOMEM);
488 }
489
490 /* Work with contiguous regions of memory. */
491 m_copydata(m, 0, inlen, (caddr_t)priv->inbuf);
492
493 priv->stats.InOctets += inlen;
494
495 /* Get initial length value. */
496 len = priv->inbuf[0] << 8;
497 len += priv->inbuf[1];
498
499 cf = (len & 0x8000);
500 len &= 0x7fff;
501
502 /* Is data compressed or not really? */
503 if (cf) {
504 priv->stats.FramesComp++;
505 len1 = Pred1Decompress(node, priv->inbuf + 2, priv->outbuf,
506 inlen - 4, PRED1_BUF_SIZE);
507 if (len != len1) {
508 /* Error is detected. Send reset request */
509 m_freem(m);
510 priv->stats.Errors++;
511 log(LOG_NOTICE, "ng_pred1: Comp length error (%d) "
512 "--> len (%d)\n", len, len1);
513 return (EIO);
514 }
515
516 /*
517 * CRC check on receive is defined in RFC. It is surely required
518 * for compressed frames to signal dictionary corruption,
519 * but it is actually useless for uncompressed frames because
520 * the same check has already done by HDLC and/or other layer.
521 */

Callers 1

ng_pred1_rcvdataFunction · 0.85

Calls 9

m_unshareFunction · 0.85
m_copydataFunction · 0.85
Pred1DecompressFunction · 0.85
Crc16Function · 0.85
m_copybackFunction · 0.85
m_adjFunction · 0.85
Pred1SyncTableFunction · 0.85
m_freemFunction · 0.50
logFunction · 0.50

Tested by

no test coverage detected