Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

srv6: Fix packet drop with GSO type mismatch #30732

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 5 additions & 15 deletions bpf/lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ srv6_encapsulation(struct __ctx_buff *ctx, int growth, __u16 new_payload_len,

/* Add room between Ethernet and network headers. */
if (ctx_adjust_hroom(ctx, growth, BPF_ADJ_ROOM_MAC,
ctx_adjust_hroom_flags()))
BPF_F_ADJ_ROOM_ENCAP_L3_IPV6))
YutaroHayakawa marked this conversation as resolved.
Show resolved Hide resolved
return DROP_INVALID;
if (ctx_store_bytes(ctx, ETH_HLEN, &new_ip6, len, 0) < 0)
return DROP_WRITE_ERROR;
Expand Down Expand Up @@ -315,7 +315,7 @@ srv6_handling4(struct __ctx_buff *ctx, union v6addr *src_sid,
void *data, *data_end;
struct iphdr *ip4;
__u8 nexthdr;
int growth;
int growth = 0;

/* Inner packet is IPv4. */
if (!revalidate_data(ctx, &data, &data_end, &ip4))
Expand All @@ -329,25 +329,15 @@ srv6_handling4(struct __ctx_buff *ctx, union v6addr *src_sid,
*/
new_payload_len = bpf_ntohs(ip4->tot_len) - (__u16)(ip4->ihl << 2) + sizeof(struct iphdr);

/* We need to change skb->protocol and the corresponding packet
* field because the L3 protocol will now be IPv6.
*/
if (ctx_change_proto(ctx, outer_proto, 0) < 0)
return DROP_WRITE_ERROR;
if (ctx_store_bytes(ctx, offsetof(struct ethhdr, h_proto),
&outer_proto, sizeof(outer_proto), 0) < 0)
return DROP_WRITE_ERROR;
/* ctx_change_proto above grows the packet from IPv4 header
* length to IPv6 header length. It adds the additional space
* before the inner L3 header, in the same place we will later
* add the outer IPv6 header.
* Thus, deduce this space from the next packet growth.
*/
growth = sizeof(struct iphdr);

#ifdef ENABLE_SRV6_SRH_ENCAP
growth += sizeof(struct srv6_srh) + sizeof(struct in6_addr);
growth += sizeof(struct ipv6hdr) + sizeof(struct srv6_srh) + sizeof(struct in6_addr);
new_payload_len += sizeof(struct srv6_srh) + sizeof(struct in6_addr);
#else
growth += sizeof(struct ipv6hdr);
#endif /* ENABLE_SRV6_SRH_ENCAP */

return srv6_encapsulation(ctx, growth, new_payload_len, nexthdr,
Expand Down