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