Lines Matching +full:cs +full:- +full:3
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
15 * 3. Neither the name of the University nor the names of its contributors
37 * - Initial distribution.
85 register struct cstate *tstate = comp->tstate;
88 for (i = max_state; i > 0; --i) {
90 tstate[i].cs_next = &tstate[i - 1];
94 comp->last_cs = &tstate[0];
95 comp->last_recv = 255;
96 comp->last_xmit = 255;
97 comp->flags = SLF_TOSS;
101 /* ENCODE encodes a number that is known to be non-zero. ENCODEZ
102 * checks for zero (since zero has to be encoded in the 32-bit, 3 byte
129 cp += 3; \
138 cp += 3; \
147 cp += 3; \
161 register struct cstate *cs = comp->last_cs->cs_next;
162 register u_int hlen = ip->ip_hl;
175 if ((ip->ip_off & htons(0x3fff)) || m->m_len < 40) {
177 ip->ip_off, (unsigned long)m->m_len);
189 * Packet is compressible -- we're going to send either a COMPRESSED_TCP or
195 slstat->sls_packets++;
196 if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr ||
197 ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr ||
198 *(int *) th != ((int *) &cs->cs_ip)[cs->cs_ip.ip_hl]) {
201 * Wasn't the first -- search for it.
208 * state for the datagram, the oldest state is (re-)used.
211 register struct cstate *lastcs = comp->last_cs;
214 lcs = cs;
215 cs = cs->cs_next;
216 slstat->sls_searches++;
217 if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr
218 && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr
219 && *(int *) th == ((int *) &cs->cs_ip)[cs->cs_ip.ip_hl])
221 } while (cs != lastcs);
224 * Didn't find it -- re-use oldest cstate. Send an uncompressed packet
230 slstat->sls_misses++;
231 comp->last_cs = lcs;
232 #define THOFFSET(th) (th->th_off)
233 hlen += th->th_off;
235 if (hlen > m->m_len)
242 * Found it -- move to the front on the connection list.
244 if (cs == lastcs)
245 comp->last_cs = lcs;
247 lcs->cs_next = cs->cs_next;
248 cs->cs_next = lastcs->cs_next;
249 lastcs->cs_next = cs;
256 * service. The 2nd line checks the "Don't fragment" bit. The 3rd line
257 * checks the time-to-live and protocol (the protocol check is unnecessary
263 oth = (struct tcphdr *) & ((int *) &cs->cs_ip)[hlen];
265 hlen += th->th_off;
267 if (hlen > m->m_len)
270 if (((u_short *) ip)[0] != ((u_short *) & cs->cs_ip)[0] ||
271 ((u_short *) ip)[3] != ((u_short *) & cs->cs_ip)[3] ||
272 ((u_short *) ip)[4] != ((u_short *) & cs->cs_ip)[4] ||
275 memcmp(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
277 memcmp(th + 1, oth + 1, (THOFFSET(th) - 5) << 2))) {
287 deltaS = ntohs(th->th_urp);
290 } else if (th->th_urp != oth->th_urp) {
293 * argh! URG not set but urp changed -- a sensible implementation should
299 deltaS = (u_short) (ntohs(th->th_win) - ntohs(oth->th_win));
304 deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack);
312 deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq);
331 if (ip->ip_len != cs->cs_ip.ip_len &&
332 ntohs(cs->cs_ip.ip_len) == hlen)
341 * actual changes match one of our special case encodings -- send packet
348 deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
356 if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
364 deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
376 deltaA = ntohs(th->th_sum);
377 memcpy(&cs->cs_ip, ip, hlen);
380 * We want to use the original packet as our compressed packet. (cp -
383 * id and two for the tcp checksum. So, (cp - new_seq) + 4 bytes of header
387 deltaS = cp - new_seq;
395 if (comp->last_xmit == cs->cs_id && compress_cid) {
396 hlen -= deltaS + 3;
400 comp->last_xmit = cs->cs_id;
401 hlen -= deltaS + 4;
404 *cp++ = cs->cs_id;
406 m->m_len -= hlen;
407 m->m_offset += hlen;
411 slstat->sls_compressed++;
415 * Update connection state cs & send uncompressed packet ('uncompressed'
420 memcpy(&cs->cs_ip, ip, hlen);
421 ip->ip_p = cs->cs_id;
422 comp->last_xmit = cs->cs_id;
434 register struct cstate *cs;
442 if (ip->ip_p > max_state)
444 cs = &comp->rstate[comp->last_recv = ip->ip_p];
445 comp->flags &= ~SLF_TOSS;
446 ip->ip_p = IPPROTO_TCP;
452 hlen = ip->ip_hl << 2;
459 memcpy(&cs->cs_ip, ip, hlen);
460 cs->cs_hlen = hlen;
461 slstat->sls_uncompressedin++;
472 slstat->sls_compressedin++;
482 if (*cp > max_state || comp->last_recv == 255)
485 comp->flags &= ~SLF_TOSS;
486 comp->last_recv = *cp++;
493 if (comp->flags & SLF_TOSS) {
494 slstat->sls_tossed++;
498 cs = &comp->rstate[comp->last_recv];
499 hlen = cs->cs_ip.ip_hl << 2;
500 th = (struct tcphdr *) & ((u_char *) & cs->cs_ip)[hlen];
501 th->th_sum = htons((*cp << 8) | cp[1]);
511 register u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
513 th->th_ack = htonl(ntohl(th->th_ack) + i);
514 th->th_seq = htonl(ntohl(th->th_seq) + i);
519 th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len)
520 - cs->cs_hlen);
526 DECODEU(th->th_urp)
530 DECODES(th->th_win)
532 DECODEL(th->th_ack)
536 DECODEL(th->th_seq)
541 DECODES(cs->cs_ip.ip_id)
543 cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1);
546 cs->cs_ip.ip_id, (u_long)ntohl(th->th_seq));
555 len -= (cp - *bufp);
563 *bufp = cp - cs->cs_hlen;
564 len += cs->cs_hlen;
565 cs->cs_ip.ip_len = htons(len);
568 cs->cs_ip.ip_sum = 0;
569 bp = (u_short *)&cs->cs_ip;
570 for (changes = 0; hlen > 0; hlen -= 2)
574 cs->cs_ip.ip_sum = ~changes;
577 memcpy(*bufp, &cs->cs_ip, cs->cs_hlen);
581 comp->flags |= SLF_TOSS;
582 slstat->sls_errorin++;
589 prompt_Printf(arg->prompt, "VJ compression statistics:\n");
590 prompt_Printf(arg->prompt, " Out: %d (compress) / %d (total)",
591 arg->bundle->ncp.ipcp.vj.slstat.sls_compressed,
592 arg->bundle->ncp.ipcp.vj.slstat.sls_packets);
593 prompt_Printf(arg->prompt, " %d (miss) / %d (search)\n",
594 arg->bundle->ncp.ipcp.vj.slstat.sls_misses,
595 arg->bundle->ncp.ipcp.vj.slstat.sls_searches);
596 prompt_Printf(arg->prompt, " In: %d (compress), %d (uncompress)",
597 arg->bundle->ncp.ipcp.vj.slstat.sls_compressedin,
598 arg->bundle->ncp.ipcp.vj.slstat.sls_uncompressedin);
599 prompt_Printf(arg->prompt, " %d (error), %d (tossed)\n",
600 arg->bundle->ncp.ipcp.vj.slstat.sls_errorin,
601 arg->bundle->ncp.ipcp.vj.slstat.sls_tossed);