Skip to content

Commit

Permalink
netdev-native-tnl: Mark all vxlan/geneve packets as tunneled.
Browse files Browse the repository at this point in the history
Previously some packets were excluded from the tunnel mark if they
weren't L4. However, this causes problems with multi encapsulated
packets like arp.

Due to these flags being set, additional checks are required in checksum
modification code.

Fixes: 084c808 ("userspace: Support VXLAN and GENEVE TSO.")
Reported-by: David Marchand <[email protected]>
Signed-off-by: Mike Pattrick <[email protected]>
Signed-off-by: 0-day Robot <[email protected]>
  • Loading branch information
mkp-rh authored and ovsrobot committed Feb 15, 2024
1 parent f2bb573 commit 54c91a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
19 changes: 17 additions & 2 deletions lib/dp-packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1386,8 +1386,8 @@ dp_packet_ip_checksum_bad(const struct dp_packet *p)

/* Return 'true' is packet 'b' is not encapsulated and is marked for IPv4
* checksum offload, or if 'b' is encapsulated and the outer layer is marked
* for IPv4 checksum offload. IPv6 packets and non offloaded packets return
* 'false'. */
* for IPv4 checksum offload. IPv6 packets, non offloaded packets, and IPv4
* packets that are marked as good return 'false'. */
static inline bool
dp_packet_hwol_l3_csum_ipv4_ol(const struct dp_packet *b)
{
Expand All @@ -1400,6 +1400,21 @@ dp_packet_hwol_l3_csum_ipv4_ol(const struct dp_packet *b)
return false;
}

/* Return 'true' is packet 'b' is not encapsulated and is marked for IPv4
* checksum offload, or if 'b' is encapsulated and the outer layer is marked
* for IPv4 checksum offload. IPv6 packets and non offloaded packets return
* 'false'. */
static inline bool
dp_packet_hwol_l3_ipv4(const struct dp_packet *b)
{
if (dp_packet_hwol_is_outer_ipv4(b)) {
return true;
} else if (!dp_packet_hwol_is_outer_ipv6(b)) {
return dp_packet_hwol_tx_ip_csum(b);
}
return false;
}

/* Calculate and set the IPv4 header checksum in packet 'p'. */
static inline void
dp_packet_ip_set_header_csum(struct dp_packet *p, bool inner)
Expand Down
10 changes: 8 additions & 2 deletions lib/netdev-native-tnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ netdev_tnl_ip_extract_tnl_md(struct dp_packet *packet, struct flow_tnl *tnl,

/* A packet coming from a network device might have the
* csum already checked. In this case, skip the check. */
if (OVS_UNLIKELY(!dp_packet_ip_checksum_good(packet))
&& !dp_packet_hwol_tx_ip_csum(packet)) {
if (OVS_UNLIKELY(!dp_packet_hwol_l3_csum_ipv4_ol(packet))) {
if (csum(ip, IP_IHL(ip->ip_ihl_ver) * 4)) {
VLOG_WARN_RL(&err_rl, "ip packet has invalid checksum");
return NULL;
Expand Down Expand Up @@ -299,6 +298,13 @@ dp_packet_tnl_ol_process(struct dp_packet *packet,
(char *) dp_packet_eth(packet) +
VXLAN_HLEN);
}
} else {
/* Mark non-l4 packets as tunneled. */
if (data->tnl_type == OVS_VPORT_TYPE_GENEVE) {
dp_packet_hwol_set_tunnel_geneve(packet);
} else if (data->tnl_type == OVS_VPORT_TYPE_VXLAN) {
dp_packet_hwol_set_tunnel_vxlan(packet);
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ packet_set_ipv4_addr(struct dp_packet *packet,
}
}

if (dp_packet_hwol_tx_ip_csum(packet)) {
if (dp_packet_hwol_l3_ipv4(packet)) {
dp_packet_ol_reset_ip_csum_good(packet);
} else {
nh->ip_csum = recalc_csum32(nh->ip_csum, old_addr, new_addr);
Expand Down Expand Up @@ -1328,7 +1328,7 @@ packet_set_ipv4(struct dp_packet *packet, ovs_be32 src, ovs_be32 dst,
if (nh->ip_tos != tos) {
uint8_t *field = &nh->ip_tos;

if (dp_packet_hwol_tx_ip_csum(packet)) {
if (dp_packet_hwol_l3_ipv4(packet)) {
dp_packet_ol_reset_ip_csum_good(packet);
} else {
nh->ip_csum = recalc_csum16(nh->ip_csum, htons((uint16_t) *field),
Expand All @@ -1341,7 +1341,7 @@ packet_set_ipv4(struct dp_packet *packet, ovs_be32 src, ovs_be32 dst,
if (nh->ip_ttl != ttl) {
uint8_t *field = &nh->ip_ttl;

if (dp_packet_hwol_tx_ip_csum(packet)) {
if (dp_packet_hwol_l3_ipv4(packet)) {
dp_packet_ol_reset_ip_csum_good(packet);
} else {
nh->ip_csum = recalc_csum16(nh->ip_csum, htons(*field << 8),
Expand Down Expand Up @@ -1979,7 +1979,7 @@ IP_ECN_set_ce(struct dp_packet *pkt, bool is_ipv6)

tos |= IP_ECN_CE;
if (nh->ip_tos != tos) {
if (dp_packet_hwol_tx_ip_csum(pkt)) {
if (dp_packet_hwol_l3_ipv4(pkt)) {
dp_packet_ol_reset_ip_csum_good(pkt);
} else {
nh->ip_csum = recalc_csum16(nh->ip_csum, htons(nh->ip_tos),
Expand Down

0 comments on commit 54c91a0

Please sign in to comment.