genet: workaround for problem with ICMPv6 echo replies

The ICMPv6 echo reply is constructed with the IPv6 header too close to
the beginning of a packet for an Ethernet header to be prepended, so we
end up with an mbuf containing just the Ethernet header.  The GENET
controller doesn't seem to handle this, with or without transmit checksum
offload.  At least until we have chip documentation, do a pullup to
satisfy the chip.  Hopefully this can be fixed properly in the future.
This commit is contained in:
Mike Karels 2020-05-30 02:09:36 +00:00
parent 0add2a5229
commit 51cefda170
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=361642

View File

@ -76,6 +76,10 @@ __FBSDID("$FreeBSD$");
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#define ICMPV6_HACK /* workaround for chip issue */
#ifdef ICMPV6_HACK
#include <netinet/icmp6.h>
#endif
#include "syscon_if.h"
#include "miibus_if.h"
@ -968,6 +972,36 @@ gen_encap(struct gen_softc *sc, struct mbuf **mp)
q = &sc->tx_queue[DEF_TXQUEUE];
m = *mp;
#ifdef ICMPV6_HACK
/*
* Reflected ICMPv6 packets, e.g. echo replies, tend to get laid
* out with only the Ethernet header in the first mbuf, and this
* doesn't seem to work.
*/
#define ICMP6_LEN (sizeof(struct ether_header) + sizeof(struct ip6_hdr) + \
sizeof(struct icmp6_hdr))
if (m->m_len == sizeof(struct ether_header)) {
int ether_type = mtod(m, struct ether_header *)->ether_type;
if (ntohs(ether_type) == ETHERTYPE_IPV6 &&
m->m_next->m_len >= sizeof(struct ip6_hdr)) {
struct ip6_hdr *ip6;
ip6 = mtod(m->m_next, struct ip6_hdr *);
if (ip6->ip6_nxt == IPPROTO_ICMPV6) {
m = m_pullup(m,
MIN(m->m_pkthdr.len, ICMP6_LEN));
if (m == NULL) {
if (sc->ifp->if_flags & IFF_DEBUG)
device_printf(sc->dev,
"ICMPV6 pullup fail\n");
*mp = NULL;
return (ENOMEM);
}
}
}
}
#undef ICMP6_LEN
#endif
if ((if_getcapenable(sc->ifp) & (IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6)) !=
0) {
csum_flags = m->m_pkthdr.csum_flags;