net: Verify L4 checksum unconditionally for reassembled packets

In case of reassembled IP packets, we cannot rely on checksum
offloading as the drivers/HW has no means to verify L4 checksum before
the fragment is reassembled. Therefore, for such packets, verify L4
checksum in the software unconditionally.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2023-10-30 13:23:02 +01:00 committed by Fabio Baltieri
parent 76a256ea57
commit 24abc4307b
4 changed files with 8 additions and 4 deletions

View file

@ -610,7 +610,8 @@ enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
return NET_DROP;
}
if (net_if_need_calc_rx_checksum(net_pkt_iface(pkt))) {
if (net_if_need_calc_rx_checksum(net_pkt_iface(pkt)) ||
net_pkt_is_ip_reassembled(pkt)) {
if (net_calc_chksum_icmpv4(pkt) != 0U) {
NET_DBG("DROP: Invalid checksum");
goto drop;

View file

@ -342,7 +342,8 @@ enum net_verdict net_icmpv6_input(struct net_pkt *pkt,
}
if (net_if_need_calc_rx_checksum(net_pkt_iface(pkt))) {
if (net_if_need_calc_rx_checksum(net_pkt_iface(pkt)) ||
net_pkt_is_ip_reassembled(pkt)) {
if (net_calc_chksum_icmpv6(pkt) != 0U) {
NET_DBG("DROP: invalid checksum");
goto drop;

View file

@ -3609,7 +3609,8 @@ struct net_tcp_hdr *net_tcp_input(struct net_pkt *pkt,
struct net_tcp_hdr *tcp_hdr;
if (IS_ENABLED(CONFIG_NET_TCP_CHECKSUM) &&
net_if_need_calc_rx_checksum(net_pkt_iface(pkt)) &&
(net_if_need_calc_rx_checksum(net_pkt_iface(pkt)) ||
net_pkt_is_ip_reassembled(pkt)) &&
net_calc_chksum_tcp(pkt) != 0U) {
NET_DBG("DROP: checksum mismatch");
goto drop;

View file

@ -164,7 +164,8 @@ struct net_udp_hdr *net_udp_input(struct net_pkt *pkt,
}
if (IS_ENABLED(CONFIG_NET_UDP_CHECKSUM) &&
net_if_need_calc_rx_checksum(net_pkt_iface(pkt))) {
(net_if_need_calc_rx_checksum(net_pkt_iface(pkt)) ||
net_pkt_is_ip_reassembled(pkt))) {
if (!udp_hdr->chksum) {
if (IS_ENABLED(CONFIG_NET_UDP_MISSING_CHECKSUM) &&
net_pkt_family(pkt) == AF_INET) {