Commit 19c3401a authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso Committed by David S. Miller

net: ipv4: place control buffer handling away from fragmentation iterators

Deal with the IPCB() area away from the iterators.

The bridge codebase has its own control buffer layout, move specific
IP control buffer handling into the IPv4 codepath.
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8a6a1f17
...@@ -525,9 +525,6 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from) ...@@ -525,9 +525,6 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)
skb_copy_hash(to, from); skb_copy_hash(to, from);
/* Copy the flags to each fragment. */
IPCB(to)->flags = IPCB(from)->flags;
#ifdef CONFIG_NET_SCHED #ifdef CONFIG_NET_SCHED
to->tc_index = from->tc_index; to->tc_index = from->tc_index;
#endif #endif
...@@ -582,6 +579,18 @@ void ip_fraglist_init(struct sk_buff *skb, struct iphdr *iph, ...@@ -582,6 +579,18 @@ void ip_fraglist_init(struct sk_buff *skb, struct iphdr *iph,
} }
EXPORT_SYMBOL(ip_fraglist_init); EXPORT_SYMBOL(ip_fraglist_init);
static void ip_fraglist_ipcb_prepare(struct sk_buff *skb,
struct ip_fraglist_iter *iter)
{
struct sk_buff *to = iter->frag;
/* Copy the flags to each fragment. */
IPCB(to)->flags = IPCB(skb)->flags;
if (iter->offset == 0)
ip_options_fragment(to);
}
void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter) void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter)
{ {
unsigned int hlen = iter->hlen; unsigned int hlen = iter->hlen;
...@@ -598,8 +607,6 @@ void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter) ...@@ -598,8 +607,6 @@ void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter)
iph = iter->iph; iph = iter->iph;
iph->tot_len = htons(frag->len); iph->tot_len = htons(frag->len);
ip_copy_metadata(frag, skb); ip_copy_metadata(frag, skb);
if (iter->offset == 0)
ip_options_fragment(frag);
iter->offset += skb->len - hlen; iter->offset += skb->len - hlen;
iph->frag_off = htons(iter->offset >> 3); iph->frag_off = htons(iter->offset >> 3);
if (frag->next) if (frag->next)
...@@ -627,6 +634,25 @@ void ip_frag_init(struct sk_buff *skb, unsigned int hlen, ...@@ -627,6 +634,25 @@ void ip_frag_init(struct sk_buff *skb, unsigned int hlen,
} }
EXPORT_SYMBOL(ip_frag_init); EXPORT_SYMBOL(ip_frag_init);
static void ip_frag_ipcb(struct sk_buff *from, struct sk_buff *to,
bool first_frag, struct ip_frag_state *state)
{
/* Copy the flags to each fragment. */
IPCB(to)->flags = IPCB(from)->flags;
if (IPCB(from)->flags & IPSKB_FRAG_PMTU)
state->iph->frag_off |= htons(IP_DF);
/* ANK: dirty, but effective trick. Upgrade options only if
* the segment to be fragmented was THE FIRST (otherwise,
* options are already fixed) and make it ONCE
* on the initial skb, so that all the following fragments
* will inherit fixed options.
*/
if (first_frag)
ip_options_fragment(from);
}
struct sk_buff *ip_frag_next(struct sk_buff *skb, struct ip_frag_state *state) struct sk_buff *ip_frag_next(struct sk_buff *skb, struct ip_frag_state *state)
{ {
unsigned int len = state->left; unsigned int len = state->left;
...@@ -685,18 +711,6 @@ struct sk_buff *ip_frag_next(struct sk_buff *skb, struct ip_frag_state *state) ...@@ -685,18 +711,6 @@ struct sk_buff *ip_frag_next(struct sk_buff *skb, struct ip_frag_state *state)
iph = ip_hdr(skb2); iph = ip_hdr(skb2);
iph->frag_off = htons((state->offset >> 3)); iph->frag_off = htons((state->offset >> 3));
if (IPCB(skb)->flags & IPSKB_FRAG_PMTU)
iph->frag_off |= htons(IP_DF);
/* ANK: dirty, but effective trick. Upgrade options only if
* the segment to be fragmented was THE FIRST (otherwise,
* options are already fixed) and make it ONCE
* on the initial skb, so that all the following fragments
* will inherit fixed options.
*/
if (state->offset == 0)
ip_options_fragment(skb);
/* /*
* Added AC : If we are fragmenting a fragment that's not the * Added AC : If we are fragmenting a fragment that's not the
* last fragment then keep MF on each bit * last fragment then keep MF on each bit
...@@ -799,8 +813,10 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, ...@@ -799,8 +813,10 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
for (;;) { for (;;) {
/* Prepare header of the next frame, /* Prepare header of the next frame,
* before previous one went down. */ * before previous one went down. */
if (iter.frag) if (iter.frag) {
ip_fraglist_ipcb_prepare(skb, &iter);
ip_fraglist_prepare(skb, &iter); ip_fraglist_prepare(skb, &iter);
}
err = output(net, sk, skb); err = output(net, sk, skb);
...@@ -844,11 +860,14 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, ...@@ -844,11 +860,14 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
*/ */
while (state.left > 0) { while (state.left > 0) {
bool first_frag = (state.offset == 0);
skb2 = ip_frag_next(skb, &state); skb2 = ip_frag_next(skb, &state);
if (IS_ERR(skb2)) { if (IS_ERR(skb2)) {
err = PTR_ERR(skb2); err = PTR_ERR(skb2);
goto fail; goto fail;
} }
ip_frag_ipcb(skb, skb2, first_frag, &state);
/* /*
* Put this fragment into the sending queue. * Put this fragment into the sending queue.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment