Add RFC3542-style checksum compuation on raw, IPv6 sockets

This patch adds support for RFC3542-style checksum computation on raw,
IPv6 sockets via the IPV6_CHECKSUM socket option.

This allows the development of application-layer utilities such as
ping6 which are unable to compute the raw packet checksum without a
prior knowledge of the source address selection.
This commit is contained in:
Grant Erickson
2012-12-19 18:21:07 -08:00
committed by Simon Goldschmidt
parent e2c2afbbe0
commit d74464e091
4 changed files with 102 additions and 1 deletions

View File

@@ -51,6 +51,7 @@
#include "arch/perf.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"
#include "lwip/inet_chksum.h"
#include <string.h>
@@ -313,6 +314,16 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr)
src_ip = &pcb->local_ip;
}
#if LWIP_IPV6
/* If requested, based on the IPV6_CHECKSUM socket option per RFC3542, */
/* compute the checksum and update the checksum in the payload. */
if (PCB_ISIPV6(pcb) && pcb->chksum_reqd) {
u16_t chksum;
chksum = ip6_chksum_pseudo(q, pcb->protocol, q->tot_len, ipX_2_ip6(src_ip), ipX_2_ip6(dst_ip));
*(u16_t *)(((u8_t *)q->payload) + pcb->chksum_offset) = chksum;
}
#endif
NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
err = ipX_output_if(PCB_ISIPV6(pcb), q, ipX_2_ip(src_ip), ipX_2_ip(dst_ip), pcb->ttl, pcb->tos, pcb->protocol, netif);
NETIF_SET_HWADDRHINT(netif, NULL);