Skip to content

Commit

Permalink
netdev-native-tnl: Consider L2 padding when encapsulating.
Browse files Browse the repository at this point in the history
Some ethernet frame may be padded to 64 bytes.

Fixes: 63171f0 ("userspace: L3 tunnel support for GRE and LISP")
Reported-by: Jun Wang <[email protected]>
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2024-July/053193.html
Signed-off-by: David Marchand <[email protected]>
  • Loading branch information
david-marchand committed Jul 1, 2024
1 parent e9a6bcf commit 60ae6c4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/netdev-native-tnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ void *
netdev_tnl_push_ip_header(struct dp_packet *packet, const void *header,
int size, int *ip_tot_size, ovs_be32 ipv6_label)
{
struct ovs_16aligned_ip6_hdr *ip6;
struct eth_header *eth;
uint32_t payload_size;
struct ip_header *ip;
struct ovs_16aligned_ip6_hdr *ip6;

eth = dp_packet_push_uninit(packet, size);
*ip_tot_size = dp_packet_size(packet) - sizeof (struct eth_header);
payload_size = dp_packet_size(packet) - dp_packet_l2_pad_size(packet);
*ip_tot_size = payload_size - sizeof (struct eth_header);

memcpy(eth, header, size);
/* The encapsulated packet has type Ethernet. Adjust dp_packet. */
Expand All @@ -171,7 +173,7 @@ netdev_tnl_push_ip_header(struct dp_packet *packet, const void *header,
*ip_tot_size -= IPV6_HEADER_LEN;
ip6->ip6_plen = htons(*ip_tot_size);
packet_set_ipv6_flow_label(&ip6->ip6_flow, ipv6_label);
packet->l4_ofs = dp_packet_size(packet) - *ip_tot_size;
packet->l4_ofs = payload_size - *ip_tot_size;

if (dp_packet_hwol_is_tunnel_geneve(packet) ||
dp_packet_hwol_is_tunnel_vxlan(packet)) {
Expand All @@ -197,7 +199,7 @@ netdev_tnl_push_ip_header(struct dp_packet *packet, const void *header,

dp_packet_ol_reset_ip_csum_good(packet);
*ip_tot_size -= IP_HEADER_LEN;
packet->l4_ofs = dp_packet_size(packet) - *ip_tot_size;
packet->l4_ofs = payload_size - *ip_tot_size;
return ip + 1;
}
}
Expand Down

0 comments on commit 60ae6c4

Please sign in to comment.