/* Free a compression data structure */ void
slhc_free(struct slcompress *comp)
{ if ( IS_ERR_OR_NULL(comp) ) return;
if ( comp->tstate != NULLSLSTATE )
kfree( comp->tstate );
if ( comp->rstate != NULLSLSTATE )
kfree( comp->rstate );
kfree( comp );
}
/* Put a short in host order into a char array in network order */ staticinlineunsignedchar *
put16(unsignedchar *cp, unsignedshort x)
{
*cp++ = x >> 8;
*cp++ = x;
ip = (struct iphdr *) icp; if (ip->version != 4 || ip->ihl < 5) return isize;
/* Bail if this packet isn't TCP, or is an IP fragment */ if (ip->protocol != IPPROTO_TCP || (ntohs(ip->frag_off) & 0x3fff)) { /* Send as regular IP */ if(ip->protocol != IPPROTO_TCP)
comp->sls_o_nontcp++; else
comp->sls_o_tcp++; return isize;
}
nlen = ip->ihl * 4; if (isize < nlen + sizeof(*th)) return isize;
/* if current equal oldest, at end of list */ if ( cs == ocs ) break;
lcs = cs;
cs = cs->next;
comp->sls_o_searches++;
} /* *Didn'tfindit--re-useoldestcstate.Sendan *uncompressedpacketthattellstheothersidewhat *connectionnumberwe'reusingforthisconversation. * *Notethatsincethestatelistiscircular,theoldest *statepointstothenewestandweonlyneedtoset *xmit_oldesttoupdatethelrulinkage.
*/
comp->sls_o_misses++;
comp->xmit_oldest = lcs->cs_this; goto uncompressed;
found: /* *Foundit--movetothefrontontheconnectionlist.
*/ if(lcs == ocs) { /* found at most recently used */
} elseif (cs == ocs) { /* found at least recently used */
comp->xmit_oldest = lcs->cs_this;
} else { /* more than 2 elements */
lcs->next = cs->next;
cs->next = ocs->next;
ocs->next = cs;
}
int
slhc_uncompress(struct slcompress *comp, unsignedchar *icp, int isize)
{ int changes; long x; struct tcphdr *thp; struct iphdr *ip; struct cstate *cs; int len, hdrlen; unsignedchar *cp = icp;
/* We've got a compressed packet; read the change byte */
comp->sls_i_compressed++; if(isize < 3){
comp->sls_i_error++; return0;
}
changes = *cp++; if(changes & NEW_C){ /* Make sure the state index is in range, then grab the state. *Ifwehaveagoodstateindex,clearthe'discard'flag.
*/
x = *cp++; /* Read conn index */ if(x < 0 || x > comp->rslot_limit) goto bad;
/* Check if the cstate is initialized */ if (!comp->rstate[x].initialized) goto bad;
comp->flags &=~ SLF_TOSS;
comp->recv_current = x;
} else { /* this packet has an implicit state index. If we've *hadalineerrorsincethelasttimewegotan
* explicit state index, we have to toss the packet. */ if(comp->flags & SLF_TOSS){
comp->sls_i_tossed++; return0;
}
}
cs = &comp->rstate[comp->recv_current];
thp = &cs->cs_tcp;
ip = &cs->cs_ip;
/* The packet is shorter than a legal IP header. *Alsomakesureisizeispositive.
*/ if (isize < (int)sizeof(struct iphdr)) {
runt:
comp->sls_i_runt++; return slhc_toss(comp);
}
iph = (struct iphdr *)icp; /* Peek at the IP header's IHL field to find its length */
ihl = iph->ihl; /* The IP header length field is too small, *orpacketisshorterthantheIPheaderfollowed *byminimaltcpheader.
*/ if (ihl < 5 || isize < ihl * 4 + sizeof(struct tcphdr)) goto runt;
index = iph->protocol;
iph->protocol = IPPROTO_TCP;
if (ip_fast_csum(icp, ihl)) { /* Bad IP header checksum; discard */
comp->sls_i_badcheck++; return slhc_toss(comp);
} if (index > comp->rslot_limit) {
comp->sls_i_error++; return slhc_toss(comp);
}
th = (struct tcphdr *)(icp + ihl * 4); if (th->doff < sizeof(struct tcphdr) / 4) goto runt; if (isize < ihl * 4 + th->doff * 4) goto runt; /* Update local state */
cs = &comp->rstate[comp->recv_current = index];
comp->flags &=~ SLF_TOSS;
memcpy(&cs->cs_ip, iph, sizeof(*iph));
memcpy(&cs->cs_tcp, th, sizeof(*th)); if (ihl > 5)
memcpy(cs->cs_ipopt, &iph[1], (ihl - 5) * 4); if (th->doff > 5)
memcpy(cs->cs_tcpopt, &th[1], (th->doff - 5) * 4);
cs->cs_hsize = ihl*2 + th->doff*2;
cs->initialized = true; /* Put headers back on packet *Neitherheaderchecksumisrecalculated
*/
comp->sls_i_uncompressed++; return isize;
}
int
slhc_toss(struct slcompress *comp)
{ if ( comp == NULLSLCOMPR ) return0;
comp->flags |= SLF_TOSS; return0;
}
#else/* CONFIG_INET */
int
slhc_toss(struct slcompress *comp)
{
printk(KERN_DEBUG "Called IP function on non IP-system: slhc_toss"); return -EINVAL;
} int
slhc_uncompress(struct slcompress *comp, unsignedchar *icp, int isize)
{
printk(KERN_DEBUG "Called IP function on non IP-system: slhc_uncompress"); return -EINVAL;
} int
slhc_compress(struct slcompress *comp, unsignedchar *icp, int isize, unsignedchar *ocp, unsignedchar **cpp, int compress_cid)
{
printk(KERN_DEBUG "Called IP function on non IP-system: slhc_compress"); return -EINVAL;
}
int
slhc_remember(struct slcompress *comp, unsignedchar *icp, int isize)
{
printk(KERN_DEBUG "Called IP function on non IP-system: slhc_remember"); return -EINVAL;
}
void
slhc_free(struct slcompress *comp)
{
printk(KERN_DEBUG "Called IP function on non IP-system: slhc_free");
} struct slcompress *
slhc_init(int rslots, int tslots)
{
printk(KERN_DEBUG "Called IP function on non IP-system: slhc_init"); return NULL;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.