Skip to content

Commit

Permalink
Make a copy of IP-header while unrolling (#585)
Browse files Browse the repository at this point in the history
This fixes problem with ss_skb_fmt_src_addr() which is called from the
tfw_http_add_x_forwarded_for() function. In case of GRO, unrollong
process can take place and orignal SKB metadata will be lost.
  • Loading branch information
milabs authored Jul 14, 2016
1 parent 118b112 commit 798299d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tempesta_fw/ss_skb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,25 @@ ss_skb_queue_coalesce_tail(SsSkbList *skb_list, const struct sk_buff *skb)
return 0;
}

/**
* Tempesta makes use of the source IP address that is kept in the IP
* header of the original skb @from. Copy the needed IP header contents to
* the new skb @to.
*/
static inline void
__copy_ip_header(struct sk_buff *to, const struct sk_buff *from)
{
const struct iphdr *ip4 = ip_hdr(from);
const struct ipv6hdr *ip6 = ipv6_hdr(from);

if (ip6->version == 6)
memcpy(to->data, ip6, sizeof(*ip6));
else
memcpy(to->data, ip4, sizeof(*ip4));

skb_reset_network_header(to);
}

/*
* When the original SKB is a clone then its shinfo and payload cannot be
* modified as they are shared with other SKB users. As the SKB is unrolled,
Expand All @@ -1042,6 +1061,10 @@ ss_skb_unroll_slow(SsSkbList *skb_list, struct sk_buff *skb)
goto cleanup;
}

/* Copy the IP header contents to the first skb in the chain. */
if (skb_list->first)
__copy_ip_header(skb_list->first, skb);

/* TODO: Optimize skb reallocation. Consider to place clone's shinfo
* right after the origal's shinfo in case space to the chunk boundary
* is available. It can save some allocations but keep in mind that tail
Expand Down

0 comments on commit 798299d

Please sign in to comment.