Skip to content

Commit

Permalink
Merge pull request #1100 from tempesta-tech/ri-copy-network-headers-i…
Browse files Browse the repository at this point in the history
…n-ss-skb-split

copy network headers in ss_skb_split()
  • Loading branch information
i-rinat authored Nov 15, 2018
2 parents cf2c036 + 62167a9 commit c662213
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions tempesta_fw/ss_skb.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,31 @@ ss_skb_process(struct sk_buff *skb, unsigned int *off, ss_skb_actor_t actor,
}
EXPORT_SYMBOL(ss_skb_process);

/**
* 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);

/*
* Place IP header just after link layer headers,
* see definitions of MAX_TCP_HEADER and MAX_IP_HDR_LEN.
* Note that only new skbs allocated by ss_skb_alloc() are used here,
* so all of them have reserved MAX_TCP_HEADER areas.
*/
BUG_ON(skb_headroom(to) < MAX_TCP_HEADER);
skb_set_network_header(to, -(MAX_TCP_HEADER - MAX_HEADER));
if (ip6->version == 6)
memcpy_fast(skb_network_header(to), ip6, sizeof(*ip6));
else
memcpy_fast(skb_network_header(to), ip4, sizeof(*ip4));
}

/*
* Split @skb in two at a given offset. The original SKB is shrunk
* to specified size @len, and the remaining data is put into a new SKB.
Expand Down Expand Up @@ -969,6 +994,7 @@ ss_skb_split(struct sk_buff *skb, int len)
* or recalculate the checksum.
*/
skb_split(skb, buff, len);
__copy_ip_header(buff, skb);

return buff;
}
Expand Down Expand Up @@ -1019,31 +1045,6 @@ ss_skb_queue_coalesce_tail(struct sk_buff **skb_head, 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);

/*
* Place IP header just after link layer headers,
* see definitions of MAX_TCP_HEADER and MAX_IP_HDR_LEN.
* Note that only new skbs allocated by ss_skb_alloc() are used here,
* so all of them have reserved MAX_TCP_HEADER areas.
*/
BUG_ON(skb_headroom(to) < MAX_TCP_HEADER);
skb_set_network_header(to, -(MAX_TCP_HEADER - MAX_HEADER));
if (ip6->version == 6)
memcpy_fast(skb_network_header(to), ip6, sizeof(*ip6));
else
memcpy_fast(skb_network_header(to), ip4, sizeof(*ip4));
}

/**
* Tempesta FW forwards skbs with application and transport payload as is,
* so initialize such skbs such that TCP/IP stack won't stumble on dirty
Expand Down

0 comments on commit c662213

Please sign in to comment.