Lines Matching +full:no +full:- +full:comp

23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
40 * - Initial distribution.
64 #define INCR(counter) ++comp->counter;
71 sl_compress_init(struct slcompress *comp)
74 struct cstate *tstate = comp->tstate;
76 memset(comp, 0, sizeof(*comp));
77 for (i = MAX_STATES - 1; i > 0; --i) {
79 tstate[i].cs_next = &tstate[i - 1];
81 tstate[0].cs_next = &tstate[MAX_STATES - 1];
83 comp->last_cs = &tstate[0];
84 comp->last_recv = 255;
85 comp->last_xmit = 255;
86 comp->flags = SLF_TOSS;
95 sl_compress_setup(struct slcompress *comp, int max_state)
98 struct cstate *tstate = comp->tstate;
100 if (max_state == -1) {
101 max_state = MAX_STATES - 1;
102 memset(comp, 0, sizeof(*comp));
105 memset(comp->tstate, 0, sizeof(comp->tstate));
106 memset(comp->rstate, 0, sizeof(comp->rstate));
108 for (i = max_state; i > 0; --i) {
110 tstate[i].cs_next = &tstate[i - 1];
114 comp->last_cs = &tstate[0];
115 comp->last_recv = 255;
116 comp->last_xmit = 255;
117 comp->flags = SLF_TOSS;
122 * ENCODE encodes a number that is known to be non-zero. ENCODEZ checks for
174 sl_compress_tcp(struct mbuf *m, struct ip *ip, struct slcompress *comp,
177 struct cstate *cs = comp->last_cs->cs_next;
178 u_int hlen = ip->ip_hl;
192 if ((ip->ip_off & htons(0x3fff)) || m->m_len < 40)
196 if ((th->th_flags & (TH_SYN|TH_FIN|TH_RST|TH_ACK)) != TH_ACK)
199 * Packet is compressible -- we're going to send either a
206 if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr ||
207 ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr ||
208 *(int32_t *)th != ((int32_t *)&cs->cs_ip)[cs->cs_ip.ip_hl]) {
210 * Wasn't the first -- search for it.
218 * for the datagram, the oldest state is (re-)used.
221 struct cstate *lastcs = comp->last_cs;
224 lcs = cs; cs = cs->cs_next;
226 if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr
227 && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr
229 ((int32_t *)&cs->cs_ip)[cs->cs_ip.ip_hl])
234 * Didn't find it -- re-use oldest cstate. Send an
242 comp->last_cs = lcs;
243 hlen += th->th_off;
245 if (hlen > m->m_len)
250 /* Found it -- move to the front on the connection list. */
252 comp->last_cs = lcs;
254 lcs->cs_next = cs->cs_next;
255 cs->cs_next = lastcs->cs_next;
256 lastcs->cs_next = cs;
264 * The 3rd line checks the time-to-live and protocol (the protocol
271 oth = (struct tcphdr *)&((int32_t *)&cs->cs_ip)[hlen];
273 hlen += th->th_off;
275 if (hlen > m->m_len)
278 if (((uint16_t *)ip)[0] != ((uint16_t *)&cs->cs_ip)[0] ||
279 ((uint16_t *)ip)[3] != ((uint16_t *)&cs->cs_ip)[3] ||
280 ((uint16_t *)ip)[4] != ((uint16_t *)&cs->cs_ip)[4] ||
281 th->th_off != oth->th_off ||
283 memcmp(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
284 (th->th_off > 5 &&
285 memcmp(th + 1, oth + 1, (th->th_off - 5) << 2)))
293 if (th->th_flags & TH_URG) {
294 deltaS = ntohs(th->th_urp);
297 } else if (th->th_urp != oth->th_urp)
299 * argh! URG not set but urp changed -- a sensible
305 deltaS = (uint16_t)(ntohs(th->th_win) - ntohs(oth->th_win));
311 deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack);
319 deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq);
337 if (ip->ip_len != cs->cs_ip.ip_len &&
338 ntohs(cs->cs_ip.ip_len) == hlen)
346 * actual changes match one of our special case encodings --
353 deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
361 if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
369 deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
374 if (th->th_flags & TH_PUSH)
380 deltaA = ntohs(th->th_sum);
381 memcpy(&cs->cs_ip, ip, hlen);
385 * (cp - new_seq) is the number of bytes we need for compressed
388 * So, (cp - new_seq) + 4 bytes of header are needed. hlen is how
392 deltaS = cp - new_seq;
394 if (compress_cid == 0 || comp->last_xmit != cs->cs_id) {
395 comp->last_xmit = cs->cs_id;
396 hlen -= deltaS + 4;
399 *cp++ = cs->cs_id;
401 hlen -= deltaS + 3;
405 m->m_len -= hlen;
406 m->m_data += hlen;
420 memcpy(&cs->cs_ip, ip, hlen);
421 ip->ip_p = cs->cs_id;
422 comp->last_xmit = cs->cs_id;
428 sl_uncompress_tcp(u_char **bufp, int len, u_int type, struct slcompress *comp)
435 vjlen = sl_uncompress_tcp_core(cp, len, len, type, comp, &hdr, &hlen);
442 len -= vjlen;
446 * packet. If we're not aligned on a 4-byte boundary, copy the
457 cp -= hlen;
473 struct slcompress *comp, u_char **hdrp, u_int *hlenp)
489 if (ip->ip_p >= MAX_STATES)
491 cs = &comp->rstate[comp->last_recv = ip->ip_p];
492 comp->flags &=~ SLF_TOSS;
493 ip->ip_p = IPPROTO_TCP;
498 hlen = ip->ip_hl << 2;
501 hlen += ((struct tcphdr *)&((char *)ip)[hlen])->th_off << 2;
504 memcpy(&cs->cs_ip, ip, hlen);
505 cs->cs_hlen = hlen;
507 *hdrp = (u_char *)&cs->cs_ip;
531 comp->flags &=~ SLF_TOSS;
532 comp->last_recv = *cp++;
539 if (comp->flags & SLF_TOSS) {
541 return -1;
544 cs = &comp->rstate[comp->last_recv];
545 hlen = cs->cs_ip.ip_hl << 2;
546 th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen];
547 th->th_sum = htons((*cp << 8) | cp[1]);
550 th->th_flags |= TH_PUSH;
552 th->th_flags &=~ TH_PUSH;
557 u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
558 th->th_ack = htonl(ntohl(th->th_ack) + i);
559 th->th_seq = htonl(ntohl(th->th_seq) + i);
564 th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len)
565 - cs->cs_hlen);
570 th->th_flags |= TH_URG;
571 DECODEU(th->th_urp)
573 th->th_flags &=~ TH_URG;
575 DECODES(th->th_win)
577 DECODEL(th->th_ack)
579 DECODEL(th->th_seq)
583 DECODES(cs->cs_ip.ip_id)
585 cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1);
591 vjlen = cp - buf;
592 buflen -= vjlen;
600 total_len += cs->cs_hlen - vjlen;
601 cs->cs_ip.ip_len = htons(total_len);
604 bp = (uint16_t *)&cs->cs_ip;
605 cs->cs_ip.ip_sum = 0;
606 for (changes = 0; hlen > 0; hlen -= 2)
610 cs->cs_ip.ip_sum = ~ changes;
612 *hdrp = (u_char *)&cs->cs_ip;
613 *hlenp = cs->cs_hlen;
617 comp->flags |= SLF_TOSS;
619 return -1;