fix lwIP TCP checksums on LE: remove htons from pseudo-header sum, add htons to return values
This commit is contained in:
1 parent
f85f2f20fb
commit
f1bd65f450
1 file changed
+8
-8
@@ -600,8 +600,8 @@ tcp_pseudo_checksum(uint32_t src_ip, uint32_t dst_ip, uint8_t proto, uint16_t tc
|
||||
sum += (uint32_t)ntohs((uint16_t)(src_ip & 0xFFFF));
|
||||
sum += (uint32_t)ntohs((uint16_t)((dst_ip >> 16) & 0xFFFF));
|
||||
sum += (uint32_t)ntohs((uint16_t)(dst_ip & 0xFFFF));
|
||||
sum += htons((uint16_t)proto);
|
||||
sum += htons(tcp_len);
|
||||
sum += (uint32_t)(uint16_t)proto;
|
||||
sum += (uint32_t)tcp_len;
|
||||
|
||||
const struct pbuf *q;
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
@@ -655,8 +655,8 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
||||
seg->p->payload = seg->tcphdr;
|
||||
|
||||
seg->tcphdr->chksum = 0;
|
||||
seg->tcphdr->chksum = tcp_pseudo_checksum(pcb->local_ip, pcb->remote_ip,
|
||||
IP_PROTO_TCP, seg->p->tot_len, seg->p);
|
||||
seg->tcphdr->chksum = htons(tcp_pseudo_checksum(pcb->local_ip, pcb->remote_ip,
|
||||
IP_PROTO_TCP, seg->p->tot_len, seg->p));
|
||||
|
||||
if (pbuf_header(seg->p, (int16_t)sizeof(struct ip_hdr)) == 0) {
|
||||
iph = (struct ip_hdr *)seg->p->payload;
|
||||
@@ -669,7 +669,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
||||
iph->proto = IP_PROTO_TCP;
|
||||
iph->src = pcb->local_ip;
|
||||
iph->dst = pcb->remote_ip;
|
||||
iph->chksum = tcp_ip_checksum(iph);
|
||||
iph->chksum = htons(tcp_ip_checksum(iph));
|
||||
err = pcb->ctx->output(pcb->ctx->output_arg, seg->p, pcb->local_ip, pcb->remote_ip);
|
||||
pbuf_header(seg->p, -(int16_t)sizeof(struct ip_hdr));
|
||||
} else {
|
||||
@@ -855,8 +855,8 @@ tcp_output_control_segment(const struct tcp_pcb *pcb, struct pbuf *p,
|
||||
|
||||
{
|
||||
struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload;
|
||||
tcphdr->chksum = tcp_pseudo_checksum(src_ip, dst_ip,
|
||||
IP_PROTO_TCP, p->tot_len, p);
|
||||
tcphdr->chksum = htons(tcp_pseudo_checksum(src_ip, dst_ip,
|
||||
IP_PROTO_TCP, p->tot_len, p));
|
||||
}
|
||||
|
||||
if (pbuf_header(p, (int16_t)sizeof(struct ip_hdr)) == 0) {
|
||||
@@ -876,7 +876,7 @@ tcp_output_control_segment(const struct tcp_pcb *pcb, struct pbuf *p,
|
||||
}
|
||||
iph->src = src_ip;
|
||||
iph->dst = dst_ip;
|
||||
iph->chksum = tcp_ip_checksum(iph);
|
||||
iph->chksum = htons(tcp_ip_checksum(iph));
|
||||
if (pcb != NULL) {
|
||||
err = pcb->ctx->output(pcb->ctx->output_arg, p, src_ip, dst_ip);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user