mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-23 14:46:01 +00:00
icmp6: keep to the RFC and send as much as possible with icmp6 error messages
See bug 56013 Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
This commit is contained in:
parent
4f30e0daff
commit
d843e47a1d
|
@ -57,9 +57,9 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if LWIP_ICMP6_DATASIZE == 0
|
#if !LWIP_ICMP6_DATASIZE || (LWIP_ICMP6_DATASIZE > (IP6_MIN_MTU_LENGTH - IP6_HLEN - ICMP6_HLEN))
|
||||||
#undef LWIP_ICMP6_DATASIZE
|
#undef LWIP_ICMP6_DATASIZE
|
||||||
#define LWIP_ICMP6_DATASIZE 8
|
#define LWIP_ICMP6_DATASIZE (IP6_MIN_MTU_LENGTH - IP6_HLEN - ICMP6_HLEN)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
|
@ -387,17 +387,18 @@ icmp6_send_response_with_addrs_and_netif(struct pbuf *p, u8_t code, u32_t data,
|
||||||
{
|
{
|
||||||
struct pbuf *q;
|
struct pbuf *q;
|
||||||
struct icmp6_hdr *icmp6hdr;
|
struct icmp6_hdr *icmp6hdr;
|
||||||
|
u16_t datalen = LWIP_MIN(p->tot_len, LWIP_ICMP6_DATASIZE);
|
||||||
|
|
||||||
/* ICMPv6 header + IPv6 header + data */
|
/* ICMPv6 header + datalen (as much of the offending packet as possible) */
|
||||||
q = pbuf_alloc(PBUF_IP, sizeof(struct icmp6_hdr) + IP6_HLEN + LWIP_ICMP6_DATASIZE,
|
q = pbuf_alloc(PBUF_IP, sizeof(struct icmp6_hdr) + datalen,
|
||||||
PBUF_RAM);
|
PBUF_RAM);
|
||||||
if (q == NULL) {
|
if (q == NULL) {
|
||||||
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded: failed to allocate pbuf for ICMPv6 packet.\n"));
|
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded: failed to allocate pbuf for ICMPv6 packet.\n"));
|
||||||
ICMP6_STATS_INC(icmp6.memerr);
|
ICMP6_STATS_INC(icmp6.memerr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LWIP_ASSERT("check that first pbuf can hold icmp 6message",
|
LWIP_ASSERT("check that first pbuf can hold icmp6 header",
|
||||||
(q->len >= (sizeof(struct icmp6_hdr) + IP6_HLEN + LWIP_ICMP6_DATASIZE)));
|
(q->len >= (sizeof(struct icmp6_hdr))));
|
||||||
|
|
||||||
icmp6hdr = (struct icmp6_hdr *)q->payload;
|
icmp6hdr = (struct icmp6_hdr *)q->payload;
|
||||||
icmp6hdr->type = type;
|
icmp6hdr->type = type;
|
||||||
|
@ -405,8 +406,7 @@ icmp6_send_response_with_addrs_and_netif(struct pbuf *p, u8_t code, u32_t data,
|
||||||
icmp6hdr->data = lwip_htonl(data);
|
icmp6hdr->data = lwip_htonl(data);
|
||||||
|
|
||||||
/* copy fields from original packet */
|
/* copy fields from original packet */
|
||||||
SMEMCPY((u8_t *)q->payload + sizeof(struct icmp6_hdr), (u8_t *)p->payload,
|
pbuf_take_at(q, p->payload, datalen, sizeof(struct icmp6_hdr));
|
||||||
IP6_HLEN + LWIP_ICMP6_DATASIZE);
|
|
||||||
|
|
||||||
/* calculate checksum */
|
/* calculate checksum */
|
||||||
icmp6hdr->chksum = 0;
|
icmp6hdr->chksum = 0;
|
||||||
|
|
|
@ -2539,10 +2539,12 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_ICMP6_DATASIZE: bytes from original packet to send back in
|
* LWIP_ICMP6_DATASIZE: bytes from original packet to send back in
|
||||||
* ICMPv6 error messages.
|
* ICMPv6 error messages (0 = default of IP6_MIN_MTU_LENGTH)
|
||||||
|
* ATTENTION: RFC4443 section 2.4 says IP6_MIN_MTU_LENGTH is a MUST,
|
||||||
|
* so override this only if you absolutely have to!
|
||||||
*/
|
*/
|
||||||
#if !defined LWIP_ICMP6_DATASIZE || defined __DOXYGEN__
|
#if !defined LWIP_ICMP6_DATASIZE || defined __DOXYGEN__
|
||||||
#define LWIP_ICMP6_DATASIZE 8
|
#define LWIP_ICMP6_DATASIZE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -146,6 +146,8 @@ PACK_STRUCT_END
|
||||||
# include "arch/epstruct.h"
|
# include "arch/epstruct.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ICMP6_HLEN 8
|
||||||
|
|
||||||
/** This is the ICMP6 header adapted for echo req/resp. */
|
/** This is the ICMP6 header adapted for echo req/resp. */
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
# include "arch/bpstruct.h"
|
# include "arch/bpstruct.h"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user