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.
53 #define INCR(counter) ++comp->counter;
65 struct cstate *tstate = comp->tstate;
67 if (max_state == -1) {
68 max_state = MAX_STATES - 1;
72 bzero((char *)comp->tstate, sizeof(comp->tstate));
73 bzero((char *)comp->rstate, sizeof(comp->rstate));
75 for (i = max_state; i > 0; --i) {
77 tstate[i].cs_next = &tstate[i - 1];
81 comp->last_cs = &tstate[0];
82 comp->last_recv = 255;
83 comp->last_xmit = 255;
84 comp->flags = SLF_TOSS;
87 /* ENCODE encodes a number that is known to be non-zero. ENCODEZ
88 * checks for zero (since zero has to be encoded in the long, 3 byte
115 cp += 3; \
124 cp += 3; \
133 cp += 3; \
147 * The caller is responsible for adjusting m->m_pkthdr.len upon return,
154 struct cstate *cs = comp->last_cs->cs_next;
155 u_int hlen = ip->ip_hl;
169 if ((ip->ip_off & htons(0x3fff)) || m->m_len < 40)
176 * Packet is compressible -- we're going to send either a
183 if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr ||
184 ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr ||
185 *(int32_t *)th != ((int32_t *)&cs->cs_ip)[cs->cs_ip.ip_hl]) {
187 * Wasn't the first -- search for it.
196 * for the datagram, the oldest state is (re-)used.
199 struct cstate *lastcs = comp->last_cs;
202 lcs = cs; cs = cs->cs_next;
204 if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr
205 && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr
207 ((int32_t *)&cs->cs_ip)[cs->cs_ip.ip_hl])
209 } while (cs != lastcs);
212 * Didn't find it -- re-use oldest cstate. Send an
220 comp->last_cs = lcs;
221 hlen += th->th_off;
223 if (hlen > m->m_len)
229 * Found it -- move to the front on the connection list.
231 if (cs == lastcs)
232 comp->last_cs = lcs;
234 lcs->cs_next = cs->cs_next;
235 cs->cs_next = lastcs->cs_next;
236 lastcs->cs_next = cs;
244 * The 3rd line checks the time-to-live and protocol (the protocol
251 oth = (struct tcphdr *)&((int32_t *)&cs->cs_ip)[hlen];
253 hlen += th->th_off;
255 if (hlen > m->m_len)
258 if (((u_int16_t *)ip)[0] != ((u_int16_t *)&cs->cs_ip)[0] ||
259 ((u_int16_t *)ip)[3] != ((u_int16_t *)&cs->cs_ip)[3] ||
260 ((u_int16_t *)ip)[4] != ((u_int16_t *)&cs->cs_ip)[4] ||
261 th->th_off != oth->th_off ||
263 BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
264 (th->th_off > 5 &&
265 BCMP(th + 1, oth + 1, (th->th_off - 5) << 2)))
275 deltaS = ntohs(th->th_urp);
278 } else if (th->th_urp != oth->th_urp)
279 /* argh! URG not set but urp changed -- a sensible
285 deltaS = (u_int16_t)(ntohs(th->th_win) - ntohs(oth->th_win));
291 deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack);
299 deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq);
317 if (ip->ip_len != cs->cs_ip.ip_len &&
318 ntohs(cs->cs_ip.ip_len) == hlen)
326 * actual changes match one of our special case encodings --
333 deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
341 if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
349 deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
360 deltaA = ntohs(th->th_sum);
361 BCOPY(ip, &cs->cs_ip, hlen);
365 * (cp - new_seq) is the number of bytes we need for compressed
368 * So, (cp - new_seq) + 4 bytes of header are needed. hlen is how
372 deltaS = cp - new_seq;
374 if (compress_cid == 0 || comp->last_xmit != cs->cs_id) {
375 comp->last_xmit = cs->cs_id;
376 hlen -= deltaS + 4;
379 *cp++ = cs->cs_id;
381 hlen -= deltaS + 3;
385 m->m_len -= hlen;
386 m->m_data += hlen;
394 * Update connection state cs & send uncompressed packet ('uncompressed'
399 BCOPY(ip, &cs->cs_ip, hlen);
400 ip->ip_p = cs->cs_id;
401 comp->last_xmit = cs->cs_id;
419 len -= vjlen;
423 * packet. If we're not aligned on a 4-byte boundary, copy the
429 if ((intptr_t)cp & 3) {
431 BCOPY(cp, ((intptr_t)cp &~ 3), len);
432 cp = (u_char *)((intptr_t)cp &~ 3);
434 cp -= hlen;
456 struct cstate *cs;
464 if (ip->ip_p >= MAX_STATES)
466 cs = &comp->rstate[comp->last_recv = ip->ip_p];
467 comp->flags &=~ SLF_TOSS;
468 ip->ip_p = IPPROTO_TCP;
473 hlen = ip->ip_hl << 2;
476 hlen += ((struct tcphdr *)&((char *)ip)[hlen])->th_off << 2;
479 BCOPY(ip, &cs->cs_ip, hlen);
480 cs->cs_hlen = hlen;
482 *hdrp = (u_char *) &cs->cs_ip;
502 comp->flags &=~ SLF_TOSS;
503 comp->last_recv = *cp++;
508 if (comp->flags & SLF_TOSS) {
510 return (-1);
513 cs = &comp->rstate[comp->last_recv];
514 hlen = cs->cs_ip.ip_hl << 2;
515 th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen];
516 th->th_sum = htons((*cp << 8) | cp[1]);
526 u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
527 th->th_ack = htonl(ntohl(th->th_ack) + i);
528 th->th_seq = htonl(ntohl(th->th_seq) + i);
533 th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len)
534 - cs->cs_hlen);
540 DECODEU(th->th_urp)
544 DECODES(th->th_win)
546 DECODEL(th->th_ack)
548 DECODEL(th->th_seq)
552 DECODES(cs->cs_ip.ip_id)
554 cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1);
561 vjlen = cp - buf;
562 buflen -= vjlen;
568 total_len += cs->cs_hlen - vjlen;
569 cs->cs_ip.ip_len = htons(total_len);
572 bp = (u_int16_t *) &cs->cs_ip;
573 cs->cs_ip.ip_sum = 0;
574 for (changes = 0; hlen > 0; hlen -= 2)
578 cs->cs_ip.ip_sum = ~ changes;
580 *hdrp = (u_char *) &cs->cs_ip;
581 *hlenp = cs->cs_hlen;
585 comp->flags |= SLF_TOSS;
587 return (-1);