lwip: fix broken default ICMPv6 handling of checksums.

ICMPv6 should always have checksum generated for it as per RFC 3542
chapter 3.1.

(cherry picked from commit 5e9df2c698)
This commit is contained in:
Knut Andre Tidemann 2017-01-11 12:11:20 +01:00 committed by goldsimon
parent cb97e27120
commit 2694486309
2 changed files with 14 additions and 0 deletions

View File

@ -53,6 +53,7 @@
#include "lwip/dns.h"
#include "lwip/mld6.h"
#include "lwip/priv/tcpip_priv.h"
#include "lwip/sockets.h"
#include <string.h>
@ -562,6 +563,13 @@ pcb_new(struct api_msg *msg)
case NETCONN_RAW:
msg->conn->pcb.raw = raw_new_ip_type(iptype, msg->msg.n.proto);
if (msg->conn->pcb.raw != NULL) {
#if LWIP_IPV6
/* ICMPv6 packets should always have checksum calculated by the stack as per RFC 3542 chapter 3.1 */
if (NETCONNTYPE_ISIPV6(msg->conn->type) && msg->conn->pcb.raw->protocol == IPPROTO_ICMPV6) {
msg->conn->pcb.raw->chksum_reqd = 1;
msg->conn->pcb.raw->chksum_offset = 2;
}
#endif /* LWIP_IPV6 */
raw_recv(msg->conn->pcb.raw, recv_raw, msg->conn);
}
break;

View File

@ -2574,6 +2574,12 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
switch (optname) {
#if LWIP_IPV6 && LWIP_RAW
case IPV6_CHECKSUM:
/* It should not be possible to disable the checksum generation with ICMPv6
* as per RFC 3542 chapter 3.1 */
if(sock->conn->pcb.raw->protocol == IPPROTO_ICMPV6) {
return EINVAL;
}
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_RAW);
if (*(const int *)optval < 0) {
sock->conn->pcb.raw->chksum_reqd = 0;