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

Function sl_uncompress_tcp_core

freebsd/net/slcompress.c:452–591  ·  view source on GitHub ↗

* Uncompress a packet of total length total_len. The first buflen * bytes are at buf; this must include the entire (compressed or * uncompressed) TCP/IP header. This procedure returns the length * of the VJ header, with a pointer to the uncompressed IP header * in *hdrp and its length in *hlenp. */

Source from the content-addressed store, hash-verified

450 * in *hdrp and its length in *hlenp.
451 */
452int
453sl_uncompress_tcp_core(u_char *buf, int buflen, int total_len, u_int type,
454 struct slcompress *comp, u_char **hdrp, u_int *hlenp)
455{
456 u_char *cp;
457 u_int hlen, changes;
458 struct tcphdr *th;
459 struct cstate *cs;
460 struct ip *ip;
461 u_int16_t *bp;
462 u_int vjlen;
463
464 switch (type) {
465 case TYPE_UNCOMPRESSED_TCP:
466 ip = (struct ip *) buf;
467 if (ip->ip_p >= MAX_STATES)
468 goto bad;
469 cs = &comp->rstate[comp->last_recv = ip->ip_p];
470 comp->flags &=~ SLF_TOSS;
471 ip->ip_p = IPPROTO_TCP;
472 /*
473 * Calculate the size of the TCP/IP header and make sure that
474 * we don't overflow the space we have available for it.
475 */
476 hlen = ip->ip_hl << 2;
477 if (hlen + sizeof(struct tcphdr) > buflen)
478 goto bad;
479 hlen += ((struct tcphdr *)&((char *)ip)[hlen])->th_off << 2;
480 if (hlen > MAX_HDR || hlen > buflen)
481 goto bad;
482 BCOPY(ip, &cs->cs_ip, hlen);
483 cs->cs_hlen = hlen;
484 INCR(sls_uncompressedin)
485 *hdrp = (u_char *) &cs->cs_ip;
486 *hlenp = hlen;
487 return (0);
488
489 default:
490 goto bad;
491
492 case TYPE_COMPRESSED_TCP:
493 break;
494 }
495 /* We've got a compressed packet. */
496 INCR(sls_compressedin)
497 cp = buf;
498 changes = *cp++;
499 if (changes & NEW_C) {
500 /* Make sure the state index is in range, then grab the state.
501 * If we have a good state index, clear the 'discard' flag. */
502 if (*cp >= MAX_STATES)
503 goto bad;
504
505 comp->flags &=~ SLF_TOSS;
506 comp->last_recv = *cp++;
507 } else {
508 /* this packet has an implicit state index. If we've
509 * had a line error since the last time we got an

Callers 3

sppp_inputFunction · 0.85
sl_uncompress_tcpFunction · 0.85
ng_vjc_rcvdataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected